Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/cleanup renderer simplify #110

Merged
merged 3 commits into from
Jan 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions HPL2/include/graphics/ForgeRenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ namespace hpl {
/**
* tracks the resources used by a single command buffer
*/
//TODO: transiation this to Frame.h
struct Frame {
public:
uint32_t m_currentFrame = 0;
Expand All @@ -125,6 +126,11 @@ namespace hpl {
inline void pushResource(const T& ele) {
m_resourcePool->Push(ele);
}

inline uint32_t FrameCount() {
return m_currentFrame;
}

inline uint32_t index() {
return m_frameIndex;
}
Expand Down
92 changes: 92 additions & 0 deletions HPL2/include/graphics/Frame.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
#pragma once

#include <graphics/ForgeRenderer.h>

namespace hpl {
/**
* A variable that is only peristent for the frame
*/
template<typename T>
class TransientFrameVariable final {
public:
//static std::function<void(T&)> defaultOnReset = ;

inline T& Fetch(
ForgeRenderer::Frame& frame, std::function<void(T&)> onReset = [](T& value) {
value = T();
}) {
if (frame.FrameCount() != m_frameCount) {
m_frameCount = frame.FrameCount();
onReset(m_value);
}
return m_value;
}

private:
uint32_t m_frameCount;
T m_value;
};

class ResetFrameHandler final {
public:
bool Check(ForgeRenderer::Frame& frame) {
if (frame.FrameCount() != m_frameCount) {
m_frameCount = frame.FrameCount();
return true;
}
return false;
}

private:
uint32_t m_frameCount = 0;
};

//class Frame {
//public:
// uint32_t m_currentFrame = 0;
// uint32_t m_frameIndex = 0;
// GpuCmdRingElement m_cmdRingElement;
// bool m_isFinished = true;
// // FrameState m_state = FrameState::Unitialize;
//
// ForgeRenderer* m_renderer = nullptr;
// SwapChain* m_swapChain = nullptr;
// Cmd* m_cmd = nullptr;
// CmdPool* m_cmdPool = nullptr;
// Fence* m_renderCompleteFence = nullptr;
// Semaphore* m_renderCompleteSemaphore = nullptr;
// CommandResourcePool* m_resourcePool = nullptr;
// RenderTarget* m_finalRenderTarget = nullptr;
//
// template<typename T>
// inline void pushResource(const T& ele) {
// m_resourcePool->Push(ele);
// }
//
// inline uint32_t FrameCount() {
// return m_currentFrame;
// }
//
// inline uint32_t index() {
// return m_frameIndex;
// }
//
// inline Cmd*& cmd() {
// return m_cmdRingElement.pCmds[0];
// }
//
// inline RenderTarget* finalTarget() {
// return m_finalRenderTarget;
// }
//
// // inline RenderTarget* swapChainTarget() {
// // return m_swapChainTarget;
// // }
//
// inline GpuCmdRingElement& RingElement() {
// return m_cmdRingElement;
// }
//
// friend class ForgeRenderer;
//};
} // namespace hpl
24 changes: 17 additions & 7 deletions HPL2/include/graphics/RendererDeferred2.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
#include <graphics/RenderTarget.h>
#include <graphics/Renderable.h>
#include <graphics/Renderer.h>
#include <graphics/Frame.h>
#include <math/MathTypes.h>

#include <Common_3/Graphics/Interfaces/IGraphics.h>
Expand Down Expand Up @@ -269,11 +270,6 @@ namespace hpl {
SharedShader m_translucencyIlluminationShaderAlpha;
SharedShader m_translucencyIlluminationShaderPremulAlpha;

struct DisableEnableDepthPipelines {
SharedPipeline m_enableDepth;
SharedPipeline m_disableDepth;
};

struct BlendPipelines {
SharedPipeline m_pipelineBlendAdd;
SharedPipeline m_pipelineBlendMul;
Expand Down Expand Up @@ -311,11 +307,25 @@ namespace hpl {
BlendPipelines m_translucencyRefractionPipline;
BlendPipelines m_translucencyRefractionPiplineNoDepth;

BlendPipelines m_translucencyIlluminationPipline;
BlendPipelines m_translucencyIlluminationPiplineNoDepth;
SharedPipeline m_translucencyIlluminationPipline;
SharedPipeline m_translucencyIlluminationPiplineNoDepth;

//BlendPipelines m_translucencyIlluminationPipline;
//BlendPipelines m_translucencyIlluminationPiplineNoDepth;

CopyTextureSubpass4 m_copySubpass;


// variables that are persistent for the frame
struct TransientFrameVars {
folly::F14ValueMap<iRenderable*, uint32_t> m_objectSlotIndex;
uint32_t m_objectIndex = 0;
uint32_t m_indirectIndex = 0;
uint32_t m_particleIndex = 0;
};
ResetFrameHandler m_resetHandler;
TransientFrameVariable<TransientFrameVars> m_variables;

bool m_supportIndirectRootConstant = false;
};
}; // namespace hpl
Expand Down
13 changes: 13 additions & 0 deletions HPL2/include/graphics/SceneResource.h
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,19 @@ namespace hpl::resource {
};

struct WaterMaterial {
uint32_t m_diffuseTextureIndex;
uint32_t m_normalTextureIndex;
uint32_t m_cubemapTextureIndex;
uint32_t m_config;

float m_refractionScale;
float m_frenselBias;
float m_frenselPow;
float m_reflectionFadeStart;

float m_reflectionFadeEnd;
float m_waveSpeed;
float m_waveAmplitude;
float m_waveFreq;
};
}
14 changes: 8 additions & 6 deletions HPL2/resource/scene_defs.h.fsl
Original file line number Diff line number Diff line change
Expand Up @@ -46,20 +46,22 @@ STRUCT(TranslucentMaterial) {
};

STRUCT(WaterMaterial) {
DATA(uint, diffuseTextureIndex, None);
DATA(uint, normalTextureIndex, None);
DATA(uint, cubeMapTextureIndex, None);
DATA(uint, config, None);

DATA(float, refractionScale, None);
DATA(float, frenselBias, None);
DATA(float, frenselPow, None);

DATA(float, frenselPos, None);
DATA(float, reflectionFadeStart, None);


DATA(float, reflectionFadeEnd, None);
DATA(float, waveSpeed, None);
DATA(float, waveAmplitude, None);

DATA(float, waveFreq, None);
DATA(uint, _pad0, None);
DATA(uint, _pad1, None);
DATA(uint, _pad2, None);

};


Expand Down
4 changes: 2 additions & 2 deletions HPL2/resource/translucency_shade.frag.fsl
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ STRUCT(PsIn)
DATA(float3, normal, NORMAL);
DATA(float3, tangent, TANGENT);
DATA(float3, bitangent, BITANGENT);
DATA(float4, color, COLOR);
DATA(float4, Color, COLOR);
};

STRUCT(PsOut)
Expand All @@ -37,7 +37,7 @@ PsOut PS_MAIN(PsIn In, SV_PrimitiveID(uint) primitiveID)

#ifndef USE_ILLUMINATION
SampleSceneTextureFloat4(material.diffuseTextureIndex, Get(sceneSampler), In.uv.xy, finalColor);
finalColor *= In.color;
finalColor *= In.Color;
#endif

float finalAlpha = obj.alphaAmount;
Expand Down
4 changes: 2 additions & 2 deletions HPL2/resource/translucency_shade.vert.fsl
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ STRUCT(VSOutput)
DATA(float3, normal, NORMAL);
DATA(float3, tangent, TANGENT);
DATA(float3, bitangent, BITANGENT);
DATA(float4, color, COLOR);
DATA(float4, Color, COLOR);
};

VSOutput VS_MAIN(VSInput In, SV_InstanceID(uint) InstanceID)
Expand All @@ -46,7 +46,7 @@ VSOutput VS_MAIN(VSInput In, SV_InstanceID(uint) InstanceID)
Out.tangent = normalize(mul(normalMat, In.Tangent.xyz));
Out.bitangent = normalize(mul(normalMat, cross(In.Tangent.xyz, In.Normal.xyz)));
Out.Position = mul(modelViewPrj, float4(In.Position.xyz, 1.0));
Out.color = In.Color;
Out.Color = In.Color;

RETURN(Out);
}
Expand Down
6 changes: 6 additions & 0 deletions HPL2/sources/graphics/FrameReset.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

#pragma once

class FrameReset {

};
Loading
Loading