Class MaterialCompiler

java.lang.Object
dev.engine.graphics.common.material.MaterialCompiler

public final class MaterialCompiler extends Object
Compiles material properties into shader code and GPU-uploadable data.

This bridges the gap between the user's property bag (MaterialData) and the GPU's typed buffers + shader structs. The user never writes shader code for standard materials — this generates everything automatically.

  • Method Details

    • shaderKey

      public static String shaderKey(MaterialData mat)
      Derives a shader key from a material's shaderHint + property set. Same key = same shader variant. Different properties = different key.
    • generateMaterialStruct

      public static String generateMaterialStruct(MaterialData mat)
      Generates a Slang struct definition from the material's actual properties.
    • generateMaterialCbuffer

      public static String generateMaterialCbuffer(MaterialData mat, int binding)
      Generates a Slang cbuffer with the material's properties inlined.
    • serializeMaterialData

      public static ByteBuffer serializeMaterialData(MaterialData mat)
      Serializes the material's property values into a ByteBuffer for GPU upload. Properties are laid out in the same order as the generated struct.
    • injectMaterialData

      public static String injectMaterialData(String source, MaterialData mat, int binding)
      Injects material struct/cbuffer into shader source, replacing the // __MATERIAL_DATA__ placeholder.
    • registerType

      public static void registerType(Class<?> javaType, String slangType, int sizeInBytes)
      Registers a custom type for material → Slang mapping.