Fixing PBR on <= GLSL 130:

- GLSLCompat now implements mat3(mat4) and determinant() and inverse() for mat2 and mat3
 - PBR.glslib uses this functions again instead of one-off workarounds
master
MeFisto94 5 years ago
parent 2379cfba77
commit 2276197a2b
  1. 36
      jme3-core/src/main/resources/Common/ShaderLib/GLSLCompat.glsllib
  2. 6
      jme3-core/src/main/resources/Common/ShaderLib/PBR.glsllib

@ -42,4 +42,40 @@ out vec4 outFragColor;
# define isnan(val) !(val<0.0||val>0.0||val==0.0)
#endif
#if __VERSION__ == 110
mat3 mat3(mat4 m) {
return mat3(m[0].xyz, m[1].xyz, m[2].xyz);
}
#endif
#if __VERSION__ <= 140
float determinant(mat2 m) {
return m[0][0] * m[1][1] - m[1][0] * m[0][1];
}
float determinant(mat3 m) {
return + m[0][0] * (m[1][1] * m[2][2] - m[1][2] * m[2][1])
- m[0][1] * (m[1][0] * m[2][2] - m[1][2] * m[2][0])
+ m[0][2] * (m[1][0] * m[2][1] - m[1][1] * m[2][0]);
}
#endif
#if __VERSION__ <= 130
mat2 inverse(mat2 m) {
return mat2(m[1][1], -m[0][1], -m[1][0], m[0][0]) / determinant(m);
}
mat3 inverse(mat3 m) {
return mat3(
+ (m[1][1] * m[2][2] - m[2][1] * m[1][2]),
- (m[1][0] * m[2][2] - m[2][0] * m[1][2]),
+ (m[1][0] * m[2][1] - m[2][0] * m[1][1]),
- (m[0][1] * m[2][2] - m[2][1] * m[0][2]),
+ (m[0][0] * m[2][2] - m[2][0] * m[0][2]),
- (m[0][0] * m[2][1] - m[2][0] * m[0][1]),
+ (m[0][1] * m[1][2] - m[1][1] * m[0][2]),
- (m[0][0] * m[1][2] - m[1][0] * m[0][2]),
+ (m[0][0] * m[1][1] - m[1][0] * m[0][1])) / determinant(m);
}
#endif

@ -143,12 +143,8 @@ float renderProbe(vec3 viewDir, vec3 worldPos, vec3 normal, vec3 norm, float Rou
if(lightProbeData[0][3] != 0.0){
// oriented box probe
mat3 wToLocalRot;
wToLocalRot[0].xyz = lightProbeData[0].xyz;
wToLocalRot[1].xyz = lightProbeData[1].xyz;
wToLocalRot[2].xyz = lightProbeData[2].xyz;
mat3 wToLocalRot = inverse(mat3(lightProbeData));
wToLocalRot = inverse(wToLocalRot);
vec3 scale = vec3(lightProbeData[0][3], lightProbeData[1][3], lightProbeData[2][3]);
#if NB_PROBES >= 2
// probe blending

Loading…
Cancel
Save