升级水插件
This commit is contained in:
@@ -20,10 +20,12 @@ Shader "Crest/Inputs/Absorption/Color"
|
||||
|
||||
SubShader
|
||||
{
|
||||
ZTest Always
|
||||
ZWrite Off
|
||||
|
||||
Pass
|
||||
{
|
||||
Blend SrcAlpha OneMinusSrcAlpha
|
||||
ZWrite Off
|
||||
ColorMask RGB
|
||||
|
||||
CGPROGRAM
|
||||
|
||||
@@ -19,12 +19,13 @@ Shader "Crest/Inputs/Albedo/Color"
|
||||
}
|
||||
SubShader
|
||||
{
|
||||
ZTest Always
|
||||
ZWrite Off
|
||||
|
||||
Pass
|
||||
{
|
||||
Blend [_Crest_BlendModeSource] [_Crest_BlendModeTarget]
|
||||
|
||||
ZWrite Off
|
||||
|
||||
CGPROGRAM
|
||||
#pragma vertex Vertex
|
||||
#pragma fragment Fragment
|
||||
|
||||
@@ -18,6 +18,8 @@ Shader "Crest/Inputs/Animated Waves/Add From Texture"
|
||||
SubShader
|
||||
{
|
||||
Blend One One
|
||||
ZTest Always
|
||||
ZWrite Off
|
||||
|
||||
Pass
|
||||
{
|
||||
@@ -25,7 +27,7 @@ Shader "Crest/Inputs/Animated Waves/Add From Texture"
|
||||
#pragma vertex Vert
|
||||
#pragma fragment Frag
|
||||
|
||||
#pragma shader_feature_local d_HeightsOnly
|
||||
#pragma shader_feature_local_fragment d_HeightsOnly
|
||||
|
||||
#include "UnityCG.cginc"
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Crest Water System
|
||||
// Crest Water System
|
||||
// Copyright © 2024 Wave Harmonic. All rights reserved.
|
||||
|
||||
// Push water under the geometry. Needs to be rendered into all LODs - set Octave Wave length to 0.
|
||||
@@ -13,6 +13,9 @@ Shader "Crest/Inputs/Animated Waves/Push Water Under Convex Hull"
|
||||
|
||||
SubShader
|
||||
{
|
||||
ZTest Always
|
||||
ZWrite Off
|
||||
|
||||
Pass
|
||||
{
|
||||
BlendOp Min
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Crest Water System
|
||||
// Crest Water System
|
||||
// Copyright © 2024 Wave Harmonic. All rights reserved.
|
||||
|
||||
// This writes straight into the displacement texture and sets the water height to the y value of the geometry.
|
||||
@@ -16,6 +16,9 @@ Shader "Crest/Inputs/Animated Waves/Set Water Height Using Geometry"
|
||||
|
||||
SubShader
|
||||
{
|
||||
ZTest Always
|
||||
ZWrite Off
|
||||
|
||||
Pass
|
||||
{
|
||||
Blend Off
|
||||
|
||||
@@ -16,6 +16,9 @@ Shader "Crest/Inputs/Animated Waves/Wave Particle"
|
||||
{
|
||||
Tags { "DisableBatching" = "True" }
|
||||
|
||||
ZTest Always
|
||||
ZWrite Off
|
||||
|
||||
Pass
|
||||
{
|
||||
Blend One One
|
||||
|
||||
@@ -14,6 +14,9 @@ Shader "Crest/Inputs/Dynamic Waves/Add Bump"
|
||||
|
||||
SubShader
|
||||
{
|
||||
ZTest Always
|
||||
ZWrite Off
|
||||
|
||||
Pass
|
||||
{
|
||||
Blend One One
|
||||
|
||||
@@ -14,6 +14,9 @@ Shader "Crest/Inputs/Dynamic Waves/Dampen Circle"
|
||||
|
||||
SubShader
|
||||
{
|
||||
ZTest Always
|
||||
ZWrite Off
|
||||
|
||||
Pass
|
||||
{
|
||||
Blend SrcAlpha OneMinusSrcAlpha
|
||||
|
||||
@@ -26,6 +26,8 @@ Shader "Crest/Inputs/Flow/Add From Texture"
|
||||
SubShader
|
||||
{
|
||||
Blend One One
|
||||
ZTest Always
|
||||
ZWrite Off
|
||||
|
||||
Pass
|
||||
{
|
||||
@@ -33,10 +35,10 @@ Shader "Crest/Inputs/Flow/Add From Texture"
|
||||
#pragma vertex Vert
|
||||
#pragma fragment Frag
|
||||
|
||||
#pragma shader_feature_local d_FlipX
|
||||
#pragma shader_feature_local d_FlipZ
|
||||
#pragma shader_feature_local d_Feather
|
||||
#pragma shader_feature_local d_NegativeValues
|
||||
#pragma shader_feature_local_fragment d_FlipX
|
||||
#pragma shader_feature_local_fragment d_FlipZ
|
||||
#pragma shader_feature_local_fragment d_Feather
|
||||
#pragma shader_feature_local_fragment d_NegativeValues
|
||||
|
||||
#include "UnityCG.cginc"
|
||||
|
||||
|
||||
@@ -21,6 +21,9 @@ Shader "Crest/Inputs/Flow/Fixed Direction"
|
||||
|
||||
SubShader
|
||||
{
|
||||
ZTest Always
|
||||
ZWrite Off
|
||||
|
||||
Pass
|
||||
{
|
||||
CGPROGRAM
|
||||
@@ -28,7 +31,7 @@ Shader "Crest/Inputs/Flow/Fixed Direction"
|
||||
#pragma fragment Frag
|
||||
|
||||
#pragma shader_feature_local d_Feather
|
||||
#pragma shader_feature_local d_ApplyRotation
|
||||
#pragma shader_feature_local_fragment d_ApplyRotation
|
||||
|
||||
#include "UnityCG.cginc"
|
||||
|
||||
|
||||
@@ -15,6 +15,8 @@ Shader "Crest/Inputs/Foam/Add From Texture"
|
||||
SubShader
|
||||
{
|
||||
Blend One One
|
||||
ZTest Always
|
||||
ZWrite Off
|
||||
|
||||
Pass
|
||||
{
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Crest Water System
|
||||
// Crest Water System
|
||||
// Copyright © 2024 Wave Harmonic. All rights reserved.
|
||||
|
||||
Shader "Crest/Inputs/Foam/Add From Vertex Colors"
|
||||
@@ -14,6 +14,8 @@ Shader "Crest/Inputs/Foam/Add From Vertex Colors"
|
||||
SubShader
|
||||
{
|
||||
Blend One One
|
||||
ZTest Always
|
||||
ZWrite Off
|
||||
|
||||
Pass
|
||||
{
|
||||
|
||||
@@ -18,6 +18,7 @@ RWTexture2DArray<float3> _Crest_Target;
|
||||
CBUFFER_START(CrestPerMaterial)
|
||||
int _Crest_Blend;
|
||||
float _Crest_Weight;
|
||||
float4 _Crest_Multiplier;
|
||||
float2 _Crest_TextureSize;
|
||||
float2 _Crest_TexturePosition;
|
||||
float2 _Crest_TextureRotation;
|
||||
@@ -42,7 +43,7 @@ void Execute(uint3 id)
|
||||
return;
|
||||
}
|
||||
|
||||
const half4 source = _Crest_Texture.SampleLevel(LODData_linear_clamp_sampler, uv, 0);
|
||||
const half4 source = _Crest_Texture.SampleLevel(LODData_linear_clamp_sampler, uv, 0) * _Crest_Multiplier;
|
||||
const half3 target = _Crest_Target[id];
|
||||
weight *= source.a;
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Crest Water System
|
||||
// Crest Water System
|
||||
// Copyright © 2024 Wave Harmonic. All rights reserved.
|
||||
|
||||
// Renders convex hull to the clip surface texture.
|
||||
@@ -70,8 +70,9 @@ Shader "Hidden/Crest/Inputs/Clip/Convex Hull"
|
||||
|
||||
SubShader
|
||||
{
|
||||
ZWrite Off
|
||||
ColorMask R
|
||||
ZTest Always
|
||||
ZWrite Off
|
||||
|
||||
Pass
|
||||
{
|
||||
|
||||
@@ -18,6 +18,7 @@ Texture2D _Crest_Texture;
|
||||
RWTexture2DArray<float> _Crest_Target;
|
||||
|
||||
CBUFFER_START(CrestPerMaterial)
|
||||
float _Crest_Multiplier;
|
||||
float2 _Crest_TextureSize;
|
||||
float2 _Crest_TexturePosition;
|
||||
float2 _Crest_TextureRotation;
|
||||
@@ -36,7 +37,7 @@ void Execute(uint3 id)
|
||||
return;
|
||||
}
|
||||
|
||||
const float result = _Crest_Texture.SampleLevel(LODData_linear_clamp_sampler, uv, 0).x;
|
||||
const float result = _Crest_Texture.SampleLevel(LODData_linear_clamp_sampler, uv, 0).x * _Crest_Multiplier;
|
||||
|
||||
// Painted clip defines a minimum value of the clip.
|
||||
_Crest_Target[id] = max(_Crest_Target[id], result);
|
||||
|
||||
@@ -29,6 +29,7 @@ Texture2D<m_CrestType> _Crest_Texture;
|
||||
RWTexture2DArray<m_CrestType> _Crest_Target;
|
||||
|
||||
CBUFFER_START(CrestInputTexture)
|
||||
float2 _Crest_Multiplier;
|
||||
float2 _Crest_TextureSize;
|
||||
float2 _Crest_TexturePosition;
|
||||
float2 _Crest_TextureRotation;
|
||||
@@ -50,7 +51,7 @@ void Execute(uint3 id)
|
||||
}
|
||||
|
||||
m_CrestType current = _Crest_Target[id];
|
||||
m_CrestType result = _Crest_Texture.SampleLevel(LODData_linear_clamp_sampler, uv, 0);
|
||||
m_CrestType result = _Crest_Texture.SampleLevel(LODData_linear_clamp_sampler, uv, 0) * _Crest_Multiplier;
|
||||
result.x += _Crest_HeightOffset;
|
||||
|
||||
// Take highest terrain height.
|
||||
|
||||
@@ -20,6 +20,7 @@ RWTexture2DArray<float2> _Crest_Target;
|
||||
CBUFFER_START(CrestPerMaterial)
|
||||
int _Crest_Blend;
|
||||
float _Crest_Weight;
|
||||
float2 _Crest_Multiplier;
|
||||
float2 _Crest_TextureSize;
|
||||
float2 _Crest_TexturePosition;
|
||||
float2 _Crest_TextureRotation;
|
||||
@@ -53,6 +54,8 @@ void Execute(uint3 id)
|
||||
source = source * 2.0 - 1.0;
|
||||
}
|
||||
|
||||
source *= _Crest_Multiplier;
|
||||
|
||||
if (_Crest_Blend == m_CrestBlendAlpha)
|
||||
{
|
||||
weight *= saturate(length(source));
|
||||
|
||||
@@ -20,6 +20,7 @@ RWTexture2DArray<float> _Crest_Target;
|
||||
CBUFFER_START(CrestPerMaterial)
|
||||
int _Crest_Blend;
|
||||
float _Crest_Weight;
|
||||
float _Crest_Multiplier;
|
||||
float2 _Crest_TextureSize;
|
||||
float2 _Crest_TexturePosition;
|
||||
float2 _Crest_TextureRotation;
|
||||
@@ -45,7 +46,7 @@ void Execute(uint3 id)
|
||||
return;
|
||||
}
|
||||
|
||||
const float source = _Crest_Texture.SampleLevel(LODData_linear_clamp_sampler, uv, 0).x;
|
||||
const float source = _Crest_Texture.SampleLevel(LODData_linear_clamp_sampler, uv, 0).x * _Crest_Multiplier;
|
||||
const float target = _Crest_Target[id];
|
||||
|
||||
_Crest_Target[id] = Blend(_Crest_Blend, weight, _Crest_SimDeltaTime, source, target);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Crest Water System
|
||||
// Crest Water System
|
||||
// Copyright © 2024 Wave Harmonic. All rights reserved.
|
||||
|
||||
// An implementation of the Jump Flood algorithm by Rong and Tan
|
||||
|
||||
@@ -23,6 +23,7 @@ RWTexture2DArray<float> _Crest_Target;
|
||||
CBUFFER_START(CrestPerMaterial)
|
||||
int _Crest_Blend;
|
||||
float _Crest_Weight;
|
||||
float _Crest_Multiplier;
|
||||
float2 _Crest_TextureSize;
|
||||
float2 _Crest_TexturePosition;
|
||||
float2 _Crest_TextureRotation;
|
||||
@@ -48,10 +49,11 @@ void Execute(uint3 id)
|
||||
}
|
||||
|
||||
#if d_CatmullRom
|
||||
const float source = Utility::SampleTextureCatmullRom(_Crest_Texture, LODData_linear_clamp_sampler, uv, _Crest_Resolution).x;
|
||||
const float source = Utility::SampleTextureCatmullRom(_Crest_Texture, LODData_linear_clamp_sampler, uv, _Crest_Resolution)
|
||||
#else
|
||||
const float source = _Crest_Texture.SampleLevel(LODData_linear_clamp_sampler, uv, 0.0).x;
|
||||
const float source = _Crest_Texture.SampleLevel(LODData_linear_clamp_sampler, uv, 0.0)
|
||||
#endif
|
||||
.x * _Crest_Multiplier;
|
||||
|
||||
const float target = _Crest_Target[id];
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@ RWTexture2DArray<float3> _Crest_Target;
|
||||
CBUFFER_START(CrestPerMaterial)
|
||||
int _Crest_Blend;
|
||||
float _Crest_Weight;
|
||||
float4 _Crest_Multiplier;
|
||||
float2 _Crest_TextureSize;
|
||||
float2 _Crest_TexturePosition;
|
||||
float2 _Crest_TextureRotation;
|
||||
@@ -42,7 +43,7 @@ void Execute(uint3 id)
|
||||
return;
|
||||
}
|
||||
|
||||
const half4 source = _Crest_Texture.SampleLevel(LODData_linear_clamp_sampler, uv, 0);
|
||||
const half4 source = _Crest_Texture.SampleLevel(LODData_linear_clamp_sampler, uv, 0) * _Crest_Multiplier;
|
||||
const half3 target = _Crest_Target[id];
|
||||
weight *= source.a;
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Crest Water System
|
||||
// Crest Water System
|
||||
// Copyright © 2024 Wave Harmonic. All rights reserved.
|
||||
|
||||
Shader "Crest/Inputs/All/Override"
|
||||
@@ -15,11 +15,13 @@ Shader "Crest/Inputs/All/Override"
|
||||
|
||||
SubShader
|
||||
{
|
||||
ZTest Always
|
||||
ZWrite Off
|
||||
|
||||
Pass
|
||||
{
|
||||
Blend Off
|
||||
ColorMask [_Crest_ColorMask]
|
||||
ZWrite Off
|
||||
|
||||
CGPROGRAM
|
||||
#pragma vertex Vertex
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Crest Water System
|
||||
// Crest Water System
|
||||
// Copyright © 2024 Wave Harmonic. All rights reserved.
|
||||
|
||||
// 0-1 scaling of existing water data using multiplicative blending.
|
||||
@@ -32,6 +32,9 @@ Shader "Crest/Inputs/All/Scale"
|
||||
|
||||
SubShader
|
||||
{
|
||||
ZTest Always
|
||||
ZWrite Off
|
||||
|
||||
Pass
|
||||
{
|
||||
// Multiply
|
||||
@@ -42,8 +45,8 @@ Shader "Crest/Inputs/All/Scale"
|
||||
#pragma fragment Frag
|
||||
|
||||
#pragma shader_feature_local d_Texture
|
||||
#pragma shader_feature_local d_Invert
|
||||
#pragma shader_feature_local d_Feather
|
||||
#pragma shader_feature_local_fragment d_Invert
|
||||
|
||||
#include "UnityCG.cginc"
|
||||
|
||||
|
||||
@@ -17,10 +17,12 @@ Shader "Crest/Inputs/Scattering/Color"
|
||||
|
||||
SubShader
|
||||
{
|
||||
ZTest Always
|
||||
ZWrite Off
|
||||
|
||||
Pass
|
||||
{
|
||||
Blend SrcAlpha OneMinusSrcAlpha
|
||||
ZWrite Off
|
||||
ColorMask RGB
|
||||
|
||||
CGPROGRAM
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Crest Water System
|
||||
// Crest Water System
|
||||
// Copyright © 2024 Wave Harmonic. All rights reserved.
|
||||
|
||||
// Generates waves from geometry that is rendered into the water simulation from a top down camera. Expects
|
||||
@@ -39,7 +39,7 @@ Shader "Crest/Inputs/Shape Waves/Add From Geometry"
|
||||
#pragma fragment Fragment
|
||||
// #pragma enable_d3d11_debug_symbols
|
||||
|
||||
#pragma shader_feature_local d_Feather
|
||||
#pragma shader_feature_local_fragment d_Feather
|
||||
|
||||
#include "UnityCG.cginc"
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Crest Water System
|
||||
// Crest Water System
|
||||
// Copyright © 2024 Wave Harmonic. All rights reserved.
|
||||
|
||||
Shader "Crest/Inputs/All/Utility"
|
||||
@@ -17,12 +17,14 @@ Shader "Crest/Inputs/All/Utility"
|
||||
|
||||
SubShader
|
||||
{
|
||||
ZTest Always
|
||||
ZWrite Off
|
||||
|
||||
Pass
|
||||
{
|
||||
Blend [_Crest_BlendModeSource] [_Crest_BlendModeTarget]
|
||||
BlendOp [_Crest_BlendOperation]
|
||||
ColorMask [_Crest_ColorMask]
|
||||
ZWrite Off
|
||||
|
||||
CGPROGRAM
|
||||
#pragma vertex Vertex
|
||||
|
||||
@@ -12,6 +12,9 @@ Shader "Crest/Inputs/Depth/Water Depth From Geometry"
|
||||
|
||||
SubShader
|
||||
{
|
||||
ZTest Always
|
||||
ZWrite Off
|
||||
|
||||
Pass
|
||||
{
|
||||
BlendOp Max
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Crest Water System
|
||||
// Crest Water System
|
||||
// Copyright © 2024 Wave Harmonic. All rights reserved.
|
||||
|
||||
// This sets base water height to Y value of geometry.
|
||||
@@ -17,6 +17,9 @@ Shader "Crest/Inputs/Level/Water Level From Geometry"
|
||||
|
||||
SubShader
|
||||
{
|
||||
ZTest Always
|
||||
ZWrite Off
|
||||
|
||||
Pass
|
||||
{
|
||||
Blend [_Crest_BlendSource] [_Crest_BlendTarget]
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Crest Water System
|
||||
// Crest Water System
|
||||
// Copyright © 2024 Wave Harmonic. All rights reserved.
|
||||
|
||||
#pragma kernel CrestPackLevel
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Crest Water System
|
||||
// Crest Water System
|
||||
// Copyright © 2024 Wave Harmonic. All rights reserved.
|
||||
|
||||
#pragma kernel CrestQueryDisplacement d_CrestDisplacement
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Crest Water System
|
||||
// Crest Water System
|
||||
// Copyright © 2024 Wave Harmonic. All rights reserved.
|
||||
|
||||
// Merged into Query.compute.
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Crest Water System
|
||||
// Crest Water System
|
||||
// Copyright © 2024 Wave Harmonic. All rights reserved.
|
||||
|
||||
// Merged into Query.compute.
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Crest Water System
|
||||
// Crest Water System
|
||||
// Copyright © 2024 Wave Harmonic. All rights reserved.
|
||||
|
||||
// Compute shader to perform combine of displacements. Reads and writes to texture array which saves
|
||||
@@ -14,6 +14,7 @@
|
||||
#pragma kernel ShapeCombine_FLOW_ON_DYNAMIC_WAVE_SIM_ON _FLOW_ON _DYNAMIC_WAVE_SIM_ON
|
||||
#pragma kernel ShapeCombine_FLOW_ON_DYNAMIC_WAVE_SIM_ON_DISABLE_COMBINE _FLOW_ON _DYNAMIC_WAVE_SIM_ON _DISABLE_COMBINE
|
||||
#pragma kernel ShapeCombineDynamicWaves
|
||||
#pragma kernel ShapeCombineDynamicWaves_DISABLE_COMBINE _DISABLE_COMBINE
|
||||
#pragma kernel ShapeCombineCopyDynamicWaves
|
||||
|
||||
#include "HLSLSupport.cginc"
|
||||
@@ -107,6 +108,7 @@ void ShapeCombineBase(uint3 id)
|
||||
#endif // _FLOW_ON
|
||||
}
|
||||
|
||||
// Disabled for last LOD.
|
||||
#if !_DISABLE_COMBINE
|
||||
{
|
||||
const Cascade cascade = Cascade::MakeAnimatedWaves(slice0 + 1);
|
||||
@@ -136,14 +138,19 @@ void ShapeCombineDynamicWaves(uint3 id)
|
||||
const float2 positionWSXZ = cascade.UVToWorld(uv);
|
||||
float3 result = 0.0;
|
||||
|
||||
// Disabled for last LOD.
|
||||
#if !_DISABLE_COMBINE
|
||||
{
|
||||
const Cascade cascade = Cascade::MakeDynamicWaves(slice0 + 1);
|
||||
// We are sampling from the target which matches Animated Waves descriptor.
|
||||
const Cascade cascade = Cascade::MakeAnimatedWaves(slice0 + 1);
|
||||
const float3 uv = cascade.WorldToUV(positionWSXZ);
|
||||
// Waves to combine down from the next lod up the chain.
|
||||
SampleDisplacementsCompute(_Crest_DynamicWavesTarget, cascade._Resolution, uv, 1.0, result);
|
||||
}
|
||||
#endif
|
||||
|
||||
{
|
||||
// We are sampling from Dynamic Waves.
|
||||
const Cascade cascade = Cascade::MakeDynamicWaves(slice0);
|
||||
const float3 uv = cascade.WorldToUV(positionWSXZ);
|
||||
result += cascade.SampleDynamicWavesDisplacement(uv, _Crest_HorizontalDisplace, _Crest_DisplaceClamp);
|
||||
@@ -168,4 +175,5 @@ m_CrestNameSpaceEnd
|
||||
[numthreads(THREAD_GROUP_SIZE_X, THREAD_GROUP_SIZE_Y, 1)] void ShapeCombine_FLOW_ON_DYNAMIC_WAVE_SIM_ON(uint3 id : SV_DispatchThreadID) { m_Crest::ShapeCombineBase(id); }
|
||||
[numthreads(THREAD_GROUP_SIZE_X, THREAD_GROUP_SIZE_Y, 1)] void ShapeCombine_FLOW_ON_DYNAMIC_WAVE_SIM_ON_DISABLE_COMBINE(uint3 id : SV_DispatchThreadID) { m_Crest::ShapeCombineBase(id); }
|
||||
[numthreads(THREAD_GROUP_SIZE_X, THREAD_GROUP_SIZE_Y, 1)] void ShapeCombineDynamicWaves(uint3 id : SV_DispatchThreadID) { m_Crest::ShapeCombineDynamicWaves(id); }
|
||||
[numthreads(THREAD_GROUP_SIZE_X, THREAD_GROUP_SIZE_Y, 1)] void ShapeCombineDynamicWaves_DISABLE_COMBINE(uint3 id : SV_DispatchThreadID) { m_Crest::ShapeCombineDynamicWaves(id); }
|
||||
[numthreads(THREAD_GROUP_SIZE_X, THREAD_GROUP_SIZE_Y, 1)] void ShapeCombineCopyDynamicWaves(uint3 id : SV_DispatchThreadID) { m_Crest::ShapeCombineCopyDynamicWaves(id); }
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Crest Water System
|
||||
// Crest Water System
|
||||
// Copyright © 2024 Wave Harmonic. All rights reserved.
|
||||
|
||||
#pragma kernel CrestShorelineColor
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Crest Water System
|
||||
// Crest Water System
|
||||
// Copyright © 2024 Wave Harmonic. All rights reserved.
|
||||
|
||||
// Solves 2D wave equation
|
||||
@@ -40,10 +40,11 @@ void UpdateDynamicWaves(uint3 id)
|
||||
const float sliceIndexSource = id.z + _Crest_LodChange;
|
||||
const Cascade cascadeSource = Cascade::MakeDynamicWavesSource(sliceIndexSource);
|
||||
|
||||
// Off either end of the cascade - not useful to sample anything from previous frame. Always initialise
|
||||
// with 0 values.
|
||||
if (sliceIndexSource < 0.0 || sliceIndexSource >= cascadeSource._Count - 1.0)
|
||||
// Off either end of the cascade. Not useful to sample anything from previous
|
||||
// frame, as we do not produce any new data from sources of waves.
|
||||
if (sliceIndexSource < 0.0 || sliceIndexSource >= cascadeSource._Count)
|
||||
{
|
||||
// Always initialise with 0 values.
|
||||
_Crest_Target[id] = (float2)0;
|
||||
return;
|
||||
}
|
||||
@@ -91,21 +92,14 @@ void UpdateDynamicWaves(uint3 id)
|
||||
const float3 X = float3(1.0, 0.0, 0.0);
|
||||
const float3 Y = float3(-X.y, X.x, 0.0);
|
||||
|
||||
// no border wrap mode for RTs in unity it seems,
|
||||
// so make any off-array reads 0 manually
|
||||
const bool insideTarget = sliceIndexSource <= cascadeSource._Count && sliceIndexSource >= 0;
|
||||
|
||||
float fxm, fym, fxp, fyp; float2 ft_v;
|
||||
ft_v = fxm = fym = fxp = fyp = 0.0;
|
||||
|
||||
if (insideTarget)
|
||||
{
|
||||
fxm = cascadeSource.SampleDynamicWaves(uv_source - e * X).x; // x minus
|
||||
fym = cascadeSource.SampleDynamicWaves(uv_source - e * Y).x; // y minus
|
||||
fxp = cascadeSource.SampleDynamicWaves(uv_source + e * X).x; // x plus
|
||||
fyp = cascadeSource.SampleDynamicWaves(uv_source + e * Y).x; // y plus
|
||||
ft_v = cascadeSource.SampleDynamicWaves(uv_source);
|
||||
}
|
||||
fxm = cascadeSource.SampleDynamicWaves(uv_source - e * X).x; // x minus
|
||||
fym = cascadeSource.SampleDynamicWaves(uv_source - e * Y).x; // y minus
|
||||
fxp = cascadeSource.SampleDynamicWaves(uv_source + e * X).x; // x plus
|
||||
fyp = cascadeSource.SampleDynamicWaves(uv_source + e * Y).x; // y plus
|
||||
ft_v = cascadeSource.SampleDynamicWaves(uv_source);
|
||||
|
||||
// wave propagation
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Crest Water System
|
||||
// Crest Water System
|
||||
// Copyright © 2024 Wave Harmonic. All rights reserved.
|
||||
|
||||
#pragma kernel CrestUpdateFoam
|
||||
|
||||
@@ -0,0 +1,154 @@
|
||||
// Crest Water System
|
||||
// Copyright © 2024 Wave Harmonic. All rights reserved.
|
||||
|
||||
// Soft shadow term is red, hard shadow term is green.
|
||||
|
||||
#pragma kernel CrestUpdateShadowsBRP _BRP
|
||||
#pragma kernel CrestUpdateShadowsHRP _HRP
|
||||
#pragma kernel CrestUpdateShadowsURP _URP
|
||||
|
||||
// Both BIRP.
|
||||
#pragma multi_compile __ SHADOWS_SPLIT_SPHERES
|
||||
#pragma multi_compile __ SHADOWS_SINGLE_CASCADE
|
||||
|
||||
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Library/Utility/RP/Compute.hlsl"
|
||||
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Library/Utility/RP/Shadows.hlsl"
|
||||
|
||||
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Library/Macros.hlsl"
|
||||
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Library/Constants.hlsl"
|
||||
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Library/Globals.hlsl"
|
||||
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Library/InputsDriven.hlsl"
|
||||
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Library/Cascade.hlsl"
|
||||
|
||||
// Noise functions used for jitter.
|
||||
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Library/Utility/Noise/Noise.hlsl"
|
||||
|
||||
|
||||
// JitterDiameterSoft, JitterDiameterHard, CurrentFrameWeightSoft, CurrentFrameWeightHard
|
||||
float4 _Crest_JitterDiameters_CurrentFrameWeights;
|
||||
float _Crest_SimDeltaTime;
|
||||
float4x4 _Crest_MainCameraProjectionMatrix;
|
||||
|
||||
bool _Crest_SampleColorMap;
|
||||
float3 _Crest_Absorption;
|
||||
float3 _Crest_Scattering;
|
||||
|
||||
RWTexture2DArray<float2> _Crest_Target;
|
||||
|
||||
|
||||
m_CrestNameSpace
|
||||
|
||||
half ComputeShadow(const float4 i_positionWS, const float i_jitterDiameter, const half i_terrainHeight, const uint i_LodIndex)
|
||||
{
|
||||
float4 positionWS = i_positionWS;
|
||||
bool noShadows = false;
|
||||
|
||||
if (i_jitterDiameter > 0.0)
|
||||
{
|
||||
// Add jitter.
|
||||
positionWS.xz += i_jitterDiameter * (hash33(uint3(abs(positionWS.xz * 10.0), _Time.y * 120.0)) - 0.5).xy;
|
||||
|
||||
// Shadow Bleeding.
|
||||
// If we are not within a terrain, then check for shadow bleeding.
|
||||
if (i_positionWS.y > i_terrainHeight)
|
||||
{
|
||||
// WorldToSafeUV
|
||||
half terrainHeight = Cascade::MakeDepth(i_LodIndex).SampleSceneHeight(positionWS.xz);
|
||||
|
||||
// If our current position is below the jittered terrain height, then we have landed within a terrain and
|
||||
// we do not want to sample those shadows.
|
||||
if (i_positionWS.y < terrainHeight)
|
||||
{
|
||||
// Return no shadows.
|
||||
noShadows = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return noShadows ? 1.0 : Utility::SampleShadows(positionWS);
|
||||
}
|
||||
|
||||
void UpdateShadows(const uint3 id)
|
||||
{
|
||||
const uint slice0 = id.z;
|
||||
const Cascade cascade = Cascade::MakeShadow(slice0);
|
||||
const float2 worldPosXZ = cascade.IDToWorld(id.xy);
|
||||
|
||||
float4 positionWS = 1.0;
|
||||
positionWS.xz = worldPosXZ;
|
||||
positionWS.y = g_Crest_WaterCenter.y;
|
||||
|
||||
// Shadow from last frame. Manually implement black border.
|
||||
const float sliceIndexSource = clamp((int)slice0 + g_Crest_LodChange, 0.0, g_Crest_LodCount - 1.0);
|
||||
half2 shadow = Cascade::MakeShadowSource(sliceIndexSource).SampleShadowOverflow(positionWS.xz, 1.0);
|
||||
|
||||
// Add displacement so shorelines do not receive shadows incorrectly.
|
||||
positionWS.xyz += Cascade::MakeAnimatedWaves(slice0).SampleDisplacement(positionWS.xz);
|
||||
|
||||
// This was calculated in vertex but we have to sample sea level offset in fragment.
|
||||
float4 mainCameraCoordinates = mul(_Crest_MainCameraProjectionMatrix, positionWS);
|
||||
|
||||
// Check if the current sample is visible in the main camera (and therefore the shadow map can be sampled). This is
|
||||
// required as the shadow buffer is world aligned and surrounds viewer.
|
||||
float3 projected = mainCameraCoordinates.xyz / mainCameraCoordinates.w;
|
||||
if (projected.z < 1.0 && projected.z > 0.0 && abs(projected.x) < 1.0 && abs(projected.y) < 1.0)
|
||||
{
|
||||
half2 shadowThisFrame = 1.0;
|
||||
|
||||
#if (SHADEROPTIONS_CAMERA_RELATIVE_RENDERING != 0)
|
||||
positionWS.xyz -= _WorldSpaceCameraPos.xyz;
|
||||
#endif
|
||||
|
||||
half terrainHeight = Cascade::MakeDepth(slice0).SampleSceneHeight(positionWS.xz);
|
||||
|
||||
half softJitter = _Crest_JitterDiameters_CurrentFrameWeights[CREST_SHADOW_INDEX_SOFT];
|
||||
|
||||
if (_Crest_SampleColorMap)
|
||||
{
|
||||
half3 absorption = _Crest_Absorption;
|
||||
half3 scattering = _Crest_Scattering;
|
||||
|
||||
if (g_Crest_SampleAbsorptionSimulation)
|
||||
{
|
||||
absorption = Cascade::MakeAbsorption(slice0).SampleAbsorption(positionWS.xz);
|
||||
}
|
||||
|
||||
if (g_Crest_SampleScatteringSimulation)
|
||||
{
|
||||
scattering = Cascade::MakeScattering(slice0).SampleScattering(positionWS.xz);
|
||||
}
|
||||
|
||||
half3 extinction = absorption + scattering;
|
||||
half factor = saturate(min(min(extinction.x, extinction.y), extinction.z) * g_Crest_DynamicSoftShadowsFactor);
|
||||
softJitter = (1.0 - factor) * k_Crest_MaximumShadowJitter;
|
||||
}
|
||||
|
||||
// Add soft shadowing data.
|
||||
shadowThisFrame[CREST_SHADOW_INDEX_SOFT] = ComputeShadow
|
||||
(
|
||||
positionWS,
|
||||
softJitter,
|
||||
terrainHeight,
|
||||
slice0
|
||||
);
|
||||
|
||||
// Add hard shadowing data.
|
||||
shadowThisFrame[CREST_SHADOW_INDEX_HARD] = ComputeShadow
|
||||
(
|
||||
positionWS,
|
||||
_Crest_JitterDiameters_CurrentFrameWeights[CREST_SHADOW_INDEX_HARD],
|
||||
terrainHeight,
|
||||
slice0
|
||||
);
|
||||
|
||||
shadowThisFrame = (half2)1.0 - saturate(shadowThisFrame + Utility::ComputeShadowFade(positionWS));
|
||||
|
||||
shadow = lerp(shadow, shadowThisFrame, _Crest_JitterDiameters_CurrentFrameWeights.zw * _Crest_SimDeltaTime * 60.0);
|
||||
}
|
||||
|
||||
_Crest_Target[id] = shadow;
|
||||
}
|
||||
|
||||
m_CrestNameSpaceEnd
|
||||
|
||||
m_CrestKernelXRP(UpdateShadows)
|
||||
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c47c6200534474da18e1134965c102f3
|
||||
ComputeShaderImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -100,7 +100,8 @@ half2 Fragment(Varyings input)
|
||||
float4 positionWS = float4(input.positionWS.xyz, 1.0);
|
||||
|
||||
// Shadow from last frame. Manually implement black border.
|
||||
half2 shadow = Cascade::MakeShadowSource(_Crest_LodIndex + g_Crest_LodChange).SampleShadowOverflow(positionWS.xz, 1.0);
|
||||
const float sliceIndexSource = clamp((int)_Crest_LodIndex + g_Crest_LodChange, 0.0, g_Crest_LodCount - 1.0);
|
||||
half2 shadow = Cascade::MakeShadowSource(sliceIndexSource).SampleShadowOverflow(positionWS.xz, 1.0);
|
||||
|
||||
// Add displacement so shorelines do not receive shadows incorrectly.
|
||||
positionWS.xyz += Cascade::MakeAnimatedWaves(_Crest_LodIndex).SampleDisplacement(positionWS.xz);
|
||||
|
||||
@@ -1,170 +1,7 @@
|
||||
// Crest Water System
|
||||
// Crest Water System
|
||||
// Copyright © 2024 Wave Harmonic. All rights reserved.
|
||||
|
||||
// Soft shadow term is red, hard shadow term is green.
|
||||
|
||||
Shader "Hidden/Crest/Simulation/Update Shadow"
|
||||
Shader "Hidden/Crest/Obsolete/Simulation/Update Shadow"
|
||||
{
|
||||
SubShader
|
||||
{
|
||||
PackageRequirements
|
||||
{
|
||||
"com.unity.render-pipelines.high-definition"
|
||||
}
|
||||
|
||||
Tags { "RenderPipeline"="HDRenderPipeline" }
|
||||
|
||||
Pass
|
||||
{
|
||||
HLSLPROGRAM
|
||||
#pragma vertex Vertex
|
||||
#pragma fragment Fragment
|
||||
|
||||
// #pragma enable_d3d11_debug_symbols
|
||||
|
||||
// SHADOW_ULTRA_LOW uses Gather which is 4.5. HDRP minimum is 5.0 so this is fine.
|
||||
#pragma target 4.5
|
||||
|
||||
// TODO: We might be able to expose this to give developers the option.
|
||||
// #pragma multi_compile SHADOW_ULTRA_LOW SHADOW_LOW SHADOW_MEDIUM SHADOW_HIGH
|
||||
|
||||
// Ultra low uses Gather to filter which should be same cost as not filtering. See algorithms per keyword:
|
||||
// Runtime/Lighting/Shadow/HDShadowAlgorithms.hlsl
|
||||
#define SHADOW_ULTRA_LOW
|
||||
#define AREA_SHADOW_LOW
|
||||
#define PUNCTUAL_SHADOW_ULTRA_LOW
|
||||
#define DIRECTIONAL_SHADOW_ULTRA_LOW
|
||||
|
||||
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl"
|
||||
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/CommonMaterial.hlsl"
|
||||
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl"
|
||||
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/HDShadow.hlsl"
|
||||
|
||||
float4x4 _Crest_ViewProjectionMatrix;
|
||||
|
||||
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Data/UpdateShadow.hlsl"
|
||||
|
||||
m_CrestNameSpace
|
||||
|
||||
half SampleShadows(const float4 i_positionWS)
|
||||
{
|
||||
// Get directional light data. By definition we only have one directional light casting shadow.
|
||||
DirectionalLightData light = _DirectionalLightDatas[_DirectionalShadowIndex];
|
||||
HDShadowContext context = InitShadowContext();
|
||||
|
||||
// Zeros are for screen space position and world space normal which are for filtering and normal bias
|
||||
// respectively. They did not appear to have an impact.
|
||||
half shadows = GetDirectionalShadowAttenuation(context, 0, i_positionWS.xyz, 0, _DirectionalShadowIndex, -light.forward);
|
||||
// Apply shadow strength from main light.
|
||||
shadows = LerpWhiteTo(shadows, light.shadowDimmer);
|
||||
|
||||
return shadows;
|
||||
}
|
||||
|
||||
half ComputeShadowFade(const float4 i_positionWS)
|
||||
{
|
||||
// TODO: Work out shadow fade.
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
m_CrestNameSpaceEnd
|
||||
ENDHLSL
|
||||
}
|
||||
}
|
||||
|
||||
SubShader
|
||||
{
|
||||
PackageRequirements
|
||||
{
|
||||
"com.unity.render-pipelines.universal"
|
||||
}
|
||||
|
||||
Tags { "RenderPipeline"="UniversalPipeline" }
|
||||
|
||||
Pass
|
||||
{
|
||||
HLSLPROGRAM
|
||||
|
||||
#pragma vertex Vertex
|
||||
#pragma fragment Fragment
|
||||
// #pragma enable_d3d11_debug_symbols
|
||||
|
||||
// Maybe this is the equivalent of the SHADOW_COLLECTOR_PASS define? Inspired from com.unity.render-pipelines.universal/Shaders/Utils/ScreenSpaceShadows.shader
|
||||
#define _MAIN_LIGHT_SHADOWS_CASCADE
|
||||
#define MAIN_LIGHT_CALCULATE_SHADOWS
|
||||
|
||||
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
|
||||
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"
|
||||
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/CommonMaterial.hlsl"
|
||||
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Shadows.hlsl"
|
||||
|
||||
#define CREST_SAMPLE_SHADOW_HARD
|
||||
|
||||
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Data/UpdateShadow.hlsl"
|
||||
|
||||
m_CrestNameSpace
|
||||
|
||||
half SampleShadows(const float4 i_positionWS)
|
||||
{
|
||||
// Includes soft shadows if _SHADOWS_SOFT is defined (requires multi-compile pragma).
|
||||
return MainLightRealtimeShadow(TransformWorldToShadowCoord(i_positionWS.xyz));
|
||||
}
|
||||
|
||||
half ComputeShadowFade(const float4 i_positionWS)
|
||||
{
|
||||
return GetShadowFade(i_positionWS.xyz);
|
||||
}
|
||||
|
||||
m_CrestNameSpaceEnd
|
||||
ENDHLSL
|
||||
}
|
||||
}
|
||||
|
||||
SubShader
|
||||
{
|
||||
Pass
|
||||
{
|
||||
HLSLPROGRAM
|
||||
#pragma vertex Vertex
|
||||
#pragma fragment Fragment
|
||||
|
||||
#pragma multi_compile_shadowcollector
|
||||
|
||||
// #pragma enable_d3d11_debug_symbols
|
||||
|
||||
#define CREST_SAMPLE_SHADOW_HARD
|
||||
#define d_Crest_ReceiveShadowsTransparent 1
|
||||
|
||||
#include "UnityCG.cginc"
|
||||
|
||||
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Library/Utility/Legacy/Core.hlsl"
|
||||
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Library/Utility/Legacy/Shadows.hlsl"
|
||||
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Data/UpdateShadow.hlsl"
|
||||
|
||||
m_CrestNameSpace
|
||||
|
||||
half SampleShadows(const float4 i_positionWS)
|
||||
{
|
||||
// NOTE: "Shadow Projection > Close Fit" can still produce artefacts when away from caster, but this
|
||||
// appears to be an improvement over the compute shader.
|
||||
float4 shadowCoord = GET_SHADOW_COORDINATES(i_positionWS);
|
||||
half shadows = UNITY_SAMPLE_SHADOW(_ShadowMapTexture, shadowCoord);
|
||||
if (_Crest_ClearShadows) shadows = 1.0;
|
||||
shadows = lerp(_LightShadowData.r, 1.0, shadows);
|
||||
|
||||
return shadows;
|
||||
}
|
||||
|
||||
half ComputeShadowFade(const float4 i_positionWS)
|
||||
{
|
||||
float z = dot(i_positionWS.xyz - _WorldSpaceCameraPos.xyz, unity_CameraToWorld._m02_m12_m22);
|
||||
float fadeDistance = UnityComputeShadowFadeDistance(i_positionWS.xyz, z);
|
||||
float fade = UnityComputeShadowFade(fadeDistance);
|
||||
return fade;
|
||||
}
|
||||
|
||||
m_CrestNameSpaceEnd
|
||||
ENDHLSL
|
||||
}
|
||||
}
|
||||
// Replaced with UpdateShadow.compute.
|
||||
}
|
||||
|
||||
@@ -106,7 +106,7 @@
|
||||
{ \
|
||||
result = Sample##name(uv); \
|
||||
} \
|
||||
else if (_Index < _Count) \
|
||||
else if ((_Index + 1) < _Count) \
|
||||
{ \
|
||||
const Cascade cascade = Cascade::Make##name(_Index + 1, this); \
|
||||
const float3 uv = cascade.WorldToUV(i_Position); \
|
||||
@@ -128,7 +128,7 @@
|
||||
{ \
|
||||
result = Sample##name(i_UV); \
|
||||
} \
|
||||
else if (_Index < _Count) \
|
||||
else if ((_Index + 1) < _Count) \
|
||||
{ \
|
||||
const Cascade cascade = Cascade::Make##name(_Index + 1, this); \
|
||||
const float3 uv = cascade.WorldToUV(UVToWorld(i_UV)); \
|
||||
|
||||
@@ -42,9 +42,6 @@
|
||||
#define CREST_SSS_MAXIMUM 0.6
|
||||
#define CREST_SSS_RANGE 0.12
|
||||
|
||||
// Note: Must match k_MaskBelowSurfaceCull in UnderwaterRenderer.Mask.cs.
|
||||
// Fog rendered from below and before transparents and water tile is culled.
|
||||
#define CREST_MASK_BELOW_SURFACE_CULLED -2.0
|
||||
// Note: Must match k_MaskBelowSurface in UnderwaterRenderer.Mask.cs.
|
||||
// Fog rendered from below.
|
||||
#define CREST_MASK_BELOW_SURFACE -1.0
|
||||
@@ -62,6 +59,7 @@
|
||||
// used to scale the meniscus as it is calculate using a pixel offset which can make the meniscus large at a distance.
|
||||
#define MENISCUS_MAXIMUM_DISTANCE 15.0
|
||||
|
||||
#define k_Crest_MaskInsidePortal 5
|
||||
|
||||
#if defined(STEREO_INSTANCING_ON) || defined(STEREO_MULTIVIEW_ON)
|
||||
#define CREST_HANDLE_XR 1
|
||||
|
||||
@@ -12,6 +12,8 @@ SamplerState LODData_linear_clamp_sampler;
|
||||
SamplerState LODData_point_clamp_sampler;
|
||||
SamplerState sampler_Crest_linear_repeat;
|
||||
|
||||
SamplerState _Crest_linear_clamp_sampler;
|
||||
|
||||
CBUFFER_START(CrestPerFrame)
|
||||
float3 g_Crest_WaterCenter;
|
||||
float g_Crest_WaterScale;
|
||||
@@ -31,6 +33,7 @@ int g_Crest_ForceUnderwater;
|
||||
|
||||
float3 g_Crest_PrimaryLightDirection;
|
||||
float3 g_Crest_PrimaryLightIntensity;
|
||||
bool g_Crest_PrimaryLightHasCookie;
|
||||
|
||||
float g_Crest_DynamicSoftShadowsFactor;
|
||||
|
||||
@@ -39,7 +42,7 @@ bool g_Crest_SampleScatteringSimulation;
|
||||
|
||||
// Motion Vector Parameters
|
||||
float g_Crest_WaterScaleChange;
|
||||
float3 g_Crest_WaterCenterDelta;
|
||||
float2 g_Crest_WaterCenterDelta;
|
||||
|
||||
// Shifting Origin
|
||||
#if (CREST_SHIFTING_ORIGIN != 0)
|
||||
|
||||
@@ -90,21 +90,27 @@ void PosToSliceIndices
|
||||
}
|
||||
}
|
||||
|
||||
bool IsUnderwater(const bool i_FrontFace, const int i_ForceUnderwater)
|
||||
bool IsUnderWater(const bool i_FrontFace, const int i_ForceUnderwater)
|
||||
{
|
||||
bool underwater = false;
|
||||
|
||||
// We are well below water.
|
||||
if (i_ForceUnderwater == 1)
|
||||
{
|
||||
return true;
|
||||
underwater = true;
|
||||
}
|
||||
|
||||
// We are well above water.
|
||||
if (i_ForceUnderwater == 2)
|
||||
else if (i_ForceUnderwater == 2)
|
||||
{
|
||||
return false;
|
||||
underwater = false;
|
||||
}
|
||||
// Use facing.
|
||||
else
|
||||
{
|
||||
underwater = !i_FrontFace;
|
||||
}
|
||||
|
||||
return !i_FrontFace;
|
||||
return underwater;
|
||||
}
|
||||
|
||||
float FeatherWeightFromUV(const float2 i_uv, const half i_featherWidth)
|
||||
|
||||
@@ -9,15 +9,10 @@
|
||||
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Library/Constants.hlsl"
|
||||
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Library/Macros.hlsl"
|
||||
|
||||
CBUFFER_START(CrestChunkInstanceData)
|
||||
uint _Crest_LodIndex;
|
||||
float _Crest_ChunkMeshScaleAlpha;
|
||||
float _Crest_ChunkMeshScaleAlphaSource;
|
||||
float _Crest_ChunkGeometryGridWidth;
|
||||
float _Crest_ChunkGeometryGridWidthSource;
|
||||
float _Crest_ChunkFarNormalsWeight;
|
||||
float2 _Crest_ChunkNormalScrollSpeed;
|
||||
CBUFFER_END
|
||||
// NOTE: Unity does not recognize uint in FrameDebugger. It will be under Floats
|
||||
// with incorrect values. Change to int for debugging.
|
||||
uint _Crest_LodIndex;
|
||||
|
||||
|
||||
Texture2DArray g_Crest_CascadeAbsorption;
|
||||
m_DisplacementTexture(Texture2DArray, 4) g_Crest_CascadeAnimatedWaves;
|
||||
|
||||
@@ -31,6 +31,12 @@ type Fragment(m_Crest::Varyings i_Input) : SV_Target \
|
||||
return m_Crest::Fragment(i_Input); \
|
||||
}
|
||||
|
||||
#define m_CrestFragmentVariant(type, name) \
|
||||
type Fragment(m_Crest::Varyings i_Input) : SV_Target \
|
||||
{ \
|
||||
return m_Crest::name(i_Input); \
|
||||
}
|
||||
|
||||
#define m_CrestFragmentWithFrontFace(type) \
|
||||
type Fragment(m_Crest::Varyings i_Input, const bool i_IsFrontFace : SV_IsFrontFace) : SV_Target \
|
||||
{ \
|
||||
@@ -69,4 +75,10 @@ void Crest##name(uint3 id : SV_DispatchThreadID) \
|
||||
m_Crest::name(uint3(id.xy, g_Crest_LodCount - 1 - id.z)); \
|
||||
}
|
||||
|
||||
// Cross render pipeline kernels.
|
||||
#define m_CrestKernelXRP(name) \
|
||||
[numthreads(THREAD_GROUP_SIZE_X, THREAD_GROUP_SIZE_Y, 1)] void Crest##name##BRP(uint3 id : SV_DispatchThreadID) { m_Crest::name(id); } \
|
||||
[numthreads(THREAD_GROUP_SIZE_X, THREAD_GROUP_SIZE_Y, 1)] void Crest##name##HRP(uint3 id : SV_DispatchThreadID) { m_Crest::name(id); } \
|
||||
[numthreads(THREAD_GROUP_SIZE_X, THREAD_GROUP_SIZE_Y, 1)] void Crest##name##URP(uint3 id : SV_DispatchThreadID) { m_Crest::name(id); } \
|
||||
|
||||
#endif // CREST_MACROS_H
|
||||
|
||||
@@ -7,10 +7,13 @@
|
||||
//
|
||||
// WaveHarmonic.Crest.Editor.ShaderSettings: static fields
|
||||
//
|
||||
#define CREST_PACKAGE_HDRP (1)
|
||||
#define CREST_PACKAGE_URP (1)
|
||||
#define CREST_PORTALS (0)
|
||||
#define CREST_SHIFTING_ORIGIN (0)
|
||||
#define CREST_SHADOWS_BUILT_IN_RENDER_PIPELINE (1)
|
||||
#define CREST_FULL_PRECISION_DISPLACEMENT (1)
|
||||
#define CREST_DISCARD_ATMOSPHERIC_SCATTERING (1)
|
||||
#define CREST_LEGACY_UNDERWATER (0)
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
// Crest Water System
|
||||
// Copyright © 2024 Wave Harmonic. All rights reserved.
|
||||
|
||||
#ifndef d_WaveHarmonic_Utility_Helpers
|
||||
#define d_WaveHarmonic_Utility_Helpers
|
||||
|
||||
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Library/Utility/Macros.hlsl"
|
||||
|
||||
m_UtilityNameSpace
|
||||
|
||||
void Swap(inout float a, inout float b)
|
||||
{
|
||||
float t = a; a = b; b = t;
|
||||
}
|
||||
|
||||
// Adapted from:
|
||||
// https://alex.vlachos.com/graphics/Alex_Vlachos_Advanced_VR_Rendering_GDC2015.pdf
|
||||
float3 ScreenSpaceDither(const float2 i_ScreenPosition)
|
||||
{
|
||||
// Iestyn's RGB dither (7 asm instructions) from Portal 2 X360, slightly modified for VR.
|
||||
float3 dither = dot(float2(171.0, 231.0), i_ScreenPosition.xy);
|
||||
dither.rgb = frac(dither.rgb / float3(103.0, 71.0, 97.0)) - float3(0.5, 0.5, 0.5);
|
||||
return (dither.rgb / 255.0);
|
||||
}
|
||||
|
||||
float2 WorldNormalToScreenDirection(const float3 i_PositionWS, const float3 i_NormalWS, const float4x4 i_MatrixVP, const float i_Offset)
|
||||
{
|
||||
const float3 p0 = i_PositionWS;
|
||||
const float3 p1 = p0 + i_NormalWS * i_Offset;
|
||||
|
||||
const float4 clip0 = mul(i_MatrixVP, float4(p0, 1));
|
||||
const float4 clip1 = mul(i_MatrixVP, float4(p1, 1));
|
||||
|
||||
const float2 uv0 = (clip0.xy / clip0.w) * 0.5 + 0.5;
|
||||
const float2 uv1 = (clip1.xy / clip1.w) * 0.5 + 0.5;
|
||||
|
||||
float2 direction = normalize(uv1 - uv0);
|
||||
|
||||
#if UNITY_UV_STARTS_AT_TOP
|
||||
direction.y = -direction.y;
|
||||
#endif
|
||||
|
||||
return direction;
|
||||
}
|
||||
|
||||
m_UtilityNameSpaceEnd
|
||||
|
||||
#endif // d_WaveHarmonic_Utility_Helpers
|
||||
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 90443daddb561477ca109fbfe1d80fdd
|
||||
ShaderIncludeImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,257 +1,4 @@
|
||||
// Crest Water System
|
||||
// Copyright © 2024 Wave Harmonic. All rights reserved.
|
||||
|
||||
// This file is subject to the Unity Companion License:
|
||||
// https://github.com/Unity-Technologies/Graphics/blob/7ff8fd444c179fd9bb380d61f4865be6935b47dd/LICENSE.md
|
||||
|
||||
// Adds functions from SRP.
|
||||
|
||||
// Adapted from:
|
||||
// https://github.com/Unity-Technologies/Graphics/blob/8f54e6591e93fb3bf8e9879a0e43665dfbe2f629/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl
|
||||
|
||||
#ifndef UNITY_COMMON_INCLUDED
|
||||
#define UNITY_COMMON_INCLUDED
|
||||
|
||||
// Add "real" alias for "fixed". Helps with including files downstream.
|
||||
|
||||
#define real fixed
|
||||
#define real2 fixed2
|
||||
#define real3 fixed3
|
||||
#define real4 fixed4
|
||||
|
||||
// Commented lines have no "fixed" equivalent.
|
||||
|
||||
#define real2x2 fixed2x2
|
||||
// #define real2x3 fixed2x3
|
||||
// #define real2x4 fixed2x4
|
||||
// #define real3x2 fixed3x2
|
||||
#define real3x3 fixed3x3
|
||||
// #define real3x4 fixed3x4
|
||||
// #define real4x3 fixed4x3
|
||||
#define real4x4 fixed4x4
|
||||
|
||||
//
|
||||
// MACROS
|
||||
//
|
||||
|
||||
#define ZERO_INITIALIZE(type, name) UNITY_INITIALIZE_OUTPUT(type,name)
|
||||
#define TransformObjectToHClip(positionOS) UnityObjectToClipPos(float4(positionOS, 1.0))
|
||||
|
||||
// Taken from:
|
||||
// com.unity.render-pipelines.core@10.5.0/ShaderLibrary/API/D3D11.hlsl
|
||||
// com.unity.render-pipelines.core@10.5.0/ShaderLibrary/API/Metal.hlsl
|
||||
// com.unity.render-pipelines.core@10.5.0/ShaderLibrary/API/Switch.hlsl
|
||||
// com.unity.render-pipelines.core@10.5.0/ShaderLibrary/API/Vulkan.hlsl
|
||||
|
||||
// GameCore, PSSL etc require an NDA so hard to confirm how some of these APIs are implemented, but the PPv2 package has
|
||||
// some of APIs (the ones we use) and they are the same:
|
||||
// com.unity.postprocessing/PostProcessing/Shaders/API/
|
||||
|
||||
// Texture abstraction.
|
||||
|
||||
#define TEXTURE2D(textureName) UNITY_DECLARE_TEX2D_NOSAMPLER(textureName)
|
||||
#define TEXTURE2D_ARRAY(textureName) UNITY_DECLARE_TEX2DARRAY_NOSAMPLER(textureName)
|
||||
#define TEXTURECUBE(textureName) UNITY_DECLARE_TEXCUBE_NOSAMPLER(textureName)
|
||||
// #define TEXTURECUBE_ARRAY(textureName) TextureCubeArray textureName
|
||||
// #define TEXTURE3D(textureName) Texture3D textureName
|
||||
|
||||
// #ifdef SHADER_API_D3D11
|
||||
|
||||
// #define TEXTURE2D_FLOAT(textureName) TEXTURE2D(textureName)
|
||||
// #define TEXTURE2D_ARRAY_FLOAT(textureName) TEXTURE2D_ARRAY(textureName)
|
||||
// #define TEXTURECUBE_FLOAT(textureName) TEXTURECUBE(textureName)
|
||||
// #define TEXTURECUBE_ARRAY_FLOAT(textureName) TEXTURECUBE_ARRAY(textureName)
|
||||
// #define TEXTURE3D_FLOAT(textureName) TEXTURE3D(textureName)
|
||||
|
||||
// #define TEXTURE2D_HALF(textureName) TEXTURE2D(textureName)
|
||||
// #define TEXTURE2D_ARRAY_HALF(textureName) TEXTURE2D_ARRAY(textureName)
|
||||
// #define TEXTURECUBE_HALF(textureName) TEXTURECUBE(textureName)
|
||||
// #define TEXTURECUBE_ARRAY_HALF(textureName) TEXTURECUBE_ARRAY(textureName)
|
||||
// #define TEXTURE3D_HALF(textureName) TEXTURE3D(textureName)
|
||||
|
||||
// #else // !SHADER_API_D3D11
|
||||
|
||||
// #define TEXTURE2D_FLOAT(textureName) Texture2D_float textureName
|
||||
// #define TEXTURE2D_ARRAY_FLOAT(textureName) Texture2DArray_float textureName
|
||||
// #define TEXTURECUBE_FLOAT(textureName) TextureCube_float textureName
|
||||
// #define TEXTURECUBE_ARRAY_FLOAT(textureName) TextureCubeArray_float textureName
|
||||
// #define TEXTURE3D_FLOAT(textureName) Texture3D_float textureName
|
||||
|
||||
// #define TEXTURE2D_HALF(textureName) Texture2D_half textureName
|
||||
// #define TEXTURE2D_ARRAY_HALF(textureName) Texture2DArray_half textureName
|
||||
// #define TEXTURECUBE_HALF(textureName) TextureCube_half textureName
|
||||
// #define TEXTURECUBE_ARRAY_HALF(textureName) TextureCubeArray_half textureName
|
||||
// #define TEXTURE3D_HALF(textureName) Texture3D_half textureName
|
||||
|
||||
// #endif // SHADER_API_D3D11
|
||||
|
||||
// #define TEXTURE2D_SHADOW(textureName) TEXTURE2D(textureName)
|
||||
// #define TEXTURE2D_ARRAY_SHADOW(textureName) TEXTURE2D_ARRAY(textureName)
|
||||
// #define TEXTURECUBE_SHADOW(textureName) TEXTURECUBE(textureName)
|
||||
// #define TEXTURECUBE_ARRAY_SHADOW(textureName) TEXTURECUBE_ARRAY(textureName)
|
||||
|
||||
#define RW_TEXTURE2D(type, textureName) RWTexture2D<type> textureName
|
||||
#define RW_TEXTURE2D_ARRAY(type, textureName) RWTexture2DArray<type> textureName
|
||||
// #define RW_TEXTURE3D(type, textureName) RWTexture3D<type> textureName
|
||||
|
||||
#define SAMPLER(samplerName) SamplerState samplerName
|
||||
// #define SAMPLER_CMP(samplerName) SamplerComparisonState samplerName
|
||||
// #define ASSIGN_SAMPLER(samplerName, samplerValue) samplerName = samplerValue
|
||||
|
||||
// #define TEXTURE2D_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER(samplerName)
|
||||
// #define TEXTURE2D_ARRAY_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER(samplerName)
|
||||
// #define TEXTURECUBE_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER(samplerName)
|
||||
// #define TEXTURECUBE_ARRAY_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER(samplerName)
|
||||
// #define TEXTURE3D_PARAM(textureName, samplerName) TEXTURE3D(textureName), SAMPLER(samplerName)
|
||||
|
||||
// #define TEXTURE2D_SHADOW_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER_CMP(samplerName)
|
||||
// #define TEXTURE2D_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER_CMP(samplerName)
|
||||
// #define TEXTURECUBE_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER_CMP(samplerName)
|
||||
// #define TEXTURECUBE_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER_CMP(samplerName)
|
||||
|
||||
// #define TEXTURE2D_ARGS(textureName, samplerName) textureName, samplerName
|
||||
// #define TEXTURE2D_ARRAY_ARGS(textureName, samplerName) textureName, samplerName
|
||||
// #define TEXTURECUBE_ARGS(textureName, samplerName) textureName, samplerName
|
||||
// #define TEXTURECUBE_ARRAY_ARGS(textureName, samplerName) textureName, samplerName
|
||||
// #define TEXTURE3D_ARGS(textureName, samplerName) textureName, samplerName
|
||||
|
||||
// #define TEXTURE2D_SHADOW_ARGS(textureName, samplerName) textureName, samplerName
|
||||
// #define TEXTURE2D_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName
|
||||
// #define TEXTURECUBE_SHADOW_ARGS(textureName, samplerName) textureName, samplerName
|
||||
// #define TEXTURECUBE_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName
|
||||
|
||||
// We cannot use Unity's macros because they change the samplerName and it needs to be unchanged.
|
||||
#define SAMPLE_TEXTURE2D(textureName, samplerName, coord2) textureName.Sample(samplerName, coord2)
|
||||
#define SAMPLE_TEXTURE2D_LOD(textureName, samplerName, coord2, lod) textureName.SampleLevel(samplerName, coord2, lod)
|
||||
// #define SAMPLE_TEXTURE2D_BIAS(textureName, samplerName, coord2, bias) textureName.SampleBias(samplerName, coord2, bias)
|
||||
// #define SAMPLE_TEXTURE2D_GRAD(textureName, samplerName, coord2, dpdx, dpdy) textureName.SampleGrad(samplerName, coord2, dpdx, dpdy)
|
||||
#define SAMPLE_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Sample(samplerName, float3(coord2, index))
|
||||
// #define SAMPLE_TEXTURE2D_ARRAY_LOD(textureName, samplerName, coord2, index, lod) textureName.SampleLevel(samplerName, float3(coord2, index), lod)
|
||||
// #define SAMPLE_TEXTURE2D_ARRAY_BIAS(textureName, samplerName, coord2, index, bias) textureName.SampleBias(samplerName, float3(coord2, index), bias)
|
||||
// #define SAMPLE_TEXTURE2D_ARRAY_GRAD(textureName, samplerName, coord2, index, dpdx, dpdy) textureName.SampleGrad(samplerName, float3(coord2, index), dpdx, dpdy)
|
||||
// #define SAMPLE_TEXTURECUBE(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3)
|
||||
// #define SAMPLE_TEXTURECUBE_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod)
|
||||
// #define SAMPLE_TEXTURECUBE_BIAS(textureName, samplerName, coord3, bias) textureName.SampleBias(samplerName, coord3, bias)
|
||||
// #define SAMPLE_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Sample(samplerName, float4(coord3, index))
|
||||
// #define SAMPLE_TEXTURECUBE_ARRAY_LOD(textureName, samplerName, coord3, index, lod) textureName.SampleLevel(samplerName, float4(coord3, index), lod)
|
||||
// #define SAMPLE_TEXTURECUBE_ARRAY_BIAS(textureName, samplerName, coord3, index, bias) textureName.SampleBias(samplerName, float4(coord3, index), bias)
|
||||
// #define SAMPLE_TEXTURE3D(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3)
|
||||
// #define SAMPLE_TEXTURE3D_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod)
|
||||
|
||||
// #define SAMPLE_TEXTURE2D_SHADOW(textureName, samplerName, coord3) textureName.SampleCmpLevelZero(samplerName, (coord3).xy, (coord3).z)
|
||||
// #define SAMPLE_TEXTURE2D_ARRAY_SHADOW(textureName, samplerName, coord3, index) textureName.SampleCmpLevelZero(samplerName, float3((coord3).xy, index), (coord3).z)
|
||||
// #define SAMPLE_TEXTURECUBE_SHADOW(textureName, samplerName, coord4) textureName.SampleCmpLevelZero(samplerName, (coord4).xyz, (coord4).w)
|
||||
// #define SAMPLE_TEXTURECUBE_ARRAY_SHADOW(textureName, samplerName, coord4, index) textureName.SampleCmpLevelZero(samplerName, float4((coord4).xyz, index), (coord4).w)
|
||||
|
||||
#undef SAMPLE_DEPTH_TEXTURE
|
||||
// #undef SAMPLE_DEPTH_TEXTURE_LOD
|
||||
#define SAMPLE_DEPTH_TEXTURE(textureName, samplerName, coord2) SAMPLE_TEXTURE2D(textureName, samplerName, coord2).r
|
||||
// #define SAMPLE_DEPTH_TEXTURE_LOD(textureName, samplerName, coord2, lod) SAMPLE_TEXTURE2D_LOD(textureName, samplerName, coord2, lod).r
|
||||
|
||||
#define LOAD_TEXTURE2D(textureName, unCoord2) textureName.Load(int3(unCoord2, 0))
|
||||
// #define LOAD_TEXTURE2D_LOD(textureName, unCoord2, lod) textureName.Load(int3(unCoord2, lod))
|
||||
// #define LOAD_TEXTURE2D_MSAA(textureName, unCoord2, sampleIndex) textureName.Load(unCoord2, sampleIndex)
|
||||
#define LOAD_TEXTURE2D_ARRAY(textureName, unCoord2, index) textureName.Load(int4(unCoord2, index, 0))
|
||||
// #ifndef SHADER_API_SWITCH
|
||||
// #define LOAD_TEXTURE2D_ARRAY_MSAA(textureName, unCoord2, index, sampleIndex) textureName.Load(int3(unCoord2, index), sampleIndex)
|
||||
// #endif
|
||||
// #define LOAD_TEXTURE2D_ARRAY_LOD(textureName, unCoord2, index, lod) textureName.Load(int4(unCoord2, index, lod))
|
||||
// #define LOAD_TEXTURE3D(textureName, unCoord3) textureName.Load(int4(unCoord3, 0))
|
||||
// #define LOAD_TEXTURE3D_LOD(textureName, unCoord3, lod) textureName.Load(int4(unCoord3, lod))
|
||||
|
||||
// #define GATHER_TEXTURE2D(textureName, samplerName, coord2) textureName.Gather(samplerName, coord2)
|
||||
// #define GATHER_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Gather(samplerName, float3(coord2, index))
|
||||
// #define GATHER_TEXTURECUBE(textureName, samplerName, coord3) textureName.Gather(samplerName, coord3)
|
||||
// #define GATHER_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Gather(samplerName, float4(coord3, index))
|
||||
// #define GATHER_RED_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherRed(samplerName, coord2)
|
||||
// #define GATHER_GREEN_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherGreen(samplerName, coord2)
|
||||
// #define GATHER_BLUE_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherBlue(samplerName, coord2)
|
||||
// #define GATHER_ALPHA_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherAlpha(samplerName, coord2)
|
||||
|
||||
// Generates a triangle in homogeneous clip space, s.t.
|
||||
// v0 = (-1, -1, 1), v1 = (3, -1, 1), v2 = (-1, 3, 1).
|
||||
float2 GetFullScreenTriangleTexCoord(uint vertexID)
|
||||
{
|
||||
#if UNITY_UV_STARTS_AT_TOP
|
||||
return float2((vertexID << 1) & 2, 1.0 - (vertexID & 2));
|
||||
#else
|
||||
return float2((vertexID << 1) & 2, vertexID & 2);
|
||||
#endif
|
||||
}
|
||||
|
||||
float4 GetFullScreenTriangleVertexPosition(uint vertexID, float z = UNITY_NEAR_CLIP_VALUE)
|
||||
{
|
||||
float2 uv = float2((vertexID << 1) & 2, vertexID & 2);
|
||||
return float4(uv * 2.0 - 1.0, z, 1.0);
|
||||
}
|
||||
|
||||
#endif // UNITY_COMMON_INCLUDED
|
||||
|
||||
//
|
||||
// FUNCTIONS
|
||||
//
|
||||
|
||||
// Keep the following unguarded
|
||||
|
||||
// Taken and modified from:
|
||||
// com.unity.render-pipelines.core@12.0.0/ShaderLibrary/Common.hlsl
|
||||
float4 CrestComputeClipSpacePosition(float2 positionNDC, float deviceDepth)
|
||||
{
|
||||
float4 positionCS = float4(positionNDC * 2.0 - 1.0, deviceDepth, 1.0);
|
||||
// positionCS.y was flipped here but that is SRP specific to solve flip baked into matrix.
|
||||
return positionCS;
|
||||
}
|
||||
|
||||
// Taken and modified from:
|
||||
// com.unity.render-pipelines.core@12.0.0/ShaderLibrary/Common.hlsl
|
||||
float3 CrestComputeWorldSpacePosition(float2 positionNDC, float deviceDepth, float4x4 invViewProjMatrix)
|
||||
{
|
||||
float4 positionCS = CrestComputeClipSpacePosition(positionNDC, deviceDepth);
|
||||
float4 hpositionWS = mul(invViewProjMatrix, positionCS);
|
||||
return hpositionWS.xyz / hpositionWS.w;
|
||||
}
|
||||
|
||||
// Taken from:
|
||||
// com.unity.render-pipelines.core@12.0.0/ShaderLibrary/Common.hlsl
|
||||
float3 CrestComputeWorldSpacePosition(float4 positionCS, float4x4 invViewProjMatrix)
|
||||
{
|
||||
float4 hpositionWS = mul(invViewProjMatrix, positionCS);
|
||||
return hpositionWS.xyz / hpositionWS.w;
|
||||
}
|
||||
|
||||
#undef ComputeClipSpacePosition
|
||||
#undef ComputeWorldSpacePosition
|
||||
|
||||
// Replace these with our own as ComputeClipSpacePosition flips the Y which is not correct for BIRP.
|
||||
#define ComputeClipSpacePosition CrestComputeClipSpacePosition
|
||||
#define ComputeWorldSpacePosition CrestComputeWorldSpacePosition
|
||||
|
||||
// Taken from:
|
||||
// com.unity.render-pipelines.core/ShaderLibrary/Packing.hlsl
|
||||
real3 CrestUnpackNormalmapRGorAG(real4 packednormal)
|
||||
{
|
||||
// This do the trick
|
||||
packednormal.x *= packednormal.w;
|
||||
|
||||
real3 normal;
|
||||
normal.xy = packednormal.xy * 2 - 1;
|
||||
normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy)));
|
||||
return normal;
|
||||
}
|
||||
|
||||
// Taken from:
|
||||
// com.unity.render-pipelines.core/ShaderLibrary/Packing.hlsl
|
||||
inline real3 CrestUnpackNormal(real4 packednormal)
|
||||
{
|
||||
#if defined(UNITY_NO_DXT5nm)
|
||||
return packednormal.xyz * 2 - 1;
|
||||
#elif defined(UNITY_ASTC_NORMALMAP_ENCODING)
|
||||
return UnpackNormalDXT5nm(packednormal);
|
||||
#else
|
||||
return CrestUnpackNormalmapRGorAG(packednormal);
|
||||
#endif
|
||||
}
|
||||
|
||||
#undef UnpackNormal
|
||||
|
||||
// Replace these to solve Unity bug "ambiguous call to 'UnpackNormalmapRGorAG'"
|
||||
#define UnpackNormal CrestUnpackNormal
|
||||
// Empty.
|
||||
|
||||
@@ -1,75 +1,35 @@
|
||||
// Crest Water System
|
||||
// Copyright © 2024 Wave Harmonic. All rights reserved.
|
||||
|
||||
// This file is subject to the Unity Companion License:
|
||||
// https://github.com/Unity-Technologies/Graphics/blob/7ff8fd444c179fd9bb380d61f4865be6935b47dd/LICENSE.md
|
||||
// Builds on Unity's shim for Shader Graph.
|
||||
|
||||
// Adds functions from SRP.
|
||||
#define BUILTIN_TARGET_API 1
|
||||
|
||||
// Adapted from:
|
||||
// https://github.com/Unity-Technologies/Graphics/blob/8f54e6591e93fb3bf8e9879a0e43665dfbe2f629/com.unity.shadergraph/Editor/Generation/Targets/BuiltIn/ShaderLibrary/Core.hlsl
|
||||
// https://github.com/Unity-Technologies/Graphics/blob/7ff8fd444c179fd9bb380d61f4865be6935b47dd/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/TextureXR.hlsl
|
||||
#include "Packages/com.unity.shadergraph/Editor/Generation/Targets/BuiltIn/Editor/ShaderGraph/Includes/ShaderPass.hlsl"
|
||||
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Library/Utility/Legacy/Defines.hlsl"
|
||||
#include "Packages/com.unity.shadergraph/Editor/Generation/Targets/BuiltIn/ShaderLibrary/Shim/Shims.hlsl"
|
||||
#include "Packages/com.unity.shadergraph/Editor/Generation/Targets/BuiltIn/ShaderLibrary/Core.hlsl"
|
||||
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Library/Utility/Legacy/InputsDriven.hlsl"
|
||||
|
||||
#ifndef BUILTIN_PIPELINE_CORE_INCLUDED
|
||||
#define BUILTIN_PIPELINE_CORE_INCLUDED
|
||||
#ifndef d_WaveHarmonic_Utility_LegacyCore
|
||||
#define d_WaveHarmonic_Utility_LegacyCore
|
||||
|
||||
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Library/Utility/Legacy/Common.hlsl"
|
||||
|
||||
// Stereo-related bits
|
||||
#if defined(UNITY_STEREO_INSTANCING_ENABLED) || defined(UNITY_STEREO_MULTIVIEW_ENABLED)
|
||||
//
|
||||
// Inputs
|
||||
//
|
||||
|
||||
#define SLICE_ARRAY_INDEX unity_StereoEyeIndex
|
||||
#undef UNITY_MATRIX_I_VP
|
||||
|
||||
#define COORD_TEXTURE2D_X(pixelCoord) uint3(pixelCoord, SLICE_ARRAY_INDEX)
|
||||
|
||||
#define TEXTURE2D_X(textureName) TEXTURE2D_ARRAY(textureName)
|
||||
// #define TEXTURE2D_X_PARAM(textureName, samplerName) TEXTURE2D_ARRAY_PARAM(textureName, samplerName)
|
||||
// #define TEXTURE2D_X_ARGS(textureName, samplerName) TEXTURE2D_ARRAY_ARGS(textureName, samplerName)
|
||||
// #define TEXTURE2D_X_HALF(textureName) TEXTURE2D_ARRAY_HALF(textureName)
|
||||
// #define TEXTURE2D_X_FLOAT(textureName) TEXTURE2D_ARRAY_FLOAT(textureName)
|
||||
|
||||
#define RW_TEXTURE2D_X(type, textureName) RW_TEXTURE2D_ARRAY(type, textureName)
|
||||
|
||||
#define LOAD_TEXTURE2D_X(textureName, unCoord2) LOAD_TEXTURE2D_ARRAY(textureName, unCoord2, SLICE_ARRAY_INDEX)
|
||||
// #define LOAD_TEXTURE2D_X_LOD(textureName, unCoord2, lod) LOAD_TEXTURE2D_ARRAY_LOD(textureName, unCoord2, SLICE_ARRAY_INDEX, lod)
|
||||
#define SAMPLE_TEXTURE2D_X(textureName, samplerName, coord2) SAMPLE_TEXTURE2D_ARRAY(textureName, samplerName, coord2, SLICE_ARRAY_INDEX)
|
||||
// #define SAMPLE_TEXTURE2D_X_LOD(textureName, samplerName, coord2, lod) SAMPLE_TEXTURE2D_ARRAY_LOD(textureName, samplerName, coord2, SLICE_ARRAY_INDEX, lod)
|
||||
// #define GATHER_TEXTURE2D_X(textureName, samplerName, coord2) GATHER_TEXTURE2D_ARRAY(textureName, samplerName, coord2, SLICE_ARRAY_INDEX)
|
||||
// #define GATHER_RED_TEXTURE2D_X(textureName, samplerName, coord2) GATHER_RED_TEXTURE2D(textureName, samplerName, float3(coord2, SLICE_ARRAY_INDEX))
|
||||
// #define GATHER_GREEN_TEXTURE2D_X(textureName, samplerName, coord2) GATHER_GREEN_TEXTURE2D(textureName, samplerName, float3(coord2, SLICE_ARRAY_INDEX))
|
||||
// #define GATHER_BLUE_TEXTURE2D_X(textureName, samplerName, coord2) GATHER_BLUE_TEXTURE2D(textureName, samplerName, float3(coord2, SLICE_ARRAY_INDEX))
|
||||
|
||||
#else // UNITY_STEREO
|
||||
|
||||
#define SLICE_ARRAY_INDEX 0
|
||||
|
||||
#define COORD_TEXTURE2D_X(pixelCoord) pixelCoord
|
||||
|
||||
#define TEXTURE2D_X(textureName) TEXTURE2D(textureName)
|
||||
// #define TEXTURE2D_X_PARAM(textureName, samplerName) TEXTURE2D_PARAM(textureName, samplerName)
|
||||
// #define TEXTURE2D_X_ARGS(textureName, samplerName) TEXTURE2D_ARGS(textureName, samplerName)
|
||||
// #define TEXTURE2D_X_HALF(textureName) TEXTURE2D_HALF(textureName)
|
||||
// #define TEXTURE2D_X_FLOAT(textureName) TEXTURE2D_FLOAT(textureName)
|
||||
|
||||
#define RW_TEXTURE2D_X RW_TEXTURE2D
|
||||
|
||||
#define LOAD_TEXTURE2D_X(textureName, unCoord2) LOAD_TEXTURE2D(textureName, unCoord2)
|
||||
// #define LOAD_TEXTURE2D_X_LOD(textureName, unCoord2, lod) LOAD_TEXTURE2D_LOD(textureName, unCoord2, lod)
|
||||
#define SAMPLE_TEXTURE2D_X(textureName, samplerName, coord2) SAMPLE_TEXTURE2D(textureName, samplerName, coord2)
|
||||
// #define SAMPLE_TEXTURE2D_X_LOD(textureName, samplerName, coord2, lod) SAMPLE_TEXTURE2D_LOD(textureName, samplerName, coord2, lod)
|
||||
// #define GATHER_TEXTURE2D_X(textureName, samplerName, coord2) GATHER_TEXTURE2D(textureName, samplerName, coord2)
|
||||
// #define GATHER_RED_TEXTURE2D_X(textureName, samplerName, coord2) GATHER_RED_TEXTURE2D(textureName, samplerName, coord2)
|
||||
// #define GATHER_GREEN_TEXTURE2D_X(textureName, samplerName, coord2) GATHER_GREEN_TEXTURE2D(textureName, samplerName, coord2)
|
||||
// #define GATHER_BLUE_TEXTURE2D_X(textureName, samplerName, coord2) GATHER_BLUE_TEXTURE2D(textureName, samplerName, coord2)
|
||||
|
||||
#endif // UNITY_STEREO
|
||||
|
||||
// Helper macro to assign view index during compute/ray pass (usually from SV_DispatchThreadID or DispatchRaysIndex())
|
||||
#if defined(SHADER_STAGE_COMPUTE) || defined(SHADER_STAGE_RAY_TRACING)
|
||||
#if defined(UNITY_STEREO_INSTANCING_ENABLED)
|
||||
#define UNITY_XR_ASSIGN_VIEW_INDEX(viewIndex) unity_StereoEyeIndex = viewIndex;
|
||||
#else
|
||||
#define UNITY_XR_ASSIGN_VIEW_INDEX(viewIndex)
|
||||
#endif
|
||||
#if defined(STEREO_INSTANCING_ON) || defined(STEREO_MULTIVIEW_ON)
|
||||
float4x4 _Crest_StereoInverseViewProjection[2];
|
||||
#define UNITY_MATRIX_I_VP _Crest_StereoInverseViewProjection[unity_StereoEyeIndex]
|
||||
#else
|
||||
float4x4 _Crest_InverseViewProjection;
|
||||
#define UNITY_MATRIX_I_VP _Crest_InverseViewProjection
|
||||
#endif
|
||||
|
||||
#endif // BUILTIN_PIPELINE_CORE_INCLUDED
|
||||
// Not set and _ScreenParams.zw is "1.0 + 1.0 / _ScreenParams.xy"
|
||||
#define _ScreenSize float4(_ScreenParams.xy, float2(1.0, 1.0) / _ScreenParams.xy)
|
||||
|
||||
#endif // d_WaveHarmonic_Utility_LegacyCore
|
||||
|
||||
@@ -0,0 +1,111 @@
|
||||
// Crest Water System
|
||||
// Copyright © 2024 Wave Harmonic. All rights reserved.
|
||||
|
||||
#ifndef d_WaveHarmonic_Utility_ShaderGraphDefines
|
||||
#define d_WaveHarmonic_Utility_ShaderGraphDefines
|
||||
|
||||
//
|
||||
// Defines
|
||||
//
|
||||
|
||||
#ifdef _BUILTIN_SPECULAR_SETUP
|
||||
#define _SPECULAR_SETUP _BUILTIN_SPECULAR_SETUP
|
||||
#endif
|
||||
|
||||
#ifdef _BUILTIN_TRANSPARENT_RECEIVES_SHADOWS
|
||||
#define _TRANSPARENT_RECEIVES_SHADOWS _BUILTIN_TRANSPARENT_RECEIVES_SHADOWS
|
||||
#endif
|
||||
|
||||
|
||||
//
|
||||
// Passes
|
||||
//
|
||||
|
||||
#define SHADERPASS_FORWARD_ADD (20)
|
||||
#define SHADERPASS_DEFERRED (21)
|
||||
#define SHADERPASS_MOTION_VECTORS (22)
|
||||
|
||||
|
||||
//
|
||||
// Deferred Fix
|
||||
//
|
||||
|
||||
#if (defined(SHADER_API_GLES3) && !defined(SHADER_API_DESKTOP)) || defined(SHADER_API_GLES) || defined(SHADER_API_N3DS)
|
||||
#define UNITY_ALLOWED_MRT_COUNT 4
|
||||
#else
|
||||
#define UNITY_ALLOWED_MRT_COUNT 8
|
||||
#endif
|
||||
|
||||
// Required on Windows (and possibly others) to prevent tiling.
|
||||
#undef UNITY_SAMPLE_FULL_SH_PER_PIXEL
|
||||
#define UNITY_SAMPLE_FULL_SH_PER_PIXEL 1
|
||||
|
||||
|
||||
//
|
||||
// Stereo Instancing Fix
|
||||
//
|
||||
|
||||
#if defined(STEREO_INSTANCING_ON) && (defined(SHADER_API_D3D11) || defined(SHADER_API_GLES3) || defined(SHADER_API_GLCORE) || defined(SHADER_API_PSSL) || defined(SHADER_API_VULKAN) || (defined(SHADER_API_METAL) && !defined(UNITY_COMPILER_DXC)))
|
||||
#define UNITY_STEREO_INSTANCING_ENABLED
|
||||
#endif
|
||||
|
||||
#if defined(STEREO_MULTIVIEW_ON) && (defined(SHADER_API_GLES3) || defined(SHADER_API_GLCORE) || defined(SHADER_API_VULKAN)) && !(defined(SHADER_API_SWITCH))
|
||||
#define UNITY_STEREO_MULTIVIEW_ENABLED
|
||||
#endif
|
||||
|
||||
// Redeclared their includes to insert shadow declarations at the right spot.
|
||||
// Adapted from:
|
||||
// Packages/com.unity.shadergraph/Editor/Generation/Targets/BuiltIn/ShaderLibrary/Shim/Shims.hlsl
|
||||
|
||||
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl"
|
||||
|
||||
// Duplicate define in Macros.hlsl
|
||||
#if defined (TRANSFORM_TEX)
|
||||
#undef TRANSFORM_TEX
|
||||
#endif
|
||||
|
||||
#if defined(UNITY_STEREO_INSTANCING_ENABLED) || defined(UNITY_STEREO_MULTIVIEW_ENABLED)
|
||||
#undef GLOBAL_CBUFFER_START
|
||||
#if defined(UNITY_STEREO_MULTIVIEW_ENABLED) || ((defined(UNITY_SINGLE_PASS_STEREO) || defined(UNITY_STEREO_INSTANCING_ENABLED)) && (defined(SHADER_API_GLCORE) || defined(SHADER_API_GLES3) || defined(SHADER_API_METAL)))
|
||||
#define GLOBAL_CBUFFER_START(name) cbuffer name {
|
||||
#define GLOBAL_CBUFFER_END }
|
||||
#else
|
||||
#define GLOBAL_CBUFFER_START(name) CBUFFER_START(name)
|
||||
#define GLOBAL_CBUFFER_END CBUFFER_END
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#include "Packages/com.unity.shadergraph/Editor/Generation/Targets/BuiltIn/ShaderLibrary/Shim/HLSLSupportShim.hlsl"
|
||||
|
||||
// Fix wrong definitions.
|
||||
#undef UNITY_SAMPLE_TEX2DARRAY
|
||||
#define UNITY_SAMPLE_TEX2DARRAY(tex,coord) SAMPLE_TEXTURE2D_ARRAY(tex, sampler##tex, coord.xy, coord.z)
|
||||
|
||||
|
||||
//
|
||||
// Transparent Objects Receives Shadows
|
||||
//
|
||||
|
||||
#if _SURFACE_TYPE_TRANSPARENT
|
||||
#if _TRANSPARENT_RECEIVES_SHADOWS
|
||||
#if SHADERPASS == SHADERPASS_FORWARD || SHADERPASS == SHADERPASS_FORWARD_ADD
|
||||
#if DIRECTIONAL || DIRECTIONAL_COOKIE
|
||||
#if !SHADOWS_SCREEN
|
||||
|
||||
StructuredBuffer<float4x4> _Crest_WorldToShadow;
|
||||
|
||||
// Declarations for shadow collector.
|
||||
UNITY_DECLARE_SHADOWMAP(_ShadowMapTexture);
|
||||
float4 _ShadowMapTexture_TexelSize;
|
||||
#define SHADOWMAPSAMPLER_DEFINED 1
|
||||
#define SHADOWMAPSAMPLER_AND_TEXELSIZE_DEFINED 1
|
||||
|
||||
#define d_Crest_ShadowsOverriden 1
|
||||
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#endif // d_WaveHarmonic_Utility_ShaderGraphDefines
|
||||
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1d26727ac31d94682896ffbfdc685804
|
||||
ShaderIncludeImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,18 +1,4 @@
|
||||
// Crest Water System
|
||||
// Copyright © 2024 Wave Harmonic. All rights reserved.
|
||||
|
||||
// Defines missing inputs.
|
||||
|
||||
float4x4 _Crest_InverseViewProjection;
|
||||
float4x4 _Crest_InverseViewProjectionRight;
|
||||
|
||||
#undef UNITY_MATRIX_I_VP
|
||||
|
||||
#if defined(STEREO_INSTANCING_ON) || defined(STEREO_MULTIVIEW_ON)
|
||||
#define UNITY_MATRIX_I_VP (unity_StereoEyeIndex == 0 ? _Crest_InverseViewProjection : _Crest_InverseViewProjectionRight)
|
||||
#else
|
||||
#define UNITY_MATRIX_I_VP _Crest_InverseViewProjection
|
||||
#endif
|
||||
|
||||
// Not set and _ScreenParams.zw is "1.0 + 1.0 / _ScreenParams.xy"
|
||||
#define _ScreenSize float4(_ScreenParams.xy, float2(1.0, 1.0) / _ScreenParams.xy)
|
||||
// Empty.
|
||||
|
||||
@@ -0,0 +1,109 @@
|
||||
// Crest Water System
|
||||
// Copyright © 2024 Wave Harmonic. All rights reserved.
|
||||
|
||||
#include "Packages/com.unity.shadergraph/Editor/Generation/Targets/BuiltIn/Editor/ShaderGraph/Includes/LegacyBuilding.hlsl"
|
||||
|
||||
//
|
||||
// Transparent Objects Receives Shadows
|
||||
//
|
||||
|
||||
#if d_Crest_ShadowsOverriden
|
||||
|
||||
#define unity_WorldToShadow _Crest_WorldToShadow
|
||||
|
||||
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Library/Utility/Legacy/Shadows.hlsl"
|
||||
|
||||
#if defined(SHADER_API_MOBILE)
|
||||
#define m_UnitySampleShadowmap_PCF UnitySampleShadowmap_PCF5x5
|
||||
#else
|
||||
#define m_UnitySampleShadowmap_PCF UnitySampleShadowmap_PCF7x7
|
||||
#endif
|
||||
|
||||
// Same as UnityComputeShadowFadeDistance, except it uses keywords.
|
||||
float ComputeShadowFadeDistance(float3 positionWS, float viewZ)
|
||||
{
|
||||
// Use keyword instead of unity_ShadowFadeCenterAndType.w, as we are already
|
||||
// dependent on keywords anyway.
|
||||
return
|
||||
#if SHADOWS_SPLIT_SPHERES
|
||||
distance(positionWS, unity_ShadowFadeCenterAndType.xyz);
|
||||
#else
|
||||
viewZ;
|
||||
#endif
|
||||
}
|
||||
|
||||
float GetShadows(float3 positionWS, float4 uvLightMap)
|
||||
{
|
||||
float viewZ = -UnityWorldToViewPos(positionWS).z;
|
||||
float4 weights = GET_CASCADE_WEIGHTS(positionWS, viewZ);
|
||||
float4 coordinates = GET_SHADOW_COORDINATES(float4(positionWS, 1.0), weights);
|
||||
#if SHADOWS_SOFT
|
||||
half shadow = m_UnitySampleShadowmap_PCF(coordinates, 0);
|
||||
#else
|
||||
half shadow = UNITY_SAMPLE_SHADOW(_ShadowMapTexture, coordinates);
|
||||
#endif
|
||||
shadow = lerp(_LightShadowData.r, 1.0, shadow);
|
||||
|
||||
// Shadow Mask + mixed sun + static
|
||||
#if LIGHTMAP_ON && SHADOWS_SHADOWMASK && LIGHTMAP_SHADOW_MIXING
|
||||
float fade = UnityComputeShadowFade(ComputeShadowFadeDistance(positionWS, viewZ));
|
||||
half mask = UnitySampleBakedOcclusion(uvLightMap.xy, positionWS);
|
||||
shadow = UnityMixRealtimeAndBakedShadows(shadow, mask, fade);
|
||||
#endif
|
||||
|
||||
return shadow;
|
||||
}
|
||||
|
||||
#ifdef DIRECTIONAL
|
||||
#undef UNITY_LIGHT_ATTENUATION
|
||||
#define UNITY_LIGHT_ATTENUATION(destName, input, worldPos) \
|
||||
fixed destName = GetShadows(worldPos, input.lmap);
|
||||
#endif
|
||||
|
||||
#ifdef DIRECTIONAL_COOKIE
|
||||
#undef UNITY_LIGHT_ATTENUATION
|
||||
#define UNITY_LIGHT_ATTENUATION(destName, input, worldPos) \
|
||||
DECLARE_LIGHT_COORD(input, worldPos); \
|
||||
fixed destName = tex2D(_LightTexture0, lightCoord).w * GetShadows(worldPos, input.lmap);
|
||||
#endif
|
||||
|
||||
#endif // d_Crest_ShadowsOverriden
|
||||
|
||||
|
||||
//
|
||||
// Specular
|
||||
//
|
||||
|
||||
#ifdef _SPECULAR_SETUP
|
||||
#define SurfaceOutputStandard SurfaceOutputStandardSpecular
|
||||
#define BuildStandardSurfaceOutput BuildStandardSpecularSurfaceOutput
|
||||
#define LightingStandard LightingStandardSpecular
|
||||
#define LightingStandard_GI LightingStandardSpecular_GI
|
||||
#define LightingStandard_Deferred LightingStandardSpecular_Deferred
|
||||
|
||||
#if SHADERPASS == SHADERPASS_FORWARD_ADD
|
||||
#undef LightingStandard
|
||||
#define LightingStandard(x, y, z) LightingStandardSpecular(x, y, z); c.rgb += o.Emission;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef _SPECULAR_SETUP
|
||||
#if SHADERPASS == SHADERPASS_FORWARD_ADD
|
||||
#define LightingStandard(x, y, z) LightingStandard(x, y, z); c.rgb += o.Emission;
|
||||
#endif // SHADERPASS_FORWARD_ADD
|
||||
#endif // _SPECULAR_SETUP
|
||||
|
||||
SurfaceOutputStandardSpecular BuildStandardSpecularSurfaceOutput(SurfaceDescription surfaceDescription, InputData inputData)
|
||||
{
|
||||
SurfaceData surface = SurfaceDescriptionToSurfaceData(surfaceDescription);
|
||||
|
||||
SurfaceOutputStandardSpecular o = (SurfaceOutputStandardSpecular)0;
|
||||
o.Albedo = surface.albedo;
|
||||
o.Normal = inputData.normalWS;
|
||||
o.Specular = surface.specular;
|
||||
o.Smoothness = surface.smoothness;
|
||||
o.Occlusion = surface.occlusion;
|
||||
o.Emission = surface.emission;
|
||||
o.Alpha = surface.alpha;
|
||||
return o;
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5eab24690c4a74ceca26a143da611306
|
||||
ShaderIncludeImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,51 @@
|
||||
// Crest Water System
|
||||
// Copyright © 2024 Wave Harmonic. All rights reserved.
|
||||
|
||||
// TODO:
|
||||
// #if defined(USING_STEREO_MATRICES)
|
||||
// float4x4 _StereoNonJitteredVP[2];
|
||||
// float4x4 _StereoPreviousVP[2];
|
||||
// #else
|
||||
// float4x4 _NonJitteredVP;
|
||||
// float4x4 _PreviousVP;
|
||||
// #endif
|
||||
|
||||
float4x4 _PreviousM;
|
||||
float4x4 _PreviousVP;
|
||||
float4x4 _NonJitteredVP;
|
||||
|
||||
bool _HasLastPositionData;
|
||||
bool _ForceNoMotion;
|
||||
float _MotionVectorDepthBias;
|
||||
|
||||
#undef UNITY_PREV_MATRIX_M
|
||||
#define UNITY_PREV_MATRIX_M _PreviousM
|
||||
#define _PrevViewProjMatrix _PreviousVP
|
||||
#define _NonJitteredViewProjMatrix _NonJitteredVP
|
||||
|
||||
// X : Use last frame positions (right now skinned meshes are the only objects that use this
|
||||
// Y : Force No Motion
|
||||
// Z : Z bias value
|
||||
const static float4 unity_MotionVectorsParams = float4(_HasLastPositionData, !_ForceNoMotion, _MotionVectorDepthBias, 0);
|
||||
|
||||
// Unity will populate this, but could not see when in source.
|
||||
float4 _LastTime;
|
||||
|
||||
// We want to gather some internal data from the BuildVaryings call to
|
||||
// avoid rereading and recalculating these values again in the ShaderGraph motion vector pass
|
||||
struct MotionVectorPassOutput
|
||||
{
|
||||
float3 positionOS;
|
||||
float3 positionWS;
|
||||
};
|
||||
|
||||
SurfaceDescription BuildSurfaceDescription(Varyings varyings)
|
||||
{
|
||||
SurfaceDescriptionInputs surfaceDescriptionInputs = BuildSurfaceDescriptionInputs(varyings);
|
||||
SurfaceDescription surfaceDescription = SurfaceDescriptionFunction(surfaceDescriptionInputs);
|
||||
return surfaceDescription;
|
||||
}
|
||||
|
||||
// Very hacky, but works!
|
||||
#define BuildVaryings(content) BuildVaryings(content, inout MotionVectorPassOutput motionVectorOutput)
|
||||
#define TransformObjectToWorld(content) TransformObjectToWorld(content); motionVectorOutput.positionOS = input.positionOS; motionVectorOutput.positionWS = positionWS;
|
||||
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1eacca53c60984c4a8cadb624777e644
|
||||
ShaderIncludeImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,159 @@
|
||||
// Crest Water System
|
||||
// Copyright © 2024 Wave Harmonic. All rights reserved.
|
||||
|
||||
// Adapted from:
|
||||
// Packages/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/MotionVectorPass.hlsl
|
||||
|
||||
// This file is subject to the Unity Companion License:
|
||||
// https://github.com/Unity-Technologies/Graphics/blob/61584ec20cf305929dae85cec7b94ff2ed3942f3/LICENSE.md
|
||||
|
||||
#ifndef SG_MOTION_VECTORS_PASS_INCLUDED
|
||||
#define SG_MOTION_VECTORS_PASS_INCLUDED
|
||||
|
||||
#undef BuildVaryings
|
||||
#undef TransformObjectToWorld
|
||||
|
||||
float2 CalcNdcMotionVectorFromCsPositions(float4 posCS, float4 prevPosCS)
|
||||
{
|
||||
// Note: unity_MotionVectorsParams.y is 0 is forceNoMotion is enabled
|
||||
bool forceNoMotion = unity_MotionVectorsParams.y == 0.0;
|
||||
if (forceNoMotion)
|
||||
return float2(0.0, 0.0);
|
||||
|
||||
// Non-uniform raster needs to keep the posNDC values in float to avoid additional conversions
|
||||
// since uv remap functions use floats
|
||||
float2 posNDC = posCS.xy * rcp(posCS.w);
|
||||
float2 prevPosNDC = prevPosCS.xy * rcp(prevPosCS.w);
|
||||
|
||||
float2 velocity;
|
||||
{
|
||||
// Calculate forward velocity
|
||||
velocity = (posNDC.xy - prevPosNDC.xy);
|
||||
#if UNITY_UV_STARTS_AT_TOP
|
||||
velocity.y = -velocity.y;
|
||||
#endif
|
||||
|
||||
// Convert velocity from NDC space (-1..1) to UV 0..1 space
|
||||
// Note: It doesn't mean we don't have negative values, we store negative or positive offset in UV space.
|
||||
// Note: ((posNDC * 0.5 + 0.5) - (prevPosNDC * 0.5 + 0.5)) = (velocity * 0.5)
|
||||
velocity.xy *= 0.5;
|
||||
}
|
||||
|
||||
return velocity;
|
||||
}
|
||||
|
||||
struct MotionVectorPassAttributes
|
||||
{
|
||||
float3 previousPositionOS : TEXCOORD4; // Contains previous frame local vertex position (for skinned meshes)
|
||||
};
|
||||
|
||||
// Note: these will have z == 0.0f in the pixel shader to save on bandwidth
|
||||
struct MotionVectorPassVaryings
|
||||
{
|
||||
float4 positionCSNoJitter;
|
||||
float4 previousPositionCSNoJitter;
|
||||
};
|
||||
|
||||
struct PackedMotionVectorPassVaryings
|
||||
{
|
||||
float3 positionCSNoJitter : CLIP_POSITION_NO_JITTER;
|
||||
float3 previousPositionCSNoJitter : PREVIOUS_CLIP_POSITION_NO_JITTER;
|
||||
};
|
||||
|
||||
PackedMotionVectorPassVaryings PackMotionVectorVaryings(MotionVectorPassVaryings regularVaryings)
|
||||
{
|
||||
PackedMotionVectorPassVaryings packedVaryings;
|
||||
packedVaryings.positionCSNoJitter = regularVaryings.positionCSNoJitter.xyw;
|
||||
packedVaryings.previousPositionCSNoJitter = regularVaryings.previousPositionCSNoJitter.xyw;
|
||||
return packedVaryings;
|
||||
}
|
||||
|
||||
MotionVectorPassVaryings UnpackMotionVectorVaryings(PackedMotionVectorPassVaryings packedVaryings)
|
||||
{
|
||||
MotionVectorPassVaryings regularVaryings;
|
||||
regularVaryings.positionCSNoJitter = float4(packedVaryings.positionCSNoJitter.xy, 0, packedVaryings.positionCSNoJitter.z);
|
||||
regularVaryings.previousPositionCSNoJitter = float4(packedVaryings.previousPositionCSNoJitter.xy, 0, packedVaryings.previousPositionCSNoJitter.z);
|
||||
return regularVaryings;
|
||||
}
|
||||
|
||||
float3 GetLastFrameDeformedPosition(Attributes input, MotionVectorPassOutput currentFrameMvData, float3 previousPositionOS)
|
||||
{
|
||||
Attributes lastFrameInputAttributes = input;
|
||||
lastFrameInputAttributes.positionOS = previousPositionOS;
|
||||
|
||||
VertexDescriptionInputs lastFrameVertexDescriptionInputs = BuildVertexDescriptionInputs(lastFrameInputAttributes);
|
||||
#if defined(AUTOMATIC_TIME_BASED_MOTION_VECTORS) && defined(GRAPH_VERTEX_USES_TIME_PARAMETERS_INPUT)
|
||||
lastFrameVertexDescriptionInputs.TimeParameters = _LastTime.yxz;
|
||||
#endif
|
||||
|
||||
VertexDescription lastFrameVertexDescription = VertexDescriptionFunction(lastFrameVertexDescriptionInputs);
|
||||
previousPositionOS = lastFrameVertexDescription.Position.xyz;
|
||||
|
||||
return previousPositionOS;
|
||||
}
|
||||
|
||||
// -------------------------------------
|
||||
// Vertex
|
||||
void vert(
|
||||
Attributes input,
|
||||
MotionVectorPassAttributes passInput,
|
||||
out PackedMotionVectorPassVaryings packedMvOutput,
|
||||
out PackedVaryings packedOutput)
|
||||
{
|
||||
Varyings output = (Varyings)0;
|
||||
MotionVectorPassVaryings mvOutput = (MotionVectorPassVaryings)0;
|
||||
MotionVectorPassOutput currentFrameMvData = (MotionVectorPassOutput)0;
|
||||
output = BuildVaryings(input, currentFrameMvData);
|
||||
packedOutput = PackVaryings(output);
|
||||
|
||||
const bool forceNoMotion = unity_MotionVectorsParams.y == 0.0;
|
||||
|
||||
if (!forceNoMotion)
|
||||
{
|
||||
const bool hasDeformation = unity_MotionVectorsParams.x == 1; // Mesh has skinned deformation
|
||||
float3 previousPositionOS = hasDeformation ? passInput.previousPositionOS : input.positionOS;
|
||||
|
||||
#if defined(AUTOMATIC_TIME_BASED_MOTION_VECTORS) && defined(GRAPH_VERTEX_USES_TIME_PARAMETERS_INPUT)
|
||||
const bool applyDeformation = true;
|
||||
#else
|
||||
const bool applyDeformation = hasDeformation;
|
||||
#endif
|
||||
|
||||
#if defined(FEATURES_GRAPH_VERTEX)
|
||||
if (applyDeformation)
|
||||
previousPositionOS = GetLastFrameDeformedPosition(input, currentFrameMvData, previousPositionOS);
|
||||
else
|
||||
previousPositionOS = currentFrameMvData.positionOS;
|
||||
|
||||
#if defined(FEATURES_GRAPH_VERTEX_MOTION_VECTOR_OUTPUT)
|
||||
previousPositionOS -= currentFrameMvData.motionVector;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
mvOutput.positionCSNoJitter = mul(_NonJitteredViewProjMatrix, float4(currentFrameMvData.positionWS, 1.0f));
|
||||
mvOutput.previousPositionCSNoJitter = mul(_PrevViewProjMatrix, mul(UNITY_PREV_MATRIX_M, float4(previousPositionOS, 1.0f)));
|
||||
}
|
||||
|
||||
packedMvOutput = PackMotionVectorVaryings(mvOutput);
|
||||
}
|
||||
|
||||
// -------------------------------------
|
||||
// Fragment
|
||||
float4 frag(
|
||||
// Note: packedMvInput needs to be before packedInput as otherwise we get the following error in the speed tree 8 SG:
|
||||
// "Non system-generated input signature parameter () cannot appear after a system generated value"
|
||||
PackedMotionVectorPassVaryings packedMvInput,
|
||||
PackedVaryings packedInput) : SV_Target
|
||||
{
|
||||
Varyings input = UnpackVaryings(packedInput);
|
||||
MotionVectorPassVaryings mvInput = UnpackMotionVectorVaryings(packedMvInput);
|
||||
UNITY_SETUP_INSTANCE_ID(input);
|
||||
SurfaceDescription surfaceDescription = BuildSurfaceDescription(input);
|
||||
|
||||
#if defined(_ALPHATEST_ON)
|
||||
clip(surfaceDescription.Alpha - surfaceDescription.AlphaClipThreshold);
|
||||
#endif
|
||||
|
||||
return float4(CalcNdcMotionVectorFromCsPositions(mvInput.positionCSNoJitter, mvInput.previousPositionCSNoJitter), 0, 0);
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ae5323918c4b24b5c87c6f941810e225
|
||||
ShaderIncludeImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,4 +1,5 @@
|
||||
// Crest Water System
|
||||
// Copyright © 2024 Wave Harmonic. All rights reserved.
|
||||
|
||||
// Copyright (c) 2016 Unity Technologies
|
||||
//
|
||||
@@ -19,24 +20,9 @@
|
||||
// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
// Screen-space shadow helpers.
|
||||
|
||||
// Taken and adapted from:
|
||||
// Taken from:
|
||||
// 2020.3.12f1/DefaultResourcesExtra/Internal-ScreenSpaceShadows.shader
|
||||
|
||||
// Main changes is that now only world position is required. Specialised for the shadow LOD data.
|
||||
|
||||
// Add multi_compile_shadowcollector pragma to get SHADOWS_SPLIT_SPHERES and SHADOWS_SINGLE_CASCADE.
|
||||
// https://docs.unity3d.com/Manual/SL-MultipleProgramVariants.html
|
||||
|
||||
// SHADOWS_SCREEN + SHADOWS_CUBE will never be triggered for transparency, but
|
||||
// Unity still compiles the variant which causes compiler errors.
|
||||
#if defined(_SURFACE_TYPE_TRANSPARENT) && !defined(SHADERGRAPH_PREVIEW) && !defined(SHADOWS_SCREEN) && !defined(SHADOWS_CUBE)
|
||||
#define d_Crest_ReceiveShadowsTransparent 1
|
||||
#endif
|
||||
|
||||
#if d_Crest_ReceiveShadowsTransparent
|
||||
|
||||
#include "UnityShadowLibrary.cginc"
|
||||
|
||||
#ifndef SHADOWMAPSAMPLER_DEFINED
|
||||
@@ -49,30 +35,27 @@ float4 _ShadowMapTexture_TexelSize;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
//
|
||||
// Keywords based defines
|
||||
//
|
||||
#if defined (SHADOWS_SPLIT_SPHERES)
|
||||
#define GET_CASCADE_WEIGHTS(wpos) getCascadeWeights_splitSpheres(wpos)
|
||||
#define GET_CASCADE_WEIGHTS(wpos, z) getCascadeWeights_splitSpheres(wpos)
|
||||
#else
|
||||
#define GET_CASCADE_WEIGHTS(wpos) getCascadeWeights(wpos)
|
||||
#define GET_CASCADE_WEIGHTS(wpos, z) getCascadeWeights( wpos, z )
|
||||
#endif
|
||||
|
||||
#if defined (SHADOWS_SINGLE_CASCADE)
|
||||
#define GET_SHADOW_COORDINATES(wpos) getShadowCoord_SingleCascade(wpos)
|
||||
#define GET_SHADOW_COORDINATES(wpos,cascadeWeights) getShadowCoord_SingleCascade(wpos)
|
||||
#else
|
||||
#define GET_SHADOW_COORDINATES(wpos) getShadowCoord(wpos)
|
||||
#define GET_SHADOW_COORDINATES(wpos,cascadeWeights) getShadowCoord(wpos,cascadeWeights)
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Gets the cascade weights based on the world position of the fragment.
|
||||
* Returns a float4 with only one component set that corresponds to the appropriate cascade.
|
||||
*/
|
||||
inline fixed4 getCascadeWeights(float3 wpos)
|
||||
inline fixed4 getCascadeWeights(float3 wpos, float z)
|
||||
{
|
||||
// Calculate depth. Normally this would be depth from the depth buffer.
|
||||
float z = dot(wpos - _WorldSpaceCameraPos.xyz, unity_CameraToWorld._m02_m12_m22);
|
||||
fixed4 zNear = float4( z >= _LightSplitsNear );
|
||||
fixed4 zFar = float4( z < _LightSplitsFar );
|
||||
fixed4 weights = zNear * zFar;
|
||||
@@ -99,9 +82,8 @@ inline fixed4 getCascadeWeights_splitSpheres(float3 wpos)
|
||||
* Returns the shadowmap coordinates for the given fragment based on the world position and z-depth.
|
||||
* These coordinates belong to the shadowmap atlas that contains the maps for all cascades.
|
||||
*/
|
||||
inline float4 getShadowCoord(float4 wpos)
|
||||
inline float4 getShadowCoord( float4 wpos, fixed4 cascadeWeights )
|
||||
{
|
||||
fixed4 cascadeWeights = GET_CASCADE_WEIGHTS(wpos.xyz);
|
||||
float3 sc0 = mul (unity_WorldToShadow[0], wpos).xyz;
|
||||
float3 sc1 = mul (unity_WorldToShadow[1], wpos).xyz;
|
||||
float3 sc2 = mul (unity_WorldToShadow[2], wpos).xyz;
|
||||
@@ -119,7 +101,5 @@ inline float4 getShadowCoord(float4 wpos)
|
||||
*/
|
||||
inline float4 getShadowCoord_SingleCascade( float4 wpos )
|
||||
{
|
||||
return float4(mul(unity_WorldToShadow[0], wpos).xyz, 0);
|
||||
return float4( mul (unity_WorldToShadow[0], wpos).xyz, 0);
|
||||
}
|
||||
|
||||
#endif // d_Crest_ReceiveShadowsTransparent
|
||||
|
||||
@@ -9,55 +9,54 @@
|
||||
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Library/Macros.hlsl"
|
||||
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Library/Globals.hlsl"
|
||||
|
||||
TEXTURE2D_X(_Crest_ScreenSpaceShadowTexture);
|
||||
float4 _Crest_ScreenSpaceShadowTexture_TexelSize;
|
||||
|
||||
#if CREST_URP
|
||||
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"
|
||||
|
||||
// Unity renamed keyword.
|
||||
#ifdef USE_FORWARD_PLUS
|
||||
#define USE_CLUSTER_LIGHT_LOOP USE_FORWARD_PLUS
|
||||
#endif // USE_FORWARD_PLUS
|
||||
|
||||
#ifdef FORWARD_PLUS_SUBTRACTIVE_LIGHT_CHECK
|
||||
#define CLUSTER_LIGHT_LOOP_SUBTRACTIVE_LIGHT_CHECK FORWARD_PLUS_SUBTRACTIVE_LIGHT_CHECK
|
||||
#endif // FORWARD_PLUS_SUBTRACTIVE_LIGHT_CHECK
|
||||
|
||||
#if UNITY_VERSION >= 60000000
|
||||
#if defined(STEREO_INSTANCING_ON) || defined(STEREO_MULTIVIEW_ON)
|
||||
#if _ALPHATEST_ON
|
||||
#if !USE_CLUSTER_LIGHT_LOOP
|
||||
// If not clustered and additional light shadows and XR, the shading model
|
||||
// completely breaks. It is like shadow attenuation is NaN or some obscure
|
||||
// compiler issue. For 2022.3, it is broken for forward+ only, but cannot be fixed.
|
||||
#define d_ShadowMaskBroken 1
|
||||
#else
|
||||
#if _RECEIVE_SHADOWS_OFF
|
||||
// Right eye broken rendering similar to above.
|
||||
#define d_AdditionalLightsBroken 1
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#endif // CREST_URP
|
||||
|
||||
#if CREST_HDRP
|
||||
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl"
|
||||
|
||||
#ifndef SHADERGRAPH_PREVIEW
|
||||
#if CREST_HDRP_FORWARD_PASS
|
||||
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/HDShadow.hlsl"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if UNITY_VERSION < 202310
|
||||
#define GetMeshRenderingLayerMask GetMeshRenderingLightLayer
|
||||
#endif
|
||||
#endif // UNITY_VERSION
|
||||
|
||||
#if UNITY_VERSION < 60000000
|
||||
#if PROBE_VOLUMES_L1
|
||||
#define AMBIENT_PROBE_BUFFER 1
|
||||
#endif
|
||||
#endif // PROBE_VOLUMES_L1
|
||||
#endif // UNITY_VERSION
|
||||
#endif // CREST_HDRP
|
||||
|
||||
m_CrestNameSpace
|
||||
|
||||
// TODO: Move
|
||||
void ApplyIndirectLightingMultiplier
|
||||
(
|
||||
inout half3 io_AmbientLight
|
||||
)
|
||||
{
|
||||
// Allows control of baked lighting through volume framework.
|
||||
#ifndef SHADERGRAPH_PREVIEW
|
||||
// We could create a BuiltinData struct which would have rendering layers on it, but it seems more complicated.
|
||||
io_AmbientLight *= GetIndirectDiffuseMultiplier(GetMeshRenderingLayerMask());
|
||||
#endif
|
||||
}
|
||||
#else // CREST_HDRP
|
||||
m_CrestNameSpace
|
||||
#endif
|
||||
|
||||
void PrimaryLight
|
||||
(
|
||||
const float3 i_PositionWS,
|
||||
@@ -82,72 +81,46 @@ void PrimaryLight
|
||||
o_Direction = normalize(UnityWorldSpaceLightDir(i_PositionWS));
|
||||
#else
|
||||
o_Direction = _WorldSpaceLightPos0.xyz;
|
||||
// Prevents divide by zero.
|
||||
if (all(o_Direction == 0)) o_Direction = half3(0.0, 1.0, 0.0);
|
||||
#endif
|
||||
o_Color = _LightColor0.rgb;
|
||||
#if SHADERPASS == SHADERPASS_FORWARD_ADD
|
||||
#if !SHADOWS_SCREEN
|
||||
// FIXME: undeclared identifier 'IN' in Pass: BuiltIn ForwardAdd, Vertex program with DIRECTIONAL SHADOWS_SCREEN
|
||||
UNITY_LIGHT_ATTENUATION(attenuation, IN, i_PositionWS)
|
||||
o_Color *= attenuation;
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
void AmbientLight(out half3 o_AmbientLight)
|
||||
half3 AmbientLight(const half3 i_AmbientLight)
|
||||
{
|
||||
half3 ambient = i_AmbientLight;
|
||||
|
||||
#ifndef SHADERGRAPH_PREVIEW
|
||||
#if CREST_HDRP
|
||||
// Allows control of baked lighting through volume framework.
|
||||
// We could create a BuiltinData struct which would have rendering layers on it, but it seems more complicated.
|
||||
ambient *= GetIndirectDiffuseMultiplier(GetMeshRenderingLayerMask());
|
||||
#endif // CREST_HDRP
|
||||
#endif // SHADERGRAPH_PREVIEW
|
||||
|
||||
return ambient;
|
||||
}
|
||||
|
||||
half3 AmbientLight()
|
||||
{
|
||||
// Use the constant term (0th order) of SH stuff - this is the average.
|
||||
o_AmbientLight =
|
||||
const half3 ambient =
|
||||
#if AMBIENT_PROBE_BUFFER
|
||||
half3(_AmbientProbeData[0].w, _AmbientProbeData[1].w, _AmbientProbeData[2].w);
|
||||
#else
|
||||
half3(unity_SHAr.w, unity_SHAg.w, unity_SHAb.w);
|
||||
#endif
|
||||
|
||||
#if CREST_HDRP
|
||||
ApplyIndirectLightingMultiplier(o_AmbientLight);
|
||||
#endif
|
||||
}
|
||||
|
||||
// Position: SRP = WS / BIRP = SS (z ignored)
|
||||
half PrimaryLightShadows(const float3 i_Position)
|
||||
{
|
||||
// Unshadowed.
|
||||
half shadow = 1;
|
||||
|
||||
#if CREST_URP
|
||||
// We could skip GetMainLight but this is recommended approach which is likely more robust to API changes.
|
||||
float4 shadowCoord = TransformWorldToShadowCoord(i_Position);
|
||||
Light light = GetMainLight(TransformWorldToShadowCoord(i_Position));
|
||||
shadow = light.shadowAttenuation;
|
||||
#endif
|
||||
|
||||
#ifndef SHADERGRAPH_PREVIEW
|
||||
#if CREST_HDRP_FORWARD_PASS
|
||||
DirectionalLightData light = _DirectionalLightDatas[_DirectionalShadowIndex];
|
||||
HDShadowContext context = InitShadowContext();
|
||||
context.directionalShadowData = _HDDirectionalShadowData[_DirectionalShadowIndex];
|
||||
|
||||
float3 positionWS = GetCameraRelativePositionWS(i_Position);
|
||||
// From Unity:
|
||||
// > With XR single-pass and camera-relative: offset position to do lighting computations from the combined center view (original camera matrix).
|
||||
// > This is required because there is only one list of lights generated on the CPU. Shadows are also generated once and shared between the instanced views.
|
||||
ApplyCameraRelativeXR(positionWS);
|
||||
|
||||
// TODO: Pass in screen space position and scene normal.
|
||||
shadow = GetDirectionalShadowAttenuation
|
||||
(
|
||||
context,
|
||||
0, // positionSS
|
||||
positionWS,
|
||||
0, // normalWS
|
||||
light.shadowIndex,
|
||||
-light.forward
|
||||
);
|
||||
|
||||
// Apply shadow strength from main light.
|
||||
shadow = LerpWhiteTo(shadow, light.shadowDimmer);
|
||||
#endif // CREST_HDRP_FORWARD_PASS
|
||||
#endif // SHADERGRAPH_PREVIEW
|
||||
|
||||
#if CREST_BIRP
|
||||
shadow = LOAD_TEXTURE2D_X(_Crest_ScreenSpaceShadowTexture, min(i_Position.xy, _Crest_ScreenSpaceShadowTexture_TexelSize.zw - 1.0)).r;
|
||||
#endif
|
||||
|
||||
return shadow;
|
||||
return AmbientLight(ambient);
|
||||
}
|
||||
|
||||
half3 AdditionalLighting(const float3 i_PositionWS, const float4 i_ScreenPosition, const float2 i_StaticLightMapUV)
|
||||
@@ -156,32 +129,38 @@ half3 AdditionalLighting(const float3 i_PositionWS, const float4 i_ScreenPositio
|
||||
|
||||
#if CREST_URP
|
||||
#if defined(_ADDITIONAL_LIGHTS)
|
||||
InputData inputData = (InputData)0;
|
||||
inputData.normalizedScreenSpaceUV = i_ScreenPosition.xy / i_ScreenPosition.w;
|
||||
inputData.positionWS = i_PositionWS;
|
||||
|
||||
// Shadowmask.
|
||||
#if defined(SHADOWS_SHADOWMASK) && defined(LIGHTMAP_ON)
|
||||
half4 shadowMask = SAMPLE_SHADOWMASK(i_StaticLightMapUV);
|
||||
#elif !defined(LIGHTMAP_ON)
|
||||
half4 shadowMask = unity_ProbesOcclusion;
|
||||
#else
|
||||
half4 shadowMask = half4(1, 1, 1, 1);
|
||||
inputData.shadowMask = SAMPLE_SHADOWMASK(i_StaticLightMapUV);
|
||||
#endif
|
||||
|
||||
const half4 shadowMask = CalculateShadowMask(inputData);
|
||||
|
||||
// No AO, but we need the struct.
|
||||
AmbientOcclusionFactor aoFactor = CreateAmbientOcclusionFactor(inputData.normalizedScreenSpaceUV, 0.0);
|
||||
|
||||
uint pixelLightCount = GetAdditionalLightsCount();
|
||||
|
||||
#ifdef _LIGHT_LAYERS
|
||||
uint meshRenderingLayers = GetMeshRenderingLayer();
|
||||
#endif
|
||||
|
||||
#if USE_CLUSTER_LIGHT_LOOP
|
||||
InputData inputData = (InputData)0;
|
||||
// For Foward+ LIGHT_LOOP_BEGIN macro uses inputData.normalizedScreenSpaceUV and inputData.positionWS.
|
||||
inputData.normalizedScreenSpaceUV = i_ScreenPosition.xy / i_ScreenPosition.w;
|
||||
inputData.positionWS = i_PositionWS;
|
||||
#endif
|
||||
|
||||
LIGHT_LOOP_BEGIN(pixelLightCount)
|
||||
// Includes shadows and cookies.
|
||||
Light light = GetAdditionalLight(lightIndex, i_PositionWS, shadowMask);
|
||||
Light light = GetAdditionalLight(lightIndex, inputData, shadowMask, aoFactor);
|
||||
|
||||
#if d_ShadowMaskBroken
|
||||
light.shadowAttenuation = 1.0;
|
||||
#endif
|
||||
|
||||
#if d_AdditionalLightsBroken
|
||||
light.color = 0.0;
|
||||
#endif
|
||||
|
||||
#ifdef _LIGHT_LAYERS
|
||||
if (IsMatchingLightLayer(light.layerMask, meshRenderingLayers))
|
||||
#endif
|
||||
@@ -189,9 +168,29 @@ LIGHT_LOOP_BEGIN(pixelLightCount)
|
||||
color += light.color * (light.distanceAttenuation * light.shadowAttenuation);
|
||||
}
|
||||
LIGHT_LOOP_END
|
||||
|
||||
#if USE_CLUSTER_LIGHT_LOOP
|
||||
// Additional directional lights.
|
||||
[loop] for (uint lightIndex = 0; lightIndex < min(URP_FP_DIRECTIONAL_LIGHTS_COUNT, MAX_VISIBLE_LIGHTS); lightIndex++)
|
||||
{
|
||||
CLUSTER_LIGHT_LOOP_SUBTRACTIVE_LIGHT_CHECK
|
||||
|
||||
Light light = GetAdditionalLight(lightIndex, inputData, shadowMask, aoFactor);
|
||||
|
||||
#ifdef _LIGHT_LAYERS
|
||||
if (IsMatchingLightLayer(light.layerMask, meshRenderingLayers))
|
||||
#endif
|
||||
{
|
||||
color += light.color * (light.distanceAttenuation * light.shadowAttenuation);
|
||||
}
|
||||
}
|
||||
#endif // USE_CLUSTER_LIGHT_LOOP
|
||||
#endif // _ADDITIONAL_LIGHTS
|
||||
#endif // CREST_URP
|
||||
|
||||
// HDRP todo.
|
||||
// BIRP has additional lights as additional passes. Handled elsewhere.
|
||||
|
||||
return color;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a381e15a67ba0474ea0e685cc27a6f8a
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,71 @@
|
||||
// Crest Water System
|
||||
// Copyright © 2024 Wave Harmonic. All rights reserved.
|
||||
|
||||
#ifndef d_WaveHarmonic_Utility_RenderPipeline_Compute
|
||||
#define d_WaveHarmonic_Utility_RenderPipeline_Compute
|
||||
|
||||
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Library/Settings.Crest.hlsl"
|
||||
|
||||
// Compute does not have an equivalent of PackageRequirements.
|
||||
// We must handle it ourselves.
|
||||
|
||||
// Fallback to BIRP if HDRP package missing.
|
||||
#if _HRP
|
||||
#if (CREST_PACKAGE_HDRP != 1)
|
||||
#undef _HRP
|
||||
#define _BRP 1
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// Fallback to BIRP if URP package missing.
|
||||
#if _URP
|
||||
#if (CREST_PACKAGE_URP != 1)
|
||||
#undef _URP
|
||||
#define _BRP 1
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if _BRP
|
||||
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Library/Utility/Legacy/Core.hlsl"
|
||||
#endif
|
||||
|
||||
#if _HRP
|
||||
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl"
|
||||
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl"
|
||||
#endif
|
||||
|
||||
#if _URP
|
||||
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl"
|
||||
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
|
||||
#endif
|
||||
|
||||
|
||||
//
|
||||
// Stereo Rendering
|
||||
//
|
||||
|
||||
// Unity 6 only, but had compilation errors for non HDRP anyway:
|
||||
// #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/TextureXR.hlsl"
|
||||
|
||||
#ifndef RW_TEXTURE2D_X
|
||||
#if defined(UNITY_STEREO_INSTANCING_ENABLED) || defined(UNITY_STEREO_MULTIVIEW_ENABLED)
|
||||
#define COORD_TEXTURE2D_X(pixelCoord) uint3(pixelCoord, SLICE_ARRAY_INDEX)
|
||||
#define RW_TEXTURE2D_X(type, textureName) RW_TEXTURE2D_ARRAY(type, textureName)
|
||||
#else // UNITY_STEREO
|
||||
#define COORD_TEXTURE2D_X(pixelCoord) pixelCoord
|
||||
#define RW_TEXTURE2D_X RW_TEXTURE2D
|
||||
#endif // UNITY_STEREO
|
||||
#endif // RW_TEXTURE2D_X
|
||||
|
||||
#ifndef UNITY_XR_ASSIGN_VIEW_INDEX
|
||||
// Helper macro to assign view index during compute/ray pass (usually from SV_DispatchThreadID or DispatchRaysIndex())
|
||||
#if defined(SHADER_STAGE_COMPUTE) || defined(SHADER_STAGE_RAY_TRACING)
|
||||
#if defined(UNITY_STEREO_INSTANCING_ENABLED)
|
||||
#define UNITY_XR_ASSIGN_VIEW_INDEX(viewIndex) unity_StereoEyeIndex = viewIndex;
|
||||
#else
|
||||
#define UNITY_XR_ASSIGN_VIEW_INDEX(viewIndex)
|
||||
#endif
|
||||
#endif
|
||||
#endif // UNITY_XR_ASSIGN_VIEW_INDEX
|
||||
|
||||
#endif // d_WaveHarmonic_Utility_RenderPipeline_Compute
|
||||
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 68cb1a44e787e45bd9de666d527b10f2
|
||||
ShaderIncludeImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: de25b8cb31cac9b4db1835b9632de8db
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,12 @@
|
||||
// Crest Water System
|
||||
// Copyright © 2024 Wave Harmonic. All rights reserved.
|
||||
|
||||
#ifndef d_WaveHarmonic_Utility_RenderPipeline_HDRP_Common
|
||||
#define d_WaveHarmonic_Utility_RenderPipeline_HDRP_Common
|
||||
|
||||
#define LoadSceneColor LoadCameraColor
|
||||
#define LoadSceneDepth LoadCameraDepth
|
||||
#define SampleSceneColor SampleCameraColor
|
||||
#define SampleSceneDepth SampleCameraDepth
|
||||
|
||||
#endif // d_WaveHarmonic_Utility_RenderPipeline_HDRP_Common
|
||||
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 327c164f365e1468789c5950ac945e17
|
||||
ShaderIncludeImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,107 @@
|
||||
// Crest Water System
|
||||
// Copyright © 2024 Wave Harmonic. All rights reserved.
|
||||
|
||||
#ifndef d_WaveHarmonic_Utility_RenderPipeline_Shadows
|
||||
#define d_WaveHarmonic_Utility_RenderPipeline_Shadows
|
||||
|
||||
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Library/Utility/Macros.hlsl"
|
||||
|
||||
#if _BRP
|
||||
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Library/Utility/Legacy/Shadows.hlsl"
|
||||
|
||||
bool _Crest_ClearShadows;
|
||||
#endif
|
||||
|
||||
#if _HRP
|
||||
// TODO: We might be able to expose this to give developers the option.
|
||||
// #pragma multi_compile SHADOW_ULTRA_LOW SHADOW_LOW SHADOW_MEDIUM SHADOW_HIGH
|
||||
|
||||
// Ultra low uses Gather to filter which should be same cost as not filtering. See algorithms per keyword:
|
||||
// Runtime/Lighting/Shadow/HDShadowAlgorithms.hlsl
|
||||
#define SHADOW_ULTRA_LOW
|
||||
#define AREA_SHADOW_LOW
|
||||
#define PUNCTUAL_SHADOW_ULTRA_LOW
|
||||
#define DIRECTIONAL_SHADOW_ULTRA_LOW
|
||||
|
||||
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/CommonMaterial.hlsl"
|
||||
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/HDShadow.hlsl"
|
||||
#endif
|
||||
|
||||
#if _URP
|
||||
// Maybe this is the equivalent of the SHADOW_COLLECTOR_PASS define?
|
||||
// Inspired from com.unity.render-pipelines.universal/Shaders/Utils/ScreenSpaceShadows.shader
|
||||
#define _MAIN_LIGHT_SHADOWS_CASCADE
|
||||
#define MAIN_LIGHT_CALCULATE_SHADOWS
|
||||
|
||||
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/CommonMaterial.hlsl"
|
||||
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Shadows.hlsl"
|
||||
#endif
|
||||
|
||||
m_UtilityNameSpace
|
||||
|
||||
#if _BRP
|
||||
half SampleShadows(const float4 i_positionWS)
|
||||
{
|
||||
// NOTE: "Shadow Projection > Close Fit" can still produce artefacts when away from caster, but this
|
||||
// appears to be an improvement over the compute shader.
|
||||
|
||||
// Calculate depth. Normally this would be depth from the depth buffer.
|
||||
float z = dot(i_positionWS.xyz - _WorldSpaceCameraPos.xyz, unity_CameraToWorld._m02_m12_m22);
|
||||
|
||||
float4 weights = GET_CASCADE_WEIGHTS(i_positionWS.xyz, z);
|
||||
float4 shadowCoord = GET_SHADOW_COORDINATES(i_positionWS, weights);
|
||||
half shadows = UNITY_SAMPLE_SHADOW(_ShadowMapTexture, shadowCoord);
|
||||
if (_Crest_ClearShadows) shadows = 1.0;
|
||||
shadows = lerp(_LightShadowData.r, 1.0, shadows);
|
||||
|
||||
return shadows;
|
||||
}
|
||||
|
||||
half ComputeShadowFade(const float4 i_positionWS)
|
||||
{
|
||||
float z = dot(i_positionWS.xyz - _WorldSpaceCameraPos.xyz, unity_CameraToWorld._m02_m12_m22);
|
||||
float fadeDistance = UnityComputeShadowFadeDistance(i_positionWS.xyz, z);
|
||||
float fade = UnityComputeShadowFade(fadeDistance);
|
||||
return fade;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if _HRP
|
||||
half SampleShadows(const float4 i_positionWS)
|
||||
{
|
||||
// Get directional light data. By definition we only have one directional light casting shadow.
|
||||
DirectionalLightData light = _DirectionalLightDatas[_DirectionalShadowIndex];
|
||||
HDShadowContext context = InitShadowContext();
|
||||
|
||||
// Zeros are for screen space position and world space normal which are for filtering and normal bias
|
||||
// respectively. They did not appear to have an impact.
|
||||
half shadows = GetDirectionalShadowAttenuation(context, 0, i_positionWS.xyz, 0, _DirectionalShadowIndex, -light.forward);
|
||||
// Apply shadow strength from main light.
|
||||
shadows = LerpWhiteTo(shadows, light.shadowDimmer);
|
||||
|
||||
return shadows;
|
||||
}
|
||||
|
||||
half ComputeShadowFade(const float4 i_positionWS)
|
||||
{
|
||||
// TODO: Work out shadow fade.
|
||||
return 0.0;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if _URP
|
||||
half SampleShadows(const float4 i_positionWS)
|
||||
{
|
||||
// Includes soft shadows if _SHADOWS_SOFT is defined (requires multi-compile pragma).
|
||||
return MainLightRealtimeShadow(TransformWorldToShadowCoord(i_positionWS.xyz));
|
||||
}
|
||||
|
||||
half ComputeShadowFade(const float4 i_positionWS)
|
||||
{
|
||||
return GetShadowFade(i_positionWS.xyz);
|
||||
}
|
||||
#endif
|
||||
|
||||
m_UtilityNameSpaceEnd
|
||||
|
||||
#endif // d_WaveHarmonic_Utility_RenderPipeline_Shadows
|
||||
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 07d6b2cd79ac04fa5b56cffd5fb1bb31
|
||||
ShaderIncludeImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,85 @@
|
||||
// Crest Water System
|
||||
// Copyright © 2024 Wave Harmonic. All rights reserved.
|
||||
|
||||
#ifndef CREST_SHADOWS_H
|
||||
#define CREST_SHADOWS_H
|
||||
|
||||
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Library/Macros.hlsl"
|
||||
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Library/Globals.hlsl"
|
||||
|
||||
#if CREST_BIRP
|
||||
TEXTURE2D_X(_Crest_ScreenSpaceShadowTexture);
|
||||
float4 _Crest_ScreenSpaceShadowTexture_TexelSize;
|
||||
#endif // CREST_BIRP
|
||||
|
||||
#if CREST_URP
|
||||
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"
|
||||
#endif // CREST_URP
|
||||
|
||||
#if CREST_HDRP
|
||||
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl"
|
||||
|
||||
#ifndef SHADERGRAPH_PREVIEW
|
||||
#if CREST_HDRP_FORWARD_PASS
|
||||
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/HDShadow.hlsl"
|
||||
#endif // CREST_HDRP_FORWARD_PASS
|
||||
#endif // SHADERGRAPH_PREVIEW
|
||||
#endif // CREST_HDRP
|
||||
|
||||
m_CrestNameSpace
|
||||
|
||||
// Position: SRP = WS / BIRP = SS (z ignored)
|
||||
half PrimaryLightShadows(const float3 i_Position, const float2 i_ScreenPosition)
|
||||
{
|
||||
// Unshadowed.
|
||||
half shadow = 1;
|
||||
|
||||
#if CREST_URP
|
||||
// We could skip GetMainLight but this is recommended approach which is likely more robust to API changes.
|
||||
float4 shadowCoord = TransformWorldToShadowCoord(i_Position);
|
||||
Light light = GetMainLight(TransformWorldToShadowCoord(i_Position));
|
||||
shadow = light.shadowAttenuation;
|
||||
#endif
|
||||
|
||||
#ifndef SHADERGRAPH_PREVIEW
|
||||
#if CREST_HDRP_FORWARD_PASS
|
||||
DirectionalLightData light = _DirectionalLightDatas[_DirectionalShadowIndex];
|
||||
HDShadowContext context = InitShadowContext();
|
||||
context.directionalShadowData = _HDDirectionalShadowData[_DirectionalShadowIndex];
|
||||
|
||||
float3 positionWS = GetCameraRelativePositionWS(i_Position);
|
||||
// From Unity:
|
||||
// > With XR single-pass and camera-relative: offset position to do lighting computations from the combined center view (original camera matrix).
|
||||
// > This is required because there is only one list of lights generated on the CPU. Shadows are also generated once and shared between the instanced views.
|
||||
ApplyCameraRelativeXR(positionWS);
|
||||
|
||||
// TODO: Pass in screen space position and scene normal.
|
||||
shadow = GetDirectionalShadowAttenuation
|
||||
(
|
||||
context,
|
||||
0, // positionSS
|
||||
positionWS,
|
||||
0, // normalWS
|
||||
light.shadowIndex,
|
||||
-light.forward
|
||||
);
|
||||
|
||||
// Apply shadow strength from main light.
|
||||
shadow = LerpWhiteTo(shadow, light.shadowDimmer);
|
||||
#endif // CREST_HDRP_FORWARD_PASS
|
||||
#endif // SHADERGRAPH_PREVIEW
|
||||
|
||||
#if CREST_BIRP
|
||||
shadow = LOAD_TEXTURE2D_X(_Crest_ScreenSpaceShadowTexture, min(i_ScreenPosition, _Crest_ScreenSpaceShadowTexture_TexelSize.zw - 1.0)).r;
|
||||
#if DIRECTIONAL_COOKIE
|
||||
const half attenuation = tex2D(_LightTexture0, mul(unity_WorldToLight, float4(i_Position, 1.0)).xy).w;
|
||||
shadow = min(attenuation, shadow);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
return shadow;
|
||||
}
|
||||
|
||||
m_CrestNameSpaceEnd
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b4623a51d04ef4e9c82e9196bf28e48d
|
||||
ShaderIncludeImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7bf6aebdc1c0f3f47bad2841e2a11446
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,69 @@
|
||||
// Crest Water System
|
||||
// Copyright © 2024 Wave Harmonic. All rights reserved.
|
||||
|
||||
#ifndef d_WaveHarmonic_Crest_Meniscus
|
||||
#define d_WaveHarmonic_Crest_Meniscus
|
||||
|
||||
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Library/Settings.Crest.hlsl"
|
||||
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Library/Macros.hlsl"
|
||||
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Library/Constants.hlsl"
|
||||
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Library/Cascade.hlsl"
|
||||
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Library/Utility/Depth.hlsl"
|
||||
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Library/Globals.hlsl"
|
||||
|
||||
float2 _Crest_HorizonNormal;
|
||||
|
||||
TEXTURE2D_X(_Crest_WaterMaskTexture);
|
||||
|
||||
m_CrestNameSpace
|
||||
|
||||
struct Attributes
|
||||
{
|
||||
uint id : SV_VertexID;
|
||||
UNITY_VERTEX_INPUT_INSTANCE_ID
|
||||
};
|
||||
|
||||
struct Varyings
|
||||
{
|
||||
float4 positionCS : SV_POSITION;
|
||||
UNITY_VERTEX_OUTPUT_STEREO
|
||||
};
|
||||
|
||||
Varyings Vertex(Attributes input)
|
||||
{
|
||||
Varyings output;
|
||||
ZERO_INITIALIZE(Varyings, output);
|
||||
UNITY_SETUP_INSTANCE_ID(input);
|
||||
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output);
|
||||
output.positionCS = GetFullScreenTriangleVertexPosition(input.id, UNITY_RAW_FAR_CLIP_VALUE);
|
||||
return output;
|
||||
}
|
||||
|
||||
half4 Fragment(Varyings input)
|
||||
{
|
||||
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);
|
||||
|
||||
const uint2 positionSS = input.positionCS.xy;
|
||||
const float mask = LOAD_TEXTURE2D_X(_Crest_WaterMaskTexture, positionSS).x;
|
||||
const float2 offset = -((float2)mask) * _Crest_HorizonNormal;
|
||||
float weight = 1.0;
|
||||
|
||||
// Sample three pixels along the normal. If the sample is different than the
|
||||
// current mask, apply meniscus. Offset must be added to positionSS as floats.
|
||||
[unroll]
|
||||
for (int i = 1; i <= 3; i++)
|
||||
{
|
||||
const float2 uv = positionSS + offset * (float)i;
|
||||
const float newMask = LOAD_TEXTURE2D_X(_Crest_WaterMaskTexture, uv).r;
|
||||
weight *= newMask != mask && newMask != 0.0 ? 0.9 : 1.0;
|
||||
}
|
||||
|
||||
return weight;
|
||||
}
|
||||
|
||||
m_CrestNameSpaceEnd
|
||||
|
||||
m_CrestVertex
|
||||
m_CrestFragment(half4)
|
||||
|
||||
#endif // d_WaveHarmonic_Crest_Meniscus
|
||||
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0d256485a6a0c40f291276367afcede2
|
||||
ShaderIncludeImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,245 @@
|
||||
// Crest Water System
|
||||
// Copyright © 2024 Wave Harmonic. All rights reserved.
|
||||
|
||||
#ifndef d_WaveHarmonic_Crest_Meniscus
|
||||
#define d_WaveHarmonic_Crest_Meniscus
|
||||
|
||||
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Library/Settings.Crest.hlsl"
|
||||
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Library/Macros.hlsl"
|
||||
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Library/Constants.hlsl"
|
||||
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Library/Globals.hlsl"
|
||||
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Library/Cascade.hlsl"
|
||||
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Library/Utility/Helpers.hlsl"
|
||||
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Library/Utility/Depth.hlsl"
|
||||
|
||||
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Surface/Shim.hlsl"
|
||||
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Library/Utility/Lighting.hlsl"
|
||||
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Surface/VolumeLighting.hlsl"
|
||||
|
||||
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Surface/Data.hlsl"
|
||||
|
||||
#if d_Masked
|
||||
TEXTURE2D_X(_Crest_WaterMaskTexture);
|
||||
#endif
|
||||
|
||||
#if d_Crest_Lighting
|
||||
// Surface/Volume parameters.
|
||||
half4 _Crest_Absorption;
|
||||
half4 _Crest_Scattering;
|
||||
half _Crest_Anisotropy;
|
||||
half _Crest_DirectTerm;
|
||||
half _Crest_AmbientTerm;
|
||||
half _Crest_ShadowsAffectsAmbientFactor;
|
||||
|
||||
// Volume parameters.
|
||||
half _Crest_SunBoost;
|
||||
half3 _Crest_AmbientLighting;
|
||||
int _Crest_DataSliceOffset;
|
||||
#endif
|
||||
|
||||
half _Crest_Radius;
|
||||
half _Crest_RefractionStrength;
|
||||
|
||||
m_CrestNameSpace
|
||||
|
||||
struct Attributes
|
||||
{
|
||||
#if d_Crest_Geometry
|
||||
float3 positionOS : POSITION;
|
||||
#else
|
||||
uint id : SV_VertexID;
|
||||
#endif
|
||||
UNITY_VERTEX_INPUT_INSTANCE_ID
|
||||
};
|
||||
|
||||
struct Varyings
|
||||
{
|
||||
float4 positionCS : SV_POSITION;
|
||||
#if d_Crest_Geometry
|
||||
float3 positionWS : TEXCOORD;
|
||||
#else
|
||||
float2 uv : TEXCOORD;
|
||||
#endif
|
||||
UNITY_VERTEX_OUTPUT_STEREO
|
||||
};
|
||||
|
||||
Varyings Vertex(Attributes input)
|
||||
{
|
||||
Varyings output;
|
||||
ZERO_INITIALIZE(Varyings, output);
|
||||
UNITY_SETUP_INSTANCE_ID(input);
|
||||
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output);
|
||||
|
||||
#if d_Crest_Geometry
|
||||
output.positionCS = TransformObjectToHClip(input.positionOS);
|
||||
output.positionWS = TransformObjectToWorld(input.positionOS);
|
||||
#else
|
||||
output.positionCS = GetFullScreenTriangleVertexPosition(input.id);
|
||||
output.uv = GetFullScreenTriangleTexCoord(input.id);
|
||||
#endif
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
half4 Fragment(Varyings input)
|
||||
{
|
||||
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);
|
||||
|
||||
#if d_Masked
|
||||
// Prevent rendering inside of new portal modules.
|
||||
if (LOAD_TEXTURE2D_X(_Crest_WaterMaskTexture, input.positionCS.xy).r == k_Crest_MaskInsidePortal)
|
||||
{
|
||||
discard;
|
||||
}
|
||||
#endif
|
||||
|
||||
float3 positionWS;
|
||||
float3 directionWS;
|
||||
float2 uv;
|
||||
|
||||
#if d_Crest_Geometry
|
||||
{
|
||||
positionWS = input.positionWS;
|
||||
#if (SHADEROPTIONS_CAMERA_RELATIVE_RENDERING != 0)
|
||||
positionWS.xyz += _WorldSpaceCameraPos.xyz;
|
||||
#endif
|
||||
directionWS = GetWorldSpaceNormalizeViewDir(positionWS);
|
||||
uv = input.positionCS.xy / _ScreenSize.xy;
|
||||
}
|
||||
#else
|
||||
{
|
||||
positionWS = ComputeWorldSpacePosition(input.uv, UNITY_NEAR_CLIP_VALUE, UNITY_MATRIX_I_VP);
|
||||
|
||||
#if (SHADEROPTIONS_CAMERA_RELATIVE_RENDERING != 0)
|
||||
positionWS.xyz += _WorldSpaceCameraPos.xyz;
|
||||
#endif
|
||||
|
||||
directionWS = GetWorldSpaceNormalizeViewDir(positionWS);
|
||||
|
||||
uv = input.uv;
|
||||
}
|
||||
#endif
|
||||
|
||||
const float height = SampleWaterLineHeight(positionWS.xz).r;
|
||||
|
||||
// Double as we half it if below.
|
||||
float radius = _Crest_Radius * 2.0;
|
||||
|
||||
#if d_Crest_Refraction
|
||||
// Double the radius as aggressive falloff makes it much smaller.
|
||||
radius *= 2.0;
|
||||
#endif
|
||||
|
||||
float signedDistance = positionWS.y - height;
|
||||
|
||||
float3 viewDirWS = normalize(_WorldSpaceCameraPos - positionWS);
|
||||
|
||||
const float distance = abs(signedDistance);
|
||||
|
||||
if (signedDistance < 0)
|
||||
{
|
||||
radius = max(0.002, radius * 0.25);
|
||||
}
|
||||
|
||||
if (distance > radius)
|
||||
{
|
||||
discard;
|
||||
}
|
||||
|
||||
half3 color = 0.0;
|
||||
|
||||
#if d_Crest_Lighting
|
||||
{
|
||||
half3 absorption = _Crest_Absorption.xyz;
|
||||
half3 scattering = _Crest_Scattering.xyz;
|
||||
|
||||
// Keep the same as the volume.
|
||||
const int sliceIndex = clamp(_Crest_DataSliceOffset, 0, g_Crest_LodCount - 2);
|
||||
|
||||
if (g_Crest_SampleAbsorptionSimulation) absorption = Cascade::MakeAbsorption(sliceIndex).Sample(_WorldSpaceCameraPos.xz).xyz;
|
||||
if (g_Crest_SampleScatteringSimulation) scattering = Cascade::MakeScattering(sliceIndex).Sample(_WorldSpaceCameraPos.xz).xyz;
|
||||
|
||||
float3 lightDirection; float3 lightColor;
|
||||
PrimaryLight(positionWS, lightColor, lightDirection);
|
||||
|
||||
const half3 extinction = VolumeExtinction(absorption, scattering);
|
||||
|
||||
half opacity = 1.0;
|
||||
#if !d_Crest_Refraction
|
||||
// Meniscus can look too dark in shallow water.
|
||||
{
|
||||
const float depth = Cascade::MakeDepth(sliceIndex).SampleSignedDepthFromSeaLevel(_WorldSpaceCameraPos.xz);
|
||||
opacity = VolumeOpacity(extinction, depth * 0.25);
|
||||
}
|
||||
#endif
|
||||
|
||||
half shadow = 1.0;
|
||||
{
|
||||
// Soft in red, hard in green. But hard not computed in HDRP.
|
||||
shadow = 1.0 - Cascade::MakeShadow(sliceIndex).SampleShadow(_WorldSpaceCameraPos.xz).x;
|
||||
}
|
||||
|
||||
half3 lighting = VolumeLighting
|
||||
(
|
||||
extinction,
|
||||
scattering,
|
||||
_Crest_Anisotropy,
|
||||
shadow,
|
||||
lerp(half3(0, 1, 0), directionWS, opacity),
|
||||
AmbientLight(_Crest_AmbientLighting),
|
||||
lerp(half3(0, -1, 0), lightDirection, opacity),
|
||||
lightColor,
|
||||
half3(0.0, 0.0, 0.0), // Additional lights
|
||||
_Crest_AmbientTerm,
|
||||
_Crest_DirectTerm,
|
||||
_Crest_SunBoost,
|
||||
_Crest_ShadowsAffectsAmbientFactor
|
||||
);
|
||||
|
||||
#if CREST_HDRP
|
||||
lighting *= GetCurrentExposureMultiplier();
|
||||
#endif
|
||||
|
||||
color = lighting;
|
||||
}
|
||||
#endif
|
||||
|
||||
const float falloff = 1.0 - smoothstep(0.0, radius, distance);
|
||||
|
||||
#if d_Crest_Refraction
|
||||
{
|
||||
const half3 normal = SampleWaterLineNormal(positionWS.xz, height);
|
||||
float2 dir = Utility::WorldNormalToScreenDirection(positionWS, normal, UNITY_MATRIX_VP, 0.01);
|
||||
|
||||
const float aspect = _ScreenParams.x / _ScreenParams.y;
|
||||
dir.x /= aspect;
|
||||
|
||||
const float2 uvRefracted = uv - dir * falloff * _Crest_RefractionStrength;
|
||||
|
||||
half3 scene = SampleSceneColor(uvRefracted);
|
||||
|
||||
if (signedDistance >= 0)
|
||||
{
|
||||
// Blend back in with original. Cannot seem to do this with alpha without losing
|
||||
// some lighting.
|
||||
scene = lerp
|
||||
(
|
||||
scene,
|
||||
SampleSceneColor(uv),
|
||||
saturate((distance / radius) * 5.0)
|
||||
);
|
||||
}
|
||||
|
||||
color = lerp(color, scene, 0.5);
|
||||
}
|
||||
#endif
|
||||
|
||||
return float4(color, falloff);
|
||||
}
|
||||
|
||||
m_CrestNameSpaceEnd
|
||||
|
||||
m_CrestVertex
|
||||
m_CrestFragment(half4)
|
||||
|
||||
#endif // d_WaveHarmonic_Crest_Meniscus
|
||||
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f9eca4b9660d6423d89353a4148e9191
|
||||
ShaderIncludeImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,594 @@
|
||||
// Crest Water System
|
||||
// Copyright © 2024 Wave Harmonic. All rights reserved.
|
||||
|
||||
Shader "Crest/Meniscus"
|
||||
{
|
||||
Properties
|
||||
{
|
||||
_Crest_Radius("Radius", Range(0.001, 0.1)) = 0.01
|
||||
|
||||
[Space(10)]
|
||||
|
||||
[Toggle(d_Crest_Refraction)]
|
||||
_Crest_RefractionEnabled("Refraction", Integer) = 1
|
||||
_Crest_RefractionStrength("Refraction Strength", Range(0, 1)) = 0.2
|
||||
|
||||
[Space(10)]
|
||||
|
||||
[Toggle(d_Crest_Lighting)]
|
||||
_Crest_LightingEnabled("Lighting", Integer) = 1
|
||||
}
|
||||
|
||||
HLSLINCLUDE
|
||||
#pragma vertex Vertex
|
||||
#pragma fragment Fragment
|
||||
|
||||
// #pragma enable_d3d11_debug_symbols
|
||||
ENDHLSL
|
||||
|
||||
SubShader
|
||||
{
|
||||
PackageRequirements
|
||||
{
|
||||
"com.unity.render-pipelines.high-definition"
|
||||
}
|
||||
|
||||
Tags { "RenderPipeline"="HDRenderPipeline" }
|
||||
|
||||
Blend SrcAlpha OneMinusSrcAlpha
|
||||
ColorMask RGB
|
||||
Cull Off
|
||||
ZTest Always
|
||||
ZWrite Off
|
||||
|
||||
Pass
|
||||
{
|
||||
Name "Meniscus"
|
||||
|
||||
HLSLPROGRAM
|
||||
#pragma shader_feature_local_fragment _ d_Crest_Refraction
|
||||
#pragma shader_feature_local_fragment _ d_Crest_Lighting
|
||||
|
||||
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl"
|
||||
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl"
|
||||
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Library/Utility/RP/HDRP/Common.hlsl"
|
||||
|
||||
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Meniscus/Meniscus.hlsl"
|
||||
ENDHLSL
|
||||
}
|
||||
|
||||
Pass
|
||||
{
|
||||
PackageRequirements
|
||||
{
|
||||
"com.waveharmonic.crest.portals"
|
||||
}
|
||||
|
||||
Name "Meniscus (Masked)"
|
||||
|
||||
HLSLPROGRAM
|
||||
#pragma shader_feature_local_fragment _ d_Crest_Refraction
|
||||
#pragma shader_feature_local_fragment _ d_Crest_Lighting
|
||||
|
||||
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl"
|
||||
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl"
|
||||
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Library/Utility/RP/HDRP/Common.hlsl"
|
||||
|
||||
#define d_Masked 1
|
||||
|
||||
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Meniscus/Meniscus.hlsl"
|
||||
ENDHLSL
|
||||
}
|
||||
|
||||
Pass
|
||||
{
|
||||
PackageRequirements
|
||||
{
|
||||
"com.waveharmonic.crest.portals"
|
||||
}
|
||||
|
||||
Name "Meniscus (Front Face)"
|
||||
|
||||
Cull Back
|
||||
ZTest LEqual
|
||||
|
||||
HLSLPROGRAM
|
||||
#pragma shader_feature_local_fragment _ d_Crest_Refraction
|
||||
#pragma shader_feature_local_fragment _ d_Crest_Lighting
|
||||
|
||||
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl"
|
||||
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl"
|
||||
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Library/Utility/RP/HDRP/Common.hlsl"
|
||||
|
||||
#define d_Crest_Geometry 1
|
||||
|
||||
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Meniscus/Meniscus.hlsl"
|
||||
ENDHLSL
|
||||
}
|
||||
|
||||
Pass
|
||||
{
|
||||
PackageRequirements
|
||||
{
|
||||
"com.waveharmonic.crest.portals"
|
||||
}
|
||||
|
||||
Name "Meniscus (Back Face)"
|
||||
|
||||
Cull Front
|
||||
ZTest LEqual
|
||||
|
||||
HLSLPROGRAM
|
||||
#pragma shader_feature_local_fragment _ d_Crest_Refraction
|
||||
#pragma shader_feature_local_fragment _ d_Crest_Lighting
|
||||
|
||||
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl"
|
||||
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl"
|
||||
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Library/Utility/RP/HDRP/Common.hlsl"
|
||||
|
||||
#define d_Crest_Geometry 1
|
||||
|
||||
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Meniscus/Meniscus.hlsl"
|
||||
ENDHLSL
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// Obsolete. Depends on the raster mask.
|
||||
//
|
||||
|
||||
Pass
|
||||
{
|
||||
Name "Meniscus"
|
||||
|
||||
Blend DstColor Zero
|
||||
|
||||
HLSLPROGRAM
|
||||
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl"
|
||||
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl"
|
||||
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Meniscus/Meniscus.Obsolete.hlsl"
|
||||
ENDHLSL
|
||||
}
|
||||
|
||||
Pass
|
||||
{
|
||||
PackageRequirements
|
||||
{
|
||||
"com.waveharmonic.crest.portals"
|
||||
}
|
||||
|
||||
Name "Meniscus (Portal)"
|
||||
|
||||
Blend DstColor Zero
|
||||
|
||||
HLSLPROGRAM
|
||||
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl"
|
||||
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl"
|
||||
|
||||
// Full-screen only applicable portals with back-faces.
|
||||
#define d_Crest_HasBackFace 1
|
||||
|
||||
#include "Packages/com.waveharmonic.crest.portals/Runtime/Shaders/Meniscus.hlsl"
|
||||
ENDHLSL
|
||||
}
|
||||
|
||||
Pass
|
||||
{
|
||||
PackageRequirements
|
||||
{
|
||||
"com.waveharmonic.crest.portals"
|
||||
}
|
||||
|
||||
Name "Meniscus (Front Face)"
|
||||
|
||||
Blend DstColor Zero
|
||||
Cull Back
|
||||
ZTest LEqual
|
||||
|
||||
HLSLPROGRAM
|
||||
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl"
|
||||
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl"
|
||||
|
||||
#define d_Crest_Geometry 1
|
||||
#define d_Crest_FrontFace 1
|
||||
|
||||
#include "Packages/com.waveharmonic.crest.portals/Runtime/Shaders/Meniscus.hlsl"
|
||||
ENDHLSL
|
||||
}
|
||||
|
||||
Pass
|
||||
{
|
||||
PackageRequirements
|
||||
{
|
||||
"com.waveharmonic.crest.portals"
|
||||
}
|
||||
|
||||
Name "Meniscus (Back Face)"
|
||||
|
||||
Blend DstColor Zero
|
||||
Cull Front
|
||||
ZTest LEqual
|
||||
|
||||
HLSLPROGRAM
|
||||
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl"
|
||||
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl"
|
||||
|
||||
#define d_Crest_Geometry 1
|
||||
#define d_Crest_BackFace 1
|
||||
|
||||
#include "Packages/com.waveharmonic.crest.portals/Runtime/Shaders/Meniscus.hlsl"
|
||||
ENDHLSL
|
||||
}
|
||||
}
|
||||
|
||||
SubShader
|
||||
{
|
||||
PackageRequirements
|
||||
{
|
||||
"com.unity.render-pipelines.universal"
|
||||
}
|
||||
|
||||
Tags { "RenderPipeline"="UniversalPipeline" }
|
||||
|
||||
Blend SrcAlpha OneMinusSrcAlpha
|
||||
ColorMask RGB
|
||||
Cull Off
|
||||
ZTest Always
|
||||
ZWrite Off
|
||||
|
||||
Pass
|
||||
{
|
||||
Name "Meniscus"
|
||||
|
||||
HLSLPROGRAM
|
||||
#pragma shader_feature_local_fragment _ d_Crest_Refraction
|
||||
#pragma shader_feature_local_fragment _ d_Crest_Lighting
|
||||
|
||||
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl"
|
||||
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
|
||||
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareOpaqueTexture.hlsl"
|
||||
|
||||
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Meniscus/Meniscus.hlsl"
|
||||
ENDHLSL
|
||||
}
|
||||
|
||||
Pass
|
||||
{
|
||||
PackageRequirements
|
||||
{
|
||||
"com.waveharmonic.crest.portals"
|
||||
}
|
||||
|
||||
Name "Meniscus (Masked)"
|
||||
|
||||
HLSLPROGRAM
|
||||
#pragma shader_feature_local_fragment _ d_Crest_Refraction
|
||||
#pragma shader_feature_local_fragment _ d_Crest_Lighting
|
||||
|
||||
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl"
|
||||
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
|
||||
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareOpaqueTexture.hlsl"
|
||||
|
||||
#define d_Masked 1
|
||||
|
||||
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Meniscus/Meniscus.hlsl"
|
||||
ENDHLSL
|
||||
}
|
||||
|
||||
Pass
|
||||
{
|
||||
PackageRequirements
|
||||
{
|
||||
"com.waveharmonic.crest.portals"
|
||||
}
|
||||
|
||||
Name "Meniscus (Front Face)"
|
||||
|
||||
Cull Back
|
||||
ZTest LEqual
|
||||
|
||||
HLSLPROGRAM
|
||||
#pragma shader_feature_local_fragment _ d_Crest_Refraction
|
||||
#pragma shader_feature_local_fragment _ d_Crest_Lighting
|
||||
|
||||
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl"
|
||||
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
|
||||
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareOpaqueTexture.hlsl"
|
||||
|
||||
#define d_Crest_Geometry 1
|
||||
|
||||
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Meniscus/Meniscus.hlsl"
|
||||
ENDHLSL
|
||||
}
|
||||
|
||||
Pass
|
||||
{
|
||||
PackageRequirements
|
||||
{
|
||||
"com.waveharmonic.crest.portals"
|
||||
}
|
||||
|
||||
Name "Meniscus (Back Face)"
|
||||
|
||||
Cull Front
|
||||
ZTest LEqual
|
||||
|
||||
HLSLPROGRAM
|
||||
#pragma shader_feature_local_fragment _ d_Crest_Refraction
|
||||
#pragma shader_feature_local_fragment _ d_Crest_Lighting
|
||||
|
||||
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl"
|
||||
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
|
||||
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareOpaqueTexture.hlsl"
|
||||
|
||||
#define d_Crest_Geometry 1
|
||||
|
||||
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Meniscus/Meniscus.hlsl"
|
||||
ENDHLSL
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// Obsolete. Depends on the raster mask.
|
||||
//
|
||||
|
||||
Pass
|
||||
{
|
||||
Name "Meniscus"
|
||||
|
||||
Blend DstColor Zero
|
||||
|
||||
HLSLPROGRAM
|
||||
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl"
|
||||
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
|
||||
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Meniscus/Meniscus.Obsolete.hlsl"
|
||||
ENDHLSL
|
||||
}
|
||||
|
||||
Pass
|
||||
{
|
||||
PackageRequirements
|
||||
{
|
||||
"com.waveharmonic.crest.portals"
|
||||
}
|
||||
|
||||
Name "Meniscus (Portal)"
|
||||
|
||||
Blend DstColor Zero
|
||||
|
||||
HLSLPROGRAM
|
||||
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl"
|
||||
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
|
||||
|
||||
// Full-screen only applicable portals with back-faces.
|
||||
#define d_Crest_HasBackFace 1
|
||||
|
||||
#include "Packages/com.waveharmonic.crest.portals/Runtime/Shaders/Meniscus.hlsl"
|
||||
ENDHLSL
|
||||
}
|
||||
|
||||
Pass
|
||||
{
|
||||
PackageRequirements
|
||||
{
|
||||
"com.waveharmonic.crest.portals"
|
||||
}
|
||||
|
||||
Name "Meniscus (Front Face)"
|
||||
|
||||
Blend DstColor Zero
|
||||
Cull Back
|
||||
ZTest LEqual
|
||||
|
||||
HLSLPROGRAM
|
||||
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl"
|
||||
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
|
||||
|
||||
#define d_Crest_Geometry 1
|
||||
#define d_Crest_FrontFace 1
|
||||
|
||||
#include "Packages/com.waveharmonic.crest.portals/Runtime/Shaders/Meniscus.hlsl"
|
||||
ENDHLSL
|
||||
}
|
||||
|
||||
Pass
|
||||
{
|
||||
PackageRequirements
|
||||
{
|
||||
"com.waveharmonic.crest.portals"
|
||||
}
|
||||
|
||||
Name "Meniscus (Back Face)"
|
||||
|
||||
Blend DstColor Zero
|
||||
Cull Front
|
||||
ZTest LEqual
|
||||
|
||||
HLSLPROGRAM
|
||||
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl"
|
||||
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
|
||||
|
||||
#define d_Crest_Geometry 1
|
||||
#define d_Crest_BackFace 1
|
||||
|
||||
#include "Packages/com.waveharmonic.crest.portals/Runtime/Shaders/Meniscus.hlsl"
|
||||
ENDHLSL
|
||||
}
|
||||
}
|
||||
|
||||
SubShader
|
||||
{
|
||||
Blend SrcAlpha OneMinusSrcAlpha
|
||||
ColorMask RGB
|
||||
Cull Off
|
||||
ZTest Always
|
||||
ZWrite Off
|
||||
|
||||
Pass
|
||||
{
|
||||
Name "Meniscus"
|
||||
|
||||
HLSLPROGRAM
|
||||
#pragma shader_feature_local_fragment _ d_Crest_Refraction
|
||||
#pragma shader_feature_local_fragment _ d_Crest_Lighting
|
||||
|
||||
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Library/Utility/Legacy/Core.hlsl"
|
||||
#include "Packages/com.unity.shadergraph/Editor/Generation/Targets/BuiltIn/ShaderLibrary/DeclareOpaqueTexture.hlsl"
|
||||
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Meniscus/Meniscus.hlsl"
|
||||
ENDHLSL
|
||||
}
|
||||
|
||||
Pass
|
||||
{
|
||||
PackageRequirements
|
||||
{
|
||||
"com.waveharmonic.crest.portals"
|
||||
}
|
||||
|
||||
Name "Meniscus (Masked)"
|
||||
|
||||
HLSLPROGRAM
|
||||
#pragma shader_feature_local_fragment _ d_Crest_Refraction
|
||||
#pragma shader_feature_local_fragment _ d_Crest_Lighting
|
||||
|
||||
#define d_Masked 1
|
||||
|
||||
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Library/Utility/Legacy/Core.hlsl"
|
||||
#include "Packages/com.unity.shadergraph/Editor/Generation/Targets/BuiltIn/ShaderLibrary/DeclareOpaqueTexture.hlsl"
|
||||
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Meniscus/Meniscus.hlsl"
|
||||
ENDHLSL
|
||||
}
|
||||
|
||||
Pass
|
||||
{
|
||||
PackageRequirements
|
||||
{
|
||||
"com.waveharmonic.crest.portals"
|
||||
}
|
||||
|
||||
Name "Meniscus (Front)"
|
||||
|
||||
Cull Back
|
||||
ZTest LEqual
|
||||
|
||||
HLSLPROGRAM
|
||||
#pragma shader_feature_local_fragment _ d_Crest_Refraction
|
||||
#pragma shader_feature_local_fragment _ d_Crest_Lighting
|
||||
#define d_Crest_Geometry 1
|
||||
|
||||
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Library/Utility/Legacy/Core.hlsl"
|
||||
#include "Packages/com.unity.shadergraph/Editor/Generation/Targets/BuiltIn/ShaderLibrary/DeclareOpaqueTexture.hlsl"
|
||||
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Meniscus/Meniscus.hlsl"
|
||||
ENDHLSL
|
||||
}
|
||||
|
||||
Pass
|
||||
{
|
||||
PackageRequirements
|
||||
{
|
||||
"com.waveharmonic.crest.portals"
|
||||
}
|
||||
|
||||
Name "Meniscus (Back)"
|
||||
|
||||
Cull Front
|
||||
ZTest LEqual
|
||||
|
||||
HLSLPROGRAM
|
||||
#pragma shader_feature_local_fragment _ d_Crest_Refraction
|
||||
#pragma shader_feature_local_fragment _ d_Crest_Lighting
|
||||
#define d_Crest_Geometry 1
|
||||
|
||||
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Library/Utility/Legacy/Core.hlsl"
|
||||
#include "Packages/com.unity.shadergraph/Editor/Generation/Targets/BuiltIn/ShaderLibrary/DeclareOpaqueTexture.hlsl"
|
||||
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Meniscus/Meniscus.hlsl"
|
||||
ENDHLSL
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// Obsolete. Depends on the raster mask.
|
||||
//
|
||||
|
||||
Pass
|
||||
{
|
||||
Name "Meniscus"
|
||||
|
||||
Blend DstColor Zero
|
||||
|
||||
HLSLPROGRAM
|
||||
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Library/Utility/Legacy/Core.hlsl"
|
||||
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Meniscus/Meniscus.Obsolete.hlsl"
|
||||
ENDHLSL
|
||||
}
|
||||
|
||||
Pass
|
||||
{
|
||||
PackageRequirements
|
||||
{
|
||||
"com.waveharmonic.crest.portals"
|
||||
}
|
||||
|
||||
Name "Meniscus (Portal)"
|
||||
|
||||
Blend DstColor Zero
|
||||
|
||||
HLSLPROGRAM
|
||||
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Library/Utility/Legacy/Core.hlsl"
|
||||
|
||||
// Full-screen only applicable portals with back-faces.
|
||||
#define d_Crest_HasBackFace 1
|
||||
|
||||
#include "Packages/com.waveharmonic.crest.portals/Runtime/Shaders/Meniscus.hlsl"
|
||||
ENDHLSL
|
||||
}
|
||||
|
||||
Pass
|
||||
{
|
||||
PackageRequirements
|
||||
{
|
||||
"com.waveharmonic.crest.portals"
|
||||
}
|
||||
|
||||
Name "Meniscus (Front Face)"
|
||||
|
||||
Blend DstColor Zero
|
||||
Cull Back
|
||||
ZTest LEqual
|
||||
|
||||
HLSLPROGRAM
|
||||
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Library/Utility/Legacy/Core.hlsl"
|
||||
|
||||
#define d_Crest_Geometry 1
|
||||
#define d_Crest_FrontFace 1
|
||||
|
||||
#include "Packages/com.waveharmonic.crest.portals/Runtime/Shaders/Meniscus.hlsl"
|
||||
ENDHLSL
|
||||
}
|
||||
|
||||
Pass
|
||||
{
|
||||
PackageRequirements
|
||||
{
|
||||
"com.waveharmonic.crest.portals"
|
||||
}
|
||||
|
||||
Name "Meniscus (Back Face)"
|
||||
|
||||
Blend DstColor Zero
|
||||
Cull Front
|
||||
ZTest LEqual
|
||||
|
||||
HLSLPROGRAM
|
||||
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Library/Utility/Legacy/Core.hlsl"
|
||||
|
||||
#define d_Crest_Geometry 1
|
||||
#define d_Crest_BackFace 1
|
||||
|
||||
#include "Packages/com.waveharmonic.crest.portals/Runtime/Shaders/Meniscus.hlsl"
|
||||
ENDHLSL
|
||||
}
|
||||
}
|
||||
|
||||
CustomEditor "WaveHarmonic.Crest.Editor.CustomShaderGUI"
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ec7c774912c6f4b3cb6d73444cdedeca
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,41 @@
|
||||
// Crest Water System
|
||||
// Copyright © 2024 Wave Harmonic. All rights reserved.
|
||||
|
||||
#ifndef d_WaveHarmonic_Crest_SurfaceData
|
||||
#define d_WaveHarmonic_Crest_SurfaceData
|
||||
|
||||
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Library/Macros.hlsl"
|
||||
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Library/Globals.hlsl"
|
||||
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Surface/Utility.hlsl"
|
||||
|
||||
TEXTURE2D_FLOAT(_Crest_WaterLine);
|
||||
float _Crest_WaterLineTexel;
|
||||
float2 _Crest_WaterLineResolution;
|
||||
float2 _Crest_WaterLineSnappedPosition;
|
||||
|
||||
m_CrestNameSpace
|
||||
|
||||
float SampleWaterLineHeight(const float2 i_PositionWS)
|
||||
{
|
||||
const float2 uv = (i_PositionWS - _Crest_WaterLineSnappedPosition) / (_Crest_WaterLineTexel * _Crest_WaterLineResolution) + 0.5;
|
||||
return _Crest_WaterLine.SampleLevel(_Crest_linear_clamp_sampler, uv, 0).r + g_Crest_WaterCenter.y;
|
||||
}
|
||||
|
||||
half3 SampleWaterLineNormal(const float2 i_PositionWS, const float i_Height)
|
||||
{
|
||||
const float2 uv = (i_PositionWS - _Crest_WaterLineSnappedPosition) / (_Crest_WaterLineTexel * _Crest_WaterLineResolution) + 0.5;
|
||||
const float3 dd = float3(1.0 / _Crest_WaterLineResolution.xy, 0.0);
|
||||
const float xOffset = _Crest_WaterLine.SampleLevel(_Crest_linear_clamp_sampler, uv + dd.xz, 0).r;
|
||||
const float zOffset = _Crest_WaterLine.SampleLevel(_Crest_linear_clamp_sampler, uv + dd.zy, 0).r;
|
||||
|
||||
return normalize(half3
|
||||
(
|
||||
(xOffset - i_Height) / _Crest_WaterLineTexel,
|
||||
1.0,
|
||||
(zOffset - i_Height) / _Crest_WaterLineTexel
|
||||
));
|
||||
}
|
||||
|
||||
m_CrestNameSpaceEnd
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 23b1ac5d9553947b69f3b3cfa0e3551d
|
||||
ShaderIncludeImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,35 @@
|
||||
// Crest Water System
|
||||
// Copyright © 2024 Wave Harmonic. All rights reserved.
|
||||
|
||||
#ifndef d_WaveHarmonic_Crest_SurfaceFacing
|
||||
#define d_WaveHarmonic_Crest_SurfaceFacing
|
||||
|
||||
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Library/Constants.hlsl"
|
||||
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Library/Macros.hlsl"
|
||||
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Library/Settings.Crest.hlsl"
|
||||
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Library/Helpers.hlsl"
|
||||
|
||||
TEXTURE2D_X(_Crest_WaterMaskTexture);
|
||||
|
||||
m_CrestNameSpace
|
||||
|
||||
bool IsUnderWater(const bool i_FrontFace, const int i_ForceUnderwater, const uint2 i_PositionSS)
|
||||
{
|
||||
bool underwater = false;
|
||||
|
||||
// Use mask.
|
||||
if (i_ForceUnderwater == 0)
|
||||
{
|
||||
underwater = LOAD_TEXTURE2D_X(_Crest_WaterMaskTexture, i_PositionSS).r <= CREST_MASK_BELOW_SURFACE;
|
||||
}
|
||||
else
|
||||
{
|
||||
underwater = IsUnderWater(i_FrontFace, i_ForceUnderwater);
|
||||
}
|
||||
|
||||
return underwater;
|
||||
}
|
||||
|
||||
m_CrestNameSpaceEnd
|
||||
|
||||
#endif // d_WaveHarmonic_Crest_SurfaceFacing
|
||||
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e6b28bd595bf6434facba01c0b5d41b9
|
||||
ShaderIncludeImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,67 @@
|
||||
// Crest Water System
|
||||
// Copyright © 2024 Wave Harmonic. All rights reserved.
|
||||
|
||||
#ifndef d_WaveHarmonic_Crest_SurfaceFog
|
||||
#define d_WaveHarmonic_Crest_SurfaceFog
|
||||
|
||||
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Library/Macros.hlsl"
|
||||
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Library/Settings.Crest.hlsl"
|
||||
|
||||
#define d_Crest_WaterSurface 1
|
||||
|
||||
#if (CREST_LEGACY_UNDERWATER != 1)
|
||||
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Volume/Graph/IntegrateWaterVolume.hlsl"
|
||||
#endif
|
||||
|
||||
m_CrestNameSpace
|
||||
|
||||
#if (CREST_LEGACY_UNDERWATER != 0)
|
||||
static bool s_IsUnderWater;
|
||||
#endif
|
||||
|
||||
void SetUpFog(bool i_Underwater, float3 i_PositionWS, float i_Multiplier, float i_FogDistance, half3 i_ViewWS, float2 i_PositionSS)
|
||||
{
|
||||
s_IsUnderWater = i_Underwater;
|
||||
|
||||
#if (CREST_LEGACY_UNDERWATER != 1)
|
||||
s_PositionSS = i_PositionSS;
|
||||
s_PositionWS = i_PositionWS;
|
||||
s_ViewWS = i_ViewWS;
|
||||
s_FogDistance = i_FogDistance;
|
||||
s_DepthRaw = 0;
|
||||
s_FogMultiplier = i_Multiplier;
|
||||
#endif
|
||||
}
|
||||
|
||||
m_CrestNameSpaceEnd
|
||||
|
||||
#if (CREST_LEGACY_UNDERWATER != 0)
|
||||
#if (CREST_DISCARD_ATMOSPHERIC_SCATTERING != 0)
|
||||
|
||||
#if CREST_BIRP
|
||||
#ifdef UNITY_PASS_FORWARDADD
|
||||
#define m_Unity_FogColor fixed4(0, 0, 0, 0)
|
||||
#else
|
||||
#define m_Unity_FogColor unity_FogColor
|
||||
#endif // UNITY_PASS_FORWARDADD
|
||||
|
||||
#undef UNITY_APPLY_FOG
|
||||
#define UNITY_APPLY_FOG(coord, color) \
|
||||
if (!m_Crest::s_IsUnderWater) \
|
||||
{ \
|
||||
UNITY_APPLY_FOG_COLOR(coord, color, m_Unity_FogColor); \
|
||||
}
|
||||
#endif // CREST_BIRP
|
||||
|
||||
#if CREST_HDRP
|
||||
#define EvaluateAtmosphericScattering(i, V, color) m_Crest::s_IsUnderWater ? color : EvaluateAtmosphericScattering(i, V, color)
|
||||
#endif
|
||||
|
||||
#if CREST_URP
|
||||
#define MixFog(color, coord) m_Crest::s_IsUnderWater ? color : MixFog(color, coord)
|
||||
#endif
|
||||
|
||||
#endif // CREST_DISCARD_ATMOSPHERIC_SCATTERING
|
||||
#endif // CREST_LEGACY_UNDERWATER
|
||||
|
||||
#endif // d_WaveHarmonic_Crest_SurfaceFog
|
||||
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 944710ebd91d247cca9b0a31307f6b87
|
||||
ShaderIncludeImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -30,6 +30,8 @@
|
||||
// Guard against Shader Graph preview.
|
||||
#ifndef SHADERGRAPH_PREVIEW
|
||||
|
||||
#define d_Crest_WaterSurface 1
|
||||
|
||||
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Surface/Shim.hlsl"
|
||||
|
||||
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Library/Macros.hlsl"
|
||||
@@ -45,6 +47,8 @@
|
||||
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Library/Flow.hlsl"
|
||||
|
||||
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Library/Utility/Lighting.hlsl"
|
||||
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Library/Utility/Shadows.hlsl"
|
||||
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Surface/Facing.hlsl"
|
||||
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Surface/Normal.hlsl"
|
||||
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Surface/Reflection.hlsl"
|
||||
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Surface/Refraction.hlsl"
|
||||
@@ -53,19 +57,12 @@
|
||||
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Surface/Fresnel.hlsl"
|
||||
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Surface/Foam.hlsl"
|
||||
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Surface/Alpha.hlsl"
|
||||
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Surface/Fog.hlsl"
|
||||
|
||||
#if (CREST_PORTALS != 0)
|
||||
#include "Packages/com.waveharmonic.crest.portals/Runtime/Shaders/Library/Portals.hlsl"
|
||||
#endif
|
||||
|
||||
#if (CREST_SHADOWS_BUILT_IN_RENDER_PIPELINE != 0)
|
||||
#if CREST_BIRP
|
||||
#define SHADOWS_SPLIT_SPHERES 1
|
||||
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Library/Utility/Legacy/Core.hlsl"
|
||||
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Library/Utility/Legacy/Shadows.hlsl"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
bool _Crest_DrawBoundaryXZ;
|
||||
float4 _Crest_BoundaryXZ;
|
||||
|
||||
@@ -92,6 +89,7 @@ void Fragment(m_Properties)
|
||||
o_Occlusion = 1.0;
|
||||
o_Alpha = 1.0;
|
||||
|
||||
const float2 positionSS = i_ScreenPosition.xy * _ScreenSize.xy;
|
||||
|
||||
// Editor only. There is no defined editor symbol.
|
||||
if (_Crest_DrawBoundaryXZ)
|
||||
@@ -107,7 +105,7 @@ void Fragment(m_Properties)
|
||||
}
|
||||
}
|
||||
|
||||
const bool underwater = IsUnderwater(i_Facing, g_Crest_ForceUnderwater);
|
||||
bool underwater = IsUnderWater(i_Facing, g_Crest_ForceUnderwater, positionSS);
|
||||
|
||||
// TODO: Should we use PosToSIs or check for overflow?
|
||||
float slice0 = _Crest_LodIndex;
|
||||
@@ -121,6 +119,7 @@ void Fragment(m_Properties)
|
||||
const Cascade cascade1 = Cascade::Make(slice1);
|
||||
|
||||
float sceneRawZ = i_SceneDepthRaw;
|
||||
float negativeFog = _ProjectionParams.y;
|
||||
|
||||
#if (CREST_PORTALS != 0)
|
||||
#ifndef CREST_SHADOWPASS
|
||||
@@ -128,7 +127,7 @@ void Fragment(m_Properties)
|
||||
if (m_CrestPortal)
|
||||
{
|
||||
const float pixelRawZ = i_ScreenPositionRaw.z / i_ScreenPositionRaw.w;
|
||||
if (OutsideOfPortal(i_ScreenPosition.xy, pixelRawZ, sceneRawZ))
|
||||
if (Portal::EvaluateSurface(i_ScreenPosition.xy, pixelRawZ, i_PositionWS, underwater, sceneRawZ, negativeFog))
|
||||
{
|
||||
o_Alpha = 0.0;
|
||||
return;
|
||||
@@ -242,15 +241,6 @@ void Fragment(m_Properties)
|
||||
|
||||
// Normal.
|
||||
{
|
||||
WaterNormal
|
||||
(
|
||||
i_WaterLevelDerivatives,
|
||||
i_ViewDirectionWS,
|
||||
_Crest_MinimumReflectionDirectionY,
|
||||
underwater,
|
||||
o_NormalWS
|
||||
);
|
||||
|
||||
if (_Crest_NormalMapEnabled)
|
||||
{
|
||||
o_NormalWS.xz += SampleNormalMaps
|
||||
@@ -268,6 +258,17 @@ void Fragment(m_Properties)
|
||||
|
||||
o_NormalWS = normalize(o_NormalWS);
|
||||
|
||||
WaterNormal
|
||||
(
|
||||
i_WaterLevelDerivatives,
|
||||
i_ViewDirectionWS,
|
||||
_Crest_MinimumReflectionDirectionY,
|
||||
underwater,
|
||||
o_NormalWS
|
||||
);
|
||||
|
||||
o_NormalWS = normalize(o_NormalWS);
|
||||
|
||||
o_NormalWS.xz *= _Crest_NormalsStrengthOverall;
|
||||
o_NormalWS.y = lerp(1.0, o_NormalWS.y, _Crest_NormalsStrengthOverall);
|
||||
|
||||
@@ -282,11 +283,7 @@ void Fragment(m_Properties)
|
||||
float sceneDistance = 1000.0;
|
||||
float3 scenePositionWS = 0.0;
|
||||
|
||||
half3 ambientLight = 0.0;
|
||||
AmbientLight
|
||||
(
|
||||
ambientLight
|
||||
);
|
||||
const half3 ambientLight = AmbientLight();
|
||||
|
||||
float3 lightIntensity = 0.0;
|
||||
half3 lightDirection = 0.0;
|
||||
@@ -300,15 +297,8 @@ void Fragment(m_Properties)
|
||||
|
||||
half3 additionalLight = AdditionalLighting(i_PositionWS, i_ScreenPositionRaw, i_StaticLightMapUV);
|
||||
|
||||
#if d_Crest_ReceiveShadowsTransparent
|
||||
// Sample shadow maps.
|
||||
float4 shadowCoord = GET_SHADOW_COORDINATES(float4(i_PositionWS, 1.0));
|
||||
half shadows = UNITY_SAMPLE_SHADOW(_ShadowMapTexture, shadowCoord);
|
||||
shadows = lerp(_LightShadowData.r, 1.0, shadows);
|
||||
shadows = min(shadow.y, shadows);
|
||||
#endif
|
||||
|
||||
#if d_Transparent
|
||||
#ifndef d_SkipRefraction
|
||||
bool caustics;
|
||||
RefractedScene
|
||||
(
|
||||
@@ -325,11 +315,24 @@ void Fragment(m_Properties)
|
||||
scenePositionWS,
|
||||
caustics
|
||||
);
|
||||
#endif
|
||||
|
||||
float refractedSeaLevel = 0;
|
||||
float3 refractedSurfacePosition = 0;
|
||||
if (!underwater)
|
||||
#if CREST_BIRP
|
||||
#if SHADERPASS == SHADERPASS_FORWARD_BASE
|
||||
if (g_Crest_PrimaryLightHasCookie)
|
||||
{
|
||||
// If light has a cookie, it is zero for the ForwardBase pass. We need to split
|
||||
// emission over ForwardBase and ForwardAdd. Ambient is done in the former, while
|
||||
// direct (eg caustics) is done in ForwardAdd.
|
||||
o_Emission = 0;
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
#endif // d_SkipRefraction
|
||||
#endif // d_Transparent
|
||||
|
||||
float refractedSeaLevel = g_Crest_WaterCenter.y;
|
||||
float3 refractedSurfacePosition = float3(0, refractedSeaLevel, 0);
|
||||
if (!underwater && slice1 < g_Crest_LodCount)
|
||||
{
|
||||
// Sample larger slice to avoid the first slice.
|
||||
float4 displacement = Cascade::MakeAnimatedWaves(slice1).Sample(scenePositionWS.xz);
|
||||
@@ -347,15 +350,11 @@ void Fragment(m_Properties)
|
||||
}
|
||||
|
||||
#if d_Transparent
|
||||
#ifndef d_SkipRefraction
|
||||
// Caustics
|
||||
if (_Crest_CausticsEnabled && !underwater && caustics)
|
||||
{
|
||||
float3 position = scenePositionWS;
|
||||
#if CREST_BIRP
|
||||
position = float3(i_ScreenPosition.xy * _ScreenSize.xy, 0);
|
||||
#endif
|
||||
|
||||
half lightOcclusion = PrimaryLightShadows(position);
|
||||
half lightOcclusion = PrimaryLightShadows(scenePositionWS, positionSS);
|
||||
|
||||
half blur = 0.0;
|
||||
#ifdef CREST_FLOW_ON
|
||||
@@ -384,7 +383,8 @@ void Fragment(m_Properties)
|
||||
underwater
|
||||
);
|
||||
}
|
||||
#endif
|
||||
#endif // d_SkipRefraction
|
||||
#endif // d_Transparent
|
||||
|
||||
half3 sss = 0.0;
|
||||
|
||||
@@ -404,11 +404,11 @@ void Fragment(m_Properties)
|
||||
}
|
||||
|
||||
// Volume Lighting
|
||||
half3 volumeLight = 0.0;
|
||||
half3 volumeOpacity = 0.0;
|
||||
VolumeLighting
|
||||
const half3 extinction = VolumeExtinction(absorption, scattering);
|
||||
const half3 volumeOpacity = VolumeOpacity(extinction, sceneDistance);
|
||||
const half3 volumeLight = VolumeLighting
|
||||
(
|
||||
absorption,
|
||||
extinction,
|
||||
scattering,
|
||||
_Crest_Anisotropy,
|
||||
shadow.x,
|
||||
@@ -419,11 +419,8 @@ void Fragment(m_Properties)
|
||||
additionalLight,
|
||||
_Crest_AmbientTerm,
|
||||
_Crest_DirectTerm,
|
||||
sceneDistance,
|
||||
sss,
|
||||
_Crest_ShadowsAffectsAmbientFactor,
|
||||
volumeLight,
|
||||
volumeOpacity
|
||||
_Crest_ShadowsAffectsAmbientFactor
|
||||
);
|
||||
|
||||
// Fresnel
|
||||
@@ -531,11 +528,6 @@ void Fragment(m_Properties)
|
||||
|
||||
half3 intensity = _Crest_FoamIntensityAlbedo;
|
||||
|
||||
#if d_Crest_ReceiveShadowsTransparent
|
||||
// @HACK: Scale intensity as BIRP does not support shadows for transparent objects.
|
||||
intensity = max(_Crest_FoamIntensityAlbedo * saturate(ShadeSH9(float4(o_NormalWS, 1.0))), _Crest_FoamIntensityAlbedo * shadows);
|
||||
#endif
|
||||
|
||||
ApplyFoamToSurface
|
||||
(
|
||||
albedo,
|
||||
@@ -589,12 +581,15 @@ void Fragment(m_Properties)
|
||||
o_Alpha = min(o_Alpha, 1.0);
|
||||
}
|
||||
|
||||
#if d_Crest_ReceiveShadowsTransparent
|
||||
// @HACK: Dull highlights as BIRP does not support shadows for transparent objects.
|
||||
o_Smoothness *= lerp(1, shadows, foam * 100);
|
||||
// @FIXME: 0.2 to difference when high. Likely incorrect shadow sampling.
|
||||
o_Specular = shadows < 0.2 ? 1.0 - max(shadows, 0.3) : o_Specular;
|
||||
#endif
|
||||
SetUpFog
|
||||
(
|
||||
underwater,
|
||||
i_PositionWS,
|
||||
1.0, // N/A: multiplier for fog nodes
|
||||
sceneDistance - negativeFog,
|
||||
i_ViewDirectionWS,
|
||||
positionSS
|
||||
);
|
||||
}
|
||||
|
||||
m_CrestNameSpaceEnd
|
||||
|
||||
@@ -8,6 +8,14 @@
|
||||
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Library/Globals.hlsl"
|
||||
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Library/Cascade.hlsl"
|
||||
|
||||
// These are per cascade, set per chunk instance.
|
||||
CBUFFER_START(CrestChunkGeometryData)
|
||||
float _Crest_ChunkMeshScaleAlpha;
|
||||
float _Crest_ChunkMeshScaleAlphaSource;
|
||||
float _Crest_ChunkGeometryGridWidth;
|
||||
float _Crest_ChunkGeometryGridWidthSource;
|
||||
CBUFFER_END
|
||||
|
||||
m_CrestNameSpace
|
||||
|
||||
// i_meshScaleAlpha is passed in as it is provided per tile and is set only for LOD0
|
||||
@@ -49,7 +57,8 @@ void SnapAndTransitionVertLayout(in const float4x4 i_objectMatrix, in const floa
|
||||
objectPosXZWS += _WorldSpaceCameraPos.xz;
|
||||
#endif
|
||||
|
||||
io_worldPos.xz -= frac(objectPosXZWS / GRID_SIZE_2) * GRID_SIZE_2; // caution - sign of frac might change in non-hlsl shaders
|
||||
const float2 gridOffset = frac(objectPosXZWS / GRID_SIZE_2) * GRID_SIZE_2;
|
||||
io_worldPos.xz -= gridOffset; // caution - sign of frac might change in non-hlsl shaders
|
||||
|
||||
// compute lod transition alpha
|
||||
o_lodAlpha = ComputeLodAlpha(io_worldPos, i_meshScaleAlpha, i_cascadeData0);
|
||||
@@ -63,6 +72,20 @@ void SnapAndTransitionVertLayout(in const float4x4 i_objectMatrix, in const floa
|
||||
const float minRadius = 0.375;
|
||||
if (abs(offset.x) < minRadius) io_worldPos.x += offset.x * o_lodAlpha * GRID_SIZE_4;
|
||||
if (abs(offset.y) < minRadius) io_worldPos.z += offset.y * o_lodAlpha * GRID_SIZE_4;
|
||||
|
||||
#if SHADER_API_VULKAN
|
||||
#if CREST_HDRP
|
||||
#if _TRANSPARENT_WRITES_MOTION_VEC
|
||||
// Fixes artifacts where parts of the surface appear to be clipped. It appears to
|
||||
// be a precision issue (LOD resolution not power of 2), but only when the MV code
|
||||
// path is active - even though it writes to a separate target.
|
||||
if (any(isinf(gridOffset)))
|
||||
{
|
||||
o_lodAlpha = 0.0;
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
void SnapAndTransitionVertLayout(in const float i_meshScaleAlpha, in const Cascade i_cascadeData0, in const float i_geometryGridSize, inout float3 io_worldPos, out float o_lodAlpha)
|
||||
|
||||
@@ -13,6 +13,10 @@
|
||||
#include "Packages/com.waveharmonic.crest.shifting-origin/Runtime/Shaders/ShiftingOrigin.hlsl"
|
||||
#endif
|
||||
|
||||
// These are per cascade, set per chunk instance.
|
||||
float _Crest_ChunkFarNormalsWeight;
|
||||
float2 _Crest_ChunkNormalScrollSpeed;
|
||||
|
||||
m_CrestNameSpace
|
||||
|
||||
half2 SampleNormalMaps
|
||||
|
||||
@@ -65,7 +65,7 @@ void RefractedScene
|
||||
#if (CREST_PORTALS != 0)
|
||||
#if _ALPHATEST_ON
|
||||
// Portals
|
||||
ApplyPortalRefractions(positionNDCRefracted, i_SceneZRaw, i_Underwater, sceneDepthRawRefracted, o_Caustics);
|
||||
Portal::EvaluateRefraction(positionNDCRefracted, i_SceneZRaw, i_Underwater, sceneDepthRawRefracted, o_Caustics);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
@@ -10,13 +10,12 @@
|
||||
#ifndef CREST_SHADERGRAPH_CONSTANTS_H
|
||||
#define CREST_SHADERGRAPH_CONSTANTS_H
|
||||
|
||||
// "pow(f,e) will not work for negative f"
|
||||
#pragma warning (disable : 3571)
|
||||
|
||||
#ifdef UNIVERSAL_PIPELINE_CORE_INCLUDED
|
||||
#define CREST_URP 1
|
||||
|
||||
#if (SHADERPASS == SHADERPASS_SHADOWCASTER)
|
||||
#define CREST_SHADOWPASS 1
|
||||
#endif
|
||||
|
||||
#if _SURFACE_TYPE_TRANSPARENT
|
||||
#define d_Transparent 1
|
||||
#endif
|
||||
@@ -24,18 +23,11 @@
|
||||
#elif BUILTIN_TARGET_API
|
||||
#define CREST_BIRP 1
|
||||
|
||||
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Library/Utility/Legacy/InputsDriven.hlsl"
|
||||
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Library/Utility/Legacy/Common.hlsl"
|
||||
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Library/Utility/Legacy/Core.hlsl"
|
||||
|
||||
#if _BUILTIN_SURFACE_TYPE_TRANSPARENT
|
||||
#define d_Transparent 1
|
||||
#endif
|
||||
|
||||
// SHADERPASS is currently broken:
|
||||
// https://forum.unity.com/threads/built-in-renderer-shaderpass-include-in-wrong-place.1444156/
|
||||
// #if (SHADERPASS == SHADERPASS_SHADOWCASTER)
|
||||
// #define CREST_SHADOWPASS 1
|
||||
// #endif
|
||||
#else
|
||||
// HDRP does not appear to have a reliable keyword to target.
|
||||
#define CREST_HDRP 1
|
||||
@@ -49,8 +41,21 @@
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(CREST_BIRP) || defined(CREST_URP)
|
||||
#if (SHADERPASS == SHADERPASS_SHADOWCASTER)
|
||||
#define CREST_SHADOWPASS 1
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(CREST_HDRP) && (SHADERPASS == SHADERPASS_FORWARD)
|
||||
#define CREST_HDRP_FORWARD_PASS 1
|
||||
#endif
|
||||
|
||||
#if defined(CREST_BIRP) && (SHADERPASS == SHADERPASS_FORWARD_ADD)
|
||||
#ifndef DIRECTIONAL_COOKIE
|
||||
#define d_SkipRefraction 1
|
||||
#define d_IsAdditionalLight 1
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#endif // CREST_SHADERGRAPH_CONSTANTS_H
|
||||
|
||||
@@ -29,14 +29,14 @@
|
||||
|
||||
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Library/Utility/Depth.hlsl"
|
||||
|
||||
#if CREST_URP
|
||||
#ifndef CREST_HDRP
|
||||
#if (SHADERPASS == SHADERPASS_MOTION_VECTORS)
|
||||
#define _TRANSPARENT_WRITES_MOTION_VEC 1
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if _TRANSPARENT_WRITES_MOTION_VEC
|
||||
#define m_Slice clamp(_Crest_LodIndex + (isMotionVectors ? g_Crest_LodChange : 0), 0, g_Crest_LodCount)
|
||||
#define m_Slice clamp((int)_Crest_LodIndex + (isMotionVectors ? g_Crest_LodChange : 0), 0, g_Crest_LodCount)
|
||||
#define m_Make(slice) Make(slice, isMotionVectors)
|
||||
#else
|
||||
#define m_Slice _Crest_LodIndex
|
||||
@@ -146,7 +146,7 @@ void Vertex(m_Properties)
|
||||
o_PositionWS.xz -= g_Crest_WaterCenter.xz;
|
||||
o_PositionWS.xz *= g_Crest_WaterScaleChange;
|
||||
o_PositionWS.xz += g_Crest_WaterCenter.xz;
|
||||
o_PositionWS += g_Crest_WaterCenterDelta;
|
||||
o_PositionWS.xz += g_Crest_WaterCenterDelta;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -18,9 +18,22 @@ float SchlickPhase(float phaseG, float cosTheta)
|
||||
return (1.0 - schlickK * schlickK) / (4.0 * PI * phaseFactor * phaseFactor);
|
||||
}
|
||||
|
||||
void VolumeLighting
|
||||
half3 VolumeExtinction(const half3 i_Absorption, const half3 i_Scattering)
|
||||
{
|
||||
// Extinction is light absorbed plus light scattered out.
|
||||
return i_Absorption + i_Scattering;
|
||||
}
|
||||
|
||||
half3 VolumeOpacity(const half3 i_Extinction, const half i_WaterRayLength)
|
||||
{
|
||||
// Like 'alpha' value or obscurance. Volume light needs multiplying by this value
|
||||
// to be correct in shallows.
|
||||
return 1.0 - exp(-i_Extinction * max(0.0, i_WaterRayLength));
|
||||
}
|
||||
|
||||
half3 VolumeLighting
|
||||
(
|
||||
const half3 i_Absorption,
|
||||
const half3 i_Extinction,
|
||||
const half3 i_Scattering,
|
||||
const half i_PhaseG,
|
||||
const half i_DirectionalLightShadow,
|
||||
@@ -31,15 +44,11 @@ void VolumeLighting
|
||||
const half3 i_AdditionalLight,
|
||||
const half i_AmbientLightingTerm,
|
||||
const half i_PrimaryLightingTerm,
|
||||
const half i_WaterRayLength,
|
||||
const half3 i_SunBoost,
|
||||
const half i_ShadowsAffectAmbientLightingFactor,
|
||||
out half3 o_VolumeLight,
|
||||
out half3 o_VolumeOpacity
|
||||
const half i_ShadowsAffectAmbientLightingFactor
|
||||
)
|
||||
{
|
||||
// Extinction is light absorbed plus light scattered out.
|
||||
const half3 extinction = i_Absorption + i_Scattering;
|
||||
const half3 extinction = i_Extinction;
|
||||
|
||||
const float ambientLightShadow = lerp
|
||||
(
|
||||
@@ -48,6 +57,9 @@ void VolumeLighting
|
||||
saturate(min(min(extinction.x, extinction.y), extinction.z) * i_ShadowsAffectAmbientLightingFactor * g_Crest_DynamicSoftShadowsFactor)
|
||||
);
|
||||
|
||||
#ifdef d_IsAdditionalLight
|
||||
const float3 inscattered = i_PrimaryLightIntensity;
|
||||
#else
|
||||
// Sun
|
||||
const float sunPhase = SchlickPhase(i_PhaseG, dot(i_PrimaryLightDirection, i_ViewDirectionWS));
|
||||
const float3 inScatteredSun = (1.0 + i_SunBoost) * sunPhase * i_PrimaryLightIntensity * i_PrimaryLightingTerm;
|
||||
@@ -55,11 +67,11 @@ void VolumeLighting
|
||||
|
||||
// Total inscattered
|
||||
const float3 inscattered = (inScatteredAmbient + i_AdditionalLight + inScatteredSun * i_DirectionalLightShadow);
|
||||
const float3 scatteringAmount = saturate(i_Scattering / max(extinction, 0.00001));
|
||||
o_VolumeLight = inscattered * scatteringAmount;
|
||||
#endif
|
||||
|
||||
// Like 'alpha' value or obscurance. Volume light needs multiplying by this value to be correct in shallows.
|
||||
o_VolumeOpacity = 1.0 - exp(-extinction * max(0.0, i_WaterRayLength));
|
||||
const float3 scatteringAmount = saturate(i_Scattering / max(extinction, 0.00001));
|
||||
|
||||
return inscattered * scatteringAmount;
|
||||
}
|
||||
|
||||
half PinchSSS
|
||||
|
||||
@@ -522,20 +522,6 @@
|
||||
"m_SlotId": 0
|
||||
}
|
||||
},
|
||||
{
|
||||
"m_OutputSlot": {
|
||||
"m_Node": {
|
||||
"m_Id": "6fb510b9ca124cf881fe849664df5924"
|
||||
},
|
||||
"m_SlotId": 2
|
||||
},
|
||||
"m_InputSlot": {
|
||||
"m_Node": {
|
||||
"m_Id": "8e8aee51883445f1b08bfbec696cb18d"
|
||||
},
|
||||
"m_SlotId": 0
|
||||
}
|
||||
},
|
||||
{
|
||||
"m_OutputSlot": {
|
||||
"m_Node": {
|
||||
@@ -862,10 +848,10 @@
|
||||
"m_Id": "4bb923e45f9f48bab142707a3af6e4bd"
|
||||
},
|
||||
{
|
||||
"m_Id": "8e8aee51883445f1b08bfbec696cb18d"
|
||||
"m_Id": "b7891fe7e5a34f03adebd8a45505c5fc"
|
||||
},
|
||||
{
|
||||
"m_Id": "b7891fe7e5a34f03adebd8a45505c5fc"
|
||||
"m_Id": "8e8aee51883445f1b08bfbec696cb18d"
|
||||
},
|
||||
{
|
||||
"m_Id": "e207931e020242bba83058a59f3fb07d"
|
||||
@@ -1170,7 +1156,7 @@
|
||||
"m_ObjectId": "0b12e9fc0b164611b7fa17e0c6955043",
|
||||
"m_Title": "Interpolators",
|
||||
"m_Position": {
|
||||
"x": 590.9999389648438,
|
||||
"x": 591.0,
|
||||
"y": 208.5
|
||||
}
|
||||
}
|
||||
@@ -2458,7 +2444,7 @@
|
||||
"m_SGVersion": 0,
|
||||
"m_Type": "UnityEditor.Rendering.HighDefinition.ShaderGraph.SystemData",
|
||||
"m_ObjectId": "4d02d98ad13c416c989fa4a1c65d2550",
|
||||
"m_MaterialNeedsUpdateHash": 279864,
|
||||
"m_MaterialNeedsUpdateHash": 279880,
|
||||
"m_SurfaceType": 1,
|
||||
"m_RenderingPass": 4,
|
||||
"m_BlendMode": 0,
|
||||
@@ -2483,7 +2469,7 @@
|
||||
"m_TessellationShapeFactor": 0.75,
|
||||
"m_TessellationBackFaceCullEpsilon": -0.25,
|
||||
"m_TessellationMaxDisplacement": 0.009999999776482582,
|
||||
"m_Version": 1,
|
||||
"m_Version": 2,
|
||||
"inspectorFoldoutMask": 11
|
||||
}
|
||||
|
||||
@@ -3382,7 +3368,7 @@
|
||||
"overrideHLSLDeclaration": false,
|
||||
"hlslDeclarationOverride": 0,
|
||||
"m_Hidden": false,
|
||||
"m_Value": 0.0,
|
||||
"m_Value": 0.03,
|
||||
"m_FloatType": 1,
|
||||
"m_RangeValues": {
|
||||
"x": -1.0,
|
||||
@@ -3677,7 +3663,7 @@
|
||||
"overrideHLSLDeclaration": false,
|
||||
"hlslDeclarationOverride": 0,
|
||||
"m_Hidden": false,
|
||||
"m_Value": 0.4000000059604645,
|
||||
"m_Value": 0.8,
|
||||
"m_FloatType": 1,
|
||||
"m_RangeValues": {
|
||||
"x": 0.0,
|
||||
@@ -4620,7 +4606,7 @@
|
||||
"m_SGVersion": 2,
|
||||
"m_Type": "UnityEditor.Rendering.Universal.ShaderGraph.UniversalLitSubTarget",
|
||||
"m_ObjectId": "a52dd0dd7c42405cabd2b96b877532a3",
|
||||
"m_WorkflowMode": 0,
|
||||
"m_WorkflowMode": 1,
|
||||
"m_NormalDropOffSpace": 2,
|
||||
"m_ClearCoat": false,
|
||||
"m_BlendModePreserveSpecular": false
|
||||
@@ -5096,10 +5082,11 @@
|
||||
|
||||
{
|
||||
"m_SGVersion": 0,
|
||||
"m_Type": "UnityEditor.Rendering.BuiltIn.ShaderGraph.BuiltInLitSubTarget",
|
||||
"m_Type": "WaveHarmonic.Crest.Editor.ShaderGraph.BuiltInLitSubTarget",
|
||||
"m_ObjectId": "bb3b0e5f6ef041aebb81194f38a5d07c",
|
||||
"m_WorkflowMode": 1,
|
||||
"m_NormalDropOffSpace": 2
|
||||
"m_NormalDropOffSpace": 2,
|
||||
"m_TransparentReceiveShadows": true
|
||||
}
|
||||
|
||||
{
|
||||
@@ -5349,7 +5336,7 @@
|
||||
"overrideHLSLDeclaration": false,
|
||||
"hlslDeclarationOverride": 0,
|
||||
"m_Hidden": false,
|
||||
"m_Value": 10.0,
|
||||
"m_Value": 3.0,
|
||||
"m_FloatType": 0,
|
||||
"m_RangeValues": {
|
||||
"x": 0.0,
|
||||
@@ -5433,7 +5420,8 @@
|
||||
"m_Type": "UnityEditor.Rendering.HighDefinition.ShaderGraph.HDLitData",
|
||||
"m_ObjectId": "cee72db709954dd38e8039e087fe5744",
|
||||
"m_RayTracing": false,
|
||||
"m_MaterialType": 4,
|
||||
"m_MaterialType": 0,
|
||||
"m_MaterialTypeMask": 18,
|
||||
"m_RefractionModel": 1,
|
||||
"m_SSSTransmission": true,
|
||||
"m_EnergyConservingSpecular": false,
|
||||
|
||||
@@ -1,19 +1,15 @@
|
||||
// Crest Water System
|
||||
// Crest Water System
|
||||
// Copyright © 2024 Wave Harmonic. All rights reserved.
|
||||
|
||||
// Provides utility passes for rendering like clearing the stencil buffer.
|
||||
|
||||
Shader "Hidden/Crest/Utility/Blit"
|
||||
Shader "Hidden/Crest/Legacy/Blit"
|
||||
{
|
||||
HLSLINCLUDE
|
||||
#pragma vertex Vertex
|
||||
#pragma fragment Fragment
|
||||
|
||||
#include "UnityCG.cginc"
|
||||
|
||||
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Library/Utility/Legacy/Core.hlsl"
|
||||
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Library/Utility/Legacy/InputsDriven.hlsl"
|
||||
|
||||
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Library/Utility/Depth.hlsl"
|
||||
|
||||
struct Attributes
|
||||
@@ -44,28 +40,10 @@ Shader "Hidden/Crest/Utility/Blit"
|
||||
|
||||
SubShader
|
||||
{
|
||||
Cull Off ZWrite On ZTest Always
|
||||
|
||||
Pass
|
||||
{
|
||||
// Copies the color texture.
|
||||
Name "Copy Color"
|
||||
|
||||
ZWrite Off
|
||||
ZTest Always
|
||||
Cull Off
|
||||
|
||||
HLSLPROGRAM
|
||||
TEXTURE2D_X(_CameraColorTexture);
|
||||
|
||||
float4 Fragment(Varyings input) : SV_Target
|
||||
{
|
||||
// We need this when sampling a screenspace texture.
|
||||
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);
|
||||
return LOAD_TEXTURE2D_X(_CameraColorTexture, input.positionCS.xy);
|
||||
}
|
||||
ENDHLSL
|
||||
}
|
||||
Blend Off
|
||||
Cull Off
|
||||
ZTest Always
|
||||
ZWrite Off
|
||||
|
||||
Pass
|
||||
{
|
||||
@@ -73,8 +51,6 @@ Shader "Hidden/Crest/Utility/Blit"
|
||||
Name "Copy Depth / Clear Stencil"
|
||||
|
||||
ZWrite On
|
||||
ZTest Always
|
||||
Cull Off
|
||||
|
||||
Stencil
|
||||
{
|
||||
@@ -94,52 +70,9 @@ Shader "Hidden/Crest/Utility/Blit"
|
||||
ENDHLSL
|
||||
}
|
||||
|
||||
Pass
|
||||
{
|
||||
// Clears the depth buffer without clearing the stencil.
|
||||
Name "Clear Depth"
|
||||
|
||||
ZWrite On
|
||||
ZTest Always
|
||||
Cull Off
|
||||
|
||||
HLSLPROGRAM
|
||||
float Fragment(Varyings input) : SV_Depth
|
||||
{
|
||||
return 0.0;
|
||||
}
|
||||
ENDHLSL
|
||||
}
|
||||
|
||||
Pass
|
||||
{
|
||||
// Clears the stencil buffer without clearing depth
|
||||
Name "Clear Stencil"
|
||||
|
||||
ZWrite Off
|
||||
ZTest Always
|
||||
Cull Off
|
||||
Blend Zero One
|
||||
|
||||
Stencil
|
||||
{
|
||||
Ref 0
|
||||
Comp Always
|
||||
Pass Replace
|
||||
}
|
||||
|
||||
HLSLPROGRAM
|
||||
float Fragment(Varyings input) : SV_Target
|
||||
{
|
||||
return 0.0;
|
||||
}
|
||||
ENDHLSL
|
||||
}
|
||||
|
||||
Pass
|
||||
{
|
||||
Name "Copy"
|
||||
Blend Off
|
||||
|
||||
HLSLPROGRAM
|
||||
TEXTURE2D(_Utility_MainTexture);
|
||||
@@ -150,5 +83,23 @@ Shader "Hidden/Crest/Utility/Blit"
|
||||
}
|
||||
ENDHLSL
|
||||
}
|
||||
|
||||
Pass
|
||||
{
|
||||
Name "Merge Depth"
|
||||
|
||||
// All is required to merge depth.
|
||||
ZTest Less
|
||||
ZWrite On
|
||||
|
||||
HLSLPROGRAM
|
||||
TEXTURE2D_X(_Utility_MainTexture);
|
||||
float Fragment(Varyings input) : SV_Depth
|
||||
{
|
||||
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);
|
||||
return LOAD_DEPTH_TEXTURE_X(_Utility_MainTexture, input.positionCS.xy);
|
||||
}
|
||||
ENDHLSL
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Crest Water System
|
||||
// Crest Water System
|
||||
// Copyright © 2024 Wave Harmonic. All rights reserved.
|
||||
|
||||
// Clear specific components using a mask.
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7c6a37fe33f609947b680abac9e850cc
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,42 @@
|
||||
// Crest Water System
|
||||
// Copyright © 2024 Wave Harmonic. All rights reserved.
|
||||
|
||||
Shader "Hidden/Crest/Legacy/CaptureShadowMatrices"
|
||||
{
|
||||
SubShader
|
||||
{
|
||||
Blend Off
|
||||
ColorMask 0
|
||||
Cull Off
|
||||
ZTest Always
|
||||
ZWrite Off
|
||||
|
||||
Pass
|
||||
{
|
||||
HLSLPROGRAM
|
||||
#pragma target 4.5
|
||||
#pragma vertex Vertex
|
||||
#pragma fragment Fragment
|
||||
|
||||
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl"
|
||||
|
||||
RWStructuredBuffer<float4x4> _Crest_WorldToShadow;
|
||||
float4x4 unity_WorldToShadow[4];
|
||||
|
||||
float4 Vertex(uint id : SV_VertexID) : SV_POSITION
|
||||
{
|
||||
return GetFullScreenTriangleVertexPosition(id);
|
||||
}
|
||||
|
||||
float4 Fragment(float4 pos : SV_POSITION) : SV_Target
|
||||
{
|
||||
_Crest_WorldToShadow[0] = unity_WorldToShadow[0];
|
||||
_Crest_WorldToShadow[1] = unity_WorldToShadow[1];
|
||||
_Crest_WorldToShadow[2] = unity_WorldToShadow[2];
|
||||
_Crest_WorldToShadow[3] = unity_WorldToShadow[3];
|
||||
return 0;
|
||||
}
|
||||
ENDHLSL
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 17feb724c7e004b4e8e418931db7eff3
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,51 @@
|
||||
// Crest Water System
|
||||
// Copyright © 2024 Wave Harmonic. All rights reserved.
|
||||
|
||||
Shader "Hidden/Crest/Legacy/ForceShadows"
|
||||
{
|
||||
CGINCLUDE
|
||||
#pragma vertex Vertex
|
||||
#pragma fragment Fragment
|
||||
|
||||
fixed4 Vertex(fixed4 v : POSITION) : SV_POSITION
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
fixed4 Fragment(fixed4 i : SV_POSITION) : SV_Target
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
ENDCG
|
||||
|
||||
SubShader
|
||||
{
|
||||
ZTest Always
|
||||
ZWrite Off
|
||||
ColorMask 0
|
||||
|
||||
Pass
|
||||
{
|
||||
Tags
|
||||
{
|
||||
"LightMode" = "ForwardBase"
|
||||
}
|
||||
|
||||
CGPROGRAM
|
||||
#pragma multi_compile_fwdbase
|
||||
ENDCG
|
||||
}
|
||||
|
||||
Pass
|
||||
{
|
||||
Tags
|
||||
{
|
||||
"LightMode" = "ForwardAdd"
|
||||
}
|
||||
|
||||
CGPROGRAM
|
||||
#pragma multi_compile_fwdadd_fullshadows
|
||||
ENDCG
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c9f384b6b84e943ed83161cb82d95b2e
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user