|
1 |
| - |
2 | 1 | //-------------------------------------------------------------------------------------
|
3 | 2 | // Fill SurfaceData/Builtin data function
|
4 | 3 | //-------------------------------------------------------------------------------------
|
5 |
| - |
6 |
| -// In unity we can have a mix of fully baked lightmap (static lightmap) + enlighten realtime lightmap (dynamic lightmap) |
7 |
| -// for each case we can have directional lightmap or not. |
8 |
| -// Else we have lightprobe for dynamic/moving entity. Either SH9 per object lightprobe or SH4 per pixel per object volume probe |
9 |
| -float3 SampleBakedGI(float3 positionWS, float3 normalWS, float2 uvStaticLightmap, float2 uvDynamicLightmap) |
10 |
| -{ |
11 |
| - // If there is no lightmap, it assume lightprobe |
12 |
| -#if !defined(LIGHTMAP_ON) && !defined(DYNAMICLIGHTMAP_ON) |
13 |
| - |
14 |
| -// TODO: Confirm with Ionut but it seems that UNITY_LIGHT_PROBE_PROXY_VOLUME is always define for high end and |
15 |
| -// unity_ProbeVolumeParams always bind. |
16 |
| - if (unity_ProbeVolumeParams.x == 0.0) |
17 |
| - { |
18 |
| - // TODO: pass a tab of coefficient instead! |
19 |
| - float4 SHCoefficients[7]; |
20 |
| - SHCoefficients[0] = unity_SHAr; |
21 |
| - SHCoefficients[1] = unity_SHAg; |
22 |
| - SHCoefficients[2] = unity_SHAb; |
23 |
| - SHCoefficients[3] = unity_SHBr; |
24 |
| - SHCoefficients[4] = unity_SHBg; |
25 |
| - SHCoefficients[5] = unity_SHBb; |
26 |
| - SHCoefficients[6] = unity_SHC; |
27 |
| - |
28 |
| - return SampleSH9(SHCoefficients, normalWS); |
29 |
| - } |
30 |
| - else |
31 |
| - { |
32 |
| - // TODO: Move all this to C++! |
33 |
| - float4x4 identity = 0; |
34 |
| - identity._m00_m11_m22_m33 = 1.0; |
35 |
| - float4x4 WorldToTexture = (unity_ProbeVolumeParams.y == 1.0f) ? unity_ProbeVolumeWorldToObject : identity; |
36 |
| - |
37 |
| - float4x4 translation = identity; |
38 |
| - translation._m30_m31_m32 = -unity_ProbeVolumeMin.xyz; |
39 |
| - |
40 |
| - float4x4 scale = 0; |
41 |
| - scale._m00_m11_m22_m33 = float4(unity_ProbeVolumeSizeInv.xyz, 1.0); |
42 |
| - |
43 |
| - WorldToTexture = mul(mul(scale, translation), WorldToTexture); |
44 |
| - |
45 |
| - return SampleProbeVolumeSH4(TEXTURE3D_PARAM(unity_ProbeVolumeSH, samplerunity_ProbeVolumeSH), positionWS, normalWS, WorldToTexture, unity_ProbeVolumeParams.z); |
46 |
| - } |
47 |
| - |
48 |
| -#else |
49 |
| - |
50 |
| - float3 bakeDiffuseLighting = float3(0.0, 0.0, 0.0); |
51 |
| - |
52 |
| - #ifdef LIGHTMAP_ON |
53 |
| - #ifdef DIRLIGHTMAP_COMBINED |
54 |
| - bakeDiffuseLighting += SampleDirectionalLightmap(TEXTURE2D_PARAM(unity_Lightmap, samplerunity_Lightmap), |
55 |
| - TEXTURE2D_PARAM(unity_LightmapInd, samplerunity_Lightmap), |
56 |
| - uvStaticLightmap, unity_LightmapST, normalWS); |
57 |
| - #else |
58 |
| - bakeDiffuseLighting += SampleSingleLightmap(TEXTURE2D_PARAM(unity_Lightmap, samplerunity_Lightmap), uvStaticLightmap, unity_LightmapST); |
59 |
| - #endif |
60 |
| - #endif |
61 |
| - |
62 |
| - #ifdef DYNAMICLIGHTMAP_ON |
63 |
| - #ifdef DIRLIGHTMAP_COMBINED |
64 |
| - bakeDiffuseLighting += SampleDirectionalLightmap(TEXTURE2D_PARAM(unity_DynamicLightmap, samplerunity_DynamicLightmap), |
65 |
| - TEXTURE2D_PARAM(unity_DynamicDirectionality, samplerunity_DynamicLightmap), |
66 |
| - uvDynamicLightmap, unity_DynamicLightmapST, normalWS); |
67 |
| - #else |
68 |
| - bakeDiffuseLighting += SampleSingleLightmap(TEXTURE2D_PARAM(unity_DynamicLightmap, samplerunity_DynamicLightmap), uvDynamicLightmap, unity_DynamicLightmapST); |
69 |
| - #endif |
70 |
| - #endif |
71 |
| - |
72 |
| - return bakeDiffuseLighting; |
73 |
| - |
74 |
| -#endif |
75 |
| -} |
76 |
| - |
77 |
| -float2 CalculateVelocity(float4 positionCS, float4 previousPositionCS) |
78 |
| -{ |
79 |
| - // This test on define is required to remove warning of divide by 0 when initializing empty struct |
80 |
| - // TODO: Add forward opaque MRT case... |
81 |
| -#if (SHADERPASS == SHADERPASS_VELOCITY) || (SHADERPASS == SHADERPASS_GBUFFER && SHADEROPTIONS_VELOCITY_IN_GBUFFER) |
82 |
| - // Encode velocity |
83 |
| - positionCS.xy = positionCS.xy / positionCS.w; |
84 |
| - previousPositionCS.xy = previousPositionCS.xy / previousPositionCS.w; |
85 |
| - |
86 |
| - return (positionCS.xy - previousPositionCS.xy) * _ForceNoMotion; |
87 |
| -#else |
88 |
| - return float2(0.0, 0.0); |
89 |
| -#endif |
90 |
| -} |
| 4 | +#include "../MaterialUtilities.hlsl" |
91 | 5 |
|
92 | 6 | void GetBuiltinData(FragInput input, SurfaceData surfaceData, float alpha, out BuiltinData builtinData)
|
93 | 7 | {
|
|
0 commit comments