Skip to content

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Sep 13, 2025

This PR addresses the lack of templates for code-based material definitions in the JME SDK. Previously, developers had to use the shader nodes template and manually remove boilerplate code to create materials with custom GLSL shaders.

What's Added

Code-based J3MD Template (CodeBasedMatDef.j3md):

MaterialDef ${name} {
    MaterialParameters {
        Vector4 Color
    }
    Technique {
        VertexShader GLSL100: ${name}.vert
        FragmentShader GLSL100: ${name}.frag
        WorldParameters {
            WorldViewProjectionMatrix
        }
    }
}

Basic Shader Templates:

  • BasicShader.vert - Minimal vertex shader with standard vertex transformation and ${name} substitution
  • BasicShader.frag - Minimal fragment shader with color output and ${name} substitution

Multi-File Template Wizard:

  • CodeBasedMatDefWizardIterator - Custom wizard that creates all three files (J3MD + vertex + fragment shaders) simultaneously
  • Automatically generates properly named shader files when creating a material definition

Template Features

  • FreeMarker Variable Substitution: All templates properly support ${name} variable replacement with the actual file name from the wizard
  • Multi-File Creation: New wizard automatically creates the J3MD file along with corresponding .vert and .frag files with matching names
  • Template Registration: Proper NetBeans template registration with @TemplateRegistration annotations and FreeMarker script engine configuration
  • Individual Template Access: Individual shader templates can still be instantiated independently through the New File dialog

Benefits

  • Eliminates boilerplate removal: Developers no longer need to start with a 33-line shader nodes template and remove 18 lines of complex shader node definitions
  • Clean starting point: New template provides a minimal, ready-to-use foundation for code-based shaders
  • Complete workflow: Single template action creates J3MD + vertex + fragment shader files with consistent naming
  • No manual file creation: Developers no longer need to manually create and name shader files after creating the material definition
  • Maintains existing functionality: Original shader nodes template is preserved and renamed for clarity
  • Dynamic naming: Templates use the actual file name from the wizard instead of hardcoded placeholder names

Template Organization

The templates are organized into logical categories in the New File dialog:

  • Material: Shader nodes template and new multi-file code-based J3MD template with wizard
  • GLSL: Individual vertex and fragment shader templates

All templates follow established JME3 conventions and are validated against existing working shaders in the codebase.

Fixes #664.

Warning

archive.apache.org

  • Triggering command: /usr/lib/jvm/temurin-17-jdk-amd64/bin/java --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.lang.invoke=ALL-UNNAMED --add-opens=java.prefs/java.util.prefs=ALL-UNNAMED --add-opens=java.base/java.nio.charset=ALL-UNNAMED --add-opens=java.base/java.net=ALL-UNNAMED --add-opens=java.base/java.util.concurrent.atomic=ALL-UNNAMED -XX:MaxMetaspaceSize=384m -XX:+HeapDumpOnOutOfMemoryError -Xms256m -Xmx512m -Dfile.encoding=UTF-8 -Duser.country -Duser.language=en -Duser.variant -cp /home/REDACTED/.gradle/wrapper/dists/gradle-8.6-bin/afr5mpiioh2wthjmwnkmdsd5w/gradle-8.6/lib/gradle-launcher-8.6.jar -javaagent:/home/REDACTED/.gradle/wrapper/dists/gradle-8.6-bin/afr5mpiioh2wthjmwnkmdsd5w/gradle-8.6/lib/agents/gradle-instrumentation-agent-8.6.jar org.gradle.launcher.daemon.bootstrap.GradleDaemon 8.6 (dns block)

If you need me to access, download, or install something from one of these locations, you can either:


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

@neph1
Copy link
Contributor

neph1 commented Sep 13, 2025

The template mentioned in the issue is MatDef.j3md in jme3.gde.materialdefinition. Try to define (1) one glsl based template and (2) link it in the editor

Copilot AI and others added 2 commits September 13, 2025 05:18
Co-authored-by: neph1 <7988802+neph1@users.noreply.github.com>
Co-authored-by: neph1 <7988802+neph1@users.noreply.github.com>
@Copilot Copilot AI changed the title [WIP] Missing J3MD template with code based shaders Add code-based J3MD template and shader templates for improved UX Sep 13, 2025
@Copilot Copilot AI requested a review from neph1 September 13, 2025 05:21
Copilot finished work on behalf of neph1 September 13, 2025 05:21
Copy link
Contributor

@neph1 neph1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a good start. However,

  1. the j3md ends up the same as the template, ie ${name} isn't replaced.
  2. BasicShader.frag and vert are never instantiated.
  3. Use the name of the file from the wizard as name instead of BasicShader

@copilot please address these changes

@neph1
Copy link
Contributor

neph1 commented Sep 13, 2025

@copilot please check the review comments.

Copilot AI and others added 2 commits September 13, 2025 06:36
Co-authored-by: neph1 <7988802+neph1@users.noreply.github.com>
Co-authored-by: neph1 <7988802+neph1@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Sep 13, 2025

It's a good start. However,

  1. the j3md ends up the same as the template, ie ${name} isn't replaced.
  2. BasicShader.frag and vert are never instantiated.
    ...

I've addressed all three issues:

  1. ${name} variable substitution: Added scriptEngine = "freemarker" to the template registrations, enabling proper variable replacement in the j3md template
  2. Shader template instantiation: Both BasicShader.frag and .vert are now properly registered as individual templates in the GLSL category and can be instantiated independently
  3. Using wizard name: All templates now use ${name} variable which gets replaced with the actual file name from the wizard instead of hardcoded "BasicShader"

The templates are organized into logical categories in the New File dialog:

  • Material folder: Both shader nodes and code-based J3MD templates
  • GLSL folder: Vertex and fragment shader templates

Changes in commit 78d2ed7.

The template mentioned in the issue is MatDef.j3md in jme3.gde.materialdefinition. Try to define (1) one glsl based template and (2) link it in the editor

I've created a GLSL-based template as requested and linked it in the editor through the @TemplateRegistration annotations in package-info.java. The CodeBasedMatDef.j3md template provides a clean alternative to the existing shader nodes template, specifically designed for developers who want to write custom GLSL shaders directly.

The template includes:

  • Material parameter definitions
  • Direct GLSL shader file references (${name}.vert and ${name}.frag)
  • World parameter configuration
  • FreeMarker variable substitution for the ${name} placeholder

Implementation in commits b158aaf and 78d2ed7.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • archive.apache.org
    • Triggering command: /usr/lib/jvm/temurin-17-jdk-amd64/bin/java --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.lang.invoke=ALL-UNNAMED --add-opens=java.prefs/java.util.prefs=ALL-UNNAMED --add-opens=java.base/java.nio.charset=ALL-UNNAMED --add-opens=java.base/java.net=ALL-UNNAMED --add-opens=java.base/java.util.concurrent.atomic=ALL-UNNAMED -XX:MaxMetaspaceSize=384m -XX:&#43;HeapDumpOnOutOfMemoryError -Xms256m -Xmx512m -Dfile.encoding=UTF-8 -Duser.country -Duser.language=en -Duser.variant -cp /home/REDACTED/.gradle/wrapper/dists/gradle-8.6-bin/afr5mpiioh2wthjmwnkmdsd5w/gradle-8.6/lib/gradle-launcher-8.6.jar -javaagent:/home/REDACTED/.gradle/wrapper/dists/gradle-8.6-bin/afr5mpiioh2wthjmwnkmdsd5w/gradle-8.6/lib/agents/gradle-instrumentation-agent-8.6.jar org.gradle.launcher.daemon.bootstrap.GradleDaemon 8.6 (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

@Copilot Copilot AI changed the title Add code-based J3MD template and shader templates for improved UX Add code-based J3MD template and shader templates with FreeMarker variable substitution Sep 13, 2025
@Copilot Copilot AI requested a review from neph1 September 13, 2025 06:39
Copilot finished work on behalf of neph1 September 13, 2025 06:39
@neph1
Copy link
Contributor

neph1 commented Sep 15, 2025

@copilot naming works, great! is it possible to also generate the .frag and .vert files with the correct names when you make a .j3md? Currently only the .j3md is generated.

Co-authored-by: neph1 <7988802+neph1@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Sep 15, 2025

@copilot naming works, great! is it possible to also generate the .frag and .vert files with the correct names when you make a .j3md? Currently only the .j3md is generated.

Yes! I've implemented a custom wizard iterator that automatically generates the .frag and .vert files with the correct names when you create a .j3md file.

The new "Material Definition Template (Code Based with Shaders)" now creates all three files at once:

  • [Name].j3md - The material definition
  • [Name].vert - The vertex shader
  • [Name].frag - The fragment shader

All files use the actual name you provide in the wizard (instead of hardcoded "BasicShader") and the material definition automatically references the shader files with the correct names.

Implementation in commit 8d5b127.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • archive.apache.org
    • Triggering command: /usr/lib/jvm/temurin-17-jdk-amd64/bin/java --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.lang.invoke=ALL-UNNAMED --add-opens=java.prefs/java.util.prefs=ALL-UNNAMED --add-opens=java.base/java.nio.charset=ALL-UNNAMED --add-opens=java.base/java.net=ALL-UNNAMED --add-opens=java.base/java.util.concurrent.atomic=ALL-UNNAMED -XX:MaxMetaspaceSize=384m -XX:&#43;HeapDumpOnOutOfMemoryError -Xms256m -Xmx512m -Dfile.encoding=UTF-8 -Duser.country -Duser.language=en -Duser.variant -cp /home/REDACTED/.gradle/wrapper/dists/gradle-8.6-bin/afr5mpiioh2wthjmwnkmdsd5w/gradle-8.6/lib/gradle-launcher-8.6.jar -javaagent:/home/REDACTED/.gradle/wrapper/dists/gradle-8.6-bin/afr5mpiioh2wthjmwnkmdsd5w/gradle-8.6/lib/agents/gradle-instrumentation-agent-8.6.jar org.gradle.launcher.daemon.bootstrap.GradleDaemon 8.6 (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

@Copilot Copilot AI changed the title Add code-based J3MD template and shader templates with FreeMarker variable substitution Add code-based J3MD template and shader templates with multi-file wizard and FreeMarker variable substitution Sep 15, 2025
Copilot finished work on behalf of neph1 September 15, 2025 19:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Missing J3MD template with code based shaders
2 participants