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

feat: tweak logic with instance #46

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
15 changes: 14 additions & 1 deletion HPL2/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,19 @@ function(fsl_compile)


IF(CMAKE_SYSTEM_NAME MATCHES "Windows")
add_custom_command(
TARGET HPL_SHADERS
MAIN_DEPENDENCY
${shader_resources}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMAND ${CMAKE_COMMAND} -E env "VULKAN_SDK=${VULKAN_SDK}" "python3" "${FSL_COMPILER}"
-l DIRECT3D12
-d ${CMAKE_CURRENT_BINARY_DIR}/Shaders/
--verbose
-b ${CMAKE_CURRENT_BINARY_DIR}/CompiledShaders/
--incremental
--compile ${ARG_INPUT}
)
add_custom_command(
TARGET HPL_SHADERS
MAIN_DEPENDENCY
Expand All @@ -303,7 +316,7 @@ function(fsl_compile)
${shader_resources}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMAND ${CMAKE_COMMAND} -E env "VULKAN_SDK=$ENV{VULKAN_SDK}" "python3" "${FSL_COMPILER}"
-l VULKAN
-l VULKAN
-d ${CMAKE_CURRENT_BINARY_DIR}/Shaders/
--verbose
-b ${CMAKE_CURRENT_BINARY_DIR}/CompiledShaders/
Expand Down
30 changes: 25 additions & 5 deletions HPL2/core/include/graphics/RendererDeferred.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
#include <array>
#include <cstdint>
#include <memory>
#include <stdint.h>
#include <unordered_map>
#include <vector>

Expand Down Expand Up @@ -79,7 +80,7 @@ namespace hpl {
static constexpr uint32_t MaxObjectUniforms = 4096;
static constexpr uint32_t MaxLightUniforms = 1024;
static constexpr uint32_t MaxHiZMipLevels = 32;
static constexpr uint32_t MaxMaterialFrameDescriptors = 1024;
static constexpr uint32_t MaxMaterialFrameDescriptors = 256;


enum LightConfiguration { HasGoboMap = 0x1, HasShadowMap = 0x2 };
Expand Down Expand Up @@ -156,6 +157,26 @@ namespace hpl {
float2 viewportSize;
};

struct UniformFogData {
mat4 m_mvp;
mat4 m_mv;
mat4 m_invModelRotation;
float4 m_color;
float4 m_rayCastStart;
float4 m_fogNegPlaneDistNeg;
float4 m_fogNegPlaneDistPos;
float m_start;
float m_length;
float m_falloffExp;
};

struct UniformFullscreenFogData {
float4 m_color;
float m_fogStart;
float m_fogLength;
float m_fogFalloffExp;
};

class ShadowMapData {
public:
ForgeRenderTarget m_target;
Expand Down Expand Up @@ -354,11 +375,10 @@ namespace hpl {
void cmdBindMaterialDescriptor(Cmd* cmd, const ForgeRenderer::Frame& frame, cMaterial* apMaterial);
void cmdBindObjectDescriptor(Cmd* cmd, const ForgeRenderer::Frame& frame, cMaterial* apMaterial, iRenderable* apObject, const PerObjectOption& option);

void cmdBindMaterialAndObject(Cmd* cmd,
uint32_t cmdBindMaterialAndObject(Cmd* cmd,
const ForgeRenderer::Frame& frame,
cMaterial* apMaterial,
iRenderable* apObject,
std::function<void(uint32_t)> objectIndexHandle,
const PerObjectOption& option);

std::array<std::unique_ptr<iVertexBuffer>, eDeferredShapeQuality_LastEnum> m_shapeSphere;
Expand Down Expand Up @@ -387,7 +407,7 @@ namespace hpl {
ForgeTextureHandle m_ssaoScatterDiskTexture;

Image* m_dissolveImage;
ForgeBufferHandle m_perFrameBuffer;
std::array<ForgeBufferHandle, MaxMaterialFrameDescriptors> m_perFrameBuffer;

// decal pass
std::array<Pipeline*, eMaterialBlendMode_LastEnum> m_decalPipeline;
Expand Down Expand Up @@ -623,7 +643,7 @@ namespace hpl {
iRenderable* m_renderable = nullptr;
};
struct UniformPropBlock {
static constexpr uint32_t MaxObjectTest = 32768;
static constexpr uint32_t MaxObjectTest = 2048;
mat4 viewProjeciton;
uint32_t numObjects;
uint32_t maxMipLevel;
Expand Down
2 changes: 1 addition & 1 deletion HPL2/core/resource/dds_enemy_glow.frag.fsl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ STRUCT(PsIn)
DATA(float3, normal, NORMAL);
};

RES(Tex2D(float4), diffuseMap, UPDATE_FREQ_PER_FRAME, t1, binding = 1);
RES(Tex2D(float4), diffuseMap, UPDATE_FREQ_PER_FRAME, t0, binding = 1);
RES(SamplerState, diffuseSampler, UPDATE_FREQ_NONE, s0, binding = 2);

float4 PS_MAIN(PsIn In)
Expand Down
2 changes: 1 addition & 1 deletion HPL2/core/resource/dds_flash.frag.fsl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ CBUFFER(uniformBlock, UPDATE_FREQ_PER_FRAME, b0, binding = 0) {
DATA(float3x3, normalMat, None);
};

RES(Tex2D(float4), diffuseMap, UPDATE_FREQ_PER_FRAME, t1, binding = 1);
RES(Tex2D(float4), diffuseMap, UPDATE_FREQ_PER_FRAME, t0, binding = 1);
RES(SamplerState, diffuseSampler, UPDATE_FREQ_NONE, s0, binding = 2);

float4 PS_MAIN(PsIn In)
Expand Down
2 changes: 1 addition & 1 deletion HPL2/core/resource/dds_outline_stencil.frag.fsl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ STRUCT(PsIn)
DATA(float2, uv, TEXCOORD0);
};

RES(Tex2D(float4), diffuseMap, UPDATE_FREQ_PER_FRAME, t1, binding = 1);
RES(Tex2D(float4), diffuseMap, UPDATE_FREQ_PER_FRAME, t0, binding = 1);
RES(SamplerState, diffuseSampler, UPDATE_FREQ_NONE, s0, binding = 2);

float4 PS_MAIN(PsIn In)
Expand Down
6 changes: 3 additions & 3 deletions HPL2/core/resource/decal.vert.fsl
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,16 @@ STRUCT(VSOutput)
DATA(float2, uv, TEXCOORD0);
};

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

float4x4 modelView = mul(Get(viewMat), Get(uniformObjectBuffer)[Get(objectIndex)].modelMat);
float4x4 modelView = mul(Get(viewMat), Get(uniformObjectBuffer)[InstanceID].modelMat);
float4x4 modelViewPrj = mul(Get(projMat), modelView);

VSOutput Out;
Out.color = In.Color;
Out.uv = mul(Get(uniformObjectBuffer)[Get(objectIndex)].uvMat, float4(In.TexCoord, 0, 1.0)).xy;
Out.uv = mul(Get(uniformObjectBuffer)[InstanceID].uvMat, float4(In.TexCoord, 0, 1.0)).xy;
Out.Position = mul(modelViewPrj, float4(In.Position.xyz, 1.0));
RETURN(Out);
}
24 changes: 1 addition & 23 deletions HPL2/core/resource/deferred_fog.frag.fsl
Original file line number Diff line number Diff line change
@@ -1,28 +1,7 @@
/// Copyright © 2009-2020 Frictional Games
/// Copyright 2023 Michael Pollind
/// SPDX-License-Identifier: GPL-3.0
PUSH_CONSTANT(uRootConstants, b0)
{
DATA(float2, viewTexel, None);
};

STRUCT(UniformFog) {
DATA(float4x4, mvp, None);
DATA(float4x4, mv, None);
DATA(float4x4, invViewModelRotation, None);
DATA(float4, fogColor, None);
DATA(float4, rayCastStart, None);
DATA(float4, fogNegPlaneDistNeg, None);
DATA(float4, fogNegPlaneDistPos, None);
DATA(float, start, None);
DATA(float, len, None);
DATA(float, falloffExp, None);
DATA(uint, flags, None);
};
RES(Buffer(UniformFog), uniformFogBuffer, UPDATE_FREQ_PER_FRAME, t1, binding = 0);

RES(Tex2D(float4), positionMap, UPDATE_FREQ_PER_FRAME, t1, binding = 2);
RES(SamplerState, nearestSampler, UPDATE_FREQ_NONE, s1, binding = 3);
#include "deferred_fog.resource.h.fsl"

STRUCT(PsIn)
{
Expand Down Expand Up @@ -54,7 +33,6 @@ float GetPlaneIntersection(uint InstanceID, float3 ray, float3 avPlaneNormal, fl
float4 PS_MAIN(PsIn In)
{
INIT_MAIN;


float2 ndc = In.Position.xy * Get(viewTexel);
float fDepth = -SampleTex2D(Get(positionMap), Get(nearestSampler), ndc).z;
Expand Down
31 changes: 31 additions & 0 deletions HPL2/core/resource/deferred_fog.resource.h.fsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
PUSH_CONSTANT(uRootConstants, b0)
{
DATA(float2, viewTexel, None);
};

STRUCT(UniformFog) {
DATA(float4x4, mvp, None);
DATA(float4x4, mv, None);
DATA(float4x4, invViewModelRotation, None);
DATA(float4, fogColor, None);
DATA(float4, rayCastStart, None);
DATA(float4, fogNegPlaneDistNeg, None);
DATA(float4, fogNegPlaneDistPos, None);
DATA(float, start, None);
DATA(float, len, None);
DATA(float, falloffExp, None);
DATA(uint, flags, None);
};
RES(SamplerState, nearestSampler, UPDATE_FREQ_NONE, s0, binding = 3);
RES(Tex2D(float4), positionMap, UPDATE_FREQ_PER_FRAME, t0, binding = 2);
RES(Buffer(UniformFog), uniformFogBuffer, UPDATE_FREQ_PER_FRAME, t1, binding = 0);

CBUFFER(uniformFogFullscreen, UPDATE_FREQ_PER_FRAME, b1, binding = 1)
{
DATA(float4, color, None);
DATA(float, fogStart, None);
DATA(float, fogLength, None);
DATA(float, falloffExp, None);
};


15 changes: 1 addition & 14 deletions HPL2/core/resource/deferred_fog.vert.fsl
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,7 @@
/// Copyright 2023 Michael Pollind
/// SPDX-License-Identifier: GPL-3.0

STRUCT(UniformFog) {
DATA(float4x4, mvp, None);
DATA(float4x4, mv, None);
DATA(float4x4, invViewModelRotation, None);
DATA(float4, fogColor, None);
DATA(float4, rayCastStart, None);
DATA(float4, fogNegPlaneDistNeg, None);
DATA(float4, fogNegPlaneDistPos, None);
DATA(float, start, None);
DATA(float, len, None);
DATA(float, falloffExp, None);
DATA(uint, flags, None);
};
RES(Buffer(UniformFog), uniformFogBuffer, UPDATE_FREQ_PER_FRAME, t1, binding = 0);
#include "deferred_fog.resource.h.fsl"

STRUCT(VSInput)
{
Expand Down
14 changes: 3 additions & 11 deletions HPL2/core/resource/deferred_fog_fullscreen.frag.fsl
Original file line number Diff line number Diff line change
@@ -1,23 +1,15 @@
/// Copyright © 2009-2020 Frictional Games
/// Copyright 2023 Michael Pollind
/// SPDX-License-Identifier: GPL-3.0

#include "deferred_fog.resource.h.fsl"

STRUCT(PsIn)
{
DATA(float4, Position, SV_Position);
DATA(float2, uv, TEXCOORD0);
};

CBUFFER(uniformFogFullscreen, UPDATE_FREQ_PER_FRAME, b1, binding = 1)
{
DATA(float4, color, None);
DATA(float, fogStart, None);
DATA(float, fogLength, None);
DATA(float, falloffExp, None);
};

RES(Tex2D(float4), positionMap, UPDATE_FREQ_PER_FRAME, t1, binding = 2);
RES(SamplerState, nearestSampler, UPDATE_FREQ_NONE, s1, binding = 3);

float4 PS_MAIN(PsIn In)
{
INIT_MAIN;
Expand Down
2 changes: 1 addition & 1 deletion HPL2/core/resource/deferred_light_spotlight.frag.fsl
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ float4 PS_MAIN(PsIn In)
float fShadowSum = 0.0;
float fJitterZ = 0.0;
float2 vScreenJitterCoord = In.Position.xy * (1.0 / float(SHADOW_JITTER_SIZE));
vScreenJitterCoord.y = fract(vScreenJitterCoord.y); //Make sure the coord is in 0 - 1 range
vScreenJitterCoord.y = frac(vScreenJitterCoord.y); //Make sure the coord is in 0 - 1 range
vScreenJitterCoord.y *= 1.0 / (float(SHADOW_JITTER_SAMPLES)/2.0); //Access only first texture piece

for(int i=0; i < 2; i++)
Expand Down
Loading