blinn phong shading works
This commit is contained in:
@@ -23,14 +23,14 @@ struct BlinnPhong : IBRDF
|
|||||||
sheen = 1;
|
sheen = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
float3 evaluate(float3x3 tbn, float3 viewDir_WS, float3 lightDir_WS, float3 lightColor)
|
float3 evaluate(float3x3 tbn, float3 viewDir_TS, float3 lightDir_TS, float3 lightColor)
|
||||||
{
|
{
|
||||||
float3 normal_WS = mul(normal, tbn);
|
float3 normal_TS = normalize(normal);
|
||||||
float diffuse = max(dot(normal_WS, lightDir_WS), 0);
|
float diffuse = max(dot(normal_TS, lightDir_TS), 0);
|
||||||
float3 h = lightDir_WS + viewDir_WS;
|
float3 h = normalize(lightDir_TS + viewDir_TS);
|
||||||
float specular = dot(normal_WS, h);
|
float specular = saturate(dot(normal_TS, h));
|
||||||
|
|
||||||
return (viewDir_WS + float3(1, 1, 1)) / 2;//baseColor * (diffuse + specular) * lightColor;
|
return baseColor * (diffuse + specular) * lightColor;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -14,7 +14,8 @@ struct DirectionalLight : ILightEnv
|
|||||||
|
|
||||||
float3 illuminate<B:IBRDF>(LightingParameter params, B brdf)
|
float3 illuminate<B:IBRDF>(LightingParameter params, B brdf)
|
||||||
{
|
{
|
||||||
return brdf.evaluate(params.tbn, params.viewDir_WS, -normalize(direction.xyz), color.xyz);
|
float3 lightDir_TS = mul(params.tbn, direction.xyz);
|
||||||
|
return brdf.evaluate(params.tbn, params.viewDir_TS, -normalize(lightDir_TS), color.xyz);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -26,9 +27,10 @@ struct PointLight : ILightEnv
|
|||||||
float3 illuminate<B:IBRDF>(LightingParameter params, B brdf)
|
float3 illuminate<B:IBRDF>(LightingParameter params, B brdf)
|
||||||
{
|
{
|
||||||
float3 lightDir_WS = position_WS.xyz - params.position_WS;
|
float3 lightDir_WS = position_WS.xyz - params.position_WS;
|
||||||
float d = length(lightDir_WS);
|
float3 lightDir_TS = mul(params.tbn, lightDir_WS);
|
||||||
|
float d = length(lightDir_TS);
|
||||||
float illuminance = max(1 - d / colorRange.w, 0);
|
float illuminance = max(1 - d / colorRange.w, 0);
|
||||||
return brdf.evaluate(params.tbn, params.viewDir_WS, normalize(lightDir_WS), colorRange.xyz);
|
return brdf.evaluate(params.tbn, params.viewDir_TS, normalize(lightDir_TS), colorRange.xyz);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool insidePlane(Plane plane)
|
bool insidePlane(Plane plane)
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ struct LightingParameter
|
|||||||
{
|
{
|
||||||
float3x3 tbn;
|
float3x3 tbn;
|
||||||
float3 position_WS;
|
float3 position_WS;
|
||||||
float3 viewDir_WS;
|
float3 viewDir_TS;
|
||||||
};
|
};
|
||||||
|
|
||||||
// data passed to fragment shader
|
// data passed to fragment shader
|
||||||
@@ -39,7 +39,7 @@ struct FragmentParameter
|
|||||||
LightingParameter result;
|
LightingParameter result;
|
||||||
result.tbn = float3x3(normalize(tangent_WS), normalize(biTangent_WS), normalize(normal_WS));
|
result.tbn = float3x3(normalize(tangent_WS), normalize(biTangent_WS), normalize(normal_WS));
|
||||||
result.position_WS = position_WS;
|
result.position_WS = position_WS;
|
||||||
result.viewDir_WS = normalize(viewDir_WS);
|
result.viewDir_TS = normalize(mul(result.tbn, viewDir_WS));
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ struct Camera
|
|||||||
}
|
}
|
||||||
Vector getCameraPosition() const
|
Vector getCameraPosition() const
|
||||||
{
|
{
|
||||||
return -viewMatrix[3];
|
return cameraPos;
|
||||||
}
|
}
|
||||||
void mouseMove(float deltaX, float deltaY);
|
void mouseMove(float deltaX, float deltaY);
|
||||||
void mouseScroll(float x);
|
void mouseScroll(float x);
|
||||||
|
|||||||
Reference in New Issue
Block a user