浏览代码

HDRenderloop: Remove flags from light + experiment bias on receiver

/main
Sebastien Lagarde 8 年前
当前提交
36745c50
共有 11 个文件被更改,包括 75 次插入63 次删除
  1. 12
      Assets/ScriptableRenderLoop/HDRenderLoop/HDRenderLoop.cs
  2. 17
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Lighting/LightDefinition.cs
  3. 16
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Lighting/LightDefinition.cs.hlsl
  4. 9
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Lighting/SinglePass/SinglePass.hlsl
  5. 10
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/Lit/Lit.hlsl
  6. 11
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/Lit/LitDefault.shader
  7. 3
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Shadow/ShadowDefinition.cs
  8. 9
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Shadow/ShadowDefinition.cs.hlsl
  9. 6
      Assets/ScriptableRenderLoop/ShaderLibrary/Common.hlsl
  10. 36
      Assets/TestScenes/HDTest/HDRenderLoopTest.unity
  11. 9
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Shadow/EVSM.meta

12
Assets/ScriptableRenderLoop/HDRenderLoop/HDRenderLoop.cs


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;
l.IESIndex = -1;
l.cookieIndex = -1;
l.shadowIndex = -1;
// Setup shadow data arrays
bool hasShadows = shadowOutput.GetShadowSliceCountLightIndex(lightIndex) != 0;

{
// 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)
{

s.worldToShadow = shadowOutput.shadowSlices[shadowSliceIndex].shadowTransform.transpose; // Transpose to go from ShadowToWorld to WorldToShadow
s.worldToShadow = shadowOutput.shadowSlices[shadowSliceIndex].shadowTransform.transpose; // Transpose for hlsl reading ?
if (light.lightType == LightType.Spot)
{

{
s.shadowType = ShadowType.Directional;
}
s.bias = light.light.shadowBias;
shadows.Add(s);
}

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


// structure definition
//-----------------------------------------------------------------------------
[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 angleOffset;
public Vector3 right;
public LightFlags flags;
// index are -1 if not used
public Vector2 unused;
public Vector3 unused;
};
[GenerateHLSL]

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


#ifndef LIGHTDEFINITION_CS_HLSL
#define 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 up;
float angleOffset;
float3 right;
int flags;
float diffuseScale;
float specularScale;
float shadowDimmer;

float2 unused;
float3 unused;
};
// Generated from UnityEngine.Experimental.ScriptableRenderLoop.AreaLightData

{
return value.right;
}
int GetFlags(PunctualLightData value)
{
return value.flags;
}
float GetDiffuseScale(PunctualLightData value)
{
return value.diffuseScale;

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

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


float3 GetShadowTextureCoordinate(LightLoopContext lightLoopContext, PunctualShadowData shadowData, float3 positionWS)
{
// Note: scale and bias of shadow atlas are included in ShadowTransform but could be apply here.
float4 positionTXS = mul(float4(positionWS, 1.0), shadowData.worldToShadow);
return positionTXS.xyz / positionTXS.w;
float4 positionTXS = mul(float4(positionWS, 1.0), shadowData.worldToShadow);
positionTXS.xyz /= positionTXS.w;
// positionTXS.z -= shadowData.bias; // Apply a linear bias
return positionTXS;
}
float4 SampleShadowCompare(LightLoopContext lightLoopContext, int index, float3 texCoord)

float objDepth = saturate(257.0 / 256.0 - texCoord.z);
float objDepth = saturate(1.0 - texCoord.z);
// 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, float3(texCoord.xy, objDepth)).xxxx;

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


// 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)
[branch] if (lightData.cookieIndex && illuminance > 0.0f)
{
float3x3 lightToWorld = float3x3(lightData.right, lightData.up, lightData.forward);
illuminance *= SampleCookie(lightData.cookieIndex, lightToWorld, L);

const bool hasIES = (lightData.flags & LIGHTFLAGS_HAS_IES) != 0;
[branch] if (hasIES && illuminance > 0.0f)
[branch] if (lightData.IESIndex >= 0 && illuminance > 0.0f)
{
float3x3 lightToWorld = float3x3(lightData.right, lightData.up, lightData.forward);
float2 sphericalCoord = GetIESTextureCoordinate(lightToWorld, L);

const bool hasShadow = (lightData.flags & LIGHTFLAGS_HAS_SHADOW) != 0;
[branch] if (hasShadow && illuminance > 0.0f)
[branch] if (lightData.shadowIndex >= 0 && illuminance > 0.0f)
{
PunctualShadowData shadowData = GetPunctualShadowData(lightLoopContext, lightData.shadowIndex, L);

float shadowAttenuation = GetPunctualShadowAttenuation(lightLoopContext, lightData.shadowIndex, shadowData, shadowCoord, shadowPosDX, shadowPosDY, preLightData.unPositionSS);
shadowAttenuation = lerp(1.0, shadowAttenuation, lightData.shadowDimmer);
illuminance *= shadowAttenuation;
}

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


// ------------------------------------------------------------------
Pass
{
Name "DepthOnly" // Name is not used
Tags { "LightMode" = "ShadowCaster" } // This will be only for transparent object based on the RenderQueue index
Name "ShadowCaster"
Tags{ "LightMode" = "ShadowCaster" }
Blend [_SrcBlend] [_DstBlend]
ZWrite [_ZWrite]
Cull [_CullMode]
Cull[_CullMode]
ZWrite On ZTest LEqual
HLSLPROGRAM

ZERO_INITIALIZE(FragInput, output);
output.positionHS = input.positionHS;
#if NEED_TANGENT_TO_WORLD
output.positionWS.xyz = input.interpolators[0].xyz;
output.tangentToWorld[0] = input.interpolators[1].xyz;

3
Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Shadow/ShadowDefinition.cs


public Matrix4x4 worldToShadow;
public ShadowType shadowType;
public Vector3 unused;
public float bias;
public Vector2 unused;
};
} // namespace UnityEngine.Experimental.ScriptableRenderLoop

9
Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Shadow/ShadowDefinition.cs.hlsl


{
float4x4 worldToShadow;
int shadowType;
float3 unused;
float bias;
float2 unused;
};
//

{
return value.shadowType;
}
float3 GetUnused(PunctualShadowData value)
float GetBias(PunctualShadowData value)
{
return value.bias;
}
float2 GetUnused(PunctualShadowData value)
{
return value.unused;
}

6
Assets/ScriptableRenderLoop/ShaderLibrary/Common.hlsl


// This allow to easily share code.
// If a compute shader call this function inPositionSS is an integer usually calculate like: uint2 inPositionSS = groupId.xy * BLOCK_SIZE + groupThreadId.xy
// else it is current unormalized screen coordinate like return by VPOS
Coordinate GetCoordinate(float2 inPositionSS, float2 invScreenSize)
Coordinate GetCoordinate(float2 positionSS, float2 invScreenSize)
coord.positionSS = inPositionSS;
coord.positionSS = positionSS;
// TODO: How to detect automatically that we are a compute shader ?
#if SHADER_STAGE_COMPUTE
// In case of compute shader an extra half offset is added to the screenPos to shift the integer position to pixel center.

coord.unPositionSS = int2(inPositionSS);
coord.unPositionSS = int2(positionSS);
return coord;
}

36
Assets/TestScenes/HDTest/HDRenderLoopTest.unity


m_Component:
- component: {fileID: 733865594}
- component: {fileID: 733865595}
- component: {fileID: 733865596}
m_Layer: 0
m_Name: Spotlight
m_TagString: Untagged

m_Type: 0
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_Intensity: 8
m_Range: 13.18
m_Range: 12.92
m_SpotAngle: 79.1
m_CookieSize: 10
m_Shadows:

m_BounceIntensity: 1
m_ShadowRadius: 0
m_ShadowAngle: 0
--- !u!114 &733865596
MonoBehaviour:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 733865593}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 7a68c43fe1f2a47cfa234b5eeaa98012, type: 3}
m_Name:
m_EditorClassIdentifier:
shadowResolution: 512
innerSpotPercent: 0
shadowDimmer: 1
affectDiffuse: 1
affectSpecular: 1
--- !u!1001 &744696321
Prefab:
m_ObjectHideFlags: 0

m_Component:
- component: {fileID: 1854618466}
- component: {fileID: 1854618465}
- component: {fileID: 1854618467}
m_Layer: 0
m_Name: Point light (1)
m_TagString: Untagged

m_Father: {fileID: 0}
m_RootOrder: 17
m_LocalEulerAnglesHint: {x: -0.39200002, y: 1.033, z: -0.92}
--- !u!114 &1854618467
MonoBehaviour:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1854618464}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 7a68c43fe1f2a47cfa234b5eeaa98012, type: 3}
m_Name:
m_EditorClassIdentifier:
shadowResolution: 512
innerSpotPercent: 0
shadowDimmer: 1
affectDiffuse: 1
affectSpecular: 1
--- !u!4 &1860830036 stripped
Transform:
m_PrefabParentObject: {fileID: 4000010760374938, guid: 1faa212e4ad88f04a81c5ed019001de5,

9
Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Shadow/EVSM.meta


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