|
|
@ -42,21 +42,22 @@ void main()
|
|
|
|
vec3 tangent = vec3(1.0, 0.0, 0.0);
|
|
|
|
vec3 tangent = vec3(1.0, 0.0, 0.0);
|
|
|
|
vec3 binormal = normalize(cross(tangent, normalizedNormal));
|
|
|
|
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
|
|
|
|
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
|
|
|
|
#else
|
|
|
|
vec3 viewNormal = normalize(gl_NormalMatrix * passNormal);
|
|
|
|
vec3 viewNormal = normalize(gl_NormalMatrix * passNormal);
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
#if @parallax
|
|
|
|
#if @parallax
|
|
|
|
vec3 cameraPos = osg_ViewMatrixInverse[3].xyz;
|
|
|
|
vec3 cameraPos = (gl_ModelViewMatrixInverse * vec4(0,0,0,1)).xyz;
|
|
|
|
vec3 eyeDir = normalize(cameraPos - (osg_ViewMatrixInverse * vec4(passViewPos, 1)).xyz);
|
|
|
|
vec3 objectPos = (gl_ModelViewMatrixInverse * vec4(passViewPos, 1)).xyz;
|
|
|
|
adjustedUV += getParallaxOffset(eyeDir, tbn, normalTex.a);
|
|
|
|
vec3 eyeDir = normalize(cameraPos - objectPos);
|
|
|
|
|
|
|
|
adjustedUV += getParallaxOffset(eyeDir, tbnTranspose, normalTex.a);
|
|
|
|
|
|
|
|
|
|
|
|
// update normal using new coordinates
|
|
|
|
// update normal using new coordinates
|
|
|
|
normalTex = texture2D(normalMap, adjustedUV);
|
|
|
|
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
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
vec4 diffuseTex = texture2D(diffuseMap, adjustedUV);
|
|
|
|
vec4 diffuseTex = texture2D(diffuseMap, adjustedUV);
|
|
|
|