'push'
This commit is contained in:
@@ -0,0 +1,4 @@
|
||||
// Crest Water System
|
||||
// Copyright © 2024 Wave Harmonic. All rights reserved.
|
||||
|
||||
// Empty.
|
||||
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4ff429977add540198b8820ff8f0cd7a
|
||||
ShaderIncludeImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,35 @@
|
||||
// Crest Water System
|
||||
// Copyright © 2024 Wave Harmonic. All rights reserved.
|
||||
|
||||
// Builds on Unity's shim for Shader Graph.
|
||||
|
||||
#define BUILTIN_TARGET_API 1
|
||||
|
||||
#include "Packages/com.unity.shadergraph/Editor/Generation/Targets/BuiltIn/Editor/ShaderGraph/Includes/ShaderPass.hlsl"
|
||||
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Library/Utility/Legacy/Defines.hlsl"
|
||||
#include "Packages/com.unity.shadergraph/Editor/Generation/Targets/BuiltIn/ShaderLibrary/Shim/Shims.hlsl"
|
||||
#include "Packages/com.unity.shadergraph/Editor/Generation/Targets/BuiltIn/ShaderLibrary/Core.hlsl"
|
||||
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Library/Utility/Legacy/InputsDriven.hlsl"
|
||||
|
||||
#ifndef d_WaveHarmonic_Utility_LegacyCore
|
||||
#define d_WaveHarmonic_Utility_LegacyCore
|
||||
|
||||
|
||||
//
|
||||
// Inputs
|
||||
//
|
||||
|
||||
#undef UNITY_MATRIX_I_VP
|
||||
|
||||
#if defined(STEREO_INSTANCING_ON) || defined(STEREO_MULTIVIEW_ON)
|
||||
float4x4 _Crest_StereoInverseViewProjection[2];
|
||||
#define UNITY_MATRIX_I_VP _Crest_StereoInverseViewProjection[unity_StereoEyeIndex]
|
||||
#else
|
||||
float4x4 _Crest_InverseViewProjection;
|
||||
#define UNITY_MATRIX_I_VP _Crest_InverseViewProjection
|
||||
#endif
|
||||
|
||||
// Not set and _ScreenParams.zw is "1.0 + 1.0 / _ScreenParams.xy"
|
||||
#define _ScreenSize float4(_ScreenParams.xy, float2(1.0, 1.0) / _ScreenParams.xy)
|
||||
|
||||
#endif // d_WaveHarmonic_Utility_LegacyCore
|
||||
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8501e8dffc440417cb78449e6079d3fa
|
||||
ShaderIncludeImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -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:
|
||||
@@ -0,0 +1,4 @@
|
||||
// Crest Water System
|
||||
// Copyright © 2024 Wave Harmonic. All rights reserved.
|
||||
|
||||
// Empty.
|
||||
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8e956ca85fd1846899d2a3b106267dcd
|
||||
ShaderIncludeImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -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:
|
||||
@@ -0,0 +1,105 @@
|
||||
// Crest Water System
|
||||
// Copyright © 2024 Wave Harmonic. All rights reserved.
|
||||
|
||||
// Copyright (c) 2016 Unity Technologies
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
// this software and associated documentation files (the "Software"), to deal in
|
||||
// the Software without restriction, including without limitation the rights to
|
||||
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
// of the Software, and to permit persons to whom the Software is furnished to do
|
||||
// so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
// FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
// Taken from:
|
||||
// 2020.3.12f1/DefaultResourcesExtra/Internal-ScreenSpaceShadows.shader
|
||||
|
||||
#include "UnityShadowLibrary.cginc"
|
||||
|
||||
#ifndef SHADOWMAPSAMPLER_DEFINED
|
||||
UNITY_DECLARE_SHADOWMAP(_ShadowMapTexture);
|
||||
#define SHADOWMAPSAMPLER_DEFINED
|
||||
|
||||
#ifndef SHADOWMAPSAMPLER_AND_TEXELSIZE_DEFINED
|
||||
float4 _ShadowMapTexture_TexelSize;
|
||||
#define SHADOWMAPSAMPLER_AND_TEXELSIZE_DEFINED
|
||||
#endif
|
||||
#endif
|
||||
|
||||
//
|
||||
// Keywords based defines
|
||||
//
|
||||
#if defined (SHADOWS_SPLIT_SPHERES)
|
||||
#define GET_CASCADE_WEIGHTS(wpos, z) getCascadeWeights_splitSpheres(wpos)
|
||||
#else
|
||||
#define GET_CASCADE_WEIGHTS(wpos, z) getCascadeWeights( wpos, z )
|
||||
#endif
|
||||
|
||||
#if defined (SHADOWS_SINGLE_CASCADE)
|
||||
#define GET_SHADOW_COORDINATES(wpos,cascadeWeights) getShadowCoord_SingleCascade(wpos)
|
||||
#else
|
||||
#define GET_SHADOW_COORDINATES(wpos,cascadeWeights) getShadowCoord(wpos,cascadeWeights)
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Gets the cascade weights based on the world position of the fragment.
|
||||
* Returns a float4 with only one component set that corresponds to the appropriate cascade.
|
||||
*/
|
||||
inline fixed4 getCascadeWeights(float3 wpos, float z)
|
||||
{
|
||||
fixed4 zNear = float4( z >= _LightSplitsNear );
|
||||
fixed4 zFar = float4( z < _LightSplitsFar );
|
||||
fixed4 weights = zNear * zFar;
|
||||
return weights;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the cascade weights based on the world position of the fragment and the poisitions of the split spheres for each cascade.
|
||||
* Returns a float4 with only one component set that corresponds to the appropriate cascade.
|
||||
*/
|
||||
inline fixed4 getCascadeWeights_splitSpheres(float3 wpos)
|
||||
{
|
||||
float3 fromCenter0 = wpos.xyz - unity_ShadowSplitSpheres[0].xyz;
|
||||
float3 fromCenter1 = wpos.xyz - unity_ShadowSplitSpheres[1].xyz;
|
||||
float3 fromCenter2 = wpos.xyz - unity_ShadowSplitSpheres[2].xyz;
|
||||
float3 fromCenter3 = wpos.xyz - unity_ShadowSplitSpheres[3].xyz;
|
||||
float4 distances2 = float4(dot(fromCenter0,fromCenter0), dot(fromCenter1,fromCenter1), dot(fromCenter2,fromCenter2), dot(fromCenter3,fromCenter3));
|
||||
fixed4 weights = float4(distances2 < unity_ShadowSplitSqRadii);
|
||||
weights.yzw = saturate(weights.yzw - weights.xyz);
|
||||
return weights;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the shadowmap coordinates for the given fragment based on the world position and z-depth.
|
||||
* These coordinates belong to the shadowmap atlas that contains the maps for all cascades.
|
||||
*/
|
||||
inline float4 getShadowCoord( float4 wpos, fixed4 cascadeWeights )
|
||||
{
|
||||
float3 sc0 = mul (unity_WorldToShadow[0], wpos).xyz;
|
||||
float3 sc1 = mul (unity_WorldToShadow[1], wpos).xyz;
|
||||
float3 sc2 = mul (unity_WorldToShadow[2], wpos).xyz;
|
||||
float3 sc3 = mul (unity_WorldToShadow[3], wpos).xyz;
|
||||
float4 shadowMapCoordinate = float4(sc0 * cascadeWeights[0] + sc1 * cascadeWeights[1] + sc2 * cascadeWeights[2] + sc3 * cascadeWeights[3], 1);
|
||||
#if defined(UNITY_REVERSED_Z)
|
||||
float noCascadeWeights = 1 - dot(cascadeWeights, float4(1, 1, 1, 1));
|
||||
shadowMapCoordinate.z += noCascadeWeights;
|
||||
#endif
|
||||
return shadowMapCoordinate;
|
||||
}
|
||||
|
||||
/**
|
||||
* Same as the getShadowCoord; but optimized for single cascade
|
||||
*/
|
||||
inline float4 getShadowCoord_SingleCascade( float4 wpos )
|
||||
{
|
||||
return float4( mul (unity_WorldToShadow[0], wpos).xyz, 0);
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 14d63b54d73024767903a5caa23e8e53
|
||||
ShaderIncludeImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user