diff --git a/HPL2/include/graphics/RendererDeferred.h b/HPL2/include/graphics/RendererDeferred.h index a122e9f83..ecb88f6f6 100644 --- a/HPL2/include/graphics/RendererDeferred.h +++ b/HPL2/include/graphics/RendererDeferred.h @@ -289,6 +289,7 @@ namespace hpl { SharedRootSignature m_lightClusterRootSignature; std::array m_lightDescriptorPerFrameSet; + SharedDescriptorSet m_lightDescriptorConstSet; SharedShader m_lightClusterShader; SharedShader m_clearLightClusterShader; SharedPipeline m_lightClusterPipeline; diff --git a/HPL2/include/graphics/SceneResource.h b/HPL2/include/graphics/SceneResource.h index c2cd21c11..016cbce03 100644 --- a/HPL2/include/graphics/SceneResource.h +++ b/HPL2/include/graphics/SceneResource.h @@ -147,7 +147,7 @@ namespace hpl::resource { uint m_alphaTextureIndex; uint m_specularTextureIndex; uint m_heightTextureIndex; - uint m_illuminiationTextureIndex; + uint m_illuminationTextureIndex; uint m_dissolveAlphaTextureIndex; uint m_materialConfig; float m_heightMapScale; @@ -162,7 +162,7 @@ namespace hpl::resource { uint32_t m_alphaTextureIndex; uint32_t m_specularTextureIndex; uint32_t m_heightTextureIndex; - uint32_t m_illuminiationTextureIndex; + uint32_t m_illuminationTextureIndex; uint32_t m_dissolveAlphaTextureIndex; uint32_t m_cubeMapTextureIndex; uint32_t m_cubeMapAlphaTextureIndex; diff --git a/HPL2/resource/decal_shade.frag.fsl b/HPL2/resource/decal_shade.frag.fsl index 4769f1aca..d68f47706 100644 --- a/HPL2/resource/decal_shade.frag.fsl +++ b/HPL2/resource/decal_shade.frag.fsl @@ -21,8 +21,11 @@ float4 PS_MAIN(PsIn In, SV_PrimitiveID(uint) primitiveID) const Decal decal = Get(decals)[Get(indirectDrawId)]; #endif - float4 diffuseColor; - SampleSceneTextureFloat4(decal.diffuseTextureIndex, Get(sceneSampler), In.uv, diffuseColor); + float4 diffuseColor = float4(0,0,0,0); + const uint diffuseTextureIndex = decal.diffuseTextureIndex; + BeginNonUniformResourceIndex(diffuseTextureIndex); + diffuseColor = SampleTex2D(Get(sceneTextures)[diffuseTextureIndex], Get(sceneSampler), In.uv); + EndNonUniformResourceIndex(); if(diffuseColor.w < 0.01 ) { discard; } diff --git a/HPL2/resource/depth_shade.frag.fsl b/HPL2/resource/depth_shade.frag.fsl index 8cdb1bfa6..581804be7 100644 --- a/HPL2/resource/depth_shade.frag.fsl +++ b/HPL2/resource/depth_shade.frag.fsl @@ -25,12 +25,11 @@ float4 PS_MAIN(PsIn In, SV_PrimitiveID(uint) primitiveID) float diffuseAlpha = 1.0; float4 value; - if(SampleSceneTextureFloat4(material.alphaTextureIndex,Get(sceneSampler), In.uv, value)) { - if((material.config & MATERIAL_IS_ALPHA_SINGLE_CHANNEL) > 0) { - diffuseAlpha = value.r; - } else { - diffuseAlpha = value.a; - } + const uint alphaTextureIndex = material.alphaTextureIndex; + if(isTextureIndexValid(alphaTextureIndex)) { + BeginNonUniformResourceIndex(alphaTextureIndex); + diffuseAlpha = ((material.config & MATERIAL_IS_ALPHA_SINGLE_CHANNEL) > 0) ? SampleTex2D(Get(sceneTextures)[alphaTextureIndex], Get(sceneSampler), In.uv.xy).r : SampleTex2D(Get(sceneTextures)[alphaTextureIndex], Get(sceneSampler), In.uv.xy).a; + EndNonUniformResourceIndex(); } if(diffuseAlpha < 0.5) { diff --git a/HPL2/resource/particle_shade.frag.fsl b/HPL2/resource/particle_shade.frag.fsl index 4c525fde8..ef1d2f266 100644 --- a/HPL2/resource/particle_shade.frag.fsl +++ b/HPL2/resource/particle_shade.frag.fsl @@ -25,8 +25,10 @@ float4 PS_MAIN(PsIn In) #endif float4 finalColor = float4(0.0, 0.0 ,0.0, 1.0); - SampleSceneTextureFloat4(particle.diffuseTextureIndex, Get(sceneSampler), In.uv, finalColor); - finalColor *= In.color; + const uint diffuseTextureIndex = particle.diffuseTextureIndex; + BeginNonUniformResourceIndex(diffuseTextureIndex); + finalColor = SampleTex2D(Get(sceneTextures)[diffuseTextureIndex], Get(sceneSampler), In.uv) * In.color; + EndNonUniformResourceIndex(); float finalAlpha = particle.sceneAlpha; if ((Get(worldInfo).worldFlags & WORLD_FLAG_IS_FOG_ENABLED) > 0) { diff --git a/HPL2/resource/scene_defs.h.fsl b/HPL2/resource/scene_defs.h.fsl index 6e207aee1..ddfc066ee 100644 --- a/HPL2/resource/scene_defs.h.fsl +++ b/HPL2/resource/scene_defs.h.fsl @@ -18,7 +18,7 @@ #define LIGHT_CLUSTER_DATA_POS(il, ix, iy) ( LIGHT_CLUSTER_COUNT_POS(ix, iy)*LIGHT_CLUSTER_COUNT + (il) ) #define PRIMARY_VIEWPORT_INDEX 0 -#define SCENE_MAX_REFLECTION_COUNT 10000 +#define SCENE_MAX_REFLECTION_COUNT 4 #define SCENE_MAX_TEXTURE_COUNT 10000 #define SCENE_MAX_TEXTURE_CUBE_COUNT 5000 @@ -28,7 +28,7 @@ STRUCT(TranslucentMaterial) { DATA(uint, alphaTextureIndex, None); DATA(uint, specularTextureIndex, None); DATA(uint, heightTextureIndex, None); - DATA(uint, illuminiationTextureIndex, None); + DATA(uint, illuminationTextureIndex, None); DATA(uint, dissolveAlphaTextureIndex, None); DATA(uint, cubeMapTextureIndex, None); DATA(uint, cubeMapAlphaTextureIndex, None); @@ -67,7 +67,7 @@ STRUCT(DiffuseMaterial) { DATA(uint, alphaTextureIndex, None); DATA(uint, specularTextureIndex, None); DATA(uint, heightTextureIndex, None); - DATA(uint, illuminiationTextureIndex, None); + DATA(uint, illuminationTextureIndex, None); DATA(uint, dissolveAlphaTextureIndex, None); DATA(uint, config, None); diff --git a/HPL2/resource/scene_light_cluster.comp.fsl b/HPL2/resource/scene_light_cluster.comp.fsl index 3fe4470c2..40f74c47d 100644 --- a/HPL2/resource/scene_light_cluster.comp.fsl +++ b/HPL2/resource/scene_light_cluster.comp.fsl @@ -9,7 +9,7 @@ void CS_MAIN(SV_GroupThreadID(uint3) threadInGroupId, SV_GroupID(uint3) groupId) const float invClusterWidth = 1.0f / float(LIGHT_CLUSTER_WIDTH); const float invClusterHeight = 1.0f / float(LIGHT_CLUSTER_HEIGHT); - ViewportInfo viewInfo = Get(viewports)[PRIMARY_VIEWPORT_INDEX]; + ViewportInfo viewInfo = Get(viewport); float2 screenDim = viewInfo.rect.zw; //Near and far values of the cluster in view space diff --git a/HPL2/resource/scene_light_cluster_resource.h.fsl b/HPL2/resource/scene_light_cluster_resource.h.fsl index bc544dc43..effbdd917 100644 --- a/HPL2/resource/scene_light_cluster_resource.h.fsl +++ b/HPL2/resource/scene_light_cluster_resource.h.fsl @@ -1,11 +1,10 @@ #include "scene_defs.h.fsl" -CBUFFER(sceneInfo, UPDATE_FREQ_PER_FRAME, b0, binding = 0) { - DATA(WorldInfo, worldInfo, None); - DATA(ViewportInfo, viewports[64], None); +CBUFFER(uniformBlock_rootcbv, UPDATE_FREQ_NONE, b2, binding = 1) { + DATA(ViewportInfo, viewport, None); }; -RES(Buffer(Light), lights, UPDATE_FREQ_PER_FRAME, t0, binding = 1); -RES(RWBuffer(atomic_uint), lightClustersCount, UPDATE_FREQ_PER_FRAME, u0, binding = 2); -RES(RWBuffer(atomic_uint), lightClusters, UPDATE_FREQ_PER_FRAME, u1, binding = 3); +RES(Buffer(Light), lights, UPDATE_FREQ_PER_FRAME, t0, binding = 2); +RES(RWBuffer(atomic_uint), lightClustersCount, UPDATE_FREQ_PER_FRAME, u0, binding = 3); +RES(RWBuffer(atomic_uint), lightClusters, UPDATE_FREQ_PER_FRAME, u1, binding = 4); diff --git a/HPL2/resource/scene_resource.h.fsl b/HPL2/resource/scene_resource.h.fsl index 971b3e178..1758da807 100644 --- a/HPL2/resource/scene_resource.h.fsl +++ b/HPL2/resource/scene_resource.h.fsl @@ -15,47 +15,47 @@ RES(SamplerState, nearEdgeClampSampler, UPDATE_FREQ_NONE, s0, binding = 0); RES(SamplerState, nearPointWrapSampler, UPDATE_FREQ_NONE, s1, binding = 1); RES(SamplerState, linearBorderSampler, UPDATE_FREQ_NONE, s2, binding = 2); -RES(SamplerComparisonState, shadowCmpSampler, UPDATE_FREQ_NONE, s3, binding = 2); -RES(SamplerState, sceneSampler, UPDATE_FREQ_NONE, s4, binding = 3); +RES(SamplerComparisonState, shadowCmpSampler, UPDATE_FREQ_NONE, s3, binding = 3); +RES(SamplerState, sceneSampler, UPDATE_FREQ_NONE, s4, binding = 4); -CBUFFER(sceneInfo, UPDATE_FREQ_PER_FRAME, b1, binding = 4) { +CBUFFER(sceneInfo, UPDATE_FREQ_PER_FRAME, b1, binding = 5) { DATA(WorldInfo, worldInfo, None); }; -CBUFFER(uniformBlock_rootcbv, UPDATE_FREQ_NONE, b2, binding = 5) { +CBUFFER(uniformBlock_rootcbv, UPDATE_FREQ_NONE, b2, binding = 6) { DATA(ViewportInfo, viewport, None); }; -RES(Buffer(UniformObject), sceneObjects, UPDATE_FREQ_PER_FRAME, t0, binding = 5); -RES(Buffer(Light), lights, UPDATE_FREQ_PER_FRAME, t1, binding = 6); -RES(Buffer(Particle), particles, UPDATE_FREQ_PER_FRAME, t2, binding = 7); -RES(Buffer(Decal), decals, UPDATE_FREQ_PER_FRAME, t3, binding = 8); +RES(Buffer(UniformObject), sceneObjects, UPDATE_FREQ_PER_FRAME, t0, binding = 7); +RES(Buffer(Light), lights, UPDATE_FREQ_PER_FRAME, t1, binding = 8); +RES(Buffer(Particle), particles, UPDATE_FREQ_PER_FRAME, t2, binding = 9); +RES(Buffer(Decal), decals, UPDATE_FREQ_PER_FRAME, t3, binding = 10); // opaque geometry set -RES(ByteBuffer, vtxOpaqueIndex, UPDATE_FREQ_NONE, t4, binding = 9); -RES(ByteBuffer, vtxOpaquePosition, UPDATE_FREQ_NONE, t5, binding = 10); -RES(ByteBuffer, vtxOpaqueTangnet, UPDATE_FREQ_NONE, t6, binding = 11); -RES(ByteBuffer, vtxOpaqueNormal, UPDATE_FREQ_NONE, t7, binding = 12); -RES(ByteBuffer, vtxOpaqueUv, UPDATE_FREQ_NONE, t8, binding = 13); -RES(ByteBuffer, vtxOpaqueColor, UPDATE_FREQ_NONE, t9, binding = 14); +RES(ByteBuffer, vtxOpaqueIndex, UPDATE_FREQ_NONE, t4, binding = 11); +RES(ByteBuffer, vtxOpaquePosition, UPDATE_FREQ_NONE, t5, binding = 12); +RES(ByteBuffer, vtxOpaqueTangnet, UPDATE_FREQ_NONE, t6, binding = 13); +RES(ByteBuffer, vtxOpaqueNormal, UPDATE_FREQ_NONE, t7, binding = 14); +RES(ByteBuffer, vtxOpaqueUv, UPDATE_FREQ_NONE, t8, binding = 15); +RES(ByteBuffer, vtxOpaqueColor, UPDATE_FREQ_NONE, t9, binding = 16); -RES(Buffer(DiffuseMaterial), sceneDiffuseMat, UPDATE_FREQ_NONE, t10, binding = 15); -RES(Buffer(TranslucentMaterial), sceneTranslucentMat, UPDATE_FREQ_NONE, t11, binding = 16); -RES(Buffer(WaterMaterial), sceneWaterMat, UPDATE_FREQ_NONE, t12, binding = 17); +RES(Buffer(DiffuseMaterial), sceneDiffuseMat, UPDATE_FREQ_NONE, t10, binding = 17); +RES(Buffer(TranslucentMaterial), sceneTranslucentMat, UPDATE_FREQ_NONE, t11, binding = 18); +RES(Buffer(WaterMaterial), sceneWaterMat, UPDATE_FREQ_NONE, t12, binding = 19); -RES(Tex2D(float4), shadowTexture, UPDATE_FREQ_NONE, t13, binding = 17); -RES(Tex2D(float4), visibilityTexture, UPDATE_FREQ_PER_FRAME, t14, binding = 18); -RES(Tex2D(float4), albedoTexture, UPDATE_FREQ_PER_FRAME, t15, binding = 19); -RES(Tex2D(float4), refractionTexture, UPDATE_FREQ_PER_FRAME, t16, binding = 20); -RES(Tex2D(float4), reflectionTexture[SCENE_MAX_REFLECTION_COUNT], UPDATE_FREQ_PER_FRAME, t17, binding = 20); +RES(Tex2D(float4), shadowTexture, UPDATE_FREQ_NONE, t13, binding = 20); +RES(Tex2D(float4), visibilityTexture, UPDATE_FREQ_PER_FRAME, t14, binding = 21); +RES(Tex2D(float4), albedoTexture, UPDATE_FREQ_PER_FRAME, t15, binding = 22); +RES(Tex2D(float4), refractionTexture, UPDATE_FREQ_PER_FRAME, t16, binding = 23); +RES(Tex2D(float4), reflectionTexture[SCENE_MAX_REFLECTION_COUNT], UPDATE_FREQ_PER_FRAME, t17, binding = 24); -RES(Tex2D(float4), dissolveTexture, UPDATE_FREQ_NONE, t22, binding = 21); +RES(Tex2D(float4), dissolveTexture, UPDATE_FREQ_NONE, t22, binding = 25); -RES(ByteBuffer, lightClustersCount, UPDATE_FREQ_PER_FRAME, t23, binding = 22); -RES(ByteBuffer, lightClusters, UPDATE_FREQ_PER_FRAME, t24, binding = 23); +RES(ByteBuffer, lightClustersCount, UPDATE_FREQ_PER_FRAME, t23, binding = 26); +RES(ByteBuffer, lightClusters, UPDATE_FREQ_PER_FRAME, t24, binding = 27); -RES(Tex2D(float4), sceneTextures[SCENE_MAX_TEXTURE_COUNT], UPDATE_FREQ_PER_FRAME, t25, binding = 24); -RES(TexCube(float4), sceneCubeTextures[SCENE_MAX_TEXTURE_CUBE_COUNT], UPDATE_FREQ_PER_FRAME, t10025, binding = 25); +RES(Tex2D(float4), sceneTextures[SCENE_MAX_TEXTURE_COUNT], UPDATE_FREQ_PER_FRAME, t25, binding = 28); +RES(TexCube(float4), sceneCubeTextures[SCENE_MAX_TEXTURE_CUBE_COUNT], UPDATE_FREQ_PER_FRAME, t10025, binding = 29); #define SCENE_OBJECT_ID_BIT 19 // 13 bits for ObjectID #define SCENE_PRIM_ID_BIT 0 // 19 bits for PrimitiveID @@ -71,43 +71,4 @@ RES(TexCube(float4), sceneCubeTextures[SCENE_MAX_TEXTURE_CUBE_COUNT], UPDATE_FR #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) -bool SampleSceneTextureProjFloat4(uint textureIdx, SamplerState sh, float4 projectUV, inout float4 value) { - if(textureIdx < SCENE_MAX_TEXTURE_COUNT) { - BeginNonUniformResourceIndex(textureIdx); - value = SampleTex2DProj(Get(sceneTextures)[textureIdx], sh, projectUV); - EndNonUniformResourceIndex(); - return true; - } - return false; -} - -INLINE bool SampleSceneCubeTextureFloat4(uint textureIdx, SamplerState sh, float3 uv, inout float4 value) { - if(textureIdx < SCENE_MAX_TEXTURE_CUBE_COUNT) { - BeginNonUniformResourceIndex(textureIdx); - value = SampleTexCube(Get(sceneCubeTextures)[textureIdx], sh, uv); - EndNonUniformResourceIndex(); - return true; - } - return false; -} - -INLINE bool SampleSceneTextureFloat4(uint textureIdx,SamplerState sh, float2 uv, inout float4 value) { - if(textureIdx < SCENE_MAX_TEXTURE_COUNT) { - BeginNonUniformResourceIndex(textureIdx); - value = SampleTex2D(Get(sceneTextures)[textureIdx], sh, uv); - EndNonUniformResourceIndex(); - return true; - } - return false; -} -INLINE bool SampleSceneTextureGradFloat4(uint textureIdx, SamplerState sh, float2 uv, float2 texCoordDX, float2 texCoordDY, inout float4 value) { - if(textureIdx < SCENE_MAX_TEXTURE_COUNT) { - BeginNonUniformResourceIndex(textureIdx); - value = SampleGradTex2D(Get(sceneTextures)[textureIdx], sh, uv, texCoordDX, texCoordDY); - EndNonUniformResourceIndex(); - return true; - } - return false; -} - #endif diff --git a/HPL2/resource/translucency_shade.frag.fsl b/HPL2/resource/translucency_shade.frag.fsl index bbe784d04..422f0cd2b 100644 --- a/HPL2/resource/translucency_shade.frag.fsl +++ b/HPL2/resource/translucency_shade.frag.fsl @@ -36,8 +36,10 @@ PsOut PS_MAIN(PsIn In, SV_PrimitiveID(uint) primitiveID) float4 finalColor = float4(0.0, 0.0 ,0.0, 1.0); #ifndef USE_ILLUMINATION - SampleSceneTextureFloat4(material.diffuseTextureIndex, Get(sceneSampler), In.uv.xy, finalColor); - finalColor *= In.Color; + const uint diffuseTextureIndex = material.diffuseTextureIndex; + BeginNonUniformResourceIndex(diffuseTextureIndex); + finalColor = SampleTex2D(Get(sceneTextures)[diffuseTextureIndex], Get(sceneSampler), In.uv.xy) * In.Color; + EndNonUniformResourceIndex(); #endif float finalAlpha = obj.alphaAmount; @@ -71,8 +73,13 @@ PsOut PS_MAIN(PsIn In, SV_PrimitiveID(uint) primitiveID) float3 mapNormal = float3(0,0,0); float3 screenNormal = float3(0,0,0); - float4 normalSample; - if(SampleSceneTextureFloat4(material.normalTextureIndex, Get(sceneSampler), In.uv, normalSample)) { + float4 normalSample = float4(0,0,0,0); + const uint normalTextureIndex = material.normalTextureIndex; + if(isTextureIndexValid(normalTextureIndex)) { + BeginNonUniformResourceIndex(normalTextureIndex); + normalSample = SampleTex2D(Get(sceneTextures)[normalTextureIndex], Get(sceneSampler), In.uv.xy); + EndNonUniformResourceIndex(); + mapNormal = normalSample.xyz * 2.0 - 1.0; screenNormal = normalize(mapNormal.x * In.tangent + mapNormal.y * In.bitangent + mapNormal.z * In.normal); } else { @@ -118,15 +125,22 @@ PsOut PS_MAIN(PsIn In, SV_PrimitiveID(uint) primitiveID) viewInfo.viewMat[0].xyz, viewInfo.viewMat[1].xyz, viewInfo.viewMat[2].xyz)), vEnvUv); - float4 reflectionColor; - if(SampleSceneCubeTextureFloat4(material.cubeMapTextureIndex, Get(sceneSampler), vEnvUv, reflectionColor)) { + const uint cubeMapTextureIndex = material.cubeMapTextureIndex; + if(isTextureCubeIndexValid(cubeMapTextureIndex)) { float afEDotN = max(dot(-eyeVec, screenNormal),0.0); float fFresnel = Fresnel(afEDotN, material.frenselBias, material.frenselPos); + float4 reflectionColor = f4(0.0); + BeginNonUniformResourceIndex(cubeMapTextureIndex); + reflectionColor = SampleTexCube(Get(sceneCubeTextures)[cubeMapTextureIndex], Get(sceneSampler), vEnvUv); + EndNonUniformResourceIndex(); + //Alpha for environment map - float4 specular; - if(SampleSceneTextureFloat4(material.cubeMapAlphaTextureIndex, Get(sceneSampler), In.uv.xy, specular)) { - reflectionColor *= specular.w; + const uint cubeMapAlphaTextureIndex = material.cubeMapAlphaTextureIndex; + if(isTextureIndexValid(cubeMapAlphaTextureIndex)) { + BeginNonUniformResourceIndex(cubeMapAlphaTextureIndex); + reflectionColor *= SampleTex2D(Get(sceneTextures)[cubeMapAlphaTextureIndex], Get(sceneSampler), In.uv.xy).w; + EndNonUniformResourceIndex(); } finalColor.xyz += reflectionColor.xyz * fFresnel * finalAlpha * obj.lightLevel; diff --git a/HPL2/resource/translucency_water_shade.frag.fsl b/HPL2/resource/translucency_water_shade.frag.fsl index e4bcc17ea..3bd71efca 100644 --- a/HPL2/resource/translucency_water_shade.frag.fsl +++ b/HPL2/resource/translucency_water_shade.frag.fsl @@ -63,8 +63,8 @@ PsOut PS_MAIN(PsIn In, SV_PrimitiveID(uint) primitiveID) float3 vFinalNormal = normalize(vNormal1*0.7 + vNormal2*0.3); //Get the diffuse color - const uint diffuseTextureIndex = material.normalTextureIndex; - float4 surfaceColor; //= SampleTex2D(Get(diffuseMap), Get(materialSampler), vUv1); + const uint diffuseTextureIndex = material.diffuseTextureIndex; + float4 surfaceColor = float4(0,0,0,0); BeginNonUniformResourceIndex(diffuseTextureIndex); surfaceColor = SampleTex2D(Get(sceneTextures)[diffuseTextureIndex], Get(sceneSampler), vUv1); EndNonUniformResourceIndex(); diff --git a/HPL2/resource/visibilityBuffer_alpha_pass.frag.fsl b/HPL2/resource/visibilityBuffer_alpha_pass.frag.fsl index 2fcaf3eef..1a070eb9a 100644 --- a/HPL2/resource/visibilityBuffer_alpha_pass.frag.fsl +++ b/HPL2/resource/visibilityBuffer_alpha_pass.frag.fsl @@ -46,24 +46,25 @@ float4 PS_MAIN(PsIn In, SV_PrimitiveID(uint) primitiveID) } - float4 value; - if(SampleSceneTextureFloat4(material.alphaTextureIndex,Get(sceneSampler), texCoord, value)) { - if((material.config & MATERIAL_IS_ALPHA_SINGLE_CHANNEL) > 0) { - diffuseAlpha = value.r; - } else { - diffuseAlpha = value.a; - } + const uint alphaTextureIndex = material.alphaTextureIndex; + if(isTextureIndexValid(alphaTextureIndex)) { + BeginNonUniformResourceIndex(alphaTextureIndex); + diffuseAlpha = ((material.config & MATERIAL_IS_ALPHA_SINGLE_CHANNEL) > 0) ? SampleTex2D(Get(sceneTextures)[alphaTextureIndex], Get(sceneSampler), In.uv.xy).r : SampleTex2D(Get(sceneTextures)[alphaTextureIndex], Get(sceneSampler), In.uv.xy).a; + EndNonUniformResourceIndex(); } if(obj.dissolveAmount < 1.0 || isTextureIndexValid(material.alphaTextureIndex) || (material.config & MATERIAL_USE_ALPHA_DISSOLVE_FILTER) > 0) { const float2 dissolveCoord = In.Position.xy * (1.0/128.0); //128 = size of dissolve texture. float fDissolve = SampleTex2D(Get(dissolveTexture), Get(nearPointWrapSampler), dissolveCoord).x; - float4 alphaValue; - if(SampleSceneTextureFloat4(material.dissolveAlphaTextureIndex, Get(sceneSampler), texCoord, alphaValue)) { + const uint dissolveAlphaTextureIndex = material.dissolveAlphaTextureIndex; + if(isTextureIndexValid(dissolveAlphaTextureIndex)) { + float fDissolveAlpha = 0.0f; //Get in 0.75 - 1 range fDissolve = fDissolve * 0.25 + 0.75; - float fDissolveAlpha = ((material.config & MATERIAL_IS_ALPHA_SINGLE_CHANNEL) > 0) ? alphaValue.r : alphaValue.a; + BeginNonUniformResourceIndex(dissolveAlphaTextureIndex); + fDissolveAlpha = ((material.config & MATERIAL_IS_ALPHA_SINGLE_CHANNEL) > 0) ? SampleTex2D(Get(sceneTextures)[dissolveAlphaTextureIndex], Get(sceneSampler), texCoord).r : SampleTex2D(Get(sceneTextures)[dissolveAlphaTextureIndex], Get(sceneSampler), texCoord).a; + EndNonUniformResourceIndex(); fDissolve -= (0.25 - fDissolveAlpha * 0.25); } else { //Get in 0.5 - 1 range. diff --git a/HPL2/resource/visibility_emit_shade_pass.frag.fsl b/HPL2/resource/visibility_emit_shade_pass.frag.fsl index 3e54afa93..654fcfe5d 100644 --- a/HPL2/resource/visibility_emit_shade_pass.frag.fsl +++ b/HPL2/resource/visibility_emit_shade_pass.frag.fsl @@ -113,8 +113,8 @@ float4 PS_MAIN(PsIn In) float4 diffuseColor = float4(0,0,0,0); float3 shadedColor = f3(0.0f); - if(isTextureIndexValid(material.diffuseTextureIndex)) { - const uint diffuseTextureIdx = material.diffuseTextureIndex; + const uint diffuseTextureIdx = material.diffuseTextureIndex; + if(isTextureIndexValid(diffuseTextureIdx)) { BeginNonUniformResourceIndex(diffuseTextureIdx); diffuseColor = SampleGradTex2D(Get(sceneTextures)[diffuseTextureIdx], Get(sceneSampler), texCoord, texCoordDX, texCoordDY); EndNonUniformResourceIndex(); diff --git a/HPL2/resource/visibility_shade_pass.frag.fsl b/HPL2/resource/visibility_shade_pass.frag.fsl index d1982f55a..82bd74fa7 100644 --- a/HPL2/resource/visibility_shade_pass.frag.fsl +++ b/HPL2/resource/visibility_shade_pass.frag.fsl @@ -183,13 +183,21 @@ float4 PS_MAIN(PsIn In) float4 normalSample = float4(0,0,0,0); float3 shadedColor = float3(0.0,0.0,0.0); - if (SampleSceneTextureGradFloat4(material.normalTextureIndex, Get(sceneSampler), texCoord, texCoordDX, texCoordDY, normalSample)) { + const uint normalTextureIndex = material.normalTextureIndex; + if (isTextureIndexValid(normalTextureIndex)) { + BeginNonUniformResourceIndex(normalTextureIndex); + normalSample = SampleGradTex2D(Get(sceneTextures)[normalTextureIndex], Get(sceneSampler), texCoord, texCoordDX, texCoordDY); + EndNonUniformResourceIndex(); + normalSample -= 0.5; worldNormal = normalize(normalSample.x * worldTangent + normalSample.y * worldBitangent+ normalSample.z * worldNormal); } float4 illuminationSample = float4(0,0,0,0); - if(obj.illuminationAmount > 0 && SampleSceneTextureGradFloat4(material.illuminiationTextureIndex, Get(sceneSampler), texCoord, texCoordDX, texCoordDY, illuminationSample)) { - shadedColor += (obj.illuminationAmount * illuminationSample.xyz); + const uint illuminationTextureIndex = material.illuminationTextureIndex; + if(obj.illuminationAmount > 0 && isTextureIndexValid(illuminationTextureIndex) ) { + BeginNonUniformResourceIndex(illuminationTextureIndex); + shadedColor += obj.illuminationAmount * SampleGradTex2D(Get(sceneTextures)[illuminationTextureIndex], Get(sceneSampler), texCoord, texCoordDX, texCoordDY).xyz; + EndNonUniformResourceIndex(); } float2 texelPos = (In.position.xy / viewInfo.rect.zw); @@ -198,7 +206,12 @@ float4 PS_MAIN(PsIn In) const uint lightClusterCount = LoadByte(Get(lightClustersCount), LIGHT_FROXEL_COUNT_POS(clusterCoords.x, clusterCoords.y, slice) << 2); float4 specular = float4(0,0,0,0); - SampleSceneTextureGradFloat4(material.specularTextureIndex, Get(sceneSampler), texCoord, texCoordDX, texCoordDY, specular); + const uint specularTextureIndex = material.specularTextureIndex; + if(isTextureIndexValid(specularTextureIndex )) { + BeginNonUniformResourceIndex(specularTextureIndex); + specular = SampleGradTex2D(Get(sceneTextures)[specularTextureIndex], Get(sceneSampler), texCoord, texCoordDX, texCoordDY); + EndNonUniformResourceIndex(); + } for(uint j = 0; j < lightClusterCount; ++j) { const uint index = LoadByte(Get(lightClusters), LIGHT_FROXEL_DATA_POS(clusterCoords.x, clusterCoords.y, slice, j) << 2); const Light light = Get(lights)[index]; diff --git a/HPL2/sources/graphics/ForgeRenderer.cpp b/HPL2/sources/graphics/ForgeRenderer.cpp index ed8c6d6af..8f7eb4fc9 100644 --- a/HPL2/sources/graphics/ForgeRenderer.cpp +++ b/HPL2/sources/graphics/ForgeRenderer.cpp @@ -1,5 +1,6 @@ #include +#include "Common_3/OS/Interfaces/IOperatingSystem.h" #include "engine/IUpdateEventLoop.h" #include "engine/Interface.h" #include "graphics/Material.h" @@ -28,6 +29,11 @@ namespace hpl { // m_resourcePoolIndex = (m_resourcePoolIndex + 1) % ResourcePoolSize; //m_currentFrameCount++; m_frame.m_cmdRingElement = getNextGpuCmdRingElement(&m_graphicsCmdRing, true, 1); + FenceStatus fenceStatus; + getFenceStatus(m_renderer, m_frame.m_cmdRingElement.pFence, &fenceStatus); + if (fenceStatus == FENCE_STATUS_INCOMPLETE) + waitForFences(m_renderer, 1, &m_frame.m_cmdRingElement.pFence); + m_frame.m_currentFrame++; m_frame.m_frameIndex = (m_frame.m_frameIndex + 1) % ForgeRenderer::SwapChainLength; //m_frame.m_swapChainTarget = m_swapChain.m_handle->ppRenderTargets[m_frame.m_swapChainIndex]; @@ -36,10 +42,6 @@ namespace hpl { m_frame.m_cmd = m_frame.cmd(); m_frame.m_renderer = this; - FenceStatus fenceStatus; - getFenceStatus(m_renderer, m_frame.m_cmdRingElement.pFence, &fenceStatus); - if (fenceStatus == FENCE_STATUS_INCOMPLETE) - waitForFences(m_renderer, 1, &m_frame.m_cmdRingElement.pFence); resetCmdPool(m_renderer, m_frame.m_cmdRingElement.pCmdPool); m_frame.m_resourcePool->ResetPool(); @@ -137,176 +139,172 @@ namespace hpl { } #endif - #endif - - RendererDesc settings; - memset(&settings, 0, sizeof(settings)); - initRenderer("HPL2", &settings, &m_renderer); - - QueueDesc queueDesc = {}; - queueDesc.mType = QUEUE_TYPE_GRAPHICS; - queueDesc.mFlag = QUEUE_FLAG_INIT_MICROPROFILE; - addQueue(m_renderer, &queueDesc, &m_graphicsQueue); - - GpuCmdRingDesc cmdRingDesc = {}; - cmdRingDesc.pQueue = m_graphicsQueue; - cmdRingDesc.mPoolCount = SwapChainLength; - cmdRingDesc.mCmdPerPoolCount = 1; - cmdRingDesc.mAddSyncPrimitives = true; - addGpuCmdRing(m_renderer, &cmdRingDesc, &m_graphicsCmdRing); - - - const auto windowSize = window->GetWindowSize(); - m_swapChain.Load(m_renderer, [&](SwapChain** handle) { - SwapChainDesc swapChainDesc = {}; - swapChainDesc.mWindowHandle = m_window->ForgeWindowHandle(); - m_swapChainCount = getRecommendedSwapchainImageCount(m_renderer, &swapChainDesc.mWindowHandle); - swapChainDesc.mPresentQueueCount = 1; - swapChainDesc.ppPresentQueues = &m_graphicsQueue; - swapChainDesc.mWidth = windowSize.x; - swapChainDesc.mHeight = windowSize.y; - swapChainDesc.mImageCount = m_swapChainCount; - swapChainDesc.mColorFormat = TinyImageFormat_R8G8B8A8_UNORM;//getRecommendedSwapchainFormat(false, false); - swapChainDesc.mColorSpace = COLOR_SPACE_SDR_LINEAR; - swapChainDesc.mColorClearValue = { { 1, 1, 1, 1 } }; - swapChainDesc.mEnableVsync = false; - addSwapChain(m_renderer, &swapChainDesc, handle); - return true; - }); - RootSignatureDesc graphRootDesc = {}; - addRootSignature(m_renderer, &graphRootDesc, &m_pipelineSignature); - - addSemaphore(m_renderer, &m_imageAcquiredSemaphore); - for(auto& rt: m_finalRenderTarget) { - rt.Load(m_renderer,[&](RenderTarget** target) { - RenderTargetDesc renderTarget = {}; - renderTarget.mArraySize = 1; - renderTarget.mClearValue.depth = 1.0f; - renderTarget.mDepth = 1; - renderTarget.mFormat = TinyImageFormat_R8G8B8A8_UNORM; - renderTarget.mWidth = windowSize.x; - renderTarget.mHeight = windowSize.y; - renderTarget.mDescriptors = DESCRIPTOR_TYPE_TEXTURE; - renderTarget.mSampleCount = SAMPLE_COUNT_1; - renderTarget.mSampleQuality = 0; - renderTarget.mStartState = RESOURCE_STATE_SHADER_RESOURCE; - renderTarget.pName = "final output RT"; - addRenderTarget(m_renderer, &renderTarget, target); - return true; - }); - } - m_pointSampler.Load(m_renderer, [&](Sampler **sampler) { - SamplerDesc samplerDesc = {}; - addSampler(m_renderer, &samplerDesc, sampler); - return true; - }); +#endif - { - m_finalShader.Load(m_renderer, [&](Shader** shader){ - ShaderLoadDesc shaderLoadDesc = {}; - shaderLoadDesc.mStages[0].pFileName = "fullscreen.vert"; - shaderLoadDesc.mStages[1].pFileName = "final_posteffect.frag"; - addShader(m_renderer, &shaderLoadDesc, shader); - return true; - }); - - std::array samplers = { - m_pointSampler.m_handle - }; - std::array samplerName = { - (const char*)"inputSampler" - }; - RootSignatureDesc rootDesc = { &m_finalShader.m_handle, 1 }; - rootDesc.ppStaticSamplers = samplers.data(); - rootDesc.ppStaticSamplerNames = samplerName.data(); - rootDesc.mStaticSamplerCount = 1; - addRootSignature(m_renderer, &rootDesc, &m_finalRootSignature); - - DescriptorSetDesc setDesc = { m_finalRootSignature, DESCRIPTOR_UPDATE_FREQ_PER_FRAME, 1}; - for(auto& desc: m_finalPerFrameDescriptorSet) { - desc.Load(m_renderer, [&](DescriptorSet** handle) { - addDescriptorSet(m_renderer, &setDesc, handle); + RendererDesc settings; + memset(&settings, 0, sizeof(settings)); + initRenderer("HPL2", &settings, &m_renderer); + + QueueDesc queueDesc = {}; + queueDesc.mType = QUEUE_TYPE_GRAPHICS; + queueDesc.mFlag = QUEUE_FLAG_INIT_MICROPROFILE; + addQueue(m_renderer, &queueDesc, &m_graphicsQueue); + + GpuCmdRingDesc cmdRingDesc = {}; + cmdRingDesc.pQueue = m_graphicsQueue; + cmdRingDesc.mPoolCount = SwapChainLength; + cmdRingDesc.mCmdPerPoolCount = 1; + cmdRingDesc.mAddSyncPrimitives = true; + addGpuCmdRing(m_renderer, &cmdRingDesc, &m_graphicsCmdRing); + + WindowHandle winHandle = m_window->ForgeWindowHandle(); + m_swapChainCount = getRecommendedSwapchainImageCount(m_renderer, &winHandle); + const auto windowSize = window->GetWindowSize(); + m_swapChain.Load(m_renderer, [&](SwapChain** handle) { + SwapChainDesc swapChainDesc = {}; + swapChainDesc.mWindowHandle = winHandle; + swapChainDesc.mPresentQueueCount = 1; + swapChainDesc.ppPresentQueues = &m_graphicsQueue; + swapChainDesc.mWidth = windowSize.x; + swapChainDesc.mHeight = windowSize.y; + swapChainDesc.mImageCount = m_swapChainCount; + swapChainDesc.mColorFormat = TinyImageFormat_R8G8B8A8_UNORM; // getRecommendedSwapchainFormat(false, false); + swapChainDesc.mColorSpace = COLOR_SPACE_SDR_LINEAR; + swapChainDesc.mColorClearValue = { { 1, 1, 1, 1 } }; + swapChainDesc.mEnableVsync = false; + addSwapChain(m_renderer, &swapChainDesc, handle); + return true; + }); + RootSignatureDesc graphRootDesc = {}; + addRootSignature(m_renderer, &graphRootDesc, &m_pipelineSignature); + + addSemaphore(m_renderer, &m_imageAcquiredSemaphore); + for (auto& rt : m_finalRenderTarget) { + rt.Load(m_renderer, [&](RenderTarget** target) { + RenderTargetDesc renderTarget = {}; + renderTarget.mArraySize = 1; + renderTarget.mClearValue.depth = 1.0f; + renderTarget.mDepth = 1; + renderTarget.mFormat = TinyImageFormat_R8G8B8A8_UNORM; + renderTarget.mWidth = windowSize.x; + renderTarget.mHeight = windowSize.y; + renderTarget.mDescriptors = DESCRIPTOR_TYPE_TEXTURE; + renderTarget.mSampleCount = SAMPLE_COUNT_1; + renderTarget.mSampleQuality = 0; + renderTarget.mStartState = RESOURCE_STATE_SHADER_RESOURCE; + renderTarget.pName = "final output RT"; + addRenderTarget(m_renderer, &renderTarget, target); + return true; + }); + } + m_pointSampler.Load(m_renderer, [&](Sampler** sampler) { + SamplerDesc samplerDesc = {}; + addSampler(m_renderer, &samplerDesc, sampler); return true; }); - } - m_finalPipeline.Load(m_renderer, [&](Pipeline** pipeline) { - DepthStateDesc depthStateDisabledDesc = {}; - depthStateDisabledDesc.mDepthWrite = false; - depthStateDisabledDesc.mDepthTest = false; - - RasterizerStateDesc rasterStateNoneDesc = {}; - rasterStateNoneDesc.mCullMode = CULL_MODE_NONE; - - PipelineDesc pipelineDesc = {}; - pipelineDesc.mType = PIPELINE_TYPE_GRAPHICS; - GraphicsPipelineDesc& graphicsPipelineDesc = pipelineDesc.mGraphicsDesc; - graphicsPipelineDesc.mPrimitiveTopo = PRIMITIVE_TOPO_TRI_LIST; - graphicsPipelineDesc.pShaderProgram = m_finalShader.m_handle; - graphicsPipelineDesc.pRootSignature = m_finalRootSignature; - graphicsPipelineDesc.mRenderTargetCount = 1; - graphicsPipelineDesc.mDepthStencilFormat = TinyImageFormat_UNDEFINED; - graphicsPipelineDesc.pVertexLayout = NULL; - graphicsPipelineDesc.pRasterizerState = &rasterStateNoneDesc; - graphicsPipelineDesc.pDepthState = &depthStateDisabledDesc; - graphicsPipelineDesc.pBlendState = NULL; - - graphicsPipelineDesc.pColorFormats = &m_swapChain.m_handle->ppRenderTargets[0]->mFormat; - graphicsPipelineDesc.mSampleCount = m_swapChain.m_handle->ppRenderTargets[0]->mSampleCount; - graphicsPipelineDesc.mSampleQuality = m_swapChain.m_handle->ppRenderTargets[0]->mSampleQuality; - addPipeline(m_renderer, &pipelineDesc, pipeline); - return true; - }); - } - { - ShaderLoadDesc postProcessCopyShaderDec = {}; - postProcessCopyShaderDec.mStages[0].pFileName = "fullscreen.vert"; - postProcessCopyShaderDec.mStages[1].pFileName = "post_processing_copy.frag"; - addShader(m_renderer, &postProcessCopyShaderDec, &m_copyShader); - - RootSignatureDesc rootDesc = { &m_copyShader, 1 }; - addRootSignature(m_renderer, &rootDesc, &m_copyPostProcessingRootSignature); - DescriptorSetDesc setDesc = { m_copyPostProcessingRootSignature, DESCRIPTOR_UPDATE_FREQ_PER_DRAW, MaxCopyFrames }; - addDescriptorSet(m_renderer, &setDesc, &m_copyPostProcessingDescriptorSet[0]); - addDescriptorSet(m_renderer, &setDesc, &m_copyPostProcessingDescriptorSet[1]); - - DepthStateDesc depthStateDisabledDesc = {}; - depthStateDisabledDesc.mDepthWrite = false; - depthStateDisabledDesc.mDepthTest = false; - - RasterizerStateDesc rasterStateNoneDesc = {}; - rasterStateNoneDesc.mCullMode = CULL_MODE_NONE; - - PipelineDesc pipelineDesc = {}; - pipelineDesc.mType = PIPELINE_TYPE_GRAPHICS; - GraphicsPipelineDesc& copyPipelineDesc = pipelineDesc.mGraphicsDesc; - copyPipelineDesc.mPrimitiveTopo = PRIMITIVE_TOPO_TRI_LIST; - copyPipelineDesc.pShaderProgram = m_copyShader; - copyPipelineDesc.pRootSignature = m_copyPostProcessingRootSignature; - copyPipelineDesc.mRenderTargetCount = 1; - copyPipelineDesc.mDepthStencilFormat = TinyImageFormat_UNDEFINED; - copyPipelineDesc.pVertexLayout = NULL; - copyPipelineDesc.pRasterizerState = &rasterStateNoneDesc; - copyPipelineDesc.pDepthState = &depthStateDisabledDesc; - copyPipelineDesc.pBlendState = NULL; - - { - TinyImageFormat format = TinyImageFormat_R8G8B8A8_UNORM; - copyPipelineDesc.pColorFormats = &format; - copyPipelineDesc.mSampleCount = SAMPLE_COUNT_1; - copyPipelineDesc.mSampleQuality = m_swapChain.m_handle->ppRenderTargets[0]->mSampleQuality; - addPipeline(m_renderer, &pipelineDesc, &m_copyPostProcessingPipelineToUnormR8G8B8A8); - } - { - copyPipelineDesc.pColorFormats = &m_swapChain.m_handle->ppRenderTargets[0]->mFormat; - copyPipelineDesc.mSampleCount = m_swapChain.m_handle->ppRenderTargets[0]->mSampleCount; - copyPipelineDesc.mSampleQuality = m_swapChain.m_handle->ppRenderTargets[0]->mSampleQuality; - addPipeline(m_renderer, &pipelineDesc, &m_copyPostProcessingPipelineToSwapChain ); - } - } + { + m_finalShader.Load(m_renderer, [&](Shader** shader) { + ShaderLoadDesc shaderLoadDesc = {}; + shaderLoadDesc.mStages[0].pFileName = "fullscreen.vert"; + shaderLoadDesc.mStages[1].pFileName = "final_posteffect.frag"; + addShader(m_renderer, &shaderLoadDesc, shader); + return true; + }); + + std::array samplers = { m_pointSampler.m_handle }; + std::array samplerName = { (const char*)"inputSampler" }; + RootSignatureDesc rootDesc = { &m_finalShader.m_handle, 1 }; + rootDesc.ppStaticSamplers = samplers.data(); + rootDesc.ppStaticSamplerNames = samplerName.data(); + rootDesc.mStaticSamplerCount = 1; + addRootSignature(m_renderer, &rootDesc, &m_finalRootSignature); + + DescriptorSetDesc setDesc = { m_finalRootSignature, DESCRIPTOR_UPDATE_FREQ_PER_FRAME, 1 }; + for (auto& desc : m_finalPerFrameDescriptorSet) { + desc.Load(m_renderer, [&](DescriptorSet** handle) { + addDescriptorSet(m_renderer, &setDesc, handle); + return true; + }); + } + m_finalPipeline.Load(m_renderer, [&](Pipeline** pipeline) { + DepthStateDesc depthStateDisabledDesc = {}; + depthStateDisabledDesc.mDepthWrite = false; + depthStateDisabledDesc.mDepthTest = false; + + RasterizerStateDesc rasterStateNoneDesc = {}; + rasterStateNoneDesc.mCullMode = CULL_MODE_NONE; + + PipelineDesc pipelineDesc = {}; + pipelineDesc.mType = PIPELINE_TYPE_GRAPHICS; + GraphicsPipelineDesc& graphicsPipelineDesc = pipelineDesc.mGraphicsDesc; + graphicsPipelineDesc.mPrimitiveTopo = PRIMITIVE_TOPO_TRI_LIST; + graphicsPipelineDesc.pShaderProgram = m_finalShader.m_handle; + graphicsPipelineDesc.pRootSignature = m_finalRootSignature; + graphicsPipelineDesc.mRenderTargetCount = 1; + graphicsPipelineDesc.mDepthStencilFormat = TinyImageFormat_UNDEFINED; + graphicsPipelineDesc.pVertexLayout = NULL; + graphicsPipelineDesc.pRasterizerState = &rasterStateNoneDesc; + graphicsPipelineDesc.pDepthState = &depthStateDisabledDesc; + graphicsPipelineDesc.pBlendState = NULL; + + graphicsPipelineDesc.pColorFormats = &m_swapChain.m_handle->ppRenderTargets[0]->mFormat; + graphicsPipelineDesc.mSampleCount = m_swapChain.m_handle->ppRenderTargets[0]->mSampleCount; + graphicsPipelineDesc.mSampleQuality = m_swapChain.m_handle->ppRenderTargets[0]->mSampleQuality; + addPipeline(m_renderer, &pipelineDesc, pipeline); + return true; + }); + } + { + ShaderLoadDesc postProcessCopyShaderDec = {}; + postProcessCopyShaderDec.mStages[0].pFileName = "fullscreen.vert"; + postProcessCopyShaderDec.mStages[1].pFileName = "post_processing_copy.frag"; + addShader(m_renderer, &postProcessCopyShaderDec, &m_copyShader); + + RootSignatureDesc rootDesc = { &m_copyShader, 1 }; + addRootSignature(m_renderer, &rootDesc, &m_copyPostProcessingRootSignature); + DescriptorSetDesc setDesc = { m_copyPostProcessingRootSignature, DESCRIPTOR_UPDATE_FREQ_PER_DRAW, MaxCopyFrames }; + addDescriptorSet(m_renderer, &setDesc, &m_copyPostProcessingDescriptorSet[0]); + addDescriptorSet(m_renderer, &setDesc, &m_copyPostProcessingDescriptorSet[1]); + + DepthStateDesc depthStateDisabledDesc = {}; + depthStateDisabledDesc.mDepthWrite = false; + depthStateDisabledDesc.mDepthTest = false; + + RasterizerStateDesc rasterStateNoneDesc = {}; + rasterStateNoneDesc.mCullMode = CULL_MODE_NONE; + + PipelineDesc pipelineDesc = {}; + pipelineDesc.mType = PIPELINE_TYPE_GRAPHICS; + GraphicsPipelineDesc& copyPipelineDesc = pipelineDesc.mGraphicsDesc; + copyPipelineDesc.mPrimitiveTopo = PRIMITIVE_TOPO_TRI_LIST; + copyPipelineDesc.pShaderProgram = m_copyShader; + copyPipelineDesc.pRootSignature = m_copyPostProcessingRootSignature; + copyPipelineDesc.mRenderTargetCount = 1; + copyPipelineDesc.mDepthStencilFormat = TinyImageFormat_UNDEFINED; + copyPipelineDesc.pVertexLayout = NULL; + copyPipelineDesc.pRasterizerState = &rasterStateNoneDesc; + copyPipelineDesc.pDepthState = &depthStateDisabledDesc; + copyPipelineDesc.pBlendState = NULL; + + { + TinyImageFormat format = TinyImageFormat_R8G8B8A8_UNORM; + copyPipelineDesc.pColorFormats = &format; + copyPipelineDesc.mSampleCount = SAMPLE_COUNT_1; + copyPipelineDesc.mSampleQuality = m_swapChain.m_handle->ppRenderTargets[0]->mSampleQuality; + addPipeline(m_renderer, &pipelineDesc, &m_copyPostProcessingPipelineToUnormR8G8B8A8); + } + + { + copyPipelineDesc.pColorFormats = &m_swapChain.m_handle->ppRenderTargets[0]->mFormat; + copyPipelineDesc.mSampleCount = m_swapChain.m_handle->ppRenderTargets[0]->mSampleCount; + copyPipelineDesc.mSampleQuality = m_swapChain.m_handle->ppRenderTargets[0]->mSampleQuality; + addPipeline(m_renderer, &pipelineDesc, &m_copyPostProcessingPipelineToSwapChain); + } + } - m_windowEventHandler.Connect(window->NativeWindowEvent()); - IncrementFrame(); + m_windowEventHandler.Connect(window->NativeWindowEvent()); + IncrementFrame(); } Sampler* ForgeRenderer::resolve(SamplerPoolKey key) { diff --git a/HPL2/sources/graphics/RendererDeferred.cpp b/HPL2/sources/graphics/RendererDeferred.cpp index d25704fa8..a2e214d48 100644 --- a/HPL2/sources/graphics/RendererDeferred.cpp +++ b/HPL2/sources/graphics/RendererDeferred.cpp @@ -388,7 +388,7 @@ namespace hpl { { eMaterialTexture_Alpha, &diffuseMaterial.m_alphaTextureIndex }, { eMaterialTexture_Specular, &diffuseMaterial.m_specularTextureIndex }, { eMaterialTexture_Height, &diffuseMaterial.m_heightTextureIndex }, - { eMaterialTexture_Illumination, &diffuseMaterial.m_illuminiationTextureIndex }, + { eMaterialTexture_Illumination, &diffuseMaterial.m_illuminationTextureIndex }, { eMaterialTexture_DissolveAlpha, &diffuseMaterial.m_dissolveAlphaTextureIndex }, }; for (auto& tex : textures) { @@ -1646,6 +1646,13 @@ namespace hpl { addDescriptorSet(forgeRenderer->Rend(), &descriptorSetDesc, descSet); return true; }); + + m_lightDescriptorConstSet.Load(forgeRenderer->Rend(), [&](DescriptorSet** descSet) { + DescriptorSetDesc descriptorSetDesc{ m_lightClusterRootSignature.m_handle, DESCRIPTOR_UPDATE_FREQ_NONE, 1 }; + addDescriptorSet(forgeRenderer->Rend(), &descriptorSetDesc, descSet); + return true; + }); + // update descriptorSet for (size_t swapchainIndex = 0; swapchainIndex < ForgeRenderer::SwapChainLength; swapchainIndex++) { m_sceneDescriptorPerFrameSet[swapchainIndex].Load(forgeRenderer->Rend(), [&](DescriptorSet** descSet) { @@ -1653,11 +1660,6 @@ namespace hpl { addDescriptorSet(forgeRenderer->Rend(), &descriptorSetDesc, descSet); return true; }); - // m_sceneDescriptorPerBatchSet[swapchainIndex].Load(forgeRenderer->Rend(), [&](DescriptorSet** descSet) { - // DescriptorSetDesc descriptorSetDesc{ m_sceneRootSignature.m_handle, DESCRIPTOR_UPDATE_FREQ_PER_BATCH, ScenePerDescriptorBatchSize }; - // addDescriptorSet(forgeRenderer->Rend(), &descriptorSetDesc, descSet); - // return true; - // }); m_lightDescriptorPerFrameSet[swapchainIndex].Load(forgeRenderer->Rend(), [&](DescriptorSet** descSet) { DescriptorSetDesc descriptorSetDesc{ m_lightClusterRootSignature.m_handle, DESCRIPTOR_UPDATE_FREQ_PER_FRAME, 1 }; addDescriptorSet(forgeRenderer->Rend(), &descriptorSetDesc, descSet); @@ -1681,7 +1683,6 @@ namespace hpl { DescriptorData{ .pName = "lights", .ppBuffers = &m_lightBuffer[swapchainIndex].m_handle }, DescriptorData{ .pName = "lightClustersCount", .ppBuffers = &m_lightClusterCountBuffer[swapchainIndex].m_handle }, DescriptorData{ .pName = "lightClusters", .ppBuffers = &m_lightClustersBuffer[swapchainIndex].m_handle }, - DescriptorData{ .pName = "sceneInfo", .ppBuffers = &m_perSceneInfoBuffer[swapchainIndex].m_handle }, }; updateDescriptorSet( forgeRenderer->Rend(), 0, m_lightDescriptorPerFrameSet[swapchainIndex].m_handle, params.size(), params.data()); @@ -1740,6 +1741,7 @@ namespace hpl { auto& sharedMat = m_sharedMaterial[material->Index()]; if (sharedMat.m_material != material || sharedMat.m_version != material->Generation()) { sharedMat.m_material = material; + sharedMat.m_version = material->Generation(); for (uint32_t slot = 0; slot < eMaterialTexture_LastEnum; slot++) { eMaterialTexture textureType = static_cast(slot); @@ -2170,7 +2172,7 @@ namespace hpl { { eMaterialTexture_Alpha, &translucenctMaterial.m_alphaTextureIndex }, { eMaterialTexture_Specular, &translucenctMaterial.m_specularTextureIndex }, { eMaterialTexture_Height, &translucenctMaterial.m_heightTextureIndex }, - { eMaterialTexture_Illumination, &translucenctMaterial.m_illuminiationTextureIndex }, + { eMaterialTexture_Illumination, &translucenctMaterial.m_illuminationTextureIndex }, { eMaterialTexture_DissolveAlpha, &translucenctMaterial.m_dissolveAlphaTextureIndex }, { eMaterialTexture_CubeMap, &translucenctMaterial.m_cubeMapTextureIndex }, { eMaterialTexture_CubeMapAlpha, &translucenctMaterial.m_cubeMapAlphaTextureIndex }, @@ -2399,6 +2401,7 @@ namespace hpl { } case eLightType_Spot: { + cLightSpot* pLightSpot = static_cast(light); const float fFarHeight = pLightSpot->GetTanHalfFOV() * pLightSpot->GetRadius() * 2.0f; // Note: Aspect might be wonky if there is no gobo. @@ -2580,6 +2583,7 @@ namespace hpl { cmdResourceBarrier(cmd, barriers.size(), barriers.data(), 0, nullptr, 0, nullptr); } cmdBindPipeline(cmd, m_lightClusterPipeline.m_handle); + cmdBindDescriptorSetWithRootCbvs(cmd, 0, m_lightDescriptorConstSet.m_handle, mainViewportParams.size(), mainViewportParams.data()); cmdBindDescriptorSet(cmd, 0, m_lightDescriptorPerFrameSet[frame.m_frameIndex].m_handle); cmdDispatch(cmd, lightCount, 1, LightClusterSlices); {