forked from doodlum/skyrim-community-shaders
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDistantTree.hlsl
165 lines (134 loc) · 3.82 KB
/
DistantTree.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
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
struct VS_INPUT
{
float3 Position : POSITION0;
float2 TexCoord0 : TEXCOORD0;
float4 InstanceData1 : TEXCOORD4;
float4 InstanceData2 : TEXCOORD5;
float4 InstanceData3 : TEXCOORD6;
float4 InstanceData4 : TEXCOORD7;
};
struct VS_OUTPUT
{
float4 Position : SV_POSITION0;
float3 TexCoord : TEXCOORD0;
#if defined(RENDER_DEPTH)
float4 Depth : TEXCOORD3;
#else
float4 WorldPosition : POSITION1;
float4 PreviousWorldPosition : POSITION2;
#endif
};
#ifdef VSHADER
cbuffer PerTechnique : register(b0)
{
float4 FogParam : packoffset(c0);
};
cbuffer PerGeometry : register(b2)
{
row_major float4x4 WorldViewProj : packoffset(c0);
row_major float4x4 World : packoffset(c4);
row_major float4x4 PreviousWorld : packoffset(c8);
};
VS_OUTPUT main(VS_INPUT input)
{
VS_OUTPUT vsout;
float3 scaledModelPosition = input.InstanceData1.www * input.Position.xyz;
float3 adjustedModelPosition = 0.0.xxx;
adjustedModelPosition.x = dot(float2(1, -1) * input.InstanceData2.xy, scaledModelPosition.xy);
adjustedModelPosition.y = dot(input.InstanceData2.yx, scaledModelPosition.xy);
adjustedModelPosition.z = scaledModelPosition.z;
float4 finalModelPosition = float4(input.InstanceData1.xyz + adjustedModelPosition.xyz, 1.0);
float4 viewPosition = mul(WorldViewProj, finalModelPosition);
# ifdef RENDER_DEPTH
vsout.Depth.xy = viewPosition.zw;
vsout.Depth.zw = input.InstanceData2.zw;
# else
vsout.WorldPosition = mul(World, finalModelPosition);
vsout.PreviousWorldPosition = mul(PreviousWorld, finalModelPosition);
# endif
vsout.Position = viewPosition;
vsout.TexCoord = float3(input.TexCoord0.xy, FogParam.z);
return vsout;
}
#endif
typedef VS_OUTPUT PS_INPUT;
struct PS_OUTPUT
{
float4 Albedo : SV_Target0;
#if !defined(RENDER_DEPTH)
float2 MotionVector : SV_Target1;
float4 Normal : SV_Target2;
#endif
};
#ifdef PSHADER
SamplerState SampDiffuse : register(s0);
Texture2D<float4> TexDiffuse : register(t0);
cbuffer AlphaTestRefCB : register(b11)
{
float AlphaTestRefRS : packoffset(c0);
}
cbuffer PerFrame : register(b12)
{
float4 UnknownPerFrame1[12] : packoffset(c0);
row_major float4x4 ScreenProj : packoffset(c12);
row_major float4x4 PreviousScreenProj : packoffset(c16);
}
cbuffer PerTechnique : register(b0)
{
float4 DiffuseColor : packoffset(c0);
float4 AmbientColor : packoffset(c1);
};
const static float DepthOffsets[16] = {
0.003921568,
0.533333361,
0.133333340,
0.666666687,
0.800000000,
0.266666681,
0.933333337,
0.400000000,
0.200000000,
0.733333349,
0.066666670,
0.600000000,
0.996078432,
0.466666669,
0.866666675,
0.333333343
};
PS_OUTPUT main(PS_INPUT input)
{
PS_OUTPUT psout;
# if defined(RENDER_DEPTH)
uint2 temp = uint2(input.Position.xy);
uint index = ((temp.x << 2) & 12) | (temp.y & 3);
float depthOffset = 0.5 - DepthOffsets[index];
float depthModifier = (input.Depth.w * depthOffset) + input.Depth.z - 0.5;
if (depthModifier < 0) {
discard;
}
float alpha = TexDiffuse.Sample(SampDiffuse, input.TexCoord.xy).w;
if ((alpha - AlphaTestRefRS) < 0) {
discard;
}
psout.Albedo.xyz = input.Depth.xxx / input.Depth.yyy;
psout.Albedo.w = 0;
# else
float4 baseColor = TexDiffuse.Sample(SampDiffuse, input.TexCoord.xy);
# if defined(DO_ALPHA_TEST)
if ((baseColor.w - AlphaTestRefRS) < 0) {
discard;
}
# endif
psout.Albedo = float4((input.TexCoord.zzz * DiffuseColor.xyz + AmbientColor.xyz) * baseColor.xyz, 1.0);
float4 screenPosition = mul(ScreenProj, input.WorldPosition);
screenPosition.xy = screenPosition.xy / screenPosition.ww;
float4 previousScreenPosition = mul(PreviousScreenProj, input.PreviousWorldPosition);
previousScreenPosition.xy = previousScreenPosition.xy / previousScreenPosition.ww;
float2 screenMotionVector = float2(-0.5, 0.5) * (screenPosition.xy - previousScreenPosition.xy);
psout.MotionVector = screenMotionVector;
psout.Normal = float4(0.5, 0.5, 0, 0);
# endif
return psout;
}
#endif