creative icon indicating copy to clipboard operation
creative copied to clipboard

Support for Shaders

Open yusshu opened this issue 1 year ago • 3 comments

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(); }
    }
}

yusshu avatar Dec 12 '23 04:12 yusshu

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.

dev-hydrogen avatar Dec 17 '23 16:12 dev-hydrogen

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

BiConsumer avatar Dec 17 '23 17:12 BiConsumer

The mixin option looks like a dream 🤤

MelonHell avatar Dec 22 '23 10:12 MelonHell