Sebastien Lagarde
8 年前
当前提交
fab6bd80
共有 2 个文件被更改,包括 102 次插入 和 4 次删除
-
17Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Lighting/Lighting.hlsl
-
89Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Lighting/Deferred.shader
|
|||
#ifndef UNITY_LIGHTING_INCLUDED |
|||
#define UNITY_LIGHTING_INCLUDED |
|||
|
|||
// We need to define the macro used for env map evaluation based on the different architecture. |
|||
// Like for material we have one define by architecture. |
|||
// TODO: who setup the define for a given architecture ? |
|||
// The lighting architecture is in charge to define the light loop |
|||
// It is also in charge to define the sampling function for shadowmap, ies, cookie and reflection |
|||
// as only the lighting architecture is aware of the usage of texture atlas, array and format (latlong, 2D, cube) |
|||
|
|||
#ifdef SINGLE_PASS |
|||
#include "Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Lighting/SinglePass/SinglePass.hlsl" |
|||
//#elif ... |
|||
#endif |
|||
#include "Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Lighting/LightingForward/LightingForward.hlsl" |
|||
#ifdef SINGLE_PASS |
|||
#include "Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Lighting/SinglePass/SinglePassLoop.hlsl" |
|||
//#elif ... |
|||
#endif |
|||
|
|||
|
|||
#endif // UNITY_LIGHTING_INCLUDED |
|
|||
Shader "Hidden/Unity/Deferred" |
|||
{ |
|||
Properties |
|||
{ |
|||
_SrcBlend("", Float) = 1 |
|||
_DstBlend("", Float) = 1 |
|||
} |
|||
|
|||
SubShader |
|||
{ |
|||
|
|||
Pass |
|||
{ |
|||
ZWrite Off |
|||
Blend[_SrcBlend][_DstBlend] |
|||
|
|||
HLSLPROGRAM |
|||
#pragma target 5.0 |
|||
#pragma only_renderers d3d11 // TEMP: unitl we go futher in dev |
|||
|
|||
#pragma vertex VertDeferred |
|||
#pragma fragment FragDeferred |
|||
|
|||
// Chose supported lighting architecture in case of deferred rendering |
|||
#pragma multi_compile SINGLE_PASS |
|||
|
|||
// CAUTION: In case deferred lighting need to support various lighting model statically, we will require to do multicompile with different define like UNITY_MATERIAL_DISNEYGXX |
|||
// TODO: Currently a users that add a new deferred material must also add it manually here... Need to think about it. Maybe add a multicompile inside a file in Material directory to include here ? |
|||
#define UNITY_MATERIAL_LIT // Need to be define before including Material.hlsl |
|||
#include "Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Lighting/Lighting.hlsl" // This include Material.hlsl |
|||
#include "Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/ShaderVariables.hlsl" |
|||
|
|||
DECLARE_GBUFFER_TEXTURE(_CameraGBufferTexture); |
|||
DECLARE_GBUFFER_BAKE_LIGHTING(_CameraGBufferTexture); |
|||
|
|||
UNITY_DECLARE_TEX2D(_CameraDepthTexture); |
|||
|
|||
float4x4 _InvViewProjMatrix; |
|||
|
|||
struct Attributes |
|||
{ |
|||
float3 positionOS : POSITION; |
|||
}; |
|||
|
|||
struct Varyings |
|||
{ |
|||
float4 positionHS : SV_POSITION; |
|||
}; |
|||
|
|||
Varyings VertDeferred(Attributes input) |
|||
{ |
|||
// TODO: implement SV_vertexID full screen quad |
|||
// Lights are draw as one fullscreen quad |
|||
Varyings output; |
|||
float3 positionWS = TransformObjectToWorld(input.positionOS); |
|||
output.positionHS = TransformWorldToHClip(positionWS); |
|||
|
|||
return output; |
|||
} |
|||
|
|||
float4 FragDeferred(Varyings input) : SV_Target |
|||
{ |
|||
Coordinate coord = GetCoordinate(input.positionHS.xy, _ScreenSize.zw); |
|||
|
|||
// No need to manage inverse depth, this is handled by the projection matrix |
|||
float depth = _CameraDepthTexture.Load(uint3(coord.unPositionSS, 0)).x; |
|||
float3 positionWS = UnprojectToWorld(depth, coord.positionSS, _InvViewProjMatrix); |
|||
float3 V = GetWorldSpaceNormalizeViewDir(positionWS); |
|||
|
|||
FETCH_GBUFFER(gbuffer, _CameraGBufferTexture, coord.unPositionSS); |
|||
BSDFData bsdfData = DECODE_FROM_GBUFFER(gbuffer); |
|||
|
|||
PreLightData preLightData = GetPreLightData(V, positionWS, coord, bsdfData); |
|||
|
|||
float4 diffuseLighting; |
|||
float4 specularLighting; |
|||
FETCH_BAKE_LIGHTING_GBUFFER(gbuffer, _CameraGBufferTexture, coord.unPositionSS); |
|||
float3 bakeDiffuseLighting = DECODE_BAKE_LIGHTING_FROM_GBUFFER(gbuffer); |
|||
LightingLoop(V, positionWS, preLightData, bsdfData, bakeDiffuseLighting, diffuseLighting, specularLighting); |
|||
|
|||
return float4(diffuseLighting.rgb + specularLighting.rgb, 1.0); |
|||
} |
|||
|
|||
ENDHLSL |
|||
} |
|||
|
|||
} |
|||
Fallback Off |
|||
} |
撰写
预览
正在加载...
取消
保存
Reference in new issue