修改水
This commit is contained in:
@@ -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
|
||||
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 941ad013a0cbf4dec8d525ee790f5c6e
|
||||
ShaderIncludeImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -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
|
||||
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 65a9a0cfb233a4a418d51cbf55265c55
|
||||
ShaderIncludeImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 31c666ce642464bd1901041e360703ef
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,257 @@
|
||||
// Crest Water System
|
||||
|
||||
// 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
|
||||
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4ff429977add540198b8820ff8f0cd7a
|
||||
ShaderIncludeImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,75 @@
|
||||
// Crest Water System
|
||||
|
||||
// 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.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
|
||||
|
||||
#ifndef BUILTIN_PIPELINE_CORE_INCLUDED
|
||||
#define BUILTIN_PIPELINE_CORE_INCLUDED
|
||||
|
||||
#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)
|
||||
|
||||
#define SLICE_ARRAY_INDEX unity_StereoEyeIndex
|
||||
|
||||
#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
|
||||
#endif
|
||||
|
||||
#endif // BUILTIN_PIPELINE_CORE_INCLUDED
|
||||
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8501e8dffc440417cb78449e6079d3fa
|
||||
ShaderIncludeImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,18 @@
|
||||
// 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)
|
||||
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8e956ca85fd1846899d2a3b106267dcd
|
||||
ShaderIncludeImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,125 @@
|
||||
// Crest Water System
|
||||
|
||||
// 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.
|
||||
|
||||
// Screen-space shadow helpers.
|
||||
|
||||
// Taken and adapted 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
|
||||
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) getCascadeWeights_splitSpheres(wpos)
|
||||
#else
|
||||
#define GET_CASCADE_WEIGHTS(wpos) getCascadeWeights(wpos)
|
||||
#endif
|
||||
|
||||
#if defined (SHADOWS_SINGLE_CASCADE)
|
||||
#define GET_SHADOW_COORDINATES(wpos) getShadowCoord_SingleCascade(wpos)
|
||||
#else
|
||||
#define GET_SHADOW_COORDINATES(wpos) getShadowCoord(wpos)
|
||||
#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)
|
||||
{
|
||||
// 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;
|
||||
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 = 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;
|
||||
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);
|
||||
}
|
||||
|
||||
#endif // d_Crest_ReceiveShadowsTransparent
|
||||
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 14d63b54d73024767903a5caa23e8e53
|
||||
ShaderIncludeImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,200 @@
|
||||
// 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"
|
||||
|
||||
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
|
||||
#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
|
||||
|
||||
#if UNITY_VERSION < 60000000
|
||||
#if PROBE_VOLUMES_L1
|
||||
#define AMBIENT_PROBE_BUFFER 1
|
||||
#endif
|
||||
#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,
|
||||
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;
|
||||
#endif
|
||||
o_Color = _LightColor0.rgb;
|
||||
#endif
|
||||
}
|
||||
|
||||
void AmbientLight(out half3 o_AmbientLight)
|
||||
{
|
||||
// Use the constant term (0th order) of SH stuff - this is the average.
|
||||
o_AmbientLight =
|
||||
#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;
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
return color;
|
||||
}
|
||||
|
||||
m_CrestNameSpaceEnd
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 986eee3bc5a7a49f7a6a1f94c96d22e8
|
||||
ShaderIncludeImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -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
|
||||
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ac63edd7bcb3b4b35a5ea50c7deb4202
|
||||
ShaderIncludeImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 85562641776fc423e829bb13477e80f3
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -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
|
||||
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5f79fd5a427da4de09803ded352ecfb1
|
||||
ShaderIncludeImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -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.
|
||||
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1ae623fc941b44349a1836e6ab666922
|
||||
TextScriptImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user