浏览代码

Added mixed vertex/frag SH evaluation. Added GlossyEnvironmentColor to be used when glossy reflections are off.

/RenderPassXR_Sandbox
Felipe Lira 7 年前
当前提交
301fd283
共有 4 个文件被更改,包括 29 次插入27 次删除
  1. 37
      ScriptableRenderPipeline/LightweightPipeline/LightweightPipeline.cs
  2. 1
      ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightInput.cginc
  3. 14
      ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightLighting.cginc
  4. 4
      ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightPassLit.cginc

37
ScriptableRenderPipeline/LightweightPipeline/LightweightPipeline.cs


InitializeMainShadowLightIndex(lights, out lightData.shadowLightIndex);
}
private void SetupShaderLightConstants(VisibleLight[] lights, ref LightData lightData, ref CullResults cullResults, ref ScriptableRenderContext context)
{
if (lightData.isSingleLight)
SetupShaderSingleLightConstants(lights, (lightData.pixelLightsCount > 0) ? 0 : -1, ref context);
else
SetupShaderLightListConstants(lights, ref lightData, ref context);
}
private void InitializeLightConstants(VisibleLight[] lights, int lightIndex, out Vector4 lightPos, out Vector4 lightColor, out Vector4 lightSpotDir,
out Vector4 lightAttenuationParams)
{

}
}
private void SetupShaderSingleLightConstants(VisibleLight[] lights, int lightIndex, ref ScriptableRenderContext context)
private void SetupShaderLightConstants(VisibleLight[] lights, ref LightData lightData, ref CullResults cullResults, ref ScriptableRenderContext context)
{
CommandBuffer cmd = CommandBufferPool.Get("SetupSingleLightConstants");
Vector4 glossyEnvColor = RenderSettings.ambientSkyColor.gamma * RenderSettings.reflectionIntensity;
cmd.SetGlobalVector("_GlossyEnvironmentColor", glossyEnvColor);
if (m_Asset.AttenuationTexture != null) cmd.SetGlobalTexture("_AttenuationTexture", m_Asset.AttenuationTexture);
if (lightData.isSingleLight)
SetupShaderSingleLightConstants(cmd, lights, (lightData.pixelLightsCount > 0) ? 0 : -1, ref context);
else
SetupShaderLightListConstants(cmd, lights, ref lightData, ref context);
context.ExecuteCommandBuffer(cmd);
CommandBufferPool.Release(cmd);
}
private void SetupShaderSingleLightConstants(CommandBuffer cmd, VisibleLight[] lights, int lightIndex, ref ScriptableRenderContext context)
CommandBuffer cmd = new CommandBuffer() { name = "SetupSingleLightConstants" };
if (m_Asset.AttenuationTexture != null) cmd.SetGlobalTexture("_AttenuationTexture", m_Asset.AttenuationTexture);
context.ExecuteCommandBuffer(cmd);
cmd.Dispose();
private void SetupShaderLightListConstants(VisibleLight[] lights, ref LightData lightData, ref ScriptableRenderContext context)
private void SetupShaderLightListConstants(CommandBuffer cmd, VisibleLight[] lights, ref LightData lightData, ref ScriptableRenderContext context)
{
int maxLights = Math.Min(kMaxVisibleLights, lights.Length);

lightIndexMap[i] = -1;
m_CullResults.SetLightIndexMap(lightIndexMap);
CommandBuffer cmd = CommandBufferPool.Get("SetupLightShaderConstants");
if (m_Asset.AttenuationTexture != null) cmd.SetGlobalTexture("_AttenuationTexture", m_Asset.AttenuationTexture);
context.ExecuteCommandBuffer(cmd);
CommandBufferPool.Release(cmd);
}
private void SetShaderKeywords(ref LightData lightData, ref ScriptableRenderContext context)

1
ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightInput.cginc


half _Shininess;
samplerCUBE _Cube;
half4 _ReflectColor;
half4 _GlossyEnvironmentColor;
struct LightweightVertexInput
{

14
ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightLighting.cginc


#ifndef LIGHTWEIGHT_LIGHTING_INCLUDED
#define LIGHTWEIGHT_LIGHTING_INCLUDED
UnityIndirect LightweightGI(float2 lightmapUV, half3 ambientColor, half3 reflectVec, half occlusion, half roughness)
UnityIndirect LightweightGI(float2 lightmapUV, half3 ambientColor, half3 normalWorld, half3 reflectVec, half occlusion, half roughness)
o.diffuse = (DecodeLightmap(UNITY_SAMPLE_TEX2D(unity_Lightmap, lightmapUV)));
ambientColor = (DecodeLightmap(UNITY_SAMPLE_TEX2D(unity_Lightmap, lightmapUV)));
#else
ambientColor += SHEvalLinearL0L1(half4(normalWorld, 1.0));
ambientColor = max(half3(0.0, 0.0, 0.0), ambientColor);
#if defined(_VERTEX_LIGHTS) || !defined(LIGHTMAP_ON)
o.diffuse += ambientColor;
#endif
o.diffuse *= occlusion;
o.diffuse = ambientColor * occlusion;
#ifndef _GLOSSYREFLECTIONS_OFF
// perceptualRoughness

o.specular = Unity_GlossyEnvironment(UNITY_PASS_TEXCUBE(unity_SpecCube0), unity_SpecCube0_HDR, g) * occlusion;
#else
o.specular = half3(0, 0, 0);
o.specular = _GlossyEnvironmentColor * occlusion;
#endif
return o;

4
ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightPassLit.cginc


//#endif
#if !defined(LIGHTMAP_ON)
o.fogCoord.yzw += max(half3(0, 0, 0), ShadeSH9(half4(normal, 1)));
o.fogCoord.yzw = SHEvalLinearL2(half4(normal, 1.0));
#endif
UNITY_TRANSFER_FOG(o, o.hpos);

// TODO: Reflection Probe blend support.
half3 reflectVec = reflect(-i.viewDir.xyz, normal);
half occlusion = Occlusion(uv);
UnityIndirect indirectLight = LightweightGI(lightmapUV, i.fogCoord.yzw, reflectVec, occlusion, perceptualRoughness);
UnityIndirect indirectLight = LightweightGI(lightmapUV, i.fogCoord.yzw, normal, reflectVec, occlusion, perceptualRoughness);
// PBS
// grazingTerm = F90

正在加载...
取消
保存