Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,7 @@ void main(){
vec3 viewDir = normalize(g_CameraPosition - wPosition);

#if defined(NORMALMAP) || defined(PARALLAXMAP)
vec3 tan = normalize(wTangent.xyz);
vec3 norm = normalize(wNormal);
mat3 tbnMat = mat3(tan, wTangent.w * cross(norm, tan), norm.xyz);
mat3 tbnMat = mat3(wTangent.xyz, wTangent.w * cross( (wNormal), (wTangent.xyz)), wNormal.xyz);
#endif

#if (defined(PARALLAXMAP) || (defined(NORMALMAP_PARALLAX) && defined(NORMALMAP)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ void main(){
#endif

wPosition = TransformWorld(modelSpacePos).xyz;
wNormal = TransformWorld(vec4(modelSpaceNorm,0.0)).xyz;
wNormal = TransformWorldNormal(modelSpaceNorm);

#if defined(NORMALMAP) || defined(PARALLAXMAP)
wTangent = vec4(TransformWorld(vec4(modelSpaceTan,0.0)).xyz,inTangent.w);
wTangent = vec4(TransformWorldNormal(modelSpaceTan),inTangent.w);
#endif

Color = m_BaseColor;
Expand Down
17 changes: 12 additions & 5 deletions jme3-core/src/main/resources/Common/ShaderLib/Instancing.glsllib
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,16 @@ vec4 TransformWorldViewProjection(vec4 position)
return g_ViewProjectionMatrix * TransformWorld(position);
}

vec3 TransformNormal(vec3 vec)
{
vec3 TransformWorldNormal(vec3 vec) {
vec4 quat = vec4(inInstanceData[0].w, inInstanceData[1].w,
inInstanceData[2].w, inInstanceData[3].w);

vec3 worldNormal = vec + vec3(2.0) * cross(cross(vec, quat.xyz) + vec3(quat.w) * vec, quat.xyz);

return (g_ViewMatrix * vec4(worldNormal, 0.0)).xyz;
return vec + vec3(2.0) * cross(cross(vec, quat.xyz) + vec3(quat.w) * vec, quat.xyz);
}

vec3 TransformNormal(vec3 vec)
{
return (g_ViewMatrix * vec4(TransformWorldNormal(vec), 0.0)).xyz;
}

// Prevent user from using g_** matrices which will have invalid data in this case.
Expand Down Expand Up @@ -97,4 +99,9 @@ vec3 TransformNormal(vec3 normal) {
return g_NormalMatrix * normal;
}

vec3 TransformWorldNormal(vec3 normal) {
return normalize((g_WorldMatrix * vec4(normal,0.0)).xyz);
}


#endif