Selaa lähdekoodia

Remove unused IBL code which requires tangents / bitangents, and do not require tangents for IBL / non-normalmapped. Fix PBR techniques so that VS also refers to NORMALMAP define when necessary, since that is now required to trigger the tangent calculation. Closes #2072.

Lasse Öörni 8 vuotta sitten
vanhempi
sitoutus
c2c1d06cd2

+ 1 - 237
bin/CoreData/Shaders/GLSL/IBL.glsl

@@ -1,241 +1,6 @@
 #line 10001
 #ifdef COMPILEPS
 
-    //
-    // Legacy Importance Sampled IBL
-    //
-
-    // vec3 ImportanceSampleSimple(in vec2 Xi, in float roughness, in vec3 T, in vec3 B, in vec3 N)
-    // {
-    //     float a = roughness * roughness;
-    //     mat3 tbn = mat3(T, B, N);
-    //     #ifdef IBLFAST
-    //         const float blurFactor = 0.0;
-    //     #else
-    //         const float blurFactor = 5.0;
-    //     #endif
-    //     vec2 xx = Xi.xy * blurFactor;
-    //     xx = xx - 1.0 * trunc(xx/1.0); // hlsl style modulo
-    //     vec3 Xi3 = mix(vec3(0,0,1), normalize(vec3(xx, 1.0)), a);
-    //     vec3 XiWS = tbn * Xi3;
-    //     return normalize(N + XiWS);
-    // }
-
-    // // Karis '13
-    // vec3 ImportanceSampleGGX(in vec2 Xi, in float roughness, in vec3 T, in vec3 B, in vec3 N)
-    // {
-    //     float a = roughness * roughness;
-    //     float Phi = 2.0 * M_PI * Xi.x;
-    //     float CosTheta = sqrt((1.0 - Xi.y) / (1.0 + (a*a - 1.0) * Xi.y));
-    //     float SinTheta = sqrt(1.0 - CosTheta * CosTheta);
-    //     vec3 H = vec3(0,0,0);
-    //     H.x = SinTheta * cos(Phi);
-    //     H.y = SinTheta * sin(Phi);
-    //     H.z = CosTheta;
-
-    //     vec3 UpVector = abs(N.z) < 0.999 ? vec3(0.0, 0.0, 1.0) : vec3(1.0, 0.0, 0.0);
-    //     vec3 TangentX = normalize(cross(UpVector, N));
-    //     vec3 TangentY = cross(N, TangentX);
-    //     // Tangent to world space
-    //     return TangentX * H.x + TangentY * H.y + N * H.z;
-    // }
-
-    // #ifdef IBLFAST
-    //     #define IMPORTANCE_SAMPLES 1
-    // #else
-    //     #define IMPORTANCE_SAMPLES 4
-    // #endif
-
-    // #define IMPORTANCE_KERNEL_SIZE 16
-    // vec2 IMPORTANCE_KERNEL[IMPORTANCE_KERNEL_SIZE] = vec2[] (
-    //     vec2(-0.0780436, 0.0558389),
-    //     vec2(0.034318, -0.0635879),
-    //     vec2(0.00230821, 0.0807279),
-    //     vec2(0.0124638, 0.117585),
-    //     vec2(0.093943, -0.0944602),
-    //     vec2(0.139348, -0.109816),
-    //     vec2(-0.181872, -0.129649),
-    //     vec2(0.240066, -0.0494057),
-    //     vec2(0.115965, -0.0374714),
-    //     vec2(-0.294819, -0.100726),
-    //     vec2(-0.149652, 0.37459),
-    //     vec2(0.261695, -0.292813),
-    //     vec2(-0.37944, -0.425145),
-    //     vec2(0.628994, -0.189387),
-    //     vec2(-0.331257, -0.646864),
-    //     vec2(-0.467004, 0.439687)
-    //   );
-
-    //   float GetMipFromRougness(float roughness)
-    //   {
-    //       float smoothness = 1.0 - roughness;
-    //       return (1.0 - smoothness * smoothness) * 10.0;
-    //   }
-
-    // /// Perform importance sampling
-    // ///     reflectVec: calculated vector of reflection
-    // ///     wsNormal: world-space normal of the surface
-    // ///     toCamera: direction from the pixel to the camera
-    // ///     specular: specular color
-    // ///     roughness: surface roughness
-    // ///     reflectionCubeColor: output color for diffuse
-    // // Implementation based on Epics 2013 course notes
-    // vec3 ImportanceSampling(in vec3 reflectVec, in vec3 tangent, in vec3 bitangent, in vec3 wsNormal, in vec3 toCamera,  in vec3 diffColor, in vec3 specColor, in float roughness, inout vec3 reflectionCubeColor)
-    // {
-    //     reflectionCubeColor = vec3(1,1,1);
-
-    //     vec3 reflectSpec = normalize(GetSpecularDominantDir(wsNormal, reflectVec, roughness));
-
-    //     vec3 V = normalize(-toCamera);
-    //     vec3 N = normalize(wsNormal);
-    //     float ndv = clamp(abs(dot(N, V)), 0.0, 1.0);
-
-    //     float specMipLevel = GetMipFromRougness(roughness);
-
-    //     vec3 accumulatedColor = vec3(0,0,0);
-    //     for (int i = 0; i < IMPORTANCE_SAMPLES; ++i)
-    //     {
-    //         vec3 kd = vec3(1,1,1);
-    //         vec3 diffuseFactor = vec3(0,0,0);
-    //         vec3 specularFactor = vec3(0,0,0);
-
-    //         {
-    //             // Diffuse IBL
-    //             const float rough = 1.0;
-    //             const float mipLevel = 9.0;
-
-    //             vec3 H = ImportanceSampleSimple(IMPORTANCE_KERNEL[i], rough, tangent, bitangent, N);
-    //             vec3 L = 2.0 * dot( V, H ) * H - V;
-
-    //             float vdh = clamp(abs(dot(V, H)), 0.0, 1.0);
-    //             float ndh = clamp(abs(dot(N, H)), 0.0, 1.0);
-    //             float ndl = clamp(abs(dot(N, L)), 0.0, 1.0);
-
-    //             vec3 sampledColor = textureLod(sZoneCubeMap, L, mipLevel).rgb;
-
-    //             vec3 diffuseTerm = Diffuse(diffColor, rough, ndv, ndl, vdh);
-    //             vec3 lightTerm = sampledColor;
-
-    //             diffuseFactor = lightTerm * diffuseTerm;
-    //         }
-
-    //         {
-    //             // Specular IBL
-    //             float rough = roughness;
-    //             float mipLevel = specMipLevel;
-
-    //             vec3 H = ImportanceSampleSimple(IMPORTANCE_KERNEL[i], rough, tangent, bitangent, N);
-    //             vec3 L = 2.0 * dot( V, H ) * H - V;
-    //             vec3 sampledColor = textureLod(sZoneCubeMap, L, mipLevel).rgb;
-
-    //             float vdh = clamp(abs(dot(V, H)), 0.0, 1.0);
-    //             float ndh = clamp(abs(dot(N, H)), 0.0, 1.0);
-    //             float ndl = clamp(abs(dot(N, L)), 0.0, 1.0);
-
-    //             vec3 fresnelTerm = Fresnel(specColor, vdh);
-    //             float distTerm = 1.0; // Optimization, this term is mathematically cancelled out  -- Distribution(ndh, roughness);
-    //             float visTerm = Visibility(ndl, ndv, rough);
-
-    //             vec3 lightTerm = sampledColor * ndl;
-
-    //             float pdf = ndl > 0.05 ? ImportanceSamplePDF(distTerm, ndh, vdh) : 4.0; // reduce artifacts at extreme grazing angles
-
-    //             vec3 specularTerm = SpecularBRDF(distTerm, fresnelTerm, visTerm, ndl, ndv);
-
-    //             // energy conservation:
-    //             // Specular conservation:
-    //             specularFactor = lightTerm * specularTerm / pdf;
-    //             specularFactor = max(
-    //               clamp(normalize(specularFactor) * (length(sampledColor * specColor)), 0.0, 1.0),
-    //               specularFactor
-    //             );
-
-    //             // Diffuse conservation:
-    //             //kd = (sampledColor * specColor)/specularFactor; //energy conservation
-    //             kd = 1.0 - specularFactor;
-    //         }
-
-    //         accumulatedColor += specularFactor + diffuseFactor * kd;
-    //     }
-
-    //     return (accumulatedColor / IMPORTANCE_SAMPLES);
-    // }
-
-    // vec3 ImportanceSamplingSimple(in vec3 reflectVec, in vec3 tangent, in vec3 bitangent, in vec3 wsNormal, in vec3 toCamera,  in vec3 diffColor, in vec3 specColor, in float roughness, inout vec3 reflectionCubeColor)
-    // {
-    //     reflectionCubeColor = vec3(1,1,1);
-
-    //     reflectVec = normalize(GetSpecularDominantDir(wsNormal, reflectVec, roughness));
-
-    //     vec3 Hn = normalize(-toCamera + wsNormal);
-    //     float ndv = clamp(dot(-toCamera, wsNormal), 0.0, 1.0);
-    //     float vdh = clamp(dot(-toCamera, Hn), 0.0, 1.0);
-    //     float ndh = clamp(dot(wsNormal, Hn), 0.0, 1.0);
-
-    //     vec3 accumulatedColor = vec3(0,0,0);
-    //     for (int i = 0; i < IMPORTANCE_SAMPLES; ++i)
-    //     {
-    //         vec3 kd = vec3(1,1,1);
-    //         vec3 diffuseFactor = vec3(0,0,0);
-    //         vec3 specularFactor = vec3(0,0,0);
-
-    //         {
-    //             // Diffuse IBL
-    //             const float rough = 1.0;
-    //             const float mipLevel = 9.0;
-
-    //             vec3 perturb = ImportanceSampleGGX(IMPORTANCE_KERNEL[i].xy, rough, tangent, bitangent, wsNormal);
-    //             vec3 sampleVec = wsNormal + perturb; //perturb by the sample vector
-
-    //             vec3 sampledColor = textureLod(sZoneCubeMap, sampleVec, mipLevel).rgb;
-    //             float ndl = clamp(dot(sampleVec, wsNormal), 0.0, 1.0);
-
-    //             vec3 diffuseTerm = Diffuse(diffColor, rough, ndv, ndl, vdh);
-    //             vec3 lightTerm = sampledColor;
-
-    //             diffuseFactor = lightTerm * diffuseTerm;
-    //         }
-
-    //         {
-    //             // Specular IBL
-    //             float rough = roughness;
-    //             float mipLevel =  GetMipFromRougness(rough);
-
-    //             vec3 perturb = ImportanceSampleGGX(IMPORTANCE_KERNEL[i].xy, rough, tangent, bitangent, reflectVec);
-    //             vec3 sampleVec = reflectVec + perturb; //perturb by the sample vector
-
-    //             vec3 sampledColor = textureCube(sZoneCubeMap, sampleVec, mipLevel).rgb;
-    //             float ndl = clamp(dot(sampleVec, wsNormal), 0.0, 1.0);
-
-    //             vec3 fresnelTerm = SchlickFresnel(specColor, ndh) ;
-    //             float distTerm = 1.0; //Optimization, this term is mathematically cancelled out  //Distribution(ndh, roughness);
-    //             float visTerm = SmithGGXVisibility(ndl, ndv, rough);
-    //             vec3 lightTerm = sampledColor * ndl;
-
-    //             float pdf = 1.0; //ImportanceSamplePDF(distTerm, ndh, vdh);
-
-    //             specularFactor = lightTerm * SpecularBRDF(distTerm, fresnelTerm, visTerm, ndl, ndv) / pdf;
-    //             specularFactor *= pdf * ndv * (4.0 * ndl * ndv); // hacks
-    //             kd = (1.0 - clamp(specularFactor, 0.0, 1.0)); //energy conservation
-    //         }
-
-    //         accumulatedColor += specularFactor + diffuseFactor * kd;
-    //     }
-
-    //     return accumulatedColor / IMPORTANCE_SAMPLES;
-    // }
-
-    /// Determine reflection vector based on surface roughness, rougher uses closer to the normal and smoother uses closer to the reflection vector
-    ///     normal: surface normal
-    ///     reflection: vector of reflection off of the surface
-    ///     roughness: surface roughness
-    // vec3 GetSpecularDominantDir(vec3 normal, vec3 reflection, float roughness)
-    // {
-    //     float smoothness = 1.0 - roughness;
-    //     float lerpFactor = smoothness * (sqrt(smoothness) + roughness);
-    //     return mix(normal, reflection, lerpFactor);
-    // }
-
     float GetMipFromRoughness(float roughness)
     {
         return (roughness * 12.0 - pow(roughness, 6.0) * 1.5);
@@ -270,7 +35,7 @@
     ///     toCamera: normalized direction from surface point to camera
     ///     roughness: surface roughness
     ///     ambientOcclusion: ambient occlusion
-    vec3 ImageBasedLighting(vec3 reflectVec, vec3 tangent, vec3 bitangent, vec3 wsNormal, vec3 toCamera, vec3 diffColor, vec3 specColor, float roughness, inout vec3 reflectionCubeColor)
+    vec3 ImageBasedLighting(vec3 reflectVec, vec3 wsNormal, vec3 toCamera, vec3 diffColor, vec3 specColor, float roughness, inout vec3 reflectionCubeColor)
     {
         roughness = max(roughness, 0.08);
         reflectVec = GetSpecularDominantDir(wsNormal, reflectVec, roughness);
@@ -307,6 +72,5 @@
         vec3 environmentDiffuse = EnvBRDFApprox(diffColor, 1.0, ndv);
 
         return (hdrCube * environmentSpecular + hdrCubeD * environmentDiffuse) * brightness;
-        //return ImportanceSampling(reflectVec, tangent, bitangent, wsNormal, toCamera, diffColor, specColor, roughness, reflectionCubeColor);
     }
 #endif

+ 4 - 4
bin/CoreData/Shaders/GLSL/PBRLitSolid.glsl

@@ -9,7 +9,7 @@
 #include "IBL.glsl"
 #line 30010
 
-#if defined(NORMALMAP) || defined(IBL)
+#if defined(NORMALMAP)
     varying vec4 vTexCoord;
     varying vec4 vTangent;
 #else
@@ -57,7 +57,7 @@ void VS()
         vColor = iColor;
     #endif
 
-    #if defined(NORMALMAP) || defined(DIRBILLBOARD) || defined(IBL)
+    #if defined(NORMALMAP) || defined(DIRBILLBOARD)
         vec4 tangent = GetWorldTangent(modelMatrix);
         vec3 bitangent = cross(tangent.xyz, vNormal) * tangent.w;
         vTexCoord = vec4(GetTexCoord(iTexCoord), bitangent.xy);
@@ -145,7 +145,7 @@ void PS()
     diffColor.rgb = diffColor.rgb - diffColor.rgb * metalness;
 
     // Get normal
-    #if defined(NORMALMAP) || defined(DIRBILLBOARD) || defined(IBL)
+    #if defined(NORMALMAP) || defined(DIRBILLBOARD)
         vec3 tangent = vTangent.xyz;
         vec3 bitangent = vec3(vTexCoord.zw, vTangent.w);
         mat3 tbn = mat3(tangent, bitangent, vNormal);
@@ -239,7 +239,7 @@ void PS()
         vec3 cubeColor = vVertexLight.rgb;
 
         #ifdef IBL
-          vec3 iblColor = ImageBasedLighting(reflection, tangent, bitangent, normal, toCamera, diffColor.rgb, specColor.rgb, roughness, cubeColor);
+          vec3 iblColor = ImageBasedLighting(reflection, normal, toCamera, diffColor.rgb, specColor.rgb, roughness, cubeColor);
           float gamma = 0.0;
           finalColor.rgb += iblColor;
         #endif

+ 1 - 229
bin/CoreData/Shaders/HLSL/IBL.hlsl

@@ -1,232 +1,5 @@
 #ifdef COMPILEPS
 
-    //  float3 ImportanceSampleSimple(in float2 Xi, in float roughness, in float3 T, in float3 B, in float3 N)
-    // {
-    //     const float a = roughness * roughness;
-    //     const float3x3 tbn = float3x3(T, B, N);
-    //     #ifdef IBLFAST
-    //         const float blurFactor = 0.0;
-    //     #else
-    //         const float blurFactor = 5.0;
-    //     #endif
-    //     const float3 Xi3 = lerp(float3(0,0,1), normalize(float3(Xi.xy * blurFactor % 1.0 , 1.0)), a);
-    //     const float3 XiWS = mul(Xi3, tbn);
-    //     return normalize(N + XiWS);
-    // }
-
-    // // Karis '13
-    // float3 ImportanceSampleGGX(in float2 Xi, in float roughness, in float3 T, in float3 B, in float3 N)
-    // {
-    //     float a = roughness * roughness;
-    //     float Phi = 2.0 * M_PI * Xi.x;
-    //     float CosTheta = (sqrt((1.0 - Xi.y) / (1.0 + (a*a - 1.0) * Xi.y)));
-    //     float SinTheta = sqrt(1.0 - CosTheta * CosTheta);
-    //     float3 H = 0;
-    //     H.x = SinTheta * cos(Phi);
-    //     H.y = SinTheta * sin(Phi);
-    //     H.z = CosTheta;
-
-    //     float3 UpVector = abs(N.z) < 0.999 ? float3(0, 0, 1) : float3(1, 0, 0);
-    //     float3 TangentX = normalize(cross(UpVector, N));
-    //     float3 TangentY = cross(N, TangentX);
-    //     // Tangent to world space
-    //     return TangentX * H.x + TangentY * H.y + N * H.z;
-    // }
-
-    // #ifdef IBLFAST
-    //     #define IMPORTANCE_SAMPLES 1
-    // #else
-    //     #define IMPORTANCE_SAMPLES 16
-    // #endif
-
-    // #define IMPORTANCE_KERNEL_SIZE 16
-    // static const float2 IMPORTANCE_KERNEL[IMPORTANCE_KERNEL_SIZE] =
-    // {
-    //     float2(-0.0780436, 0.0558389),
-    //     float2(0.034318, -0.0635879),
-    //     float2(0.00230821, 0.0807279),
-    //     float2(0.0124638, 0.117585),
-    //     float2(0.093943, -0.0944602),
-    //     float2(0.139348, -0.109816),
-    //     float2(-0.181872, -0.129649),
-    //     float2(0.240066, -0.0494057),
-    //     float2(0.115965, -0.0374714),
-    //     float2(-0.294819, -0.100726),
-    //     float2(-0.149652, 0.37459),
-    //     float2(0.261695, -0.292813),
-    //     float2(-0.37944, -0.425145),
-    //     float2(0.628994, -0.189387),
-    //     float2(-0.331257, -0.646864),
-    //     float2(-0.467004, 0.439687),
-    // };
-
-    // float GetMipFromRougness(float roughness)
-    // {
-    //     const float smoothness = 1.0 - roughness;
-    //     return (1.0 - smoothness * smoothness) * 10.0;
-    // }
-
-    // /// Perform importance sampling
-    // ///     reflectVec: calculated vector of reflection
-    // ///     wsNormal: world-space normal of the surface
-    // ///     toCamera: direction from the pixel to the camera
-    // ///     specular: specular color
-    // ///     roughness: surface roughness
-    // ///     reflectionCubeColor: output color for diffuse
-
-    // // Implementation based on Epics 2013 course notes
-    // float3 ImportanceSampling(in float3 reflectVec, in float3 tangent, in float3 bitangent, in float3 wsNormal, in float3 toCamera,  in float3 diffColor, in float3 specColor, in float roughness, inout float3 reflectionCubeColor)
-    // {
-    //     reflectionCubeColor = 1.0;
-
-    //     const float3 reflectSpec = normalize(GetSpecularDominantDir(wsNormal, reflectVec, roughness));
-
-    //     const float3 V = normalize(-toCamera);
-    //     const float3 N = normalize(wsNormal);
-    //     const float ndv = saturate(abs(dot(N, V)));
-
-    //     const float specMipLevel = GetMipFromRougness(roughness);
-
-    //     float3 accumulatedColor = float3(0,0,0);
-    //     for (int i = 0; i < IMPORTANCE_SAMPLES; ++i)
-    //     {
-    //         float3 kd = 1.0;
-    //         float3 diffuseFactor = 0.0;
-    //         float3 specularFactor = 0.0;
-
-    //         {
-    //             // Diffuse IBL
-    //             const float rough = 1.0;
-    //             const float mipLevel = 9.0;
-
-    //             const float3 H = ImportanceSampleSimple(IMPORTANCE_KERNEL[i], rough, tangent, bitangent, N);
-    //             const float3 L = 2.0 * dot( V, H ) * H - V;
-
-    //             const float vdh = saturate(abs(dot(V, H)));
-    //             const float ndh = saturate(abs(dot(N, H)));
-    //             const float ndl = saturate(abs(dot(N, L)));
-
-    //             const float3 sampledColor = SampleCubeLOD(ZoneCubeMap, float4(L, mipLevel));
-
-    //             const float3 diffuseTerm = Diffuse(diffColor, rough, ndv, ndl, vdh);
-    //             const float3 lightTerm = sampledColor;
-
-    //             diffuseFactor = lightTerm * diffuseTerm;
-    //         }
-
-    //         {
-    //             // Specular IBL
-    //             const float rough = roughness;
-    //             const float mipLevel = specMipLevel;
-
-    //             const float3 H = ImportanceSampleSimple(IMPORTANCE_KERNEL[i], rough, tangent, bitangent, N);
-    //             const float3 L = 2.0 * dot( V, H ) * H - V;
-    //             const float3 sampledColor = SampleCubeLOD(ZoneCubeMap, float4(L, mipLevel));
-
-    //             const float vdh = saturate(abs(dot(V, H)));
-    //             const float ndh = saturate(abs(dot(N, H)));
-    //             const float ndl = saturate(abs(dot(N, L)));
-
-    //             const float3 fresnelTerm = Fresnel(specColor, vdh);
-    //             const float distTerm = 1.0;//Distribution(ndh_, roughness);
-    //             const float visTerm = Visibility(ndl, ndv, rough);
-    //             const float3 lightTerm = sampledColor * ndl;
-
-    //             const float pdf = ndl > 0.05 ? ImportanceSamplePDF(distTerm, ndh, vdh) : 4.0; // reduce artifacts at extreme grazing angles
-
-    //             const float3 specularTerm = SpecularBRDF(distTerm, fresnelTerm, visTerm, ndl, ndv);
-
-    //             // Energy conservation:
-    //             // Specular conservation:
-    //             specularFactor = lightTerm * specularTerm / pdf;
-    //             specularFactor = max(saturate(normalize(specularFactor) * (length(sampledColor * specColor))), specularFactor);
-
-    //             // Diffuse conservation:
-    //             kd = 1.0 - specularFactor;
-    //         }
-
-    //         accumulatedColor += specularFactor + diffuseFactor * kd;
-    //     }
-
-    //     return (accumulatedColor / IMPORTANCE_SAMPLES);
-    // }
-
-
-    // float3 ImportanceSamplingSimple(in float3 reflectVec, in float3 tangent, in float3 bitangent, in float3 wsNormal, in float3 toCamera,  in float3 diffColor, in float3 specColor, in float roughness, inout float3 reflectionCubeColor)
-    // {
-    //     reflectionCubeColor = 1.0;
-
-    //     reflectVec = normalize(GetSpecularDominantDir(wsNormal, reflectVec, roughness));
-
-    //     const float3 Hn = normalize(-toCamera + wsNormal);
-    //     const float ndv = saturate(dot(-toCamera, wsNormal));
-    //     const float vdh = saturate(dot(-toCamera, Hn));
-    //     const float ndh = saturate(dot(wsNormal, Hn));
-
-    //     float3 accumulatedColor = float3(0,0,0);
-    //     for (int i = 0; i < IMPORTANCE_SAMPLES; ++i)
-    //     {
-    //         float3 kd = 1.0;
-    //         float3 diffuseFactor = 0.0;
-    //         float3 specularFactor = 0.0;
-
-    //         {
-    //             // Diffuse IBL
-    //             const float rough = 1.0;
-    //             const float mipLevel = 9.0;
-
-    //             const float3 perturb = ImportanceSampleGGX(IMPORTANCE_KERNEL[i].xy, rough, tangent, bitangent, wsNormal);
-    //             const float3 sampleVec = wsNormal + perturb; //perturb by the sample vector
-
-    //             const float3 sampledColor = SampleCubeLOD(ZoneCubeMap, float4(sampleVec, mipLevel));
-    //             const float ndl = saturate(dot(sampleVec, wsNormal));
-
-    //             const float3 diffuseTerm = Diffuse(diffColor, rough, ndv, ndl, vdh);
-    //             const float3 lightTerm = sampledColor;
-
-    //             diffuseFactor = lightTerm * diffuseTerm;
-    //         }
-
-    //         {
-    //             // Specular IBL
-    //             const float rough = roughness;
-    //             const float mipLevel =  GetMipFromRougness(rough);
-
-    //             const float3 perturb = ImportanceSampleGGX(IMPORTANCE_KERNEL[i].xy, rough, tangent, bitangent, reflectVec);
-    //             const float3 sampleVec = reflectVec + perturb; //perturb by the sample vector
-
-    //             const float3 sampledColor = SampleCubeLOD(ZoneCubeMap, float4(sampleVec, mipLevel));
-    //             const float ndl = saturate(dot(sampleVec, wsNormal));
-
-    //             const float3 fresnelTerm = SchlickFresnel(specColor, ndh) ;
-    //             const float distTerm = 1.0; //Optimization, this term is mathematically cancelled out  //Distribution(ndh, roughness);
-    //             const float visTerm = SmithGGXVisibility(ndl, ndv, rough);
-    //             const float3 lightTerm = sampledColor * ndl;
-
-    //             const float pdf = 1.0;//ImportanceSamplePDF(distTerm, ndh, vdh);
-
-    //             specularFactor = lightTerm * SpecularBRDF(distTerm, fresnelTerm, visTerm, ndl, ndv) / pdf;
-    //             specularFactor *= pdf * ndv * (4.0 * ndl * ndv); // hacks
-    //             kd = (1.0 - saturate(specularFactor)); //energy conservation
-    //         }
-
-    //         accumulatedColor += specularFactor + diffuseFactor * kd;
-    //     }
-
-    //     return accumulatedColor / IMPORTANCE_SAMPLES;
-    // }
-
-    /// Determine reflection vector based on surface roughness, rougher uses closer to the normal and smoother uses closer to the reflection vector
-    ///     normal: surface normal
-    ///     reflection: vector of reflection off of the surface
-    ///     roughness: surface roughness
-    // float3 GetSpecularDominantDir(float3 normal, float3 reflection, float roughness)
-    // {
-    //     const float smoothness = 1.0 - roughness;
-    //     const float lerpFactor = smoothness * (sqrt(smoothness) + roughness);
-    //     return lerp(normal, reflection, lerpFactor);
-    // }
-
     float GetMipFromRoughness(float roughness)
     {
         return (roughness * 12.0 - pow(roughness, 6.0) * 1.5);
@@ -261,7 +34,7 @@
     ///     toCamera: normalized direction from surface point to camera
     ///     roughness: surface roughness
     ///     ambientOcclusion: ambient occlusion
-    float3 ImageBasedLighting(in float3 reflectVec, in float3 tangent, in float3 bitangent, in float3 wsNormal, in float3 toCamera, in float3 diffColor, in float3 specColor, in float roughness, inout float3 reflectionCubeColor)
+    float3 ImageBasedLighting(in float3 reflectVec, in float3 wsNormal, in float3 toCamera, in float3 diffColor, in float3 specColor, in float roughness, inout float3 reflectionCubeColor)
     { 
         roughness = max(roughness, 0.08);
         reflectVec = GetSpecularDominantDir(wsNormal, reflectVec, roughness);
@@ -300,6 +73,5 @@
         const float3 environmentDiffuse = EnvBRDFApprox(diffColor, 1.0, ndv);
 
         return (hdrCube * environmentSpecular + hdrCubeD * environmentDiffuse) * brightness;
-        //return ImportanceSampling(reflectVec, tangent, bitangent, wsNormal, toCamera, diffColor, specColor, roughness, reflectionCubeColor);
     }
 #endif

+ 10 - 10
bin/CoreData/Shaders/HLSL/PBRLitSolid.hlsl

@@ -21,7 +21,7 @@ void VS(float4 iPos : POSITION,
     #if defined(LIGHTMAP) || defined(AO)
         float2 iTexCoord2 : TEXCOORD1,
     #endif
-    #if (defined(NORMALMAP)|| defined(IBL) || defined(TRAILFACECAM) || defined(TRAILBONE)) && !defined(BILLBOARD) && !defined(DIRBILLBOARD)
+    #if (defined(NORMALMAP) || defined(TRAILFACECAM) || defined(TRAILBONE)) && !defined(BILLBOARD) && !defined(DIRBILLBOARD)
         float4 iTangent : TANGENT,
     #endif
     #ifdef SKINNED
@@ -34,11 +34,11 @@ void VS(float4 iPos : POSITION,
     #if defined(BILLBOARD) || defined(DIRBILLBOARD)
         float2 iSize : TEXCOORD1,
     #endif
-    #if defined(NORMALMAP) || defined(IBL)
+    #ifndef NORMALMAP
+        out float2 oTexCoord : TEXCOORD0,
+    #else
         out float4 oTexCoord : TEXCOORD0,
         out float4 oTangent : TEXCOORD3,
-    #else
-        out float2 oTexCoord : TEXCOORD0,
     #endif
     out float3 oNormal : TEXCOORD1,
     out float4 oWorldPos : TEXCOORD2,
@@ -89,7 +89,7 @@ void VS(float4 iPos : POSITION,
         oColor = iColor;
     #endif
 
-    #if defined(NORMALMAP) || defined(IBL)
+    #if defined(NORMALMAP)
         const float4 tangent = GetWorldTangent(modelMatrix);
         const float3 bitangent = cross(tangent.xyz, oNormal) * tangent.w;
         oTexCoord = float4(GetTexCoord(iTexCoord), bitangent.xy);
@@ -140,11 +140,11 @@ void VS(float4 iPos : POSITION,
 }
 
 void PS(
-    #if defined(NORMALMAP) || defined(IBL)
+    #ifndef NORMALMAP
+        float2 iTexCoord : TEXCOORD0,
+    #else
         float4 iTexCoord : TEXCOORD0,
         float4 iTangent : TEXCOORD3,
-    #else
-        float2 iTexCoord : TEXCOORD0,
     #endif
     float3 iNormal : TEXCOORD1,
     float4 iWorldPos : TEXCOORD2,
@@ -226,7 +226,7 @@ void PS(
     diffColor.rgb = diffColor.rgb - diffColor.rgb * metalness; // Modulate down the diffuse
 
     // Get normal
-    #if defined(NORMALMAP) || defined(IBL)
+    #if defined(NORMALMAP)
         const float3 tangent = normalize(iTangent.xyz);
         const float3 bitangent = normalize(float3(iTexCoord.zw, iTangent.w));
         const float3x3 tbn = float3x3(tangent, bitangent, iNormal);
@@ -322,7 +322,7 @@ void PS(
         float3 cubeColor = iVertexLight.rgb;
 
         #ifdef IBL
-            const float3 iblColor = ImageBasedLighting(reflection, tangent, bitangent, normal, toCamera, diffColor, specColor, roughness, cubeColor);
+            const float3 iblColor = ImageBasedLighting(reflection, normal, toCamera, diffColor, specColor, roughness, cubeColor);
             const float gamma = 0;
             finalColor += iblColor;
         #endif

+ 1 - 1
bin/CoreData/Techniques/PBR/DiffNormalSpecEmissive.xml

@@ -1,4 +1,4 @@
-<technique vs="PBRLitSolid" ps="PBRLitSolid" psdefines="DIFFMAP NORMALMAP SPECMAP EMISSIVEMAP">
+<technique vs="PBRLitSolid" ps="PBRLitSolid" vsdefines="NORMALMAP" psdefines="DIFFMAP NORMALMAP SPECMAP EMISSIVEMAP">
     <pass name="base" />
     <pass name="light" depthtest="equal" depthwrite="false" blend="add" />>
     <pass name="material" psdefines="MATERIAL" depthtest="equal" depthwrite="false" />

+ 1 - 1
bin/CoreData/Techniques/PBR/DiffNormalSpecEmissiveAlpha.xml

@@ -1,4 +1,4 @@
-<technique vs="PBRLitSolid" ps="PBRLitSolid" psdefines="DIFFMAP SPECMAP EMISSIVEMAP NORMALMAP">
+<technique vs="PBRLitSolid" ps="PBRLitSolid" vsdefines="NORMALMAP" psdefines="DIFFMAP SPECMAP EMISSIVEMAP NORMALMAP">
     <pass name="alpha" depthwrite="false" blend="alpha" />
     <pass name="litalpha" depthwrite="false" blend="addalpha" />
     <pass name="shadow" vs="Shadow" ps="Shadow" psexcludes="PACKEDNORMAL" />

+ 1 - 1
bin/CoreData/Techniques/PBR/PBRDiffNormal.xml

@@ -1,4 +1,4 @@
-<technique vs="PBRLitSolid" ps="PBRLitSolid" vsdefines="IBL" psdefines="DIFFMAP NORMALMAP PBR IBL">
+<technique vs="PBRLitSolid" ps="PBRLitSolid" vsdefines="NORMALMAP IBL" psdefines="DIFFMAP NORMALMAP PBR IBL">
     <pass name="base" />
     <pass name="light" depthtest="equal" depthwrite="false" blend="add" />
     <pass name="material" psdefines="MATERIAL" depthtest="equal" depthwrite="false" />

+ 1 - 1
bin/CoreData/Techniques/PBR/PBRDiffNormalAlpha.xml

@@ -1,4 +1,4 @@
-<technique vs="PBRLitSolid" ps="PBRLitSolid" vsdefines="IBL" psdefines="DIFFMAP NORMALMAP PBR IBL">
+<technique vs="PBRLitSolid" ps="PBRLitSolid" vsdefines="NORMALMAP IBL" psdefines="DIFFMAP NORMALMAP PBR IBL">
     <pass name="alpha" depthwrite="false" blend="alpha" />
     <pass name="litalpha" depthwrite="false" blend="addalpha" />
     <pass name="shadow" vs="Shadow" ps="Shadow" psexcludes="PACKEDNORMAL" />

+ 1 - 1
bin/CoreData/Techniques/PBR/PBRDiffNormalEmissive.xml

@@ -1,4 +1,4 @@
-<technique vs="PBRLitSolid" ps="PBRLitSolid"  vsdefines="IBL" psdefines="DIFFMAP NORMALMAP EMISSIVEMAP PBR IBL">
+<technique vs="PBRLitSolid" ps="PBRLitSolid"  vsdefines="NORMALMAP IBL" psdefines="DIFFMAP NORMALMAP EMISSIVEMAP PBR IBL">
     <pass name="light" depthtest="equal" depthwrite="false" blend="add" />
     <pass name="material" psdefines="MATERIAL" depthtest="equal" depthwrite="false" />
     <pass name="deferred" psdefines="DEFERRED" blend="add" />

+ 1 - 1
bin/CoreData/Techniques/PBR/PBRDiffNormalEmissiveAlpha.xml

@@ -1,4 +1,4 @@
-<technique vs="PBRLitSolid" ps="PBRLitSolid"  vsdefines="IBL" psdefines="DIFFMAP NORMALMAP EMISSIVEMAP PBR IBL">
+<technique vs="PBRLitSolid" ps="PBRLitSolid"  vsdefines="NORMALMAP IBL" psdefines="DIFFMAP NORMALMAP EMISSIVEMAP PBR IBL">
     <pass name="alpha" depthwrite="false" blend="alpha" />
     <pass name="litalpha" depthwrite="false" blend="addalpha" />
     <pass name="shadow" vs="Shadow" ps="Shadow" psexcludes="PACKEDNORMAL" />

+ 1 - 1
bin/CoreData/Techniques/PBR/PBRMetallicRoughDiffNormalSpec.xml

@@ -1,4 +1,4 @@
-<technique vs="PBRLitSolid" ps="PBRLitSolid" vsdefines="IBL" psdefines="NORMALMAP DIFFMAP METALLIC ROUGHNESS PBR IBL">
+<technique vs="PBRLitSolid" ps="PBRLitSolid" vsdefines="NORMALMAP IBL" psdefines="NORMALMAP DIFFMAP METALLIC ROUGHNESS PBR IBL">
     <pass name="base" />
     <pass name="light" depthtest="equal" depthwrite="false" blend="add" />
     <pass name="material" psdefines="MATERIAL" depthtest="equal" depthwrite="false" />

+ 1 - 1
bin/CoreData/Techniques/PBR/PBRMetallicRoughDiffNormalSpecEmissive.xml

@@ -1,4 +1,4 @@
-<technique vs="PBRLitSolid" ps="PBRLitSolid" vsdefines="IBL" psdefines="DIFFMAP NORMALMAP EMISSIVEMAP METALLIC ROUGHNESS PBR IBL">
+<technique vs="PBRLitSolid" ps="PBRLitSolid" vsdefines="NORMALMAP IBL" psdefines="DIFFMAP NORMALMAP EMISSIVEMAP METALLIC ROUGHNESS PBR IBL">
     <pass name="base" />
     <pass name="light" depthtest="equal" depthwrite="false" blend="add" />
     <pass name="material" psdefines="MATERIAL" depthtest="equal" depthwrite="false" />

+ 1 - 1
bin/CoreData/Techniques/PBR/PBRMetallicRoughDiffNormalSpecEmissiveAlpha.xml

@@ -1,4 +1,4 @@
-<technique vs="PBRLitSolid" ps="PBRLitSolid" vsdefines="IBL" psdefines="DIFFMAP NORMALMAP EMISSIVEMAP PBR IBL METALLIC ROUGHNESS">
+<technique vs="PBRLitSolid" ps="PBRLitSolid" vsdefines="NORMALMAP IBL" psdefines="DIFFMAP NORMALMAP EMISSIVEMAP PBR IBL METALLIC ROUGHNESS">
     <pass name="alpha" depthwrite="false" blend="alpha" />
     <pass name="litalpha" depthwrite="false" blend="addalpha" />
     <pass name="shadow" vs="Shadow" ps="Shadow" psexcludes="PACKEDNORMAL" />