升级水插件
This commit is contained in:
@@ -106,7 +106,7 @@
|
||||
{ \
|
||||
result = Sample##name(uv); \
|
||||
} \
|
||||
else if (_Index < _Count) \
|
||||
else if ((_Index + 1) < _Count) \
|
||||
{ \
|
||||
const Cascade cascade = Cascade::Make##name(_Index + 1, this); \
|
||||
const float3 uv = cascade.WorldToUV(i_Position); \
|
||||
@@ -128,7 +128,7 @@
|
||||
{ \
|
||||
result = Sample##name(i_UV); \
|
||||
} \
|
||||
else if (_Index < _Count) \
|
||||
else if ((_Index + 1) < _Count) \
|
||||
{ \
|
||||
const Cascade cascade = Cascade::Make##name(_Index + 1, this); \
|
||||
const float3 uv = cascade.WorldToUV(UVToWorld(i_UV)); \
|
||||
|
||||
@@ -42,9 +42,6 @@
|
||||
#define CREST_SSS_MAXIMUM 0.6
|
||||
#define CREST_SSS_RANGE 0.12
|
||||
|
||||
// Note: Must match k_MaskBelowSurfaceCull in UnderwaterRenderer.Mask.cs.
|
||||
// Fog rendered from below and before transparents and water tile is culled.
|
||||
#define CREST_MASK_BELOW_SURFACE_CULLED -2.0
|
||||
// Note: Must match k_MaskBelowSurface in UnderwaterRenderer.Mask.cs.
|
||||
// Fog rendered from below.
|
||||
#define CREST_MASK_BELOW_SURFACE -1.0
|
||||
@@ -62,6 +59,7 @@
|
||||
// used to scale the meniscus as it is calculate using a pixel offset which can make the meniscus large at a distance.
|
||||
#define MENISCUS_MAXIMUM_DISTANCE 15.0
|
||||
|
||||
#define k_Crest_MaskInsidePortal 5
|
||||
|
||||
#if defined(STEREO_INSTANCING_ON) || defined(STEREO_MULTIVIEW_ON)
|
||||
#define CREST_HANDLE_XR 1
|
||||
|
||||
@@ -12,6 +12,8 @@ SamplerState LODData_linear_clamp_sampler;
|
||||
SamplerState LODData_point_clamp_sampler;
|
||||
SamplerState sampler_Crest_linear_repeat;
|
||||
|
||||
SamplerState _Crest_linear_clamp_sampler;
|
||||
|
||||
CBUFFER_START(CrestPerFrame)
|
||||
float3 g_Crest_WaterCenter;
|
||||
float g_Crest_WaterScale;
|
||||
@@ -31,6 +33,7 @@ int g_Crest_ForceUnderwater;
|
||||
|
||||
float3 g_Crest_PrimaryLightDirection;
|
||||
float3 g_Crest_PrimaryLightIntensity;
|
||||
bool g_Crest_PrimaryLightHasCookie;
|
||||
|
||||
float g_Crest_DynamicSoftShadowsFactor;
|
||||
|
||||
@@ -39,7 +42,7 @@ bool g_Crest_SampleScatteringSimulation;
|
||||
|
||||
// Motion Vector Parameters
|
||||
float g_Crest_WaterScaleChange;
|
||||
float3 g_Crest_WaterCenterDelta;
|
||||
float2 g_Crest_WaterCenterDelta;
|
||||
|
||||
// Shifting Origin
|
||||
#if (CREST_SHIFTING_ORIGIN != 0)
|
||||
|
||||
@@ -90,21 +90,27 @@ void PosToSliceIndices
|
||||
}
|
||||
}
|
||||
|
||||
bool IsUnderwater(const bool i_FrontFace, const int i_ForceUnderwater)
|
||||
bool IsUnderWater(const bool i_FrontFace, const int i_ForceUnderwater)
|
||||
{
|
||||
bool underwater = false;
|
||||
|
||||
// We are well below water.
|
||||
if (i_ForceUnderwater == 1)
|
||||
{
|
||||
return true;
|
||||
underwater = true;
|
||||
}
|
||||
|
||||
// We are well above water.
|
||||
if (i_ForceUnderwater == 2)
|
||||
else if (i_ForceUnderwater == 2)
|
||||
{
|
||||
return false;
|
||||
underwater = false;
|
||||
}
|
||||
// Use facing.
|
||||
else
|
||||
{
|
||||
underwater = !i_FrontFace;
|
||||
}
|
||||
|
||||
return !i_FrontFace;
|
||||
return underwater;
|
||||
}
|
||||
|
||||
float FeatherWeightFromUV(const float2 i_uv, const half i_featherWidth)
|
||||
|
||||
@@ -9,15 +9,10 @@
|
||||
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Library/Constants.hlsl"
|
||||
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Library/Macros.hlsl"
|
||||
|
||||
CBUFFER_START(CrestChunkInstanceData)
|
||||
uint _Crest_LodIndex;
|
||||
float _Crest_ChunkMeshScaleAlpha;
|
||||
float _Crest_ChunkMeshScaleAlphaSource;
|
||||
float _Crest_ChunkGeometryGridWidth;
|
||||
float _Crest_ChunkGeometryGridWidthSource;
|
||||
float _Crest_ChunkFarNormalsWeight;
|
||||
float2 _Crest_ChunkNormalScrollSpeed;
|
||||
CBUFFER_END
|
||||
// NOTE: Unity does not recognize uint in FrameDebugger. It will be under Floats
|
||||
// with incorrect values. Change to int for debugging.
|
||||
uint _Crest_LodIndex;
|
||||
|
||||
|
||||
Texture2DArray g_Crest_CascadeAbsorption;
|
||||
m_DisplacementTexture(Texture2DArray, 4) g_Crest_CascadeAnimatedWaves;
|
||||
|
||||
@@ -31,6 +31,12 @@ type Fragment(m_Crest::Varyings i_Input) : SV_Target \
|
||||
return m_Crest::Fragment(i_Input); \
|
||||
}
|
||||
|
||||
#define m_CrestFragmentVariant(type, name) \
|
||||
type Fragment(m_Crest::Varyings i_Input) : SV_Target \
|
||||
{ \
|
||||
return m_Crest::name(i_Input); \
|
||||
}
|
||||
|
||||
#define m_CrestFragmentWithFrontFace(type) \
|
||||
type Fragment(m_Crest::Varyings i_Input, const bool i_IsFrontFace : SV_IsFrontFace) : SV_Target \
|
||||
{ \
|
||||
@@ -69,4 +75,10 @@ void Crest##name(uint3 id : SV_DispatchThreadID) \
|
||||
m_Crest::name(uint3(id.xy, g_Crest_LodCount - 1 - id.z)); \
|
||||
}
|
||||
|
||||
// Cross render pipeline kernels.
|
||||
#define m_CrestKernelXRP(name) \
|
||||
[numthreads(THREAD_GROUP_SIZE_X, THREAD_GROUP_SIZE_Y, 1)] void Crest##name##BRP(uint3 id : SV_DispatchThreadID) { m_Crest::name(id); } \
|
||||
[numthreads(THREAD_GROUP_SIZE_X, THREAD_GROUP_SIZE_Y, 1)] void Crest##name##HRP(uint3 id : SV_DispatchThreadID) { m_Crest::name(id); } \
|
||||
[numthreads(THREAD_GROUP_SIZE_X, THREAD_GROUP_SIZE_Y, 1)] void Crest##name##URP(uint3 id : SV_DispatchThreadID) { m_Crest::name(id); } \
|
||||
|
||||
#endif // CREST_MACROS_H
|
||||
|
||||
@@ -7,10 +7,13 @@
|
||||
//
|
||||
// WaveHarmonic.Crest.Editor.ShaderSettings: static fields
|
||||
//
|
||||
#define CREST_PACKAGE_HDRP (1)
|
||||
#define CREST_PACKAGE_URP (1)
|
||||
#define CREST_PORTALS (0)
|
||||
#define CREST_SHIFTING_ORIGIN (0)
|
||||
#define CREST_SHADOWS_BUILT_IN_RENDER_PIPELINE (1)
|
||||
#define CREST_FULL_PRECISION_DISPLACEMENT (1)
|
||||
#define CREST_DISCARD_ATMOSPHERIC_SCATTERING (1)
|
||||
#define CREST_LEGACY_UNDERWATER (0)
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
// Crest Water System
|
||||
// Copyright © 2024 Wave Harmonic. All rights reserved.
|
||||
|
||||
#ifndef d_WaveHarmonic_Utility_Helpers
|
||||
#define d_WaveHarmonic_Utility_Helpers
|
||||
|
||||
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Library/Utility/Macros.hlsl"
|
||||
|
||||
m_UtilityNameSpace
|
||||
|
||||
void Swap(inout float a, inout float b)
|
||||
{
|
||||
float t = a; a = b; b = t;
|
||||
}
|
||||
|
||||
// Adapted from:
|
||||
// https://alex.vlachos.com/graphics/Alex_Vlachos_Advanced_VR_Rendering_GDC2015.pdf
|
||||
float3 ScreenSpaceDither(const float2 i_ScreenPosition)
|
||||
{
|
||||
// Iestyn's RGB dither (7 asm instructions) from Portal 2 X360, slightly modified for VR.
|
||||
float3 dither = dot(float2(171.0, 231.0), i_ScreenPosition.xy);
|
||||
dither.rgb = frac(dither.rgb / float3(103.0, 71.0, 97.0)) - float3(0.5, 0.5, 0.5);
|
||||
return (dither.rgb / 255.0);
|
||||
}
|
||||
|
||||
float2 WorldNormalToScreenDirection(const float3 i_PositionWS, const float3 i_NormalWS, const float4x4 i_MatrixVP, const float i_Offset)
|
||||
{
|
||||
const float3 p0 = i_PositionWS;
|
||||
const float3 p1 = p0 + i_NormalWS * i_Offset;
|
||||
|
||||
const float4 clip0 = mul(i_MatrixVP, float4(p0, 1));
|
||||
const float4 clip1 = mul(i_MatrixVP, float4(p1, 1));
|
||||
|
||||
const float2 uv0 = (clip0.xy / clip0.w) * 0.5 + 0.5;
|
||||
const float2 uv1 = (clip1.xy / clip1.w) * 0.5 + 0.5;
|
||||
|
||||
float2 direction = normalize(uv1 - uv0);
|
||||
|
||||
#if UNITY_UV_STARTS_AT_TOP
|
||||
direction.y = -direction.y;
|
||||
#endif
|
||||
|
||||
return direction;
|
||||
}
|
||||
|
||||
m_UtilityNameSpaceEnd
|
||||
|
||||
#endif // d_WaveHarmonic_Utility_Helpers
|
||||
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 90443daddb561477ca109fbfe1d80fdd
|
||||
ShaderIncludeImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,257 +1,4 @@
|
||||
// Crest Water System
|
||||
// Copyright © 2024 Wave Harmonic. All rights reserved.
|
||||
|
||||
// This file is subject to the Unity Companion License:
|
||||
// https://github.com/Unity-Technologies/Graphics/blob/7ff8fd444c179fd9bb380d61f4865be6935b47dd/LICENSE.md
|
||||
|
||||
// Adds functions from SRP.
|
||||
|
||||
// Adapted from:
|
||||
// https://github.com/Unity-Technologies/Graphics/blob/8f54e6591e93fb3bf8e9879a0e43665dfbe2f629/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl
|
||||
|
||||
#ifndef UNITY_COMMON_INCLUDED
|
||||
#define UNITY_COMMON_INCLUDED
|
||||
|
||||
// Add "real" alias for "fixed". Helps with including files downstream.
|
||||
|
||||
#define real fixed
|
||||
#define real2 fixed2
|
||||
#define real3 fixed3
|
||||
#define real4 fixed4
|
||||
|
||||
// Commented lines have no "fixed" equivalent.
|
||||
|
||||
#define real2x2 fixed2x2
|
||||
// #define real2x3 fixed2x3
|
||||
// #define real2x4 fixed2x4
|
||||
// #define real3x2 fixed3x2
|
||||
#define real3x3 fixed3x3
|
||||
// #define real3x4 fixed3x4
|
||||
// #define real4x3 fixed4x3
|
||||
#define real4x4 fixed4x4
|
||||
|
||||
//
|
||||
// MACROS
|
||||
//
|
||||
|
||||
#define ZERO_INITIALIZE(type, name) UNITY_INITIALIZE_OUTPUT(type,name)
|
||||
#define TransformObjectToHClip(positionOS) UnityObjectToClipPos(float4(positionOS, 1.0))
|
||||
|
||||
// Taken from:
|
||||
// com.unity.render-pipelines.core@10.5.0/ShaderLibrary/API/D3D11.hlsl
|
||||
// com.unity.render-pipelines.core@10.5.0/ShaderLibrary/API/Metal.hlsl
|
||||
// com.unity.render-pipelines.core@10.5.0/ShaderLibrary/API/Switch.hlsl
|
||||
// com.unity.render-pipelines.core@10.5.0/ShaderLibrary/API/Vulkan.hlsl
|
||||
|
||||
// GameCore, PSSL etc require an NDA so hard to confirm how some of these APIs are implemented, but the PPv2 package has
|
||||
// some of APIs (the ones we use) and they are the same:
|
||||
// com.unity.postprocessing/PostProcessing/Shaders/API/
|
||||
|
||||
// Texture abstraction.
|
||||
|
||||
#define TEXTURE2D(textureName) UNITY_DECLARE_TEX2D_NOSAMPLER(textureName)
|
||||
#define TEXTURE2D_ARRAY(textureName) UNITY_DECLARE_TEX2DARRAY_NOSAMPLER(textureName)
|
||||
#define TEXTURECUBE(textureName) UNITY_DECLARE_TEXCUBE_NOSAMPLER(textureName)
|
||||
// #define TEXTURECUBE_ARRAY(textureName) TextureCubeArray textureName
|
||||
// #define TEXTURE3D(textureName) Texture3D textureName
|
||||
|
||||
// #ifdef SHADER_API_D3D11
|
||||
|
||||
// #define TEXTURE2D_FLOAT(textureName) TEXTURE2D(textureName)
|
||||
// #define TEXTURE2D_ARRAY_FLOAT(textureName) TEXTURE2D_ARRAY(textureName)
|
||||
// #define TEXTURECUBE_FLOAT(textureName) TEXTURECUBE(textureName)
|
||||
// #define TEXTURECUBE_ARRAY_FLOAT(textureName) TEXTURECUBE_ARRAY(textureName)
|
||||
// #define TEXTURE3D_FLOAT(textureName) TEXTURE3D(textureName)
|
||||
|
||||
// #define TEXTURE2D_HALF(textureName) TEXTURE2D(textureName)
|
||||
// #define TEXTURE2D_ARRAY_HALF(textureName) TEXTURE2D_ARRAY(textureName)
|
||||
// #define TEXTURECUBE_HALF(textureName) TEXTURECUBE(textureName)
|
||||
// #define TEXTURECUBE_ARRAY_HALF(textureName) TEXTURECUBE_ARRAY(textureName)
|
||||
// #define TEXTURE3D_HALF(textureName) TEXTURE3D(textureName)
|
||||
|
||||
// #else // !SHADER_API_D3D11
|
||||
|
||||
// #define TEXTURE2D_FLOAT(textureName) Texture2D_float textureName
|
||||
// #define TEXTURE2D_ARRAY_FLOAT(textureName) Texture2DArray_float textureName
|
||||
// #define TEXTURECUBE_FLOAT(textureName) TextureCube_float textureName
|
||||
// #define TEXTURECUBE_ARRAY_FLOAT(textureName) TextureCubeArray_float textureName
|
||||
// #define TEXTURE3D_FLOAT(textureName) Texture3D_float textureName
|
||||
|
||||
// #define TEXTURE2D_HALF(textureName) Texture2D_half textureName
|
||||
// #define TEXTURE2D_ARRAY_HALF(textureName) Texture2DArray_half textureName
|
||||
// #define TEXTURECUBE_HALF(textureName) TextureCube_half textureName
|
||||
// #define TEXTURECUBE_ARRAY_HALF(textureName) TextureCubeArray_half textureName
|
||||
// #define TEXTURE3D_HALF(textureName) Texture3D_half textureName
|
||||
|
||||
// #endif // SHADER_API_D3D11
|
||||
|
||||
// #define TEXTURE2D_SHADOW(textureName) TEXTURE2D(textureName)
|
||||
// #define TEXTURE2D_ARRAY_SHADOW(textureName) TEXTURE2D_ARRAY(textureName)
|
||||
// #define TEXTURECUBE_SHADOW(textureName) TEXTURECUBE(textureName)
|
||||
// #define TEXTURECUBE_ARRAY_SHADOW(textureName) TEXTURECUBE_ARRAY(textureName)
|
||||
|
||||
#define RW_TEXTURE2D(type, textureName) RWTexture2D<type> textureName
|
||||
#define RW_TEXTURE2D_ARRAY(type, textureName) RWTexture2DArray<type> textureName
|
||||
// #define RW_TEXTURE3D(type, textureName) RWTexture3D<type> textureName
|
||||
|
||||
#define SAMPLER(samplerName) SamplerState samplerName
|
||||
// #define SAMPLER_CMP(samplerName) SamplerComparisonState samplerName
|
||||
// #define ASSIGN_SAMPLER(samplerName, samplerValue) samplerName = samplerValue
|
||||
|
||||
// #define TEXTURE2D_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER(samplerName)
|
||||
// #define TEXTURE2D_ARRAY_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER(samplerName)
|
||||
// #define TEXTURECUBE_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER(samplerName)
|
||||
// #define TEXTURECUBE_ARRAY_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER(samplerName)
|
||||
// #define TEXTURE3D_PARAM(textureName, samplerName) TEXTURE3D(textureName), SAMPLER(samplerName)
|
||||
|
||||
// #define TEXTURE2D_SHADOW_PARAM(textureName, samplerName) TEXTURE2D(textureName), SAMPLER_CMP(samplerName)
|
||||
// #define TEXTURE2D_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURE2D_ARRAY(textureName), SAMPLER_CMP(samplerName)
|
||||
// #define TEXTURECUBE_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE(textureName), SAMPLER_CMP(samplerName)
|
||||
// #define TEXTURECUBE_ARRAY_SHADOW_PARAM(textureName, samplerName) TEXTURECUBE_ARRAY(textureName), SAMPLER_CMP(samplerName)
|
||||
|
||||
// #define TEXTURE2D_ARGS(textureName, samplerName) textureName, samplerName
|
||||
// #define TEXTURE2D_ARRAY_ARGS(textureName, samplerName) textureName, samplerName
|
||||
// #define TEXTURECUBE_ARGS(textureName, samplerName) textureName, samplerName
|
||||
// #define TEXTURECUBE_ARRAY_ARGS(textureName, samplerName) textureName, samplerName
|
||||
// #define TEXTURE3D_ARGS(textureName, samplerName) textureName, samplerName
|
||||
|
||||
// #define TEXTURE2D_SHADOW_ARGS(textureName, samplerName) textureName, samplerName
|
||||
// #define TEXTURE2D_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName
|
||||
// #define TEXTURECUBE_SHADOW_ARGS(textureName, samplerName) textureName, samplerName
|
||||
// #define TEXTURECUBE_ARRAY_SHADOW_ARGS(textureName, samplerName) textureName, samplerName
|
||||
|
||||
// We cannot use Unity's macros because they change the samplerName and it needs to be unchanged.
|
||||
#define SAMPLE_TEXTURE2D(textureName, samplerName, coord2) textureName.Sample(samplerName, coord2)
|
||||
#define SAMPLE_TEXTURE2D_LOD(textureName, samplerName, coord2, lod) textureName.SampleLevel(samplerName, coord2, lod)
|
||||
// #define SAMPLE_TEXTURE2D_BIAS(textureName, samplerName, coord2, bias) textureName.SampleBias(samplerName, coord2, bias)
|
||||
// #define SAMPLE_TEXTURE2D_GRAD(textureName, samplerName, coord2, dpdx, dpdy) textureName.SampleGrad(samplerName, coord2, dpdx, dpdy)
|
||||
#define SAMPLE_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Sample(samplerName, float3(coord2, index))
|
||||
// #define SAMPLE_TEXTURE2D_ARRAY_LOD(textureName, samplerName, coord2, index, lod) textureName.SampleLevel(samplerName, float3(coord2, index), lod)
|
||||
// #define SAMPLE_TEXTURE2D_ARRAY_BIAS(textureName, samplerName, coord2, index, bias) textureName.SampleBias(samplerName, float3(coord2, index), bias)
|
||||
// #define SAMPLE_TEXTURE2D_ARRAY_GRAD(textureName, samplerName, coord2, index, dpdx, dpdy) textureName.SampleGrad(samplerName, float3(coord2, index), dpdx, dpdy)
|
||||
// #define SAMPLE_TEXTURECUBE(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3)
|
||||
// #define SAMPLE_TEXTURECUBE_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod)
|
||||
// #define SAMPLE_TEXTURECUBE_BIAS(textureName, samplerName, coord3, bias) textureName.SampleBias(samplerName, coord3, bias)
|
||||
// #define SAMPLE_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Sample(samplerName, float4(coord3, index))
|
||||
// #define SAMPLE_TEXTURECUBE_ARRAY_LOD(textureName, samplerName, coord3, index, lod) textureName.SampleLevel(samplerName, float4(coord3, index), lod)
|
||||
// #define SAMPLE_TEXTURECUBE_ARRAY_BIAS(textureName, samplerName, coord3, index, bias) textureName.SampleBias(samplerName, float4(coord3, index), bias)
|
||||
// #define SAMPLE_TEXTURE3D(textureName, samplerName, coord3) textureName.Sample(samplerName, coord3)
|
||||
// #define SAMPLE_TEXTURE3D_LOD(textureName, samplerName, coord3, lod) textureName.SampleLevel(samplerName, coord3, lod)
|
||||
|
||||
// #define SAMPLE_TEXTURE2D_SHADOW(textureName, samplerName, coord3) textureName.SampleCmpLevelZero(samplerName, (coord3).xy, (coord3).z)
|
||||
// #define SAMPLE_TEXTURE2D_ARRAY_SHADOW(textureName, samplerName, coord3, index) textureName.SampleCmpLevelZero(samplerName, float3((coord3).xy, index), (coord3).z)
|
||||
// #define SAMPLE_TEXTURECUBE_SHADOW(textureName, samplerName, coord4) textureName.SampleCmpLevelZero(samplerName, (coord4).xyz, (coord4).w)
|
||||
// #define SAMPLE_TEXTURECUBE_ARRAY_SHADOW(textureName, samplerName, coord4, index) textureName.SampleCmpLevelZero(samplerName, float4((coord4).xyz, index), (coord4).w)
|
||||
|
||||
#undef SAMPLE_DEPTH_TEXTURE
|
||||
// #undef SAMPLE_DEPTH_TEXTURE_LOD
|
||||
#define SAMPLE_DEPTH_TEXTURE(textureName, samplerName, coord2) SAMPLE_TEXTURE2D(textureName, samplerName, coord2).r
|
||||
// #define SAMPLE_DEPTH_TEXTURE_LOD(textureName, samplerName, coord2, lod) SAMPLE_TEXTURE2D_LOD(textureName, samplerName, coord2, lod).r
|
||||
|
||||
#define LOAD_TEXTURE2D(textureName, unCoord2) textureName.Load(int3(unCoord2, 0))
|
||||
// #define LOAD_TEXTURE2D_LOD(textureName, unCoord2, lod) textureName.Load(int3(unCoord2, lod))
|
||||
// #define LOAD_TEXTURE2D_MSAA(textureName, unCoord2, sampleIndex) textureName.Load(unCoord2, sampleIndex)
|
||||
#define LOAD_TEXTURE2D_ARRAY(textureName, unCoord2, index) textureName.Load(int4(unCoord2, index, 0))
|
||||
// #ifndef SHADER_API_SWITCH
|
||||
// #define LOAD_TEXTURE2D_ARRAY_MSAA(textureName, unCoord2, index, sampleIndex) textureName.Load(int3(unCoord2, index), sampleIndex)
|
||||
// #endif
|
||||
// #define LOAD_TEXTURE2D_ARRAY_LOD(textureName, unCoord2, index, lod) textureName.Load(int4(unCoord2, index, lod))
|
||||
// #define LOAD_TEXTURE3D(textureName, unCoord3) textureName.Load(int4(unCoord3, 0))
|
||||
// #define LOAD_TEXTURE3D_LOD(textureName, unCoord3, lod) textureName.Load(int4(unCoord3, lod))
|
||||
|
||||
// #define GATHER_TEXTURE2D(textureName, samplerName, coord2) textureName.Gather(samplerName, coord2)
|
||||
// #define GATHER_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) textureName.Gather(samplerName, float3(coord2, index))
|
||||
// #define GATHER_TEXTURECUBE(textureName, samplerName, coord3) textureName.Gather(samplerName, coord3)
|
||||
// #define GATHER_TEXTURECUBE_ARRAY(textureName, samplerName, coord3, index) textureName.Gather(samplerName, float4(coord3, index))
|
||||
// #define GATHER_RED_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherRed(samplerName, coord2)
|
||||
// #define GATHER_GREEN_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherGreen(samplerName, coord2)
|
||||
// #define GATHER_BLUE_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherBlue(samplerName, coord2)
|
||||
// #define GATHER_ALPHA_TEXTURE2D(textureName, samplerName, coord2) textureName.GatherAlpha(samplerName, coord2)
|
||||
|
||||
// Generates a triangle in homogeneous clip space, s.t.
|
||||
// v0 = (-1, -1, 1), v1 = (3, -1, 1), v2 = (-1, 3, 1).
|
||||
float2 GetFullScreenTriangleTexCoord(uint vertexID)
|
||||
{
|
||||
#if UNITY_UV_STARTS_AT_TOP
|
||||
return float2((vertexID << 1) & 2, 1.0 - (vertexID & 2));
|
||||
#else
|
||||
return float2((vertexID << 1) & 2, vertexID & 2);
|
||||
#endif
|
||||
}
|
||||
|
||||
float4 GetFullScreenTriangleVertexPosition(uint vertexID, float z = UNITY_NEAR_CLIP_VALUE)
|
||||
{
|
||||
float2 uv = float2((vertexID << 1) & 2, vertexID & 2);
|
||||
return float4(uv * 2.0 - 1.0, z, 1.0);
|
||||
}
|
||||
|
||||
#endif // UNITY_COMMON_INCLUDED
|
||||
|
||||
//
|
||||
// FUNCTIONS
|
||||
//
|
||||
|
||||
// Keep the following unguarded
|
||||
|
||||
// Taken and modified from:
|
||||
// com.unity.render-pipelines.core@12.0.0/ShaderLibrary/Common.hlsl
|
||||
float4 CrestComputeClipSpacePosition(float2 positionNDC, float deviceDepth)
|
||||
{
|
||||
float4 positionCS = float4(positionNDC * 2.0 - 1.0, deviceDepth, 1.0);
|
||||
// positionCS.y was flipped here but that is SRP specific to solve flip baked into matrix.
|
||||
return positionCS;
|
||||
}
|
||||
|
||||
// Taken and modified from:
|
||||
// com.unity.render-pipelines.core@12.0.0/ShaderLibrary/Common.hlsl
|
||||
float3 CrestComputeWorldSpacePosition(float2 positionNDC, float deviceDepth, float4x4 invViewProjMatrix)
|
||||
{
|
||||
float4 positionCS = CrestComputeClipSpacePosition(positionNDC, deviceDepth);
|
||||
float4 hpositionWS = mul(invViewProjMatrix, positionCS);
|
||||
return hpositionWS.xyz / hpositionWS.w;
|
||||
}
|
||||
|
||||
// Taken from:
|
||||
// com.unity.render-pipelines.core@12.0.0/ShaderLibrary/Common.hlsl
|
||||
float3 CrestComputeWorldSpacePosition(float4 positionCS, float4x4 invViewProjMatrix)
|
||||
{
|
||||
float4 hpositionWS = mul(invViewProjMatrix, positionCS);
|
||||
return hpositionWS.xyz / hpositionWS.w;
|
||||
}
|
||||
|
||||
#undef ComputeClipSpacePosition
|
||||
#undef ComputeWorldSpacePosition
|
||||
|
||||
// Replace these with our own as ComputeClipSpacePosition flips the Y which is not correct for BIRP.
|
||||
#define ComputeClipSpacePosition CrestComputeClipSpacePosition
|
||||
#define ComputeWorldSpacePosition CrestComputeWorldSpacePosition
|
||||
|
||||
// Taken from:
|
||||
// com.unity.render-pipelines.core/ShaderLibrary/Packing.hlsl
|
||||
real3 CrestUnpackNormalmapRGorAG(real4 packednormal)
|
||||
{
|
||||
// This do the trick
|
||||
packednormal.x *= packednormal.w;
|
||||
|
||||
real3 normal;
|
||||
normal.xy = packednormal.xy * 2 - 1;
|
||||
normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy)));
|
||||
return normal;
|
||||
}
|
||||
|
||||
// Taken from:
|
||||
// com.unity.render-pipelines.core/ShaderLibrary/Packing.hlsl
|
||||
inline real3 CrestUnpackNormal(real4 packednormal)
|
||||
{
|
||||
#if defined(UNITY_NO_DXT5nm)
|
||||
return packednormal.xyz * 2 - 1;
|
||||
#elif defined(UNITY_ASTC_NORMALMAP_ENCODING)
|
||||
return UnpackNormalDXT5nm(packednormal);
|
||||
#else
|
||||
return CrestUnpackNormalmapRGorAG(packednormal);
|
||||
#endif
|
||||
}
|
||||
|
||||
#undef UnpackNormal
|
||||
|
||||
// Replace these to solve Unity bug "ambiguous call to 'UnpackNormalmapRGorAG'"
|
||||
#define UnpackNormal CrestUnpackNormal
|
||||
// Empty.
|
||||
|
||||
@@ -1,75 +1,35 @@
|
||||
// Crest Water System
|
||||
// Copyright © 2024 Wave Harmonic. All rights reserved.
|
||||
|
||||
// This file is subject to the Unity Companion License:
|
||||
// https://github.com/Unity-Technologies/Graphics/blob/7ff8fd444c179fd9bb380d61f4865be6935b47dd/LICENSE.md
|
||||
// Builds on Unity's shim for Shader Graph.
|
||||
|
||||
// Adds functions from SRP.
|
||||
#define BUILTIN_TARGET_API 1
|
||||
|
||||
// Adapted from:
|
||||
// https://github.com/Unity-Technologies/Graphics/blob/8f54e6591e93fb3bf8e9879a0e43665dfbe2f629/com.unity.shadergraph/Editor/Generation/Targets/BuiltIn/ShaderLibrary/Core.hlsl
|
||||
// https://github.com/Unity-Technologies/Graphics/blob/7ff8fd444c179fd9bb380d61f4865be6935b47dd/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/TextureXR.hlsl
|
||||
#include "Packages/com.unity.shadergraph/Editor/Generation/Targets/BuiltIn/Editor/ShaderGraph/Includes/ShaderPass.hlsl"
|
||||
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Library/Utility/Legacy/Defines.hlsl"
|
||||
#include "Packages/com.unity.shadergraph/Editor/Generation/Targets/BuiltIn/ShaderLibrary/Shim/Shims.hlsl"
|
||||
#include "Packages/com.unity.shadergraph/Editor/Generation/Targets/BuiltIn/ShaderLibrary/Core.hlsl"
|
||||
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Library/Utility/Legacy/InputsDriven.hlsl"
|
||||
|
||||
#ifndef BUILTIN_PIPELINE_CORE_INCLUDED
|
||||
#define BUILTIN_PIPELINE_CORE_INCLUDED
|
||||
#ifndef d_WaveHarmonic_Utility_LegacyCore
|
||||
#define d_WaveHarmonic_Utility_LegacyCore
|
||||
|
||||
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Library/Utility/Legacy/Common.hlsl"
|
||||
|
||||
// Stereo-related bits
|
||||
#if defined(UNITY_STEREO_INSTANCING_ENABLED) || defined(UNITY_STEREO_MULTIVIEW_ENABLED)
|
||||
//
|
||||
// Inputs
|
||||
//
|
||||
|
||||
#define SLICE_ARRAY_INDEX unity_StereoEyeIndex
|
||||
#undef UNITY_MATRIX_I_VP
|
||||
|
||||
#define COORD_TEXTURE2D_X(pixelCoord) uint3(pixelCoord, SLICE_ARRAY_INDEX)
|
||||
|
||||
#define TEXTURE2D_X(textureName) TEXTURE2D_ARRAY(textureName)
|
||||
// #define TEXTURE2D_X_PARAM(textureName, samplerName) TEXTURE2D_ARRAY_PARAM(textureName, samplerName)
|
||||
// #define TEXTURE2D_X_ARGS(textureName, samplerName) TEXTURE2D_ARRAY_ARGS(textureName, samplerName)
|
||||
// #define TEXTURE2D_X_HALF(textureName) TEXTURE2D_ARRAY_HALF(textureName)
|
||||
// #define TEXTURE2D_X_FLOAT(textureName) TEXTURE2D_ARRAY_FLOAT(textureName)
|
||||
|
||||
#define RW_TEXTURE2D_X(type, textureName) RW_TEXTURE2D_ARRAY(type, textureName)
|
||||
|
||||
#define LOAD_TEXTURE2D_X(textureName, unCoord2) LOAD_TEXTURE2D_ARRAY(textureName, unCoord2, SLICE_ARRAY_INDEX)
|
||||
// #define LOAD_TEXTURE2D_X_LOD(textureName, unCoord2, lod) LOAD_TEXTURE2D_ARRAY_LOD(textureName, unCoord2, SLICE_ARRAY_INDEX, lod)
|
||||
#define SAMPLE_TEXTURE2D_X(textureName, samplerName, coord2) SAMPLE_TEXTURE2D_ARRAY(textureName, samplerName, coord2, SLICE_ARRAY_INDEX)
|
||||
// #define SAMPLE_TEXTURE2D_X_LOD(textureName, samplerName, coord2, lod) SAMPLE_TEXTURE2D_ARRAY_LOD(textureName, samplerName, coord2, SLICE_ARRAY_INDEX, lod)
|
||||
// #define GATHER_TEXTURE2D_X(textureName, samplerName, coord2) GATHER_TEXTURE2D_ARRAY(textureName, samplerName, coord2, SLICE_ARRAY_INDEX)
|
||||
// #define GATHER_RED_TEXTURE2D_X(textureName, samplerName, coord2) GATHER_RED_TEXTURE2D(textureName, samplerName, float3(coord2, SLICE_ARRAY_INDEX))
|
||||
// #define GATHER_GREEN_TEXTURE2D_X(textureName, samplerName, coord2) GATHER_GREEN_TEXTURE2D(textureName, samplerName, float3(coord2, SLICE_ARRAY_INDEX))
|
||||
// #define GATHER_BLUE_TEXTURE2D_X(textureName, samplerName, coord2) GATHER_BLUE_TEXTURE2D(textureName, samplerName, float3(coord2, SLICE_ARRAY_INDEX))
|
||||
|
||||
#else // UNITY_STEREO
|
||||
|
||||
#define SLICE_ARRAY_INDEX 0
|
||||
|
||||
#define COORD_TEXTURE2D_X(pixelCoord) pixelCoord
|
||||
|
||||
#define TEXTURE2D_X(textureName) TEXTURE2D(textureName)
|
||||
// #define TEXTURE2D_X_PARAM(textureName, samplerName) TEXTURE2D_PARAM(textureName, samplerName)
|
||||
// #define TEXTURE2D_X_ARGS(textureName, samplerName) TEXTURE2D_ARGS(textureName, samplerName)
|
||||
// #define TEXTURE2D_X_HALF(textureName) TEXTURE2D_HALF(textureName)
|
||||
// #define TEXTURE2D_X_FLOAT(textureName) TEXTURE2D_FLOAT(textureName)
|
||||
|
||||
#define RW_TEXTURE2D_X RW_TEXTURE2D
|
||||
|
||||
#define LOAD_TEXTURE2D_X(textureName, unCoord2) LOAD_TEXTURE2D(textureName, unCoord2)
|
||||
// #define LOAD_TEXTURE2D_X_LOD(textureName, unCoord2, lod) LOAD_TEXTURE2D_LOD(textureName, unCoord2, lod)
|
||||
#define SAMPLE_TEXTURE2D_X(textureName, samplerName, coord2) SAMPLE_TEXTURE2D(textureName, samplerName, coord2)
|
||||
// #define SAMPLE_TEXTURE2D_X_LOD(textureName, samplerName, coord2, lod) SAMPLE_TEXTURE2D_LOD(textureName, samplerName, coord2, lod)
|
||||
// #define GATHER_TEXTURE2D_X(textureName, samplerName, coord2) GATHER_TEXTURE2D(textureName, samplerName, coord2)
|
||||
// #define GATHER_RED_TEXTURE2D_X(textureName, samplerName, coord2) GATHER_RED_TEXTURE2D(textureName, samplerName, coord2)
|
||||
// #define GATHER_GREEN_TEXTURE2D_X(textureName, samplerName, coord2) GATHER_GREEN_TEXTURE2D(textureName, samplerName, coord2)
|
||||
// #define GATHER_BLUE_TEXTURE2D_X(textureName, samplerName, coord2) GATHER_BLUE_TEXTURE2D(textureName, samplerName, coord2)
|
||||
|
||||
#endif // UNITY_STEREO
|
||||
|
||||
// Helper macro to assign view index during compute/ray pass (usually from SV_DispatchThreadID or DispatchRaysIndex())
|
||||
#if defined(SHADER_STAGE_COMPUTE) || defined(SHADER_STAGE_RAY_TRACING)
|
||||
#if defined(UNITY_STEREO_INSTANCING_ENABLED)
|
||||
#define UNITY_XR_ASSIGN_VIEW_INDEX(viewIndex) unity_StereoEyeIndex = viewIndex;
|
||||
#else
|
||||
#define UNITY_XR_ASSIGN_VIEW_INDEX(viewIndex)
|
||||
#endif
|
||||
#if defined(STEREO_INSTANCING_ON) || defined(STEREO_MULTIVIEW_ON)
|
||||
float4x4 _Crest_StereoInverseViewProjection[2];
|
||||
#define UNITY_MATRIX_I_VP _Crest_StereoInverseViewProjection[unity_StereoEyeIndex]
|
||||
#else
|
||||
float4x4 _Crest_InverseViewProjection;
|
||||
#define UNITY_MATRIX_I_VP _Crest_InverseViewProjection
|
||||
#endif
|
||||
|
||||
#endif // BUILTIN_PIPELINE_CORE_INCLUDED
|
||||
// Not set and _ScreenParams.zw is "1.0 + 1.0 / _ScreenParams.xy"
|
||||
#define _ScreenSize float4(_ScreenParams.xy, float2(1.0, 1.0) / _ScreenParams.xy)
|
||||
|
||||
#endif // d_WaveHarmonic_Utility_LegacyCore
|
||||
|
||||
@@ -0,0 +1,111 @@
|
||||
// Crest Water System
|
||||
// Copyright © 2024 Wave Harmonic. All rights reserved.
|
||||
|
||||
#ifndef d_WaveHarmonic_Utility_ShaderGraphDefines
|
||||
#define d_WaveHarmonic_Utility_ShaderGraphDefines
|
||||
|
||||
//
|
||||
// Defines
|
||||
//
|
||||
|
||||
#ifdef _BUILTIN_SPECULAR_SETUP
|
||||
#define _SPECULAR_SETUP _BUILTIN_SPECULAR_SETUP
|
||||
#endif
|
||||
|
||||
#ifdef _BUILTIN_TRANSPARENT_RECEIVES_SHADOWS
|
||||
#define _TRANSPARENT_RECEIVES_SHADOWS _BUILTIN_TRANSPARENT_RECEIVES_SHADOWS
|
||||
#endif
|
||||
|
||||
|
||||
//
|
||||
// Passes
|
||||
//
|
||||
|
||||
#define SHADERPASS_FORWARD_ADD (20)
|
||||
#define SHADERPASS_DEFERRED (21)
|
||||
#define SHADERPASS_MOTION_VECTORS (22)
|
||||
|
||||
|
||||
//
|
||||
// Deferred Fix
|
||||
//
|
||||
|
||||
#if (defined(SHADER_API_GLES3) && !defined(SHADER_API_DESKTOP)) || defined(SHADER_API_GLES) || defined(SHADER_API_N3DS)
|
||||
#define UNITY_ALLOWED_MRT_COUNT 4
|
||||
#else
|
||||
#define UNITY_ALLOWED_MRT_COUNT 8
|
||||
#endif
|
||||
|
||||
// Required on Windows (and possibly others) to prevent tiling.
|
||||
#undef UNITY_SAMPLE_FULL_SH_PER_PIXEL
|
||||
#define UNITY_SAMPLE_FULL_SH_PER_PIXEL 1
|
||||
|
||||
|
||||
//
|
||||
// Stereo Instancing Fix
|
||||
//
|
||||
|
||||
#if defined(STEREO_INSTANCING_ON) && (defined(SHADER_API_D3D11) || defined(SHADER_API_GLES3) || defined(SHADER_API_GLCORE) || defined(SHADER_API_PSSL) || defined(SHADER_API_VULKAN) || (defined(SHADER_API_METAL) && !defined(UNITY_COMPILER_DXC)))
|
||||
#define UNITY_STEREO_INSTANCING_ENABLED
|
||||
#endif
|
||||
|
||||
#if defined(STEREO_MULTIVIEW_ON) && (defined(SHADER_API_GLES3) || defined(SHADER_API_GLCORE) || defined(SHADER_API_VULKAN)) && !(defined(SHADER_API_SWITCH))
|
||||
#define UNITY_STEREO_MULTIVIEW_ENABLED
|
||||
#endif
|
||||
|
||||
// Redeclared their includes to insert shadow declarations at the right spot.
|
||||
// Adapted from:
|
||||
// Packages/com.unity.shadergraph/Editor/Generation/Targets/BuiltIn/ShaderLibrary/Shim/Shims.hlsl
|
||||
|
||||
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl"
|
||||
|
||||
// Duplicate define in Macros.hlsl
|
||||
#if defined (TRANSFORM_TEX)
|
||||
#undef TRANSFORM_TEX
|
||||
#endif
|
||||
|
||||
#if defined(UNITY_STEREO_INSTANCING_ENABLED) || defined(UNITY_STEREO_MULTIVIEW_ENABLED)
|
||||
#undef GLOBAL_CBUFFER_START
|
||||
#if defined(UNITY_STEREO_MULTIVIEW_ENABLED) || ((defined(UNITY_SINGLE_PASS_STEREO) || defined(UNITY_STEREO_INSTANCING_ENABLED)) && (defined(SHADER_API_GLCORE) || defined(SHADER_API_GLES3) || defined(SHADER_API_METAL)))
|
||||
#define GLOBAL_CBUFFER_START(name) cbuffer name {
|
||||
#define GLOBAL_CBUFFER_END }
|
||||
#else
|
||||
#define GLOBAL_CBUFFER_START(name) CBUFFER_START(name)
|
||||
#define GLOBAL_CBUFFER_END CBUFFER_END
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#include "Packages/com.unity.shadergraph/Editor/Generation/Targets/BuiltIn/ShaderLibrary/Shim/HLSLSupportShim.hlsl"
|
||||
|
||||
// Fix wrong definitions.
|
||||
#undef UNITY_SAMPLE_TEX2DARRAY
|
||||
#define UNITY_SAMPLE_TEX2DARRAY(tex,coord) SAMPLE_TEXTURE2D_ARRAY(tex, sampler##tex, coord.xy, coord.z)
|
||||
|
||||
|
||||
//
|
||||
// Transparent Objects Receives Shadows
|
||||
//
|
||||
|
||||
#if _SURFACE_TYPE_TRANSPARENT
|
||||
#if _TRANSPARENT_RECEIVES_SHADOWS
|
||||
#if SHADERPASS == SHADERPASS_FORWARD || SHADERPASS == SHADERPASS_FORWARD_ADD
|
||||
#if DIRECTIONAL || DIRECTIONAL_COOKIE
|
||||
#if !SHADOWS_SCREEN
|
||||
|
||||
StructuredBuffer<float4x4> _Crest_WorldToShadow;
|
||||
|
||||
// Declarations for shadow collector.
|
||||
UNITY_DECLARE_SHADOWMAP(_ShadowMapTexture);
|
||||
float4 _ShadowMapTexture_TexelSize;
|
||||
#define SHADOWMAPSAMPLER_DEFINED 1
|
||||
#define SHADOWMAPSAMPLER_AND_TEXELSIZE_DEFINED 1
|
||||
|
||||
#define d_Crest_ShadowsOverriden 1
|
||||
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#endif // d_WaveHarmonic_Utility_ShaderGraphDefines
|
||||
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1d26727ac31d94682896ffbfdc685804
|
||||
ShaderIncludeImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,18 +1,4 @@
|
||||
// Crest Water System
|
||||
// Copyright © 2024 Wave Harmonic. All rights reserved.
|
||||
|
||||
// Defines missing inputs.
|
||||
|
||||
float4x4 _Crest_InverseViewProjection;
|
||||
float4x4 _Crest_InverseViewProjectionRight;
|
||||
|
||||
#undef UNITY_MATRIX_I_VP
|
||||
|
||||
#if defined(STEREO_INSTANCING_ON) || defined(STEREO_MULTIVIEW_ON)
|
||||
#define UNITY_MATRIX_I_VP (unity_StereoEyeIndex == 0 ? _Crest_InverseViewProjection : _Crest_InverseViewProjectionRight)
|
||||
#else
|
||||
#define UNITY_MATRIX_I_VP _Crest_InverseViewProjection
|
||||
#endif
|
||||
|
||||
// Not set and _ScreenParams.zw is "1.0 + 1.0 / _ScreenParams.xy"
|
||||
#define _ScreenSize float4(_ScreenParams.xy, float2(1.0, 1.0) / _ScreenParams.xy)
|
||||
// Empty.
|
||||
|
||||
@@ -0,0 +1,109 @@
|
||||
// Crest Water System
|
||||
// Copyright © 2024 Wave Harmonic. All rights reserved.
|
||||
|
||||
#include "Packages/com.unity.shadergraph/Editor/Generation/Targets/BuiltIn/Editor/ShaderGraph/Includes/LegacyBuilding.hlsl"
|
||||
|
||||
//
|
||||
// Transparent Objects Receives Shadows
|
||||
//
|
||||
|
||||
#if d_Crest_ShadowsOverriden
|
||||
|
||||
#define unity_WorldToShadow _Crest_WorldToShadow
|
||||
|
||||
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Library/Utility/Legacy/Shadows.hlsl"
|
||||
|
||||
#if defined(SHADER_API_MOBILE)
|
||||
#define m_UnitySampleShadowmap_PCF UnitySampleShadowmap_PCF5x5
|
||||
#else
|
||||
#define m_UnitySampleShadowmap_PCF UnitySampleShadowmap_PCF7x7
|
||||
#endif
|
||||
|
||||
// Same as UnityComputeShadowFadeDistance, except it uses keywords.
|
||||
float ComputeShadowFadeDistance(float3 positionWS, float viewZ)
|
||||
{
|
||||
// Use keyword instead of unity_ShadowFadeCenterAndType.w, as we are already
|
||||
// dependent on keywords anyway.
|
||||
return
|
||||
#if SHADOWS_SPLIT_SPHERES
|
||||
distance(positionWS, unity_ShadowFadeCenterAndType.xyz);
|
||||
#else
|
||||
viewZ;
|
||||
#endif
|
||||
}
|
||||
|
||||
float GetShadows(float3 positionWS, float4 uvLightMap)
|
||||
{
|
||||
float viewZ = -UnityWorldToViewPos(positionWS).z;
|
||||
float4 weights = GET_CASCADE_WEIGHTS(positionWS, viewZ);
|
||||
float4 coordinates = GET_SHADOW_COORDINATES(float4(positionWS, 1.0), weights);
|
||||
#if SHADOWS_SOFT
|
||||
half shadow = m_UnitySampleShadowmap_PCF(coordinates, 0);
|
||||
#else
|
||||
half shadow = UNITY_SAMPLE_SHADOW(_ShadowMapTexture, coordinates);
|
||||
#endif
|
||||
shadow = lerp(_LightShadowData.r, 1.0, shadow);
|
||||
|
||||
// Shadow Mask + mixed sun + static
|
||||
#if LIGHTMAP_ON && SHADOWS_SHADOWMASK && LIGHTMAP_SHADOW_MIXING
|
||||
float fade = UnityComputeShadowFade(ComputeShadowFadeDistance(positionWS, viewZ));
|
||||
half mask = UnitySampleBakedOcclusion(uvLightMap.xy, positionWS);
|
||||
shadow = UnityMixRealtimeAndBakedShadows(shadow, mask, fade);
|
||||
#endif
|
||||
|
||||
return shadow;
|
||||
}
|
||||
|
||||
#ifdef DIRECTIONAL
|
||||
#undef UNITY_LIGHT_ATTENUATION
|
||||
#define UNITY_LIGHT_ATTENUATION(destName, input, worldPos) \
|
||||
fixed destName = GetShadows(worldPos, input.lmap);
|
||||
#endif
|
||||
|
||||
#ifdef DIRECTIONAL_COOKIE
|
||||
#undef UNITY_LIGHT_ATTENUATION
|
||||
#define UNITY_LIGHT_ATTENUATION(destName, input, worldPos) \
|
||||
DECLARE_LIGHT_COORD(input, worldPos); \
|
||||
fixed destName = tex2D(_LightTexture0, lightCoord).w * GetShadows(worldPos, input.lmap);
|
||||
#endif
|
||||
|
||||
#endif // d_Crest_ShadowsOverriden
|
||||
|
||||
|
||||
//
|
||||
// Specular
|
||||
//
|
||||
|
||||
#ifdef _SPECULAR_SETUP
|
||||
#define SurfaceOutputStandard SurfaceOutputStandardSpecular
|
||||
#define BuildStandardSurfaceOutput BuildStandardSpecularSurfaceOutput
|
||||
#define LightingStandard LightingStandardSpecular
|
||||
#define LightingStandard_GI LightingStandardSpecular_GI
|
||||
#define LightingStandard_Deferred LightingStandardSpecular_Deferred
|
||||
|
||||
#if SHADERPASS == SHADERPASS_FORWARD_ADD
|
||||
#undef LightingStandard
|
||||
#define LightingStandard(x, y, z) LightingStandardSpecular(x, y, z); c.rgb += o.Emission;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef _SPECULAR_SETUP
|
||||
#if SHADERPASS == SHADERPASS_FORWARD_ADD
|
||||
#define LightingStandard(x, y, z) LightingStandard(x, y, z); c.rgb += o.Emission;
|
||||
#endif // SHADERPASS_FORWARD_ADD
|
||||
#endif // _SPECULAR_SETUP
|
||||
|
||||
SurfaceOutputStandardSpecular BuildStandardSpecularSurfaceOutput(SurfaceDescription surfaceDescription, InputData inputData)
|
||||
{
|
||||
SurfaceData surface = SurfaceDescriptionToSurfaceData(surfaceDescription);
|
||||
|
||||
SurfaceOutputStandardSpecular o = (SurfaceOutputStandardSpecular)0;
|
||||
o.Albedo = surface.albedo;
|
||||
o.Normal = inputData.normalWS;
|
||||
o.Specular = surface.specular;
|
||||
o.Smoothness = surface.smoothness;
|
||||
o.Occlusion = surface.occlusion;
|
||||
o.Emission = surface.emission;
|
||||
o.Alpha = surface.alpha;
|
||||
return o;
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5eab24690c4a74ceca26a143da611306
|
||||
ShaderIncludeImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,51 @@
|
||||
// Crest Water System
|
||||
// Copyright © 2024 Wave Harmonic. All rights reserved.
|
||||
|
||||
// TODO:
|
||||
// #if defined(USING_STEREO_MATRICES)
|
||||
// float4x4 _StereoNonJitteredVP[2];
|
||||
// float4x4 _StereoPreviousVP[2];
|
||||
// #else
|
||||
// float4x4 _NonJitteredVP;
|
||||
// float4x4 _PreviousVP;
|
||||
// #endif
|
||||
|
||||
float4x4 _PreviousM;
|
||||
float4x4 _PreviousVP;
|
||||
float4x4 _NonJitteredVP;
|
||||
|
||||
bool _HasLastPositionData;
|
||||
bool _ForceNoMotion;
|
||||
float _MotionVectorDepthBias;
|
||||
|
||||
#undef UNITY_PREV_MATRIX_M
|
||||
#define UNITY_PREV_MATRIX_M _PreviousM
|
||||
#define _PrevViewProjMatrix _PreviousVP
|
||||
#define _NonJitteredViewProjMatrix _NonJitteredVP
|
||||
|
||||
// X : Use last frame positions (right now skinned meshes are the only objects that use this
|
||||
// Y : Force No Motion
|
||||
// Z : Z bias value
|
||||
const static float4 unity_MotionVectorsParams = float4(_HasLastPositionData, !_ForceNoMotion, _MotionVectorDepthBias, 0);
|
||||
|
||||
// Unity will populate this, but could not see when in source.
|
||||
float4 _LastTime;
|
||||
|
||||
// We want to gather some internal data from the BuildVaryings call to
|
||||
// avoid rereading and recalculating these values again in the ShaderGraph motion vector pass
|
||||
struct MotionVectorPassOutput
|
||||
{
|
||||
float3 positionOS;
|
||||
float3 positionWS;
|
||||
};
|
||||
|
||||
SurfaceDescription BuildSurfaceDescription(Varyings varyings)
|
||||
{
|
||||
SurfaceDescriptionInputs surfaceDescriptionInputs = BuildSurfaceDescriptionInputs(varyings);
|
||||
SurfaceDescription surfaceDescription = SurfaceDescriptionFunction(surfaceDescriptionInputs);
|
||||
return surfaceDescription;
|
||||
}
|
||||
|
||||
// Very hacky, but works!
|
||||
#define BuildVaryings(content) BuildVaryings(content, inout MotionVectorPassOutput motionVectorOutput)
|
||||
#define TransformObjectToWorld(content) TransformObjectToWorld(content); motionVectorOutput.positionOS = input.positionOS; motionVectorOutput.positionWS = positionWS;
|
||||
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1eacca53c60984c4a8cadb624777e644
|
||||
ShaderIncludeImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,159 @@
|
||||
// Crest Water System
|
||||
// Copyright © 2024 Wave Harmonic. All rights reserved.
|
||||
|
||||
// Adapted from:
|
||||
// Packages/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/MotionVectorPass.hlsl
|
||||
|
||||
// This file is subject to the Unity Companion License:
|
||||
// https://github.com/Unity-Technologies/Graphics/blob/61584ec20cf305929dae85cec7b94ff2ed3942f3/LICENSE.md
|
||||
|
||||
#ifndef SG_MOTION_VECTORS_PASS_INCLUDED
|
||||
#define SG_MOTION_VECTORS_PASS_INCLUDED
|
||||
|
||||
#undef BuildVaryings
|
||||
#undef TransformObjectToWorld
|
||||
|
||||
float2 CalcNdcMotionVectorFromCsPositions(float4 posCS, float4 prevPosCS)
|
||||
{
|
||||
// Note: unity_MotionVectorsParams.y is 0 is forceNoMotion is enabled
|
||||
bool forceNoMotion = unity_MotionVectorsParams.y == 0.0;
|
||||
if (forceNoMotion)
|
||||
return float2(0.0, 0.0);
|
||||
|
||||
// Non-uniform raster needs to keep the posNDC values in float to avoid additional conversions
|
||||
// since uv remap functions use floats
|
||||
float2 posNDC = posCS.xy * rcp(posCS.w);
|
||||
float2 prevPosNDC = prevPosCS.xy * rcp(prevPosCS.w);
|
||||
|
||||
float2 velocity;
|
||||
{
|
||||
// Calculate forward velocity
|
||||
velocity = (posNDC.xy - prevPosNDC.xy);
|
||||
#if UNITY_UV_STARTS_AT_TOP
|
||||
velocity.y = -velocity.y;
|
||||
#endif
|
||||
|
||||
// Convert velocity from NDC space (-1..1) to UV 0..1 space
|
||||
// Note: It doesn't mean we don't have negative values, we store negative or positive offset in UV space.
|
||||
// Note: ((posNDC * 0.5 + 0.5) - (prevPosNDC * 0.5 + 0.5)) = (velocity * 0.5)
|
||||
velocity.xy *= 0.5;
|
||||
}
|
||||
|
||||
return velocity;
|
||||
}
|
||||
|
||||
struct MotionVectorPassAttributes
|
||||
{
|
||||
float3 previousPositionOS : TEXCOORD4; // Contains previous frame local vertex position (for skinned meshes)
|
||||
};
|
||||
|
||||
// Note: these will have z == 0.0f in the pixel shader to save on bandwidth
|
||||
struct MotionVectorPassVaryings
|
||||
{
|
||||
float4 positionCSNoJitter;
|
||||
float4 previousPositionCSNoJitter;
|
||||
};
|
||||
|
||||
struct PackedMotionVectorPassVaryings
|
||||
{
|
||||
float3 positionCSNoJitter : CLIP_POSITION_NO_JITTER;
|
||||
float3 previousPositionCSNoJitter : PREVIOUS_CLIP_POSITION_NO_JITTER;
|
||||
};
|
||||
|
||||
PackedMotionVectorPassVaryings PackMotionVectorVaryings(MotionVectorPassVaryings regularVaryings)
|
||||
{
|
||||
PackedMotionVectorPassVaryings packedVaryings;
|
||||
packedVaryings.positionCSNoJitter = regularVaryings.positionCSNoJitter.xyw;
|
||||
packedVaryings.previousPositionCSNoJitter = regularVaryings.previousPositionCSNoJitter.xyw;
|
||||
return packedVaryings;
|
||||
}
|
||||
|
||||
MotionVectorPassVaryings UnpackMotionVectorVaryings(PackedMotionVectorPassVaryings packedVaryings)
|
||||
{
|
||||
MotionVectorPassVaryings regularVaryings;
|
||||
regularVaryings.positionCSNoJitter = float4(packedVaryings.positionCSNoJitter.xy, 0, packedVaryings.positionCSNoJitter.z);
|
||||
regularVaryings.previousPositionCSNoJitter = float4(packedVaryings.previousPositionCSNoJitter.xy, 0, packedVaryings.previousPositionCSNoJitter.z);
|
||||
return regularVaryings;
|
||||
}
|
||||
|
||||
float3 GetLastFrameDeformedPosition(Attributes input, MotionVectorPassOutput currentFrameMvData, float3 previousPositionOS)
|
||||
{
|
||||
Attributes lastFrameInputAttributes = input;
|
||||
lastFrameInputAttributes.positionOS = previousPositionOS;
|
||||
|
||||
VertexDescriptionInputs lastFrameVertexDescriptionInputs = BuildVertexDescriptionInputs(lastFrameInputAttributes);
|
||||
#if defined(AUTOMATIC_TIME_BASED_MOTION_VECTORS) && defined(GRAPH_VERTEX_USES_TIME_PARAMETERS_INPUT)
|
||||
lastFrameVertexDescriptionInputs.TimeParameters = _LastTime.yxz;
|
||||
#endif
|
||||
|
||||
VertexDescription lastFrameVertexDescription = VertexDescriptionFunction(lastFrameVertexDescriptionInputs);
|
||||
previousPositionOS = lastFrameVertexDescription.Position.xyz;
|
||||
|
||||
return previousPositionOS;
|
||||
}
|
||||
|
||||
// -------------------------------------
|
||||
// Vertex
|
||||
void vert(
|
||||
Attributes input,
|
||||
MotionVectorPassAttributes passInput,
|
||||
out PackedMotionVectorPassVaryings packedMvOutput,
|
||||
out PackedVaryings packedOutput)
|
||||
{
|
||||
Varyings output = (Varyings)0;
|
||||
MotionVectorPassVaryings mvOutput = (MotionVectorPassVaryings)0;
|
||||
MotionVectorPassOutput currentFrameMvData = (MotionVectorPassOutput)0;
|
||||
output = BuildVaryings(input, currentFrameMvData);
|
||||
packedOutput = PackVaryings(output);
|
||||
|
||||
const bool forceNoMotion = unity_MotionVectorsParams.y == 0.0;
|
||||
|
||||
if (!forceNoMotion)
|
||||
{
|
||||
const bool hasDeformation = unity_MotionVectorsParams.x == 1; // Mesh has skinned deformation
|
||||
float3 previousPositionOS = hasDeformation ? passInput.previousPositionOS : input.positionOS;
|
||||
|
||||
#if defined(AUTOMATIC_TIME_BASED_MOTION_VECTORS) && defined(GRAPH_VERTEX_USES_TIME_PARAMETERS_INPUT)
|
||||
const bool applyDeformation = true;
|
||||
#else
|
||||
const bool applyDeformation = hasDeformation;
|
||||
#endif
|
||||
|
||||
#if defined(FEATURES_GRAPH_VERTEX)
|
||||
if (applyDeformation)
|
||||
previousPositionOS = GetLastFrameDeformedPosition(input, currentFrameMvData, previousPositionOS);
|
||||
else
|
||||
previousPositionOS = currentFrameMvData.positionOS;
|
||||
|
||||
#if defined(FEATURES_GRAPH_VERTEX_MOTION_VECTOR_OUTPUT)
|
||||
previousPositionOS -= currentFrameMvData.motionVector;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
mvOutput.positionCSNoJitter = mul(_NonJitteredViewProjMatrix, float4(currentFrameMvData.positionWS, 1.0f));
|
||||
mvOutput.previousPositionCSNoJitter = mul(_PrevViewProjMatrix, mul(UNITY_PREV_MATRIX_M, float4(previousPositionOS, 1.0f)));
|
||||
}
|
||||
|
||||
packedMvOutput = PackMotionVectorVaryings(mvOutput);
|
||||
}
|
||||
|
||||
// -------------------------------------
|
||||
// Fragment
|
||||
float4 frag(
|
||||
// Note: packedMvInput needs to be before packedInput as otherwise we get the following error in the speed tree 8 SG:
|
||||
// "Non system-generated input signature parameter () cannot appear after a system generated value"
|
||||
PackedMotionVectorPassVaryings packedMvInput,
|
||||
PackedVaryings packedInput) : SV_Target
|
||||
{
|
||||
Varyings input = UnpackVaryings(packedInput);
|
||||
MotionVectorPassVaryings mvInput = UnpackMotionVectorVaryings(packedMvInput);
|
||||
UNITY_SETUP_INSTANCE_ID(input);
|
||||
SurfaceDescription surfaceDescription = BuildSurfaceDescription(input);
|
||||
|
||||
#if defined(_ALPHATEST_ON)
|
||||
clip(surfaceDescription.Alpha - surfaceDescription.AlphaClipThreshold);
|
||||
#endif
|
||||
|
||||
return float4(CalcNdcMotionVectorFromCsPositions(mvInput.positionCSNoJitter, mvInput.previousPositionCSNoJitter), 0, 0);
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ae5323918c4b24b5c87c6f941810e225
|
||||
ShaderIncludeImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,4 +1,5 @@
|
||||
// Crest Water System
|
||||
// Copyright © 2024 Wave Harmonic. All rights reserved.
|
||||
|
||||
// Copyright (c) 2016 Unity Technologies
|
||||
//
|
||||
@@ -19,24 +20,9 @@
|
||||
// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
// Screen-space shadow helpers.
|
||||
|
||||
// Taken and adapted from:
|
||||
// Taken from:
|
||||
// 2020.3.12f1/DefaultResourcesExtra/Internal-ScreenSpaceShadows.shader
|
||||
|
||||
// Main changes is that now only world position is required. Specialised for the shadow LOD data.
|
||||
|
||||
// Add multi_compile_shadowcollector pragma to get SHADOWS_SPLIT_SPHERES and SHADOWS_SINGLE_CASCADE.
|
||||
// https://docs.unity3d.com/Manual/SL-MultipleProgramVariants.html
|
||||
|
||||
// SHADOWS_SCREEN + SHADOWS_CUBE will never be triggered for transparency, but
|
||||
// Unity still compiles the variant which causes compiler errors.
|
||||
#if defined(_SURFACE_TYPE_TRANSPARENT) && !defined(SHADERGRAPH_PREVIEW) && !defined(SHADOWS_SCREEN) && !defined(SHADOWS_CUBE)
|
||||
#define d_Crest_ReceiveShadowsTransparent 1
|
||||
#endif
|
||||
|
||||
#if d_Crest_ReceiveShadowsTransparent
|
||||
|
||||
#include "UnityShadowLibrary.cginc"
|
||||
|
||||
#ifndef SHADOWMAPSAMPLER_DEFINED
|
||||
@@ -49,30 +35,27 @@ float4 _ShadowMapTexture_TexelSize;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
//
|
||||
// Keywords based defines
|
||||
//
|
||||
#if defined (SHADOWS_SPLIT_SPHERES)
|
||||
#define GET_CASCADE_WEIGHTS(wpos) getCascadeWeights_splitSpheres(wpos)
|
||||
#define GET_CASCADE_WEIGHTS(wpos, z) getCascadeWeights_splitSpheres(wpos)
|
||||
#else
|
||||
#define GET_CASCADE_WEIGHTS(wpos) getCascadeWeights(wpos)
|
||||
#define GET_CASCADE_WEIGHTS(wpos, z) getCascadeWeights( wpos, z )
|
||||
#endif
|
||||
|
||||
#if defined (SHADOWS_SINGLE_CASCADE)
|
||||
#define GET_SHADOW_COORDINATES(wpos) getShadowCoord_SingleCascade(wpos)
|
||||
#define GET_SHADOW_COORDINATES(wpos,cascadeWeights) getShadowCoord_SingleCascade(wpos)
|
||||
#else
|
||||
#define GET_SHADOW_COORDINATES(wpos) getShadowCoord(wpos)
|
||||
#define GET_SHADOW_COORDINATES(wpos,cascadeWeights) getShadowCoord(wpos,cascadeWeights)
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Gets the cascade weights based on the world position of the fragment.
|
||||
* Returns a float4 with only one component set that corresponds to the appropriate cascade.
|
||||
*/
|
||||
inline fixed4 getCascadeWeights(float3 wpos)
|
||||
inline fixed4 getCascadeWeights(float3 wpos, float z)
|
||||
{
|
||||
// Calculate depth. Normally this would be depth from the depth buffer.
|
||||
float z = dot(wpos - _WorldSpaceCameraPos.xyz, unity_CameraToWorld._m02_m12_m22);
|
||||
fixed4 zNear = float4( z >= _LightSplitsNear );
|
||||
fixed4 zFar = float4( z < _LightSplitsFar );
|
||||
fixed4 weights = zNear * zFar;
|
||||
@@ -99,9 +82,8 @@ inline fixed4 getCascadeWeights_splitSpheres(float3 wpos)
|
||||
* Returns the shadowmap coordinates for the given fragment based on the world position and z-depth.
|
||||
* These coordinates belong to the shadowmap atlas that contains the maps for all cascades.
|
||||
*/
|
||||
inline float4 getShadowCoord(float4 wpos)
|
||||
inline float4 getShadowCoord( float4 wpos, fixed4 cascadeWeights )
|
||||
{
|
||||
fixed4 cascadeWeights = GET_CASCADE_WEIGHTS(wpos.xyz);
|
||||
float3 sc0 = mul (unity_WorldToShadow[0], wpos).xyz;
|
||||
float3 sc1 = mul (unity_WorldToShadow[1], wpos).xyz;
|
||||
float3 sc2 = mul (unity_WorldToShadow[2], wpos).xyz;
|
||||
@@ -119,7 +101,5 @@ inline float4 getShadowCoord(float4 wpos)
|
||||
*/
|
||||
inline float4 getShadowCoord_SingleCascade( float4 wpos )
|
||||
{
|
||||
return float4(mul(unity_WorldToShadow[0], wpos).xyz, 0);
|
||||
return float4( mul (unity_WorldToShadow[0], wpos).xyz, 0);
|
||||
}
|
||||
|
||||
#endif // d_Crest_ReceiveShadowsTransparent
|
||||
|
||||
@@ -9,55 +9,54 @@
|
||||
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Library/Macros.hlsl"
|
||||
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Library/Globals.hlsl"
|
||||
|
||||
TEXTURE2D_X(_Crest_ScreenSpaceShadowTexture);
|
||||
float4 _Crest_ScreenSpaceShadowTexture_TexelSize;
|
||||
|
||||
#if CREST_URP
|
||||
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"
|
||||
|
||||
// Unity renamed keyword.
|
||||
#ifdef USE_FORWARD_PLUS
|
||||
#define USE_CLUSTER_LIGHT_LOOP USE_FORWARD_PLUS
|
||||
#endif // USE_FORWARD_PLUS
|
||||
|
||||
#ifdef FORWARD_PLUS_SUBTRACTIVE_LIGHT_CHECK
|
||||
#define CLUSTER_LIGHT_LOOP_SUBTRACTIVE_LIGHT_CHECK FORWARD_PLUS_SUBTRACTIVE_LIGHT_CHECK
|
||||
#endif // FORWARD_PLUS_SUBTRACTIVE_LIGHT_CHECK
|
||||
|
||||
#if UNITY_VERSION >= 60000000
|
||||
#if defined(STEREO_INSTANCING_ON) || defined(STEREO_MULTIVIEW_ON)
|
||||
#if _ALPHATEST_ON
|
||||
#if !USE_CLUSTER_LIGHT_LOOP
|
||||
// If not clustered and additional light shadows and XR, the shading model
|
||||
// completely breaks. It is like shadow attenuation is NaN or some obscure
|
||||
// compiler issue. For 2022.3, it is broken for forward+ only, but cannot be fixed.
|
||||
#define d_ShadowMaskBroken 1
|
||||
#else
|
||||
#if _RECEIVE_SHADOWS_OFF
|
||||
// Right eye broken rendering similar to above.
|
||||
#define d_AdditionalLightsBroken 1
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#endif // CREST_URP
|
||||
|
||||
#if CREST_HDRP
|
||||
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl"
|
||||
|
||||
#ifndef SHADERGRAPH_PREVIEW
|
||||
#if CREST_HDRP_FORWARD_PASS
|
||||
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/HDShadow.hlsl"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if UNITY_VERSION < 202310
|
||||
#define GetMeshRenderingLayerMask GetMeshRenderingLightLayer
|
||||
#endif
|
||||
#endif // UNITY_VERSION
|
||||
|
||||
#if UNITY_VERSION < 60000000
|
||||
#if PROBE_VOLUMES_L1
|
||||
#define AMBIENT_PROBE_BUFFER 1
|
||||
#endif
|
||||
#endif // PROBE_VOLUMES_L1
|
||||
#endif // UNITY_VERSION
|
||||
#endif // CREST_HDRP
|
||||
|
||||
m_CrestNameSpace
|
||||
|
||||
// TODO: Move
|
||||
void ApplyIndirectLightingMultiplier
|
||||
(
|
||||
inout half3 io_AmbientLight
|
||||
)
|
||||
{
|
||||
// Allows control of baked lighting through volume framework.
|
||||
#ifndef SHADERGRAPH_PREVIEW
|
||||
// We could create a BuiltinData struct which would have rendering layers on it, but it seems more complicated.
|
||||
io_AmbientLight *= GetIndirectDiffuseMultiplier(GetMeshRenderingLayerMask());
|
||||
#endif
|
||||
}
|
||||
#else // CREST_HDRP
|
||||
m_CrestNameSpace
|
||||
#endif
|
||||
|
||||
void PrimaryLight
|
||||
(
|
||||
const float3 i_PositionWS,
|
||||
@@ -82,72 +81,46 @@ void PrimaryLight
|
||||
o_Direction = normalize(UnityWorldSpaceLightDir(i_PositionWS));
|
||||
#else
|
||||
o_Direction = _WorldSpaceLightPos0.xyz;
|
||||
// Prevents divide by zero.
|
||||
if (all(o_Direction == 0)) o_Direction = half3(0.0, 1.0, 0.0);
|
||||
#endif
|
||||
o_Color = _LightColor0.rgb;
|
||||
#if SHADERPASS == SHADERPASS_FORWARD_ADD
|
||||
#if !SHADOWS_SCREEN
|
||||
// FIXME: undeclared identifier 'IN' in Pass: BuiltIn ForwardAdd, Vertex program with DIRECTIONAL SHADOWS_SCREEN
|
||||
UNITY_LIGHT_ATTENUATION(attenuation, IN, i_PositionWS)
|
||||
o_Color *= attenuation;
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
void AmbientLight(out half3 o_AmbientLight)
|
||||
half3 AmbientLight(const half3 i_AmbientLight)
|
||||
{
|
||||
half3 ambient = i_AmbientLight;
|
||||
|
||||
#ifndef SHADERGRAPH_PREVIEW
|
||||
#if CREST_HDRP
|
||||
// Allows control of baked lighting through volume framework.
|
||||
// We could create a BuiltinData struct which would have rendering layers on it, but it seems more complicated.
|
||||
ambient *= GetIndirectDiffuseMultiplier(GetMeshRenderingLayerMask());
|
||||
#endif // CREST_HDRP
|
||||
#endif // SHADERGRAPH_PREVIEW
|
||||
|
||||
return ambient;
|
||||
}
|
||||
|
||||
half3 AmbientLight()
|
||||
{
|
||||
// Use the constant term (0th order) of SH stuff - this is the average.
|
||||
o_AmbientLight =
|
||||
const half3 ambient =
|
||||
#if AMBIENT_PROBE_BUFFER
|
||||
half3(_AmbientProbeData[0].w, _AmbientProbeData[1].w, _AmbientProbeData[2].w);
|
||||
#else
|
||||
half3(unity_SHAr.w, unity_SHAg.w, unity_SHAb.w);
|
||||
#endif
|
||||
|
||||
#if CREST_HDRP
|
||||
ApplyIndirectLightingMultiplier(o_AmbientLight);
|
||||
#endif
|
||||
}
|
||||
|
||||
// Position: SRP = WS / BIRP = SS (z ignored)
|
||||
half PrimaryLightShadows(const float3 i_Position)
|
||||
{
|
||||
// Unshadowed.
|
||||
half shadow = 1;
|
||||
|
||||
#if CREST_URP
|
||||
// We could skip GetMainLight but this is recommended approach which is likely more robust to API changes.
|
||||
float4 shadowCoord = TransformWorldToShadowCoord(i_Position);
|
||||
Light light = GetMainLight(TransformWorldToShadowCoord(i_Position));
|
||||
shadow = light.shadowAttenuation;
|
||||
#endif
|
||||
|
||||
#ifndef SHADERGRAPH_PREVIEW
|
||||
#if CREST_HDRP_FORWARD_PASS
|
||||
DirectionalLightData light = _DirectionalLightDatas[_DirectionalShadowIndex];
|
||||
HDShadowContext context = InitShadowContext();
|
||||
context.directionalShadowData = _HDDirectionalShadowData[_DirectionalShadowIndex];
|
||||
|
||||
float3 positionWS = GetCameraRelativePositionWS(i_Position);
|
||||
// From Unity:
|
||||
// > With XR single-pass and camera-relative: offset position to do lighting computations from the combined center view (original camera matrix).
|
||||
// > This is required because there is only one list of lights generated on the CPU. Shadows are also generated once and shared between the instanced views.
|
||||
ApplyCameraRelativeXR(positionWS);
|
||||
|
||||
// TODO: Pass in screen space position and scene normal.
|
||||
shadow = GetDirectionalShadowAttenuation
|
||||
(
|
||||
context,
|
||||
0, // positionSS
|
||||
positionWS,
|
||||
0, // normalWS
|
||||
light.shadowIndex,
|
||||
-light.forward
|
||||
);
|
||||
|
||||
// Apply shadow strength from main light.
|
||||
shadow = LerpWhiteTo(shadow, light.shadowDimmer);
|
||||
#endif // CREST_HDRP_FORWARD_PASS
|
||||
#endif // SHADERGRAPH_PREVIEW
|
||||
|
||||
#if CREST_BIRP
|
||||
shadow = LOAD_TEXTURE2D_X(_Crest_ScreenSpaceShadowTexture, min(i_Position.xy, _Crest_ScreenSpaceShadowTexture_TexelSize.zw - 1.0)).r;
|
||||
#endif
|
||||
|
||||
return shadow;
|
||||
return AmbientLight(ambient);
|
||||
}
|
||||
|
||||
half3 AdditionalLighting(const float3 i_PositionWS, const float4 i_ScreenPosition, const float2 i_StaticLightMapUV)
|
||||
@@ -156,32 +129,38 @@ half3 AdditionalLighting(const float3 i_PositionWS, const float4 i_ScreenPositio
|
||||
|
||||
#if CREST_URP
|
||||
#if defined(_ADDITIONAL_LIGHTS)
|
||||
InputData inputData = (InputData)0;
|
||||
inputData.normalizedScreenSpaceUV = i_ScreenPosition.xy / i_ScreenPosition.w;
|
||||
inputData.positionWS = i_PositionWS;
|
||||
|
||||
// Shadowmask.
|
||||
#if defined(SHADOWS_SHADOWMASK) && defined(LIGHTMAP_ON)
|
||||
half4 shadowMask = SAMPLE_SHADOWMASK(i_StaticLightMapUV);
|
||||
#elif !defined(LIGHTMAP_ON)
|
||||
half4 shadowMask = unity_ProbesOcclusion;
|
||||
#else
|
||||
half4 shadowMask = half4(1, 1, 1, 1);
|
||||
inputData.shadowMask = SAMPLE_SHADOWMASK(i_StaticLightMapUV);
|
||||
#endif
|
||||
|
||||
const half4 shadowMask = CalculateShadowMask(inputData);
|
||||
|
||||
// No AO, but we need the struct.
|
||||
AmbientOcclusionFactor aoFactor = CreateAmbientOcclusionFactor(inputData.normalizedScreenSpaceUV, 0.0);
|
||||
|
||||
uint pixelLightCount = GetAdditionalLightsCount();
|
||||
|
||||
#ifdef _LIGHT_LAYERS
|
||||
uint meshRenderingLayers = GetMeshRenderingLayer();
|
||||
#endif
|
||||
|
||||
#if USE_CLUSTER_LIGHT_LOOP
|
||||
InputData inputData = (InputData)0;
|
||||
// For Foward+ LIGHT_LOOP_BEGIN macro uses inputData.normalizedScreenSpaceUV and inputData.positionWS.
|
||||
inputData.normalizedScreenSpaceUV = i_ScreenPosition.xy / i_ScreenPosition.w;
|
||||
inputData.positionWS = i_PositionWS;
|
||||
#endif
|
||||
|
||||
LIGHT_LOOP_BEGIN(pixelLightCount)
|
||||
// Includes shadows and cookies.
|
||||
Light light = GetAdditionalLight(lightIndex, i_PositionWS, shadowMask);
|
||||
Light light = GetAdditionalLight(lightIndex, inputData, shadowMask, aoFactor);
|
||||
|
||||
#if d_ShadowMaskBroken
|
||||
light.shadowAttenuation = 1.0;
|
||||
#endif
|
||||
|
||||
#if d_AdditionalLightsBroken
|
||||
light.color = 0.0;
|
||||
#endif
|
||||
|
||||
#ifdef _LIGHT_LAYERS
|
||||
if (IsMatchingLightLayer(light.layerMask, meshRenderingLayers))
|
||||
#endif
|
||||
@@ -189,9 +168,29 @@ LIGHT_LOOP_BEGIN(pixelLightCount)
|
||||
color += light.color * (light.distanceAttenuation * light.shadowAttenuation);
|
||||
}
|
||||
LIGHT_LOOP_END
|
||||
|
||||
#if USE_CLUSTER_LIGHT_LOOP
|
||||
// Additional directional lights.
|
||||
[loop] for (uint lightIndex = 0; lightIndex < min(URP_FP_DIRECTIONAL_LIGHTS_COUNT, MAX_VISIBLE_LIGHTS); lightIndex++)
|
||||
{
|
||||
CLUSTER_LIGHT_LOOP_SUBTRACTIVE_LIGHT_CHECK
|
||||
|
||||
Light light = GetAdditionalLight(lightIndex, inputData, shadowMask, aoFactor);
|
||||
|
||||
#ifdef _LIGHT_LAYERS
|
||||
if (IsMatchingLightLayer(light.layerMask, meshRenderingLayers))
|
||||
#endif
|
||||
{
|
||||
color += light.color * (light.distanceAttenuation * light.shadowAttenuation);
|
||||
}
|
||||
}
|
||||
#endif // USE_CLUSTER_LIGHT_LOOP
|
||||
#endif // _ADDITIONAL_LIGHTS
|
||||
#endif // CREST_URP
|
||||
|
||||
// HDRP todo.
|
||||
// BIRP has additional lights as additional passes. Handled elsewhere.
|
||||
|
||||
return color;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a381e15a67ba0474ea0e685cc27a6f8a
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,71 @@
|
||||
// Crest Water System
|
||||
// Copyright © 2024 Wave Harmonic. All rights reserved.
|
||||
|
||||
#ifndef d_WaveHarmonic_Utility_RenderPipeline_Compute
|
||||
#define d_WaveHarmonic_Utility_RenderPipeline_Compute
|
||||
|
||||
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Library/Settings.Crest.hlsl"
|
||||
|
||||
// Compute does not have an equivalent of PackageRequirements.
|
||||
// We must handle it ourselves.
|
||||
|
||||
// Fallback to BIRP if HDRP package missing.
|
||||
#if _HRP
|
||||
#if (CREST_PACKAGE_HDRP != 1)
|
||||
#undef _HRP
|
||||
#define _BRP 1
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// Fallback to BIRP if URP package missing.
|
||||
#if _URP
|
||||
#if (CREST_PACKAGE_URP != 1)
|
||||
#undef _URP
|
||||
#define _BRP 1
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if _BRP
|
||||
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Library/Utility/Legacy/Core.hlsl"
|
||||
#endif
|
||||
|
||||
#if _HRP
|
||||
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl"
|
||||
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl"
|
||||
#endif
|
||||
|
||||
#if _URP
|
||||
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl"
|
||||
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
|
||||
#endif
|
||||
|
||||
|
||||
//
|
||||
// Stereo Rendering
|
||||
//
|
||||
|
||||
// Unity 6 only, but had compilation errors for non HDRP anyway:
|
||||
// #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/TextureXR.hlsl"
|
||||
|
||||
#ifndef RW_TEXTURE2D_X
|
||||
#if defined(UNITY_STEREO_INSTANCING_ENABLED) || defined(UNITY_STEREO_MULTIVIEW_ENABLED)
|
||||
#define COORD_TEXTURE2D_X(pixelCoord) uint3(pixelCoord, SLICE_ARRAY_INDEX)
|
||||
#define RW_TEXTURE2D_X(type, textureName) RW_TEXTURE2D_ARRAY(type, textureName)
|
||||
#else // UNITY_STEREO
|
||||
#define COORD_TEXTURE2D_X(pixelCoord) pixelCoord
|
||||
#define RW_TEXTURE2D_X RW_TEXTURE2D
|
||||
#endif // UNITY_STEREO
|
||||
#endif // RW_TEXTURE2D_X
|
||||
|
||||
#ifndef UNITY_XR_ASSIGN_VIEW_INDEX
|
||||
// Helper macro to assign view index during compute/ray pass (usually from SV_DispatchThreadID or DispatchRaysIndex())
|
||||
#if defined(SHADER_STAGE_COMPUTE) || defined(SHADER_STAGE_RAY_TRACING)
|
||||
#if defined(UNITY_STEREO_INSTANCING_ENABLED)
|
||||
#define UNITY_XR_ASSIGN_VIEW_INDEX(viewIndex) unity_StereoEyeIndex = viewIndex;
|
||||
#else
|
||||
#define UNITY_XR_ASSIGN_VIEW_INDEX(viewIndex)
|
||||
#endif
|
||||
#endif
|
||||
#endif // UNITY_XR_ASSIGN_VIEW_INDEX
|
||||
|
||||
#endif // d_WaveHarmonic_Utility_RenderPipeline_Compute
|
||||
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 68cb1a44e787e45bd9de666d527b10f2
|
||||
ShaderIncludeImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: de25b8cb31cac9b4db1835b9632de8db
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,12 @@
|
||||
// Crest Water System
|
||||
// Copyright © 2024 Wave Harmonic. All rights reserved.
|
||||
|
||||
#ifndef d_WaveHarmonic_Utility_RenderPipeline_HDRP_Common
|
||||
#define d_WaveHarmonic_Utility_RenderPipeline_HDRP_Common
|
||||
|
||||
#define LoadSceneColor LoadCameraColor
|
||||
#define LoadSceneDepth LoadCameraDepth
|
||||
#define SampleSceneColor SampleCameraColor
|
||||
#define SampleSceneDepth SampleCameraDepth
|
||||
|
||||
#endif // d_WaveHarmonic_Utility_RenderPipeline_HDRP_Common
|
||||
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 327c164f365e1468789c5950ac945e17
|
||||
ShaderIncludeImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,107 @@
|
||||
// Crest Water System
|
||||
// Copyright © 2024 Wave Harmonic. All rights reserved.
|
||||
|
||||
#ifndef d_WaveHarmonic_Utility_RenderPipeline_Shadows
|
||||
#define d_WaveHarmonic_Utility_RenderPipeline_Shadows
|
||||
|
||||
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Library/Utility/Macros.hlsl"
|
||||
|
||||
#if _BRP
|
||||
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Library/Utility/Legacy/Shadows.hlsl"
|
||||
|
||||
bool _Crest_ClearShadows;
|
||||
#endif
|
||||
|
||||
#if _HRP
|
||||
// TODO: We might be able to expose this to give developers the option.
|
||||
// #pragma multi_compile SHADOW_ULTRA_LOW SHADOW_LOW SHADOW_MEDIUM SHADOW_HIGH
|
||||
|
||||
// Ultra low uses Gather to filter which should be same cost as not filtering. See algorithms per keyword:
|
||||
// Runtime/Lighting/Shadow/HDShadowAlgorithms.hlsl
|
||||
#define SHADOW_ULTRA_LOW
|
||||
#define AREA_SHADOW_LOW
|
||||
#define PUNCTUAL_SHADOW_ULTRA_LOW
|
||||
#define DIRECTIONAL_SHADOW_ULTRA_LOW
|
||||
|
||||
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/CommonMaterial.hlsl"
|
||||
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/HDShadow.hlsl"
|
||||
#endif
|
||||
|
||||
#if _URP
|
||||
// Maybe this is the equivalent of the SHADOW_COLLECTOR_PASS define?
|
||||
// Inspired from com.unity.render-pipelines.universal/Shaders/Utils/ScreenSpaceShadows.shader
|
||||
#define _MAIN_LIGHT_SHADOWS_CASCADE
|
||||
#define MAIN_LIGHT_CALCULATE_SHADOWS
|
||||
|
||||
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/CommonMaterial.hlsl"
|
||||
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Shadows.hlsl"
|
||||
#endif
|
||||
|
||||
m_UtilityNameSpace
|
||||
|
||||
#if _BRP
|
||||
half SampleShadows(const float4 i_positionWS)
|
||||
{
|
||||
// NOTE: "Shadow Projection > Close Fit" can still produce artefacts when away from caster, but this
|
||||
// appears to be an improvement over the compute shader.
|
||||
|
||||
// Calculate depth. Normally this would be depth from the depth buffer.
|
||||
float z = dot(i_positionWS.xyz - _WorldSpaceCameraPos.xyz, unity_CameraToWorld._m02_m12_m22);
|
||||
|
||||
float4 weights = GET_CASCADE_WEIGHTS(i_positionWS.xyz, z);
|
||||
float4 shadowCoord = GET_SHADOW_COORDINATES(i_positionWS, weights);
|
||||
half shadows = UNITY_SAMPLE_SHADOW(_ShadowMapTexture, shadowCoord);
|
||||
if (_Crest_ClearShadows) shadows = 1.0;
|
||||
shadows = lerp(_LightShadowData.r, 1.0, shadows);
|
||||
|
||||
return shadows;
|
||||
}
|
||||
|
||||
half ComputeShadowFade(const float4 i_positionWS)
|
||||
{
|
||||
float z = dot(i_positionWS.xyz - _WorldSpaceCameraPos.xyz, unity_CameraToWorld._m02_m12_m22);
|
||||
float fadeDistance = UnityComputeShadowFadeDistance(i_positionWS.xyz, z);
|
||||
float fade = UnityComputeShadowFade(fadeDistance);
|
||||
return fade;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if _HRP
|
||||
half SampleShadows(const float4 i_positionWS)
|
||||
{
|
||||
// Get directional light data. By definition we only have one directional light casting shadow.
|
||||
DirectionalLightData light = _DirectionalLightDatas[_DirectionalShadowIndex];
|
||||
HDShadowContext context = InitShadowContext();
|
||||
|
||||
// Zeros are for screen space position and world space normal which are for filtering and normal bias
|
||||
// respectively. They did not appear to have an impact.
|
||||
half shadows = GetDirectionalShadowAttenuation(context, 0, i_positionWS.xyz, 0, _DirectionalShadowIndex, -light.forward);
|
||||
// Apply shadow strength from main light.
|
||||
shadows = LerpWhiteTo(shadows, light.shadowDimmer);
|
||||
|
||||
return shadows;
|
||||
}
|
||||
|
||||
half ComputeShadowFade(const float4 i_positionWS)
|
||||
{
|
||||
// TODO: Work out shadow fade.
|
||||
return 0.0;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if _URP
|
||||
half SampleShadows(const float4 i_positionWS)
|
||||
{
|
||||
// Includes soft shadows if _SHADOWS_SOFT is defined (requires multi-compile pragma).
|
||||
return MainLightRealtimeShadow(TransformWorldToShadowCoord(i_positionWS.xyz));
|
||||
}
|
||||
|
||||
half ComputeShadowFade(const float4 i_positionWS)
|
||||
{
|
||||
return GetShadowFade(i_positionWS.xyz);
|
||||
}
|
||||
#endif
|
||||
|
||||
m_UtilityNameSpaceEnd
|
||||
|
||||
#endif // d_WaveHarmonic_Utility_RenderPipeline_Shadows
|
||||
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 07d6b2cd79ac04fa5b56cffd5fb1bb31
|
||||
ShaderIncludeImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,85 @@
|
||||
// Crest Water System
|
||||
// Copyright © 2024 Wave Harmonic. All rights reserved.
|
||||
|
||||
#ifndef CREST_SHADOWS_H
|
||||
#define CREST_SHADOWS_H
|
||||
|
||||
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Library/Macros.hlsl"
|
||||
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Library/Globals.hlsl"
|
||||
|
||||
#if CREST_BIRP
|
||||
TEXTURE2D_X(_Crest_ScreenSpaceShadowTexture);
|
||||
float4 _Crest_ScreenSpaceShadowTexture_TexelSize;
|
||||
#endif // CREST_BIRP
|
||||
|
||||
#if CREST_URP
|
||||
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"
|
||||
#endif // CREST_URP
|
||||
|
||||
#if CREST_HDRP
|
||||
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl"
|
||||
|
||||
#ifndef SHADERGRAPH_PREVIEW
|
||||
#if CREST_HDRP_FORWARD_PASS
|
||||
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/HDShadow.hlsl"
|
||||
#endif // CREST_HDRP_FORWARD_PASS
|
||||
#endif // SHADERGRAPH_PREVIEW
|
||||
#endif // CREST_HDRP
|
||||
|
||||
m_CrestNameSpace
|
||||
|
||||
// Position: SRP = WS / BIRP = SS (z ignored)
|
||||
half PrimaryLightShadows(const float3 i_Position, const float2 i_ScreenPosition)
|
||||
{
|
||||
// Unshadowed.
|
||||
half shadow = 1;
|
||||
|
||||
#if CREST_URP
|
||||
// We could skip GetMainLight but this is recommended approach which is likely more robust to API changes.
|
||||
float4 shadowCoord = TransformWorldToShadowCoord(i_Position);
|
||||
Light light = GetMainLight(TransformWorldToShadowCoord(i_Position));
|
||||
shadow = light.shadowAttenuation;
|
||||
#endif
|
||||
|
||||
#ifndef SHADERGRAPH_PREVIEW
|
||||
#if CREST_HDRP_FORWARD_PASS
|
||||
DirectionalLightData light = _DirectionalLightDatas[_DirectionalShadowIndex];
|
||||
HDShadowContext context = InitShadowContext();
|
||||
context.directionalShadowData = _HDDirectionalShadowData[_DirectionalShadowIndex];
|
||||
|
||||
float3 positionWS = GetCameraRelativePositionWS(i_Position);
|
||||
// From Unity:
|
||||
// > With XR single-pass and camera-relative: offset position to do lighting computations from the combined center view (original camera matrix).
|
||||
// > This is required because there is only one list of lights generated on the CPU. Shadows are also generated once and shared between the instanced views.
|
||||
ApplyCameraRelativeXR(positionWS);
|
||||
|
||||
// TODO: Pass in screen space position and scene normal.
|
||||
shadow = GetDirectionalShadowAttenuation
|
||||
(
|
||||
context,
|
||||
0, // positionSS
|
||||
positionWS,
|
||||
0, // normalWS
|
||||
light.shadowIndex,
|
||||
-light.forward
|
||||
);
|
||||
|
||||
// Apply shadow strength from main light.
|
||||
shadow = LerpWhiteTo(shadow, light.shadowDimmer);
|
||||
#endif // CREST_HDRP_FORWARD_PASS
|
||||
#endif // SHADERGRAPH_PREVIEW
|
||||
|
||||
#if CREST_BIRP
|
||||
shadow = LOAD_TEXTURE2D_X(_Crest_ScreenSpaceShadowTexture, min(i_ScreenPosition, _Crest_ScreenSpaceShadowTexture_TexelSize.zw - 1.0)).r;
|
||||
#if DIRECTIONAL_COOKIE
|
||||
const half attenuation = tex2D(_LightTexture0, mul(unity_WorldToLight, float4(i_Position, 1.0)).xy).w;
|
||||
shadow = min(attenuation, shadow);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
return shadow;
|
||||
}
|
||||
|
||||
m_CrestNameSpaceEnd
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b4623a51d04ef4e9c82e9196bf28e48d
|
||||
ShaderIncludeImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user