浏览代码

HDRenderLoop: Push draft not compiling

/main
Sebastien Lagarde 8 年前
当前提交
1602a326
共有 6 个文件被更改,包括 72 次插入19 次删除
  1. 25
      Assets/ScriptableRenderLoop/HDRenderLoop/HDRenderLoop.cs
  2. 23
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Lighting/LightDefinition.cs
  3. 12
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Lighting/LightingForward/LightingForward.hlsl
  4. 25
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/Lit/Lit.hlsl
  5. 2
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/Lit/LitDefault.shader
  6. 4
      Assets/ScriptableRenderLoop/ShaderLibrary/API/D3D11.hlsl

25
Assets/ScriptableRenderLoop/HDRenderLoop/HDRenderLoop.cs


public const int MaxLights = 32;
public const int MaxProbes = 32;
//[SerializeField]
//ShadowSettings m_ShadowSettings = ShadowSettings.Default;
//ShadowRenderPass m_ShadowPass;
[SerializeField]
ShadowSettings m_ShadowSettings = ShadowSettings.Default;
ShadowRenderPass m_ShadowPass;
[SerializeField]
TextureSettings m_TextureSettings = TextureSettings.Default;

// Debug
m_DebugViewMaterialGBuffer = CreateEngineMaterial("Hidden/Unity/DebugViewMaterialGBuffer");
// m_ShadowPass = new ShadowRenderPass (m_ShadowSettings);
m_ShadowPass = new ShadowRenderPass (m_ShadowSettings);
m_cubeReflTexArray = new TextureCacheCubemap();
m_cubeReflTexArray.AllocTextureArray(32, (int)m_TextureSettings.reflectionCubemapSize, TextureFormat.BC6H, true);

//---------------------------------------------------------------------------------------------------------------------------------------------------
void UpdatePunctualLights(VisibleLight[] visibleLights)
void UpdatePunctualLights(VisibleLight[] visibleLights, ref ShadowOutput shadow)
{
var lights = new List<PunctualLightData>();

if (!CullResults.GetCullingParameters(camera, out cullingParams))
continue;
//m_ShadowPass.UpdateCullingParameters (ref cullingParams);
m_ShadowPass.UpdateCullingParameters (ref cullingParams);
//ShadowOutput shadows;
//m_ShadowPass.Render (renderLoop, cullResults, out shadows);
//UpdateLightConstants(cullResults.visibleLights /*, ref shadows */);
UpdatePunctualLights(cullResults.visibleLights);
UpdateReflectionProbes(cullResults.visibleReflectionProbes);
InitAndClearBuffer(camera, renderLoop);
RenderGBuffer(cullResults, camera, renderLoop);

}
else
{
ShadowOutput shadows;
m_ShadowPass.Render(renderLoop, cullResults, out shadows);
UpdatePunctualLights(cullResults.visibleLights, ref shadows);
UpdateReflectionProbes(cullResults.visibleReflectionProbes);
RenderDeferredLighting(camera, renderLoop);
RenderForward(cullResults, camera, renderLoop);

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


public float angleScale;
public float angleOffset;
public Vector2 unused2;
public int flags;
public int IESIndex;
};
[GenerateHLSL]

public float unused1;
};
[GenerateHLSL]
public struct PlanarLightData
struct PunctualShadowData
public Vector3 positionWS;
// 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

12
Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Lighting/LightingForward/LightingForward.hlsl


StructuredBuffer<EnvLightData> _EnvLightList;
int _EnvLightCount;
// Note: Here we have a max number of shadow (32?) (should be a static array but unity doesn't support loading array of struct)
StructuredBuffer<PunctualShadowData> _PunctualShadowList;
UNITY_DECLARE_SHADOWMAP(_ShadowMapAtlas); // Shadowmap Atlas
float SampleShadow(int shadowIndex)
{
PunctualShadowData shadowData = _PunctualShadowList[shadowIndex];
getShadowTextureSpaceCoordinate(shadowData.marix);
shadowData
return UNITY_SAMPLE_SHADOW(_ShadowMapAtlas, ...);
}
void ForwardLighting( float3 V, float3 positionWS, PreLightData prelightData, BSDFData bsdfData,
out float4 diffuseLighting,
out float4 specularLighting)

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


diffuseLighting = float4(0.0, 0.0, 0.0, 1.0);
specularLighting = float4(0.0, 0.0, 0.0, 1.0);
// 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)
{
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)
{
float3x3 lightToWorld = float3x3(lightData.right, lightData.up, lightData.forward);
illuminance *= SampleIES(lightData.iesIndex, lightToWorld, L);
}
const bool hasShadow = (lightData.flags & LIGHTFLAGS_HAS_SHADOW) == 0;
[branch] if (lightData.hasShadow && illuminance > 0.0f)
{
float4x4 lightToWorld = float3x3(lightData.right, lightData.up, lightData.forward);
float shadowAttenuation = SampleShadow(lightData.shadowIndex, lightToWorld, L, positionWS);
shadowAttenuation = lerp(1.0, shadowAttenuation, lightData.shadowDimmer);
illuminance *= shadowAttenuation;
}
if (illuminance > 0.0f)
{
BSDF(V, L, positionWS, prelightData, bsdfData, diffuseLighting.rgb, specularLighting.rgb);

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


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

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


#define TEXTURE2D_ARGS(textureName, samplerName) Texture2D textureName, SamplerState samplerName
#define TEXTURE2D_PASS(textureName, samplerName) textureName, samplerName
#define SAMPLE_TEXTURE2D(textureName, samplerName, coord) textureName.Sample(samplerName, coord)
#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)
正在加载...
取消
保存