-
Notifications
You must be signed in to change notification settings - Fork 0
/
vs_gbuffer.hlsl
74 lines (58 loc) · 2.07 KB
/
vs_gbuffer.hlsl
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
#pragma pack_matrix( row_major )
ByteAddressBuffer matrix_buffer : register(t0);
struct ModelViewProjection
{
matrix MVP;
};
ConstantBuffer<ModelViewProjection> ModelViewProjectionCB : register(b0);
ConstantBuffer<ModelViewProjection> test : register(b1);
struct VertexPosColor
{
float3 Position : POSITION;
float3 normal : NORMAL;
float2 UV : TEXCOORD;
};
struct VertexShaderOutput
{
float4 position : SV_Position;
float4 Color : COLOR;
float2 UV : TEXCOORD0;
float3 normal : NORMAL;
float4 frag_p : TEXCOORD1;
};
VertexShaderOutput main(VertexPosColor IN)
{
VertexShaderOutput OUT;
uint offset = (uint)ModelViewProjectionCB.MVP[0][0];
float4 m0 = asfloat(matrix_buffer.Load4(offset + 0));
float4 m1 = asfloat(matrix_buffer.Load4(offset + 16));
float4 m2 = asfloat(matrix_buffer.Load4(offset + 32));
float4 m3 = asfloat(matrix_buffer.Load4(offset + 48));
matrix m = { m0.x,m0.y,m0.z,m0.w,
m1.x,m1.y,m1.z,m1.w,
m2.x,m2.y,m2.z,m2.w,
m3.x,m3.y,m3.z,m3.w};
uint mmoffset = (uint)ModelViewProjectionCB.MVP[0][1];
float4 mm0 = asfloat(matrix_buffer.Load4(mmoffset + 0));
float4 mm1 = asfloat(matrix_buffer.Load4(mmoffset + 16));
float4 mm2 = asfloat(matrix_buffer.Load4(mmoffset + 32));
float4 mm3 = asfloat(matrix_buffer.Load4(mmoffset + 48));
matrix mm = { mm0.x,mm0.y,mm0.z,mm0.w,
mm1.x,mm1.y,mm1.z,mm1.w,
mm2.x,mm2.y,mm2.z,mm2.w,
mm3.x,mm3.y,mm3.z,mm3.w};
float3x3 mm3x3 = { mm0.x,mm0.y,mm0.z,
mm1.x,mm1.y,mm1.z,
mm2.x,mm2.y,mm2.z};
float4 p = mul(float4(IN.Position,1.0f),m);
float4 world_p = mul(float4(IN.Position,1.0f),mm);
OUT.position = p;
OUT.frag_p = world_p;
float4 fake_light_p = float4(0,0,0,1);
OUT.Color = (mul(fake_light_p,mm));//float4(1,1,1,1);
OUT.UV = IN.UV;
float3 n = IN.normal;
OUT.normal = mul(n,mm3x3);
//OUT.normal = normalize(n);//normalize(mul(float4(n,0),mm3).xyz);
return OUT;
}