leon-o / iris-flw-compat

Enable Flywheel's optimizations when using shaderpacks.
MIT License
46 stars 24 forks source link

Brightly lit contraptions #82

Closed codegoose closed 1 month ago

codegoose commented 10 months ago

Hi there,

I noticed that contraptions are not affected by shader lighting in my server so I went digging around. I added some code to output the results of the vertex shader transformations to the filesystem so I could take a look:

void main() {
  v = FLWCreateVertex();
  vertex(v);
  v.light = vec2(0, 0.85f);
  vec3 skewedNormal = v.normal + vec3(0.5f, 0.5f, 0.5f);
  _flw_tangent = vec4(normalize(skewedNormal - v.normal * dot(skewedNormal, v.normal)).xyz, 1.0f);
  _flw_patched_vertex_pos = FLWVertex(v);
  texCoord = (gl_TextureMatrix[0] * vec4(v.texCoords, 0, 1)).xy;
  vertexColor = v.color.rgb;
  vec3 vertexNormal = fastNormalize(v.normal);
  vec3 vertexTangent = fastNormalize(_flw_tangent.xyz);
  vertexPos = gbufferModelViewInverse * (gl_ModelViewMatrix * inverse(gl_ProjectionMatrix * gl_ModelViewMatrix) * _flw_patched_vertex_pos);
  TBN = mat3(gbufferModelViewInverse) * (gl_NormalMatrix * mat3(vertexTangent, cross(vertexTangent, vertexNormal) * sign(_flw_tangent.w), vertexNormal));
  lmCoord = saturate((vec4(max(v.light, texture3D(uLightVolume, BoxCoord).rg) * 255.0f, 0, 1)).xy * 0.00416667f);
  gl_Position = _flw_patched_vertex_pos;
}

(This is with the Super Duper Vanilla pack.)

I noticed that the ShaderPatcherBase.java is inserting this into Create's passthrough.vert shader:

v = FLWCreateVertex();
vertex(v);
v.light = vec2(0,0.85);

This has the effects of causing the contraptions to be very brightly lit:

2023-11-26_20 11 52

Upon removing the v.light = vec2(0,0.85); line, contraptions go back to normal:

2023-11-26_20 12 10

I'm just wondering what the reasoning behind this is as I don't have full context of what's going on, really.

Hr0bak commented 3 months ago

I have the exact same problem! But I'm a very superficial user( I would be so grateful if you could explain where exactly to find this file, and the document in it, where I can edit this setting and fix the problem.

codegoose commented 2 months ago

I have the exact same problem! But I'm a very superficial user( I would be so grateful if you could explain where exactly to find this file, and the document in it, where I can edit this setting and fix the problem.

It's in here: https://github.com/leon-o/iris-flw-compat/blob/6f8b46b2f0270fc5a7feea354dd2b03c96a295af/src/main/java/top/leonx/irisflw/transformer/ShaderPatcherBase.java#L40

I had just removed that line and rebuilt the JAR.

leon-o commented 1 month ago

Sorry, it was my mistake. I have already fixed this issue in bef9d93.