浏览代码

Procedural sky now uses the Sky Framework (V1 functionality not tested)

/main
Julien Ignace 8 年前
当前提交
58445897
共有 27 个文件被更改,包括 581 次插入20 次删除
  1. 7
      Assets/ScriptableRenderLoop/HDRenderLoop/HDRenderLoop.asset
  2. 2
      Assets/ScriptableRenderLoop/HDRenderLoop/HDRenderLoop.cs
  3. 4
      Assets/ScriptableRenderLoop/HDRenderLoop/Lighting/LightLoop.cs
  4. 9
      Assets/ScriptableRenderLoop/HDRenderLoop/Lighting/TilePass/TilePass.cs
  5. 2
      Assets/ScriptableRenderLoop/HDRenderLoop/Sky/HDRISky/Editor/HDRISkyEditor.cs
  6. 11
      Assets/ScriptableRenderLoop/HDRenderLoop/Sky/HDRISky/HDRISkyRenderer.cs
  7. 2
      Assets/ScriptableRenderLoop/HDRenderLoop/Sky/HDRISky/Resources/SkyHDRI.shader
  8. 4
      Assets/ScriptableRenderLoop/HDRenderLoop/Sky/SkyManager.cs
  9. 6
      Assets/ScriptableRenderLoop/HDRenderLoop/Sky/SkyParameters.cs
  10. 104
      Assets/TestScenes/HDTest/GlobalIlluminationTest.unity
  11. 2
      Assets/ScriptableRenderLoop/HDRenderLoop/Sky/ProceduralSky/Resources/SkyProcedural.shader
  12. 9
      Assets/ScriptableRenderLoop/HDRenderLoop/Sky/ProceduralSky.meta
  13. 9
      Assets/ScriptableRenderLoop/HDRenderLoop/Sky/ProceduralSky/Editor.meta
  14. 61
      Assets/ScriptableRenderLoop/HDRenderLoop/Sky/ProceduralSky/Editor/ProceduralSkyEditor.cs
  15. 12
      Assets/ScriptableRenderLoop/HDRenderLoop/Sky/ProceduralSky/Editor/ProceduralSkyEditor.cs.meta
  16. 105
      Assets/ScriptableRenderLoop/HDRenderLoop/Sky/ProceduralSky/ProceduralSkyParameters.cs
  17. 12
      Assets/ScriptableRenderLoop/HDRenderLoop/Sky/ProceduralSky/ProceduralSkyParameters.cs.meta
  18. 219
      Assets/ScriptableRenderLoop/HDRenderLoop/Sky/ProceduralSky/ProceduralSkyRenderer.cs
  19. 12
      Assets/ScriptableRenderLoop/HDRenderLoop/Sky/ProceduralSky/ProceduralSkyRenderer.cs.meta
  20. 9
      Assets/ScriptableRenderLoop/HDRenderLoop/Sky/ProceduralSky/Resources.meta
  21. 0
      /Assets/ScriptableRenderLoop/HDRenderLoop/Sky/ProceduralSky/Resources/AtmosphericScattering.hlsl
  22. 0
      /Assets/ScriptableRenderLoop/HDRenderLoop/Sky/ProceduralSky/Resources/AtmosphericScattering.hlsl.meta
  23. 0
      /Assets/ScriptableRenderLoop/HDRenderLoop/Sky/ProceduralSky/Resources/SkyProcedural.shader
  24. 0
      /Assets/ScriptableRenderLoop/HDRenderLoop/Sky/ProceduralSky/Resources/SkyProcedural.shader.meta

7
Assets/ScriptableRenderLoop/HDRenderLoop/HDRenderLoop.asset


m_Script: {fileID: 11500000, guid: 558064ecdbf6b6742892d699acb39aed, type: 3}
m_Name: HDRenderLoop
m_EditorClassIdentifier:
m_SkyParameters:
skyHDRI: {fileID: 0}
rotation: 0
exposure: 0
multiplier: 1
skyResolution: 256
m_ShadowSettings:
enabled: 1
shadowAtlasWidth: 4096

spotCookieSize: 128
pointCookieSize: 512
reflectionCubemapSize: 128
m_Dirty: 0

2
Assets/ScriptableRenderLoop/HDRenderLoop/HDRenderLoop.cs


void RenderSky(Camera camera, RenderLoop renderLoop)
{
m_SkyManager.RenderSky(camera, m_SkyParameters, m_CameraColorBufferRT, m_CameraDepthBufferRT, renderLoop);
m_SkyManager.RenderSky(camera, m_lightLoop.GetCurrentSunLight(), m_SkyParameters, m_CameraColorBufferRT, m_CameraDepthBufferRT, renderLoop);
}
void RenderForward(CullResults cullResults, Camera camera, RenderLoop renderLoop, bool renderOpaque)

4
Assets/ScriptableRenderLoop/HDRenderLoop/Lighting/LightLoop.cs


{
public class BaseLightLoop
{
protected Light m_CurrentSunLight = null;
// TODO: We should rather put the texture settings in LightLoop, but how do we serialize it ?
public virtual void Build(TextureSettings textureSettings) {}

public virtual void RenderDeferredLighting(Camera camera, RenderLoop renderLoop, RenderTargetIdentifier cameraColorBufferRT) {}
public virtual void RenderForward(Camera camera, RenderLoop renderLoop, bool renderOpaque) {}
public Light GetCurrentSunLight() { return m_CurrentSunLight; }
}
}

9
Assets/ScriptableRenderLoop/HDRenderLoop/Lighting/TilePass/TilePass.cs


bool hasDirectionalShadows = light.light.shadows != LightShadows.None && shadowOutput.GetShadowSliceCountLightIndex(lightIndex) != 0;
bool hasDirectionalNotReachMaxLimit = directionalShadowcount == 0; // Only one cascade shadow allowed
// If we have not found a directional shadow casting light yet, we register the last directional anyway as "sun".
if (directionalShadowcount == 0)
{
m_CurrentSunLight = light.light;
}
// Always choose the directional shadow casting light if it exists.
m_CurrentSunLight = light.light;
directionalLightData.shadowIndex = m_lightList.shadows.Count;
directionalShadowcount += GetShadows(light, lightIndex, ref shadowOutput);

2
Assets/ScriptableRenderLoop/HDRenderLoop/Sky/HDRISky/Editor/HDRISkyEditor.cs


{
[CanEditMultipleObjects]
[CustomEditor(typeof(HDRISkyParameters))]
public class TestClassEditor
public class HDRISkyParametersEditor
: Editor
{
private class Styles

11
Assets/ScriptableRenderLoop/HDRenderLoop/Sky/HDRISky/HDRISkyRenderer.cs


public class HDRISkyRenderer
: SkyRenderer
{
MaterialPropertyBlock m_PropertyBlock = null;
m_SkyHDRIMaterial = Utilities.CreateEngineMaterial("HDRenderLoop/Sky/SkyHDRI");
m_PropertyBlock = new MaterialPropertyBlock();
m_SkyHDRIMaterial = Utilities.CreateEngineMaterial("Hidden/HDRenderLoop/Sky/SkyHDRI");
}
override public void Cleanup()

return;
}
m_PropertyBlock.SetTexture("_Cubemap", hdriSkyParams.skyHDRI);
m_PropertyBlock.SetVector("_SkyParam", new Vector4(hdriSkyParams.exposure, hdriSkyParams.multiplier, hdriSkyParams.rotation, 0.0f));
//m_RenderSkyPropertyBlock.SetMatrix("_InvViewProjMatrix", invViewProjectionMatrix);
m_SkyHDRIMaterial.SetTexture("_Cubemap", hdriSkyParams.skyHDRI);
m_SkyHDRIMaterial.SetVector("_SkyParam", new Vector4(hdriSkyParams.exposure, hdriSkyParams.multiplier, hdriSkyParams.rotation, 0.0f));
cmd.DrawMesh(builtinParams.skyMesh, Matrix4x4.identity, m_SkyHDRIMaterial, 0, 0, m_PropertyBlock);
cmd.DrawMesh(builtinParams.skyMesh, Matrix4x4.identity, m_SkyHDRIMaterial);
builtinParams.renderLoop.ExecuteCommandBuffer(cmd);
cmd.Dispose();
}

2
Assets/ScriptableRenderLoop/HDRenderLoop/Sky/HDRISky/Resources/SkyHDRI.shader


Shader "HDRenderLoop/Sky/SkyHDRI"
Shader "Hidden/HDRenderLoop/Sky/SkyHDRI"
{
SubShader
{

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


public Matrix4x4 invViewProjMatrix;
public Mesh skyMesh;
public RenderLoop renderLoop;
public Light sunLight;
}
public class SkyManager

}
}
public void RenderSky(Camera camera, SkyParameters skyParameters, RenderTargetIdentifier colorBuffer, RenderTargetIdentifier depthBuffer, RenderLoop renderLoop)
public void RenderSky(Camera camera, Light sunLight, SkyParameters skyParameters, RenderTargetIdentifier colorBuffer, RenderTargetIdentifier depthBuffer, RenderLoop renderLoop)
{
using (new Utilities.ProfilingSample("Sky Pass", renderLoop))
{

m_BuiltinParameters.sunLight = sunLight;
if (skyParameters.GetHash() != m_SkyParametersHash)
{

6
Assets/ScriptableRenderLoop/HDRenderLoop/Sky/SkyParameters.cs


{
int hash = 13;
foreach (var p in m_Properties)
hash = hash * 23 + p.GetValue(this).GetHashCode();
{
System.Object obj = p.GetValue(this);
if(obj != null) // Sometimes it can be a null reference.
hash = hash * 23 + obj.GetHashCode();
}
return hash;
}
}

104
Assets/TestScenes/HDTest/GlobalIlluminationTest.unity


m_Component:
- component: {fileID: 1692663595}
- component: {fileID: 1692663596}
- component: {fileID: 1692663597}
m_Layer: 0
m_Name: SceneParameters
m_TagString: Untagged

multiplier: 1
resolution: 512
skyHDRI: {fileID: 8900000, guid: 9b513842339ef704ca63ef696691bc34, type: 3}
--- !u!114 &1692663597
MonoBehaviour:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1692663594}
m_Enabled: 0
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 54bcd1d5cb4984847971142e9444d2fb, type: 3}
m_Name:
m_EditorClassIdentifier:
rotation: 0
exposure: 0
multiplier: 1
resolution: 256
worldRayleighColorRamp:
serializedVersion: 2
key0: {r: 1, g: 1, b: 1, a: 1}
key1: {r: 1, g: 1, b: 1, a: 1}
key2: {r: 0, g: 0, b: 0, a: 0}
key3: {r: 0, g: 0, b: 0, a: 0}
key4: {r: 0, g: 0, b: 0, a: 0}
key5: {r: 0, g: 0, b: 0, a: 0}
key6: {r: 0, g: 0, b: 0, a: 0}
key7: {r: 0, g: 0, b: 0, a: 0}
ctime0: 0
ctime1: 65535
ctime2: 0
ctime3: 0
ctime4: 0
ctime5: 0
ctime6: 0
ctime7: 0
atime0: 0
atime1: 65535
atime2: 0
atime3: 0
atime4: 0
atime5: 0
atime6: 0
atime7: 0
m_Mode: 0
m_NumColorKeys: 2
m_NumAlphaKeys: 2
worldRayleighColorIntensity: 1
worldRayleighDensity: 10
worldRayleighExtinctionFactor: 1.1
worldRayleighIndirectScatter: 0.33
worldMieColorRamp:
serializedVersion: 2
key0: {r: 1, g: 1, b: 1, a: 1}
key1: {r: 1, g: 1, b: 1, a: 1}
key2: {r: 0, g: 0, b: 0, a: 0}
key3: {r: 0, g: 0, b: 0, a: 0}
key4: {r: 0, g: 0, b: 0, a: 0}
key5: {r: 0, g: 0, b: 0, a: 0}
key6: {r: 0, g: 0, b: 0, a: 0}
key7: {r: 0, g: 0, b: 0, a: 0}
ctime0: 0
ctime1: 65535
ctime2: 0
ctime3: 0
ctime4: 0
ctime5: 0
ctime6: 0
ctime7: 0
atime0: 0
atime1: 65535
atime2: 0
atime3: 0
atime4: 0
atime5: 0
atime6: 0
atime7: 0
m_Mode: 0
m_NumColorKeys: 2
m_NumAlphaKeys: 2
worldMieColorIntensity: 1
worldMieDensity: 15
worldMieExtinctionFactor: 0
worldMiePhaseAnisotropy: 0.9
worldNearScatterPush: 0
worldNormalDistance: 1000
heightRayleighColor: {r: 1, g: 1, b: 1, a: 1}
heightRayleighIntensity: 1
heightRayleighDensity: 10
heightMieDensity: 0
heightExtinctionFactor: 1.1
heightSeaLevel: 0
heightDistance: 50
heightPlaneShift: {x: 0, y: 0, z: 0}
heightNearScatterPush: 0
heightNormalDistance: 1000
skyDomeRotation: {x: 0, y: 0, z: 0}
skyDomeVerticalFlip: 0
skyDomeCubemap: {fileID: 8900000, guid: 9b513842339ef704ca63ef696691bc34, type: 3}
skyDomeExposure: 1
skyDomeTint: {r: 1, g: 1, b: 1, a: 1}
skyDomeTrackedYawRotation: {fileID: 0}
atmosphericShader: {fileID: 0}
worldScaleExponent: 1
depthTexture: 0
debugMode: 0
--- !u!1 &1736468424
GameObject:
m_ObjectHideFlags: 0

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


Shader "Hidden/HDRenderLoop/SkyProcedural"
Shader "Hidden/HDRenderLoop/Sky/SkyProcedural"
{
SubShader
{

9
Assets/ScriptableRenderLoop/HDRenderLoop/Sky/ProceduralSky.meta


fileFormatVersion: 2
guid: 65f9231eb40b6914eb24ea0b555778f0
folderAsset: yes
timeCreated: 1481646017
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

9
Assets/ScriptableRenderLoop/HDRenderLoop/Sky/ProceduralSky/Editor.meta


fileFormatVersion: 2
guid: 00372bf7f144a724bba68a081fd79e78
folderAsset: yes
timeCreated: 1481646149
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

61
Assets/ScriptableRenderLoop/HDRenderLoop/Sky/ProceduralSky/Editor/ProceduralSkyEditor.cs


using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
namespace UnityEngine.Experimental.ScriptableRenderLoop
{
//[CanEditMultipleObjects]
//[CustomEditor(typeof(ProceduralSkyParameters))]
//public class ProceduralSkyParametersEditor
// : Editor
//{
// private class Styles
// {
// public readonly GUIContent skyHDRI = new GUIContent("HDRI");
// public readonly GUIContent skyResolution = new GUIContent("Resolution");
// public readonly GUIContent skyExposure = new GUIContent("Exposure");
// public readonly GUIContent skyRotation = new GUIContent("Rotation");
// public readonly GUIContent skyMultiplier = new GUIContent("Multiplier");
// }
// private static Styles s_Styles = null;
// private static Styles styles
// {
// get
// {
// if (s_Styles == null)
// s_Styles = new Styles();
// return s_Styles;
// }
// }
// private SerializedProperty m_SkyHDRI;
// private SerializedProperty m_SkyResolution;
// private SerializedProperty m_SkyExposure;
// private SerializedProperty m_SkyMultiplier;
// private SerializedProperty m_SkyRotation;
// void OnEnable()
// {
// m_SkyHDRI = serializedObject.FindProperty("skyHDRI");
// m_SkyResolution = serializedObject.FindProperty("resolution");
// m_SkyExposure = serializedObject.FindProperty("exposure");
// m_SkyMultiplier = serializedObject.FindProperty("multiplier");
// m_SkyRotation = serializedObject.FindProperty("rotation");
// }
// public override void OnInspectorGUI()
// {
// serializedObject.Update();
// EditorGUILayout.PropertyField(m_SkyHDRI, styles.skyHDRI);
// EditorGUILayout.PropertyField(m_SkyResolution, styles.skyResolution);
// EditorGUILayout.PropertyField(m_SkyExposure, styles.skyExposure);
// EditorGUILayout.PropertyField(m_SkyMultiplier, styles.skyMultiplier);
// EditorGUILayout.PropertyField(m_SkyRotation, styles.skyRotation);
// serializedObject.ApplyModifiedProperties();
// }
//}
}

12
Assets/ScriptableRenderLoop/HDRenderLoop/Sky/ProceduralSky/Editor/ProceduralSkyEditor.cs.meta


fileFormatVersion: 2
guid: 40b56ef8d02cefa49ab82e6b7df9266b
timeCreated: 1481635925
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

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


using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace UnityEngine.Experimental.ScriptableRenderLoop
{
[ExecuteInEditMode]
public class ProceduralSkyParameters
: SkyParameters
{
public enum OcclusionDownscale { x1 = 1, x2 = 2, x4 = 4 }
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 }
[Header("Global Settings")]
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;
[Header("Height Settings")]
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;
/*
[Header("Scatter Occlusion")]
public bool useOcclusion = false;
public float occlusionBias = 0f;
public float occlusionBiasIndirect = 0.6f;
public float occlusionBiasClouds = 0.3f;
public OcclusionDownscale occlusionDownscale = OcclusionDownscale.x2;
public OcclusionSamples occlusionSamples = OcclusionSamples.x64;
public bool occlusionDepthFixup = true;
public float occlusionDepthThreshold = 25f;
public bool occlusionFullSky = false;
public float occlusionBiasSkyRayleigh = 0.2f;
public float occlusionBiasSkyMie = 0.4f;
*/
[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;
// Camera m_currentCamera;
// UnityEngine.Rendering.CommandBuffer m_occlusionCmdAfterShadows, m_occlusionCmdBeforeScreen;
public void OnValidate()
{
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);
worldRayleighIndirectScatter = Mathf.Clamp(worldRayleighIndirectScatter, 0f, 1f);
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);
/*
occlusionBias = Mathf.Clamp01(occlusionBias);
occlusionBiasIndirect = Mathf.Clamp01(occlusionBiasIndirect);
occlusionBiasClouds = Mathf.Clamp01(occlusionBiasClouds);
occlusionBiasSkyRayleigh = Mathf.Clamp01(occlusionBiasSkyRayleigh);
occlusionBiasSkyMie = Mathf.Clamp01(occlusionBiasSkyMie);
*/
skyDomeExposure = Mathf.Clamp(skyDomeExposure, 0f, 8f);
}
}
}

12
Assets/ScriptableRenderLoop/HDRenderLoop/Sky/ProceduralSky/ProceduralSkyParameters.cs.meta


fileFormatVersion: 2
guid: 54bcd1d5cb4984847971142e9444d2fb
timeCreated: 1481631764
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

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


using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.Experimental.Rendering;
namespace UnityEngine.Experimental.ScriptableRenderLoop
{
public class ProceduralSkyRenderer
: SkyRenderer
{
Material m_ProceduralSkyMaterial = null; // Renders a cubemap into a render texture (can be cube or 2D)
Gradient m_DefaultWorldRayleighColorRamp = null;
Gradient m_DefaultWorldMieColorRamp = null;
override public void Build()
{
m_ProceduralSkyMaterial = Utilities.CreateEngineMaterial("Hidden/HDRenderLoop/Sky/SkyProcedural");
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()
{
Utilities.Destroy(m_ProceduralSkyMaterial);
}
ProceduralSkyParameters GetProceduralSkyParameters(SkyParameters parameters)
{
ProceduralSkyParameters proceduralSkyParameters = parameters as ProceduralSkyParameters;
if (proceduralSkyParameters == null)
{
Debug.LogWarning("ProceduralSkyRenderer needs an instance of ProceduralSkyParameters to be able to render.");
return null;
}
return proceduralSkyParameters;
}
override public bool IsSkyValid(SkyParameters skyParameters)
{
ProceduralSkyParameters proceduralSkyParams = GetProceduralSkyParameters(skyParameters);
if (proceduralSkyParams == null)
{
return false;
}
return true; // TODO: How is it valid?
}
void UpdateKeywords(bool enable, ProceduralSkyParameters param)
{
m_ProceduralSkyMaterial.DisableKeyword("ATMOSPHERICS_OCCLUSION");
m_ProceduralSkyMaterial.DisableKeyword("ATMOSPHERICS_OCCLUSION_FULLSKY");
m_ProceduralSkyMaterial.DisableKeyword("ATMOSPHERICS_OCCLUSION_EDGE_FIXUP");
m_ProceduralSkyMaterial.DisableKeyword("ATMOSPHERICS_SUNRAYS");
m_ProceduralSkyMaterial.DisableKeyword("ATMOSPHERICS_DEBUG");
if (enable)
{
/*
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");
}
*/
if (param.debugMode != ProceduralSkyParameters.ScatterDebugMode.None)
{
m_ProceduralSkyMaterial.EnableKeyword("ATMOSPHERICS_DEBUG");
}
}
}
void UpdateStaticUniforms(ProceduralSkyParameters param)
{
m_ProceduralSkyMaterial.SetTexture("_SkyDomeCubemap", param.skyDomeCubemap);
m_ProceduralSkyMaterial.SetFloat("_SkyDomeExposure", param.skyDomeExposure);
m_ProceduralSkyMaterial.SetColor("_SkyDomeTint", param.skyDomeTint);
/*
m_ProceduralSkyMaterial.SetFloat("_ShadowBias", useOcclusion ? occlusionBias : 1f);
m_ProceduralSkyMaterial.SetFloat("_ShadowBiasIndirect", useOcclusion ? occlusionBiasIndirect : 1f);
m_ProceduralSkyMaterial.SetFloat("_ShadowBiasClouds", useOcclusion ? occlusionBiasClouds : 1f);
m_ProceduralSkyMaterial.SetVector("_ShadowBiasSkyRayleighMie", useOcclusion ? new Vector4(occlusionBiasSkyRayleigh, occlusionBiasSkyMie, 0f, 0f) : Vector4.zero);
m_ProceduralSkyMaterial.SetFloat("_OcclusionDepthThreshold", occlusionDepthThreshold);
*/
m_ProceduralSkyMaterial.SetFloat("_WorldScaleExponent", param.worldScaleExponent);
m_ProceduralSkyMaterial.SetFloat("_WorldNormalDistanceRcp", 1f / param.worldNormalDistance);
m_ProceduralSkyMaterial.SetFloat("_WorldNearScatterPush", -Mathf.Pow(Mathf.Abs(param.worldNearScatterPush), param.worldScaleExponent) * Mathf.Sign(param.worldNearScatterPush));
m_ProceduralSkyMaterial.SetFloat("_WorldRayleighDensity", -param.worldRayleighDensity / 100000f);
m_ProceduralSkyMaterial.SetFloat("_MiePhaseAnisotropy", param.worldMiePhaseAnisotropy);
m_ProceduralSkyMaterial.SetVector("_RayleighInScatterPct", new Vector4(1f - param.worldRayleighIndirectScatter, param.worldRayleighIndirectScatter, 0f, 0f));
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.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);
m_ProceduralSkyMaterial.SetVector("_RayleighColorM20", (Vector4)rayleighColorM20 * param.worldRayleighColorIntensity);
m_ProceduralSkyMaterial.SetVector("_RayleighColorM10", (Vector4)rayleighColorM10 * param.worldRayleighColorIntensity);
m_ProceduralSkyMaterial.SetVector("_RayleighColorO00", (Vector4)rayleighColorO00 * param.worldRayleighColorIntensity);
m_ProceduralSkyMaterial.SetVector("_RayleighColorP10", (Vector4)rayleighColorP10 * param.worldRayleighColorIntensity);
m_ProceduralSkyMaterial.SetVector("_RayleighColorP20", (Vector4)rayleighColorP20 * param.worldRayleighColorIntensity);
m_ProceduralSkyMaterial.SetVector("_MieColorM20", (Vector4)mieColorM20 * param.worldMieColorIntensity);
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("_HeightMieDensity", -param.heightMieDensity / 100000f);
// TODO : We can't pass the camera in builtinParams because when SkyManager call RenderSky for rendering into a cubemap we don't have an actual Camera.
// Maybe pass the rect/viewport directly?
var pixelRect = Camera.current ? Camera.current.pixelRect
: new Rect(0f, 0f, Screen.width, Screen.height);
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.SetMatrix("_InvViewProjMatrix", builtinParams.invViewProjMatrix);
}
override public void RenderSky(BuiltinSkyParameters builtinParams, SkyParameters skyParameters)
{
ProceduralSkyParameters proceduralSkyParams = GetProceduralSkyParameters(skyParameters);
if (proceduralSkyParams == null)
{
return;
}
// 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;
}
// Set shader constants.
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));
var cmd = new CommandBuffer { name = "" };
cmd.DrawMesh(builtinParams.skyMesh, Matrix4x4.identity, m_ProceduralSkyMaterial);
builtinParams.renderLoop.ExecuteCommandBuffer(cmd);
cmd.Dispose();
}
}
}

12
Assets/ScriptableRenderLoop/HDRenderLoop/Sky/ProceduralSky/ProceduralSkyRenderer.cs.meta


fileFormatVersion: 2
guid: 476423447c1989948a128fc0a0b27413
timeCreated: 1481631774
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

9
Assets/ScriptableRenderLoop/HDRenderLoop/Sky/ProceduralSky/Resources.meta


fileFormatVersion: 2
guid: 455c6cbc5c8be404c8ed6ff8b38d1155
folderAsset: yes
timeCreated: 1481646141
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

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

/Assets/ScriptableRenderLoop/HDRenderLoop/Sky/Resources/AtmosphericScattering.hlsl.meta → /Assets/ScriptableRenderLoop/HDRenderLoop/Sky/ProceduralSky/Resources/AtmosphericScattering.hlsl.meta

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

/Assets/ScriptableRenderLoop/HDRenderLoop/Sky/Resources/SkyProcedural.shader.meta → /Assets/ScriptableRenderLoop/HDRenderLoop/Sky/ProceduralSky/Resources/SkyProcedural.shader.meta

正在加载...
取消
保存