Skip to content

Commit

Permalink
feat: add gobo textures
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Pollind <[email protected]>
  • Loading branch information
pollend committed Nov 26, 2023
1 parent 1652608 commit 2d80278
Show file tree
Hide file tree
Showing 10 changed files with 220 additions and 188 deletions.
2 changes: 1 addition & 1 deletion HPL2/include/graphics/RendererDeferred2.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ namespace hpl {
SharedSampler m_samplerPointWrap;
std::array<SceneMaterial, cMaterial::MaxMaterialID> m_sceneMaterial;
TextureDescriptorPool m_sceneTexture2DPool;
ImageBindlessPool m_sceneTransientImage2DPool;
CommandSignature* m_cmdSignatureVBPass = NULL;

// diffuse
Expand Down Expand Up @@ -180,7 +181,6 @@ namespace hpl {
cRenderList m_rendererList;

// Lights
ImageBindlessPool m_transientImagePool;
SharedRootSignature m_lightClusterRootSignature;
std::array<SharedDescriptorSet, ForgeRenderer::SwapChainLength> m_lightDescriptorPerFrameSet;
SharedShader m_lightClusterShader;
Expand Down
3 changes: 2 additions & 1 deletion HPL2/include/graphics/SceneResource.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ namespace hpl::resource {

static constexpr uint32_t MaterialIDMask = 0xff; // 0000 0000 0000 0000 0000 0000 1111 1111
static constexpr uint32_t MaterialIndexMask = 0xffff00; // 0000 0000 1111 1111 1111 1111 0000 0000
static constexpr uint32_t InvalidSceneTexsture = 0xffff;
uint32_t encodeMaterialID(hpl::MaterialID id, uint32_t handle);


Expand Down Expand Up @@ -94,7 +95,7 @@ namespace hpl::resource {
float m_angle;
float4 m_lightColor;
float m_radius;
uint32_t m_pad0;
uint32_t m_goboTexture;
uint32_t m_pad1;
uint32_t m_pad2;
};
Expand Down
1 change: 1 addition & 0 deletions HPL2/resource/math_utils.h.fsl
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ float3 WorldSpaceToTangent(float3 dir, float3 normal, float3 tangent, float3 bit
return float3(a,b,c);
}

// https://bartwronski.com/2017/04/13/cull-that-cone/
float4 boundingSphereForSpotlight(in float3 origin, in float3 forward, in float size, in float angle)
{
float4 boundingSphere;
Expand Down
8 changes: 4 additions & 4 deletions HPL2/resource/parallax_bindless.h.fsl
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
#ifndef _PARALLAX_BINDLESS_H
#define _PARALLAX_BINDLESS_H

float GetNormalizedDepth(SceneTexture heightMap,float startDepth, float stopDepth, float inverseDepthRange, float2 uv, bool isHeightMapSingleChannel) {
float GetNormalizedDepth(MaterialTexture heightMap,float startDepth, float stopDepth, float inverseDepthRange, float2 uv, bool isHeightMapSingleChannel) {
float currentSample = 0.0;
float4 value;
if(SampleSceneTextureFloat4(heightMap, uv, value)) {
if(SampleMaterialTextureFloat4(heightMap, uv, value)) {
if(isHeightMapSingleChannel) {
currentSample = value.r;
} else {
Expand All @@ -32,7 +32,7 @@ float2 ParallaxAdvance(float2 uv,
float3 normal,
float3 tangent,
float3 bitangent,
SceneTexture heightMap,
MaterialTexture heightMap,
bool isHeightMapSingleChannel) {

float3 dirToCameraTS = normalize(WorldSpaceToTangent(dir, normal, tangent, bitangent));
Expand All @@ -54,7 +54,7 @@ float2 ParallaxAdvance(float2 uv,

float currentSample;
float4 value;
if(SampleSceneTextureFloat4(heightMap, uv.xy + parallaxOffset.xy, value)) {
if(SampleMaterialTextureFloat4(heightMap, uv.xy + parallaxOffset.xy, value)) {
if(isHeightMapSingleChannel) {
currentSample = value.r;
} else {
Expand Down
14 changes: 7 additions & 7 deletions HPL2/resource/scene_defs.h.fsl
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ uint DiffuseMaterial_IlluminiationTexture_ID(DiffuseMaterial mat) {return ((mat.
uint DiffuseMaterial_DissolveAlphaTexture_ID(DiffuseMaterial mat) {return (mat.tex[3] & 0xffff);}
uint DiffuseMaterial_CubeMapAlphaTexture_ID(DiffuseMaterial mat) {return ((mat.tex[3] >> 16) & 0xffff);}

STRUCT(SceneTexture)
STRUCT(MaterialTexture)
{
DATA(bool, hasGradient, None);
DATA(float2, texCoordDX, None);
Expand All @@ -67,20 +67,20 @@ STRUCT(SceneTexture)
DATA(uint, filterID, None);
DATA(uint, textureID, None);
};
bool IsSceneTextureValid(SceneTexture tex) {
bool IsMaterialTextureValid(MaterialTexture tex) {
return !(tex.textureID == INVALID_TEXTURE_INDEX);
}
SceneTexture CreateGradientSceneTexture(uint filterID, uint textureID, float2 texCoordDX, float2 texCoordDY) {
SceneTexture tex;
MaterialTexture CreateGradientMaterialTexture(uint filterID, uint textureID, float2 texCoordDX, float2 texCoordDY) {
MaterialTexture tex;
tex.filterID = filterID;
tex.textureID = textureID;
tex.texCoordDX = texCoordDX;
tex.texCoordDY = texCoordDY;
tex.hasGradient = true;
return tex;
}
SceneTexture CreateSceneTexture(uint filterID, uint textureID) {
SceneTexture tex;
MaterialTexture CreateMaterialTexture(uint filterID, uint textureID) {
MaterialTexture tex;
tex.filterID = filterID;
tex.textureID = textureID;
tex.hasGradient = false;
Expand Down Expand Up @@ -138,7 +138,7 @@ STRUCT(SpotLight) {
DATA(float, angle, none);
DATA(float4, lightColor, none);
DATA(float, radius, none);
DATA(uint, __pad0, NONE);
DATA(uint, goboTexture, NONE);
DATA(uint, __pad1, NONE);
DATA(uint, __pad2, NONE);
};
Expand Down
28 changes: 27 additions & 1 deletion HPL2/resource/scene_resource.h.fsl
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,33 @@ 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 SampleSceneTextureFloat4(SceneTexture tex, float2 uv, inout float4 value) {
INLINE 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);
EndNonUniformResourceIndex();
}
return !(textureIdx == INVALID_TEXTURE_INDEX);
}

INLINE 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();
}
return !(textureIdx == INVALID_TEXTURE_INDEX);
}
INLINE 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);
EndNonUniformResourceIndex();
}
return !(textureIdx == INVALID_TEXTURE_INDEX);
}

INLINE bool SampleMaterialTextureFloat4(MaterialTexture tex, float2 uv, inout float4 value) {
uint textureIdx = tex.textureID;
uint filterIdx = tex.filterID;
if(textureIdx < SCENE_MAX_TEXTURE_COUNT) {
Expand Down
17 changes: 8 additions & 9 deletions HPL2/resource/visibilityBuffer_alpha_pass.frag.fsl
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,14 @@ PsOut PS_MAIN(PsIn In, SV_PrimitiveID(uint) primitiveID)
uint materialIndex = MATERIAL_INDEX(obj.materialID);
DiffuseMaterial diffuseMat = Get(sceneDiffuseMat)[materialIndex];

SceneTexture alphaTexture = CreateSceneTexture(diffuseMat.samplerIndex, DiffuseMaterial_AlphaTexture_ID(diffuseMat));
SceneTexture heightTexture = CreateSceneTexture(diffuseMat.samplerIndex, DiffuseMaterial_HeightTexture_ID(diffuseMat));
SceneTexture dissolveAlphaTexture = CreateSceneTexture(diffuseMat.samplerIndex, DiffuseMaterial_DissolveAlphaTexture_ID(diffuseMat));
MaterialTexture alphaTexture = CreateMaterialTexture(diffuseMat.samplerIndex, DiffuseMaterial_AlphaTexture_ID(diffuseMat));
MaterialTexture heightTexture = CreateMaterialTexture(diffuseMat.samplerIndex, DiffuseMaterial_HeightTexture_ID(diffuseMat));
MaterialTexture dissolveAlphaTexture = CreateMaterialTexture(diffuseMat.samplerIndex, DiffuseMaterial_DissolveAlphaTexture_ID(diffuseMat));

float diffuseAlpha = 1.0;


float2 texCoord = In.uv;
if(IsSceneTextureValid(heightTexture)) {
if(IsMaterialTextureValid(heightTexture)) {
texCoord += ParallaxAdvance(
In.uv,
0.0,
Expand All @@ -51,24 +50,24 @@ PsOut PS_MAIN(PsIn In, SV_PrimitiveID(uint) primitiveID)


float4 value;
if(SampleSceneTextureFloat4(alphaTexture, texCoord, value)) {
if(SampleMaterialTextureFloat4(alphaTexture, texCoord, value)) {
if((diffuseMat.materialConfig & MATERIAL_IS_ALPHA_SINGLE_CHANNEL) > 0) {
diffuseAlpha = value.r;
} else {
diffuseAlpha = value.a;
}
}

if(obj.dissolveAmount < 1.0 || IsSceneTextureValid(alphaTexture) || (diffuseMat.materialConfig & MATERIAL_USE_ALPHA_DISSOLVE_FILTER) > 0) {
if(obj.dissolveAmount < 1.0 || IsMaterialTextureValid(alphaTexture) || (diffuseMat.materialConfig & 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;

if(IsSceneTextureValid(dissolveAlphaTexture)) {
if(IsMaterialTextureValid(dissolveAlphaTexture)) {
//Get in 0.75 - 1 range
fDissolve = fDissolve * 0.25 + 0.75;

float4 alphaValue;
SampleSceneTextureFloat4(dissolveAlphaTexture, texCoord, alphaValue);
SampleMaterialTextureFloat4(dissolveAlphaTexture, texCoord, alphaValue);
float fDissolveAlpha = alphaValue.r;
fDissolve -= (0.25 - fDissolveAlpha * 0.25);
} else {
Expand Down
Loading

0 comments on commit 2d80278

Please sign in to comment.