浏览代码

HDRenderLoop: Lot of stuffs - try to prepare for various lighting architecture

- Move and rename file
- Design for various lighting architecture
/main
Sebastien Lagarde 8 年前
当前提交
00afee16
共有 31 个文件被更改,包括 328 次插入98 次删除
  1. 2
      Assets/ScriptableRenderLoop/HDRenderLoop/HDRenderLoop.cs
  2. 2
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Debug/DebugViewMaterialGBuffer.shader
  3. 42
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Lighting/LightDefinition.cs
  4. 72
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Lighting/LightDefinition.cs.hlsl
  5. 7
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/Lit/Lit.hlsl
  6. 2
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/Lit/LitData.hlsl
  7. 5
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/Lit/LitDefault.shader
  8. 2
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/Lit/LitEnvTemplate.hlsl
  9. 2
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/Lit/LitShare.hlsl
  10. 5
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/Unlit/Unlit.hlsl
  11. 2
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/Unlit/UnlitData.hlsl
  12. 2
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/Unlit/UnlitShare.hlsl
  13. 5
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/ShaderPass/ShaderPassForward.hlsl
  14. 9
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Lighting/Deferred.shader.meta
  15. 16
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Lighting/Forward.hlsl
  16. 28
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Lighting/ShadowDefinition.cs
  17. 51
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Lighting/ShadowDefinition.cs.hlsl
  18. 9
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Lighting/ShadowDefinition.cs.hlsl.meta
  19. 12
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Lighting/ShadowDefinition.cs.meta
  20. 9
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Lighting/SinglePass.meta
  21. 17
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Lighting/SinglePass/SinglePass.cs
  22. 12
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Lighting/SinglePass/SinglePass.cs.meta
  23. 15
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Lighting/SinglePass/SinglePass.hlsl
  24. 9
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Lighting/SinglePass/SinglePass.hlsl.meta
  25. 62
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Lighting/SinglePass/SinglePassLoop.hlsl
  26. 9
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Lighting/SinglePass/SinglePassLoop.hlsl.meta
  27. 9
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Lighting/LightingDeferred.meta
  28. 9
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Lighting/LightingForward.meta

2
Assets/ScriptableRenderLoop/HDRenderLoop/HDRenderLoop.cs


s_punctualLightList = new ComputeBuffer(MaxLights, System.Runtime.InteropServices.Marshal.SizeOf(typeof(PunctualLightData)));
s_envLightList = new ComputeBuffer(MaxLights, System.Runtime.InteropServices.Marshal.SizeOf(typeof(EnvLightData)));
m_DeferredMaterial = CreateEngineMaterial("Hidden/Unity/LightingDeferred");
m_DeferredMaterial = CreateEngineMaterial("Hidden/Unity/Deferred");
m_FinalPassMaterial = CreateEngineMaterial("Hidden/Unity/FinalPass");
// Debug

2
Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Debug/DebugViewMaterialGBuffer.shader


#include "Color.hlsl"
// CAUTION: In case deferred lighting need to support various lighting model statically, we will require to do multicompile with different define like UNITY_MATERIAL_LIT
#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/Material/Material.hlsl"
#include "Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/ShaderVariables.hlsl"
#include "Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Debug/DebugViewMaterial.hlsl"

42
Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Lighting/LightDefinition.cs


//-----------------------------------------------------------------------------
namespace UnityEngine.Experimental.ScriptableRenderLoop
{
[GenerateHLSL]
// Power of two value as they are flag
public enum LightFlags
{
HasShadow = (1 << 0),
HasCookie = (1 << 1),
HasIES = (1 << 2)
}
// These structures share between C# and hlsl need to be align on float4, so we pad them.
[GenerateHLSL]
public struct PunctualLightData

public float useDistanceAttenuation;
public Vector3 forward;
public float diffuseScale;
public float angleScale;
public float specularScale;
public float angleOffset;
public LightFlags flags;
public float diffuseScale;
public float specularScale;
public int ShadowIndex;
public float angleScale;
public float angleOffset;
public int flags;
public int CookieIndex;
public Vector2 unused;
};
[GenerateHLSL]

public float unused1;
};
struct PunctualShadowData
{
// World to ShadowMap matrix
// Include scale and bias for shadow atlas if any
public Vector4 shadowMatrix1;
public Vector4 shadowMatrix2;
public Vector4 shadowMatrix3;
public Vector4 shadowMatrix4;
float4 shadowMapAtlasParam[6]; // shadow map size and offset of atlas per face
float shadowMapIndex[6]; //the shadow map index per face
float shadowType; // Disabled, spot, point
float quality; // shadow filtering quality
float shadowAngleScale;
float shadowAngleOffset;
float2 unused;
};
} // namespace UnityEngine.Experimental.ScriptableRenderLoop

72
Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Lighting/LightDefinition.cs.hlsl


//
//
// UnityEngine.Experimental.ScriptableRenderLoop.LightFlags: static fields
//
#define LIGHTFLAGS_HAS_SHADOW (1)
#define LIGHTFLAGS_HAS_COOKIE (2)
#define LIGHTFLAGS_HAS_IES (4)
//
// UnityEngine.Experimental.ScriptableRenderLoop.AreaShapeType: static fields
//
#define AREASHAPETYPE_RECTANGLE (0)

float3 color;
float useDistanceAttenuation;
float3 forward;
float diffuseScale;
float angleScale;
float angleOffset;
float3 right;
int flags;
float diffuseScale;
float3 right;
float angleScale;
float angleOffset;
float2 unused2;
int ShadowIndex;
int IESIndex;
int CookieIndex;
float2 unused;
};
// Generated from UnityEngine.Experimental.ScriptableRenderLoop.AreaLightData

float unused1;
};
// Generated from UnityEngine.Experimental.ScriptableRenderLoop.PlanarLightData
// PackingRules = Exact
struct PlanarLightData
{
float3 positionWS;
};
//
// Accessors for UnityEngine.Experimental.ScriptableRenderLoop.PunctualLightData
//

{
return value.forward;
}
float GetDiffuseScale(PunctualLightData value)
float GetAngleScale(PunctualLightData value)
return value.diffuseScale;
return value.angleScale;
float GetSpecularScale(PunctualLightData value)
float GetAngleOffset(PunctualLightData value)
return value.specularScale;
return value.angleOffset;
int GetFlags(PunctualLightData value)
{
return value.flags;
}
float GetDiffuseScale(PunctualLightData value)
{
return value.diffuseScale;
}
float GetSpecularScale(PunctualLightData value)
{
return value.specularScale;
}
float GetAngleScale(PunctualLightData value)
int GetShadowIndex(PunctualLightData value)
return value.angleScale;
return value.ShadowIndex;
float GetAngleOffset(PunctualLightData value)
int GetIESIndex(PunctualLightData value)
return value.angleOffset;
return value.IESIndex;
float2 GetUnused2(PunctualLightData value)
int GetCookieIndex(PunctualLightData value)
return value.unused2;
return value.CookieIndex;
}
float2 GetUnused(PunctualLightData value)
{
return value.unused;
}
//

float GetUnused1(EnvLightData value)
{
return value.unused1;
}
//
// Accessors for UnityEngine.Experimental.ScriptableRenderLoop.PlanarLightData
//
float3 GetPositionWS(PlanarLightData value)
{
return value.positionWS;
}

7
Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/Lit/Lit.hlsl


#ifndef UNITY_MATERIAL_LIT_INCLUDED
#define UNITY_MATERIAL_LIT_INCLUDED
//-----------------------------------------------------------------------------
// SurfaceData and BSDFData
//-----------------------------------------------------------------------------

// TODO: measure impact of having all these dynamic branch here and the gain (or not) of testing illuminace > 0
/*
const bool hasCookie = (lightData.flags & LIGHTFLAGS_HAS_COOKIE) == 0;
[branch] if (hasCookie && illuminance > 0.0f)
{

shadowAttenuation = lerp(1.0, shadowAttenuation, lightData.shadowDimmer);
illuminance *= shadowAttenuation;
}
*/
if (illuminance > 0.0f)
{

#include "LitEnvTemplate.hlsl"
#undef UNITY_ARGS_ENV
#undef UNITY_SAMPLE_ENV_LOD
#endif // UNITY_MATERIAL_LIT_INCLUDED

2
Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/Lit/LitData.hlsl


// No guard header!
//-------------------------------------------------------------------------------------
// FragInput
// This structure gather all possible varying/interpolator for this shader.

5
Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/Lit/LitDefault.shader


#pragma fragment Frag
#define SHADERPASS SHADERPASS_GBUFFER
#include "../../Lighting/Lighting.hlsl" // This include Material.hlsl
#include "../../Material/Material.hlsl"
#include "LitData.hlsl"
#include "LitShare.hlsl"

#pragma fragment Frag
#define SHADERPASS SHADERPASS_FORWARD
// TEMP until pragma work in include
// #include "../../Lighting/Forward.hlsl"
#pragma multi_compile SINGLE_PASS
#include "../../Lighting/Lighting.hlsl"
#include "LitData.hlsl"
#include "LitShare.hlsl"

2
Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/Lit/LitEnvTemplate.hlsl


// No guard header!
//-----------------------------------------------------------------------------
// EvaluateBSDF_Env - Reference
// ----------------------------------------------------------------------------

2
Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/Lit/LitShare.hlsl


// No guard header!
#ifndef SHADERPASS
#error Undefine_SHADERPASS
#endif

5
Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/Unlit/Unlit.hlsl


#ifndef UNITY_UNLIT_INCLUDED
#define UNITY_UNLIT_INCLUDED
//-----------------------------------------------------------------------------
// SurfaceData and BSDFData
//-----------------------------------------------------------------------------

break;
}
}
#endif // UNITY_UNLIT_INCLUDED

2
Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/Unlit/UnlitData.hlsl


// No guard header!
//-------------------------------------------------------------------------------------
// FragInput
// This structure gather all possible varying/interpolator for this shader.

2
Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/Unlit/UnlitShare.hlsl


// No guard header!
#ifndef SHADERPASS
#error Undefine_SHADERPASS
#endif

5
Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/ShaderPass/ShaderPassForward.hlsl


float4 diffuseLighting;
float4 specularLighting;
ForwardLighting(V, positionWS, preLightData, bsdfData, diffuseLighting, specularLighting);
diffuseLighting.rgb += GetBakedDiffuseLigthing(preLightData, surfaceData, builtinData, bsdfData);
float3 bakeDiffuseLighting = GetBakedDiffuseLigthing(preLightData, surfaceData, builtinData, bsdfData);
LightingLoop(V, positionWS, preLightData, bsdfData, bakeDiffuseLighting, diffuseLighting, specularLighting);
return float4(diffuseLighting.rgb + specularLighting.rgb, builtinData.opacity);
}

9
Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Lighting/Deferred.shader.meta


fileFormatVersion: 2
guid: 00dd221e34a6ab349a1196b0f2fab693
timeCreated: 1477266585
licenseType: Pro
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:

16
Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Lighting/Forward.hlsl


// There is two kind of lighting architectures.
// Those that are control from inside the "Material".shader with "Pass" concept like forward lighting. Call later forward lighting architecture.
// Those that are control outside the "Material".shader in a "Lighting".shader like deferred lighting. Call later deferred lighting architecture.
// When dealing with deferred lighting architecture, the renderloop is in charge to call the correct .shader.
// RenderLoop can do multiple call of various deferred lighting architecture.
// (Note: enabled variant for deferred lighting architecture are in deferred.shader)
// When dealing with forward lighting architecture, the renderloop must specify a shader pass (like "forward") but it also need
// to specify which variant of the forward lighting architecture he want (with cmd.EnableShaderKeyword()).
// Renderloop can suppose dynamically switching from regular forward to tile forward for example within the same "Forward" pass.
// The purpose of the following pragma is to define the variant available for "Forward" Pass in "Material".shader.
// If only one keyword is present it mean that only one type of forward lighting architecture is supported.
// Must match name in GetKeyword() method of forward lighting architecture .cs file
// #pragma multi_compile SINGLE_PASS -> can't use a pragma from include... (for now)

28
Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Lighting/ShadowDefinition.cs


using UnityEngine;
//-----------------------------------------------------------------------------
// structure definition
//-----------------------------------------------------------------------------
namespace UnityEngine.Experimental.ScriptableRenderLoop
{
[GenerateHLSL]
public enum ShadowType
{
Spot,
Point
}
[GenerateHLSL]
public struct PunctualShadowData
{
// World to ShadowMap matrix
// Include scale and bias for shadow atlas if any
public Vector4 shadowMatrix1;
public Vector4 shadowMatrix2;
public Vector4 shadowMatrix3;
public Vector4 shadowMatrix4;
public ShadowType shadowType;
public Vector3 unused;
};
} // namespace UnityEngine.Experimental.ScriptableRenderLoop

51
Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Lighting/ShadowDefinition.cs.hlsl


//
// This file was automatically generated from Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Lighting/ShadowDefinition.cs. Please don't edit by hand.
//
//
// UnityEngine.Experimental.ScriptableRenderLoop.ShadowType: static fields
//
#define SHADOWTYPE_SPOT (0)
#define SHADOWTYPE_POINT (1)
// Generated from UnityEngine.Experimental.ScriptableRenderLoop.PunctualShadowData
// PackingRules = Exact
struct PunctualShadowData
{
float4 shadowMatrix1;
float4 shadowMatrix2;
float4 shadowMatrix3;
float4 shadowMatrix4;
int shadowType;
float3 unused;
};
//
// Accessors for UnityEngine.Experimental.ScriptableRenderLoop.PunctualShadowData
//
float4 GetShadowMatrix1(PunctualShadowData value)
{
return value.shadowMatrix1;
}
float4 GetShadowMatrix2(PunctualShadowData value)
{
return value.shadowMatrix2;
}
float4 GetShadowMatrix3(PunctualShadowData value)
{
return value.shadowMatrix3;
}
float4 GetShadowMatrix4(PunctualShadowData value)
{
return value.shadowMatrix4;
}
int GetShadowType(PunctualShadowData value)
{
return value.shadowType;
}
float3 GetUnused(PunctualShadowData value)
{
return value.unused;
}

9
Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Lighting/ShadowDefinition.cs.hlsl.meta


fileFormatVersion: 2
guid: f22956c3631d5f64388bdb93e12ec747
timeCreated: 1477268655
licenseType: Pro
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:

12
Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Lighting/ShadowDefinition.cs.meta


fileFormatVersion: 2
guid: 548c943bc73a18d4998420073b25d44b
timeCreated: 1477263464
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

9
Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Lighting/SinglePass.meta


fileFormatVersion: 2
guid: 16efe1cc514ae594993f6705dacbf97d
folderAsset: yes
timeCreated: 1477266406
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

17
Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Lighting/SinglePass/SinglePass.cs


using UnityEngine;
using UnityEngine.Experimental.Rendering;
using System;
//-----------------------------------------------------------------------------
// structure definition
//-----------------------------------------------------------------------------
namespace UnityEngine.Experimental.ScriptableRenderLoop
{
public class SinglePass
{
string GetKeyword()
{
return "SINGLE_PASS";
}
};
}

12
Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Lighting/SinglePass/SinglePass.cs.meta


fileFormatVersion: 2
guid: cb651810696af0d4789441b1f469aa2f
timeCreated: 1477266406
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

15
Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Lighting/SinglePass/SinglePass.hlsl


//-----------------------------------------------------------------------------
// Single pass forward loop architecture
// It use maxed list of lights of the scene - use just as proof of concept - do not used in regular game
//-----------------------------------------------------------------------------
/*
float SampleShadow(int shadowIndex)
{
PunctualShadowData shadowData = _PunctualShadowList[shadowIndex];
getShadowTextureSpaceCoordinate(shadowData.marix);
shadowData
return UNITY_SAMPLE_SHADOW(_ShadowMapAtlas, ...);
}
*/

9
Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Lighting/SinglePass/SinglePass.hlsl.meta


fileFormatVersion: 2
guid: 16878a2c634119a4ab27e2c83a09b20e
timeCreated: 1477266410
licenseType: Pro
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:

62
Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Lighting/SinglePass/SinglePassLoop.hlsl


// Users can use SHADERPASS_FORWARD here to dinstinguish behavior between deferred and forward.
StructuredBuffer<PunctualLightData> _PunctualLightList;
int _PunctualLightCount;
StructuredBuffer<EnvLightData> _EnvLightList;
int _EnvLightCount;
// Use texture array for reflection
UNITY_DECLARE_TEXCUBEARRAY(_EnvTextures);
/*
// Use texture atlas for shadow map
StructuredBuffer<PunctualShadowData> _PunctualShadowList;
UNITY_DECLARE_SHADOWMAP(_ShadowMapAtlas);
*/
// bakeDiffuseLighting is part of the prototype so a user is able to implement a "base pass" with GI and multipass direct light (aka old unity rendering path)
void LightingLoop( float3 V, float3 positionWS, PreLightData prelightData, BSDFData bsdfData, float3 bakeDiffuseLighting,
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 < _PunctualLightCount; ++i)
{
float4 localDiffuseLighting;
float4 localSpecularLighting;
EvaluateBSDF_Punctual(V, positionWS, prelightData, _PunctualLightList[i], bsdfData, localDiffuseLighting, localSpecularLighting);
diffuseLighting += localDiffuseLighting;
specularLighting += localSpecularLighting;
}
/*
for (int i = 0; i < 4; ++i)
{
float4 localDiffuseLighting;
float4 localSpecularLighting;
EvaluateBSDF_Area(V, positionWS, areaLightData[i], bsdfData, localDiffuseLighting, localSpecularLighting);
diffuseLighting += localDiffuseLighting;
specularLighting += localSpecularLighting;
}
*/
float4 iblDiffuseLighting = float4(0.0, 0.0, 0.0, 0.0);
float4 iblSpecularLighting = float4(0.0, 0.0, 0.0, 0.0);
for (int j = 0; j < _EnvLightCount; ++j)
{
float4 localDiffuseLighting;
float4 localSpecularLighting;
EvaluateBSDF_Env(V, positionWS, prelightData, _EnvLightList[j], bsdfData, UNITY_PASS_TEXCUBEARRAY(_EnvTextures), localDiffuseLighting, localSpecularLighting);
iblDiffuseLighting.rgb = lerp(iblDiffuseLighting.rgb, localDiffuseLighting.rgb, localDiffuseLighting.a); // Should be remove by the compiler if it is smart as all is constant 0
iblSpecularLighting.rgb = lerp(iblSpecularLighting.rgb, localSpecularLighting.rgb, localSpecularLighting.a);
}
diffuseLighting += iblDiffuseLighting;
diffuseLighting.rgb += bakeDiffuseLighting;
specularLighting += iblSpecularLighting;
}

9
Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Lighting/SinglePass/SinglePassLoop.hlsl.meta


fileFormatVersion: 2
guid: beb12ac3f2147dd499eee23eab1aea89
timeCreated: 1477266410
licenseType: Pro
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:

9
Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Lighting/LightingDeferred.meta


fileFormatVersion: 2
guid: df85c88f855185249aad13cf37a4952a
folderAsset: yes
timeCreated: 1476653183
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

9
Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Lighting/LightingForward.meta


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