Implemented Shadow maps (still needs improvement) #314
|
@ -7,6 +7,7 @@ struct DirectionalLightStruct
|
|||
uint cullingMask;
|
||||
vec4 diffuseColor;
|
||||
mat4 pvMatrix;
|
||||
uint shadowData;
|
||||
};
|
||||
|
||||
struct AmbientLightStruct
|
||||
|
@ -65,6 +66,8 @@ void main()
|
|||
|
||||
vec3 fragColor = vec3 (0.0f);
|
||||
|
||||
vec4 shadowMapColor = vec4 (1.0f);
|
||||
|
||||
for (int i = 0; i < lightCounts.directionalLights; ++i)
|
||||
{
|
||||
if ((lightLayer & DirLightData.dLightData[i].cullingMask) != 0)
|
||||
|
@ -77,6 +80,13 @@ void main()
|
|||
|
||||
// Calculate the fragment color
|
||||
fragColor += DirLightData.dLightData[i].diffuseColor.rgb * diffuseStrength.rrr * pixelDiffuse;
|
||||
|
||||
if ((DirLightData.dLightData[i].shadowData & uint(1)) == 1)
|
||||
{
|
||||
// calculate shadow map here
|
||||
vec2 texCoord = vec2 (gl_GlobalInvocationID.xy) / vec2 (imageSize (targetImage));
|
||||
shadowMapColor = texture (shadowMaps[0], texCoord).xxxx;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -95,6 +105,8 @@ void main()
|
|||
|
||||
// store result into result image
|
||||
imageStore(targetImage, ivec2(gl_GlobalInvocationID.xy), vec4(fragColor.rgb, 1.0f));
|
||||
|
||||
imageStore(targetImage, ivec2(gl_GlobalInvocationID.xy), shadowMapColor);
|
||||
//imageStore(targetImage, ivec2(gl_GlobalInvocationID.xy), vec4(ssaoVal.rrr, 1.0f));
|
||||
|
||||
}
|
Binary file not shown.
|
@ -198,6 +198,7 @@ namespace SHADE
|
|||
vk::PhysicalDeviceDescriptorIndexingFeatures descIndexingFeature{};
|
||||
descIndexingFeature.descriptorBindingVariableDescriptorCount = true;
|
||||
descIndexingFeature.shaderSampledImageArrayNonUniformIndexing = true;
|
||||
descIndexingFeature.descriptorBindingPartiallyBound = true;
|
||||
descIndexingFeature.runtimeDescriptorArray = true;
|
||||
|
||||
// Prepare to create the device
|
||||
|
|
|
@ -265,12 +265,6 @@ namespace SHADE
|
|||
// Add another pass to blur SSAO
|
||||
Handle<SHRenderGraphNodeCompute> ssaoBlurPass = gBufferNode->AddNodeCompute("SSAO Blur Step", ssaoBlurShader, { "SSAO", "SSAO Blur" });
|
||||
|
||||
/*-----------------------------------------------------------------------*/
|
||||
/* SHADOW MAP PASS */
|
||||
/*-----------------------------------------------------------------------*/
|
||||
// Shadow map pass will have no resources bound at first. Lighting system will add resources to the node.
|
||||
// It will initially also not have any subpasses since they will be added for each light that casts shadows.
|
||||
//auto shadowMapPassNode = renderGraph->AddNode(SHGraphicsConstants::RenderGraphNodeNames::SHADOW_MAP_PASS.data(), {}, {});
|
||||
|
||||
/*-----------------------------------------------------------------------*/
|
||||
/* DEFERRED COMPOSITE NODE */
|
||||
|
|
|
@ -60,7 +60,15 @@ namespace SHADE
|
|||
// write view projection matrix if renderer is available
|
||||
auto lightRenderer = lightComp->GetRenderer();
|
||||
if (lightRenderer)
|
||||
{
|
||||
lightPtr->pvMatrix = lightRenderer->GetCPUCameraData().viewProjectionMatrix;
|
||||
|
||||
// Boolean to cast shadows in first 8 bits (1 byte)
|
||||
lightPtr->shadowData = lightData.castShadows;
|
||||
|
||||
// Next 24 bits for shadow map index
|
||||
lightPtr->shadowData |= (lightData.shadowMapIndex << 8);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case SH_LIGHT_TYPE::POINT:
|
||||
|
|
|
@ -44,6 +44,9 @@ namespace SHADE
|
|||
//! Matrix for world to projection from light's perspective
|
||||
SHMatrix pvMatrix;
|
||||
|
||||
//! Represents boolean for casting shadows in first byte and shadow map index in the other 3.
|
||||
uint32_t shadowData;
|
||||
|
||||
};
|
||||
|
||||
// Represents how the data will be interpreted in GPU. we want to copy to a container of these before passing to GPU.
|
||||
|
@ -62,8 +65,6 @@ namespace SHADE
|
|||
//! when a fragment is being evaluated, the shader will use the fragment's
|
||||
//! layer value to AND with the light's. If result is 1, do lighting calculations.
|
||||
uint32_t cullingMask;
|
||||
|
||||
|
||||
};
|
||||
|
||||
class SH_API SHLightingSubSystem
|
||||
|
|
|
@ -205,7 +205,7 @@ namespace SHADE
|
|||
newBinding.DescriptorCount = SHVkDescriptorSetLayout::Binding::VARIABLE_DESCRIPTOR_UPPER_BOUND;
|
||||
|
||||
// Set the flags for variable bindings
|
||||
newBinding.flags = vk::DescriptorBindingFlagBits::eVariableDescriptorCount;
|
||||
newBinding.flags = vk::DescriptorBindingFlagBits::eVariableDescriptorCount | vk::DescriptorBindingFlagBits::ePartiallyBound;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue