-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgbufferfeedback_vs.hlsl
More file actions
113 lines (98 loc) · 4.63 KB
/
gbufferfeedback_vs.hlsl
File metadata and controls
113 lines (98 loc) · 4.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/*
* SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
* SPDX-License-Identifier: LicenseRef-NvidiaProprietary
*
* NVIDIA CORPORATION, its affiliates and licensors retain all intellectual
* property and proprietary rights in and to this material, related
* documentation and any modifications thereto. Any use, reproduction,
* disclosure or distribution of this material and related documentation
* without an express license agreement from NVIDIA CORPORATION or
* its affiliates is strictly prohibited.
*/
#pragma pack_matrix(row_major)
#include <donut/shaders/bindless.h>
#include <donut/shaders/forward_vertex.hlsli>
#include <donut/shaders/gbuffer_cb.h>
#include <donut/shaders/binding_helpers.hlsli>
#include <donut/shaders/packing.hlsli>
DECLARE_CBUFFER(GBufferFillConstants, c_GBuffer, GBUFFER_BINDING_VIEW_CONSTANTS, GBUFFER_SPACE_VIEW);
void input_assembler(
in SceneVertex i_vtx,
in float4 i_instanceMatrix0 : TRANSFORM0,
in float4 i_instanceMatrix1 : TRANSFORM1,
in float4 i_instanceMatrix2 : TRANSFORM2,
#if MOTION_VECTORS
in float4 i_prevInstanceMatrix0 : PREV_TRANSFORM0,
in float4 i_prevInstanceMatrix1 : PREV_TRANSFORM1,
in float4 i_prevInstanceMatrix2 : PREV_TRANSFORM2,
#endif
in uint i_instance : SV_InstanceID,
out float4 o_position : SV_Position,
out SceneVertex o_vtx,
out uint o_instance : INSTANCE
)
{
float3x4 instanceMatrix = float3x4(i_instanceMatrix0, i_instanceMatrix1, i_instanceMatrix2);
o_vtx = i_vtx;
o_vtx.pos = mul(instanceMatrix, float4(i_vtx.pos, 1.0)).xyz;
o_vtx.normal = mul(instanceMatrix, float4(i_vtx.normal, 0)).xyz;
o_vtx.tangent.xyz = mul(instanceMatrix, float4(i_vtx.tangent.xyz, 0)).xyz;
o_vtx.tangent.w = i_vtx.tangent.w;
#if MOTION_VECTORS
float3x4 prevInstanceMatrix = float3x4(i_prevInstanceMatrix0, i_prevInstanceMatrix1, i_prevInstanceMatrix2);
o_vtx.prevPos = mul(prevInstanceMatrix, float4(i_vtx.prevPos, 1.0)).xyz;
#else
o_vtx.prevPos = o_vtx.pos;
#endif
float4 worldPos = float4(o_vtx.pos, 1.0);
float4 viewPos = mul(worldPos, c_GBuffer.view.matWorldToView);
o_position = mul(viewPos, c_GBuffer.view.matViewToClip);
o_instance = i_instance;
}
// Use a raw buffer on DX11 to avoid adding the StructuredBuffer flag to the instance buffer.
// On DX11, a structured buffer cannot be used as a vertex buffer, and there should be compatibility with other passes.
// On DX12, using a structured buffer results in more optimal code being generated.
#ifdef TARGET_D3D11
ByteAddressBuffer t_Instances : REGISTER_SRV(GBUFFER_BINDING_INSTANCE_BUFFER, GBUFFER_SPACE_INPUT);
#else
StructuredBuffer<InstanceData> t_Instances : REGISTER_SRV(GBUFFER_BINDING_INSTANCE_BUFFER, GBUFFER_SPACE_INPUT);
#endif
ByteAddressBuffer t_Vertices : REGISTER_SRV(GBUFFER_BINDING_VERTEX_BUFFER, GBUFFER_SPACE_INPUT);
DECLARE_PUSH_CONSTANTS(GBufferPushConstants, g_Push, GBUFFER_BINDING_PUSH_CONSTANTS, GBUFFER_SPACE_INPUT);
// Version of the vertex shader that uses buffer loads to read vertex attributes and transforms.
void buffer_loads(
in uint i_vertex : SV_VertexID,
in uint i_instance : SV_InstanceID,
out float4 o_position : SV_Position,
out SceneVertex o_vtx,
out uint o_instance : INSTANCE
)
{
o_instance = i_instance;
i_instance += g_Push.startInstanceLocation;
i_vertex += g_Push.startVertexLocation;
#ifdef TARGET_D3D11
const InstanceData instance = LoadInstanceData(t_Instances, i_instance * c_SizeOfInstanceData);
#else
const InstanceData instance = t_Instances[i_instance];
#endif
float3 pos = asfloat(t_Vertices.Load3(g_Push.positionOffset + i_vertex * c_SizeOfPosition));
float3 prevPos = asfloat(t_Vertices.Load3(g_Push.prevPositionOffset + i_vertex * c_SizeOfPosition));
float2 texCoord = asfloat(t_Vertices.Load2(g_Push.texCoordOffset + i_vertex * c_SizeOfTexcoord));
uint packedNormal = t_Vertices.Load(g_Push.normalOffset + i_vertex * c_SizeOfNormal);
uint packedTangent = t_Vertices.Load(g_Push.tangentOffset + i_vertex * c_SizeOfNormal);
float3 normal = Unpack_RGB8_SNORM(packedNormal);
float4 tangent = Unpack_RGBA8_SNORM(packedTangent);
o_vtx.pos = mul(instance.transform, float4(pos, 1.0)).xyz;
o_vtx.texCoord = texCoord;
o_vtx.normal = mul(instance.transform, float4(normal, 0)).xyz;
o_vtx.tangent.xyz = mul(instance.transform, float4(tangent.xyz, 0)).xyz;
o_vtx.tangent.w = tangent.w;
#if MOTION_VECTORS
o_vtx.prevPos = mul(instance.prevTransform, float4(prevPos, 1.0)).xyz;
#else
o_vtx.prevPos = o_vtx.pos;
#endif
float4 worldPos = float4(o_vtx.pos, 1.0);
o_position = mul(worldPos, c_GBuffer.view.matWorldToClip);
}