浏览代码

Clean up and refactor the procedural sky

/main
Evgenii Golubev 8 年前
当前提交
9ae68594
共有 5 个文件被更改,包括 158 次插入193 次删除
  1. 131
      Assets/ScriptableRenderLoop/HDRenderLoop/Sky/ProceduralSky/ProceduralSkyParameters.cs
  2. 188
      Assets/ScriptableRenderLoop/HDRenderLoop/Sky/ProceduralSky/ProceduralSkyRenderer.cs
  3. 13
      Assets/ScriptableRenderLoop/HDRenderLoop/Sky/ProceduralSky/Resources/AtmosphericScattering.hlsl
  4. 12
      Assets/ScriptableRenderLoop/HDRenderLoop/Sky/ProceduralSky/Resources/SkyProcedural.shader
  5. 7
      Assets/ScriptableRenderLoop/HDRenderLoop/Sky/SkyManager.cs

131
Assets/ScriptableRenderLoop/HDRenderLoop/Sky/ProceduralSky/ProceduralSkyParameters.cs


{
[ExecuteInEditMode]
[DisallowMultipleComponent]
public class ProceduralSkyParameters
: SkyParameters
public class ProceduralSkyParameters : SkyParameters
public enum OcclusionSamples { x64 = 0, x164 = 1, x244 = 2 }
public enum DepthTexture { Enable, Disable/*, Ignore*/ } // 'Ignore' appears to be currently unused.
public enum ScatterDebugMode { None, Scattering, Occlusion, OccludedScattering, Rayleigh, Mie, Height }
public enum OcclusionSamples { x64 = 0, x164 = 1, x244 = 2 }
public enum ScatterDebugMode { None, Scattering, Occlusion, OccludedScattering, Rayleigh, Mie, Height }
public Gradient worldRayleighColorRamp = null;
public float worldRayleighColorIntensity = 1f;
public float worldRayleighDensity = 10f;
public float worldRayleighExtinctionFactor = 1.1f;
public float worldRayleighIndirectScatter = 0.33f;
public Gradient worldMieColorRamp = null;
public float worldMieColorIntensity = 1f;
public float worldMieDensity = 15f;
public float worldMieExtinctionFactor = 0f;
public float worldMiePhaseAnisotropy = 0.9f;
public float worldNearScatterPush = 0f;
public float worldNormalDistance = 1000f;
public float worldMieColorIntensity = 1f;
public Gradient worldMieColorRamp = null;
public float worldMieDensity = 15f;
public float worldMieExtinctionFactor = 0f;
public float worldMiePhaseAnisotropy = 0.9f;
public float worldNearScatterPush = 0f;
public float worldNormalDistance = 1000f;
public float worldRayleighColorIntensity = 1f;
public Gradient worldRayleighColorRamp = null;
public float worldRayleighDensity = 10f;
public float worldRayleighExtinctionFactor = 1.1f;
public float worldRayleighIndirectScatter = 0.33f;
public Color heightRayleighColor = Color.white;
public float heightRayleighIntensity = 1f;
public float heightRayleighDensity = 10f;
public float heightMieDensity = 0f;
public float heightExtinctionFactor = 1.1f;
public float heightSeaLevel = 0f;
public float heightDistance = 50f;
public Vector3 heightPlaneShift = Vector3.zero;
public float heightNearScatterPush = 0f;
public float heightNormalDistance = 1000f;
[Header("Sky Dome")]
public Vector3 skyDomeRotation = Vector3.zero;
public bool skyDomeVerticalFlip = false;
public Cubemap skyDomeCubemap = null;
public float skyDomeExposure = 1f;
public Color skyDomeTint = Color.white;
public Transform skyDomeTrackedYawRotation = null;
public float heightDistance = 50f;
public float heightExtinctionFactor = 1.1f;
public float heightMieDensity = 0f;
public float heightNearScatterPush = 0f;
public float heightNormalDistance = 1000f;
public Vector3 heightPlaneShift = Vector3.zero;
public Color heightRayleighColor = Color.white;
public float heightRayleighDensity = 10f;
public float heightRayleighIntensity = 1f;
public float heightSeaLevel = 0f;
/*
[Header("Scatter Occlusion")]

*/
[Header("Other")]
public Shader atmosphericShader = null;
// public Shader occlusionShader = null;
public float worldScaleExponent = 1.0f;
// public bool forcePerPixel = true;
// public bool forcePostEffect = true;
// [Tooltip("Soft clouds need depth values. Ignore means externally controlled.")]
public DepthTexture depthTexture = DepthTexture.Enable;
public ScatterDebugMode debugMode = ScatterDebugMode.None;
public Cubemap skyHDRI = null;
// public Shader atmosphericShader = null;
// public Shader occlusionShader = null;
public float worldScaleExponent = 1.0f;
public ScatterDebugMode debugMode = ScatterDebugMode.None;
void Awake()
{
if (worldRayleighColorRamp == null)
{
worldRayleighColorRamp = new Gradient();
worldRayleighColorRamp.SetKeys(
new[] { new GradientColorKey(new Color(0.3f, 0.4f, 0.6f), 0f),
new GradientColorKey(new Color(0.5f, 0.6f, 0.8f), 1f) },
new[] { new GradientAlphaKey(1f, 0f),
new GradientAlphaKey(1f, 1f) }
);
}
if (worldMieColorRamp == null)
{
worldMieColorRamp = new Gradient();
worldMieColorRamp.SetKeys(
new[] { new GradientColorKey(new Color(0.95f, 0.75f, 0.5f), 0f),
new GradientColorKey(new Color(1f, 0.9f, 8.0f), 1f) },
new[] { new GradientAlphaKey(1f, 0f),
new GradientAlphaKey(1f, 1f) }
);
}
}
worldScaleExponent = Mathf.Clamp(worldScaleExponent, 1f, 2f);
worldNormalDistance = Mathf.Clamp(worldNormalDistance, 1f, 10000f);
worldNearScatterPush = Mathf.Clamp(worldNearScatterPush, -200f, 300f);
worldRayleighDensity = Mathf.Clamp(worldRayleighDensity, 0, 1000f);
worldMieDensity = Mathf.Clamp(worldMieDensity, 0f, 1000f);
worldMieDensity = Mathf.Clamp(worldMieDensity, 0f, 1000f);
worldMiePhaseAnisotropy = Mathf.Clamp01(worldMiePhaseAnisotropy);
worldNearScatterPush = Mathf.Clamp(worldNearScatterPush, -200f, 300f);
worldNormalDistance = Mathf.Clamp(worldNormalDistance, 1f, 10000f);
worldRayleighDensity = Mathf.Clamp(worldRayleighDensity, 0, 1000f);
worldMiePhaseAnisotropy = Mathf.Clamp01(worldMiePhaseAnisotropy);
heightNormalDistance = Mathf.Clamp(heightNormalDistance, 1f, 10000f);
heightNearScatterPush = Mathf.Clamp(heightNearScatterPush, -200f, 300f);
heightRayleighDensity = Mathf.Clamp(heightRayleighDensity, 0, 1000f);
heightMieDensity = Mathf.Clamp(heightMieDensity, 0, 1000f);
heightMieDensity = Mathf.Clamp(heightMieDensity, 0, 1000f);
heightNearScatterPush = Mathf.Clamp(heightNearScatterPush, -200f, 300f);
heightNormalDistance = Mathf.Clamp(heightNormalDistance, 1f, 10000f);
heightRayleighDensity = Mathf.Clamp(heightRayleighDensity, 0, 1000f);
worldScaleExponent = Mathf.Clamp(worldScaleExponent, 1f, 2f);
occlusionBias = Mathf.Clamp01(occlusionBias);
occlusionBiasIndirect = Mathf.Clamp01(occlusionBiasIndirect);
occlusionBiasClouds = Mathf.Clamp01(occlusionBiasClouds);
occlusionBiasSkyRayleigh = Mathf.Clamp01(occlusionBiasSkyRayleigh);
occlusionBiasSkyMie = Mathf.Clamp01(occlusionBiasSkyMie);
occlusionBias = Mathf.Clamp01(occlusionBias);
occlusionBiasClouds = Mathf.Clamp01(occlusionBiasClouds);
occlusionBiasIndirect = Mathf.Clamp01(occlusionBiasIndirect);
occlusionBiasSkyMie = Mathf.Clamp01(occlusionBiasSkyMie);
occlusionBiasSkyRayleigh = Mathf.Clamp01(occlusionBiasSkyRayleigh);
skyDomeExposure = Mathf.Clamp(skyDomeExposure, 0f, 8f);
}
}
}

188
Assets/ScriptableRenderLoop/HDRenderLoop/Sky/ProceduralSky/ProceduralSkyRenderer.cs


: SkyRenderer<ProceduralSkyParameters>
{
Material m_ProceduralSkyMaterial = null; // Renders a cubemap into a render texture (can be cube or 2D)
Gradient m_DefaultWorldRayleighColorRamp = null;
Gradient m_DefaultWorldMieColorRamp = null;
if (m_DefaultWorldRayleighColorRamp == null)
{
m_DefaultWorldRayleighColorRamp = new Gradient();
m_DefaultWorldRayleighColorRamp.SetKeys(
new[] { new GradientColorKey(new Color(0.3f, 0.4f, 0.6f), 0f),
new GradientColorKey(new Color(0.5f, 0.6f, 0.8f), 1f) },
new[] { new GradientAlphaKey(1f, 0f),
new GradientAlphaKey(1f, 1f) }
);
}
if (m_DefaultWorldMieColorRamp == null)
{
m_DefaultWorldMieColorRamp = new Gradient();
m_DefaultWorldMieColorRamp.SetKeys(
new[] { new GradientColorKey(new Color(0.95f, 0.75f, 0.5f), 0f),
new GradientColorKey(new Color(1f, 0.9f, 8.0f), 1f) },
new[] { new GradientAlphaKey(1f, 0f),
new GradientAlphaKey(1f, 1f) }
);
}
}
override public void Cleanup()

//ProceduralSkyParameters proceduralSkyParams = GetParameters(skyParameters);
return true; // TODO: See with Evgenii what makes it valid or invalid.
ProceduralSkyParameters allParams = GetParameters(skyParameters);
return allParams.skyHDRI != null &&
allParams.worldMieColorRamp != null &&
allParams.worldRayleighColorRamp != null;
void UpdateKeywords(bool enable, ProceduralSkyParameters param)
void SetKeywords(BuiltinSkyParameters builtinParams, ProceduralSkyParameters param)
// Ensure that all preprocessor symbols are initially undefined.
m_ProceduralSkyMaterial.DisableKeyword("ATMOSPHERICS_DEBUG");
m_ProceduralSkyMaterial.DisableKeyword("ATMOSPHERICS_OCCLUSION_FULLSKY");
m_ProceduralSkyMaterial.DisableKeyword("ATMOSPHERICS_OCCLUSION_FULLSKY");
m_ProceduralSkyMaterial.DisableKeyword("ATMOSPHERICS_DEBUG");
m_ProceduralSkyMaterial.DisableKeyword("PERFORM_SKY_OCCLUSION_TEST");
if (enable)
/*
if (useOcclusion)
/*
if (useOcclusion)
{
m_ProceduralSkyMaterial.EnableKeyword("ATMOSPHERICS_OCCLUSION");
if(occlusionDepthFixup && occlusionDownscale != OcclusionDownscale.x1)
m_ProceduralSkyMaterial.EnableKeyword("ATMOSPHERICS_OCCLUSION_EDGE_FIXUP");
if(occlusionFullSky)
m_ProceduralSkyMaterial.EnableKeyword("ATMOSPHERICS_OCCLUSION_FULLSKY");
}
*/
m_ProceduralSkyMaterial.EnableKeyword("ATMOSPHERICS_OCCLUSION");
if(occlusionDepthFixup && occlusionDownscale != OcclusionDownscale.x1)
m_ProceduralSkyMaterial.EnableKeyword("ATMOSPHERICS_OCCLUSION_EDGE_FIXUP");
if(occlusionFullSky)
m_ProceduralSkyMaterial.EnableKeyword("ATMOSPHERICS_OCCLUSION_FULLSKY");
}
*/
if (param.debugMode != ProceduralSkyParameters.ScatterDebugMode.None)
{
m_ProceduralSkyMaterial.EnableKeyword("ATMOSPHERICS_DEBUG");
}
// Expected to be valid for the sky pass, and invalid for the cube map generation pass.
if (builtinParams.depthBufferIsValid)
{
m_ProceduralSkyMaterial.EnableKeyword("PERFORM_SKY_OCCLUSION_TEST");
}
if (param.debugMode != ProceduralSkyParameters.ScatterDebugMode.None)
{
m_ProceduralSkyMaterial.EnableKeyword("ATMOSPHERICS_DEBUG");
void UpdateStaticUniforms(ProceduralSkyParameters param)
void SetUniforms(BuiltinSkyParameters builtinParams, ProceduralSkyParameters param)
m_ProceduralSkyMaterial.SetTexture("_SkyDomeCubemap", param.skyDomeCubemap);
m_ProceduralSkyMaterial.SetFloat("_SkyDomeExposure", param.skyDomeExposure);
m_ProceduralSkyMaterial.SetColor("_SkyDomeTint", param.skyDomeTint);
m_ProceduralSkyMaterial.SetTexture("_Cubemap", param.skyHDRI);
m_ProceduralSkyMaterial.SetVector("_SkyParam", new Vector4(param.exposure, param.multiplier, param.rotation, 0.0f));
m_ProceduralSkyMaterial.SetMatrix("_ViewProjMatrix", builtinParams.viewProjMatrix);
m_ProceduralSkyMaterial.SetMatrix("_InvViewProjMatrix", builtinParams.invViewProjMatrix);
m_ProceduralSkyMaterial.SetInt("_AtmosphericsDebugMode", (int)param.debugMode);
Vector3 sunDirection = (builtinParams.sunLight != null) ? -builtinParams.sunLight.transform.forward : Vector3.zero;
m_ProceduralSkyMaterial.SetVector("_SunDirection", sunDirection);
/*
m_ProceduralSkyMaterial.SetFloat("_ShadowBias", useOcclusion ? occlusionBias : 1f);

m_ProceduralSkyMaterial.SetFloat("_OcclusionDepthThreshold", occlusionDepthThreshold);
m_ProceduralSkyMaterial.SetVector("_OcclusionTexture_TexelSize", ???);
m_ProceduralSkyMaterial.SetFloat("_WorldScaleExponent", param.worldScaleExponent);
var pixelRect = new Rect(0f, 0f, builtinParams.screenSize.x, builtinParams.screenSize.y);
var scale = 1.0f; //(float)(int)occlusionDownscale;
var depthTextureScaledTexelSize = new Vector4(scale / pixelRect.width,
scale / pixelRect.height,
-scale / pixelRect.width,
-scale / pixelRect.height);
m_ProceduralSkyMaterial.SetVector("_DepthTextureScaledTexelSize", depthTextureScaledTexelSize);
m_ProceduralSkyMaterial.SetFloat("_WorldScaleExponent", param.worldScaleExponent);
m_ProceduralSkyMaterial.SetFloat("_MiePhaseAnisotropy", param.worldMiePhaseAnisotropy);
m_ProceduralSkyMaterial.SetVector("_RayleighInScatterPct", new Vector4(1f - param.worldRayleighIndirectScatter, param.worldRayleighIndirectScatter, 0f, 0f));
m_ProceduralSkyMaterial.SetFloat("_WorldMieDensity", -param.worldMieDensity / 100000f);
m_ProceduralSkyMaterial.SetFloat("_HeightNormalDistanceRcp", 1f / param.heightNormalDistance);
m_ProceduralSkyMaterial.SetFloat("_HeightNearScatterPush", -Mathf.Pow(Mathf.Abs(param.heightNearScatterPush), param.worldScaleExponent) * Mathf.Sign(param.heightNearScatterPush));
m_ProceduralSkyMaterial.SetFloat("_HeightRayleighDensity", -param.heightRayleighDensity / 100000f);
var rayleighColorM20 = param.worldRayleighColorRamp.Evaluate(0.00f);
var rayleighColorM10 = param.worldRayleighColorRamp.Evaluate(0.25f);
var rayleighColorO00 = param.worldRayleighColorRamp.Evaluate(0.50f);
var rayleighColorP10 = param.worldRayleighColorRamp.Evaluate(0.75f);
var rayleighColorP20 = param.worldRayleighColorRamp.Evaluate(1.00f);
m_ProceduralSkyMaterial.SetFloat("_HeightSeaLevel", param.heightSeaLevel);
m_ProceduralSkyMaterial.SetFloat("_HeightDistanceRcp", 1f / param.heightDistance);
m_ProceduralSkyMaterial.SetVector("_HeightPlaneShift", param.heightPlaneShift);
m_ProceduralSkyMaterial.SetVector("_HeightRayleighColor", (Vector4)param.heightRayleighColor * param.heightRayleighIntensity);
m_ProceduralSkyMaterial.SetFloat("_HeightExtinctionFactor", param.heightExtinctionFactor);
m_ProceduralSkyMaterial.SetFloat("_RayleighExtinctionFactor", param.worldRayleighExtinctionFactor);
m_ProceduralSkyMaterial.SetFloat("_MieExtinctionFactor", param.worldMieExtinctionFactor);
Gradient worldRayleighColorRamp = param.worldRayleighColorRamp != null ? param.worldRayleighColorRamp : m_DefaultWorldRayleighColorRamp;
Gradient worldMieColorRamp = param.worldMieColorRamp != null ? param.worldMieColorRamp : m_DefaultWorldMieColorRamp;
var rayleighColorM20 = worldRayleighColorRamp.Evaluate(0.00f);
var rayleighColorM10 = worldRayleighColorRamp.Evaluate(0.25f);
var rayleighColorO00 = worldRayleighColorRamp.Evaluate(0.50f);
var rayleighColorP10 = worldRayleighColorRamp.Evaluate(0.75f);
var rayleighColorP20 = worldRayleighColorRamp.Evaluate(1.00f);
var mieColorM20 = worldMieColorRamp.Evaluate(0.00f);
var mieColorO00 = worldMieColorRamp.Evaluate(0.50f);
var mieColorP20 = worldMieColorRamp.Evaluate(1.00f);
var mieColorM20 = param.worldMieColorRamp.Evaluate(0.00f);
var mieColorO00 = param.worldMieColorRamp.Evaluate(0.50f);
var mieColorP20 = param.worldMieColorRamp.Evaluate(1.00f);
m_ProceduralSkyMaterial.SetVector("_RayleighColorM20", (Vector4)rayleighColorM20 * param.worldRayleighColorIntensity);
m_ProceduralSkyMaterial.SetVector("_RayleighColorM10", (Vector4)rayleighColorM10 * param.worldRayleighColorIntensity);

m_ProceduralSkyMaterial.SetVector("_MieColorO00", (Vector4)mieColorO00 * param.worldMieColorIntensity);
m_ProceduralSkyMaterial.SetVector("_MieColorP20", (Vector4)mieColorP20 * param.worldMieColorIntensity);
m_ProceduralSkyMaterial.SetInt("_AtmosphericsDebugMode", (int)param.debugMode);
}
void UpdateDynamicUniforms(BuiltinSkyParameters builtinParams, ProceduralSkyParameters param)
{
/* For now, we only use the directional light we are attached to, and the current camera. */
var trackedYaw = param.skyDomeTrackedYawRotation ? param.skyDomeTrackedYawRotation.eulerAngles.y : 0f;
m_ProceduralSkyMaterial.SetMatrix("_SkyDomeRotation",
Matrix4x4.TRS(Vector3.zero, Quaternion.Euler(param.skyDomeRotation.x, 0f, 0f), Vector3.one)
* Matrix4x4.TRS(Vector3.zero, Quaternion.Euler(0f, param.skyDomeRotation.y - trackedYaw, 0f), Vector3.one)
* Matrix4x4.TRS(Vector3.zero, Quaternion.identity, new Vector3(1f, param.skyDomeVerticalFlip ? -1f : 1f, 1f))
);
Vector3 sunDirection = (builtinParams.sunLight != null) ? -builtinParams.sunLight.transform.forward : Vector3.zero;
m_ProceduralSkyMaterial.SetVector("_SunDirection", sunDirection);
m_ProceduralSkyMaterial.SetFloat("_WorldMieDensity", -param.worldMieDensity / 100000f);
m_ProceduralSkyMaterial.SetFloat("_HeightNormalDistanceRcp", 1f / param.heightNormalDistance);
m_ProceduralSkyMaterial.SetFloat("_HeightNearScatterPush", -Mathf.Pow(Mathf.Abs(param.heightNearScatterPush), param.worldScaleExponent) * Mathf.Sign(param.heightNearScatterPush));
m_ProceduralSkyMaterial.SetFloat("_HeightRayleighDensity", -param.heightRayleighDensity / 100000f);
m_ProceduralSkyMaterial.SetFloat("_HeightSeaLevel", param.heightSeaLevel);
m_ProceduralSkyMaterial.SetVector("_HeightPlaneShift", param.heightPlaneShift);
m_ProceduralSkyMaterial.SetFloat("_HeightDistanceRcp", 1f / param.heightDistance);
m_ProceduralSkyMaterial.SetVector("_HeightRayleighColor", (Vector4)param.heightRayleighColor * param.heightRayleighIntensity);
m_ProceduralSkyMaterial.SetFloat("_HeightExtinctionFactor", param.heightExtinctionFactor);
//var pixelRect = Camera.current ? Camera.current.pixelRect
// : new Rect(0f, 0f, Screen.width, Screen.height);
var pixelRect = new Rect(0f, 0f, builtinParams.screenSize.x, builtinParams.screenSize.y);
var scale = 1.0f; //(float)(int)occlusionDownscale;
var depthTextureScaledTexelSize = new Vector4(scale / pixelRect.width,
scale / pixelRect.height,
-scale / pixelRect.width,
-scale / pixelRect.height);
m_ProceduralSkyMaterial.SetVector("_DepthTextureScaledTexelSize", depthTextureScaledTexelSize);
m_ProceduralSkyMaterial.SetVector("_RayleighInScatterPct", new Vector4(1f - param.worldRayleighIndirectScatter, param.worldRayleighIndirectScatter, 0f, 0f));
m_ProceduralSkyMaterial.SetFloat("_RayleighExtinctionFactor", param.worldRayleighExtinctionFactor);
m_ProceduralSkyMaterial.SetFloat("_MiePhaseAnisotropy", param.worldMiePhaseAnisotropy);
m_ProceduralSkyMaterial.SetFloat("_MieExtinctionFactor", param.worldMieExtinctionFactor);
m_ProceduralSkyMaterial.SetMatrix("_InvViewProjMatrix", builtinParams.invViewProjMatrix);
}
override public void RenderSky(BuiltinSkyParameters builtinParams, SkyParameters skyParameters)

// Define select preprocessor symbols.
UpdateKeywords(true, proceduralSkyParams);
// Julien: what is it supposed to do?
if (proceduralSkyParams.depthTexture == ProceduralSkyParameters.DepthTexture.Disable)
{
// Disable depth texture rendering.
Camera.current.depthTextureMode = DepthTextureMode.None;
}
SetKeywords(builtinParams, proceduralSkyParams);
UpdateStaticUniforms(proceduralSkyParams);
UpdateDynamicUniforms(builtinParams, proceduralSkyParams);
m_ProceduralSkyMaterial.SetTexture("_Cubemap", proceduralSkyParams.skyDomeCubemap);
m_ProceduralSkyMaterial.SetVector("_SkyParam", new Vector4(proceduralSkyParams.exposure, proceduralSkyParams.multiplier, proceduralSkyParams.rotation, 0.0f));
SetUniforms(builtinParams, proceduralSkyParams);
var cmd = new CommandBuffer { name = "" };
cmd.DrawMesh(builtinParams.skyMesh, Matrix4x4.identity, m_ProceduralSkyMaterial);

13
Assets/ScriptableRenderLoop/HDRenderLoop/Sky/ProceduralSky/Resources/AtmosphericScattering.hlsl


uniform float _ShadowBias;
uniform float _ShadowBiasIndirect;
uniform float _ShadowBiasClouds;
uniform float2 _ShadowBiasSkyRayleighMie;
uniform float _OcclusionDepthThreshold;
uniform float4 _OcclusionTexture_TexelSize;

uniform float _HeightSeaLevel;
uniform float3 _HeightPlaneShift;
uniform float _HeightDistanceRcp;
uniform float4 _HeightRayleighColor;
uniform float _HeightExtinctionFactor;
uniform float _RayleighCoeffScale;
uniform float3 _RayleighSunTintIntensity;
uniform float _RayleighExtinctionFactor;
uniform float _MieCoeffScale;
uniform float3 _MieSunTintIntensity;
uniform float _HeightExtinctionFactor;
uniform float _RayleighExtinctionFactor;
uniform float4 _HeightRayleighColor;
SAMPLER2D(sampler_CameraDepthTexture)
#define SRL_BilinearSampler sampler_CameraDepthTexture // Used for all textures

12
Assets/ScriptableRenderLoop/HDRenderLoop/Sky/ProceduralSky/Resources/SkyProcedural.shader


{
ZWrite Off
ZTest LEqual
Blend One Zero
Blend One OneMinusSrcAlpha
HLSLPROGRAM
#pragma target 5.0

#pragma fragment Frag
#pragma multi_compile _ ATMOSPHERICS_DEBUG
#pragma multi_compile _ ATMOSPHERICS_OCCLUSION_FULLSKY
#pragma multi_compile _ PERFORM_SKY_OCCLUSION_TEST
#ifndef PERFORM_SKY_OCCLUSION_TEST

// input.positionCS is SV_Position
PositionInputs posInput = GetPositionInput(input.positionCS.xy, _ScreenSize.zw);
// If the sky box is too far away (depth set to 0), the resulting look is too foggy.
const float skyDepth = 0.01;

}
#endif
float3 skyColor = ClampToFloat16Max(SAMPLE_TEXTURECUBE_LOD(_Cubemap, sampler_Cubemap, dir, 0).rgb * exp2(_SkyParam.x) * _SkyParam.y);
float3 skyColor = SAMPLE_TEXTURECUBE_LOD(_Cubemap, sampler_Cubemap, dir, 0).rgb * exp2(_SkyParam.x) * _SkyParam.y;
float3 atmosphereColor = skyColor * (skyTexWeight * extinction) + scatter;
// Apply extinction to the scene color when performing alpha-blending.
return float4(skyColor * (skyTexWeight * extinction) + scatter, extinction);
// Apply the atmosphere on top of the scene using premultiplied alpha blending.
return float4(ClampToFloat16Max(atmosphereColor), extinction);
}
ENDHLSL

7
Assets/ScriptableRenderLoop/HDRenderLoop/Sky/SkyManager.cs


public Light sunLight;
public RenderTargetIdentifier colorBuffer;
public RenderTargetIdentifier depthBuffer;
public bool depthBufferIsValid;
}
public class SkyManager

m_UpdateRequired = true; // Special case. Even if update mode is set to OnDemand, we need to regenerate the environment after destroying the texture.
}
if (m_SkyboxCubemapRT == null)
{
m_SkyboxCubemapRT = new RenderTexture(resolution, resolution, 1, RenderTextureFormat.ARGBHalf);

builtinParams.screenSize = m_CubemapScreenSize;
builtinParams.skyMesh = m_CubemapFaceMesh[i];
builtinParams.colorBuffer = target;
builtinParams.depthBuffer = new RenderTargetIdentifier();
builtinParams.depthBuffer = -1;
builtinParams.depthBufferIsValid = false;
m_Renderer.RenderSky(builtinParams, skyParameters);
}
}

m_BuiltinParameters.skyMesh = BuildSkyMesh(camera.camera.GetComponent<Transform>().position, m_BuiltinParameters.invViewProjMatrix, false);
m_BuiltinParameters.colorBuffer = colorBuffer;
m_BuiltinParameters.depthBuffer = depthBuffer;
m_BuiltinParameters.depthBufferIsValid = true;
Utilities.SetRenderTarget(renderLoop, colorBuffer, depthBuffer);
m_Renderer.RenderSky(m_BuiltinParameters, skyParameters);

正在加载...
取消
保存