forked from teamnwah/openmw-tes3coop
Fix the coordinate frame for eyeDir, minor cleanup (Bug #3440)
This commit is contained in:
parent
aa5a643e3b
commit
6a1fd05074
2 changed files with 14 additions and 12 deletions
|
@ -71,23 +71,24 @@ void main()
|
|||
vec3 normalizedNormal = normalize(passNormal);
|
||||
vec3 normalizedTangent = normalize(passTangent);
|
||||
vec3 binormal = cross(normalizedTangent, normalizedNormal);
|
||||
mat3 tbn = mat3(normalizedTangent, binormal, normalizedNormal);
|
||||
mat3 tbnTranspose = mat3(normalizedTangent, binormal, normalizedNormal);
|
||||
|
||||
vec3 viewNormal = gl_NormalMatrix * normalize(tbn * (normalTex.xyz * 2.0 - 1.0));
|
||||
vec3 viewNormal = gl_NormalMatrix * normalize(tbnTranspose * (normalTex.xyz * 2.0 - 1.0));
|
||||
#else
|
||||
vec3 viewNormal = gl_NormalMatrix * normalize(passNormal);
|
||||
#endif
|
||||
|
||||
#if @parallax
|
||||
vec3 cameraPos = osg_ViewMatrixInverse[3].xyz;
|
||||
vec3 eyeDir = normalize(cameraPos - (osg_ViewMatrixInverse * vec4(passViewPos, 1)).xyz);
|
||||
vec2 offset = getParallaxOffset(eyeDir, tbn, normalTex.a);
|
||||
vec3 cameraPos = (gl_ModelViewMatrixInverse * vec4(0,0,0,1)).xyz;
|
||||
vec3 objectPos = (gl_ModelViewMatrixInverse * vec4(passViewPos, 1)).xyz;
|
||||
vec3 eyeDir = normalize(cameraPos - objectPos);
|
||||
vec2 offset = getParallaxOffset(eyeDir, tbnTranspose, normalTex.a);
|
||||
adjustedDiffuseUV += offset; // only offset diffuse for now, other textures are more likely to be using a completely different UV set
|
||||
|
||||
#if @diffuseMapUV == @normalMapUV
|
||||
// fetch a new normal using updated coordinates
|
||||
normalTex = texture2D(normalMap, adjustedDiffuseUV);
|
||||
viewNormal = gl_NormalMatrix * normalize(tbn * (normalTex.xyz * 2.0 - 1.0));
|
||||
viewNormal = gl_NormalMatrix * normalize(tbnTranspose * (normalTex.xyz * 2.0 - 1.0));
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
|
|
@ -42,21 +42,22 @@ void main()
|
|||
vec3 tangent = vec3(1.0, 0.0, 0.0);
|
||||
vec3 binormal = normalize(cross(tangent, normalizedNormal));
|
||||
tangent = normalize(cross(normalizedNormal, binormal)); // note, now we need to re-cross to derive tangent again because it wasn't orthonormal
|
||||
mat3 tbn = mat3(tangent, binormal, normalizedNormal);
|
||||
mat3 tbnTranspose = mat3(tangent, binormal, normalizedNormal);
|
||||
|
||||
vec3 viewNormal = normalize(gl_NormalMatrix * (tbn * (normalTex.xyz * 2.0 - 1.0)));
|
||||
vec3 viewNormal = normalize(gl_NormalMatrix * (tbnTranspose * (normalTex.xyz * 2.0 - 1.0)));
|
||||
#else
|
||||
vec3 viewNormal = normalize(gl_NormalMatrix * passNormal);
|
||||
#endif
|
||||
|
||||
#if @parallax
|
||||
vec3 cameraPos = osg_ViewMatrixInverse[3].xyz;
|
||||
vec3 eyeDir = normalize(cameraPos - (osg_ViewMatrixInverse * vec4(passViewPos, 1)).xyz);
|
||||
adjustedUV += getParallaxOffset(eyeDir, tbn, normalTex.a);
|
||||
vec3 cameraPos = (gl_ModelViewMatrixInverse * vec4(0,0,0,1)).xyz;
|
||||
vec3 objectPos = (gl_ModelViewMatrixInverse * vec4(passViewPos, 1)).xyz;
|
||||
vec3 eyeDir = normalize(cameraPos - objectPos);
|
||||
adjustedUV += getParallaxOffset(eyeDir, tbnTranspose, normalTex.a);
|
||||
|
||||
// update normal using new coordinates
|
||||
normalTex = texture2D(normalMap, adjustedUV);
|
||||
viewNormal = normalize(gl_NormalMatrix * (tbn * (normalTex.xyz * 2.0 - 1.0)));
|
||||
viewNormal = normalize(gl_NormalMatrix * (tbnTranspose * (normalTex.xyz * 2.0 - 1.0)));
|
||||
#endif
|
||||
|
||||
vec4 diffuseTex = texture2D(diffuseMap, adjustedUV);
|
||||
|
|
Loading…
Reference in a new issue