升级6.4.升级水,升级天气
This commit is contained in:
@@ -7,24 +7,14 @@ using System.Reflection;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Rendering;
|
||||
using UnityEngine.Rendering.HighDefinition;
|
||||
using WaveHarmonic.Crest.Internal;
|
||||
|
||||
namespace WaveHarmonic.Crest
|
||||
{
|
||||
// High Definition Render Pipeline
|
||||
partial class WaterRenderer
|
||||
{
|
||||
internal static partial class ShaderIDs
|
||||
{
|
||||
// High Definition Render Pipeline
|
||||
public static readonly int s_PrimaryLightDirection = Shader.PropertyToID("g_Crest_PrimaryLightDirection");
|
||||
public static readonly int s_PrimaryLightIntensity = Shader.PropertyToID("g_Crest_PrimaryLightIntensity");
|
||||
}
|
||||
|
||||
internal static bool s_CameraMSAA;
|
||||
|
||||
bool _DoneHighDefinitionLighting;
|
||||
|
||||
void OnBeginContextRendering(ScriptableRenderContext context, System.Collections.Generic.List<Camera> cameras)
|
||||
{
|
||||
s_CameraMSAA = false;
|
||||
@@ -32,55 +22,30 @@ namespace WaveHarmonic.Crest
|
||||
|
||||
// This use to be in OnBeginContextRendering with comment: "Most compatible with
|
||||
// lighting options if computed here". Cannot remember what that meant.
|
||||
internal void UpdateHighDefinitionLighting(Camera camera)
|
||||
Color ApplyAtmosphericAttenuation(Camera camera, Light sun, Vector3 direction, Color intensity)
|
||||
{
|
||||
if (_DoneHighDefinitionLighting)
|
||||
if (sun.TryGetComponent<HDAdditionalLightData>(out var data))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var lightDirection = Vector3.zero;
|
||||
var lightIntensity = Color.black;
|
||||
var sun = PrimaryLight;
|
||||
|
||||
if (sun != null && sun.isActiveAndEnabled && sun.TryGetComponent<HDAdditionalLightData>(out var data))
|
||||
{
|
||||
lightDirection = -sun.transform.forward;
|
||||
lightIntensity = Color.clear;
|
||||
// We could get the main light in the shader the same way we get the main light
|
||||
// shadows, but most of the data would be missing (including below horizon
|
||||
// attenuation) which would require re-running the light loop which is expensive.
|
||||
|
||||
// It was reported that Light.intensity causes flickering when updated with
|
||||
// HDAdditionalLightData.SetIntensity, unless we get intensity from there.
|
||||
{
|
||||
// Adapted from Helpers.FinalColor.
|
||||
var light = data;
|
||||
var linear = GraphicsSettings.lightsUseLinearIntensity;
|
||||
var color = linear ? light.color.linear : light.color;
|
||||
#if UNITY_6000_0_OR_NEWER
|
||||
color *= sun.intensity;
|
||||
#else
|
||||
color *= light.intensity;
|
||||
#endif
|
||||
if (linear && light.useColorTemperature) color *= Mathf.CorrelatedColorTemperatureToRGB(sun.colorTemperature);
|
||||
if (!linear) color = color.MaybeLinear();
|
||||
lightIntensity = linear ? color.MaybeGamma() : color;
|
||||
}
|
||||
|
||||
// Transmittance is for Physically Based Sky.
|
||||
var hdCamera = HDCamera.GetOrCreate(camera);
|
||||
var settings = SkyManager.GetSkySetting(hdCamera.volumeStack);
|
||||
var transmittance = settings != null
|
||||
? settings.EvaluateAtmosphericAttenuation(lightDirection, hdCamera.camera.transform.position)
|
||||
? settings.EvaluateAtmosphericAttenuation(direction, hdCamera.camera.transform.position)
|
||||
: Vector3.one;
|
||||
|
||||
lightIntensity *= transmittance.x;
|
||||
lightIntensity *= transmittance.y;
|
||||
lightIntensity *= transmittance.z;
|
||||
intensity *= transmittance.x;
|
||||
intensity *= transmittance.y;
|
||||
intensity *= transmittance.z;
|
||||
}
|
||||
|
||||
Shader.SetGlobalVector(ShaderIDs.s_PrimaryLightDirection, lightDirection);
|
||||
Shader.SetGlobalVector(ShaderIDs.s_PrimaryLightIntensity, lightIntensity);
|
||||
|
||||
_DoneHighDefinitionLighting = true;
|
||||
return intensity;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -153,7 +118,8 @@ namespace WaveHarmonic.Crest
|
||||
{
|
||||
if (this == null) return;
|
||||
|
||||
if (!WaterRenderer.ShouldRender(camera, _Water.Surface.Layer))
|
||||
// Currently, only do this for the surface.
|
||||
if (!_Water._ActiveModules.HasFlag(WaterRenderer.ActiveModules.Surface))
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -164,7 +130,7 @@ namespace WaveHarmonic.Crest
|
||||
return;
|
||||
}
|
||||
|
||||
var rt = Shader.GetGlobalTexture(Shader.PropertyToID("_CameraDepthTexture")) as RenderTexture;
|
||||
var rt = Shader.GetGlobalTexture(ShaderIDs.Unity.s_CameraDepthTexture) as RenderTexture;
|
||||
var hdCamera = HDCamera.GetOrCreate(camera);
|
||||
|
||||
if (hdCamera.allowDynamicResolution && hdCamera.canDoDynamicResolution)
|
||||
@@ -213,12 +179,8 @@ namespace WaveHarmonic.Crest
|
||||
var camera = hdCamera.camera;
|
||||
var buffer = context.cmd;
|
||||
|
||||
if (!WaterRenderer.ShouldRender(camera, _Water.Surface.Layer))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (_Water.Surface.Material == null)
|
||||
// Currently, only do this for the surface.
|
||||
if (!_Water._ActiveModules.HasFlag(WaterRenderer.ActiveModules.Surface))
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -228,12 +190,6 @@ namespace WaveHarmonic.Crest
|
||||
return;
|
||||
}
|
||||
|
||||
// Our reflections do not need them.
|
||||
if (camera == WaterReflections.CurrentCamera)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (context.hdCamera.msaaEnabled)
|
||||
{
|
||||
WaterRenderer.s_CameraMSAA = true;
|
||||
|
||||
Reference in New Issue
Block a user