From 00ce36433f3a9193eb18fbb75a83a04d368db0e6 Mon Sep 17 00:00:00 2001 From: "David G. Yu" Date: Wed, 20 May 2015 14:12:48 -0700 Subject: [PATCH] Fixed handedness flip in Gregory{Basis} shaders There was an unnecessary double-flip in the shading calculations. --- opensubdiv/osd/glslPatchGregory.glsl | 19 +++++++------------ opensubdiv/osd/glslPatchGregoryBasis.glsl | 19 +++++++------------ opensubdiv/osd/hlslPatchGregory.hlsl | 20 ++++++++------------ opensubdiv/osd/hlslPatchGregoryBasis.hlsl | 20 ++++++++------------ 4 files changed, 30 insertions(+), 48 deletions(-) diff --git a/opensubdiv/osd/glslPatchGregory.glsl b/opensubdiv/osd/glslPatchGregory.glsl index 7c316da2..2459fbba 100644 --- a/opensubdiv/osd/glslPatchGregory.glsl +++ b/opensubdiv/osd/glslPatchGregory.glsl @@ -430,7 +430,6 @@ void main() #ifdef OSD_PATCH_TESS_EVAL_GREGORY_SHADER layout(quads) in; -layout(cw) in; #if defined OSD_FRACTIONAL_ODD_SPACING layout(fractional_odd_spacing) in; @@ -523,9 +522,7 @@ void main() for (int i=0; i<4; ++i) { for (uint j=0; j<4; ++j) { - // reverse face front - vec3 A = q[i + 4*j]; - + vec3 A = q[4*i + j]; BUCP[i] += A * B[j]; DUCP[i] += A * D[j]; CUCP[i] += A * C[j]; @@ -569,7 +566,7 @@ void main() BiTangent = (OsdModelViewMatrix() * vec4(BiTangent, 0)).xyz; Tangent = (OsdModelViewMatrix() * vec4(Tangent, 0)).xyz; - normal = normalize(cross(BiTangent, Tangent)); + normal = normalize(cross(Tangent, BiTangent)); outpt.v.Nu = Nu; outpt.v.Nv = Nv; @@ -583,9 +580,7 @@ void main() for (int i=0; i<4; ++i) { for (uint j=0; j<4; ++j) { - // reverse face front - vec3 A = q[i + 4*j]; - + vec3 A = q[4*i + j]; BUCP[i] += A * B[j]; DUCP[i] += A * D[j]; } @@ -605,16 +600,16 @@ void main() BiTangent = (OsdModelViewMatrix() * vec4(BiTangent, 0)).xyz; Tangent = (OsdModelViewMatrix() * vec4(Tangent, 0)).xyz; - vec3 normal = normalize(cross(BiTangent, Tangent)); + vec3 normal = normalize(cross(Tangent, BiTangent)); #endif outpt.v.position = OsdModelViewMatrix() * vec4(WorldPos, 1.0f); outpt.v.normal = normal; - outpt.v.tangent = BiTangent; - outpt.v.bitangent = Tangent; + outpt.v.tangent = Tangent; + outpt.v.bitangent = BiTangent; - vec2 UV = vec2(v, u); + vec2 UV = vec2(u, v); OSD_USER_VARYING_PER_EVAL_POINT(UV, 0, 1, 3, 2); diff --git a/opensubdiv/osd/glslPatchGregoryBasis.glsl b/opensubdiv/osd/glslPatchGregoryBasis.glsl index 92b81d5f..0c45a67c 100644 --- a/opensubdiv/osd/glslPatchGregoryBasis.glsl +++ b/opensubdiv/osd/glslPatchGregoryBasis.glsl @@ -101,7 +101,6 @@ void main() #ifdef OSD_PATCH_TESS_EVAL_GREGORY_BASIS_SHADER layout(quads) in; -layout(cw) in; #if defined OSD_FRACTIONAL_ODD_SPACING layout(fractional_odd_spacing) in; @@ -180,9 +179,7 @@ void main() for (int i=0; i<4; ++i) { for (uint j=0; j<4; ++j) { - // reverse face front - vec3 A = q[i + 4*j]; - + vec3 A = q[4*i + j]; BUCP[i] += A * B[j]; DUCP[i] += A * D[j]; CUCP[i] += A * C[j]; @@ -207,7 +204,7 @@ void main() dVV *= 6 * level; dUV *= 9 * level; - vec3 n = cross(BiTangent, Tangent); + vec3 n = cross(Tangent, BiTangent); vec3 normal = normalize(n); float E = dot(Tangent, Tangent); @@ -235,9 +232,7 @@ void main() for (int i=0; i<4; ++i) { for (uint j=0; j<4; ++j) { - // reverse face front - vec3 A = q[i + 4*j]; - + vec3 A = q[4*i + j]; BUCP[i] += A * B[j]; DUCP[i] += A * D[j]; } @@ -254,15 +249,15 @@ void main() BiTangent *= 3 * level; Tangent *= 3 * level; - vec3 normal = normalize(cross(BiTangent, Tangent)); + vec3 normal = normalize(cross(Tangent, BiTangent)); #endif outpt.v.position = vec4(WorldPos, 1.0f); outpt.v.normal = normal; - outpt.v.tangent = BiTangent; - outpt.v.bitangent = Tangent; + outpt.v.tangent = Tangent; + outpt.v.bitangent = BiTangent; - vec2 UV = vec2(v, u); + vec2 UV = vec2(u, v); OSD_USER_VARYING_PER_EVAL_POINT(UV, 0, 5, 15, 10); diff --git a/opensubdiv/osd/hlslPatchGregory.hlsl b/opensubdiv/osd/hlslPatchGregory.hlsl index 3cc6624f..ac322ef9 100644 --- a/opensubdiv/osd/hlslPatchGregory.hlsl +++ b/opensubdiv/osd/hlslPatchGregory.hlsl @@ -295,7 +295,7 @@ HS_CONSTANT_FUNC_OUT HSConstFunc( [domain("quad")] [partitioning(HS_PARTITION)] -[outputtopology("triangle_ccw")] +[outputtopology("triangle_cw")] [outputcontrolpoints(4)] [patchconstantfunc("HSConstFunc")] GregDomainVertex hs_main_patches( @@ -537,9 +537,7 @@ void ds_main_patches( for (int i=0; i<4; ++i) { for (uint j=0; j<4; ++j) { - // reverse face front - float3 A = q[i + 4*j]; - + float3 A = q[4*i + j]; BUCP[i] += A * B[j]; DUCP[i] += A * D[j]; CUCP[i] += A * C[j]; @@ -583,7 +581,7 @@ void ds_main_patches( BiTangent = mul(OsdModelViewMatrix(), float4(BiTangent, 0)).xyz; Tangent = mul(OsdModelViewMatrix(), float4(Tangent, 0)).xyz; - normal = normalize(cross(BiTangent, Tangent)); + normal = normalize(cross(Tangent, BiTangent)); output.Nu = Nu; output.Nv = Nv; @@ -597,9 +595,7 @@ void ds_main_patches( for (int i=0; i<4; ++i) { for (uint j=0; j<4; ++j) { - // reverse face front - float3 A = q[i + 4*j]; - + float3 A = q[4*i + j]; BUCP[i] += A * B[j]; DUCP[i] += A * D[j]; } @@ -619,18 +615,18 @@ void ds_main_patches( BiTangent = mul(OsdModelViewMatrix(), float4(BiTangent, 0)).xyz; Tangent = mul(OsdModelViewMatrix(), float4(Tangent, 0)).xyz; - float3 normal = normalize(cross(BiTangent, Tangent)); + float3 normal = normalize(cross(Tangent, BiTangent)); #endif output.position = mul(OsdModelViewMatrix(), float4(WorldPos, 1.0f)); output.normal = normal; - output.tangent = BiTangent; - output.bitangent = Tangent; + output.tangent = Tangent; + output.bitangent = BiTangent; output.edgeDistance = 0; - float2 UV = float2(v, u); + float2 UV = float2(u, v); output.patchCoord = OsdInterpolatePatchCoord(UV, patch[0].patchCoord); OSD_DISPLACEMENT_CALLBACK; diff --git a/opensubdiv/osd/hlslPatchGregoryBasis.hlsl b/opensubdiv/osd/hlslPatchGregoryBasis.hlsl index 10c1b808..081dc146 100644 --- a/opensubdiv/osd/hlslPatchGregoryBasis.hlsl +++ b/opensubdiv/osd/hlslPatchGregoryBasis.hlsl @@ -78,7 +78,7 @@ HSConstFunc( [domain("quad")] [partitioning(HS_PARTITION)] -[outputtopology("triangle_ccw")] +[outputtopology("triangle_cw")] [outputcontrolpoints(20)] [patchconstantfunc("HSConstFunc")] HullVertex hs_main_patches( @@ -159,9 +159,7 @@ void ds_main_patches( for (int i=0; i<4; ++i) { for (uint j=0; j<4; ++j) { - // reverse face front - float3 A = q[i + 4*j]; - + float3 A = q[4*i + j]; BUCP[i] += A * B[j]; DUCP[i] += A * D[j]; CUCP[i] += A * C[j]; @@ -186,7 +184,7 @@ void ds_main_patches( dVV *= 6 * level; dUV *= 9 * level; - float3 n = cross(BiTangent, Tangent); + float3 n = cross(Tangent, BiTangent); float3 normal = normalize(n); float E = dot(Tangent, Tangent); @@ -214,9 +212,7 @@ void ds_main_patches( for (int i=0; i<4; ++i) { for (uint j=0; j<4; ++j) { - // reverse face front - float3 A = q[i + 4*j]; - + float3 A = q[4*i + j]; BUCP[i] += A * B[j]; DUCP[i] += A * D[j]; } @@ -233,18 +229,18 @@ void ds_main_patches( BiTangent *= 3 * level; Tangent *= 3 * level; - float3 normal = normalize(cross(BiTangent, Tangent)); + float3 normal = normalize(cross(Tangent, BiTangent)); #endif output.position = float4(WorldPos, 1.0f); output.normal = normal; - output.tangent = BiTangent; - output.bitangent = Tangent; + output.tangent = Tangent; + output.bitangent = BiTangent; output.edgeDistance = 0; - float2 UV = float2(v, u); + float2 UV = float2(u, v); output.patchCoord = OsdInterpolatePatchCoord(UV, patch[0].patchCoord); OSD_DISPLACEMENT_CALLBACK;