Fixed a buy with view space lighting calculations
This commit is contained in:
parent
39b5ac0774
commit
647182241e
|
@ -51,10 +51,10 @@ void main()
|
|||
vec3 pixelDiffuse = imageLoad (albedo, globalThread).rgb;
|
||||
|
||||
// Get position of fragment in world space
|
||||
vec3 positionWorld = imageLoad (positions, globalThread).rgb;
|
||||
vec3 positionView = imageLoad (positions, globalThread).rgb;
|
||||
|
||||
// normal of fragment
|
||||
vec3 normalWorld = imageLoad(normals, globalThread).rgb;
|
||||
vec3 normalView = imageLoad(normals, globalThread).rgb;
|
||||
|
||||
vec3 fragColor = vec3 (0.0f);
|
||||
|
||||
|
@ -64,7 +64,7 @@ void main()
|
|||
vec3 dLightNormalized = normalize (DirLightData.dLightData[i].direction);
|
||||
|
||||
// Get diffuse strength
|
||||
float diffuseStrength = max (0, dot (dLightNormalized, normalWorld));
|
||||
float diffuseStrength = max (0, dot (dLightNormalized, normalView));
|
||||
|
||||
// Calculate the fragment color
|
||||
fragColor += DirLightData.dLightData[i].diffuseColor.rgb * diffuseStrength.rrr * pixelDiffuse;
|
||||
|
|
Binary file not shown.
|
@ -70,7 +70,17 @@ namespace SHADE
|
|||
*/
|
||||
/***************************************************************************/
|
||||
static constexpr uint32_t RENDERGRAPH_RESOURCE = 4;
|
||||
|
||||
/***************************************************************************/
|
||||
/*!
|
||||
\brief
|
||||
DescriptorSet Index for render graph node compute resources. For data
|
||||
that we wish to pass to compute shaders in the render graph, this is
|
||||
the set to use. Unlike the sets from 1 to 3, this set index does not have
|
||||
hard coded bindings and is NOT part of the layouts included in the global
|
||||
data.
|
||||
*/
|
||||
/***************************************************************************/
|
||||
static constexpr uint32_t RENDERGRAPH_NODE_COMPUTE_RESOURCE = 5;
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -42,7 +42,8 @@ namespace SHADE
|
|||
{
|
||||
SHDirectionalLightData* lightPtr = reinterpret_cast<SHDirectionalLightData*>(address);
|
||||
|
||||
SHVec4 transformedDir = viewMat * SHVec4(lightData.direction[0], lightData.direction[1], lightData.direction[2], 0.0f);
|
||||
// #NoteToSelf: NEED TO TRANSPOSE HERE BECAUSE MULTIPLICATION IS ROW MAJOR.
|
||||
SHVec4 transformedDir = SHMatrix::Transpose(viewMat) * SHVec4(lightData.direction[0], lightData.direction[1], lightData.direction[2], 0.0f);
|
||||
|
||||
lightPtr->cullingMask = lightData.cullingMask;
|
||||
lightPtr->direction = SHVec3 (transformedDir.x, transformedDir.y, transformedDir.z);
|
||||
|
|
|
@ -42,16 +42,12 @@ namespace SHADE
|
|||
|
||||
//Get the descriptor set layouts required to allocate. We only want the ones for allocate because
|
||||
//global descriptors are already bound in the main system.
|
||||
auto const& layouts = computePipeline->GetPipelineLayout()->GetDescriptorSetLayoutsAllocate();
|
||||
|
||||
//Variable counts for the descriptor sets (all should be 1).
|
||||
std::vector<uint32_t> variableCounts{ static_cast<uint32_t>(layouts.size()) };
|
||||
std::fill(variableCounts.begin(), variableCounts.end(), 0);
|
||||
auto const& layouts = computePipeline->GetPipelineLayout()->GetDescriptorSetLayoutsPipeline()[SHGraphicsConstants::DescriptorSetIndex::RENDERGRAPH_RESOURCE];
|
||||
|
||||
// Allocate descriptor sets to hold the images for reading (STORAGE_IMAGE)
|
||||
for (uint32_t i = 0; i < SHGraphicsConstants::NUM_FRAME_BUFFERS; ++i)
|
||||
{
|
||||
descSetGroups[i] = graphStorage->descriptorPool->Allocate(layouts, variableCounts);
|
||||
graphResourceDescSets[i] = graphStorage->descriptorPool->Allocate({layouts}, { 1 });
|
||||
}
|
||||
|
||||
HandleResize();
|
||||
|
@ -63,7 +59,7 @@ namespace SHADE
|
|||
cmdBuffer->BindPipeline(computePipeline);
|
||||
|
||||
// bind descriptor sets
|
||||
cmdBuffer->BindDescriptorSet(descSetGroups[frameIndex], SH_PIPELINE_TYPE::COMPUTE, SHGraphicsConstants::DescriptorSetIndex::RENDERGRAPH_RESOURCE, {});
|
||||
cmdBuffer->BindDescriptorSet(graphResourceDescSets[frameIndex], SH_PIPELINE_TYPE::COMPUTE, SHGraphicsConstants::DescriptorSetIndex::RENDERGRAPH_RESOURCE, {});
|
||||
|
||||
// dispatch compute
|
||||
cmdBuffer->ComputeDispatch(groupSizeX, groupSizeY, 1);
|
||||
|
@ -89,8 +85,8 @@ namespace SHADE
|
|||
uint32_t imageIndex = (resources[i]->resourceTypeFlags & static_cast<uint32_t>(SH_ATT_DESC_TYPE_FLAGS::COLOR_PRESENT)) ? frameIndex : 0;
|
||||
|
||||
SHVkDescriptorSetGroup::viewSamplerLayout vsl = std::make_tuple(resources[i]->GetImageView(imageIndex), Handle<SHVkSampler>{}, vk::ImageLayout::eGeneral);
|
||||
descSetGroups[frameIndex]->ModifyWriteDescImage(SHGraphicsConstants::DescriptorSetIndex::RENDERGRAPH_RESOURCE, binding.BindPoint, { &vsl, 1 });
|
||||
descSetGroups[frameIndex]->UpdateDescriptorSetImages(SHGraphicsConstants::DescriptorSetIndex::RENDERGRAPH_RESOURCE, binding.BindPoint);
|
||||
graphResourceDescSets[frameIndex]->ModifyWriteDescImage(SHGraphicsConstants::DescriptorSetIndex::RENDERGRAPH_RESOURCE, binding.BindPoint, { &vsl, 1 });
|
||||
graphResourceDescSets[frameIndex]->UpdateDescriptorSetImages(SHGraphicsConstants::DescriptorSetIndex::RENDERGRAPH_RESOURCE, binding.BindPoint);
|
||||
++i;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,12 +19,15 @@ namespace SHADE
|
|||
class SHVkShaderModule;
|
||||
class SHVkCommandBuffer;
|
||||
|
||||
|
||||
class SHRenderGraphNodeCompute
|
||||
{
|
||||
private:
|
||||
static constexpr uint32_t workGroupSizeX = 16;
|
||||
static constexpr uint32_t workGroupSizeY = 16;
|
||||
|
||||
using ExternalDescSetBindCommands = std::function<void(Handle<SHVkCommandBuffer>)>;
|
||||
|
||||
//! To run the dispatch command
|
||||
Handle<SHVkPipeline> computePipeline;
|
||||
|
||||
|
@ -32,7 +35,12 @@ namespace SHADE
|
|||
Handle<SHVkPipelineLayout> pipelineLayout;
|
||||
|
||||
//! Descriptor set group to hold the images for reading (STORAGE_IMAGE)
|
||||
std::array<Handle<SHVkDescriptorSetGroup>, SHGraphicsConstants::NUM_FRAME_BUFFERS> descSetGroups;
|
||||
std::array<Handle<SHVkDescriptorSetGroup>, SHGraphicsConstants::NUM_FRAME_BUFFERS> graphResourceDescSets;
|
||||
|
||||
//! Sometimes we want to bind descriptor sets for a compute resource (buffers, images, etc). This container
|
||||
//! helps store functions that call those bind functions. The reason why we dont just have a handle to descriptor
|
||||
//! sets here is because we dont know how we want to bind the sets (different set each frame, dynamic offsets, etc).
|
||||
std::vector<ExternalDescSetBindCommands> externalDescriptorSetBindCommands;
|
||||
|
||||
//! vector of resources needed by the subpass compute
|
||||
std::vector<Handle<SHRenderGraphResource>> resources;
|
||||
|
|
Loading…
Reference in New Issue