浏览代码

Minor change, add unity_reversed_z

/main
sebastienlagarde 8 年前
当前提交
e0d8b29f
共有 11 个文件被更改,包括 193 次插入52 次删除
  1. 13
      Assets/ScriptableRenderLoop/HDRenderLoop/HDRenderLoop.cs
  2. 6
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Lighting/Lighting.hlsl
  3. 29
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Lighting/LightingDeferred.hlsl
  4. 13
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Lighting/LightingDeferred.shader
  5. 4
      Assets/ScriptableRenderLoop/ShaderLibrary/API/D3D11.hlsl
  6. 2
      Assets/ScriptableRenderLoop/ShaderLibrary/API/Validate.hlsl
  7. 6
      Assets/ScriptableRenderLoop/ShaderLibrary/Common.hlsl
  8. 142
      Assets/TestScenes/ForwardRenderLoop/ForwardRenderLoop.unity
  9. 13
      Assets/HDRenderLoop.asset
  10. 8
      Assets/HDRenderLoop.asset.meta
  11. 9
      Assets/ScriptableRenderLoop/ShaderLibrary/Postprocress.meta

13
Assets/ScriptableRenderLoop/HDRenderLoop/HDRenderLoop.cs


Matrix4x4 invProjh = projh.inverse;
m_DeferredMaterial.SetMatrix("_InvProjMatrix", invProjh);
Vector4 screenSize = new Vector4();
screenSize.x = camera.pixelWidth;
screenSize.y = camera.pixelHeight;
screenSize.z = 1.0f / camera.pixelWidth;
screenSize.w = 1.0f / camera.pixelHeight;
m_DeferredMaterial.SetVector("_ScreenSize", screenSize);
// gbufferManager.BindBuffers(m_DeferredMaterial);
// TODO: Bind depth textures
var cmd = new CommandBuffer();

InitAndClearBuffer(camera, renderLoop);
// RenderGBuffer(cullResults, camera, renderLoop);
RenderGBuffer(cullResults, camera, renderLoop);
// RenderDeferredLighting(camera, renderLoop);
RenderDeferredLighting(camera, renderLoop);
RenderForward(cullResults, camera, renderLoop);
// RenderForward(cullResults, camera, renderLoop);
FinalPass(renderLoop);

6
Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Lighting/Lighting.hlsl


#include "Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/Material.hlsl"
#if UNITY_SHADERRENDERPASS == UNITY_SHADERRENDERPASS_FORWARD || UNITY_SHADERRENDERPASS == UNITY_SHADERRENDERPASS_DEFERRED
#if UNITY_SHADERRENDERPASS == UNITY_SHADERRENDERPASS_FORWARD
//#elif UNITY_SHADERRENDERPASS == UNITY_SHADERRENDERPASS_DEFERRED
//#include "LightingDeferred.hlsl"
#elif UNITY_SHADERRENDERPASS == UNITY_SHADERRENDERPASS_DEFERRED
#include "LightingDeferred.hlsl"
#endif
#endif // UNITY_LIGHTING_INCLUDED

29
Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Lighting/LightingDeferred.hlsl


#ifndef UNITY_LIGHTING_DEFERRED_INCLUDED
#define UNITY_LIGHTING_DEFERRED_INCLUDED
//-----------------------------------------------------------------------------
// Simple deferred loop architecture
//-----------------------------------------------------------------------------
StructuredBuffer<PunctualLightData> g_punctualLightList;
int g_punctualLightCount;
// Currently just a copy/paste of forward ligthing as it is just for validation
void DeferredLighting(float3 V, float3 positionWS, BSDFData material,
out float4 diffuseLighting,
out float4 specularLighting)
{
diffuseLighting = float4(0.0, 0.0, 0.0, 0.0);
specularLighting = float4(0.0, 0.0, 0.0, 0.0);
for (int i = 0; i < g_punctualLightCount; ++i)
{
float4 localDiffuseLighting;
float4 localSpecularLighting;
EvaluateBSDF_Punctual(V, positionWS, g_punctualLightList[i], material, localDiffuseLighting, localSpecularLighting);
diffuseLighting += localDiffuseLighting;
specularLighting += localSpecularLighting;
}
}
#endif

13
Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Lighting/LightingDeferred.shader


DECLARE_GBUFFER_TEXTURE(_CameraGBufferTexture);
Texture2D _CameraDepthTexture;
float4 _ScreenSize;
float4x4 _InvProjMatrix;

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));
Coordinate coord = GetCoordinate(input.positionHS.xy, _ScreenSize.zw);
//#if UNITY_REVERSED_Z
//depth = 1.0 - depth; // This should be in the proj matrix ?
//#endif
float3 positionWS = UnprojectToWorld(depth, coord.positionSS, _InvProjMatrix);
float3 V = GetWorldSpaceNormalizeViewDir(positionWS);

float4 specularLighting;
ForwardLighting(V, positionWS, bsdfData, diffuseLighting, specularLighting);
return float4(diffuseLighting.rgb + specularLighting.rgb, 1.0);
//return float4(diffuseLighting.rgb + specularLighting.rgb, 1.0);
return float4(saturate(positionWS), 1.0f);
}
ENDCG

4
Assets/ScriptableRenderLoop/ShaderLibrary/API/D3D11.hlsl


// This file assume SHADER_API_D3D11 is defined
#define UNITY_UV_STARTS_AT_TOP 1
#define UNITY_UV_STARTS_AT_TOP 1
#define UNITY_REVERSED_Z 1
#define UNITY_NEAR_CLIP_VALUE (1.0)

2
Assets/ScriptableRenderLoop/ShaderLibrary/API/Validate.hlsl


#endif X_ \
REQUIRE_DEFINED(UNITY_UV_STARTS_AT_TOP)
REQUIRE_DEFINED(UNITY_REVERSED_Z)
*/

6
Assets/ScriptableRenderLoop/ShaderLibrary/Common.hlsl


Coordinate coord;
coord.positionSS = inPositionSS;
// TODO: How to detect automatically that we are a compute shader ?
// #if
#if 0
// coord.positionSS.xy += float2(0.5f, 0.5f);
//#endif
coord.positionSS.xy += float2(0.5f, 0.5f);
#endif
coord.positionSS *= invScreenSize;
coord.unPositionSS = int2(inPositionSS);

142
Assets/TestScenes/ForwardRenderLoop/ForwardRenderLoop.unity


%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!29 &1
SceneSettings:
OcclusionCullingSettings:
m_PVSData:
m_PVSObjectsArray: []
m_PVSPortalsArray: []
serializedVersion: 2
m_SceneGUID: 00000000000000000000000000000000
m_OcclusionCullingData: {fileID: 0}
--- !u!104 &2
RenderSettings:
m_ObjectHideFlags: 0

serializedVersion: 7
m_Type: 2
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_Intensity: 6.22
m_Intensity: 8
m_Range: 20
m_SpotAngle: 67.2
m_CookieSize: 10

m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 756999128}
m_LocalRotation: {x: -0.03901584, y: -0.61546946, z: 0.78589, w: 0.045300227}
m_LocalPosition: {x: -1.39, y: 1.25, z: 0.61}
m_LocalPosition: {x: -1.75, y: 1.47, z: 1.33}
m_RootOrder: 15
m_RootOrder: 16
--- !u!1001 &841426484
Prefab:
m_ObjectHideFlags: 0
serializedVersion: 2
m_Modification:
m_TransformParent: {fileID: 0}
m_Modifications:
- target: {fileID: 400012, guid: 923d7377c0525d74489f1f95dba59553, type: 3}
propertyPath: m_LocalPosition.x
value: 9.662517
objectReference: {fileID: 0}
- target: {fileID: 400012, guid: 923d7377c0525d74489f1f95dba59553, type: 3}
propertyPath: m_LocalPosition.y
value: 12.61
objectReference: {fileID: 0}
- target: {fileID: 400012, guid: 923d7377c0525d74489f1f95dba59553, type: 3}
propertyPath: m_LocalPosition.z
value: 6.806114
objectReference: {fileID: 0}
- target: {fileID: 400012, guid: 923d7377c0525d74489f1f95dba59553, type: 3}
propertyPath: m_LocalRotation.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 400012, guid: 923d7377c0525d74489f1f95dba59553, type: 3}
propertyPath: m_LocalRotation.y
value: -0
objectReference: {fileID: 0}
- target: {fileID: 400012, guid: 923d7377c0525d74489f1f95dba59553, type: 3}
propertyPath: m_LocalRotation.z
value: -0
objectReference: {fileID: 0}
- target: {fileID: 400012, guid: 923d7377c0525d74489f1f95dba59553, type: 3}
propertyPath: m_LocalRotation.w
value: 1
objectReference: {fileID: 0}
- target: {fileID: 400012, guid: 923d7377c0525d74489f1f95dba59553, type: 3}
propertyPath: m_RootOrder
value: 1
objectReference: {fileID: 0}
- target: {fileID: 2300032, guid: 923d7377c0525d74489f1f95dba59553, type: 3}
propertyPath: m_Materials.Array.data[0]
value:
objectReference: {fileID: 2100000, guid: 87c86082ee14fbd4b8426a8794f2060d, type: 2}
- target: {fileID: 2300036, guid: 923d7377c0525d74489f1f95dba59553, type: 3}
propertyPath: m_Materials.Array.data[0]
value:
objectReference: {fileID: 2100000, guid: 87c86082ee14fbd4b8426a8794f2060d, type: 2}
- target: {fileID: 2300052, guid: 923d7377c0525d74489f1f95dba59553, type: 3}
propertyPath: m_Materials.Array.data[0]
value:
objectReference: {fileID: 2100000, guid: 87c86082ee14fbd4b8426a8794f2060d, type: 2}
- target: {fileID: 2300040, guid: 923d7377c0525d74489f1f95dba59553, type: 3}
propertyPath: m_Materials.Array.data[0]
value:
objectReference: {fileID: 2100000, guid: 87c86082ee14fbd4b8426a8794f2060d, type: 2}
- target: {fileID: 2300056, guid: 923d7377c0525d74489f1f95dba59553, type: 3}
propertyPath: m_Materials.Array.data[0]
value:
objectReference: {fileID: 2100000, guid: 87c86082ee14fbd4b8426a8794f2060d, type: 2}
- target: {fileID: 2300048, guid: 923d7377c0525d74489f1f95dba59553, type: 3}
propertyPath: m_Materials.Array.data[0]
value:
objectReference: {fileID: 2100000, guid: 87c86082ee14fbd4b8426a8794f2060d, type: 2}
- target: {fileID: 2300044, guid: 923d7377c0525d74489f1f95dba59553, type: 3}
propertyPath: m_Materials.Array.data[0]
value:
objectReference: {fileID: 2100000, guid: 87c86082ee14fbd4b8426a8794f2060d, type: 2}
m_RemovedComponents: []
m_ParentPrefab: {fileID: 100100000, guid: 923d7377c0525d74489f1f95dba59553, type: 3}
m_IsPrefabParent: 0
--- !u!1 &942239534
GameObject:
m_ObjectHideFlags: 0

m_PreserveUVs: 1
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_SelectedWireframeHidden: 0
m_SelectedEditorRenderState: 3
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5
m_AutoUVMaxAngle: 89

m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 4
m_RootOrder: 5
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &1064871612
GameObject:

m_PreserveUVs: 1
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_SelectedWireframeHidden: 0
m_SelectedEditorRenderState: 3
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5
m_AutoUVMaxAngle: 89

m_LocalScale: {x: 5.425793, y: 5.4257946, z: 5.4257946}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 13
m_RootOrder: 14
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &1090653688
GameObject:

m_PreserveUVs: 1
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_SelectedWireframeHidden: 0
m_SelectedEditorRenderState: 3
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5
m_AutoUVMaxAngle: 89

m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 2
m_RootOrder: 3
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &1100543299
GameObject:

m_PreserveUVs: 1
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_SelectedWireframeHidden: 0
m_SelectedEditorRenderState: 3
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5
m_AutoUVMaxAngle: 89

m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 10
m_RootOrder: 11
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &1256381297
GameObject:

m_PreserveUVs: 1
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_SelectedWireframeHidden: 0
m_SelectedEditorRenderState: 3
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5
m_AutoUVMaxAngle: 89

m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 6
m_RootOrder: 7
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &1409545155
GameObject:

m_PreserveUVs: 1
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_SelectedWireframeHidden: 0
m_SelectedEditorRenderState: 3
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5
m_AutoUVMaxAngle: 89

m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 14
m_RootOrder: 15
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &1469174313
GameObject:

m_PreserveUVs: 1
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_SelectedWireframeHidden: 0
m_SelectedEditorRenderState: 3
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5
m_AutoUVMaxAngle: 89

m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 9
m_RootOrder: 10
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &1506796422
GameObject:

m_PreserveUVs: 1
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_SelectedWireframeHidden: 0
m_SelectedEditorRenderState: 3
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5
m_AutoUVMaxAngle: 89

m_LocalScale: {x: 1.0394905, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 12
m_RootOrder: 13
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &1597621866
GameObject:

m_PreserveUVs: 1
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_SelectedWireframeHidden: 0
m_SelectedEditorRenderState: 3
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5
m_AutoUVMaxAngle: 89

m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 5
m_RootOrder: 6
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &1713034008
GameObject:

m_Script: {fileID: 11500000, guid: 92bb16b4ee20841929b24d6bd771738d, type: 3}
m_Name:
m_EditorClassIdentifier:
m_RenderLoop: {fileID: 11400000, guid: bbb9d949788aad640a70f108f114474d, type: 2}
m_RenderLoop: {fileID: 11400000, guid: 2400b74f5ce370c4481e5dc417d03703, type: 2}
--- !u!1 &1758207072
GameObject:
m_ObjectHideFlags: 0

m_PreserveUVs: 1
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_SelectedWireframeHidden: 0
m_SelectedEditorRenderState: 3
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5
m_AutoUVMaxAngle: 89

m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 7
m_RootOrder: 8
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &1818419755
GameObject:

m_PreserveUVs: 1
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_SelectedWireframeHidden: 0
m_SelectedEditorRenderState: 3
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5
m_AutoUVMaxAngle: 89

m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 8
m_RootOrder: 9
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &1946201409
GameObject:

m_PreserveUVs: 1
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_SelectedWireframeHidden: 0
m_SelectedEditorRenderState: 3
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5
m_AutoUVMaxAngle: 89

m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 1
m_RootOrder: 2
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &2054101900
GameObject:

m_PreserveUVs: 1
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_SelectedWireframeHidden: 0
m_SelectedEditorRenderState: 3
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5
m_AutoUVMaxAngle: 89

m_LocalScale: {x: 0.78171986, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 3
m_RootOrder: 4
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &2136471011
GameObject:

m_PreserveUVs: 1
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_SelectedWireframeHidden: 0
m_SelectedEditorRenderState: 3
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5
m_AutoUVMaxAngle: 89

m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 11
m_RootOrder: 12
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}

13
Assets/HDRenderLoop.asset


%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 558064ecdbf6b6742892d699acb39aed, type: 3}
m_Name: HDRenderLoop
m_EditorClassIdentifier:

8
Assets/HDRenderLoop.asset.meta


fileFormatVersion: 2
guid: a760b5cf201f0f5478077e4ee5df8236
timeCreated: 1474961622
licenseType: Pro
NativeFormatImporter:
userData:
assetBundleName:
assetBundleVariant:

9
Assets/ScriptableRenderLoop/ShaderLibrary/Postprocress.meta


fileFormatVersion: 2
guid: d90c5a99d7855ad46b792d749ce7ca6f
folderAsset: yes
timeCreated: 1472140530
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存