Reducing startup time significantly
This commit is contained in:
@@ -4,7 +4,7 @@ import MaterialParameter;
|
||||
|
||||
interface ILightEnv
|
||||
{
|
||||
float3 illuminate<B:IBRDF>(MaterialParameter input, B brdf);
|
||||
float3 illuminate<B:IBRDF>(LightingParameter input, B brdf);
|
||||
};
|
||||
|
||||
struct DirectionalLight : ILightEnv
|
||||
@@ -12,10 +12,10 @@ struct DirectionalLight : ILightEnv
|
||||
float4 color;
|
||||
float4 direction;
|
||||
|
||||
float3 illuminate<B:IBRDF>(MaterialParameter input, B brdf)
|
||||
float3 illuminate<B:IBRDF>(LightingParameter params, B brdf)
|
||||
{
|
||||
float3 lightDir_TS = normalize(direction.xyz);
|
||||
return brdf.evaluate(input.viewDir_TS, -lightDir_TS, color.xyz);
|
||||
float3 lightDir_TS = mul(params.tbn, normalize(direction.xyz));
|
||||
return brdf.evaluate(params.viewDir_TS, -lightDir_TS, color.xyz);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -24,41 +24,37 @@ struct PointLight : ILightEnv
|
||||
float4 position_WS;
|
||||
float4 colorRange;
|
||||
|
||||
float3 illuminate<B:IBRDF>(MaterialParameter input, B brdf)
|
||||
float3 illuminate<B:IBRDF>(LightingParameter params, B brdf)
|
||||
{
|
||||
float3 position_TS = position_WS.xyz;
|
||||
float3 lightDir_TS = position_TS - input.position_TS;
|
||||
float3 position_TS = mul(params.tbn, position_WS.xyz);
|
||||
float3 lightDir_TS = position_TS - params.position_TS;
|
||||
float d = length(lightDir_TS);
|
||||
float illuminance = max(1 - d / colorRange.w, 0);
|
||||
return illuminance * brdf.evaluate(input.viewDir_TS, normalize(lightDir_TS), colorRange.xyz);
|
||||
return illuminance * brdf.evaluate(params.viewDir_TS, normalize(lightDir_TS), colorRange.xyz);
|
||||
}
|
||||
|
||||
bool insidePlane(Plane plane)
|
||||
{
|
||||
return dot(plane.n, getViewPos().xyz) - plane.d < -colorRange.w;
|
||||
return true;//dot(plane.n, getViewPos().xyz) - plane.d < -colorRange.w;
|
||||
}
|
||||
|
||||
bool insideFrustum(Frustum frustum, float zNear, float zFar)
|
||||
{
|
||||
bool result = true;
|
||||
|
||||
if(getViewPos().z - colorRange.w > zNear || getViewPos().z + colorRange.w < zFar)
|
||||
{
|
||||
//result = false;
|
||||
}
|
||||
for(int i = 0; i < 4 && result; ++i)
|
||||
{
|
||||
if(insidePlane(frustum.sides[i]))
|
||||
{
|
||||
//result = false;
|
||||
}
|
||||
}
|
||||
//if(getViewPos().z - colorRange.w > zNear || getViewPos().z + colorRange.w < zFar)
|
||||
//{
|
||||
// //result = false;
|
||||
//}
|
||||
//for(int i = 0; i < 4 && result; ++i)
|
||||
//{
|
||||
// if(insidePlane(frustum.sides[i]))
|
||||
// {
|
||||
// //result = false;
|
||||
// }
|
||||
//}
|
||||
return result;
|
||||
}
|
||||
float3 getViewPos()
|
||||
{
|
||||
return mul(pViewParams.viewMatrix, position_WS).xyz;
|
||||
}
|
||||
};
|
||||
|
||||
struct LightEnv
|
||||
|
||||
Reference in New Issue
Block a user