浏览代码
Add misc function for deferred rendering
Add misc function for deferred rendering
- Add world reconstruction function - Add macro to abstrct GBuffer - Add lighting information into SurfaceData and BSDFData - Clean / comment some stuff Note: forward and deferred code do not produce lighting for now/main
Sebastien Lagarde
8 年前
当前提交
6a00b2b9
共有 12 个文件被更改,包括 233 次插入 和 131 次删除
-
2Assets/ScriptableRenderLoop/HDRenderLoop/HDRenderLoop.asset.meta
-
11Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/DisneyGGX.shader
-
8Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Lighting/Lighting.hlsl
-
143Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Lighting/LightingDeferred.shader
-
6Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Lighting/LightingForward.hlsl
-
38Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/DisneyGGX.hlsl
-
60Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/Material.hlsl
-
1Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/PostProcess/FinalPass.shader
-
20Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/ShaderVariables.hlsl
-
10Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/TemplateDisneyGGX.hlsl
-
56Assets/ScriptableRenderLoop/ShaderLibrary/Common.hlsl
-
9Assets/ScriptableRenderLoop/ShaderLibrary/Postprocress.meta
|
|||
fileFormatVersion: 2 |
|||
guid: 2400b74f5ce370c4481e5dc417d03703 |
|||
timeCreated: 1474539935 |
|||
timeCreated: 1474923798 |
|||
licenseType: Pro |
|||
NativeFormatImporter: |
|||
userData: |
|
|||
#ifndef UNITY_LIGHTING_INCLUDED |
|||
#define UNITY_LIGHTING_INCLUDED |
|||
|
|||
#include "../Material/Material.hlsl" |
|||
#include "Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/Material.hlsl" |
|||
#if UNITY_SHADERRENDERPASS == UNITY_SHADERRENDERPASS_FORWARD |
|||
#if UNITY_SHADERRENDERPASS == UNITY_SHADERRENDERPASS_FORWARD || UNITY_SHADERRENDERPASS == UNITY_SHADERRENDERPASS_DEFERRED |
|||
#elif UNITY_SHADERRENDERPASS == UNITY_SHADERRENDERPASS_DEFERRED |
|||
#include "LightingDeferred.hlsl" |
|||
//#elif UNITY_SHADERRENDERPASS == UNITY_SHADERRENDERPASS_DEFERRED |
|||
//#include "LightingDeferred.hlsl" |
|||
#endif |
|||
|
|||
#endif // UNITY_LIGHTING_INCLUDED |
|
|||
Shader "Hidden/Unity/LightingDeferred" { |
|||
Properties{ |
|||
_SrcBlend("", Float) = 1 |
|||
_DstBlend("", Float) = 1 |
|||
} |
|||
SubShader{ |
|||
Shader "Hidden/Unity/LightingDeferred" |
|||
{ |
|||
Properties |
|||
{ |
|||
_SrcBlend("", Float) = 1 |
|||
_DstBlend("", Float) = 1 |
|||
} |
|||
|
|||
SubShader |
|||
{ |
|||
Pass{ |
|||
ZWrite Off |
|||
Blend[_SrcBlend][_DstBlend] |
|||
Pass |
|||
{ |
|||
ZWrite Off |
|||
Blend[_SrcBlend][_DstBlend] |
|||
CGPROGRAM |
|||
#pragma target 5.0 |
|||
#pragma only_renderers d3d11 // TEMP: unitl we go futher in dev |
|||
CGPROGRAM |
|||
#pragma target 5.0 |
|||
#pragma only_renderers d3d11 // TEMP: unitl we go futher in dev |
|||
#pragma vertex VertDeferred |
|||
#pragma fragment FragDeferred |
|||
#pragma vertex VertDeferred |
|||
#pragma fragment FragDeferred |
|||
#define UNITY_SHADERRENDERPASS UNITY_SHADERRENDERPASS_DEFERRED |
|||
// 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 |
|||
#define UNITY_MATERIAL_DISNEYGXX // Need to be define before including Material.hlsl |
|||
#include "Lighting/Lighting.hlsl" // This include Material.hlsl |
|||
#include "ShaderVariables.hlsl" |
|||
#define UNITY_SHADERRENDERPASS UNITY_SHADERRENDERPASS_DEFERRED |
|||
// 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 |
|||
#define UNITY_MATERIAL_DISNEYGXX // Need to be define before including Material.hlsl |
|||
#include "Lighting.hlsl" // This include Material.hlsl |
|||
#include "Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/ShaderVariables.hlsl" |
|||
sampler2D _CameraGBufferTexture0; |
|||
sampler2D _CameraGBufferTexture1; |
|||
sampler2D _CameraGBufferTexture2; |
|||
sampler2D _CameraGBufferTexture3; |
|||
DECLARE_GBUFFER_TEXTURE(_CameraGBufferTexture); |
|||
Texture2D _CameraDepthTexture; |
|||
sampler2D_float _CameraDepthTexture; |
|||
float4x4 _InvProjMatrix; |
|||
float _LightAsQuad; |
|||
struct Attributes |
|||
{ |
|||
float3 positionOS : POSITION; |
|||
}; |
|||
struct Attributes |
|||
{ |
|||
float3 positionOS : POSITION; |
|||
float3 normalOS : NORMAL; |
|||
}; |
|||
struct Varyings |
|||
{ |
|||
float4 positionHS : SV_POSITION; |
|||
}; |
|||
struct Varyings |
|||
{ |
|||
float4 positionHS : SV_POSITION; |
|||
float4 uv : TEXCOORD0; |
|||
float3 ray : TEXCOORD1; |
|||
}; |
|||
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); |
|||
Varyings VertDeferred(Attributes input) |
|||
{ |
|||
Varyings output; |
|||
output.positionWS = TransformObjectToWorld(input.positionOS); |
|||
output.positionHS = TransformWorldToHClip(output.positionWS); |
|||
output.uv = ComputeScreenPos(o.positionOS); |
|||
output.ray = TransformObjectToView(input.positionOS) * float3(-1, -1, 1); |
|||
return output; |
|||
} |
|||
// normal contains a ray pointing from the camera to one of near plane's |
|||
// corners in camera space when we are drawing a full screen quad. |
|||
// Otherwise, when rendering 3D shapes, use the ray calculated here. |
|||
output.ray = lerp(output.ray, normalOS, _LightAsQuad); |
|||
float4 FragDeferred(Varyings input) : SV_Target |
|||
{ |
|||
// TEMP: It is cheaper to pass inv screen size than using GetDimension on GCN |
|||
uint width; |
|||
uint height; |
|||
_CameraDepthTexture.GetDimensions(width, height); |
|||
Coordinate coord = GetCoordinate(input.positionHS.xy, float2(width, height)); |
|||
return output; |
|||
} |
|||
// 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, _InvProjMatrix); |
|||
float3 V = GetWorldSpaceNormalizeViewDir(positionWS); |
|||
float4 FragDeferred(Varyings input) : SV_Target |
|||
{ |
|||
/* |
|||
input.ray = input.ray * tex2D(_CameraDepthTexture.z / input.ray.z); |
|||
float2 uv = input.uv.xy / input.uv.w; |
|||
FETCH_GBUFFER(gbuffer, _CameraGBufferTexture, coord.unPositionSS); |
|||
BSDFData bsdfData = DECODE_FROM_GBUFFER(gbuffer); |
|||
// read depth and reconstruct world position |
|||
float depth = SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, uv); |
|||
depth = Linear01Depth(depth); |
|||
float4 vpos = float4(i.ray * depth, 1); |
|||
float3 wpos = mul(unity_CameraToWorld, vpos).xyz; |
|||
// NOTE: Currently calling the forward loop, same code... :) |
|||
float4 diffuseLighting; |
|||
float4 specularLighting; |
|||
ForwardLighting(V, positionWS, bsdfData, diffuseLighting, specularLighting); |
|||
// read depth and reconstruct world position |
|||
float depth = SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, uv); |
|||
depth = Linear01Depth(depth); |
|||
float4 vpos = float4(i.ray * depth, 1); |
|||
float3 wpos = mul(unity_CameraToWorld, vpos).xyz; |
|||
return float4(diffuseLighting.rgb + specularLighting.rgb, 1.0); |
|||
} |
|||
// unpack Gbuffer |
|||
float4 gbuffer0 = tex2D(_CameraGBufferTexture0, input.uv); |
|||
float4 gbuffer1 = tex2D(_CameraGBufferTexture1, input.uv); |
|||
float4 gbuffer2 = tex2D(_CameraGBufferTexture2, input.uv); |
|||
float4 gbuffer3 = tex2D(_CameraGBufferTexture3, input.uv); |
|||
|
|||
BSDFData bsdfData = DecodeFromGBuffer(gbuffer0, gbuffer1, gbuffer2); |
|||
|
|||
return bsdfData.diffuseColor; |
|||
*/ |
|||
|
|||
return float4(1, 0, 0, 0); |
|||
ENDCG |
|||
|
|||
ENDCG |
|||
} |
|||
|
|||
} |
|||
Fallback Off |
|
|||
fileFormatVersion: 2 |
|||
guid: d90c5a99d7855ad46b792d749ce7ca6f |
|||
folderAsset: yes |
|||
timeCreated: 1472140530 |
|||
licenseType: Pro |
|||
DefaultImporter: |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
撰写
预览
正在加载...
取消
保存
Reference in new issue