浏览代码
Merge branch 'master' into batch_rendering
Merge branch 'master' into batch_rendering
# Conflicts: # Assets/TestScenes/HDTest/GlobalIlluminationTest.unity # Assets/TestScenes/HDTest/GlobalIlluminationTest/LightingData.asset # Assets/TestScenes/HDTest/GlobalIlluminationTest/LightingData.asset.meta # Assets/TestScenes/HDTest/HDRI.meta # ProjectSettings/GraphicsSettings.asset # ProjectSettings/ProjectSettings.asset/batch_rendering
Arnaud Carre
8 年前
当前提交
2cdff1ec
共有 318 个文件被更改,包括 2855 次插入 和 1851 次删除
-
5Assets/BasicRenderLoopTutorial/BasicRenderLoop.cs
-
7Assets/Editor/Tests/RenderloopTests/RenderloopTestFixture.cs
-
2Assets/Editor/Tests/ShaderGeneratorTests/ShaderGeneratorTests.cs
-
10Assets/ScriptableRenderLoop/AdditionalLightData.cs
-
5Assets/ScriptableRenderLoop/Editor/MaterialUpgrader.cs
-
8Assets/ScriptableRenderLoop/HDRenderPipeline/Debug/DebugViewMaterial.cs
-
6Assets/ScriptableRenderLoop/HDRenderPipeline/Debug/DebugViewMaterial.cs.hlsl
-
11Assets/ScriptableRenderLoop/HDRenderPipeline/Debug/Resources/DebugViewMaterialGBuffer.shader
-
20Assets/ScriptableRenderLoop/HDRenderPipeline/Debug/Resources/DebugViewTiles.shader
-
10Assets/ScriptableRenderLoop/HDRenderPipeline/Editor/HDRenderPipelineInspector.cs
-
20Assets/ScriptableRenderLoop/HDRenderPipeline/Editor/HDRenderPipelineMenuItems.cs
-
8Assets/ScriptableRenderLoop/HDRenderPipeline/Editor/UpgradeStandardShaderMaterials.cs
-
1Assets/ScriptableRenderLoop/HDRenderPipeline/HDRenderPipeline.asset
-
2Assets/ScriptableRenderLoop/HDRenderPipeline/HDRenderPipeline.asset.meta
-
211Assets/ScriptableRenderLoop/HDRenderPipeline/HDRenderPipeline.cs
-
5Assets/ScriptableRenderLoop/HDRenderPipeline/Lighting/Forward.hlsl
-
4Assets/ScriptableRenderLoop/HDRenderPipeline/Lighting/LightDefinition.cs
-
22Assets/ScriptableRenderLoop/HDRenderPipeline/Lighting/LightDefinition.cs.hlsl
-
4Assets/ScriptableRenderLoop/HDRenderPipeline/Lighting/LightLoop.cs
-
5Assets/ScriptableRenderLoop/HDRenderPipeline/Lighting/Resources/Deferred.shader
-
7Assets/ScriptableRenderLoop/HDRenderPipeline/Lighting/TilePass/Resources/lightlistbuild-bigtile.compute
-
105Assets/ScriptableRenderLoop/HDRenderPipeline/Lighting/TilePass/TilePass.cs
-
16Assets/ScriptableRenderLoop/HDRenderPipeline/Lighting/TilePass/TilePass.cs.hlsl
-
25Assets/ScriptableRenderLoop/HDRenderPipeline/Lighting/TilePass/TilePass.hlsl
-
2Assets/ScriptableRenderLoop/HDRenderPipeline/Lighting/TilePass/TilePassLoop.hlsl
-
2Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Builtin/BuiltinData.cs
-
8Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Builtin/BuiltinData.cs.hlsl
-
7Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Builtin/BuiltinData.hlsl
-
284Assets/ScriptableRenderLoop/HDRenderPipeline/Material/LayeredLit/Editor/LayeredLitUI.cs
-
180Assets/ScriptableRenderLoop/HDRenderPipeline/Material/LayeredLit/LayeredLit.shader
-
169Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/Editor/BaseLitUI.cs
-
76Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/Editor/LitUI.cs
-
3Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/Editor/StandardSpecularToHDLitMaterialUpgrader.cs
-
6Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/Editor/StandardToHDLitMaterialUpgrader.cs
-
82Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/Lit.cs
-
12Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/Lit.cs.hlsl
-
162Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/Lit.hlsl
-
97Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/Lit.shader
-
447Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/LitData.hlsl
-
61Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/LitProperties.hlsl
-
2Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/LtcData.DisneyDiffuse.cs
-
2Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/LtcData.GGX.cs
-
8Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/Resources/PreIntegratedFGD.shader
-
268Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/LitDataInternal.hlsl
-
29Assets/ScriptableRenderLoop/HDRenderPipeline/Material/MaterialUtilities.hlsl
-
2Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Unlit/Editor/BaseUnlitUI.cs
-
2Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Unlit/Editor/UnlitUI.cs
-
4Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Unlit/Unlit.cs
-
8Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Unlit/Unlit.cs.hlsl
-
156Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Unlit/Unlit.shader
-
7Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Unlit/UnlitData.hlsl
-
207Assets/ScriptableRenderLoop/HDRenderPipeline/PostProcess/Resources/FinalPass.shader
-
2Assets/ScriptableRenderLoop/HDRenderPipeline/SceneSettings/CommonSettings.cs
-
2Assets/ScriptableRenderLoop/HDRenderPipeline/SceneSettings/Editor/CommonSettingsEditor.cs
-
2Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderConfig.cs
-
2Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderConfig.cs.hlsl
-
4Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderPass/ShaderPass.cs
-
2Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderPass/ShaderPass.cs.hlsl
-
26Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderPass/ShaderPassDebugViewMaterial.hlsl
-
28Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderPass/ShaderPassDepthOnly.hlsl
-
26Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderPass/ShaderPassDistortion.hlsl
-
37Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderPass/ShaderPassForward.hlsl
-
26Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderPass/ShaderPassForwardUnlit.hlsl
-
34Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderPass/ShaderPassGBuffer.hlsl
-
53Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderPass/ShaderPassLightTransport.hlsl
-
126Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderPass/ShaderPassVelocity.hlsl
-
32Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderVariables.hlsl
-
4Assets/ScriptableRenderLoop/HDRenderPipeline/Shadow/FixedSizePCF/FixedSizePCF.cs
-
2Assets/ScriptableRenderLoop/HDRenderPipeline/Shadow/Shadow.hlsl
-
2Assets/ScriptableRenderLoop/HDRenderPipeline/Sky/HDRISky/Editor/HDRISkyEditor.cs
-
2Assets/ScriptableRenderLoop/HDRenderPipeline/Sky/HDRISky/HDRISkyParameters.cs
-
20Assets/ScriptableRenderLoop/HDRenderPipeline/Sky/HDRISky/HDRISkyRenderer.cs
-
113Assets/ScriptableRenderLoop/HDRenderPipeline/Sky/HDRISky/Resources/SkyHDRI.shader
-
2Assets/ScriptableRenderLoop/HDRenderPipeline/Sky/ProceduralSky/Editor/ProceduralSkyEditor.cs
-
32Assets/ScriptableRenderLoop/HDRenderPipeline/Sky/ProceduralSky/ProceduralSkyParameters.cs
-
77Assets/ScriptableRenderLoop/HDRenderPipeline/Sky/ProceduralSky/ProceduralSkyRenderer.cs
-
35Assets/ScriptableRenderLoop/HDRenderPipeline/Sky/ProceduralSky/Resources/AtmosphericScattering.hlsl
-
40Assets/ScriptableRenderLoop/HDRenderPipeline/Sky/ProceduralSky/Resources/SkyProcedural.shader
-
30Assets/ScriptableRenderLoop/HDRenderPipeline/Sky/Resources/GGXConvolve.shader
-
134Assets/ScriptableRenderLoop/HDRenderPipeline/Sky/SkyManager.cs
-
2Assets/ScriptableRenderLoop/HDRenderPipeline/Sky/SkyManager.cs.hlsl
-
2Assets/ScriptableRenderLoop/HDRenderPipeline/Sky/SkyParameters.cs
-
8Assets/ScriptableRenderLoop/HDRenderPipeline/Sky/SkyRenderer.cs
-
21Assets/ScriptableRenderLoop/HDRenderPipeline/Utilities.cs
-
4Assets/ScriptableRenderLoop/RenderPasses/ShadowRenderPass.cs
-
9Assets/ScriptableRenderLoop/ShaderLibrary/API/D3D11.hlsl
-
11Assets/ScriptableRenderLoop/ShaderLibrary/AreaLighting.hlsl
-
38Assets/ScriptableRenderLoop/ShaderLibrary/BSDF.hlsl
-
88Assets/ScriptableRenderLoop/ShaderLibrary/Common.hlsl
-
33Assets/ScriptableRenderLoop/ShaderLibrary/CommonLighting.hlsl
-
22Assets/ScriptableRenderLoop/ShaderLibrary/CommonMaterial.hlsl
-
62Assets/ScriptableRenderLoop/ShaderLibrary/EntityLighting.hlsl
-
4Assets/ScriptableRenderLoop/ShaderLibrary/Fibonacci.hlsl
-
343Assets/ScriptableRenderLoop/ShaderLibrary/ImageBasedLighting.hlsl
-
42Assets/ScriptableRenderLoop/ShaderLibrary/Packing.hlsl
-
2Assets/ScriptableRenderLoop/common/TextureCache.cs
-
2Assets/ScriptableRenderLoop/common/TextureSettings.cs
-
4Assets/ScriptableRenderLoop/core/RenderPipeline.cs
-
10Assets/ScriptableRenderLoop/fptl/FptlLighting.cs
-
292Assets/ScriptableRenderLoop/fptl/Internal-DeferredComputeShading.compute
|
|||
fileFormatVersion: 2 |
|||
guid: e185fecca3c73cd47a09f1092663ef32 |
|||
timeCreated: 1483606455 |
|||
timeCreated: 1484329328 |
|||
licenseType: Pro |
|||
NativeFormatImporter: |
|||
userData: |
|
|||
// Final compositing pass, just does gamma correction for now. |
|||
|
|||
_ToneMapCoeffs1("Parameters for neutral tonemap", Vector) = (0.0, 0.0, 0.0, 0.0) |
|||
_ToneMapCoeffs2("Parameters for neutral tonemap", Vector) = (0.0, 0.0, 0.0, 0.0) |
|||
_Exposure("Exposure", Range(-32.0, 32.0)) = 0 |
|||
[ToggleOff] _EnableToneMap("Enable Tone Map", Float) = 0 |
|||
SubShader { |
|||
Pass { |
|||
ZTest Always Cull Off ZWrite Off |
|||
HLSLINCLUDE |
|||
HLSLPROGRAM |
|||
#pragma vertex Vert |
|||
#pragma fragment Frag |
|||
#pragma target 5.0 |
|||
#pragma target 4.5 |
|||
#include "Common.hlsl" |
|||
#include "Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderVariables.hlsl" |
|||
#include "ColorGrading.hlsl" |
|||
#include "Common.hlsl" |
|||
#include "Color.hlsl" |
|||
#include "Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderVariables.hlsl" |
|||
TEXTURE2D(_MainTex); |
|||
SAMPLER2D(sampler_MainTex); |
|||
TEXTURE2D(_MainTex); |
|||
SAMPLER2D(sampler_MainTex); |
|||
TEXTURE2D(_AutoExposure); |
|||
SAMPLER2D(sampler_AutoExposure); |
|||
float4 _ToneMapCoeffs1; |
|||
float4 _ToneMapCoeffs2; |
|||
TEXTURE2D(_LogLut); |
|||
SAMPLER2D(sampler_LogLut); |
|||
#define InBlack _ToneMapCoeffs1.x |
|||
#define OutBlack _ToneMapCoeffs1.y |
|||
#define InWhite _ToneMapCoeffs1.z |
|||
#define OutWhite _ToneMapCoeffs1.w |
|||
#define WhiteLevel _ToneMapCoeffs2.z |
|||
#define WhiteClip _ToneMapCoeffs2.w |
|||
float4 _LogLut_Params; |
|||
float _Exposure; |
|||
float _EnableToneMap; |
|||
float _Exposure; |
|||
struct Attributes |
|||
{ |
|||
float3 vertex : POSITION; |
|||
float2 texcoord : TEXCOORD0; |
|||
}; |
|||
float4 _NeutralTonemapperParams1; |
|||
float4 _NeutralTonemapperParams2; |
|||
struct Varyings |
|||
{ |
|||
float4 vertex : SV_POSITION; |
|||
float2 texcoord : TEXCOORD0; |
|||
}; |
|||
struct Attributes |
|||
{ |
|||
float3 vertex : POSITION; |
|||
float2 texcoord : TEXCOORD0; |
|||
}; |
|||
Varyings Vert(Attributes input) |
|||
{ |
|||
Varyings output; |
|||
output.vertex = TransformWorldToHClip(input.vertex); |
|||
output.texcoord = input.texcoord.xy; |
|||
return output; |
|||
} |
|||
struct Varyings |
|||
{ |
|||
float4 vertex : SV_POSITION; |
|||
float2 texcoord : TEXCOORD0; |
|||
}; |
|||
float3 evalCurve(float3 x, float A, float B, float C, float D, float E, float F) |
|||
{ |
|||
return ((x*(A*x + C*B) + D*E) / (x*(A*x + B) + D*F)) - E / F; |
|||
} |
|||
Varyings Vert(Attributes input) |
|||
{ |
|||
Varyings output; |
|||
output.vertex = TransformWorldToHClip(input.vertex); |
|||
output.texcoord = input.texcoord.xy; |
|||
return output; |
|||
} |
|||
float3 applyTonemapFilmicAD(float3 linearColor) |
|||
{ |
|||
float blackRatio = InBlack / OutBlack; |
|||
float whiteRatio = InWhite / OutWhite; |
|||
// Neutral tonemapping (Hable/Hejl/Frostbite) |
|||
// Input is linear RGB |
|||
float3 NeutralCurve(float3 x, float a, float b, float c, float d, float e, float f) |
|||
{ |
|||
return ((x * (a * x + c * b) + d * e) / (x * (a * x + b) + d * f)) - e / f; |
|||
} |
|||
|
|||
float3 NeutralTonemap(float3 x, float4 params1, float4 params2) |
|||
{ |
|||
// ACES supports negative color values and WILL output negative values when coming from ACES or ACEScg |
|||
// Make sure negative channels are clamped to 0.0 as this neutral tonemapper can't deal with them properly |
|||
x = max((0.0).xxx, x); |
|||
|
|||
// Tonemap |
|||
float a = params1.x; |
|||
float b = params1.y; |
|||
float c = params1.z; |
|||
float d = params1.w; |
|||
float e = params2.x; |
|||
float f = params2.y; |
|||
float whiteLevel = params2.z; |
|||
float whiteClip = params2.w; |
|||
// blend tunable coefficients |
|||
float B = lerp(0.57, 0.37, blackRatio); |
|||
float C = lerp(0.01, 0.24, whiteRatio); |
|||
float D = lerp(0.02, 0.20, blackRatio); |
|||
float3 whiteScale = (1.0).xxx / NeutralCurve(whiteLevel, a, b, c, d, e, f); |
|||
x = NeutralCurve(x * whiteScale, a, b, c, d, e, f); |
|||
x *= whiteScale; |
|||
// constants |
|||
float A = 0.2; |
|||
float E = 0.02; |
|||
float F = 0.30; |
|||
// Post-curve white point adjustment |
|||
x /= whiteClip.xxx; |
|||
// eval and correct for white point |
|||
float3 whiteScale = 1.0f / evalCurve(WhiteLevel, A, B, C, D, E, F); |
|||
float3 curr = evalCurve(linearColor * whiteScale, A, B, C, D, E, F); |
|||
return x; |
|||
} |
|||
return curr * whiteScale; |
|||
} |
|||
float4 Frag(Varyings input) : SV_Target |
|||
{ |
|||
float4 color = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, input.texcoord); |
|||
float3 remapWhite(float3 inPixel, float whitePt) |
|||
#if EYE_ADAPTATION |
|||
// var breakout for readability |
|||
const float inBlack = 0; |
|||
const float outBlack = 0; |
|||
float inWhite = whitePt; |
|||
const float outWhite = 1; |
|||
|
|||
// remap input range to output range |
|||
float3 outPixel = ((inPixel.rgb) - inBlack.xxx) / (inWhite.xxx - inBlack.xxx) * (outWhite.xxx - outBlack.xxx) + outBlack.xxx; |
|||
return (outPixel.rgb); |
|||
float autoExposure = SAMPLE_TEXTURE2D(_AutoExposure, sampler_AutoExposure, input.texcoord).r; |
|||
color *= autoExposure; |
|||
#endif |
|||
float3 NeutralTonemap(float3 x) |
|||
color.rgb *= _Exposure; // Exposure is in ev units (or 'stops'), precomputed CPU-side |
|||
|
|||
#if NEUTRAL_GRADING |
|||
float3 finalColor = applyTonemapFilmicAD(x); // curve (dynamic coeffs differ per level) |
|||
finalColor = remapWhite(finalColor, WhiteClip); // post-curve white point adjustment |
|||
finalColor = saturate(finalColor); |
|||
return finalColor; |
|||
color.rgb = NeutralTonemap(color.rgb, _NeutralTonemapperParams1, _NeutralTonemapperParams2); |
|||
#elif CUSTOM_GRADING |
|||
{ |
|||
float3 uvw = saturate(LinearToLogC(color)); |
|||
float3 ApplyToneMap(float3 color) |
|||
// Strip lut format where `height = sqrt(width)` |
|||
uvw.z *= _LogLut_Params.z; |
|||
half shift = floor(uvw.z); |
|||
uvw.xy = uvw.xy * _LogLut_Params.z * _LogLut_Params.xy + _LogLut_Params.xy * 0.5; |
|||
uvw.x += shift * _LogLut_Params.y; |
|||
uvw.xyz = lerp( |
|||
SAMPLE_TEXTURE2D(_LogLut, sampler_LogLut, uvw.xy).rgb, |
|||
SAMPLE_TEXTURE2D(_LogLut, sampler_LogLut, uvw.xy + half2(_LogLut_Params.y, 0)).rgb, |
|||
uvw.z - shift |
|||
); |
|||
|
|||
color.rgb = uvw; |
|||
} |
|||
#else |
|||
if (_EnableToneMap > 0.0) |
|||
{ |
|||
return NeutralTonemap(color); |
|||
} |
|||
else |
|||
{ |
|||
return saturate(color); |
|||
} |
|||
color = saturate(color); |
|||
#endif |
|||
float4 Frag(Varyings input) : SV_Target |
|||
{ |
|||
float4 c = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, input.texcoord); |
|||
// Gamma correction |
|||
return color; |
|||
} |
|||
// TODO: Currenlt in the editor there a an additional pass were the result is copyed in a render target RGBA8_sRGB. |
|||
// So we must not correct the sRGB here else it will be done two time. |
|||
// To fix! |
|||
ENDHLSL |
|||
c.rgb = ApplyToneMap(c.rgb * exp2(_Exposure)); |
|||
SubShader |
|||
{ |
|||
Cull Off ZWrite Off ZTest Always |
|||
// return LinearToSRGB(c); |
|||
return c; |
|||
Pass |
|||
{ |
|||
HLSLPROGRAM |
|||
#pragma vertex Vert |
|||
#pragma fragment Frag |
|||
#pragma multi_compile __ NEUTRAL_GRADING CUSTOM_GRADING |
|||
#pragma multi_compile __ EYE_ADAPTATION |
|||
} |
|||
|
|||
|
|||
Fallback Off |
|||
} |
|
|||
#pragma kernel ShadeDeferred_Fptl SHADE_DEFERRED_ENTRY=ShadeDeferred_Fptl USE_FPTL_LIGHTLIST=1 ENABLE_DEBUG=0 |
|||
#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" |
|||
#pragma kernel ShadeDeferred_Fptl_Debug SHADE_DEFERRED_ENTRY=ShadeDeferred_Fptl_Debug USE_FPTL_LIGHTLIST=1 ENABLE_DEBUG=1 |
|||
#pragma kernel ShadeDeferred_Clustered_Debug SHADE_DEFERRED_ENTRY=ShadeDeferred_Clustered_Debug USE_CLUSTERED_LIGHTLIST=1 ENABLE_DEBUG=1 |
|||
|
|||
#define TILE_SIZE 8 |
|||
|
|||
|
|||
// Hacks to get the header to compile in compute |
|||
#define SHADER_TARGET 50 |
|||
#define UNITY_PBS_USE_BRDF1 |
|||
#define fixed4 float4 |
|||
#include "UnityLightingCommon.cginc" |
|||
#undef fixed4 |
|||
|
|||
float3 EvalMaterial(UnityLight light, UnityIndirect ind); |
|||
float3 EvalIndirectSpecular(UnityLight light, UnityIndirect ind); |
|||
|
|||
// uses the optimized single layered light list for opaques only |
|||
|
|||
#ifdef USE_FPTL_LIGHTLIST |
|||
#define OPAQUES_ONLY |
|||
#endif |
|||
|
|||
#include "TiledLightingTemplate.hlsl" |
|||
#include "TiledReflectionTemplate.hlsl" |
|||
|
|||
Texture2D _CameraDepthTexture; |
|||
Texture2D _CameraGBufferTexture0; |
|||
Texture2D _CameraGBufferTexture1; |
|||
Texture2D _CameraGBufferTexture2; |
|||
Texture2D _CameraGBufferTexture3; |
|||
|
|||
RWTexture2D<float4> uavOutput : register(u0); |
|||
|
|||
struct v2f { |
|||
float4 vertex : SV_POSITION; |
|||
float2 texcoord : TEXCOORD0; |
|||
}; |
|||
|
|||
v2f vert(float4 vertex : POSITION, float2 texcoord : TEXCOORD0) |
|||
{ |
|||
v2f o; |
|||
o.vertex = UnityObjectToClipPos(vertex); |
|||
o.texcoord = texcoord.xy; |
|||
return o; |
|||
} |
|||
|
|||
struct StandardData |
|||
{ |
|||
float3 specularColor; |
|||
float3 diffuseColor; |
|||
float3 normalWorld; |
|||
float smoothness; |
|||
float occlusion; |
|||
float3 emission; |
|||
}; |
|||
|
|||
struct LocalDataBRDF |
|||
{ |
|||
StandardData gbuf; |
|||
|
|||
// extras |
|||
float oneMinusReflectivity; |
|||
float3 Vworld; |
|||
}; |
|||
|
|||
static LocalDataBRDF g_localParams; |
|||
|
|||
StandardData UnityStandardDataFromGbufferAux(float4 gbuffer0, float4 gbuffer1, float4 gbuffer2, float4 gbuffer3) |
|||
{ |
|||
StandardData data; |
|||
|
|||
data.normalWorld = normalize(2 * gbuffer2.xyz - 1); |
|||
data.smoothness = gbuffer1.a; |
|||
data.diffuseColor = gbuffer0.xyz; data.specularColor = gbuffer1.xyz; |
|||
data.occlusion = gbuffer0.a; |
|||
data.emission = gbuffer3.xyz; |
|||
|
|||
return data; |
|||
} |
|||
|
|||
half3 BRDF3_Direct2(half3 diffColor, half3 specColor, half rlPow4, half smoothness) |
|||
{ |
|||
half LUT_RANGE = 16.0; // must match range in NHxRoughness() function in GeneratedTextures.cpp |
|||
// Lookup texture to save instructions |
|||
half specular = tex2Dlod(unity_NHxRoughness, half4(rlPow4, SmoothnessToPerceptualRoughness(smoothness), 0, 0)).UNITY_ATTEN_CHANNEL * LUT_RANGE; |
|||
#if defined(_SPECULARHIGHLIGHTS_OFF) |
|||
specular = 0.0; |
|||
#endif |
|||
|
|||
return diffColor + specular * specColor; |
|||
} |
|||
|
|||
|
|||
float3 EvalMaterial(UnityLight light, UnityIndirect ind) |
|||
{ |
|||
StandardData data = g_localParams.gbuf; |
|||
return UNITY_BRDF_PBS(data.diffuseColor, data.specularColor, g_localParams.oneMinusReflectivity, data.smoothness, data.normalWorld, g_localParams.Vworld, light, ind); |
|||
} |
|||
|
|||
float3 EvalIndirectSpecular(UnityLight light, UnityIndirect ind) |
|||
{ |
|||
StandardData data = g_localParams.gbuf; |
|||
|
|||
return data.occlusion * UNITY_BRDF_PBS(0, data.specularColor, g_localParams.oneMinusReflectivity, data.smoothness, data.normalWorld, g_localParams.Vworld, light, ind).rgb; |
|||
} |
|||
|
|||
[numthreads(TILE_SIZE, TILE_SIZE, 1)] |
|||
void SHADE_DEFERRED_ENTRY(uint2 dispatchThreadId : SV_DispatchThreadID, uint2 groupId : SV_GroupID) |
|||
{ |
|||
uint2 pixCoord = dispatchThreadId; |
|||
|
|||
float zbufDpth = FetchDepth(_CameraDepthTexture, pixCoord.xy).x; |
|||
float linDepth = GetLinearDepth(zbufDpth); |
|||
|
|||
float3 vP = GetViewPosFromLinDepth(pixCoord, linDepth); |
|||
float3 vPw = mul(g_mViewToWorld, float4(vP, 1)).xyz; |
|||
float3 Vworld = normalize(mul((float3x3) g_mViewToWorld, -vP).xyz); //unity_CameraToWorld |
|||
|
|||
float4 gbuffer0 = _CameraGBufferTexture0.Load(uint3(pixCoord.xy, 0)); |
|||
float4 gbuffer1 = _CameraGBufferTexture1.Load(uint3(pixCoord.xy, 0)); |
|||
float4 gbuffer2 = _CameraGBufferTexture2.Load(uint3(pixCoord.xy, 0)); |
|||
float4 gbuffer3 = _CameraGBufferTexture3.Load(uint3(pixCoord.xy, 0)); |
|||
|
|||
StandardData data = UnityStandardDataFromGbufferAux(gbuffer0, gbuffer1, gbuffer2, gbuffer3); |
|||
|
|||
g_localParams.gbuf = data; |
|||
g_localParams.oneMinusReflectivity = 1.0 - SpecularStrength(data.specularColor.rgb); |
|||
g_localParams.Vworld = Vworld; |
|||
|
|||
uint2 tileCoord = groupId >> 1; |
|||
|
|||
uint numLightsProcessed = 0; |
|||
float3 c = data.emission + ExecuteLightList(numLightsProcessed, tileCoord, vP, vPw, Vworld); |
|||
|
|||
uint numReflectionsProcessed = 0; |
|||
c += ExecuteReflectionList(numReflectionsProcessed, tileCoord, vP, data.normalWorld, Vworld, data.smoothness); |
|||
|
|||
#if ENABLE_DEBUG |
|||
c = OverlayHeatMap(pixCoord & 15, numLightsProcessed, c); |
|||
#endif |
|||
|
|||
uavOutput[pixCoord] = float4(c, 1.0); |
|||
} |
|||
|
|||
#pragma kernel ShadeDeferred_Fptl SHADE_DEFERRED_ENTRY=ShadeDeferred_Fptl USE_FPTL_LIGHTLIST=1 ENABLE_DEBUG=0 |
|||
#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" |
|||
#pragma kernel ShadeDeferred_Fptl_Debug SHADE_DEFERRED_ENTRY=ShadeDeferred_Fptl_Debug USE_FPTL_LIGHTLIST=1 ENABLE_DEBUG=1 |
|||
#pragma kernel ShadeDeferred_Clustered_Debug SHADE_DEFERRED_ENTRY=ShadeDeferred_Clustered_Debug USE_CLUSTERED_LIGHTLIST=1 ENABLE_DEBUG=1 |
|||
|
|||
#define TILE_SIZE 8 |
|||
|
|||
|
|||
// Hacks to get the header to compile in compute |
|||
#define SHADER_TARGET 50 |
|||
#define UNITY_PBS_USE_BRDF1 |
|||
#define fixed4 float4 |
|||
#include "UnityLightingCommon.cginc" |
|||
#undef fixed4 |
|||
|
|||
float3 EvalMaterial(UnityLight light, UnityIndirect ind); |
|||
float3 EvalIndirectSpecular(UnityLight light, UnityIndirect ind); |
|||
|
|||
// uses the optimized single layered light list for opaques only |
|||
|
|||
#ifdef USE_FPTL_LIGHTLIST |
|||
#define OPAQUES_ONLY |
|||
#endif |
|||
|
|||
#include "TiledLightingTemplate.hlsl" |
|||
#include "TiledReflectionTemplate.hlsl" |
|||
|
|||
UNITY_DECLARE_TEX2D_FLOAT(_CameraDepthTexture); |
|||
Texture2D _CameraGBufferTexture0; |
|||
Texture2D _CameraGBufferTexture1; |
|||
Texture2D _CameraGBufferTexture2; |
|||
Texture2D _CameraGBufferTexture3; |
|||
|
|||
RWTexture2D<float4> uavOutput : register(u0); |
|||
|
|||
struct v2f { |
|||
float4 vertex : SV_POSITION; |
|||
float2 texcoord : TEXCOORD0; |
|||
}; |
|||
|
|||
v2f vert(float4 vertex : POSITION, float2 texcoord : TEXCOORD0) |
|||
{ |
|||
v2f o; |
|||
o.vertex = UnityObjectToClipPos(vertex); |
|||
o.texcoord = texcoord.xy; |
|||
return o; |
|||
} |
|||
|
|||
struct StandardData |
|||
{ |
|||
float3 specularColor; |
|||
float3 diffuseColor; |
|||
float3 normalWorld; |
|||
float smoothness; |
|||
float occlusion; |
|||
float3 emission; |
|||
}; |
|||
|
|||
struct LocalDataBRDF |
|||
{ |
|||
StandardData gbuf; |
|||
|
|||
// extras |
|||
float oneMinusReflectivity; |
|||
float3 Vworld; |
|||
}; |
|||
|
|||
static LocalDataBRDF g_localParams; |
|||
|
|||
StandardData UnityStandardDataFromGbufferAux(float4 gbuffer0, float4 gbuffer1, float4 gbuffer2, float4 gbuffer3) |
|||
{ |
|||
StandardData data; |
|||
|
|||
data.normalWorld = normalize(2 * gbuffer2.xyz - 1); |
|||
data.smoothness = gbuffer1.a; |
|||
data.diffuseColor = gbuffer0.xyz; data.specularColor = gbuffer1.xyz; |
|||
data.occlusion = gbuffer0.a; |
|||
data.emission = gbuffer3.xyz; |
|||
|
|||
return data; |
|||
} |
|||
|
|||
half3 BRDF3_Direct2(half3 diffColor, half3 specColor, half rlPow4, half smoothness) |
|||
{ |
|||
half LUT_RANGE = 16.0; // must match range in NHxRoughness() function in GeneratedTextures.cpp |
|||
// Lookup texture to save instructions |
|||
half specular = tex2Dlod(unity_NHxRoughness, half4(rlPow4, SmoothnessToPerceptualRoughness(smoothness), 0, 0)).UNITY_ATTEN_CHANNEL * LUT_RANGE; |
|||
#if defined(_SPECULARHIGHLIGHTS_OFF) |
|||
specular = 0.0; |
|||
#endif |
|||
|
|||
return diffColor + specular * specColor; |
|||
} |
|||
|
|||
|
|||
float3 EvalMaterial(UnityLight light, UnityIndirect ind) |
|||
{ |
|||
StandardData data = g_localParams.gbuf; |
|||
return UNITY_BRDF_PBS(data.diffuseColor, data.specularColor, g_localParams.oneMinusReflectivity, data.smoothness, data.normalWorld, g_localParams.Vworld, light, ind); |
|||
} |
|||
|
|||
float3 EvalIndirectSpecular(UnityLight light, UnityIndirect ind) |
|||
{ |
|||
StandardData data = g_localParams.gbuf; |
|||
|
|||
return data.occlusion * UNITY_BRDF_PBS(0, data.specularColor, g_localParams.oneMinusReflectivity, data.smoothness, data.normalWorld, g_localParams.Vworld, light, ind).rgb; |
|||
} |
|||
|
|||
[numthreads(TILE_SIZE, TILE_SIZE, 1)] |
|||
void SHADE_DEFERRED_ENTRY(uint2 dispatchThreadId : SV_DispatchThreadID, uint2 groupId : SV_GroupID) |
|||
{ |
|||
uint2 pixCoord = dispatchThreadId; |
|||
|
|||
float zbufDpth = FetchDepth(_CameraDepthTexture, pixCoord.xy).x; |
|||
float linDepth = GetLinearDepth(zbufDpth); |
|||
|
|||
float3 vP = GetViewPosFromLinDepth(pixCoord, linDepth); |
|||
float3 vPw = mul(g_mViewToWorld, float4(vP, 1)).xyz; |
|||
float3 Vworld = normalize(mul((float3x3) g_mViewToWorld, -vP).xyz); //unity_CameraToWorld |
|||
|
|||
float4 gbuffer0 = _CameraGBufferTexture0.Load(uint3(pixCoord.xy, 0)); |
|||
float4 gbuffer1 = _CameraGBufferTexture1.Load(uint3(pixCoord.xy, 0)); |
|||
float4 gbuffer2 = _CameraGBufferTexture2.Load(uint3(pixCoord.xy, 0)); |
|||
float4 gbuffer3 = _CameraGBufferTexture3.Load(uint3(pixCoord.xy, 0)); |
|||
|
|||
StandardData data = UnityStandardDataFromGbufferAux(gbuffer0, gbuffer1, gbuffer2, gbuffer3); |
|||
|
|||
g_localParams.gbuf = data; |
|||
g_localParams.oneMinusReflectivity = 1.0 - SpecularStrength(data.specularColor.rgb); |
|||
g_localParams.Vworld = Vworld; |
|||
|
|||
uint2 tileCoord = groupId >> 1; |
|||
|
|||
uint numLightsProcessed = 0; |
|||
float3 c = data.emission + ExecuteLightList(numLightsProcessed, tileCoord, vP, vPw, Vworld); |
|||
|
|||
uint numReflectionsProcessed = 0; |
|||
c += ExecuteReflectionList(numReflectionsProcessed, tileCoord, vP, data.normalWorld, Vworld, data.smoothness); |
|||
|
|||
#if ENABLE_DEBUG |
|||
c = OverlayHeatMap(pixCoord & 15, numLightsProcessed, c); |
|||
#endif |
|||
|
|||
uavOutput[pixCoord] = float4(c, 1.0); |
|||
} |
|||
|
部分文件因为文件数量过多而无法显示
撰写
预览
正在加载...
取消
保存
Reference in new issue