改善CSM分层
parent
3bf1444092
commit
ddff01d880
|
@ -43,7 +43,7 @@ public:
|
|||
float Zoom;
|
||||
float Ratio;
|
||||
float NearPlane = 10.f;
|
||||
float FarPlane = 10000.f;
|
||||
float FarPlane = 5000.f;
|
||||
|
||||
// constructor with vectors
|
||||
Camera(QVector3D position = QVector3D(0.0f, 0.0f, 0.0f), QVector3D up = QVector3D(0.0f, 1.0f, 0.0f), float yaw = YAW, float pitch = PITCH);
|
||||
|
|
|
@ -3,8 +3,18 @@
|
|||
|
||||
Light::Light(Camera* camera)
|
||||
: camera(camera)
|
||||
, shadowCascadeLevels{ camera->FarPlane / 50.0f, camera->FarPlane / 25.0f, camera->FarPlane / 10.0f, camera->FarPlane / 2.0f }
|
||||
//, shadowCascadeLevels{ camera->FarPlane / 25.0f, camera->FarPlane / 12.0f, camera->FarPlane / 6.0f, camera->FarPlane / 3.0f }
|
||||
{
|
||||
const float levelCount = 5;
|
||||
const float lambda = 0.5;
|
||||
for (int i = 1; i < levelCount; i++)
|
||||
{
|
||||
shadowCascadeLevels.push_back(
|
||||
lambda * camera->NearPlane * pow(camera->FarPlane / camera->NearPlane, i / levelCount)
|
||||
+ (1 - lambda) * (camera->NearPlane + i / levelCount * (camera->FarPlane - camera->NearPlane)));
|
||||
//qDebug() << shadowCascadeLevels[i-1];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -84,13 +84,13 @@ float Calculate_Avg_Dblockreceiver(vec2 projCoords , int AvgTextureSize)
|
|||
return result/(AvgTextureSize*AvgTextureSize*2*2);
|
||||
}
|
||||
|
||||
float ShadowCalculation(vec3 fragPosWorldSpace, vec3 normal)
|
||||
float ShadowCalculation(vec3 fragPosWorldSpace, vec3 normal, out int layer)
|
||||
{
|
||||
// select cascade layer
|
||||
vec4 fragPosViewSpace = view * vec4(fragPosWorldSpace, 1.0);
|
||||
float depthValue = abs(fragPosViewSpace.z);
|
||||
|
||||
int layer = -1;
|
||||
layer = -1;
|
||||
for (int i = 0; i < shadowCascadeCount; ++i)
|
||||
{
|
||||
if (depthValue < shadowCascadePlaneDistances[i])
|
||||
|
@ -225,11 +225,14 @@ void main()
|
|||
|
||||
//vec4 FragPosLightSpace = lightSpaceMatrix * vec4(WorldPos, 1.0);
|
||||
//float bias = 0.08 * max(0.05 * (1.0 - dot(N, L)), 0.005);
|
||||
float shadow = ShadowCalculation(WorldPos, N);
|
||||
int debugLayer;
|
||||
float shadow = ShadowCalculation(WorldPos, N, debugLayer);
|
||||
|
||||
//vec3 color = ambient + Lo;
|
||||
//vec3 color = indirect*1;
|
||||
vec3 color = ambient + (1.0 - shadow) * Lo;
|
||||
//color*=mix(mix(vec3(1,0,0), vec3(0,1,0), float(debugLayer)/shadowCascadeCount/0.5),
|
||||
//mix(vec3(0,1,0), vec3(0,0,1), float(debugLayer)/(shadowCascadeCount)/0.5-1), float(debugLayer)/(shadowCascadeCount));
|
||||
//vec3 color = (1.0 - shadow) * Lo;
|
||||
//vec3 color = (1.0 - shadow) * Lo + indirect*10;
|
||||
color = color / (color + vec3(1.0));
|
||||
|
|
Loading…
Reference in New Issue