This commit is contained in:
zhangjiajia
2026-05-06 16:56:59 +08:00
parent 575626d3e1
commit 81ffaaeca6
1373 changed files with 145920 additions and 0 deletions

View File

@@ -0,0 +1,74 @@
// Crest Water System
// Copyright © 2024 Wave Harmonic. All rights reserved.
// Helpers that will only be used for shaders (eg depth, lighting etc).
#ifndef d_WaveHarmonic_Utility_Depth
#define d_WaveHarmonic_Utility_Depth
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Library/Utility/Macros.hlsl"
// Silence Unity errors in SG editor.
#ifdef SHADERGRAPH_PREVIEW
#define LOAD_DEPTH_TEXTURE_X(a, b) 0
#define TEXTURE2D_X(t) Texture2D t
#else
#define LOAD_DEPTH_TEXTURE_X(textureName, coord2) LOAD_TEXTURE2D_X(textureName, coord2).r
#endif
m_UtilityNameSpace
// Taken from:
// https://www.cyanilux.com/tutorials/depth/#depth-output
float LinearDepthToNonLinear(float depth, float4 zBufferParameters)
{
return (1.0 - depth * zBufferParameters.y) / (depth * zBufferParameters.x);
}
// Taken from:
// https://www.cyanilux.com/tutorials/depth/#depth-output
float EyeDepthToNonLinear(float depth, float4 zBufferParameters)
{
return (1.0 - depth * zBufferParameters.w) / (depth * zBufferParameters.z);
}
// Same as LinearEyeDepth except supports orthographic projection. Use projection keywords to restrict support to either
// of these modes as an optimisation.
float CrestLinearEyeDepth(const float i_rawDepth)
{
#if !defined(_PROJECTION_ORTHOGRAPHIC)
// Handles UNITY_REVERSED_Z for us.
#if defined(UNITY_CG_INCLUDED)
float perspective = LinearEyeDepth(i_rawDepth);
#elif defined(UNITY_COMMON_INCLUDED)
float perspective = LinearEyeDepth(i_rawDepth, _ZBufferParams);
#endif
#endif // _PROJECTION
#if !defined(_PROJECTION_PERSPECTIVE)
// Orthographic Depth taken and modified from:
// https://github.com/keijiro/DepthInverseProjection/blob/master/Assets/InverseProjection/Resources/InverseProjection.shader
float near = _ProjectionParams.y;
float far = _ProjectionParams.z;
float isOrthographic = unity_OrthoParams.w;
#if defined(UNITY_REVERSED_Z)
float orthographic = lerp(far, near, i_rawDepth);
#else
float orthographic = lerp(near, far, i_rawDepth);
#endif // UNITY_REVERSED_Z
#endif // _PROJECTION
#if defined(_PROJECTION_ORTHOGRAPHIC)
return orthographic;
#elif defined(_PROJECTION_PERSPECTIVE)
return perspective;
#else
// If a shader does not have the projection enumeration, then assume they want to support both projection modes.
return lerp(perspective, orthographic, isOrthographic);
#endif // _PROJECTION
}
m_UtilityNameSpaceEnd
#endif // d_WaveHarmonic_Utility_Depth

View File

@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 941ad013a0cbf4dec8d525ee790f5c6e
ShaderIncludeImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,71 @@
// Crest Water System
// Copyright © 2024 Wave Harmonic. All rights reserved.
#ifndef d_WaveHarmonic_Utility_Filtering
#define d_WaveHarmonic_Utility_Filtering
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Library/Utility/Macros.hlsl"
m_UtilityNameSpace
// Taken from:
// https://gist.github.com/TheRealMJP/c83b8c0f46b63f3a88a5986f4fa982b1
//
// The following code is licensed under the MIT license:
// https://gist.github.com/TheRealMJP/bc503b0b87b643d3505d41eab8b332ae
//
// Samples a texture with Catmull-Rom filtering, using 9 texture fetches instead of 16.
// See http://vec3.ca/bicubic-filtering-in-fewer-taps/ for more details
float4 SampleTextureCatmullRom(in Texture2D<float4> tex, in SamplerState linearSampler, in float2 uv, in float2 texSize)
{
// We're going to sample a a 4x4 grid of texels surrounding the target UV coordinate. We'll do this by rounding
// down the sample location to get the exact center of our "starting" texel. The starting texel will be at
// location [1, 1] in the grid, where [0, 0] is the top left corner.
float2 samplePos = uv * texSize;
float2 texPos1 = floor(samplePos - 0.5f) + 0.5f;
// Compute the fractional offset from our starting texel to our original sample location, which we'll
// feed into the Catmull-Rom spline function to get our filter weights.
float2 f = samplePos - texPos1;
// Compute the Catmull-Rom weights using the fractional offset that we calculated earlier.
// These equations are pre-expanded based on our knowledge of where the texels will be located,
// which lets us avoid having to evaluate a piece-wise function.
float2 w0 = f * (-0.5f + f * (1.0f - 0.5f * f));
float2 w1 = 1.0f + f * f * (-2.5f + 1.5f * f);
float2 w2 = f * (0.5f + f * (2.0f - 1.5f * f));
float2 w3 = f * f * (-0.5f + 0.5f * f);
// Work out weighting factors and sampling offsets that will let us use bilinear filtering to
// simultaneously evaluate the middle 2 samples from the 4x4 grid.
float2 w12 = w1 + w2;
float2 offset12 = w2 / (w1 + w2);
// Compute the final UV coordinates we'll use for sampling the texture
float2 texPos0 = texPos1 - 1;
float2 texPos3 = texPos1 + 2;
float2 texPos12 = texPos1 + offset12;
texPos0 /= texSize;
texPos3 /= texSize;
texPos12 /= texSize;
float4 result = 0.0f;
result += tex.SampleLevel(linearSampler, float2(texPos0.x, texPos0.y), 0.0f) * w0.x * w0.y;
result += tex.SampleLevel(linearSampler, float2(texPos12.x, texPos0.y), 0.0f) * w12.x * w0.y;
result += tex.SampleLevel(linearSampler, float2(texPos3.x, texPos0.y), 0.0f) * w3.x * w0.y;
result += tex.SampleLevel(linearSampler, float2(texPos0.x, texPos12.y), 0.0f) * w0.x * w12.y;
result += tex.SampleLevel(linearSampler, float2(texPos12.x, texPos12.y), 0.0f) * w12.x * w12.y;
result += tex.SampleLevel(linearSampler, float2(texPos3.x, texPos12.y), 0.0f) * w3.x * w12.y;
result += tex.SampleLevel(linearSampler, float2(texPos0.x, texPos3.y), 0.0f) * w0.x * w3.y;
result += tex.SampleLevel(linearSampler, float2(texPos12.x, texPos3.y), 0.0f) * w12.x * w3.y;
result += tex.SampleLevel(linearSampler, float2(texPos3.x, texPos3.y), 0.0f) * w3.x * w3.y;
return result;
}
m_UtilityNameSpaceEnd
#endif // d_WaveHarmonic_Utility_Filtering

View File

@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 65a9a0cfb233a4a418d51cbf55265c55
ShaderIncludeImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -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

View File

@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 90443daddb561477ca109fbfe1d80fdd
ShaderIncludeImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 31c666ce642464bd1901041e360703ef
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,4 @@
// Crest Water System
// Copyright © 2024 Wave Harmonic. All rights reserved.
// Empty.

View File

@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 4ff429977add540198b8820ff8f0cd7a
ShaderIncludeImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,35 @@
// Crest Water System
// Copyright © 2024 Wave Harmonic. All rights reserved.
// Builds on Unity's shim for Shader Graph.
#define BUILTIN_TARGET_API 1
#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 d_WaveHarmonic_Utility_LegacyCore
#define d_WaveHarmonic_Utility_LegacyCore
//
// Inputs
//
#undef UNITY_MATRIX_I_VP
#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
// 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

View File

@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 8501e8dffc440417cb78449e6079d3fa
ShaderIncludeImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -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

View File

@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 1d26727ac31d94682896ffbfdc685804
ShaderIncludeImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,4 @@
// Crest Water System
// Copyright © 2024 Wave Harmonic. All rights reserved.
// Empty.

View File

@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 8e956ca85fd1846899d2a3b106267dcd
ShaderIncludeImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -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;
}

View File

@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 5eab24690c4a74ceca26a143da611306
ShaderIncludeImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -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;

View File

@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 1eacca53c60984c4a8cadb624777e644
ShaderIncludeImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -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

View File

@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: ae5323918c4b24b5c87c6f941810e225
ShaderIncludeImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,105 @@
// Crest Water System
// Copyright © 2024 Wave Harmonic. All rights reserved.
// Copyright (c) 2016 Unity Technologies
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of
// this software and associated documentation files (the "Software"), to deal in
// the Software without restriction, including without limitation the rights to
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
// of the Software, and to permit persons to whom the Software is furnished to do
// so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
// FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
// 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.
// Taken from:
// 2020.3.12f1/DefaultResourcesExtra/Internal-ScreenSpaceShadows.shader
#include "UnityShadowLibrary.cginc"
#ifndef SHADOWMAPSAMPLER_DEFINED
UNITY_DECLARE_SHADOWMAP(_ShadowMapTexture);
#define SHADOWMAPSAMPLER_DEFINED
#ifndef SHADOWMAPSAMPLER_AND_TEXELSIZE_DEFINED
float4 _ShadowMapTexture_TexelSize;
#define SHADOWMAPSAMPLER_AND_TEXELSIZE_DEFINED
#endif
#endif
//
// Keywords based defines
//
#if defined (SHADOWS_SPLIT_SPHERES)
#define GET_CASCADE_WEIGHTS(wpos, z) getCascadeWeights_splitSpheres(wpos)
#else
#define GET_CASCADE_WEIGHTS(wpos, z) getCascadeWeights( wpos, z )
#endif
#if defined (SHADOWS_SINGLE_CASCADE)
#define GET_SHADOW_COORDINATES(wpos,cascadeWeights) getShadowCoord_SingleCascade(wpos)
#else
#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, float z)
{
fixed4 zNear = float4( z >= _LightSplitsNear );
fixed4 zFar = float4( z < _LightSplitsFar );
fixed4 weights = zNear * zFar;
return weights;
}
/**
* Gets the cascade weights based on the world position of the fragment and the poisitions of the split spheres for each cascade.
* Returns a float4 with only one component set that corresponds to the appropriate cascade.
*/
inline fixed4 getCascadeWeights_splitSpheres(float3 wpos)
{
float3 fromCenter0 = wpos.xyz - unity_ShadowSplitSpheres[0].xyz;
float3 fromCenter1 = wpos.xyz - unity_ShadowSplitSpheres[1].xyz;
float3 fromCenter2 = wpos.xyz - unity_ShadowSplitSpheres[2].xyz;
float3 fromCenter3 = wpos.xyz - unity_ShadowSplitSpheres[3].xyz;
float4 distances2 = float4(dot(fromCenter0,fromCenter0), dot(fromCenter1,fromCenter1), dot(fromCenter2,fromCenter2), dot(fromCenter3,fromCenter3));
fixed4 weights = float4(distances2 < unity_ShadowSplitSqRadii);
weights.yzw = saturate(weights.yzw - weights.xyz);
return weights;
}
/**
* 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, fixed4 cascadeWeights )
{
float3 sc0 = mul (unity_WorldToShadow[0], wpos).xyz;
float3 sc1 = mul (unity_WorldToShadow[1], wpos).xyz;
float3 sc2 = mul (unity_WorldToShadow[2], wpos).xyz;
float3 sc3 = mul (unity_WorldToShadow[3], wpos).xyz;
float4 shadowMapCoordinate = float4(sc0 * cascadeWeights[0] + sc1 * cascadeWeights[1] + sc2 * cascadeWeights[2] + sc3 * cascadeWeights[3], 1);
#if defined(UNITY_REVERSED_Z)
float noCascadeWeights = 1 - dot(cascadeWeights, float4(1, 1, 1, 1));
shadowMapCoordinate.z += noCascadeWeights;
#endif
return shadowMapCoordinate;
}
/**
* Same as the getShadowCoord; but optimized for single cascade
*/
inline float4 getShadowCoord_SingleCascade( float4 wpos )
{
return float4( mul (unity_WorldToShadow[0], wpos).xyz, 0);
}

View File

@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 14d63b54d73024767903a5caa23e8e53
ShaderIncludeImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,153 @@
// Crest Water System
// Copyright © 2024 Wave Harmonic. All rights reserved.
// Based on tutorial: https://connect.unity.com/p/adding-your-own-hlsl-code-to-shader-graph-the-custom-function-node
#ifndef CREST_LIGHTING_H
#define CREST_LIGHTING_H
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Library/Macros.hlsl"
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Library/Globals.hlsl"
#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
#endif // CREST_URP
#if CREST_HDRP
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl"
#if UNITY_VERSION < 202310
#define GetMeshRenderingLayerMask GetMeshRenderingLightLayer
#endif // UNITY_VERSION
#if UNITY_VERSION < 60000000
#if PROBE_VOLUMES_L1
#define AMBIENT_PROBE_BUFFER 1
#endif // PROBE_VOLUMES_L1
#endif // UNITY_VERSION
#endif // CREST_HDRP
m_CrestNameSpace
void PrimaryLight
(
const float3 i_PositionWS,
out half3 o_Color,
out half3 o_Direction
)
{
#if CREST_HDRP
// We could get the main light the same way we get the main light shadows,
// but most of the data would be missing (including below horizon
// attenuation) which would require re-running the light loop which is expensive.
o_Direction = g_Crest_PrimaryLightDirection;
o_Color = g_Crest_PrimaryLightIntensity;
#elif CREST_URP
// Actual light data from the pipeline.
Light light = GetMainLight();
o_Direction = light.direction;
o_Color = light.color;
#elif CREST_BIRP
#ifndef USING_DIRECTIONAL_LIGHT
// Yes. This function wants the world position of the surface.
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
}
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.
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
return AmbientLight(ambient);
}
half3 AdditionalLighting(const float3 i_PositionWS, const float4 i_ScreenPosition, const float2 i_StaticLightMapUV)
{
half3 color = 0.0;
#if CREST_URP
#if defined(_ADDITIONAL_LIGHTS)
// 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);
#endif
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);
#ifdef _LIGHT_LAYERS
if (IsMatchingLightLayer(light.layerMask, meshRenderingLayers))
#endif
{
color += light.color * (light.distanceAttenuation * light.shadowAttenuation);
}
LIGHT_LOOP_END
#endif // _ADDITIONAL_LIGHTS
#endif // CREST_URP
// HDRP todo.
// BIRP has additional lights as additional passes. Handled elsewhere.
return color;
}
m_CrestNameSpaceEnd
#endif

View File

@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 986eee3bc5a7a49f7a6a1f94c96d22e8
ShaderIncludeImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,50 @@
// Crest Water System
// Copyright © 2024 Wave Harmonic. All rights reserved.
#ifndef d_WaveHarmonic_Utility_Macros
#define d_WaveHarmonic_Utility_Macros
#define m_UtilityNameSpace namespace WaveHarmonic { namespace Utility {
#define m_UtilityNameSpaceEnd } }
#define m_Utility WaveHarmonic::Utility
#define m_UtilityVertex \
m_Utility::Varyings Vertex(m_Utility::Attributes i_Input) \
{ \
return m_Utility::Vertex(i_Input); \
}
#define m_UtilityFragment(type) \
type Fragment(m_Utility::Varyings i_Input) : SV_Target \
{ \
return m_Utility::Fragment(i_Input); \
}
#define m_UtilityKernel(name) \
void Crest##name(uint3 id : SV_DispatchThreadID) \
{ \
m_Utility::name(id); \
}
#define m_UtilityKernelVariant(name, variant) \
void Crest##name##variant(uint3 id : SV_DispatchThreadID) \
{ \
m_Utility::name(id); \
}
#define m_UtilityKernelDefault(name) \
[numthreads(8, 8, 1)] \
void Crest##name(uint3 id : SV_DispatchThreadID) \
{ \
m_Utility::name(id); \
}
#define m_UtilityKernelDefaultVariant(name, variant) \
[numthreads(8, 8, 1)] \
void Crest##name##variant(uint3 id : SV_DispatchThreadID) \
{ \
m_Utility::name(id); \
}
#endif // d_WaveHarmonic_Utility_Macros

View File

@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: ac63edd7bcb3b4b35a5ea50c7deb4202
ShaderIncludeImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 85562641776fc423e829bb13477e80f3
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,35 @@
// See header/license in SOURCE.txt file accompanying this shader.
// Trivial modifications made to the code to translate it to HLSL by Huw Bowles
#ifndef CREST_GPU_NOISE_INCLUDED
#define CREST_GPU_NOISE_INCLUDED
uint baseHash(uint3 p)
{
p = 1103515245U * ((p.xyz >> 1U) ^ (p.yzx));
uint h32 = 1103515245U * ((p.x^p.z) ^ (p.y >> 3U));
return h32 ^ (h32 >> 16);
}
float hash13(uint3 x)
{
uint n = baseHash(x);
return float(n)*(1.0 / float(0xffffffffU));
}
float2 hash23(float3 x)
{
uint n = baseHash(x);
uint2 rz = uint2(n, n * 48271U); //see: http://random.mat.sbg.ac.at/results/karl/server/node4.html
return float2(rz.xy & (uint2)0x7fffffffU) / float(0x7fffffff);
}
float3 hash33(uint3 x)
{
uint n = baseHash(x);
uint3 rz = uint3(n, n * 16807U, n * 48271U); //see: http://random.mat.sbg.ac.at/results/karl/server/node4.html
return float3(rz & (uint3)0x7fffffffU) / float(0x7fffffff);
}
#endif // CREST_GPU_NOISE_INCLUDED

View File

@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 5f79fd5a427da4de09803ded352ecfb1
ShaderIncludeImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,10 @@
Source: https://www.shadertoy.com/view/Xt3cDn
Modifications: Trivial modifications made to the code to translate it to HLSL.
Copyright Notice:
Quality hashes collection
by nimitz 2018 (twitter: @stormoid)
The MIT License
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 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.

View File

@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 1ae623fc941b44349a1836e6ab666922
TextScriptImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 389b0f071dd5843c394f5255cd6ec73c
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -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

View File

@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 68cb1a44e787e45bd9de666d527b10f2
ShaderIncludeImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: ff5a7cc0943db46db9eac87f50e38097
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -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

View File

@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 327c164f365e1468789c5950ac945e17
ShaderIncludeImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -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

View File

@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 07d6b2cd79ac04fa5b56cffd5fb1bb31
ShaderIncludeImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -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

View File

@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: b4623a51d04ef4e9c82e9196bf28e48d
ShaderIncludeImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant: