Skip to content

Commit

Permalink
bugfix: attempt resolve broken rendering visibility buffer
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Pollind <mpollind@gmail.com>
  • Loading branch information
pollend committed Dec 22, 2023
1 parent 64f52f2 commit f88136c
Show file tree
Hide file tree
Showing 12 changed files with 502 additions and 124 deletions.
7 changes: 3 additions & 4 deletions HPL2/include/graphics/RendererDeferred2.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,6 @@ namespace hpl {
uint2 m_size = uint2(0, 0);
std::array<SharedRenderTarget, ForgeRenderer::SwapChainLength> m_outputBuffer;
std::array<SharedRenderTarget, ForgeRenderer::SwapChainLength> m_depthBuffer;
std::array<SharedRenderTarget, ForgeRenderer::SwapChainLength> m_parallaxBuffer;
std::array<SharedRenderTarget, ForgeRenderer::SwapChainLength> m_albedoBuffer; // this is used for the adding decals to albedo

std::array<SharedRenderTarget, ForgeRenderer::SwapChainLength> m_testBuffer; //encodes the parallax
Expand Down Expand Up @@ -172,7 +171,7 @@ namespace hpl {

private:


void setIndirectDrawArg(const ForgeRenderer::Frame& frame, uint32_t drawArgIndex, uint32_t slot, DrawPacket& packet);

enum MaterialSetType {
Expand All @@ -186,11 +185,11 @@ namespace hpl {

struct SharedMaterial {
public:
SharedMaterial();
void* m_material = nullptr;
uint32_t m_version = 0;
folly::small_vector<MaterialSet, 2> m_sets;
std::array<uint32_t, eMaterialTexture_LastEnum> m_textureHandles;

MaterialSet& resolveSet(MaterialSetType set);
};
SharedMaterial& resolveSharedMaterial(cMaterial* material);
Expand Down Expand Up @@ -247,7 +246,7 @@ namespace hpl {
SharedShader m_lightClusterShader;
SharedShader m_clearLightClusterShader;
SharedPipeline m_lightClusterPipeline;
SharedPipeline m_clearClusterPipeline;
SharedPipeline m_clearClusterPipeline;
std::array<SharedBuffer, ForgeRenderer::SwapChainLength> m_lightClustersBuffer;
std::array<SharedBuffer, ForgeRenderer::SwapChainLength> m_lightClusterCountBuffer;
std::array<SharedBuffer, ForgeRenderer::SwapChainLength> m_lightBuffer;
Expand Down
4 changes: 2 additions & 2 deletions HPL2/include/graphics/SceneResource.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace hpl::resource {
static constexpr uint32_t MaterailSamplerNonAntistropyCount = static_cast<uint32_t>(eTextureWrap_LastEnum) * static_cast<uint32_t>(eTextureFilter_LastEnum);
uint32_t textureFilterNonAnistropyIdx(eTextureWrap wrap, eTextureFilter filter);

static constexpr uint32_t MaxSceneTextureCount = 100000;
static constexpr uint32_t MaxSceneTextureCount = 4096;

static constexpr uint32_t MaterialIdBit = 0;
static constexpr uint32_t MaterialIndexBit = 8;
Expand Down Expand Up @@ -114,7 +114,7 @@ namespace hpl::resource {
mat4 uvMat;
};


struct SceneDecal {
uint32_t diffuseTextureIndex;
uint32_t sampleIndex;
Expand Down
6 changes: 3 additions & 3 deletions HPL2/resource/ShaderList.fsl
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
#include "solid_z_shadow.frag.fsl"
#end

#vert solid_z_shadow.vert
#include "solid_z_shadow.vert.fsl"
#end
//#vert solid_z_shadow.vert
// #include "solid_z_shadow.vert.fsl"
//#end

#frag solid_z.frag
#define SEARCH_SAMPLE_COUNT 4
Expand Down
2 changes: 1 addition & 1 deletion HPL2/resource/decal_shade.vert.fsl
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ STRUCT(VSOutput)
#endif
};

VSOutput VS_MAIN(VSInput In)
VSOutput VS_MAIN(VSInput In, SV_InstanceID(uint) InstanceID)
{
INIT_MAIN;

Expand Down
2 changes: 1 addition & 1 deletion HPL2/resource/scene_defs.h.fsl
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@

#define SCENE_SAMPLER(wrap, filter) ((wrap * SCENE_TEXTURE_FILTER_COUNT) + filter)

#define SCENE_MAX_TEXTURE_COUNT (100000)
#define SCENE_MAX_TEXTURE_COUNT 4096
#define SCENE_MAX_FILTER_COUNT (SCENE_TEXTURE_FILTER_COUNT * SCENE_TEXTURE_WRAP_COUNT)
#define SCENE_FILTER_SWITCH_CASE case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7: case 8:

Expand Down
47 changes: 23 additions & 24 deletions HPL2/resource/scene_resource.h.fsl
Original file line number Diff line number Diff line change
Expand Up @@ -18,34 +18,33 @@ CBUFFER(sceneInfo, UPDATE_FREQ_PER_FRAME, b2, binding = 0) {
};

RES(Buffer(UniformObject), sceneObjects, UPDATE_FREQ_PER_FRAME, t0, binding = 1);
RES(Buffer(Light), lights, UPDATE_FREQ_PER_FRAME, t1, binding = 14);
RES(Buffer(Particle), particles, UPDATE_FREQ_PER_FRAME, t2, binding = 15);
RES(Buffer(Decal), decals, UPDATE_FREQ_PER_FRAME, t3, binding = 16);
RES(Buffer(Light), lights, UPDATE_FREQ_PER_FRAME, t1, binding = 2);
RES(Buffer(Particle), particles, UPDATE_FREQ_PER_FRAME, t2, binding = 3);
RES(Buffer(Decal), decals, UPDATE_FREQ_PER_FRAME, t3, binding = 4);

// opaque geometry set
RES(ByteBuffer, vtxOpaqueIndex, UPDATE_FREQ_NONE, t4, binding = 3);
RES(ByteBuffer, vtxOpaquePosition, UPDATE_FREQ_NONE, t5, binding = 4);
RES(ByteBuffer, vtxOpaqueTangnet, UPDATE_FREQ_NONE, t6, binding = 5);
RES(ByteBuffer, vtxOpaqueNormal, UPDATE_FREQ_NONE, t7, binding = 6);
RES(ByteBuffer, vtxOpaqueUv, UPDATE_FREQ_NONE, t8, binding = 7);
RES(ByteBuffer, vtxOpaqueColor, UPDATE_FREQ_NONE, t9, binding = 8);
RES(ByteBuffer, vtxOpaqueIndex, UPDATE_FREQ_NONE, t4, binding = 5);
RES(ByteBuffer, vtxOpaquePosition, UPDATE_FREQ_NONE, t5, binding = 6);
RES(ByteBuffer, vtxOpaqueTangnet, UPDATE_FREQ_NONE, t6, binding = 7);
RES(ByteBuffer, vtxOpaqueNormal, UPDATE_FREQ_NONE, t7, binding = 8);
RES(ByteBuffer, vtxOpaqueUv, UPDATE_FREQ_NONE, t8, binding = 9);
RES(ByteBuffer, vtxOpaqueColor, UPDATE_FREQ_NONE, t9, binding = 10);

RES(Buffer(DiffuseMaterial), sceneDiffuseMat, UPDATE_FREQ_NONE, t10, binding = 9);
RES(Buffer(DiffuseMaterial), sceneDiffuseMat, UPDATE_FREQ_NONE, t10, binding = 11);

RES(SamplerState, nearEdgeClampSampler, UPDATE_FREQ_NONE, s0, binding = 10);
RES(SamplerState, nearPointWrapSampler, UPDATE_FREQ_NONE, s1, binding = 11);
RES(SamplerState, nearEdgeClampSampler, UPDATE_FREQ_NONE, s0, binding = 12);
RES(SamplerState, nearPointWrapSampler, UPDATE_FREQ_NONE, s1, binding = 13);

RES(Tex2D(float4), visibilityTexture, UPDATE_FREQ_PER_FRAME, t11, binding = 12);
RES(Tex2D(float4), albedoTexture, UPDATE_FREQ_PER_FRAME, t12, binding = 12);
RES(Tex2D(float4), parallaxTexture, UPDATE_FREQ_PER_FRAME, t13, binding = 12);
RES(Tex2D(float4), visibilityTexture, UPDATE_FREQ_PER_FRAME, t11, binding = 14);
RES(Tex2D(float4), albedoTexture, UPDATE_FREQ_PER_FRAME, t12, binding = 15);

RES(Tex2D(float4), dissolveTexture, UPDATE_FREQ_NONE, t14, binding = 13);
RES(Tex2D(float4), dissolveTexture, UPDATE_FREQ_NONE, t14, binding = 17);

RES(ByteBuffer, lightClustersCount, UPDATE_FREQ_PER_FRAME, t15, binding = 16);
RES(ByteBuffer, lightClusters, UPDATE_FREQ_PER_FRAME, t16, binding = 18);
RES(ByteBuffer, lightClustersCount, UPDATE_FREQ_PER_FRAME, t15, binding = 18);
RES(ByteBuffer, lightClusters, UPDATE_FREQ_PER_FRAME, t16, binding = 19);

RES(SamplerState, sceneFilters[SCENE_MAX_FILTER_COUNT], UPDATE_FREQ_NONE, s2, binding = 20);
RES(Tex2D(float4), sceneTextures[SCENE_MAX_TEXTURE_COUNT], UPDATE_FREQ_PER_FRAME, t17, binding = 20 + SCENE_MAX_FILTER_COUNT);
RES(Tex2D(float4), sceneTextures[SCENE_MAX_TEXTURE_COUNT], UPDATE_FREQ_PER_FRAME, t17, binding = 21 + SCENE_MAX_FILTER_COUNT);

#define SCENE_OBJECT_ID_BIT 19 // 13 bits for ObjectID
#define SCENE_PRIM_ID_BIT 0 // 19 bits for PrimitiveID
Expand All @@ -61,7 +60,7 @@ RES(Tex2D(float4), sceneTextures[SCENE_MAX_TEXTURE_COUNT], UPDATE_FREQ_PER_FRAM
#define SCENE_VIZ_OBJECT_ID(id) (((id) & SCENE_OBJECT_ID_MASK) >> SCENE_OBJECT_ID_BIT)
#define SCENE_VIZ_PRIM_ID(id) (((id) & SCENE_PRIM_ID_MASK) >> SCENE_PRIM_ID_BIT)

INLINE bool SampleSceneTextureProjFloat4(uint textureIdx,SamplerState sh, float4 projectUV, inout float4 value) {
bool SampleSceneTextureProjFloat4(uint textureIdx,SamplerState sh, float4 projectUV, inout float4 value) {
if(textureIdx < SCENE_MAX_TEXTURE_COUNT) {
BeginNonUniformResourceIndex(textureIdx, SCENE_MAX_TEXTURE_COUNT);
value = SampleTex2DProj(Get(sceneTextures)[textureIdx], sh, projectUV);
Expand All @@ -71,19 +70,19 @@ INLINE bool SampleSceneTextureProjFloat4(uint textureIdx,SamplerState sh, float4
return false;
}

INLINE bool SampleSceneTextureFloat4(uint textureIdx,SamplerState sh, float2 uv, inout float4 value) {
bool SampleSceneTextureFloat4(uint textureIdx,SamplerState sh, float2 uv, inout float4 value) {
if(textureIdx < SCENE_MAX_TEXTURE_COUNT) {
BeginNonUniformResourceIndex(textureIdx, SCENE_MAX_TEXTURE_COUNT);
value = SampleTex2D(Get(sceneTextures)[textureIdx], sh, uv);
EndNonUniformResourceIndex();
EndNonUniformResourceIndex();
return true;
}
return false;
}
INLINE bool SampleSceneTextureGradFloat4(uint textureIdx, SamplerState sh, float2 uv, float2 texCoordDX, float2 texCoordDY, inout float4 value) {
bool SampleSceneTextureGradFloat4(uint textureIdx, SamplerState sh, float2 uv, float2 texCoordDX, float2 texCoordDY, inout float4 value) {
if(textureIdx < SCENE_MAX_TEXTURE_COUNT) {
BeginNonUniformResourceIndex(textureIdx, SCENE_MAX_TEXTURE_COUNT);
value = SampleGradTex2D(Get(sceneTextures)[textureIdx], sh, uv, texCoordDX, texCoordDY);
value = SampleGradTex2D(Get(sceneTextures)[textureIdx], sh, uv, texCoordDX, texCoordDY);
EndNonUniformResourceIndex();
return true;
}
Expand Down
4 changes: 1 addition & 3 deletions HPL2/resource/visibility_emit_shade_pass.frag.fsl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ STRUCT(PsIn)
STRUCT(PsOut)
{
DATA(float4, albedoColor , SV_Target0);
DATA(float2, parallax, SV_Target1);
};

PsOut PS_MAIN(PsIn In)
Expand Down Expand Up @@ -104,7 +103,7 @@ PsOut PS_MAIN(PsIn In)
float2 texCoord = results.interp;
PsOut Out;
if(isTextureIndexValid(diffuseMat.heightTextureIndex)) {
Out.parallax = ParallaxAdvance(
texCoord += ParallaxAdvance(
results.interp,
0.0,
32.0,
Expand All @@ -116,7 +115,6 @@ PsOut PS_MAIN(PsIn In)
diffuseMat.heightTextureIndex,
Get(sceneFilters)[diffuseMat.samplerIndex],
(diffuseMat.materialConfig & MATERIAL_IS_HEIGHT_SINGLE_CHANNEL) > 0);
texCoord += Out.parallax;
}
float4 diffuseColor = float4(0,0,0,0);
float3 shadedColor = f3(0.0f);
Expand Down
5 changes: 3 additions & 2 deletions HPL2/resource/visibility_shade_pass.frag.fsl
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ STRUCT(PsOut)
PsOut PS_MAIN(PsIn In)
{
INIT_MAIN;
PsOut Out;

const float4 visRaw = LoadTex2D(Get(visibilityTexture), Get(nearEdgeClampSampler), uint2(In.position.xy), 0);
// Unpack float4 render target data into uint to extract data
Expand Down Expand Up @@ -118,7 +119,7 @@ PsOut PS_MAIN(PsIn In)
(diffuseMat.materialConfig & MATERIAL_IS_HEIGHT_SINGLE_CHANNEL) > 0);
}
float4 normalSample = float4(0,0,0,0);
float3 shadedColor = f3(0.0f);
float3 shadedColor = float3(0.0f);

if (SampleSceneTextureGradFloat4(diffuseMat.normalTextureIndex, Get(sceneFilters)[diffuseMat.samplerIndex], texCoord, texCoordDX, texCoordDY, normalSample)) {
normalSample -= 0.5;
Expand Down Expand Up @@ -182,8 +183,8 @@ PsOut PS_MAIN(PsIn In)
}
}

PsOut Out;
Out.outColor = float4(shadedColor, 0.0f);
//Out.outColor = float4(diffuseColor.rgb, 0.0f);
Out.test = float4(clusterCoords.x,clusterCoords.y,slice, lightClusterCount);
RETURN(Out);

Expand Down
Loading

0 comments on commit f88136c

Please sign in to comment.