Skip to content

Commit dfad3ff

Browse files
SRL: Fix issue with Texture2D_float not recognize on windows + format
1 parent baea68c commit dfad3ff

1 file changed

Lines changed: 145 additions & 146 deletions

File tree

Lines changed: 145 additions & 146 deletions
Original file line numberDiff line numberDiff line change
@@ -1,146 +1,145 @@
1-
#pragma kernel ShadeDeferred_Fptl SHADE_DEFERRED_ENTRY=ShadeDeferred_Fptl USE_FPTL_LIGHTLIST=1 ENABLE_DEBUG=0
2-
#pragma kernel ShadeDeferred_Clustered SHADE_DEFERRED_ENTRY=ShadeDeferred_Clustered USE_CLUSTERED_LIGHTLIST=1 ENABLE_DEBUG=0 //TODO: disabled clustered permutations so far as it leads to the error "All kernels must use same constant buffer layouts"
3-
#pragma kernel ShadeDeferred_Fptl_Debug SHADE_DEFERRED_ENTRY=ShadeDeferred_Fptl_Debug USE_FPTL_LIGHTLIST=1 ENABLE_DEBUG=1
4-
#pragma kernel ShadeDeferred_Clustered_Debug SHADE_DEFERRED_ENTRY=ShadeDeferred_Clustered_Debug USE_CLUSTERED_LIGHTLIST=1 ENABLE_DEBUG=1
5-
6-
#define TILE_SIZE 8
7-
8-
9-
// Hacks to get the header to compile in compute
10-
#define SHADER_TARGET 50
11-
#define UNITY_PBS_USE_BRDF1
12-
#define fixed4 float4
13-
#include "UnityLightingCommon.cginc"
14-
#undef fixed4
15-
16-
float3 EvalMaterial(UnityLight light, UnityIndirect ind);
17-
float3 EvalIndirectSpecular(UnityLight light, UnityIndirect ind);
18-
19-
// uses the optimized single layered light list for opaques only
20-
21-
#ifdef USE_FPTL_LIGHTLIST
22-
#define OPAQUES_ONLY
23-
#endif
24-
25-
#include "TiledLightingTemplate.hlsl"
26-
#include "TiledReflectionTemplate.hlsl"
27-
28-
Texture2D_float _CameraDepthTexture;
29-
Texture2D _CameraGBufferTexture0;
30-
Texture2D _CameraGBufferTexture1;
31-
Texture2D _CameraGBufferTexture2;
32-
Texture2D _CameraGBufferTexture3;
33-
34-
RWTexture2D<float4> uavOutput : register(u0);
35-
36-
struct v2f {
37-
float4 vertex : SV_POSITION;
38-
float2 texcoord : TEXCOORD0;
39-
};
40-
41-
v2f vert(float4 vertex : POSITION, float2 texcoord : TEXCOORD0)
42-
{
43-
v2f o;
44-
o.vertex = UnityObjectToClipPos(vertex);
45-
o.texcoord = texcoord.xy;
46-
return o;
47-
}
48-
49-
struct StandardData
50-
{
51-
float3 specularColor;
52-
float3 diffuseColor;
53-
float3 normalWorld;
54-
float smoothness;
55-
float occlusion;
56-
float3 emission;
57-
};
58-
59-
struct LocalDataBRDF
60-
{
61-
StandardData gbuf;
62-
63-
// extras
64-
float oneMinusReflectivity;
65-
float3 Vworld;
66-
};
67-
68-
static LocalDataBRDF g_localParams;
69-
70-
StandardData UnityStandardDataFromGbufferAux(float4 gbuffer0, float4 gbuffer1, float4 gbuffer2, float4 gbuffer3)
71-
{
72-
StandardData data;
73-
74-
data.normalWorld = normalize(2 * gbuffer2.xyz - 1);
75-
data.smoothness = gbuffer1.a;
76-
data.diffuseColor = gbuffer0.xyz; data.specularColor = gbuffer1.xyz;
77-
data.occlusion = gbuffer0.a;
78-
data.emission = gbuffer3.xyz;
79-
80-
return data;
81-
}
82-
83-
half3 BRDF3_Direct2(half3 diffColor, half3 specColor, half rlPow4, half smoothness)
84-
{
85-
half LUT_RANGE = 16.0; // must match range in NHxRoughness() function in GeneratedTextures.cpp
86-
// Lookup texture to save instructions
87-
half specular = tex2Dlod(unity_NHxRoughness, half4(rlPow4, SmoothnessToPerceptualRoughness(smoothness), 0, 0)).UNITY_ATTEN_CHANNEL * LUT_RANGE;
88-
#if defined(_SPECULARHIGHLIGHTS_OFF)
89-
specular = 0.0;
90-
#endif
91-
92-
return diffColor + specular * specColor;
93-
}
94-
95-
96-
float3 EvalMaterial(UnityLight light, UnityIndirect ind)
97-
{
98-
StandardData data = g_localParams.gbuf;
99-
return UNITY_BRDF_PBS(data.diffuseColor, data.specularColor, g_localParams.oneMinusReflectivity, data.smoothness, data.normalWorld, g_localParams.Vworld, light, ind);
100-
}
101-
102-
float3 EvalIndirectSpecular(UnityLight light, UnityIndirect ind)
103-
{
104-
StandardData data = g_localParams.gbuf;
105-
106-
return data.occlusion * UNITY_BRDF_PBS(0, data.specularColor, g_localParams.oneMinusReflectivity, data.smoothness, data.normalWorld, g_localParams.Vworld, light, ind).rgb;
107-
}
108-
109-
[numthreads(TILE_SIZE, TILE_SIZE, 1)]
110-
void SHADE_DEFERRED_ENTRY(uint2 dispatchThreadId : SV_DispatchThreadID, uint2 groupId : SV_GroupID)
111-
{
112-
uint2 pixCoord = dispatchThreadId;
113-
114-
float zbufDpth = FetchDepth(_CameraDepthTexture, pixCoord.xy).x;
115-
float linDepth = GetLinearDepth(zbufDpth);
116-
117-
float3 vP = GetViewPosFromLinDepth(pixCoord, linDepth);
118-
float3 vPw = mul(g_mViewToWorld, float4(vP, 1)).xyz;
119-
float3 Vworld = normalize(mul((float3x3) g_mViewToWorld, -vP).xyz); //unity_CameraToWorld
120-
121-
float4 gbuffer0 = _CameraGBufferTexture0.Load(uint3(pixCoord.xy, 0));
122-
float4 gbuffer1 = _CameraGBufferTexture1.Load(uint3(pixCoord.xy, 0));
123-
float4 gbuffer2 = _CameraGBufferTexture2.Load(uint3(pixCoord.xy, 0));
124-
float4 gbuffer3 = _CameraGBufferTexture3.Load(uint3(pixCoord.xy, 0));
125-
126-
StandardData data = UnityStandardDataFromGbufferAux(gbuffer0, gbuffer1, gbuffer2, gbuffer3);
127-
128-
g_localParams.gbuf = data;
129-
g_localParams.oneMinusReflectivity = 1.0 - SpecularStrength(data.specularColor.rgb);
130-
g_localParams.Vworld = Vworld;
131-
132-
uint2 tileCoord = groupId >> 1;
133-
134-
uint numLightsProcessed = 0;
135-
float3 c = data.emission + ExecuteLightList(numLightsProcessed, tileCoord, vP, vPw, Vworld);
136-
137-
uint numReflectionsProcessed = 0;
138-
c += ExecuteReflectionList(numReflectionsProcessed, tileCoord, vP, data.normalWorld, Vworld, data.smoothness);
139-
140-
#if ENABLE_DEBUG
141-
c = OverlayHeatMap(pixCoord & 15, numLightsProcessed, c);
142-
#endif
143-
144-
uavOutput[pixCoord] = float4(c, 1.0);
145-
}
146-
1+
#pragma kernel ShadeDeferred_Fptl SHADE_DEFERRED_ENTRY=ShadeDeferred_Fptl USE_FPTL_LIGHTLIST=1 ENABLE_DEBUG=0
2+
#pragma kernel ShadeDeferred_Clustered SHADE_DEFERRED_ENTRY=ShadeDeferred_Clustered USE_CLUSTERED_LIGHTLIST=1 ENABLE_DEBUG=0 //TODO: disabled clustered permutations so far as it leads to the error "All kernels must use same constant buffer layouts"
3+
#pragma kernel ShadeDeferred_Fptl_Debug SHADE_DEFERRED_ENTRY=ShadeDeferred_Fptl_Debug USE_FPTL_LIGHTLIST=1 ENABLE_DEBUG=1
4+
#pragma kernel ShadeDeferred_Clustered_Debug SHADE_DEFERRED_ENTRY=ShadeDeferred_Clustered_Debug USE_CLUSTERED_LIGHTLIST=1 ENABLE_DEBUG=1
5+
6+
#define TILE_SIZE 8
7+
8+
9+
// Hacks to get the header to compile in compute
10+
#define SHADER_TARGET 50
11+
#define UNITY_PBS_USE_BRDF1
12+
#define fixed4 float4
13+
#include "UnityLightingCommon.cginc"
14+
#undef fixed4
15+
16+
float3 EvalMaterial(UnityLight light, UnityIndirect ind);
17+
float3 EvalIndirectSpecular(UnityLight light, UnityIndirect ind);
18+
19+
// uses the optimized single layered light list for opaques only
20+
21+
#ifdef USE_FPTL_LIGHTLIST
22+
#define OPAQUES_ONLY
23+
#endif
24+
25+
#include "TiledLightingTemplate.hlsl"
26+
#include "TiledReflectionTemplate.hlsl"
27+
28+
Texture2D _CameraGBufferTexture0;
29+
Texture2D _CameraGBufferTexture1;
30+
Texture2D _CameraGBufferTexture2;
31+
Texture2D _CameraGBufferTexture3;
32+
33+
RWTexture2D<float4> uavOutput : register(u0);
34+
35+
struct v2f {
36+
float4 vertex : SV_POSITION;
37+
float2 texcoord : TEXCOORD0;
38+
};
39+
40+
v2f vert(float4 vertex : POSITION, float2 texcoord : TEXCOORD0)
41+
{
42+
v2f o;
43+
o.vertex = UnityObjectToClipPos(vertex);
44+
o.texcoord = texcoord.xy;
45+
return o;
46+
}
47+
48+
struct StandardData
49+
{
50+
float3 specularColor;
51+
float3 diffuseColor;
52+
float3 normalWorld;
53+
float smoothness;
54+
float occlusion;
55+
float3 emission;
56+
};
57+
58+
struct LocalDataBRDF
59+
{
60+
StandardData gbuf;
61+
62+
// extras
63+
float oneMinusReflectivity;
64+
float3 Vworld;
65+
};
66+
67+
static LocalDataBRDF g_localParams;
68+
69+
StandardData UnityStandardDataFromGbufferAux(float4 gbuffer0, float4 gbuffer1, float4 gbuffer2, float4 gbuffer3)
70+
{
71+
StandardData data;
72+
73+
data.normalWorld = normalize(2 * gbuffer2.xyz - 1);
74+
data.smoothness = gbuffer1.a;
75+
data.diffuseColor = gbuffer0.xyz; data.specularColor = gbuffer1.xyz;
76+
data.occlusion = gbuffer0.a;
77+
data.emission = gbuffer3.xyz;
78+
79+
return data;
80+
}
81+
82+
half3 BRDF3_Direct2(half3 diffColor, half3 specColor, half rlPow4, half smoothness)
83+
{
84+
half LUT_RANGE = 16.0; // must match range in NHxRoughness() function in GeneratedTextures.cpp
85+
// Lookup texture to save instructions
86+
half specular = tex2Dlod(unity_NHxRoughness, half4(rlPow4, SmoothnessToPerceptualRoughness(smoothness), 0, 0)).UNITY_ATTEN_CHANNEL * LUT_RANGE;
87+
#if defined(_SPECULARHIGHLIGHTS_OFF)
88+
specular = 0.0;
89+
#endif
90+
91+
return diffColor + specular * specColor;
92+
}
93+
94+
95+
float3 EvalMaterial(UnityLight light, UnityIndirect ind)
96+
{
97+
StandardData data = g_localParams.gbuf;
98+
return UNITY_BRDF_PBS(data.diffuseColor, data.specularColor, g_localParams.oneMinusReflectivity, data.smoothness, data.normalWorld, g_localParams.Vworld, light, ind);
99+
}
100+
101+
float3 EvalIndirectSpecular(UnityLight light, UnityIndirect ind)
102+
{
103+
StandardData data = g_localParams.gbuf;
104+
105+
return data.occlusion * UNITY_BRDF_PBS(0, data.specularColor, g_localParams.oneMinusReflectivity, data.smoothness, data.normalWorld, g_localParams.Vworld, light, ind).rgb;
106+
}
107+
108+
[numthreads(TILE_SIZE, TILE_SIZE, 1)]
109+
void SHADE_DEFERRED_ENTRY(uint2 dispatchThreadId : SV_DispatchThreadID, uint2 groupId : SV_GroupID)
110+
{
111+
uint2 pixCoord = dispatchThreadId;
112+
113+
float zbufDpth = FetchDepth(_CameraDepthTexture, pixCoord.xy).x;
114+
float linDepth = GetLinearDepth(zbufDpth);
115+
116+
float3 vP = GetViewPosFromLinDepth(pixCoord, linDepth);
117+
float3 vPw = mul(g_mViewToWorld, float4(vP, 1)).xyz;
118+
float3 Vworld = normalize(mul((float3x3) g_mViewToWorld, -vP).xyz); //unity_CameraToWorld
119+
120+
float4 gbuffer0 = _CameraGBufferTexture0.Load(uint3(pixCoord.xy, 0));
121+
float4 gbuffer1 = _CameraGBufferTexture1.Load(uint3(pixCoord.xy, 0));
122+
float4 gbuffer2 = _CameraGBufferTexture2.Load(uint3(pixCoord.xy, 0));
123+
float4 gbuffer3 = _CameraGBufferTexture3.Load(uint3(pixCoord.xy, 0));
124+
125+
StandardData data = UnityStandardDataFromGbufferAux(gbuffer0, gbuffer1, gbuffer2, gbuffer3);
126+
127+
g_localParams.gbuf = data;
128+
g_localParams.oneMinusReflectivity = 1.0 - SpecularStrength(data.specularColor.rgb);
129+
g_localParams.Vworld = Vworld;
130+
131+
uint2 tileCoord = groupId >> 1;
132+
133+
uint numLightsProcessed = 0;
134+
float3 c = data.emission + ExecuteLightList(numLightsProcessed, tileCoord, vP, vPw, Vworld);
135+
136+
uint numReflectionsProcessed = 0;
137+
c += ExecuteReflectionList(numReflectionsProcessed, tileCoord, vP, data.normalWorld, Vworld, data.smoothness);
138+
139+
#if ENABLE_DEBUG
140+
c = OverlayHeatMap(pixCoord & 15, numLightsProcessed, c);
141+
#endif
142+
143+
uavOutput[pixCoord] = float4(c, 1.0);
144+
}
145+

0 commit comments

Comments
 (0)