浏览代码

HDRenderloop: Progress in supporting IES and shadowmap

- Add AffectDiffuse/AffectSpecular/GetShadowDimmer UI
- Add draft of shadow map support (not working)
- Add IES in shader (not in light)
- Add LightLoopContext struct
- Add various Texture/sampler macro
- Add GetCubeFaceID
- misc stuff
/main
sebastienlagarde 8 年前
当前提交
f53cd1c7
共有 16 个文件被更改,包括 367 次插入85 次删除
  1. 30
      Assets/ScriptableRenderLoop/AdditionalLightData.cs
  2. 68
      Assets/ScriptableRenderLoop/HDRenderLoop/HDRenderLoop.cs
  3. 4
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Lighting/LightDefinition.cs
  4. 8
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Lighting/LightDefinition.cs.hlsl
  5. 2
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Lighting/Lighting.hlsl
  6. 14
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Lighting/ShadowDefinition.cs
  7. 27
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Lighting/ShadowDefinition.cs.hlsl
  8. 117
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Lighting/SinglePass/SinglePass.hlsl
  9. 21
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Lighting/SinglePass/SinglePassLoop.hlsl
  10. 40
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/Lit/Lit.hlsl
  11. 19
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/Material.hlsl
  12. 41
      Assets/ScriptableRenderLoop/ShaderLibrary/API/D3D11.hlsl
  13. 29
      Assets/ScriptableRenderLoop/ShaderLibrary/Common.hlsl
  14. 19
      Assets/ScriptableRenderLoop/ShaderLibrary/CommonLighting.hlsl
  15. 4
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Lighting/Shadow.hlsl
  16. 9
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Lighting/Shadow.hlsl.meta

30
Assets/ScriptableRenderLoop/AdditionalLightData.cs


[RangeAttribute(0.0F, 100.0F)]
public float innerSpotPercent = 0.0F;
[RangeAttribute(0.0F, 1.0F)]
public float shadowDimmer = 1.0F;
public bool affectDiffuse = true;
public bool affectSpecular = true;
public static float GetInnerSpotPercent01(AdditionalLightData lightData)
{
if (lightData != null)

}
public static bool GetAffectDiffuse(AdditionalLightData lightData)
{
if (lightData != null)
return lightData.affectDiffuse;
else
return true;
}
public static bool GetAffectSpecular(AdditionalLightData lightData)
{
if (lightData != null)
return lightData.affectSpecular;
else
return true;
}
public static float GetShadowDimmer(AdditionalLightData lightData)
{
if (lightData != null)
return Mathf.Clamp(lightData.shadowDimmer, 0F, 1F);
else
return 1.0F;
}
public static int GetShadowResolution(AdditionalLightData lightData)

68
Assets/ScriptableRenderLoop/HDRenderLoop/HDRenderLoop.cs


}
public const int MaxLights = 32;
public const int MaxShadows = 16; // Max shadow allowed on screen simultaneously - a point light is 6 shadows
public const int MaxProbes = 32;
[SerializeField]

static private ComputeBuffer s_punctualLightList;
static private ComputeBuffer s_envLightList;
static private ComputeBuffer s_punctualShadowList;
private TextureCacheCubemap m_cubeReflTexArray;

if (s_punctualLightList != null)
s_punctualLightList.Release();
if (s_punctualShadowList != null)
s_punctualShadowList.Release();
if (s_envLightList != null)
s_envLightList.Release();
}

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

s_punctualLightList.Release();
s_envLightList.Release();
s_punctualShadowList.Release();
if (m_DeferredMaterial) DestroyImmediate(m_DeferredMaterial);
if (m_FinalPassMaterial) DestroyImmediate(m_FinalPassMaterial);

//---------------------------------------------------------------------------------------------------------------------------------------------------
void UpdatePunctualLights(VisibleLight[] visibleLights, ref ShadowOutput shadow)
void UpdatePunctualLights(VisibleLight[] visibleLights, ref ShadowOutput shadowOutput)
var shadows = new List<PunctualShadowData>();
for (int lightIndex = 0; lightIndex < Math.Min(visibleLights.Length, MaxLights); lightIndex++)
{

var additionalLightData = light.light.GetComponent<AdditionalLightData>();
var l = new PunctualLightData();

l.up = light.light.transform.up;
l.right = light.light.transform.right;
l.diffuseScale = 1.0f;
l.specularScale = 1.0f;
l.shadowDimmer = 1.0f;
var additionalLightData = light.light.GetComponent<AdditionalLightData>();
var innerConePercent = AdditionalLightData.GetInnerSpotPercent01(additionalLightData);
var cosSpotOuterHalfAngle = Mathf.Clamp(Mathf.Cos(spotAngle * 0.5f * Mathf.Deg2Rad), 0.0f, 1.0f);
var cosSpotInnerHalfAngle = Mathf.Clamp(Mathf.Cos(spotAngle * 0.5f * innerConePercent * Mathf.Deg2Rad), 0.0f, 1.0f); // inner cone

l.angleOffset = 2.0f;
}
l.diffuseScale = AdditionalLightData.GetAffectDiffuse(additionalLightData) ? 1.0f : 0.0f;
l.specularScale = AdditionalLightData.GetAffectSpecular(additionalLightData) ? 1.0f : 0.0f;
l.shadowDimmer = AdditionalLightData.GetShadowDimmer(additionalLightData);
l.flags = 0;
l.IESIndex = 0;
l.cookieIndex = 0;
l.shadowIndex = 0;
// Setup shadow data arrays
bool hasShadows = shadowOutput.GetShadowSliceCountLightIndex(lightIndex) != 0;
bool hasNotReachMaxLimit = shadows.Count + (light.lightType == LightType.Point ? 6 : 1) <= MaxShadows;
if (hasShadows && hasNotReachMaxLimit) // Note < MaxShadows should be check at shadowOutput creation
{
// When we have a point light, we assumed that there is 6 consecutive PunctualShadowData
l.shadowIndex = shadows.Count;
l.flags |= LightFlags.HasShadow;
for (int sliceIndex = 0; sliceIndex < shadowOutput.GetShadowSliceCountLightIndex(lightIndex); ++sliceIndex)
{
var shadowSliceIndex = shadowOutput.GetShadowSliceIndex(lightIndex, sliceIndex);
Matrix4x4 worldToShadow = shadowOutput.shadowSlices[shadowSliceIndex].shadowTransform.transpose;
PunctualShadowData s = new PunctualShadowData();
s.worldToShadow0 = worldToShadow.GetRow(0);
s.worldToShadow1 = worldToShadow.GetRow(1);
s.worldToShadow2 = worldToShadow.GetRow(2);
s.worldToShadow3 = worldToShadow.GetRow(3);
if (light.lightType == LightType.Spot)
{
s.shadowType = ShadowType.Spot;
}
else if (light.lightType == LightType.Point)
{
s.shadowType = ShadowType.Point;
}
else
{
s.shadowType = ShadowType.Directional;
}
shadows.Add(s);
}
}
s_punctualShadowList.SetData(shadows.ToArray());
Shader.SetGlobalBuffer("_PunctualShadowList", s_punctualShadowList);
}
void UpdateReflectionProbes(VisibleReflectionProbe[] activeReflectionProbes)

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


public float diffuseScale;
public float specularScale;
public float shadowDimmer;
public int ShadowIndex;
public int shadowIndex;
public int CookieIndex;
public int cookieIndex;
public Vector2 unused;
};

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


float diffuseScale;
float specularScale;
float shadowDimmer;
int ShadowIndex;
int shadowIndex;
int CookieIndex;
int cookieIndex;
float2 unused;
};

}
int GetShadowIndex(PunctualLightData value)
{
return value.ShadowIndex;
return value.shadowIndex;
}
int GetIESIndex(PunctualLightData value)
{

{
return value.CookieIndex;
return value.cookieIndex;
}
float2 GetUnused(PunctualLightData value)
{

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


#define LIGHTING // This define is used to know that we have include lighting when compiling material, else it will generate "default" function that are neutral to use Material.hlsl alone.
#include "Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Lighting/ShadowDefinition.cs.hlsl"
#ifdef SINGLE_PASS
#include "Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Lighting/SinglePass/SinglePass.hlsl"
//#elif ...

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


public enum ShadowType
{
Spot,
Point
}
Directional,
Point
};
// A point light is 6x PunctualShadowData
public Vector4 shadowMatrix1;
public Vector4 shadowMatrix2;
public Vector4 shadowMatrix3;
public Vector4 shadowMatrix4;
public Vector4 worldToShadow0;
public Vector4 worldToShadow1;
public Vector4 worldToShadow2;
public Vector4 worldToShadow3;
public ShadowType shadowType;
public Vector3 unused;

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


// UnityEngine.Experimental.ScriptableRenderLoop.ShadowType: static fields
//
#define SHADOWTYPE_SPOT (0)
#define SHADOWTYPE_POINT (1)
#define SHADOWTYPE_DIRECTIONAL (1)
#define SHADOWTYPE_POINT (2)
float4 shadowMatrix1;
float4 shadowMatrix2;
float4 shadowMatrix3;
float4 shadowMatrix4;
float4 worldToShadow0;
float4 worldToShadow1;
float4 worldToShadow2;
float4 worldToShadow3;
int shadowType;
float3 unused;
};

//
float4 GetShadowMatrix1(PunctualShadowData value)
float4 GetWorldToShadow0(PunctualShadowData value)
return value.shadowMatrix1;
return value.worldToShadow0;
float4 GetShadowMatrix2(PunctualShadowData value)
float4 GetWorldToShadow1(PunctualShadowData value)
return value.shadowMatrix2;
return value.worldToShadow1;
float4 GetShadowMatrix3(PunctualShadowData value)
float4 GetWorldToShadow2(PunctualShadowData value)
return value.shadowMatrix3;
return value.worldToShadow2;
float4 GetShadowMatrix4(PunctualShadowData value)
float4 GetWorldToShadow3(PunctualShadowData value)
return value.shadowMatrix4;
return value.worldToShadow3;
}
int GetShadowType(PunctualShadowData value)
{

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


// It use maxed list of lights of the scene - use just as proof of concept - do not used in regular game
//-----------------------------------------------------------------------------
struct LightLoopContext
{
int sampleShadow;
int sampleReflection;
};
//-----------------------------------------------------------------------------
// Shadow
// ----------------------------------------------------------------------------
#define SINGLE_PASS_CONTEXT_SAMPLE_SHADOWATLAS 0
#define SINGLE_PASS_CONTEXT_SAMPLE_SHADOWARRAY 1
//TEXTURE2D_ARRAY(_ShadowArray);
//SAMPLER2D_SHADOW(sampler_ShadowArray);
//SAMPLER2D(sampler_ManualShadowArray); // TODO: settings sampler individually is not supported in shader yet...
//TEXTURE2D(_ShadowAtlas);
//SAMPLER2D_SHADOW(sampler_ShadowAtlas);
//SAMPLER2D(sampler_ManualShadowAtlas); // TODO: settings sampler individually is not supported in shader yet...
TEXTURE2D(g_tShadowBuffer) // TODO: No choice, the name is hardcoded in ShadowrenderPass.cs for now. Need to change this!
SAMPLER2D_SHADOW(samplerg_tShadowBuffer);
// Use texture atlas for shadow map
StructuredBuffer<PunctualShadowData> _PunctualShadowList;
float4x4 GetShadowTransform(LightLoopContext lightLoopContext, int index, float3 L)
{
int faceIndex;
if (_PunctualShadowList[index].shadowType == SHADOWTYPE_POINT)
{
GetCubeFaceID(L, faceIndex);
}
int fetchIndex = index + faceIndex;
return float4x4(_PunctualShadowList[fetchIndex].worldToShadow0, _PunctualShadowList[fetchIndex].worldToShadow1, _PunctualShadowList[fetchIndex].worldToShadow2, _PunctualShadowList[fetchIndex].worldToShadow3);
}
float4 SampleShadowCompare(LightLoopContext lightLoopContext, int index, float3 texCoord)
{
// if (lightLoopContext.sampleShadow == SINGLE_PASS_CONTEXT_SAMPLE_SHADOWATLAS)
{
// Index could be use to get scale bias for uv but this is already merged into the shadow matrix
return SAMPLE_TEXTURE2D_SHADOW(g_tShadowBuffer, samplerg_tShadowBuffer, texCoord);
}
/*
else // SINGLE_PASS_CONTEXT_SAMPLE_SHADOWARRAY
{
return SAMPLE_TEXTURE2D_ARRAY_SHADOW(_ShadowArray, sampler_ShadowArray, texCoord, index);
}
*/
}
/*
float4 SampleShadow(LightLoopContext lightLoopContext, int index, float2 texCoord)
{
if (lightLoopContext.sampleShadow == SINGLE_PASS_CONTEXT_SAMPLE_SHADOWATLAS)
{
// Index could be use to get scale bias for uv but this is already merged into the shadow matrix
return SAMPLE_TEXTURE2D(_ShadowAtlas, sampler_ManualShadowArray, texCoord);
}
else // SINGLE_PASS_CONTEXT_SAMPLE_SHADOWARRAY
{
return SAMPLE_TEXTURE2D_ARRAY(_ShadowArray, sampler_ManualShadowAtlas, texCoord, index);
}
}
*/
//-----------------------------------------------------------------------------
// IES
// ----------------------------------------------------------------------------
#define SINGLE_PASS_CONTEXT_SAMPLE_IESARRAY 0
TEXTURE2D_ARRAY(_IESArray);
SAMPLER2D(sampler_IESArray);
// sphericalTexCoord is theta and phi spherical coordinate
float4 SampleIES(LightLoopContext lightLoopContext, int index, float2 sphericalTexCoord, float lod)
{
return SAMPLE_TEXTURE2D_ARRAY_LOD(_IESArray, sampler_IESArray, sphericalTexCoord, index, 0);
}
//-----------------------------------------------------------------------------
// Reflection proble / Sky
// ----------------------------------------------------------------------------
UNITY_DECLARE_TEXCUBEARRAY(_EnvTextures);
UNITY_DECLARE_TEXCUBE(_SkyTexture);
TEXTURECUBE_ARRAY(_EnvTextures);
SAMPLERCUBE(sampler_EnvTextures);
TEXTURECUBE(_SkyTexture);
SAMPLERCUBE(sampler_SkyTexture); // NOTE: Sampler could be share here with _EnvTextures. Don't know if the shader compiler will complain...
// Note: envIndex is whatever the lighting architecture want, it can contain information like in which texture to sample (in case we have a compressed BC6H texture and an uncompressed for real time reflection ?)
// Note: index is whatever the lighting architecture want, it can contain information like in which texture to sample (in case we have a compressed BC6H texture and an uncompressed for real time reflection ?)
float4 SampleEnv(int lightLoopContext, int envIndex, float3 dirWS, float lod)
float4 SampleEnv(LightLoopContext lightLoopContext, int index, float3 texCoord, float lod)
if (lightLoopContext == SINGLE_PASS_CONTEXT_SAMPLE_REFLECTION_PROBES)
if (lightLoopContext.sampleReflection == SINGLE_PASS_CONTEXT_SAMPLE_REFLECTION_PROBES)
return UNITY_SAMPLE_TEXCUBEARRAY_LOD(_EnvTextures, float4(dirWS, envIndex), lod);
return UNITY_SAMPLE_TEXCUBEARRAY_LOD(_EnvTextures, float4(texCoord, index), lod);
return UNITY_SAMPLE_TEXCUBE_LOD(_SkyTexture, dirWS, lod);
}
}
/*
float SampleShadow(int shadowIndex)
{
PunctualShadowData shadowData = _PunctualShadowList[shadowIndex];
getShadowTextureSpaceCoordinate(shadowData.marix);
shadowData
return UNITY_SAMPLE_SHADOW(_ShadowMapAtlas, ...);
return UNITY_SAMPLE_TEXCUBE_LOD(_SkyTexture, texCoord, lod);
}
*/

21
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;

EnvLightData _EnvLightSky;
/*
// Use texture atlas for shadow map
StructuredBuffer<PunctualShadowData> _PunctualShadowList;
UNITY_DECLARE_SHADOWMAP(_ShadowMapAtlas);
*/
LightLoopContext context;
ZERO_INITIALIZE(LightLoopContext, context);
diffuseLighting = float4(0.0, 0.0, 0.0, 0.0);
specularLighting = float4(0.0, 0.0, 0.0, 0.0);

float4 localSpecularLighting;
EvaluateBSDF_Punctual(V, positionWS, prelightData, _PunctualLightList[i], bsdfData, localDiffuseLighting, localSpecularLighting);
EvaluateBSDF_Punctual(context, V, positionWS, prelightData, _PunctualLightList[i], bsdfData, localDiffuseLighting, localSpecularLighting);
diffuseLighting += localDiffuseLighting;
specularLighting += localSpecularLighting;
}

{
float4 localDiffuseLighting;
float4 localSpecularLighting;
EvaluateBSDF_Area(V, positionWS, areaLightData[i], bsdfData, localDiffuseLighting, localSpecularLighting);
EvaluateBSDF_Area(0, V, positionWS, areaLightData[i], bsdfData, localDiffuseLighting, localSpecularLighting);
diffuseLighting += localDiffuseLighting;
specularLighting += localSpecularLighting;
}

{
float4 localDiffuseLighting;
float4 localSpecularLighting;
EvaluateBSDF_Env(SINGLE_PASS_CONTEXT_SAMPLE_REFLECTION_PROBES, V, positionWS, prelightData, _EnvLightList[j], bsdfData, localDiffuseLighting, localSpecularLighting);
context.sampleReflection = SINGLE_PASS_CONTEXT_SAMPLE_REFLECTION_PROBES;
EvaluateBSDF_Env(context, V, positionWS, prelightData, _EnvLightList[j], bsdfData, 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);
}

{
float4 localDiffuseLighting;
float4 localSpecularLighting;
EvaluateBSDF_Env(SINGLE_PASS_CONTEXT_SAMPLE_SKY, V, positionWS, prelightData, _EnvLightSky, bsdfData, localDiffuseLighting, localSpecularLighting);
context.sampleReflection = SINGLE_PASS_CONTEXT_SAMPLE_SKY;
EvaluateBSDF_Env(context, V, positionWS, prelightData, _EnvLightSky, bsdfData, 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);
}

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


// EvaluateBSDF_Punctual
//-----------------------------------------------------------------------------
void EvaluateBSDF_Punctual( float3 V, float3 positionWS, PreLightData prelightData, PunctualLightData lightData, BSDFData bsdfData,
void EvaluateBSDF_Punctual( LightLoopContext lightLoopContext,
float3 V, float3 positionWS, PreLightData prelightData, PunctualLightData lightData, BSDFData bsdfData,
out float4 diffuseLighting,
out float4 specularLighting)
{

// 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;
const bool hasCookie = (lightData.flags & LIGHTFLAGS_HAS_COOKIE)!= 0;
*/
const bool hasIES = (lightData.flags & LIGHTFLAGS_HAS_IES) == 0;
const bool hasIES = (lightData.flags & LIGHTFLAGS_HAS_IES) != 0;
illuminance *= SampleIES(lightData.iesIndex, lightToWorld, L);
float2 sphericalCoord = GetIESTextureCoordinate(lightToWorld, L);
illuminance *= SampleIES(lightLoopContext, lightData.IESIndex, sphericalCoord, 0).r;
const bool hasShadow = (lightData.flags & LIGHTFLAGS_HAS_SHADOW) == 0;
[branch] if (lightData.hasShadow && illuminance > 0.0f)
const bool hasShadow = (lightData.flags & LIGHTFLAGS_HAS_SHADOW) != 0;
[branch] if (hasShadow && illuminance > 0.0f)
float4x4 lightToWorld = float3x3(lightData.right, lightData.up, lightData.forward);
float shadowAttenuation = SampleShadow(lightData.shadowIndex, lightToWorld, L, positionWS);
float4x4 shadowTransform = GetShadowTransform(lightLoopContext, lightData.shadowIndex, L);
float4 positionHS = mul(float4(positionWS, 1), shadowTransform);
float shadowAttenuation = 1; // GetShadowAttenuation(shadowTransform, positionHS.xyz / positionHS.w);
*/
if (illuminance > 0.0f)
{

// EvaluateBSDF_Area - Reference
//-----------------------------------------------------------------------------
void IntegrateGGXAreaRef(float3 V, float3 positionWS, PreLightData prelightData, AreaLightData lightData, BSDFData bsdfData,
out float4 diffuseLighting,
out float4 specularLighting,
uint sampleCount = 512)
void IntegrateGGXAreaRef( float3 V, float3 positionWS, PreLightData prelightData, AreaLightData lightData, BSDFData bsdfData,
out float4 diffuseLighting,
out float4 specularLighting,
uint sampleCount = 512)
{
// Add some jittering on Hammersley2d
float2 randNum = InitRandom(V.xy * 0.5 + 0.5);

// EvaluateBSDF_Area
//-----------------------------------------------------------------------------
void EvaluateBSDF_Area( float3 V, float3 positionWS, PreLightData prelightData, AreaLightData lightData, BSDFData bsdfData,
void EvaluateBSDF_Area( LightLoopContext lightLoopContext,
float3 V, float3 positionWS, PreLightData prelightData, AreaLightData lightData, BSDFData bsdfData,
out float4 diffuseLighting,
out float4 specularLighting)
{

// ----------------------------------------------------------------------------
// Ref: Moving Frostbite to PBR (Appendix A)
float3 IntegrateLambertIBLRef( int lightLoopContext,
float3 IntegrateLambertIBLRef( LightLoopContext lightLoopContext,
EnvLightData lightData, BSDFData bsdfData,
uint sampleCount = 2048)
{

return acc / sampleCount;
}
float3 IntegrateDisneyDiffuseIBLRef(int lightLoopContext,
float3 IntegrateDisneyDiffuseIBLRef(LightLoopContext lightLoopContext,
float3 V, EnvLightData lightData, BSDFData bsdfData,
uint sampleCount = 2048)
{

}
// Ref: Moving Frostbite to PBR (Appendix A)
float3 IntegrateSpecularGGXIBLRef( int lightLoopContext,
float3 IntegrateSpecularGGXIBLRef( LightLoopContext lightLoopContext,
float3 V, EnvLightData lightData, BSDFData bsdfData,
uint sampleCount = 2048)
{

// ----------------------------------------------------------------------------
// _preIntegratedFGD and _CubemapLD are unique for each BRDF
void EvaluateBSDF_Env( int lightLoopContext,
void EvaluateBSDF_Env( LightLoopContext lightLoopContext,
float3 V, float3 positionWS, PreLightData prelightData, EnvLightData lightData, BSDFData bsdfData,
out float4 diffuseLighting,
out float4 specularLighting)

19
Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/Material.hlsl


// In case lighting.hlsl is not include before including material.hlsl, define some neutral function, so it doesn't complain
#ifndef LIGHTING
float4 SampleEnv(int lightLoopContext, int envIndex, float3 dirWS, float lod)
struct LightLoopContext
{
int unused;
};
float4 SampleEnv(LightLoopContext lightLoopContext, int index, float3 texCoord, float lod)
{
return float4(0.0, 0.0, 0.0, 0.0);
}
float4 SampleIES(LightLoopContext lightLoopContext, int index, float2 sphericalTexCoord, float lod)
float4x4 GetShadowTransform(LightLoopContext lightLoopContext, int index, float3 L)
{
return float4x4(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
}
#endif
// Here we include all the different lighting model supported by the renderloop based on define done in .shader

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


#define UNITY_SAMPLE_TEXCUBEARRAY_LOD(tex,coord,lod) tex.SampleLevel (sampler##tex,coord, lod)
#define UNITY_SAMPLE_TEXCUBEARRAY_SAMPLER(tex,samplertex,coord) tex.Sample (sampler##samplertex,coord)
// Shadow
#define UNITY_DECLARE_SHADOWMAP(tex) Texture2D tex; SamplerComparisonState sampler##tex
#define UNITY_SAMPLE_SHADOW(tex,coord) tex.SampleCmpLevelZero (sampler##tex,(coord).xy,(coord).z)
#define UNITY_SAMPLE_SHADOW_PROJ(tex,coord) tex.SampleCmpLevelZero (sampler##tex,(coord).xy/(coord).w,(coord).z/(coord).w)
// Alternative
#define TEXTURE2D(textureName) Texture2D textureName;
#define TEXTURE2D_ARRAY(textureName) Texture2DArray textureName;
#define TEXTURECUBE(textureName) TextureCube textureName;
#define TEXTURECUBE_ARRAY(textureName) TextureCubeArray textureName;
#define TEXTURE3D(textureName) Texture3D textureName;
#define TEXTURE2D(textureName) Texture2D textureName;
#define SAMPLERCUBE(samplerName) SamplerState samplerName;
#define SAMPLER3D(samplerName) SamplerState samplerName;
#define TEXTURE2D_ARRAY_ARGS(textureName, samplerName) Texture2DArray textureName, SamplerState samplerName
#define TEXTURECUBE_ARGS(textureName, samplerName) TextureCube textureName, SamplerState samplerName
#define TEXTURECUBE_ARRAY_ARGS(textureName, samplerName) TextureCubeArray textureName, SamplerState samplerName
#define TEXTURE3D_ARGS(textureName, samplerName) Texture3D textureName, SamplerState samplerName
#define TEXTURE2D_SHADOW_ARGS(textureName, samplerName) Texture2D textureName, SamplerComparisonState samplerName
#define TEXTURE2D_ARRAY_SHADOW_ARGS(textureName, samplerName) Texture2DArray textureName, SamplerComparisonState samplerName
#define TEXTURECUBE_SHADOW_ARGS(textureName, samplerName) TextureCube textureName, SamplerComparisonState samplerName
#define SAMPLE_TEXTURE2D(textureName, samplerName, coord) textureName.Sample(samplerName, coord)
#define TEXTURE2D_ARRAY_PASS(textureName, samplerName) textureName, samplerName
#define TEXTURECUBE_PASS(textureName, samplerName) textureName, samplerName
#define TEXTURECUBE_ARRAY_PASS(textureName, samplerName) textureName, samplerName
#define TEXTURE3D_PASS(textureName, samplerName) textureName, samplerName
#define TEXTURE2D_SHADOW_PASS(textureName, samplerName) textureName, samplerName
#define TEXTURE2D_ARRAY_SHADOW_PASS(textureName, samplerName) textureName, samplerName
#define TEXTURECUBE_SHADOW_PASS(textureName, samplerName) textureName, samplerName
#define UNITY_DECLARE_SHADOWMAP(tex) Texture2D tex; SamplerComparisonState sampler##tex
#define UNITY_SAMPLE_SHADOW(tex,coord) tex.SampleCmpLevelZero (sampler##tex,(coord).xy,(coord).z)
#define UNITY_SAMPLE_SHADOW_PROJ(tex,coord) tex.SampleCmpLevelZero (sampler##tex,(coord).xy/(coord).w,(coord).z/(coord).w)
#define SAMPLE_TEXTURE2D(textureName, samplerName, coord2) textureName.Sample(samplerName, coord2)
#define SAMPLE_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Sample(samplerName, float3((coord2).xy, index))
#define SAMPLE_TEXTURECUBE(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3)
#define SAMPLE_TEXTURECUBE_ARRAY(textureName, samplerName, coord3) textureName.Sample(samplerName, float4((coord3).xyz, index))
#define SAMPLE_TEXTURE2D_SHADOW(textureName, samplerName, coord3) textureName.SampleCmpLevelZero(samplerName, (coord3).xy, (coord3).z)
#define SAMPLE_TEXTURE2D_ARRAY_SHADOW(textureName, samplerName, coord3, index) textureName.SampleCmpLevelZero(samplerName, float3((coord3).xy, index), (coord3).z)
#define SAMPLE_TEXTURECUBE_SHADOW(textureName, samplerName, coord4) textureName.SampleCmpLevelZero(samplerName, (coord3).xyz, (coord3).w)

29
Assets/ScriptableRenderLoop/ShaderLibrary/Common.hlsl


return saturate(dot(N, V)); // TODO: this saturate should not be necessary here
}
// ----------------------------------------------------------------------------
// Util cubemap
// ----------------------------------------------------------------------------
#define CUBEMAPFACE_POSITIVE_X 0
#define CUBEMAPFACE_NEGATIVE_X 1
#define CUBEMAPFACE_POSITIVE_Y 2
#define CUBEMAPFACE_NEGATIVE_Y 3
#define CUBEMAPFACE_POSITIVE_Z 4
#define CUBEMAPFACE_NEGATIVE_Z 5
{
// TODO: Use faceID intrinsic on console
float3 adir = abs(dir);
// +Z -Z
faceIndex = dir.z > 0.0f ? CUBEMAPFACE_NEGATIVE_Z : CUBEMAPFACE_POSITIVE_Z;
// +X -X
if (adir.x > adir.y && adir.x > adir.z)
{
faceIndex = dir.x > 0.0 ? CUBEMAPFACE_NEGATIVE_X : CUBEMAPFACE_POSITIVE_X;
}
// +Y -Y
else if (adir.y > adir.x && adir.y > adir.z)
{
faceIndex = dir.y > 0.0 ? CUBEMAPFACE_NEGATIVE_Y : CUBEMAPFACE_POSITIVE_Y;
}
}
#endif // UNITY_COMMON_INCLUDED

19
Assets/ScriptableRenderLoop/ShaderLibrary/CommonLighting.hlsl


}
//-----------------------------------------------------------------------------
// IES Helper
//-----------------------------------------------------------------------------
float2 GetIESTextureCoordinate(float3x3 lightToWord, float3 L)
{
// IES need to be sample in light space
float3 dir = mul(lightToWord, -L); // Using matrix on left side do a transpose
// convert to spherical coordinate
float2 sphericalCoord; // .x is theta, .y is phi
// Texture is encoded with cos(phi), scale from -1..1 to 0..1
sphericalCoord.y = (dir.z * 0.5) + 0.5;
float theta = atan2(dir.y, dir.x);
sphericalCoord.x = theta * INV_TWO_PI;
return sphericalCoord;
}
//-----------------------------------------------------------------------------
// Helper function for anisotropy
//-----------------------------------------------------------------------------

4
Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Lighting/Shadow.hlsl


//-----------------------------------------------------------------------------
// Shadow
// ----------------------------------------------------------------------------

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


fileFormatVersion: 2
guid: 272a43c3c23646a4e8bc73faebaf0ee5
timeCreated: 1477313383
licenseType: Pro
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存