Graphics: Send shadow map res to shader
This commit is contained in:
parent
3623f4ccc4
commit
f580ba523d
|
|
@ -23,7 +23,7 @@ namespace Nz
|
|||
std::size_t parameter1;
|
||||
std::size_t parameter2;
|
||||
std::size_t parameter3;
|
||||
std::size_t shadowMappingFlag;
|
||||
std::size_t shadowMapSize;
|
||||
std::size_t viewProjMatrix;
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -170,7 +170,7 @@ namespace Nz
|
|||
0.0f, 0.0f, 1.0f, 0.0f,
|
||||
0.5f, 0.5f, 0.0f, 1.0f);
|
||||
|
||||
Matrix4f projection = Matrix4f::Perspective(m_outerAngle * 2.f, 1.f, 1.f, m_radius);
|
||||
Matrix4f projection = Matrix4f::Perspective(m_outerAngle * 2.f, 1.f, 0.01f, m_radius);
|
||||
Matrix4f view = Matrix4f::TransformInverse(m_position, m_rotation);
|
||||
|
||||
m_viewProjMatrix = view * projection * biasMatrix;
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ namespace Nz
|
|||
AccessByOffset<Vector4f&>(data, lightOffset.lightMemberOffsets.color) = Vector4f(m_color.r, m_color.g, m_color.b, m_color.a);
|
||||
AccessByOffset<Vector2f&>(data, lightOffset.lightMemberOffsets.factor) = Vector2f(m_ambientFactor, m_diffuseFactor);
|
||||
AccessByOffset<Vector4f&>(data, lightOffset.lightMemberOffsets.parameter1) = Vector4f(m_direction.x, m_direction.y, m_direction.z, 0.f);
|
||||
AccessByOffset<UInt8&>(data, lightOffset.lightMemberOffsets.shadowMappingFlag) = 0;
|
||||
AccessByOffset<Vector2f&>(data, lightOffset.lightMemberOffsets.shadowMapSize) = Vector2f(-1.f, -1.f);
|
||||
}
|
||||
|
||||
void DirectionalLight::UpdateTransform(const Vector3f& /*position*/, const Quaternionf& rotation, const Vector3f& /*scale*/)
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ namespace Nz
|
|||
AccessByOffset<Vector4f&>(data, lightOffset.lightMemberOffsets.color) = Vector4f(m_color.r, m_color.g, m_color.b, m_color.a);
|
||||
AccessByOffset<Vector2f&>(data, lightOffset.lightMemberOffsets.factor) = Vector2f(m_ambientFactor, m_diffuseFactor);
|
||||
AccessByOffset<Vector4f&>(data, lightOffset.lightMemberOffsets.parameter1) = Vector4f(m_position.x, m_position.y, m_position.z, m_invRadius);
|
||||
AccessByOffset<UInt8&>(data, lightOffset.lightMemberOffsets.shadowMappingFlag) = 0;
|
||||
AccessByOffset<Vector2f&>(data, lightOffset.lightMemberOffsets.shadowMapSize) = Vector2f(-1.f, -1.f);
|
||||
}
|
||||
|
||||
void PointLight::UpdateTransform(const Vector3f& position, const Quaternionf& /*rotation*/, const Vector3f& /*scale*/)
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ namespace Nz
|
|||
lightData.lightMemberOffsets.parameter1 = lightStruct.AddField(nzsl::StructFieldType::Float4);
|
||||
lightData.lightMemberOffsets.parameter2 = lightStruct.AddField(nzsl::StructFieldType::Float4);
|
||||
lightData.lightMemberOffsets.parameter3 = lightStruct.AddField(nzsl::StructFieldType::Float4);
|
||||
lightData.lightMemberOffsets.shadowMappingFlag = lightStruct.AddField(nzsl::StructFieldType::Bool1);
|
||||
lightData.lightMemberOffsets.shadowMapSize = lightStruct.AddField(nzsl::StructFieldType::Float2);
|
||||
lightData.lightMemberOffsets.viewProjMatrix = lightStruct.AddMatrix(nzsl::StructFieldType::Float1, 4, 4, true);
|
||||
|
||||
lightData.lightSize = lightStruct.GetAlignedSize();
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ struct Light
|
|||
parameter1: vec4[f32],
|
||||
parameter2: vec4[f32],
|
||||
parameter3: vec4[f32],
|
||||
hasShadowMapping: u32,
|
||||
invShadowMapSize: vec2[f32],
|
||||
viewProjMatrix: mat4[f32]
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -234,27 +234,18 @@ fn main(input: VertToFrag) -> FragOut
|
|||
specFactor = pow(specFactor, settings.Shininess);
|
||||
|
||||
let shadowFactor = 0.0;
|
||||
if (true) //< TODO: HasShadowMapping
|
||||
if (light.invShadowMapSize.x > 0.0)
|
||||
{
|
||||
let shadowTexSize = 1.0 / 512.0; //< FIXME
|
||||
|
||||
let offsetArray = array[vec2[f32], 9](
|
||||
vec2[f32](-1.0, -1.0),
|
||||
vec2[f32](-1.0, 0.0),
|
||||
vec2[f32](-1.0, 1.0),
|
||||
vec2[f32](0.0, -1.0),
|
||||
vec2[f32](0.0, 0.0),
|
||||
vec2[f32](0.0, 1.0),
|
||||
vec2[f32](1.0, -1.0),
|
||||
vec2[f32](1.0, 0.0),
|
||||
vec2[f32](1.0, 1.0)
|
||||
);
|
||||
|
||||
for offset in offsetArray
|
||||
let shadowCoords = input.lightProjPos[i].xyz / input.lightProjPos[i].w;
|
||||
[unroll]
|
||||
for x in -1 -> 2
|
||||
{
|
||||
let shadowCoords = input.lightProjPos[i].xyz / input.lightProjPos[i].w;
|
||||
shadowCoords.xy += offset * shadowTexSize;
|
||||
shadowFactor += shadowMaps2D[i].SampleDepthComp(shadowCoords.xy, shadowCoords.z).r;
|
||||
[unroll]
|
||||
for y in -1 -> 2
|
||||
{
|
||||
let coords = shadowCoords.xy + vec2[f32](f32(x), f32(y)) * light.invShadowMapSize;
|
||||
shadowFactor += shadowMaps2D[i].SampleDepthComp(coords, shadowCoords.z).r;
|
||||
}
|
||||
}
|
||||
shadowFactor /= 9.0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ namespace Nz
|
|||
AccessByOffset<Vector4f&>(data, lightOffset.lightMemberOffsets.parameter1) = Vector4f(m_position.x, m_position.y, m_position.z, m_invRadius);
|
||||
AccessByOffset<Vector4f&>(data, lightOffset.lightMemberOffsets.parameter2) = Vector4f(m_direction.x, m_direction.y, m_direction.z, 0.f);
|
||||
AccessByOffset<Vector4f&>(data, lightOffset.lightMemberOffsets.parameter3) = Vector4f(m_innerAngleCos, m_outerAngleCos, 0.f, 0.f);
|
||||
AccessByOffset<UInt8&>(data, lightOffset.lightMemberOffsets.shadowMappingFlag) = 0;
|
||||
AccessByOffset<Vector2f&>(data, lightOffset.lightMemberOffsets.shadowMapSize) = (IsShadowCaster()) ? Vector2f(1.f / GetShadowMapSize()) : Vector2f(-1.f, -1.f);
|
||||
AccessByOffset<Matrix4f&>(data, lightOffset.lightMemberOffsets.viewProjMatrix) = m_viewProjMatrix;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue