creative
creative copied to clipboard
Support for Shaders
Make creative support shaders and add API for shader modification.
Imperatively (this would require us to parse the shaders):
Shader shader;
shader = shader.modify(m -> m
.addUniform("mat4", "ModelViewMat")
.addUniform("mat4", "ProjMat")
.addUniform("mat3", "IViewRotMat")
.addIn("vec2", "texCoord1")
.addIn("float", "part")
.injectMain(At.START, "if (...) discard;"));
Or maybe using patches (this doesn't require parsing):
Shader shader;
// diff format
shader = shader.patch("""
17 + uniform mat4 ModelViewMat;
18 + uniform mat4 ProjMat;
19 + uniform mat3 IViewRotMat;
20 +
21 + in vec2 texCoord1;
22 + in float part;
""");
Or maybe even something like Mixin, but for GLSL. have a look at JLSL.
@ShaderMixin("rendertype_entity_translucent")
class RenderTypeEntityTranslucentMixin implements FragmentShader {
@Uniform private Matrix4Float ModelViewMat;
@Uniform private Matrix4Float ProjMat;
@Uniform private Matrix3Float IViewRotMat;
@In private Vector2Float texCoord1;
@In private Vector2Float part;
@Override
@Inject(At.START)
public void main() {
if (...) { discard(); }
}
}
I really like the idea of JLSL. I haven't tried it in practice, but i imagine having access to all the comfort of intellij (autofill, copilot, etc.) for shaders is way better than any text editor / VSCode.
If this is ever implemented we have to consider the json description of core, program shaders and post shaders. I personally believe that JLSL might be way too much of a hassle, especially for includes
The mixin option looks like a dream 🤤