Normal mapping doesnt work
This commit is contained in:
@@ -24,9 +24,6 @@ struct CullingParams
|
||||
};
|
||||
|
||||
ParameterBlock<CullingParams> pCullingParams;
|
||||
// Debug
|
||||
//Texture2D lightCountHeatMap;
|
||||
//RWTexture2D<float4> debugTexture;
|
||||
|
||||
groupshared uint uMinDepth;
|
||||
groupshared uint uMaxDepth;
|
||||
|
||||
+22
-19
@@ -2,7 +2,7 @@ import Common;
|
||||
|
||||
interface IBRDF
|
||||
{
|
||||
float3 evaluate(float3x3 tbn, float3 viewDir_WS, float3 lightDir_WS, float3 lightColor);
|
||||
float3 evaluate(float3x3 tbn, float3 viewDir_WS, float3 lightDir_WS, float3 normal_WS, float3 lightColor);
|
||||
float3 evaluateAmbient();
|
||||
};
|
||||
|
||||
@@ -19,14 +19,15 @@ struct Phong : IBRDF
|
||||
normal = float3(0, 0, 1);
|
||||
}
|
||||
|
||||
float3 evaluate(float3x3 tbn, float3 viewDir_TS, float3 lightDir_TS, float3 lightColor)
|
||||
float3 evaluate(float3x3 tbn, float3 viewDir_WS, float3 lightDir_WS, float3 n, float3 lightColor)
|
||||
{
|
||||
float3 normal_TS = normalize(normal);
|
||||
float3 nDotL = dot(normal_TS, lightDir_TS);
|
||||
float3 r = 2 * (nDotL) * normal_TS - lightDir_TS;
|
||||
float rDotV = dot(r, viewDir_TS);
|
||||
float3 normal_TS = normal;
|
||||
float3 normal_WS = n;//normalize(mul(tbn, normal_TS));
|
||||
float3 nDotL = dot(normal_WS, lightDir_WS);
|
||||
float3 r = 2 * (nDotL) * normal_WS - lightDir_WS;
|
||||
float rDotV = dot(r, viewDir_WS);
|
||||
|
||||
return baseColor * max(nDotL, 0.0) * lightColor + specular * pow(max(rDotV, 0.0), shininess);
|
||||
return lightColor * (baseColor * max(nDotL, 0.0));// + specular * pow(max(rDotV, 0.0), max(shininess, 1)));
|
||||
}
|
||||
|
||||
float3 evaluateAmbient()
|
||||
@@ -48,11 +49,12 @@ struct BlinnPhong : IBRDF
|
||||
normal = float3(0, 0, 1);
|
||||
}
|
||||
|
||||
float3 evaluate(float3x3 tbn, float3 viewDir_TS, float3 lightDir_TS, float3 lightColor)
|
||||
float3 evaluate(float3x3 tbn, float3 viewDir_WS, float3 lightDir_WS, float3 normal_WS, float3 lightColor)
|
||||
{
|
||||
float3 normal_TS = normalize(normal);
|
||||
float diffuse = max(dot(normal_TS, lightDir_TS), 0);
|
||||
float3 h = normalize(lightDir_TS + viewDir_TS);
|
||||
//float3 normal_WS = normalize(mul(tbn, normal_TS));
|
||||
float diffuse = max(dot(normal_WS, lightDir_WS), 0);
|
||||
float3 h = normalize(lightDir_WS + viewDir_WS);
|
||||
float specular = pow(saturate(dot(normal_TS, h)), shininess);
|
||||
|
||||
return (baseColor * diffuse * lightColor) + (specularColor * specular);
|
||||
@@ -74,10 +76,11 @@ struct CelShading : IBRDF
|
||||
normal = float3(0, 0, 1);
|
||||
}
|
||||
|
||||
float3 evaluate(float3x3 tbn, float3 viewDir_TS, float3 lightDir_TS, float3 lightColor)
|
||||
float3 evaluate(float3x3 tbn, float3 viewDir_WS, float3 lightDir_WS, float3 n, float3 lightColor)
|
||||
{
|
||||
float3 normal_TS = normalize(normal);
|
||||
float nDotL = dot(normal_TS, lightDir_TS);
|
||||
float3 normal_WS = normalize(mul(tbn, normal_TS));
|
||||
float nDotL = dot(normal_WS, lightDir_WS);
|
||||
float diffuse = max(nDotL, 0);
|
||||
|
||||
float3 darkenedBase = baseColor * 0.8;
|
||||
@@ -145,21 +148,21 @@ struct CookTorrance : IBRDF
|
||||
return F0 + (1.0 - F0) * pow(clamp(1.0 - cosTheta, 0.0, 1.0), 5.0);
|
||||
}
|
||||
|
||||
float3 evaluate(float3x3 tbn, float3 viewDir_TS, float3 lightDir_TS, float3 lightColor)
|
||||
float3 evaluate(float3x3 tbn, float3 viewDir_WS, float3 lightDir_WS, float3 normal_WS, float3 lightColor)
|
||||
{
|
||||
float3 n = normalize(normal);
|
||||
float3 h = normalize(lightDir_TS + viewDir_TS);
|
||||
float3 n = normal_WS;//normalize(mul(tbn, normal));
|
||||
float3 h = normalize(lightDir_WS + viewDir_WS);
|
||||
|
||||
float3 F0 = float3(0.04);
|
||||
F0 = lerp(F0, baseColor, metallic);
|
||||
|
||||
float3 F = FresnelSchlick(max(dot(h, viewDir_TS), 0.0), F0);
|
||||
float3 F = FresnelSchlick(max(dot(h, viewDir_WS), 0.0), F0);
|
||||
|
||||
float NDF = TrowbridgeReitzGGX(n, h);
|
||||
float G = Smith(n, viewDir_TS, lightDir_TS);
|
||||
float G = Smith(n, viewDir_WS, lightDir_WS);
|
||||
|
||||
float3 num = NDF * G * F;
|
||||
float denom = 4.0 * max(dot(n, viewDir_TS), 0.0) * max(dot(n, lightDir_TS), 0.0) + 0.000001;
|
||||
float denom = 4.0 * max(dot(n, viewDir_WS), 0.0) * max(dot(n, lightDir_WS), 0.0) + 0.000001;
|
||||
float3 specular = num / denom;
|
||||
|
||||
float3 k_s = F;
|
||||
@@ -167,7 +170,7 @@ struct CookTorrance : IBRDF
|
||||
|
||||
k_d *= 1.0 - metallic;
|
||||
|
||||
float nDotL = max(dot(n, lightDir_TS), 0.0);
|
||||
float nDotL = max(dot(n, lightDir_WS), 0.0);
|
||||
|
||||
float3 result = (k_d * baseColor / PI + specular) * nDotL * lightColor;
|
||||
return result * ambientOcclusion;
|
||||
|
||||
@@ -14,8 +14,7 @@ struct DirectionalLight : ILightEnv
|
||||
|
||||
float3 illuminate<B:IBRDF>(LightingParameter params, B brdf)
|
||||
{
|
||||
float3 lightDir_TS = mul(params.tbn, direction.xyz);
|
||||
return brdf.evaluate(params.tbn, params.viewDir_TS, -normalize(lightDir_TS), color.xyz);
|
||||
return brdf.evaluate(params.tbn, params.viewDir_WS, -normalize(direction.xyz), params.normal_WS, color.xyz);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -26,11 +25,10 @@ struct PointLight : ILightEnv
|
||||
|
||||
float3 illuminate<B:IBRDF>(LightingParameter params, B brdf)
|
||||
{
|
||||
float3 lightDir_WS = params.position_WS - position_WS.xyz;
|
||||
float3 lightDir_TS = mul(params.tbn, lightDir_WS);
|
||||
float d = length(lightDir_TS);
|
||||
float3 lightDir_WS = position_WS.xyz - params.position_WS;
|
||||
float d = length(lightDir_WS);
|
||||
float illuminance = max(1 - d / colorRange.w, 0);
|
||||
return illuminance * brdf.evaluate(params.tbn, params.viewDir_TS, -normalize(lightDir_TS), colorRange.xyz);
|
||||
return illuminance * brdf.evaluate(params.tbn, params.viewDir_WS, normalize(lightDir_WS), normalize(params.normal_WS), colorRange.xyz);
|
||||
}
|
||||
|
||||
bool insidePlane(Plane plane, float3 position)
|
||||
|
||||
@@ -10,16 +10,17 @@ struct MaterialParameter
|
||||
// data used by light environment
|
||||
struct LightingParameter
|
||||
{
|
||||
float3x3 tbn;
|
||||
float3x3 tbn;
|
||||
float3 normal_WS;
|
||||
float3 position_WS;
|
||||
float3 viewDir_TS;
|
||||
float3 viewDir_WS;
|
||||
};
|
||||
|
||||
// data passed to fragment shader
|
||||
struct FragmentParameter
|
||||
{
|
||||
float4 position_CS : SV_Position;
|
||||
float3 viewDir_WS : POSITION1;
|
||||
float4 position_CS : SV_Position;
|
||||
float3 cameraPos_WS: POSITION0;
|
||||
float3 normal_WS : NORMAL0;
|
||||
float3 tangent_WS : TANGENT0;
|
||||
float3 biTangent_WS : TANGENT1;
|
||||
@@ -43,7 +44,8 @@ struct FragmentParameter
|
||||
LightingParameter result;
|
||||
result.tbn = float3x3(normalize(tangent_WS), normalize(biTangent_WS), normalize(normal_WS));
|
||||
result.position_WS = position_WS;
|
||||
result.viewDir_TS = normalize(mul(result.tbn, viewDir_WS));
|
||||
result.viewDir_WS = normalize(cameraPos_WS - position_WS);
|
||||
result.normal_WS = normal_WS;
|
||||
return result;
|
||||
}
|
||||
};
|
||||
@@ -64,16 +66,17 @@ struct VertexAttributes
|
||||
float4 worldPos = mul(transformMatrix, modelPos);
|
||||
float4 viewPos = mul(pViewParams.viewMatrix, worldPos);
|
||||
float4 clipPos = mul(pViewParams.projectionMatrix, viewPos);
|
||||
float3 tangent_WS = normalize(mul(transformMatrix, float4(tangent_MS, 0.0)).xyz);
|
||||
float3 biTangent_WS = normalize(mul(transformMatrix, float4(biTangent_MS, 0.0)).xyz);
|
||||
float3 normal_WS = normalize(mul(transformMatrix, float4(normal_MS, 0.0)).xyz);
|
||||
float3x3 normalMatrix = float3x3(transformMatrix);
|
||||
float3 T = mul(normalMatrix, tangent_MS);
|
||||
float3 N = mul(normalMatrix, normal_MS);
|
||||
float3 B = mul(normalMatrix, biTangent_MS);
|
||||
FragmentParameter result;
|
||||
result.viewDir_WS = pViewParams.cameraPos_WS.xyz - worldPos.xyz;
|
||||
result.normal_WS = normal_WS;
|
||||
result.tangent_WS = tangent_WS;
|
||||
result.biTangent_WS = biTangent_WS;
|
||||
result.position_WS = worldPos.xyz;
|
||||
result.position_CS = clipPos;
|
||||
result.cameraPos_WS = pViewParams.cameraPos_WS.xyz;
|
||||
result.normal_WS = N;
|
||||
result.tangent_WS = T;
|
||||
result.biTangent_WS = B;
|
||||
result.position_WS = worldPos.xyz;
|
||||
result.vertexColor = vertexColor;
|
||||
result.meshletId = meshletId;
|
||||
for(uint i = 0; i < MAX_TEXCOORDS; ++i)
|
||||
|
||||
Reference in New Issue
Block a user