Skip to content

Commit

Permalink
removal of the pos3D interpolator (#953)
Browse files Browse the repository at this point in the history
  • Loading branch information
turanszkij authored Oct 3, 2024
1 parent b2835b4 commit 52b3c69
Show file tree
Hide file tree
Showing 41 changed files with 293 additions and 476 deletions.
2 changes: 2 additions & 0 deletions Editor/CameraWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ void CameraWindow::ResetCam()

editorscene.camera_target.ClearTransform();
editorscene.camera_target.UpdateTransform();

orthoCheckBox.SetCheck(camera.IsOrtho());
}

void CameraWindow::Create(EditorComponent* _editor)
Expand Down
10 changes: 0 additions & 10 deletions WickedEngine/offlineshadercompiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -319,15 +319,8 @@ wi::vector<ShaderEntry> shaders = {
{"forceFieldPlaneVisualizerVS", wi::graphics::ShaderStage::VS },
{"envMap_skyVS", wi::graphics::ShaderStage::VS },
{"envMapVS", wi::graphics::ShaderStage::VS },
{"envMap_skyVS_emulation", wi::graphics::ShaderStage::VS },
{"envMapVS_emulation", wi::graphics::ShaderStage::VS },
{"occludeeVS", wi::graphics::ShaderStage::VS },
{"ddgi_debugVS", wi::graphics::ShaderStage::VS },
{"envMap_skyGS_emulation", wi::graphics::ShaderStage::GS },
{"envMapGS_emulation", wi::graphics::ShaderStage::GS },
{"shadowGS_emulation", wi::graphics::ShaderStage::GS },
{"shadowGS_alphatest_emulation", wi::graphics::ShaderStage::GS },
{"shadowGS_transparent_emulation", wi::graphics::ShaderStage::GS },
{"objectGS_primitiveID_emulation", wi::graphics::ShaderStage::GS },
{"objectGS_primitiveID_emulation_alphatest", wi::graphics::ShaderStage::GS },
{"voxelGS", wi::graphics::ShaderStage::GS },
Expand All @@ -342,10 +335,7 @@ wi::vector<ShaderEntry> shaders = {
{"objectVS_simple_tessellation", wi::graphics::ShaderStage::VS },
{"shadowVS", wi::graphics::ShaderStage::VS },
{"shadowVS_alphatest", wi::graphics::ShaderStage::VS },
{"shadowVS_emulation", wi::graphics::ShaderStage::VS },
{"shadowVS_alphatest_emulation", wi::graphics::ShaderStage::VS },
{"shadowVS_transparent", wi::graphics::ShaderStage::VS },
{"shadowVS_transparent_emulation", wi::graphics::ShaderStage::VS },
{"screenVS", wi::graphics::ShaderStage::VS },
{"trailVS", wi::graphics::ShaderStage::VS },

Expand Down
60 changes: 55 additions & 5 deletions WickedEngine/shaders/ShaderInterop_Renderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -742,11 +742,11 @@ struct alignas(16) ShaderEntity

#ifndef __cplusplus
// Shader-side:
inline uint GetType()
inline min16uint GetType()
{
return type8_flags8_range16 & 0xFF;
}
inline uint GetFlags()
inline min16uint GetFlags()
{
return (type8_flags8_range16 >> 8u) & 0xFF;
}
Expand Down Expand Up @@ -774,7 +774,7 @@ struct alignas(16) ShaderEntity
{
return (half)f16tof32(direction16_coneAngleCos16.y >> 16u);
}
inline uint GetShadowCascadeCount()
inline min16uint GetShadowCascadeCount()
{
return direction16_coneAngleCos16.y >> 16u;
}
Expand Down Expand Up @@ -803,11 +803,11 @@ struct alignas(16) ShaderEntity
retVal.w = (half)f16tof32(color.y >> 16u);
return retVal;
}
inline uint GetMatrixIndex()
inline min16uint GetMatrixIndex()
{
return indices & 0xFFFF;
}
inline uint GetTextureIndex()
inline min16uint GetTextureIndex()
{
return indices >> 16u;
}
Expand Down Expand Up @@ -926,6 +926,32 @@ struct alignas(16) ShaderFrustum
#endif // __cplusplus
};

struct alignas(16) ShaderFrustumCorners
{
// topleft, topright, bottomleft, bottomright
float4 cornersNEAR[4];
float4 cornersFAR[4];

#ifndef __cplusplus
inline float3 screen_to_nearplane(float2 uv)
{
float3 posTOP = lerp(cornersNEAR[0], cornersNEAR[1], uv.x);
float3 posBOTTOM = lerp(cornersNEAR[2], cornersNEAR[3], uv.x);
return lerp(posTOP, posBOTTOM, uv.y);
}
inline float3 screen_to_farplane(float2 uv)
{
float3 posTOP = lerp(cornersFAR[0], cornersFAR[1], uv.x);
float3 posBOTTOM = lerp(cornersFAR[2], cornersFAR[3], uv.x);
return lerp(posTOP, posBOTTOM, uv.y);
}
inline float3 screen_to_world(float2 uv, float lineardepthNormalized)
{
return lerp(screen_to_nearplane(uv), screen_to_farplane(uv), lineardepthNormalized);
}
#endif // __cplusplus
};

enum SHADER_ENTITY_TYPE
{
ENTITY_TYPE_DIRECTIONALLIGHT,
Expand Down Expand Up @@ -1159,6 +1185,7 @@ struct alignas(16) ShaderCamera
float4x4 inverse_view_projection;

ShaderFrustum frustum;
ShaderFrustumCorners frustum_corners;

float2 temporalaa_jitter;
float2 temporalaa_jitter_prev;
Expand Down Expand Up @@ -1314,6 +1341,29 @@ struct alignas(16) ShaderCamera
{
return pixel.x >= scissor.x && pixel.x <= scissor.z && pixel.y >= scissor.y && pixel.y <= scissor.w;
}

inline bool IsOrtho() { return options & SHADERCAMERA_OPTION_ORTHO; }

inline float3 screen_to_nearplane(float4 svposition)
{
const float2 ScreenCoord = svposition.xy * internal_resolution_rcp;
return frustum_corners.screen_to_nearplane(ScreenCoord);
}
inline float3 screen_to_farplane(float4 svposition)
{
const float2 ScreenCoord = svposition.xy * internal_resolution_rcp;
return frustum_corners.screen_to_farplane(ScreenCoord);
}

// Convert raw screen coordinate from rasterizer to world position
// Note: svposition is the SV_Position system value, the .w component can be different in different compilers
// You need to ensure that the .w component is used for linear depth (Vulkan: -fvk-use-dx-position-w, Xbox: there is a define to pass SV_Position ZW via attribute)
inline float3 screen_to_world(float4 svposition)
{
const float2 ScreenCoord = svposition.xy * internal_resolution_rcp;
const float z = IsOrtho() ? (1 - svposition.z) : inverse_lerp(z_near, z_far, svposition.w);
return frustum_corners.screen_to_world(ScreenCoord, z);
}
#endif // __cplusplus
};

Expand Down
55 changes: 0 additions & 55 deletions WickedEngine/shaders/Shaders_SOURCE.vcxitems
Original file line number Diff line number Diff line change
Expand Up @@ -479,39 +479,6 @@
<FxCompile Include="$(MSBuildThisFileDirectory)screenVS.hlsl">
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Vertex</ShaderType>
</FxCompile>
<FxCompile Include="$(MSBuildThisFileDirectory)shadowGS_alphatest_emulation.hlsl">
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Geometry</ShaderType>
<ShaderModel Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">5.0</ShaderModel>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Geometry</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Geometry</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">Geometry</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">Geometry</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Geometry</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">Geometry</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">Geometry</ShaderType>
</FxCompile>
<FxCompile Include="$(MSBuildThisFileDirectory)shadowGS_emulation.hlsl">
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Geometry</ShaderType>
<ShaderModel Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">5.0</ShaderModel>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Geometry</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Geometry</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">Geometry</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">Geometry</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Geometry</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">Geometry</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">Geometry</ShaderType>
</FxCompile>
<FxCompile Include="$(MSBuildThisFileDirectory)shadowGS_transparent_emulation.hlsl">
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Geometry</ShaderType>
<ShaderModel Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">5.0</ShaderModel>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Geometry</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Geometry</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">Geometry</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">Geometry</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Geometry</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">Geometry</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">Geometry</ShaderType>
</FxCompile>
<FxCompile Include="$(MSBuildThisFileDirectory)shadowMS.hlsl">
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Compute</ShaderType>
<ShaderModel Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">4.0</ShaderModel>
Expand Down Expand Up @@ -756,17 +723,6 @@
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">Pixel</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">Pixel</ShaderType>
</FxCompile>
<FxCompile Include="$(MSBuildThisFileDirectory)envMapGS_emulation.hlsl">
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Geometry</ShaderType>
<ShaderModel Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">5.0</ShaderModel>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Geometry</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Geometry</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">Geometry</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">Geometry</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Geometry</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">Geometry</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">Geometry</ShaderType>
</FxCompile>
<FxCompile Include="$(MSBuildThisFileDirectory)envMapVS_emulation.hlsl">
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Vertex</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Vertex</ShaderType>
Expand All @@ -777,17 +733,6 @@
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">Vertex</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">Vertex</ShaderType>
</FxCompile>
<FxCompile Include="$(MSBuildThisFileDirectory)envMap_skyGS_emulation.hlsl">
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Geometry</ShaderType>
<ShaderModel Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">5.0</ShaderModel>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Geometry</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Geometry</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">Geometry</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">Geometry</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Geometry</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">Geometry</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">Geometry</ShaderType>
</FxCompile>
<FxCompile Include="$(MSBuildThisFileDirectory)envMap_skyVS_emulation.hlsl">
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Vertex</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Vertex</ShaderType>
Expand Down
15 changes: 0 additions & 15 deletions WickedEngine/shaders/Shaders_SOURCE.vcxitems.filters
Original file line number Diff line number Diff line change
Expand Up @@ -776,18 +776,6 @@
<FxCompile Include="$(MSBuildThisFileDirectory)envMap_skyVS_emulation.hlsl">
<Filter>VS</Filter>
</FxCompile>
<FxCompile Include="$(MSBuildThisFileDirectory)shadowGS_emulation.hlsl">
<Filter>GS</Filter>
</FxCompile>
<FxCompile Include="$(MSBuildThisFileDirectory)shadowGS_alphatest_emulation.hlsl">
<Filter>GS</Filter>
</FxCompile>
<FxCompile Include="$(MSBuildThisFileDirectory)envMapGS_emulation.hlsl">
<Filter>GS</Filter>
</FxCompile>
<FxCompile Include="$(MSBuildThisFileDirectory)envMap_skyGS_emulation.hlsl">
<Filter>GS</Filter>
</FxCompile>
<FxCompile Include="$(MSBuildThisFileDirectory)skyAtmosphere_transmittanceLutCS.hlsl">
<Filter>CS</Filter>
</FxCompile>
Expand All @@ -803,9 +791,6 @@
<FxCompile Include="$(MSBuildThisFileDirectory)shadowVS_transparent_emulation.hlsl">
<Filter>VS</Filter>
</FxCompile>
<FxCompile Include="$(MSBuildThisFileDirectory)shadowGS_transparent_emulation.hlsl">
<Filter>GS</Filter>
</FxCompile>
<FxCompile Include="$(MSBuildThisFileDirectory)rtshadow_denoise_temporalCS.hlsl">
<Filter>CS</Filter>
</FxCompile>
Expand Down
9 changes: 5 additions & 4 deletions WickedEngine/shaders/captureImpostorPS.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,11 @@ ImpostorOutput main(PixelInput input)
clip(color.a - material.GetAlphaTest());

float3 N = normalize(input.nor);
float3 P = input.pos3D;

float3x3 TBN = compute_tangent_frame(N, P, uvsets.xy);


input.tan.w = input.tan.w < 0 ? -1 : 1;
half3 bitangent = cross(input.tan.xyz, input.nor) * input.tan.w;
float3x3 TBN = float3x3(input.tan.xyz, bitangent, input.nor); // unnormalized TBN! http://www.mikktspace.com/

[branch]
if (material.textures[NORMALMAP].IsValid())
{
Expand Down
11 changes: 10 additions & 1 deletion WickedEngine/shaders/emittedparticleHF.hlsli
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,20 @@ struct VertextoPixel
float4 pos : SV_POSITION;
float clip : SV_ClipDistance0;
float4 tex : TEXCOORD0;
float3 P : WORLDPOSITION;
half2 unrotated_uv : UNROTATED_UV;
nointerpolation half frameBlend : FRAMEBLEND;
nointerpolation half size : PARTICLESIZE;
nointerpolation uint color : PARTICLECOLOR;

inline float3 GetPos3D()
{
return GetCamera().screen_to_world(pos);
}

inline float3 GetViewVector()
{
return GetCamera().screen_to_nearplane(pos) - GetPos3D(); // ortho support, cannot use cameraPos!
}
};

#endif // WI_EMITTEDPARTICLE_HF
2 changes: 0 additions & 2 deletions WickedEngine/shaders/emittedparticleMS.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ struct VertextoPixel_MS
float4 pos : SV_POSITION;
float clip : SV_ClipDistance0;
half4 tex : TEXCOORD0;
float3 P : WORLDPOSITION;
half2 unrotated_uv : UNROTATED_UV;
};
struct VertextoPixel_MS_PRIM
Expand Down Expand Up @@ -81,7 +80,6 @@ void main(
float4 uvsets = bindless_buffers_float4[geometry.vb_uvs][vertexID];

VertextoPixel_MS Out;
Out.P = position;
Out.clip = dot(Out.pos, GetCamera().clip_plane);
Out.tex = half4(uvsets);
Out.pos = mul(GetCamera().view_projection, float4(position, 1));
Expand Down
8 changes: 5 additions & 3 deletions WickedEngine/shaders/emittedparticlePS_soft.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@ static const uint SLOT = BASECOLORMAP;
[earlydepthstencil]
float4 main(VertextoPixel input) : SV_TARGET
{
float3 pos3D = input.GetPos3D();

// Blocker shadow map check:
[branch]
if ((xEmitterOptions & EMITTER_OPTION_BIT_USE_RAIN_BLOCKER) && rain_blocker_check(input.P))
if ((xEmitterOptions & EMITTER_OPTION_BIT_USE_RAIN_BLOCKER) && rain_blocker_check(pos3D))
{
return 0;
}
Expand Down Expand Up @@ -102,7 +104,7 @@ float4 main(VertextoPixel input) : SV_TARGET
N = mul((float3x3)GetCamera().inverse_view, N);
N = normalize(N);

float3 V = GetCamera().position - input.P;
float3 V = input.GetViewVector();
float dist = length(V);
V /= dist;

Expand All @@ -112,7 +114,7 @@ float4 main(VertextoPixel input) : SV_TARGET
Surface surface;
surface.init();
surface.create(material, color, surfacemap_simple);
surface.P = input.P;
surface.P = pos3D;
surface.N = N;
surface.V = V;
surface.pixel = pixel;
Expand Down
1 change: 0 additions & 1 deletion WickedEngine/shaders/emittedparticleVS.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ VertextoPixel main(uint vid : SV_VertexID, uint instanceID : SV_InstanceID)
const float frameBlend = frac(spriteframe);

VertextoPixel Out;
Out.P = position;
Out.pos = float4(position, 1);
Out.clip = dot(Out.pos, GetCamera().clip_plane);
Out.pos = mul(GetCamera().view_projection, Out.pos);
Expand Down
54 changes: 0 additions & 54 deletions WickedEngine/shaders/envMapGS_emulation.hlsl

This file was deleted.

Loading

0 comments on commit 52b3c69

Please sign in to comment.