备份CatanBuilding瘦身独立工程
This commit is contained in:
8
LocalPackages/StylizedWater2/Shaders/Libraries.meta
Normal file
8
LocalPackages/StylizedWater2/Shaders/Libraries.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2865165c6c3c1ee41a13ff8ce3ce4440
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
48
LocalPackages/StylizedWater2/Shaders/Libraries/Caustics.hlsl
Normal file
48
LocalPackages/StylizedWater2/Shaders/Libraries/Caustics.hlsl
Normal file
@@ -0,0 +1,48 @@
|
||||
#include "Common.hlsl"
|
||||
|
||||
bool _EnableDirectionalCaustics;
|
||||
float4x4 CausticsProjection;
|
||||
|
||||
TEXTURE2D(_CausticsTex);
|
||||
SAMPLER(sampler_CausticsTex);
|
||||
|
||||
float2 GetCausticsProjection(in float4 positionCS, in float3 lightDir, float3 positionWS, inout half attenuation)
|
||||
{
|
||||
if(_EnableDirectionalCaustics)
|
||||
{
|
||||
#if ADVANCED_SHADING
|
||||
const float3 sceneWorldNormal = ReconstructWorldNormal(positionCS);
|
||||
|
||||
const half NdotL = saturate(dot(sceneWorldNormal, lightDir));
|
||||
attenuation *= NdotL;
|
||||
#endif
|
||||
|
||||
//CausticsProjection matrix set up through scripting
|
||||
return mul(CausticsProjection, float4(positionWS, 1.0)).xy;
|
||||
}
|
||||
|
||||
return positionWS.xz;
|
||||
}
|
||||
|
||||
float3 SampleCaustics(float2 uv, float2 time, float tiling)
|
||||
{
|
||||
float3 caustics1 = SAMPLE_TEXTURE2D(_CausticsTex, sampler_CausticsTex, uv * tiling + (time.xy)).rgb;
|
||||
float3 caustics2 = SAMPLE_TEXTURE2D(_CausticsTex, sampler_CausticsTex, (uv * tiling * 0.8) - (time.xy)).rgb;
|
||||
|
||||
#if UNITY_COLORSPACE_GAMMA
|
||||
caustics1 = SRGBToLinear(caustics1);
|
||||
caustics2 = SRGBToLinear(caustics2);
|
||||
#endif
|
||||
|
||||
float3 caustics = min(caustics1, caustics2);
|
||||
|
||||
#if HQ_CAUSTICS
|
||||
float3 caustics3 = SAMPLE_TEXTURE2D(_CausticsTex, sampler_CausticsTex, (uv * tiling * 0.6) + (time.xy * 1.2)).rgb * 1;
|
||||
float3 caustics4 = SAMPLE_TEXTURE2D(_CausticsTex, sampler_CausticsTex, (uv * tiling * 0.55) - (time.xy * 1.2)).rgb * 1;
|
||||
caustics4 = min(caustics3, caustics4);
|
||||
|
||||
caustics = min(caustics, caustics4) * 2.0;
|
||||
#endif
|
||||
|
||||
return caustics;
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 083a1df0137b41ca9e48f080418edca7
|
||||
timeCreated: 1623320383
|
||||
217
LocalPackages/StylizedWater2/Shaders/Libraries/Common.hlsl
Normal file
217
LocalPackages/StylizedWater2/Shaders/Libraries/Common.hlsl
Normal file
@@ -0,0 +1,217 @@
|
||||
//Stylized Water 2
|
||||
//Staggart Creations (http://staggart.xyz)
|
||||
//Copyright protected under Unity Asset Store EULA
|
||||
|
||||
#ifndef WATER_COMMON_INCLUDED
|
||||
#define WATER_COMMON_INCLUDED
|
||||
|
||||
//As per the "Shader" section of the documentation, this is primarily used for synchronizing animations in networked applications.
|
||||
float _CustomTime;
|
||||
#define TIME_FRAG_INPUT _CustomTime > 0 ? _CustomTime : input.uv.z
|
||||
#define TIME_VERTEX_OUTPUT _CustomTime > 0 ? _CustomTime : output.uv.z
|
||||
|
||||
#define TIME ((TIME_FRAG_INPUT * _Speed) * -_Direction.xy)
|
||||
#define TIME_VERTEX ((TIME_VERTEX_OUTPUT * _Speed) * -_Direction.xy)
|
||||
|
||||
#define HORIZONTAL_DISPLACEMENT_SCALAR 0.01
|
||||
#define UP_VECTOR float3(0,1,0)
|
||||
#define RAD2DEGREE 57.29578
|
||||
|
||||
struct WaterSurface
|
||||
{
|
||||
uint vFace;
|
||||
float3 positionWS;
|
||||
float3 viewDelta; //Un-normalized view direction,
|
||||
float3 viewDir;
|
||||
|
||||
//Normal from the base geometry, in world-space
|
||||
float3 vertexNormal;
|
||||
//Normal of geometry + waves
|
||||
float3 waveNormal;
|
||||
half3x3 tangentToWorldMatrix;
|
||||
//Tangent-space normal
|
||||
float3 tangentNormal;
|
||||
//World-space normal, include geometry+waves+normal map
|
||||
float3 tangentWorldNormal;
|
||||
//The normal used for diffuse lighting.
|
||||
float3 diffuseNormal;
|
||||
//Per-pixel offset vector
|
||||
float4 refractionOffset;
|
||||
|
||||
float3 albedo;
|
||||
float3 reflections;
|
||||
float3 caustics;
|
||||
float3 specular;
|
||||
half reflectionMask;
|
||||
half reflectionLighting;
|
||||
|
||||
float3 offset;
|
||||
float slope;
|
||||
|
||||
float fog;
|
||||
float intersection;
|
||||
float foam;
|
||||
|
||||
float alpha;
|
||||
float edgeFade;
|
||||
float shadowMask;
|
||||
};
|
||||
|
||||
//Set through the public static C# parameter: StylizedWater2.WaterObject.PositionOffset
|
||||
float3 _WaterPositionOffset;
|
||||
|
||||
float2 GetSourceUV(float2 uv, float2 wPos, float state)
|
||||
{
|
||||
#ifdef _RIVER
|
||||
//World-space tiling is useless in this case
|
||||
return uv;
|
||||
#endif
|
||||
|
||||
float2 output = lerp(uv, wPos - _WaterPositionOffset.xz, state);
|
||||
|
||||
//Pixelize
|
||||
#ifdef PIXELIZE_UV
|
||||
output.x = (int)((output.x / 0.5) + 0.5) * 0.5;
|
||||
output.y = (int)((output.y / 0.5) + 0.5) * 0.5;
|
||||
#endif
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
float4 GetVertexColor(float4 inputColor, float4 mask)
|
||||
{
|
||||
return inputColor * mask;
|
||||
}
|
||||
|
||||
float DepthDistance(float3 wPos, float3 viewPos, float3 normal)
|
||||
{
|
||||
return length((wPos - viewPos) * normal);
|
||||
}
|
||||
|
||||
float4 PackedUV(float2 sourceUV, float2 tiling, float2 time, float speed, float subTiling, float subSpeed)
|
||||
{
|
||||
float2 baseSpeed = speed.xx * tiling;
|
||||
float2 uv1 = (sourceUV.xy * tiling.xy) + (time.xy * baseSpeed);
|
||||
|
||||
float2 tiling_uv2 = tiling * subTiling;
|
||||
float2 uv2 = (sourceUV.xy * tiling_uv2) + (time.xy * (speed.xx * subSpeed * tiling_uv2));
|
||||
|
||||
return float4(uv1.xy, uv2.xy);
|
||||
}
|
||||
|
||||
struct SurfaceNormalData
|
||||
{
|
||||
float3 geometryNormalWS;
|
||||
float3 pixelNormalWS;
|
||||
float lightingStrength;
|
||||
float mask;
|
||||
};
|
||||
|
||||
float CalculateSlopeMask(float3 normalWS, float threshold, float falloff)
|
||||
{
|
||||
const float surfaceAngle = acos(dot(normalWS, UP_VECTOR) * 2.0 - 1.0) * RAD2DEGREE;
|
||||
|
||||
const float start = surfaceAngle - threshold;
|
||||
const float end = threshold - falloff;
|
||||
|
||||
return saturate((end - start) / (end - threshold));
|
||||
}
|
||||
|
||||
struct SceneDepth
|
||||
{
|
||||
float raw;
|
||||
float linear01;
|
||||
float eye;
|
||||
};
|
||||
|
||||
#define FAR_CLIP _ProjectionParams.z
|
||||
#define NEAR_CLIP _ProjectionParams.y
|
||||
//Scale linear values to the clipping planes for orthographic projection (unity_OrthoParams.w = 1 = orthographic)
|
||||
#define DEPTH_SCALAR lerp(1.0, FAR_CLIP - NEAR_CLIP, unity_OrthoParams.w)
|
||||
|
||||
//Linear depth difference between scene and current (transparent) geometry pixel
|
||||
float SurfaceDepth(SceneDepth depth, float4 positionCS)
|
||||
{
|
||||
const float sceneDepth = (unity_OrthoParams.w == 0) ? depth.eye : LinearDepthToEyeDepth(depth.raw);
|
||||
const float clipSpaceDepth = (unity_OrthoParams.w == 0) ? LinearEyeDepth(positionCS.z, _ZBufferParams) : LinearDepthToEyeDepth(positionCS.z / positionCS.w);
|
||||
|
||||
return sceneDepth - clipSpaceDepth;
|
||||
}
|
||||
|
||||
//Return depth based on the used technique (buffer, vertex color, baked texture)
|
||||
SceneDepth SampleDepth(float4 screenPos)
|
||||
{
|
||||
SceneDepth depth = (SceneDepth)0;
|
||||
|
||||
#ifndef _DISABLE_DEPTH_TEX
|
||||
screenPos.xyz /= screenPos.w;
|
||||
|
||||
depth.raw = SampleSceneDepth(screenPos.xy);
|
||||
depth.eye = LinearEyeDepth(depth.raw, _ZBufferParams);
|
||||
depth.linear01 = Linear01Depth(depth.raw, _ZBufferParams) * DEPTH_SCALAR;
|
||||
#else
|
||||
depth.raw = 1.0;
|
||||
depth.eye = 1.0;
|
||||
depth.linear01 = 1.0;
|
||||
#endif
|
||||
|
||||
return depth;
|
||||
}
|
||||
|
||||
#define ORTHOGRAPHIC_SUPPORT
|
||||
|
||||
#if defined(USING_STEREO_MATRICES)
|
||||
//Will never be used in VR, saves a per-fragment matrix multiplication
|
||||
#undef ORTHOGRAPHIC_SUPPORT
|
||||
#endif
|
||||
|
||||
//Reconstruct world-space position from depth.
|
||||
float3 ReconstructWorldPosition(float4 screenPos, float3 viewDir, SceneDepth sceneDepth)
|
||||
{
|
||||
#if UNITY_REVERSED_Z
|
||||
real rawDepth = sceneDepth.raw;
|
||||
#else
|
||||
// Adjust z to match NDC for OpenGL
|
||||
real rawDepth = lerp(UNITY_NEAR_CLIP_VALUE, 1, sceneDepth.raw);
|
||||
#endif
|
||||
|
||||
//return ComputeWorldSpacePosition(screenPos.xy / screenPos.w, rawDepth, UNITY_MATRIX_I_VP);
|
||||
|
||||
#if defined(ORTHOGRAPHIC_SUPPORT)
|
||||
//View to world position
|
||||
float4 viewPos = float4((screenPos.xy/screenPos.w) * 2.0 - 1.0, rawDepth, 1.0);
|
||||
float4x4 viewToWorld = UNITY_MATRIX_I_VP;
|
||||
#if UNITY_REVERSED_Z //Wrecked since 7.3.1 "fix" and causes warping, invert second row https://issuetracker.unity3d.com/issues/shadergraph-inverse-view-projection-transformation-matrix-is-not-the-inverse-of-view-projection-transformation-matrix
|
||||
//Commit https://github.com/Unity-Technologies/Graphics/pull/374/files
|
||||
viewToWorld._12_22_32_42 = -viewToWorld._12_22_32_42;
|
||||
#endif
|
||||
float4 viewWorld = mul(viewToWorld, viewPos);
|
||||
float3 viewWorldPos = viewWorld.xyz / viewWorld.w;
|
||||
#endif
|
||||
|
||||
//Projection to world position
|
||||
float3 camPos = GetCurrentViewPosition().xyz;
|
||||
float3 worldPos = sceneDepth.eye * (viewDir/screenPos.w) - camPos;
|
||||
float3 perspWorldPos = -worldPos;
|
||||
|
||||
#if defined(ORTHOGRAPHIC_SUPPORT)
|
||||
return lerp(perspWorldPos, viewWorldPos, unity_OrthoParams.w);
|
||||
#else
|
||||
return perspWorldPos;
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
#if UNITY_VERSION > 202110
|
||||
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/NormalReconstruction.hlsl"
|
||||
|
||||
float3 ReconstructWorldNormal(float4 positionCS)
|
||||
{
|
||||
half3 normalVS = ReconstructNormalTap3(positionCS.xy);
|
||||
|
||||
return normalVS;
|
||||
}
|
||||
#else
|
||||
float3 ReconstructWorldNormal(float4 positionCS) { return 0; }
|
||||
#endif
|
||||
#endif
|
||||
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 83975c0577d21ad4fb923060bab6981e
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,44 @@
|
||||
//Functionality to sample the water's displacement pre-pass buffer
|
||||
|
||||
uniform bool _WaterDisplacementPrePassAvailable;
|
||||
|
||||
uniform float3 _WaterDisplacementCoords;
|
||||
//XY: Bounds min
|
||||
//Z: Bounds size
|
||||
uniform Texture2D _WaterDisplacementBuffer;
|
||||
#ifndef UNITY_CORE_SAMPLERS_INCLUDED
|
||||
SamplerState sampler_LinearClamp;
|
||||
#endif
|
||||
|
||||
//Position, relative to rendering bounds (normalized 0-1)
|
||||
float2 WorldToDisplacementUV(float3 positionWS)
|
||||
{
|
||||
return (positionWS.xz - _WaterDisplacementCoords.xy) / _WaterDisplacementCoords.z;
|
||||
}
|
||||
|
||||
float SampleDisplacementBuffer(float2 uv)
|
||||
{
|
||||
if(_WaterDisplacementPrePassAvailable == false) return 0;
|
||||
const float height = _WaterDisplacementBuffer.SampleLevel(sampler_LinearClamp, uv, 0).r;
|
||||
|
||||
//Need to figure out how to determine if a void is hit
|
||||
//if(height == 0.0f) return -1000;
|
||||
|
||||
return height;
|
||||
}
|
||||
|
||||
//Main function
|
||||
float SampleWaterHeight(float3 positionWS)
|
||||
{
|
||||
return SampleDisplacementBuffer(WorldToDisplacementUV(positionWS));
|
||||
}
|
||||
|
||||
//Shader Graph
|
||||
void SampleWaterHeight_float(float3 positionWS, out float height)
|
||||
{
|
||||
#if defined(SHADERGRAPH_PREVIEW)
|
||||
height = 0;
|
||||
#else
|
||||
height = SampleWaterHeight(positionWS);
|
||||
#endif
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1318138c4ac146af86a745a7082ac2a8
|
||||
timeCreated: 1701267893
|
||||
162
LocalPackages/StylizedWater2/Shaders/Libraries/Features.hlsl
Normal file
162
LocalPackages/StylizedWater2/Shaders/Libraries/Features.hlsl
Normal file
@@ -0,0 +1,162 @@
|
||||
//Stylized Water 2
|
||||
//Staggart Creations (http://staggart.xyz)
|
||||
//Copyright protected under Unity Asset Store EULA
|
||||
|
||||
TEXTURE2D(_BumpMapLarge);
|
||||
TEXTURE2D(_BumpMapSlope);
|
||||
|
||||
float3 BlendTangentNormals(float3 a, float3 b)
|
||||
{
|
||||
#if _ADVANCED_SHADING
|
||||
return BlendNormalRNM(a, b);
|
||||
#else
|
||||
return BlendNormal(a, b);
|
||||
#endif
|
||||
}
|
||||
|
||||
float3 SampleNormals(float2 uv, float2 tiling, float subTiling, float3 wPos, float2 time, float speed, float subSpeed, float slope, int vFace)
|
||||
{
|
||||
float4 uvs = PackedUV(uv, tiling, time, speed, subTiling, subSpeed);
|
||||
float3 n1 = UnpackNormal(SAMPLE_TEXTURE2D(_BumpMap, sampler_BumpMap, uvs.xy));
|
||||
float3 n2 = UnpackNormal(SAMPLE_TEXTURE2D(_BumpMap, sampler_BumpMap, uvs.zw));
|
||||
|
||||
float3 blendedNormals = BlendTangentNormals(n1, n2);
|
||||
|
||||
#ifdef QUAD_NORMAL_SAMPLES
|
||||
uvs = PackedUV(uv, tiling, time.yx, speed, subTiling, subSpeed);
|
||||
float3 n4 = UnpackNormal(SAMPLE_TEXTURE2D(_BumpMap, sampler_BumpMap, uvs.xy * 2.0));
|
||||
float3 n5 = UnpackNormal(SAMPLE_TEXTURE2D(_BumpMap, sampler_BumpMap, uvs.zw * 2.0));
|
||||
|
||||
blendedNormals = BlendTangentNormals(blendedNormals, BlendTangentNormals(n4, n5));
|
||||
#endif
|
||||
|
||||
#if _DISTANCE_NORMALS
|
||||
float pixelDist = length(GetCurrentViewPosition().xyz - wPos.xyz);
|
||||
|
||||
#if UNDERWATER_ENABLED
|
||||
//Use vertical distance only for backfaces (underwater). This ensures tiling is reduced when moving deeper into the water, vertically
|
||||
pixelDist = lerp(length(GetCurrentViewPosition().xz - wPos.xz), pixelDist, vFace);
|
||||
#endif
|
||||
|
||||
float fadeFactor = saturate((_DistanceNormalsFadeDist.y - pixelDist) / (_DistanceNormalsFadeDist.y-_DistanceNormalsFadeDist.x));
|
||||
|
||||
float3 largeBlendedNormals;
|
||||
|
||||
uvs = PackedUV(uv, _DistanceNormalsTiling.xx, time, speed * 0.5, 0.5, 0.15);
|
||||
float3 n1b = UnpackNormal(SAMPLE_TEXTURE2D(_BumpMapLarge, sampler_BumpMap, uvs.xy));
|
||||
|
||||
#if _ADVANCED_SHADING //Use 2nd texture sample
|
||||
float3 n2b = UnpackNormal(SAMPLE_TEXTURE2D(_BumpMapLarge, sampler_BumpMap, uvs.zw));
|
||||
largeBlendedNormals = BlendTangentNormals(n1b, n2b);
|
||||
#else
|
||||
largeBlendedNormals = n1b;
|
||||
#endif
|
||||
|
||||
blendedNormals = lerp(largeBlendedNormals, blendedNormals, fadeFactor);
|
||||
#endif
|
||||
|
||||
#if _RIVER
|
||||
uvs = PackedUV(uv, tiling, time, speed * _SlopeSpeed, subTiling, subSpeed * _SlopeSpeed);
|
||||
uvs.xy = uvs.xy * float2(1, 1-_SlopeStretching);
|
||||
float3 n3 = UnpackNormal(SAMPLE_TEXTURE2D(_BumpMapSlope, sampler_BumpMap, uvs.xy));
|
||||
|
||||
#if _ADVANCED_SHADING
|
||||
n3 = BlendTangentNormals(n3, UnpackNormal(SAMPLE_TEXTURE2D(_BumpMapSlope, sampler_BumpMap, uvs.zw)));
|
||||
#endif
|
||||
|
||||
blendedNormals = lerp(blendedNormals, n3, slope);
|
||||
#endif
|
||||
|
||||
#if WAVE_SIMULATION
|
||||
BlendWaveSimulation(wPos, blendedNormals);
|
||||
#endif
|
||||
|
||||
return blendedNormals;
|
||||
}
|
||||
|
||||
float SampleIntersection(float2 uv, float gradient, float2 time)
|
||||
{
|
||||
float inter = 0;
|
||||
float dist = 0;
|
||||
|
||||
#if _SHARP_INERSECTION
|
||||
float sine = sin(time.y * 10.0 - (gradient * _IntersectionRippleDist)) * _IntersectionRippleStrength;
|
||||
float2 nUV = float2(uv.x, uv.y) * _IntersectionTiling;
|
||||
float noise = SAMPLE_TEXTURE2D(_IntersectionNoise, sampler_IntersectionNoise, nUV + time.xy).r;
|
||||
|
||||
dist = saturate(gradient / _IntersectionFalloff);
|
||||
noise = saturate((noise + sine) * dist + dist);
|
||||
inter = step(_IntersectionClipping, noise);
|
||||
#endif
|
||||
|
||||
#if _SMOOTH_INTERSECTION
|
||||
float noise1 = SAMPLE_TEXTURE2D(_IntersectionNoise, sampler_IntersectionNoise, (float2(uv.x, uv.y) * _IntersectionTiling) + (time.xy )).r;
|
||||
float noise2 = SAMPLE_TEXTURE2D(_IntersectionNoise, sampler_IntersectionNoise, (float2(uv.x, uv.y) * (_IntersectionTiling * 1.5)) - (time.xy )).r;
|
||||
|
||||
#if UNITY_COLORSPACE_GAMMA
|
||||
noise1 = SRGBToLinear(noise1);
|
||||
noise2 = SRGBToLinear(noise2);
|
||||
#endif
|
||||
|
||||
dist = saturate(gradient / _IntersectionFalloff);
|
||||
inter = saturate(noise1 + noise2 + dist) * dist;
|
||||
#endif
|
||||
|
||||
return saturate(inter);
|
||||
}
|
||||
|
||||
float ScreenEdgeMask(float2 screenPos, float length)
|
||||
{
|
||||
float lengthRcp = 1.0f/length;
|
||||
float2 t = Remap10(abs(screenPos.xy * 2.0 - 1.0), lengthRcp, lengthRcp);
|
||||
return Smoothstep01(t.x) * Smoothstep01(t.y);
|
||||
}
|
||||
|
||||
#define REFRACTION_IOR_RCP 0.7501875 //=1f/1.333f
|
||||
|
||||
float2 RefractionOffset(float2 screenPos, float3 viewDir, float3 normalWS, float strength)
|
||||
{
|
||||
//Normalized to match the more accurate method
|
||||
float2 offset = normalWS.xz * 0.5;
|
||||
|
||||
#if PHYSICAL_REFRACTION
|
||||
//Light direction as traveling towards the eye, through the water surface
|
||||
float3 rayDir = refract(-viewDir, normalWS, REFRACTION_IOR_RCP);
|
||||
//Convert to view-space, because the coordinates are used to sample a screen-space texture
|
||||
float3 viewSpaceRefraction = TransformWorldToViewDir(rayDir);
|
||||
|
||||
//Prevent streaking at the edges, by lerping to non-screenspace coordinates at the screen edges
|
||||
half edgeMask = ScreenEdgeMask(screenPos, length(viewSpaceRefraction.xy));
|
||||
//edgeMask = 1.0; //Test, disable
|
||||
|
||||
offset.xy = lerp(normalWS.xz * 0.5, viewSpaceRefraction.xy, edgeMask);
|
||||
#endif
|
||||
|
||||
return offset * strength;
|
||||
}
|
||||
|
||||
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareOpaqueTexture.hlsl"
|
||||
#define CHROMASHIFT_SIZE 0.05
|
||||
|
||||
float3 SampleOpaqueTexture(float4 screenPos, float2 offset, float dispersion)
|
||||
{
|
||||
//Normalize for perspective projection
|
||||
screenPos.xy += offset;
|
||||
screenPos.xy /= screenPos.w;
|
||||
|
||||
float3 sceneColor = SampleSceneColor(screenPos.xy).rgb;
|
||||
|
||||
#if PHYSICAL_REFRACTION //Chromatic part
|
||||
if(dispersion > 0)
|
||||
{
|
||||
float chromaShift = (length(offset) * dispersion) / screenPos.w;
|
||||
//Note: screen buffer texelsize purposely not used, this way the effect is actually consistent across all resolutions
|
||||
float texelOffset = chromaShift * CHROMASHIFT_SIZE;
|
||||
|
||||
sceneColor.r = SampleSceneColor(screenPos.xy + float2(texelOffset, 0)).r;
|
||||
sceneColor.b = SampleSceneColor(screenPos.xy - float2(texelOffset, 0)).b;
|
||||
}
|
||||
#endif
|
||||
|
||||
return sceneColor;
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e07d48b24ec0e5841b5fc7f6a2d15054
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
56
LocalPackages/StylizedWater2/Shaders/Libraries/Foam.hlsl
Normal file
56
LocalPackages/StylizedWater2/Shaders/Libraries/Foam.hlsl
Normal file
@@ -0,0 +1,56 @@
|
||||
//Stylized Water 2
|
||||
//Staggart Creations (http://staggart.xyz)
|
||||
//Copyright protected under Unity Asset Store EULA
|
||||
|
||||
#ifndef WATER_FOAM_INCLUDED
|
||||
#define WATER_FOAM_INCLUDED
|
||||
|
||||
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
|
||||
|
||||
TEXTURE2D(_FoamTex);
|
||||
SAMPLER(sampler_FoamTex);
|
||||
|
||||
#define FOAM_CHANNEL 0
|
||||
|
||||
float SampleFoamTexture(TEXTURE2D_PARAM(tex, samplerName), float2 uv, float2 tiling, float subTiling, float2 time, float speed, float subSpeed, float slopeMask, float slopeSpeed, float slopeStretch, bool slopeFoamOn)
|
||||
{
|
||||
float4 uvs = PackedUV(uv, tiling, time, speed, subTiling, subSpeed);
|
||||
|
||||
float f1 = SAMPLE_TEXTURE2D(tex, samplerName, uvs.xy)[FOAM_CHANNEL];
|
||||
float f2 = SAMPLE_TEXTURE2D(tex, samplerName, uvs.zw)[FOAM_CHANNEL];
|
||||
|
||||
#if UNITY_COLORSPACE_GAMMA
|
||||
f1 = SRGBToLinear(f1);
|
||||
f2 = SRGBToLinear(f2);
|
||||
#endif
|
||||
|
||||
float foam = saturate(f1 + f2);
|
||||
|
||||
if(slopeFoamOn)
|
||||
{
|
||||
uvs = PackedUV(uv, tiling, time, speed * slopeSpeed, subTiling, subSpeed * slopeSpeed);
|
||||
//Stretch UV vertically on slope
|
||||
uvs.yw *= 1-slopeStretch;
|
||||
|
||||
//Cannot reuse the same UV, slope foam needs to be resampled and blended in
|
||||
float f3 = SAMPLE_TEXTURE2D(tex, samplerName, uvs.xy)[FOAM_CHANNEL];
|
||||
float f4 = SAMPLE_TEXTURE2D(tex, samplerName, uvs.zw)[FOAM_CHANNEL];
|
||||
|
||||
#if UNITY_COLORSPACE_GAMMA
|
||||
f3 = SRGBToLinear(f3);
|
||||
f4 = SRGBToLinear(f4);
|
||||
#endif
|
||||
|
||||
const half slopeFoam = saturate(f3 + f4);
|
||||
|
||||
foam = lerp(foam, slopeFoam, slopeMask);
|
||||
}
|
||||
|
||||
return foam;
|
||||
}
|
||||
|
||||
float SampleFoamTexture(float2 uv, float2 tiling, float subTiling, float2 time, float speed, float subSpeed, float slopeMask, float slopeSpeed, half slopeStretch, bool slopeFoamOn)
|
||||
{
|
||||
return SampleFoamTexture(TEXTURE2D_ARGS(_FoamTex, sampler_FoamTex), uv, tiling, subTiling, time, speed, subSpeed, slopeMask, slopeSpeed, slopeStretch, slopeFoamOn);
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bc44ed7be80a4457ab68b36746675546
|
||||
timeCreated: 1686819225
|
||||
89
LocalPackages/StylizedWater2/Shaders/Libraries/Fog.hlsl
Normal file
89
LocalPackages/StylizedWater2/Shaders/Libraries/Fog.hlsl
Normal file
@@ -0,0 +1,89 @@
|
||||
//Set this to value to 1 through Shader.SetGlobalFloat to temporarily disable fog for water
|
||||
float _WaterFogDisabled;
|
||||
|
||||
//Authors of third-party fog solutions can reach out to have their method integrated here
|
||||
|
||||
#ifdef SCPostEffects
|
||||
//Macros normally used for cross-RP compatibility
|
||||
#define LINEAR_DEPTH(depth) Linear01Depth(depth, _ZBufferParams)
|
||||
|
||||
//Legacy (pre v2.2.1)
|
||||
#define DECLARE_TEX(textureName) TEXTURE2D(textureName);
|
||||
#define DECLARE_RT(textureName) TEXTURE2D_X(textureName);
|
||||
#define SAMPLE_TEX(textureName, samplerName, uv) SAMPLE_TEXTURE2D_LOD(textureName, samplerName, uv, 0)
|
||||
#define SAMPLE_RT_LOD(textureName, samplerName, uv, mip) SAMPLE_TEXTURE2D_X_LOD(textureName, samplerName, uv, mip)
|
||||
#endif
|
||||
|
||||
#ifdef AtmosphericHeightFog
|
||||
bool AHF_Enabled;
|
||||
#endif
|
||||
|
||||
//Fragment stage. Note: Screen position passed here is not normalized (divided by w-component)
|
||||
void ApplyFog(inout float3 color, float fogFactor, float4 screenPos, float3 positionWS, float vFace)
|
||||
{
|
||||
float3 foggedColor = color;
|
||||
|
||||
#ifdef UnityFog
|
||||
foggedColor = MixFog(color.rgb, fogFactor);
|
||||
#endif
|
||||
|
||||
#ifdef Colorful
|
||||
if(_DensityParams.x > 0) foggedColor.rgb = ApplyFog(color.rgb, fogFactor, positionWS, screenPos.xy / screenPos.w);
|
||||
#endif
|
||||
|
||||
#ifdef Enviro
|
||||
//Distance/height fog enabled?
|
||||
if (_EnviroParams.y > 0 || _EnviroParams.z > 0)
|
||||
{
|
||||
foggedColor.rgb = TransparentFog(float4(color.rgb, 1.0), positionWS, screenPos.xy / screenPos.w, fogFactor).rgb;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef Enviro3
|
||||
if(_EnviroFogParameters.x > 0)
|
||||
{
|
||||
foggedColor.rgb = ApplyFogAndVolumetricLights(color.rgb, screenPos.xy / screenPos.w, positionWS, 0);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef Azure
|
||||
foggedColor.rgb = ApplyAzureFog(float4(color.rgb, 1.0), positionWS).rgb;
|
||||
#endif
|
||||
|
||||
#ifdef AtmosphericHeightFog
|
||||
if (AHF_Enabled)
|
||||
{
|
||||
float4 fogParams = GetAtmosphericHeightFog(positionWS.xyz);
|
||||
foggedColor.rgb = lerp(color.rgb, fogParams.rgb, fogParams.a);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef SCPostEffects
|
||||
//Distance or height fog enabled
|
||||
if(_DistanceParams.z == 1 || _DistanceParams.w == 1)
|
||||
{
|
||||
ApplyTransparencyFog(positionWS, screenPos.xy / screenPos.w, foggedColor.rgb);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef COZY
|
||||
foggedColor = BlendStylizedFog(positionWS, float4(color.rgb, 1.0)).rgb;
|
||||
#endif
|
||||
|
||||
#ifdef Buto
|
||||
#if defined(BUTO_API_VERSION_2) //Buto 2022
|
||||
float3 positionVS = TransformWorldToView(positionWS);
|
||||
foggedColor = ButoFogBlend(screenPos.xy / screenPos.w, -positionVS.z, color.rgb);
|
||||
#else //Buto 2021
|
||||
foggedColor = ButoFogBlend(screenPos.xy / screenPos.w, color.rgb);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef UnityFog
|
||||
//Allow fog to be disabled for water globally by setting the value through script
|
||||
foggedColor = lerp(foggedColor, color, _WaterFogDisabled);
|
||||
#endif
|
||||
|
||||
//Fog only applies to the front faces, otherwise affects underwater rendering
|
||||
color.rgb = lerp(color.rgb, foggedColor.rgb, vFace);
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8427feba489ff354ab7b22c82a15ba03
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
886
LocalPackages/StylizedWater2/Shaders/Libraries/ForwardPass.hlsl
Normal file
886
LocalPackages/StylizedWater2/Shaders/Libraries/ForwardPass.hlsl
Normal file
@@ -0,0 +1,886 @@
|
||||
//Stylized Water 2
|
||||
//Staggart Creations (http://staggart.xyz)
|
||||
//Copyright protected under Unity Asset Store EULA
|
||||
|
||||
//Double sample depth to avoid depth discrepancies
|
||||
|
||||
#define COLLAPSIBLE_GROUP 1
|
||||
|
||||
//Normalize the amount of normal-based distortion between reflection probes and screen-space reflections
|
||||
#define SCREENSPACE_REFLECTION_DISTORTION_MULTIPLIER 0.25
|
||||
|
||||
struct SceneData
|
||||
{
|
||||
float4 positionSS; //Unnormalized
|
||||
float2 screenPos; //Normalized and no refraction
|
||||
float3 positionWS;
|
||||
float3 color;
|
||||
|
||||
#if defined(SCENE_SHADOWMASK)
|
||||
float shadowMask;
|
||||
#endif
|
||||
|
||||
float viewDepth;
|
||||
float verticalDepth;
|
||||
|
||||
#if RESAMPLE_REFRACTION_DEPTH && _REFRACTION
|
||||
float viewDepthRefracted;
|
||||
float verticalDepthRefracted;
|
||||
#endif
|
||||
|
||||
float skyMask;
|
||||
|
||||
//More easy debugging
|
||||
half refractionMask;
|
||||
};
|
||||
|
||||
void PopulateSceneData(inout SceneData scene, Varyings input, WaterSurface water)
|
||||
{
|
||||
scene.positionSS = input.screenPos;
|
||||
scene.screenPos = scene.positionSS.xy / scene.positionSS.w;
|
||||
|
||||
//Default for disabled depth texture
|
||||
scene.viewDepth = 1;
|
||||
scene.verticalDepth = 1;
|
||||
|
||||
scene.refractionMask = 1.0;
|
||||
#if !_DISABLE_DEPTH_TEX
|
||||
SceneDepth depth = SampleDepth(scene.positionSS);
|
||||
scene.positionWS = ReconstructWorldPosition(scene.positionSS, water.viewDelta, depth);
|
||||
|
||||
//Invert normal when viewing backfaces
|
||||
float normalSign = ceil(dot(water.viewDir, water.waveNormal));
|
||||
normalSign = normalSign == 0 ? -1 : 1;
|
||||
|
||||
//Z-distance to opaque surface
|
||||
scene.viewDepth = SurfaceDepth(depth, input.positionCS);
|
||||
//Distance to opaque geometry in normal direction
|
||||
scene.verticalDepth = DepthDistance(water.positionWS, scene.positionWS, water.waveNormal * normalSign);
|
||||
|
||||
//Compare position of water to opaque geometry, in order to filter out pixels in front of the water for refraction
|
||||
#if _REFRACTION
|
||||
SceneDepth depthRefracted = SampleDepth(scene.positionSS + water.refractionOffset);
|
||||
float3 opaqueWorldPosRefracted = ReconstructWorldPosition(scene.positionSS + water.refractionOffset, water.viewDelta, depthRefracted);
|
||||
|
||||
//Reject any offset pixels in front of the water surface
|
||||
scene.refractionMask = saturate(SurfaceDepth(depthRefracted, input.positionCS));
|
||||
//Lerp to un-refracted screen-position
|
||||
water.refractionOffset *= scene.refractionMask;
|
||||
|
||||
#if RESAMPLE_REFRACTION_DEPTH
|
||||
//With the current screen-space UV known, re-compose the water density
|
||||
depthRefracted = SampleDepth(scene.positionSS + water.refractionOffset);
|
||||
opaqueWorldPosRefracted = ReconstructWorldPosition(scene.positionSS + water.refractionOffset, water.viewDelta, depthRefracted);
|
||||
|
||||
//Also use the world-position sample as the representation of the underwater geometry (more accurate)
|
||||
scene.positionWS = lerp(scene.positionWS, opaqueWorldPosRefracted, scene.refractionMask);
|
||||
|
||||
scene.viewDepthRefracted = SurfaceDepth(depthRefracted, input.positionCS);
|
||||
scene.verticalDepthRefracted = DepthDistance(water.positionWS, opaqueWorldPosRefracted, water.waveNormal * normalSign);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(SCENE_SHADOWMASK)
|
||||
float4 sceneShadowCoords = TransformWorldToShadowCoord(scene.positionWS);
|
||||
#if UNITY_VERSION >= 202020
|
||||
Light sceneLight = GetMainLight(sceneShadowCoords, scene.positionWS, 1.0);
|
||||
#else
|
||||
Light sceneLight = GetMainLight(sceneShadowCoords);
|
||||
#endif
|
||||
|
||||
scene.shadowMask = sceneLight.shadowAttenuation;
|
||||
#endif
|
||||
|
||||
#if !_RIVER && _ADVANCED_SHADING
|
||||
half VdotN = 1.0 - saturate(dot(water.viewDir, water.waveNormal));
|
||||
float grazingTerm = saturate(pow(VdotN, 64));
|
||||
|
||||
//Resort to z-depth at surface edges. Otherwise makes intersection/edge fade visible through the water surface
|
||||
scene.verticalDepth = lerp(scene.verticalDepth, scene.viewDepth, grazingTerm);
|
||||
|
||||
#if RESAMPLE_REFRACTION_DEPTH && _REFRACTION
|
||||
scene.verticalDepthRefracted = lerp(scene.verticalDepthRefracted, scene.viewDepthRefracted, grazingTerm);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#if _REFRACTION || UNDERWATER_ENABLED
|
||||
float dispersion = _RefractionChromaticAberration * lerp(1.0, 2.0, unity_OrthoParams.w);
|
||||
|
||||
#if UNDERWATER_ENABLED
|
||||
//Behaviour, pre v1.4.1
|
||||
//dispersion *= water.vFace;
|
||||
#endif
|
||||
|
||||
scene.color = SampleOpaqueTexture(scene.positionSS, water.refractionOffset.xy, dispersion);
|
||||
#endif
|
||||
|
||||
//Skybox mask is used for backface (underwater) reflections, to blend between refraction and reflection probes
|
||||
scene.skyMask = 0;
|
||||
#ifdef DEPTH_MASK
|
||||
|
||||
#if !_DISABLE_DEPTH_TEX
|
||||
float depthSource = depth.linear01;
|
||||
|
||||
#if RESAMPLE_REFRACTION_DEPTH && _REFRACTION
|
||||
//Use depth resampled with refracted screen UV
|
||||
depthSource = depthRefracted.linear01;
|
||||
#endif
|
||||
|
||||
scene.skyMask = depthSource > 0.99 ? 1 : 0;
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
float GetWaterDensity(SceneData scene, float mask, float heightScalar, float viewDepthScalar, bool exponential)
|
||||
{
|
||||
//Best default value, otherwise water just turns invisible (infinitely shallow)
|
||||
float density = 1.0;
|
||||
|
||||
#if !_DISABLE_DEPTH_TEX
|
||||
|
||||
float viewDepth = scene.viewDepth;
|
||||
float verticalDepth = scene.verticalDepth;
|
||||
|
||||
#if defined(RESAMPLE_REFRACTION_DEPTH) && _REFRACTION
|
||||
viewDepth = scene.viewDepthRefracted;
|
||||
verticalDepth = scene.verticalDepthRefracted;
|
||||
#endif
|
||||
|
||||
float depthAttenuation = 1.0 - exp(-viewDepth * viewDepthScalar * 0.1);
|
||||
float heightAttenuation = saturate(lerp(verticalDepth * heightScalar, 1.0 - exp(-verticalDepth * heightScalar), exponential));
|
||||
|
||||
density = max(depthAttenuation, heightAttenuation);
|
||||
|
||||
#endif
|
||||
|
||||
#if !_RIVER
|
||||
//Use green vertex color channel to subtract density
|
||||
density = saturate(density - mask);
|
||||
#endif
|
||||
|
||||
return density;
|
||||
}
|
||||
|
||||
float3 GetWaterColor(SceneData scene, float3 scatterColor, float density, float absorption)
|
||||
{
|
||||
float depth = scene.verticalDepth;
|
||||
float accumulation = scene.viewDepth;
|
||||
|
||||
#if defined(RESAMPLE_REFRACTION_DEPTH) && _REFRACTION
|
||||
depth = scene.verticalDepthRefracted;
|
||||
accumulation = scene.viewDepthRefracted;
|
||||
#endif
|
||||
|
||||
//Color of light ray passing through the water, hitting the sea floor (extinction)
|
||||
const float3 underwaterColor = saturate(scene.color * exp(-density * (depth + accumulation)));
|
||||
//Energy loss of ray, as it travels deeper and scatters (absorption)
|
||||
const float scatterAmount = saturate(exp(-absorption * accumulation));
|
||||
|
||||
return lerp(underwaterColor, scatterColor, scatterAmount);
|
||||
}
|
||||
|
||||
//Note: Throws an error about a BLENDWEIGHTS vertex attribute on GLES when VR is enabled (fixed in URP 10+)
|
||||
//Possibly related to: https://issuetracker.unity3d.com/issues/oculus-a-non-system-generated-input-signature-parameter-blendindices-cannot-appear-after-a-system-generated-value
|
||||
#if SHADER_API_GLES3 && defined(STEREO_MULTIVIEW_ON)
|
||||
#define FRONT_FACE_SEMANTIC_REAL SV_IsFrontFace
|
||||
#define FRONT_FACE_TYPE_REAL bool
|
||||
#else
|
||||
#define FRONT_FACE_SEMANTIC_REAL FRONT_FACE_SEMANTIC
|
||||
#define FRONT_FACE_TYPE_REAL FRONT_FACE_TYPE
|
||||
#endif
|
||||
|
||||
float4 ForwardPassFragment(Varyings input, FRONT_FACE_TYPE_REAL vertexFace : FRONT_FACE_SEMANTIC_REAL) : SV_Target
|
||||
{
|
||||
UNITY_SETUP_INSTANCE_ID(input);
|
||||
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);
|
||||
|
||||
//Initialize with null values. Anything that isn't assigned, shouldn't be used either
|
||||
WaterSurface water = (WaterSurface)0;
|
||||
SceneData scene = (SceneData)0;
|
||||
|
||||
water.alpha = 1.0;
|
||||
water.vFace = IS_FRONT_VFACE(vertexFace, true, false); //0 = back face
|
||||
//return float4(lerp(float3(1,0,0), float3(0,1,0), water.vFace), 1.0);
|
||||
int faceSign = water.vFace > 0 ? 1 : -1;
|
||||
|
||||
//return float4(ReconstructWorldNormal(input.positionCS), 1.0);
|
||||
|
||||
/* ========
|
||||
// GEOMETRY DATA
|
||||
=========== */
|
||||
#if COLLAPSIBLE_GROUP
|
||||
|
||||
float4 vertexColor = input.color; //Mask already applied in vertex shader
|
||||
//return float4(vertexColor.rgb, 1);
|
||||
|
||||
//Vertex normal in world-space
|
||||
float3 normalWS = normalize(input.normalWS.xyz);
|
||||
#if _NORMALMAP
|
||||
float3 WorldTangent = input.tangent.xyz;
|
||||
float3 WorldBiTangent = input.bitangent.xyz;
|
||||
|
||||
//return float4(WorldBiTangent, 1.0);
|
||||
float3 positionWS = float3(input.normalWS.w, input.tangent.w, input.bitangent.w);
|
||||
#else
|
||||
float3 positionWS = input.positionWS;
|
||||
#endif
|
||||
|
||||
#if defined(TESSELLATION_ON)
|
||||
//Debug tessellation factor
|
||||
//return float4(saturate(CalcDistanceTessFactor(float4(TransformWorldToObject(positionWS.xyz), 1.0), _TessMin, _TessMax, _TessValue)).xxx, 1.0);
|
||||
#endif
|
||||
|
||||
water.positionWS = positionWS;
|
||||
//Not normalized for depth-pos reconstruction. Normalization required for lighting (otherwise breaks on mobile)
|
||||
water.viewDelta = GetCurrentViewPosition() - positionWS;
|
||||
//water.viewDir = GetWorldSpaceViewDir(positionWS); //Uses the camera's forward vector for orthographic projection, the result isn't as useful
|
||||
|
||||
//Note: SafeNormalize() tends to cause issues on mobile when dealing with large numbers
|
||||
water.viewDir = normalize(water.viewDelta);
|
||||
//return float4(water.viewDir, 1);
|
||||
|
||||
half VdotN = 1.0 - saturate(dot(water.viewDir * faceSign, normalWS));
|
||||
|
||||
#if _FLAT_SHADING
|
||||
float3 dpdx = ddx(positionWS.xyz);
|
||||
float3 dpdy = ddy(positionWS.xyz);
|
||||
normalWS = normalize(cross(dpdy, dpdx));
|
||||
#endif
|
||||
|
||||
water.vertexNormal = normalWS;
|
||||
//return float4(water.vertexNormal, 1.0);
|
||||
|
||||
//Returns mesh or world-space UV
|
||||
float2 uv = GetSourceUV(input.uv.xy, positionWS.xz, _WorldSpaceUV);;
|
||||
#endif
|
||||
|
||||
/* ========
|
||||
// WAVES
|
||||
=========== */
|
||||
#if COLLAPSIBLE_GROUP
|
||||
|
||||
water.waveNormal = normalWS;
|
||||
|
||||
#if _WAVES
|
||||
WaveInfo waves = GetWaveInfo(uv, TIME * _WaveSpeed, _WaveHeight, lerp(1, 0, vertexColor.b), _WaveFadeDistance.x, _WaveFadeDistance.y);
|
||||
|
||||
#if !_FLAT_SHADING
|
||||
waves.normal = normalize(water.vertexNormal + waves.normal);
|
||||
|
||||
//Flatten by blue vertex color weight
|
||||
waves.normal = lerp(waves.normal, normalWS, lerp(0, 1, vertexColor.b));
|
||||
|
||||
water.waveNormal = waves.normal;
|
||||
#endif
|
||||
|
||||
//return float4(water.waveNormal.xyz, 1);
|
||||
|
||||
water.offset.y += waves.position.y;
|
||||
//For steep waves the horizontal stretching is too extreme, tone it down here
|
||||
water.offset.xz += waves.position.xz;
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#if _WAVES
|
||||
//After wave displacement, recalculated world-space UVs
|
||||
if(_WorldSpaceUV == 1) uv = GetSourceUV(input.uv.xy, positionWS.xz + water.offset.xz, _WorldSpaceUV);
|
||||
//return float4(frac(uv), 0, 1);
|
||||
#endif
|
||||
|
||||
#if DYNAMIC_EFFECTS_ENABLED
|
||||
float4 dynamicEffectsData = SampleDynamicEffectsData(positionWS.xyz + water.offset.xyz);
|
||||
//return float4(BoundsEdgeMask(positionWS.xz).xxx, 1.0);
|
||||
//return float4(dynamicEffectsData.rrr, 1.0);
|
||||
#endif
|
||||
|
||||
/* ========
|
||||
// SHADOWS
|
||||
=========== */
|
||||
#if COLLAPSIBLE_GROUP
|
||||
|
||||
water.shadowMask = 1.0;
|
||||
float4 shadowCoords = float4(0, 0, 0, 0);
|
||||
#if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR)
|
||||
shadowCoords = input.shadowCoord;
|
||||
#elif defined(MAIN_LIGHT_CALCULATE_SHADOWS)
|
||||
shadowCoords = TransformWorldToShadowCoord(water.positionWS);
|
||||
#endif
|
||||
|
||||
#if UNITY_VERSION >= 202020
|
||||
half4 shadowMask = 1.0;
|
||||
#if UNITY_VERSION >= 202030
|
||||
shadowMask = SAMPLE_SHADOWMASK(input.staticLightmapUV);
|
||||
#endif
|
||||
Light mainLight = GetMainLight(shadowCoords, water.positionWS, shadowMask);
|
||||
#else
|
||||
Light mainLight = GetMainLight(shadowCoords);
|
||||
#endif
|
||||
|
||||
//return float4(shadowMask.xyz, 1.0);
|
||||
|
||||
#if _LIGHT_LAYERS && UNITY_VERSION >= 202220
|
||||
uint meshRenderingLayers = GetMeshRenderingLayer();
|
||||
if (IsMatchingLightLayer(mainLight.layerMask, meshRenderingLayers))
|
||||
#endif
|
||||
{
|
||||
water.shadowMask = mainLight.shadowAttenuation;
|
||||
}
|
||||
|
||||
//return float4(water.shadowMask.xxx,1);
|
||||
half backfaceShadows = 1;
|
||||
|
||||
#if UNDERWATER_ENABLED
|
||||
//Separate so shadows applied by Unity's lighting do not appear on backfaces
|
||||
backfaceShadows = water.shadowMask;
|
||||
water.shadowMask = lerp(1.0, water.shadowMask, water.vFace);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if _RIVER
|
||||
water.slope = CalculateSlopeMask(water.waveNormal, _SlopeAngleThreshold, _SlopeAngleFalloff);
|
||||
//return float4(water.slope.xxx, 1);
|
||||
#endif
|
||||
|
||||
/* ========
|
||||
// NORMALS
|
||||
=========== */
|
||||
#if COLLAPSIBLE_GROUP
|
||||
water.tangentNormal = float3(0.5, 0.5, 1);
|
||||
water.tangentWorldNormal = water.waveNormal;
|
||||
|
||||
#if DYNAMIC_EFFECTS_ENABLED
|
||||
if(NORMALS_AVAILABLE)
|
||||
{
|
||||
float4 dynamicNormals = SampleDynamicEffectsNormals(water.positionWS + water.offset);
|
||||
dynamicNormals.xyz = lerp(water.vertexNormal, dynamicNormals.xyz, dynamicEffectsData.a);
|
||||
|
||||
//Composite into wave normal. Not using the tangent normal, since this has variable influence on reflection, dynamic effects should denote geometry curvature
|
||||
water.waveNormal = BlendNormalWorldspaceRNM(dynamicNormals.xyz, water.waveNormal, float3(0,1,0));
|
||||
//return float4(water.waveNormal, 1.0);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if _NORMALMAP
|
||||
//Tangent-space
|
||||
water.tangentNormal = SampleNormals(uv, _NormalTiling, _NormalSubTiling, positionWS, TIME, _NormalSpeed, _NormalSubSpeed, water.slope, water.vFace);
|
||||
//return float4(SRGBToLinear(float3(water.tangentNormal.x * 0.5 + 0.5, water.tangentNormal.y * 0.5 + 0.5, 1)), 1.0);
|
||||
|
||||
//Based on wave normal, makes it easier to create blend between the smooth wave normals and high-frequency normal maps
|
||||
water.tangentToWorldMatrix = half3x3(WorldTangent, WorldBiTangent, water.waveNormal);
|
||||
|
||||
//World-space
|
||||
water.tangentWorldNormal = normalize(TransformTangentToWorld(water.tangentNormal, water.tangentToWorldMatrix));
|
||||
|
||||
//return float4(water.tangentWorldNormal, 1.0);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if _REFRACTION || UNDERWATER_ENABLED
|
||||
float3 refractionViewDir = water.viewDir;
|
||||
|
||||
#if !_RIVER
|
||||
//Technically not correct (as opposed to view direction towards the surface world position), but works better for flat water. Value represents the camera's forward vector.
|
||||
refractionViewDir = GetWorldToViewMatrix()[2].xyz;
|
||||
#endif
|
||||
|
||||
water.refractionOffset.xy = RefractionOffset(input.screenPos.xy / input.screenPos.w, refractionViewDir, water.tangentWorldNormal, _RefractionStrength * lerp(1, 0.1, unity_OrthoParams.w));
|
||||
//Float4 so it can simply be added to the un-normalized screen position
|
||||
water.refractionOffset.zw = 0;
|
||||
|
||||
//return float4(ScreenEdgeMask(input.screenPos.xy / input.screenPos.w, length(water.refractionOffset.xy)).xxx, 1.0);
|
||||
#endif
|
||||
|
||||
//Normals can perturb the screen coordinates, so needs to be calculated first
|
||||
PopulateSceneData(scene, input, water);
|
||||
|
||||
//return float4(scene.shadowMask.xxx, 1.0);
|
||||
//return float4(scene.verticalDepth.xxx, 1.0);
|
||||
//return float4(scene.viewDepth.xxx, 1.0);
|
||||
//return float4((input.screenPos.xy / input.screenPos.w).xy, 0, 1.0);
|
||||
//return float4(frac(scene.positionWS.xyz), 1.0);
|
||||
//return float4(frac(water.refractionOffset.xy), 0, 1.0);
|
||||
//return float4(scene.refractionMask.xxx, 1.0);
|
||||
|
||||
#if UNDERWATER_ENABLED
|
||||
ClipSurface(scene.positionSS.xyzw, positionWS, input.positionCS.xyz, water.vFace);
|
||||
#endif
|
||||
|
||||
/* =========
|
||||
// COLOR + FOG
|
||||
============ */
|
||||
#if COLLAPSIBLE_GROUP
|
||||
|
||||
water.fog = GetWaterDensity(scene, vertexColor.g, _DepthHorizontal, _DepthVertical, _DepthExp);
|
||||
//return float4(water.fog.xxx, 1.0);
|
||||
|
||||
//Albedo
|
||||
float4 baseColor = lerp(_ShallowColor, _BaseColor, water.fog);
|
||||
//Avoid color bleeding for foam/intersection on clear water (assumes white foam)
|
||||
//baseColor = lerp(1.0, baseColor, baseColor.a);
|
||||
|
||||
baseColor.rgb += saturate(_WaveTint * water.offset.y);
|
||||
|
||||
water.fog *= baseColor.a;
|
||||
water.alpha = baseColor.a;
|
||||
|
||||
#if COLOR_ABSORPTION && _REFRACTION
|
||||
if (_ColorAbsorption > 0)
|
||||
{
|
||||
baseColor.rgb = GetWaterColor(scene, baseColor.rgb, water.fog, _ColorAbsorption * water.vFace);
|
||||
}
|
||||
#endif
|
||||
|
||||
water.albedo.rgb = baseColor.rgb;
|
||||
#endif
|
||||
|
||||
/* ========
|
||||
// INTERSECTION FOAM
|
||||
=========== */
|
||||
#if COLLAPSIBLE_GROUP
|
||||
|
||||
water.intersection = 0;
|
||||
#if _SHARP_INERSECTION || _SMOOTH_INTERSECTION
|
||||
|
||||
float interSecGradient = 0;
|
||||
|
||||
#if !_DISABLE_DEPTH_TEX
|
||||
float intersectionHeightDelta = scene.verticalDepth;
|
||||
|
||||
#if defined(RESAMPLE_REFRACTION_DEPTH) && _REFRACTION && defined(INTERSECTION_REFRACTION)
|
||||
intersectionHeightDelta = scene.verticalDepthRefracted;
|
||||
#endif
|
||||
|
||||
interSecGradient = 1-saturate(exp(intersectionHeightDelta) / _IntersectionLength);
|
||||
#endif
|
||||
|
||||
if (_IntersectionSource == 1) interSecGradient = vertexColor.r;
|
||||
if (_IntersectionSource == 2) interSecGradient = saturate(interSecGradient + vertexColor.r);
|
||||
|
||||
#if DYNAMIC_EFFECTS_ENABLED
|
||||
//interSecGradient += dynamicEffectsData[DE_ALPHA_CHANNEL];
|
||||
#endif
|
||||
|
||||
water.intersection = SampleIntersection(uv.xy, interSecGradient, TIME * _IntersectionSpeed) * _IntersectionColor.a;
|
||||
|
||||
#if UNDERWATER_ENABLED
|
||||
//Hide on backfaces
|
||||
water.intersection *= water.vFace;
|
||||
#endif
|
||||
|
||||
#if _WAVES && !_DISABLE_DEPTH_TEX
|
||||
//Prevent from peering through waves when camera is at the water level
|
||||
if(positionWS.y < scene.positionWS.y) water.intersection = 0;
|
||||
#endif
|
||||
|
||||
//water.density += water.intersection;
|
||||
|
||||
//Flatten normals on intersection foam
|
||||
water.waveNormal = lerp(water.waveNormal, normalWS, water.intersection);
|
||||
//return float4(water.intersection.xxx,1);
|
||||
#endif
|
||||
|
||||
#if _NORMALMAP
|
||||
water.tangentWorldNormal = lerp(water.tangentWorldNormal, water.vertexNormal, water.intersection);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* ========
|
||||
// SURFACE FOAM
|
||||
=========== */
|
||||
#if COLLAPSIBLE_GROUP
|
||||
water.foam = 0;
|
||||
|
||||
#if _FOAM
|
||||
bool enableSlopeFoam = false;
|
||||
#if _RIVER
|
||||
enableSlopeFoam = true;
|
||||
#endif
|
||||
|
||||
#if !_RIVER
|
||||
//Composed mask for foam caps, based on wave height
|
||||
float crest = saturate(water.offset.y) * _FoamWaveAmount;
|
||||
|
||||
float foamSlopeMask = 0;
|
||||
#else
|
||||
//Rivers don't have waves
|
||||
float crest = 0;
|
||||
float foamSlopeMask = saturate((water.slope * _SlopeFoam) + vertexColor.a);
|
||||
#endif
|
||||
|
||||
float baseFoam = saturate(_FoamBaseAmount - water.slope + vertexColor.a);
|
||||
float foamMask = crest + baseFoam + foamSlopeMask;
|
||||
|
||||
float2 foamOffsetVector = saturate(water.offset.yy + water.tangentWorldNormal.xz);
|
||||
|
||||
//Parallaxing
|
||||
//half2 distortion = (_FoamDistortion * water.viewDir.xz / saturate(dot(water.waveNormal, water.viewDir)));
|
||||
half2 distortion = foamOffsetVector * _FoamDistortion.xx;
|
||||
|
||||
#if _RIVER
|
||||
//Only distort sideways, makes the effect appear more like foam is moving around obstacles or shallow rocks
|
||||
distortion.y = 0;
|
||||
#endif
|
||||
|
||||
float foamTex = SampleFoamTexture((uv + distortion.xy), _FoamTiling, _FoamSubTiling, TIME, _FoamSpeed, _FoamSubSpeed, foamSlopeMask, _SlopeSpeed, _SlopeStretching, enableSlopeFoam);
|
||||
if(_FoamClipping > 0) foamTex = smoothstep(_FoamClipping, 1.0, foamTex);
|
||||
|
||||
//Dissolve the foam based on the input gradient
|
||||
foamMask = saturate(1.0 - foamMask);
|
||||
water.foam = smoothstep(foamMask, foamMask + 1.0, foamTex) * saturate(_FoamColor.a);
|
||||
|
||||
//Dynamic foam (separately sampled)
|
||||
#if DYNAMIC_EFFECTS_ENABLED
|
||||
foamOffsetVector = dynamicEffectsData[DE_DISPLACEMENT_CHANNEL].xx;
|
||||
distortion = _FoamDistortion * foamOffsetVector;
|
||||
|
||||
foamTex = SampleDynamicFoam((uv + distortion.xy), _FoamTilingDynamic, _FoamSubTilingDynamic, TIME, _FoamSpeedDynamic, _FoamSubSpeedDynamic);
|
||||
|
||||
foamMask = dynamicEffectsData[DE_FOAM_CHANNEL];
|
||||
foamMask = saturate(1.0 - foamMask);
|
||||
water.foam += smoothstep(foamMask, foamMask + 1.0, foamTex);
|
||||
|
||||
water.foam = saturate(water.foam);
|
||||
#endif
|
||||
|
||||
#if _NORMALMAP
|
||||
water.tangentWorldNormal = lerp(water.tangentWorldNormal, water.waveNormal, water.foam);
|
||||
#endif
|
||||
//return float4(water.foam.xxx, 1);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* ========
|
||||
// EMISSION (Caustics + Specular)
|
||||
=========== */
|
||||
#if COLLAPSIBLE_GROUP
|
||||
|
||||
#if _CAUSTICS
|
||||
float3 causticsCoords = scene.positionWS;
|
||||
#if _DISABLE_DEPTH_TEX
|
||||
causticsCoords = causticsCoords;
|
||||
#endif
|
||||
|
||||
float causticsMask = saturate((1-water.fog) - water.intersection - water.foam - scene.skyMask) * water.vFace;
|
||||
|
||||
float2 causticsProjection = GetCausticsProjection(input.positionCS, mainLight.direction, causticsCoords, causticsMask);
|
||||
|
||||
#ifdef SCENE_SHADOWMASK
|
||||
causticsMask *= scene.shadowMask;
|
||||
#endif
|
||||
|
||||
water.caustics = SampleCaustics(causticsProjection + lerp(water.waveNormal.xz, water.tangentWorldNormal.xz, _CausticsDistortion), TIME * _CausticsSpeed, _CausticsTiling);
|
||||
|
||||
//return float4(causticsMask.xxx, 1.0);
|
||||
|
||||
//Note: not masked by surface shadows, this occurs in the lighting function so it also takes point/spot lights into account
|
||||
water.caustics *= causticsMask * _CausticsBrightness;
|
||||
//return float4(water.caustics.rgb, 1);
|
||||
#endif
|
||||
|
||||
#if _NORMALMAP
|
||||
if(_SparkleIntensity > 0)
|
||||
{
|
||||
//Can piggyback on the tangent normal
|
||||
half3 sparkles = mainLight.color * saturate(step(_SparkleSize, (water.tangentNormal.y))) * _SparkleIntensity;
|
||||
|
||||
#if !_UNLIT
|
||||
//Fade out the effect as the sun approaches the horizon
|
||||
float sunAngle = saturate(dot(water.vertexNormal, mainLight.direction));
|
||||
float angleMask = saturate(sunAngle * 10); /* 1.0/0.10 = 10 */
|
||||
sparkles *= angleMask;
|
||||
#endif
|
||||
|
||||
water.specular += sparkles.rgb;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef _SPECULARHIGHLIGHTS_OFF
|
||||
float3 lightReflectionNormal = water.tangentWorldNormal;
|
||||
|
||||
#if _FLAT_SHADING //Use face normals
|
||||
lightReflectionNormal = water.waveNormal;
|
||||
#endif
|
||||
|
||||
half specularMask = saturate((1-water.foam * 2.0) * (1-water.intersection) * water.shadowMask);
|
||||
//return float4(specularMask.xxx, 1.0);
|
||||
|
||||
float3 sunSpecular = SpecularReflection(mainLight, water.viewDir, water.waveNormal, lightReflectionNormal, _SunReflectionDistortion, lerp(8196, 64, _SunReflectionSize), _SunReflectionStrength * specularMask);
|
||||
|
||||
water.specular += sunSpecular;
|
||||
//return float4(water.specular, 1.0);
|
||||
#endif
|
||||
//return float4(specular, 1.0);
|
||||
|
||||
//Reflection probe/planar
|
||||
#ifndef _ENVIRONMENTREFLECTIONS_OFF
|
||||
|
||||
//Blend between smooth surface normal and normal map to control the reflection perturbation (probes only!)
|
||||
#if !_FLAT_SHADING
|
||||
float3 refWorldNormal = lerp(water.waveNormal, normalize(water.waveNormal + water.tangentWorldNormal), _ReflectionDistortion);
|
||||
#else //Skip, not a good fit
|
||||
float3 refWorldNormal = water.waveNormal;
|
||||
#endif
|
||||
|
||||
half3 reflectionViewDir = water.viewDir;
|
||||
|
||||
#if _REFLECTION_PROBE_BOX_PROJECTION
|
||||
//Use the camera's forward vector when the camera is orthographic
|
||||
if(unity_OrthoParams.w == 1) reflectionViewDir = GetWorldSpaceViewDir(positionWS);
|
||||
#endif
|
||||
|
||||
half3 reflectionVector = reflect(-reflectionViewDir, refWorldNormal);
|
||||
|
||||
#if !_RIVER
|
||||
//Ensure only the top hemisphere of the reflection probe is used
|
||||
//reflectionVector.y = max(0, reflectionVector.y);
|
||||
#endif
|
||||
|
||||
//Pixel offset for planar reflection, sampled in screen-space
|
||||
float3 reflectionOffsetVector = lerp(water.vertexNormal, water.tangentWorldNormal, _ReflectionDistortion);
|
||||
|
||||
#if _ADVANCED_SHADING
|
||||
//reflectionOffsetVector = TransformWorldToViewDir(reflectionOffsetVector);
|
||||
//reflectionOffsetVector.xz = reflectionOffsetVector.xy;
|
||||
#endif
|
||||
|
||||
float2 reflectionPixelOffset = (reflectionOffsetVector.xz * scene.positionSS.w * SCREENSPACE_REFLECTION_DISTORTION_MULTIPLIER).xy;
|
||||
|
||||
water.reflections = SampleReflections(reflectionVector, _ReflectionBlur, scene.positionSS.xyzw, positionWS, refWorldNormal, water.viewDir, reflectionPixelOffset, _PlanarReflectionsEnabled);
|
||||
//return float4(water.reflections, 1.0);
|
||||
|
||||
float reflectionFresnel = ReflectionFresnel(refWorldNormal, water.viewDir * faceSign, _ReflectionFresnel);
|
||||
//return float4(reflectionFresnel.xxx, 1.0);
|
||||
|
||||
water.reflectionMask = _ReflectionStrength * reflectionFresnel;
|
||||
water.reflectionLighting = 1-_ReflectionLighting;
|
||||
|
||||
#if _UNLIT
|
||||
//Nullify, otherwise reflections turn black
|
||||
water.reflectionLighting = 1.0;
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* ========
|
||||
// COMPOSITION
|
||||
=========== */
|
||||
#if COLLAPSIBLE_GROUP
|
||||
|
||||
//Foam application on top of everything up to this point
|
||||
#if _FOAM
|
||||
//Mitigate color bleeding into the foam by scaling it
|
||||
water.albedo.rgb = lerp(water.albedo.rgb, _FoamColor.rgb, saturate(water.foam * 2.0));
|
||||
#endif
|
||||
|
||||
#if _SHARP_INERSECTION || _SMOOTH_INTERSECTION
|
||||
//Layer intersection on top of everything
|
||||
water.albedo.rgb = lerp(water.albedo.rgb, _IntersectionColor.rgb, water.intersection);
|
||||
#endif
|
||||
|
||||
#if _FOAM || _SHARP_INERSECTION || _SMOOTH_INTERSECTION
|
||||
//Sum values to compose alpha
|
||||
water.alpha = saturate(water.alpha + water.intersection + water.foam);
|
||||
#endif
|
||||
|
||||
#ifndef _ENVIRONMENTREFLECTIONS_OFF
|
||||
//Foam complete, use it to mask out the reflection (considering that foam is rough)
|
||||
water.reflectionMask = saturate(water.reflectionMask - water.foam - water.intersection) * _ReflectionStrength;
|
||||
//return float4(reflectionFresnel.xxx, 1);
|
||||
|
||||
#if !_UNLIT
|
||||
//Blend reflection with albedo. Diffuse lighting will affect it
|
||||
water.albedo.rgb = lerp(water.albedo, lerp(water.albedo.rgb, water.reflections, water.reflectionMask), _ReflectionLighting);
|
||||
//return float4(water.albedo.rgb, 1);
|
||||
#endif
|
||||
#endif
|
||||
//return float4(water.reflections.rgb, 1);
|
||||
|
||||
#if !_UNLIT
|
||||
//Blend between smooth geometry normal and normal map for diffuse lighting
|
||||
water.diffuseNormal = lerp(water.waveNormal, water.tangentWorldNormal, _NormalStrength);
|
||||
#endif
|
||||
|
||||
#if _FLAT_SHADING
|
||||
//Moving forward, consider the tangent world normal the same as the flat-shaded normals
|
||||
water.tangentWorldNormal = water.waveNormal;
|
||||
#endif
|
||||
|
||||
//Horizon color (note: not using normals, since they are perturbed by waves)
|
||||
float fresnel = saturate(pow(VdotN, _HorizonDistance)) * _HorizonColor.a;
|
||||
#if UNDERWATER_ENABLED
|
||||
fresnel *= water.vFace;
|
||||
#endif
|
||||
water.albedo.rgb = lerp(water.albedo.rgb, _HorizonColor.rgb, fresnel);
|
||||
|
||||
#if UNITY_COLORSPACE_GAMMA
|
||||
//Gamma-space is likely a choice, enabling this will have the water stand out from non gamma-corrected shaders
|
||||
//water.albedo.rgb = LinearToSRGB(water.albedo.rgb);
|
||||
#endif
|
||||
|
||||
//Final alpha
|
||||
water.edgeFade = saturate(scene.verticalDepth / (_EdgeFade * 0.01));
|
||||
|
||||
#if UNDERWATER_ENABLED
|
||||
water.edgeFade = lerp(1.0, water.edgeFade, water.vFace);
|
||||
#endif
|
||||
|
||||
water.alpha *= water.edgeFade;
|
||||
#endif
|
||||
|
||||
/* ========
|
||||
// TRANSLUCENCY
|
||||
=========== */
|
||||
TranslucencyData translucencyData = (TranslucencyData)0;
|
||||
#if _TRANSLUCENCY
|
||||
float scatteringMask = 1.0;
|
||||
scatteringMask = saturate((water.fog + water.edgeFade) - (water.reflectionMask * water.vFace)) * water.shadowMask;
|
||||
scatteringMask -= water.foam;
|
||||
|
||||
scatteringMask = saturate(scatteringMask);
|
||||
|
||||
//return float4(scatteringMask.xxx, 1);
|
||||
|
||||
translucencyData = PopulateTranslucencyData(_ShallowColor.rgb, mainLight.direction, mainLight.color, water.viewDir, water.waveNormal, water.tangentWorldNormal, scatteringMask, _TranslucencyStrength, _TranslucencyStrengthDirect * water.vFace, _TranslucencyExp, _TranslucencyCurvatureMask * water.vFace, true);
|
||||
|
||||
#if UNDERWATER_ENABLED
|
||||
//Override the strength of the effect for the backfaces, to match the underwater shading post effect
|
||||
translucencyData.strength *= lerp(_UnderwaterFogBrightness * _UnderwaterSubsurfaceStrength, 1, water.vFace);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* ========
|
||||
// UNITY SURFACE & INPUT DATA
|
||||
=========== */
|
||||
#if COLLAPSIBLE_GROUP
|
||||
SurfaceData surfaceData = (SurfaceData)0;
|
||||
|
||||
surfaceData.albedo = water.albedo.rgb;
|
||||
surfaceData.specular = water.specular.rgb;
|
||||
surfaceData.metallic = 0;
|
||||
surfaceData.smoothness = 0;
|
||||
surfaceData.normalTS = water.tangentNormal;
|
||||
surfaceData.emission = 0; //To be populated with translucency+caustics
|
||||
surfaceData.occlusion = 1.0;
|
||||
surfaceData.alpha = water.alpha;
|
||||
|
||||
//https://github.com/Unity-Technologies/Graphics/blob/31106afc882d7d1d7e3c0a51835df39c6f5e3073/com.unity.render-pipelines.universal/ShaderLibrary/Input.hlsl#L34
|
||||
InputData inputData = (InputData)0;
|
||||
inputData.positionWS = positionWS;
|
||||
inputData.viewDirectionWS = water.viewDir;
|
||||
inputData.shadowCoord = shadowCoords;
|
||||
#if UNDERWATER_ENABLED
|
||||
//Flatten normals for underwater lighting (distracting, peers through the fog)
|
||||
inputData.normalWS = lerp(water.waveNormal, water.tangentWorldNormal, water.vFace);
|
||||
#else
|
||||
inputData.normalWS = water.tangentWorldNormal;
|
||||
#endif
|
||||
inputData.fogCoord = InitializeInputDataFog(float4(positionWS, 1.0), input.fogFactorAndVertexLight.x);
|
||||
inputData.vertexLighting = input.fogFactorAndVertexLight.yzw;
|
||||
|
||||
inputData.bakedGI = 0;
|
||||
|
||||
#if defined(DYNAMICLIGHTMAP_ON) && UNITY_VERSION >= 202120
|
||||
inputData.bakedGI = SAMPLE_GI(input.staticLightmapUV, input.dynamicLightmapUV.xy, input.vertexSH, inputData.normalWS);
|
||||
#elif !defined(LIGHTMAP_ON) && (defined(PROBE_VOLUMES_L1) || defined(PROBE_VOLUMES_L2))
|
||||
inputData.bakedGI = SAMPLE_GI(input.vertexSH, GetAbsolutePositionWS(inputData.positionWS), inputData.normalWS, inputData.viewDirectionWS, input.positionCS.xy);
|
||||
#else
|
||||
inputData.bakedGI = SAMPLE_GI(input.staticLightmapUV, input.vertexSH, inputData.normalWS);
|
||||
#endif
|
||||
|
||||
#if UNITY_VERSION >= 202020
|
||||
inputData.shadowMask = shadowMask;
|
||||
#endif
|
||||
|
||||
//Lightmap(static+dynamic) or SH
|
||||
//return float4(inputData.bakedGI, 1.0);
|
||||
|
||||
#endif
|
||||
|
||||
//return float4(surfaceData.emission, 1.0);
|
||||
/* ========
|
||||
// RENDERING DEBUGGER (URP 12+)
|
||||
=========== */
|
||||
#if COLLAPSIBLE_GROUP
|
||||
|
||||
#if UNITY_VERSION >= 202120 && defined(DEBUG_DISPLAY)
|
||||
inputData.positionCS = input.positionCS;
|
||||
#if _NORMALMAP
|
||||
inputData.tangentToWorld = water.tangentToWorldMatrix;
|
||||
#else
|
||||
inputData.tangentToWorld = 0;
|
||||
#endif
|
||||
inputData.normalizedScreenSpaceUV = scene.positionSS.xy / scene.positionSS.w;
|
||||
inputData.shadowMask = water.shadowMask.xxxx;
|
||||
#if defined(DYNAMICLIGHTMAP_ON)
|
||||
inputData.dynamicLightmapUV = input.dynamicLightmapUV;
|
||||
#endif
|
||||
#if defined(LIGHTMAP_ON)
|
||||
inputData.staticLightmapUV = input.staticLightmapUV;
|
||||
#else
|
||||
inputData.vertexSH = input.vertexSH;
|
||||
#endif
|
||||
|
||||
surfaceData.emission = water.caustics;
|
||||
ApplyTranslucency(translucencyData, surfaceData.emission.rgb);
|
||||
|
||||
inputData.brdfDiffuse = surfaceData.albedo;
|
||||
inputData.brdfSpecular = surfaceData.specular;
|
||||
inputData.uv = uv;
|
||||
inputData.mipCount = 0;
|
||||
inputData.texelSize = float4(1/uv.x, 1/uv.y, uv.x, uv.y);
|
||||
inputData.mipInfo = 0;
|
||||
half4 debugColor;
|
||||
|
||||
if (_DebugLightingMode == DEBUGLIGHTINGMODE_REFLECTIONS || _DebugLightingMode == DEBUGLIGHTINGMODE_REFLECTIONS_WITH_SMOOTHNESS)
|
||||
{
|
||||
return float4(water.reflections * (_DebugLightingMode == DEBUGLIGHTINGMODE_REFLECTIONS_WITH_SMOOTHNESS ? water.reflectionMask : 1), 1.0);
|
||||
}
|
||||
|
||||
if (CanDebugOverrideOutputColor(inputData, surfaceData, debugColor))
|
||||
{
|
||||
return debugColor;
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
float4 finalColor = float4(ApplyLighting(surfaceData, scene.color, mainLight, inputData, water, translucencyData, _ShadowStrength, water.vFace), water.alpha);
|
||||
|
||||
#if _REFRACTION
|
||||
finalColor.rgb = lerp(scene.color.rgb, finalColor.rgb, saturate(water.fog + water.intersection + water.foam));
|
||||
//The opaque color texture is now used. The "real" alpha value is solely the edge fade factor
|
||||
water.alpha = water.edgeFade;
|
||||
#endif
|
||||
|
||||
half fogMask = 1.0;
|
||||
#if UNDERWATER_ENABLED
|
||||
//Limit to front faces as underwater fog already applies to the bottom
|
||||
fogMask = water.vFace;
|
||||
#endif
|
||||
|
||||
ApplyFog(finalColor.rgb, inputData.fogCoord, scene.positionSS, positionWS, fogMask);
|
||||
|
||||
#if UNDERWATER_ENABLED
|
||||
float3 underwaterColor = ShadeUnderwaterSurface(surfaceData.albedo.rgb, surfaceData.emission.rgb, surfaceData.specular.rgb, scene.color.rgb, scene.skyMask,
|
||||
backfaceShadows, inputData.positionWS, inputData.normalWS, water.tangentWorldNormal, water.viewDir, scene.positionSS.xy,
|
||||
_ShallowColor.rgb, _BaseColor.rgb, water.vFace, _UnderwaterSurfaceSmoothness, _UnderwaterRefractionOffset);
|
||||
|
||||
finalColor.rgb = lerp(underwaterColor, finalColor.rgb, water.vFace);
|
||||
water.alpha = lerp(1.0, water.alpha, water.vFace);
|
||||
#endif
|
||||
|
||||
#ifdef COZY
|
||||
//water.alpha = max(water.alpha, GetStylizedFogDensity(positionWS));
|
||||
#endif
|
||||
|
||||
finalColor.a = water.alpha;
|
||||
|
||||
#if _RIVER
|
||||
//Vertex color green channel controls real alpha in this case (not the color depth gradient)
|
||||
finalColor.a = water.alpha * saturate(water.alpha - vertexColor.g);
|
||||
#endif
|
||||
|
||||
return finalColor;
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 73145541a34a4904fb2181d58d90c0b0
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
124
LocalPackages/StylizedWater2/Shaders/Libraries/Input.hlsl
Normal file
124
LocalPackages/StylizedWater2/Shaders/Libraries/Input.hlsl
Normal file
@@ -0,0 +1,124 @@
|
||||
//Stylized Water 2
|
||||
//Staggart Creations (http://staggart.xyz)
|
||||
//Copyright protected under Unity Asset Store EULA
|
||||
|
||||
TEXTURE2D(_IntersectionNoise);
|
||||
SAMPLER(sampler_IntersectionNoise);
|
||||
TEXTURE2D(_DepthTex);
|
||||
|
||||
|
||||
CBUFFER_START(UnityPerMaterial)
|
||||
float4 _ShallowColor;
|
||||
float4 _BaseColor;
|
||||
half _ColorAbsorption;
|
||||
|
||||
//float _Smoothness;
|
||||
//float _Metallic;
|
||||
|
||||
float4 _IntersectionColor;
|
||||
float _DepthVertical;
|
||||
float _DepthHorizontal;
|
||||
float _DepthExp;
|
||||
float _WorldSpaceUV;
|
||||
float2 _NormalTiling;
|
||||
float _NormalSubTiling;
|
||||
float _NormalSpeed;
|
||||
float _NormalSubSpeed;
|
||||
half _NormalStrength;
|
||||
|
||||
half2 _DistanceNormalsFadeDist;
|
||||
half _DistanceNormalsTiling;
|
||||
|
||||
half _TranslucencyStrength;
|
||||
half _TranslucencyStrengthDirect;
|
||||
half _TranslucencyExp;
|
||||
half _TranslucencyCurvatureMask;
|
||||
half _EdgeFade;
|
||||
float _WaveSpeed;
|
||||
float4 _HorizonColor;
|
||||
half _HorizonDistance;
|
||||
float _SparkleIntensity;
|
||||
half _SparkleSize;
|
||||
half _SunReflectionDistortion;
|
||||
half _SunReflectionSize;
|
||||
float _SunReflectionStrength;
|
||||
float _PointSpotLightReflectionStrength;
|
||||
half _PointSpotLightReflectionSize;
|
||||
half _PointSpotLightReflectionDistortion;
|
||||
float _ReflectionDistortion;
|
||||
float _ReflectionBlur;
|
||||
float _ReflectionFresnel;
|
||||
float _ReflectionStrength;
|
||||
half _ReflectionLighting;
|
||||
half _PlanarReflectionsEnabled;
|
||||
half _ShadowStrength;
|
||||
float2 _Direction;
|
||||
float _Speed;
|
||||
|
||||
half _SlopeStretching;
|
||||
half _SlopeSpeed;
|
||||
half _SlopeAngleThreshold;
|
||||
half _SlopeAngleFalloff;
|
||||
half _SlopeFoam;
|
||||
|
||||
//Foam
|
||||
float4 _FoamColor;
|
||||
float _FoamSpeed;
|
||||
float _FoamSubSpeed;
|
||||
float2 _FoamTiling;
|
||||
float _FoamSubTiling;
|
||||
half _FoamBaseAmount;
|
||||
half _FoamClipping;
|
||||
half _FoamWaveAmount;
|
||||
half _FoamDistortion;
|
||||
|
||||
float _FoamTilingDynamic;
|
||||
float _FoamSubTilingDynamic;
|
||||
float _FoamSpeedDynamic;
|
||||
float _FoamSubSpeedDynamic;
|
||||
|
||||
//Intersection
|
||||
half _IntersectionSource;
|
||||
half _IntersectionLength;
|
||||
half _IntersectionFalloff;
|
||||
half _IntersectionTiling;
|
||||
half _IntersectionRippleDist;
|
||||
half _IntersectionRippleStrength;
|
||||
half _IntersectionClipping;
|
||||
float _IntersectionSpeed;
|
||||
|
||||
//Waves
|
||||
half _WaveHeight;
|
||||
half _WaveNormalStr;
|
||||
float _WaveDistance;
|
||||
half2 _WaveFadeDistance;
|
||||
float _WaveSteepness;
|
||||
uint _WaveCount;
|
||||
half4 _WaveDirection;
|
||||
|
||||
half _ShoreLineWaveStr;
|
||||
half _ShoreLineWaveDistance;
|
||||
half _ShoreLineLength;
|
||||
|
||||
//Underwater
|
||||
half _CausticsBrightness;
|
||||
float _CausticsTiling;
|
||||
half _CausticsSpeed;
|
||||
half _RefractionStrength;
|
||||
half _RefractionChromaticAberration;
|
||||
half _CausticsDistortion;
|
||||
|
||||
half _UnderwaterSurfaceSmoothness;
|
||||
half _UnderwaterRefractionOffset;
|
||||
|
||||
half _VertexColorDepth;
|
||||
half _VertexColorWaveFlattening;
|
||||
half _VertexColorFoam;
|
||||
|
||||
half _WaveTint;
|
||||
#ifdef TESSELLATION_ON
|
||||
float _TessValue;
|
||||
float _TessMin;
|
||||
float _TessMax;
|
||||
#endif
|
||||
CBUFFER_END
|
||||
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 28f313ebadfa00948936ae63724fb92c
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
279
LocalPackages/StylizedWater2/Shaders/Libraries/Lighting.hlsl
Normal file
279
LocalPackages/StylizedWater2/Shaders/Libraries/Lighting.hlsl
Normal file
@@ -0,0 +1,279 @@
|
||||
//Stylized Water 2
|
||||
//Staggart Creations (http://staggart.xyz)
|
||||
//Copyright protected under Unity Asset Store EULA
|
||||
|
||||
#include "Common.hlsl"
|
||||
#include "Reflections.hlsl"
|
||||
|
||||
#if !_UNLIT
|
||||
#define LIT
|
||||
#endif
|
||||
|
||||
#define SPECULAR_POWER_RCP 0.01562 // 1.0/32
|
||||
|
||||
//Reusable for every light
|
||||
struct TranslucencyData
|
||||
{
|
||||
bool directionalLight;
|
||||
float3 subsurfaceColor;
|
||||
float3 lightColor;
|
||||
float3 lightDir;
|
||||
float3 viewDir;
|
||||
float3 normal;
|
||||
float curvature;
|
||||
float mask; //Actually the 'thickness'
|
||||
float strength;
|
||||
float strengthIncident;
|
||||
float exponent;
|
||||
|
||||
};
|
||||
|
||||
TranslucencyData PopulateTranslucencyData(float3 subsurfaceColor, float3 lightDir, float3 lightColor, float3 viewDir, float3 WorldNormal, float3 worldTangentNormal, float mask, float strength, float incidentStrength, float exponent, float offset, bool directionalLight)
|
||||
{
|
||||
TranslucencyData d = (TranslucencyData)0;
|
||||
d.directionalLight = directionalLight;
|
||||
d.subsurfaceColor = subsurfaceColor;
|
||||
d.lightColor = lightColor;
|
||||
d.lightDir = lightDir;
|
||||
|
||||
#if _ADVANCED_SHADING
|
||||
//Slightly include high frequency details
|
||||
d.normal = normalize(WorldNormal + (worldTangentNormal * 0.1));
|
||||
#else
|
||||
d.normal = WorldNormal;
|
||||
#endif
|
||||
d.curvature = offset;
|
||||
d.mask = mask; //Shadows, foam, intersection, etc
|
||||
d.strength = strength;
|
||||
d.strengthIncident = incidentStrength;
|
||||
d.viewDir = viewDir;
|
||||
d.exponent = exponent;
|
||||
|
||||
return d;
|
||||
}
|
||||
|
||||
//Backwards compatibility for <v1.5.2
|
||||
TranslucencyData PopulateTranslucencyData(float3 subsurfaceColor, float3 lightDir, float3 lightColor, float3 viewDir, float3 WorldNormal, float3 worldTangentNormal, float mask, float strength, float exponent, float offset)
|
||||
{
|
||||
return PopulateTranslucencyData(subsurfaceColor, lightDir, lightColor, viewDir, WorldNormal, worldTangentNormal, mask, strength, 0.0, exponent, offset, true);
|
||||
}
|
||||
|
||||
//Single channel overlay
|
||||
float BlendOverlay(float a, float b)
|
||||
{
|
||||
return (b < 0.5) ? 2.0 * a * b : 1.0 - 2.0 * (1.0 - a) * (1.0 - b);
|
||||
}
|
||||
|
||||
//RGB overlay
|
||||
float3 BlendOverlay(float3 a, float3 b)
|
||||
{
|
||||
return float3(BlendOverlay(a.r, b.r), BlendOverlay(a.g, b.g), BlendOverlay(a.b, b.b));
|
||||
}
|
||||
|
||||
//In URP light intensity is pre-multiplied with the HDR color, extract via magnitude of color "vector"
|
||||
float GetLightIntensity(float3 lightColor)
|
||||
{
|
||||
//Luminance equals HDR output
|
||||
return (lightColor.r * 0.3 + lightColor.g * 0.59 + lightColor.b * 0.11);
|
||||
}
|
||||
|
||||
float GetLightIntensity(Light light) { return GetLightIntensity(light.color); }
|
||||
|
||||
void ApplyTranslucency(float3 subsurfaceColor, float3 lightDir, float3 lightColor, float3 viewDir, float3 normal, float occlusion, float strength, float incidentStrength, float exponent, float offset, bool directionalLight, inout float3 emission)
|
||||
{
|
||||
//Coefficient describing how much the surface orientation is between the camera and the direction of/to the light
|
||||
half transmittance = saturate(dot(-viewDir, lightDir));
|
||||
//Exponentiate to tighten the falloff
|
||||
transmittance = saturate(pow(transmittance, exponent)) * strength;
|
||||
|
||||
half incident = 0;
|
||||
if(directionalLight)
|
||||
{
|
||||
incident = saturate(dot(lightDir, normal)) * incidentStrength;
|
||||
}
|
||||
|
||||
//Mask by normals facing away from the light (backfaces, in light-space)
|
||||
const half curvature = saturate(lerp(1.0, dot(normal, -lightDir), offset));
|
||||
transmittance *= curvature;
|
||||
|
||||
const float lightIntensity = GetLightIntensity(lightColor);
|
||||
|
||||
half attenuation = (transmittance + incident) * occlusion * lightIntensity;
|
||||
|
||||
#if _ADVANCED_SHADING
|
||||
if(directionalLight)
|
||||
{
|
||||
//Fade the effect out as the sun approaches the horizon (80 to 90 degrees)
|
||||
half sunAngle = saturate(dot(float3(0, 1, 0), lightDir));
|
||||
half angleMask = saturate(sunAngle * 10); /* 1.0/0.10 = 10 */
|
||||
attenuation *= angleMask;
|
||||
}
|
||||
|
||||
//Modulate with light color to better match dynamic lighting conditions
|
||||
subsurfaceColor = BlendOverlay(saturate(lightColor), subsurfaceColor);
|
||||
|
||||
emission += subsurfaceColor * attenuation;
|
||||
#else //Simple shading
|
||||
emission += lerp(emission, subsurfaceColor, attenuation);
|
||||
#endif
|
||||
}
|
||||
|
||||
void ApplyTranslucency(TranslucencyData translucencyData, inout float3 emission)
|
||||
{
|
||||
ApplyTranslucency(translucencyData.subsurfaceColor, translucencyData.lightDir, translucencyData.lightColor, translucencyData.viewDir, translucencyData.normal, translucencyData.mask, translucencyData.strength, translucencyData.strengthIncident, translucencyData.exponent, translucencyData.curvature, translucencyData.directionalLight, emission);
|
||||
}
|
||||
|
||||
void AdjustShadowStrength(inout Light light, float strength, float vFace)
|
||||
{
|
||||
light.shadowAttenuation = saturate(light.shadowAttenuation + (1.0 - (strength * vFace)));
|
||||
}
|
||||
|
||||
//Specular Blinn-phong reflection in world-space
|
||||
float3 SpecularReflection(Light light, float3 viewDirectionWS, float3 geometryNormalWS, float3 normalWS, float perturbation, float exponent, float intensity)
|
||||
{
|
||||
//Blend between geometry/wave normals and normals from normal map (aka distortion)
|
||||
normalWS = lerp(geometryNormalWS, normalWS, perturbation);
|
||||
|
||||
const float3 halfVec = normalize(light.direction + viewDirectionWS + (normalWS * perturbation));
|
||||
half NdotH = saturate(dot(geometryNormalWS, halfVec));
|
||||
|
||||
float specular = pow(NdotH, exponent);
|
||||
|
||||
//Attenuation includes shadows, if available
|
||||
const float3 attenuatedLightColor = light.color * (light.distanceAttenuation * light.shadowAttenuation);
|
||||
|
||||
//Mask reflection by surfaces "visible" by the light only
|
||||
float viewFactor = saturate(dot(geometryNormalWS, light.direction));
|
||||
|
||||
#if _ADVANCED_SHADING
|
||||
//Create a linear gradient a little before the cutoff point, in order to maintain HDR values properly
|
||||
viewFactor = smoothstep(0.0, 0.15, viewFactor);
|
||||
#endif
|
||||
|
||||
float3 specColor = attenuatedLightColor * specular * intensity * viewFactor;
|
||||
|
||||
#if UNITY_COLORSPACE_GAMMA
|
||||
specColor = LinearToSRGB(specColor);
|
||||
#endif
|
||||
|
||||
return specColor;
|
||||
}
|
||||
|
||||
//Based on UniversalFragmentBlinnPhong (no BRDF)
|
||||
float3 ApplyLighting(inout SurfaceData surfaceData, inout float3 sceneColor, Light mainLight, InputData inputData, WaterSurface water, TranslucencyData translucencyData, float shadowStrength, float vFace)
|
||||
{
|
||||
ApplyTranslucency(translucencyData, surfaceData.emission.rgb);
|
||||
|
||||
#if _CAUSTICS
|
||||
float causticsAttentuation = 1.0;
|
||||
#endif
|
||||
|
||||
#ifdef LIT
|
||||
#if _CAUSTICS && !defined(LIGHTMAP_ON)
|
||||
causticsAttentuation = GetLightIntensity(mainLight) * (mainLight.distanceAttenuation * mainLight.shadowAttenuation);
|
||||
#endif
|
||||
|
||||
//Allow shadow strength to be overridden.
|
||||
AdjustShadowStrength(mainLight, shadowStrength, vFace);
|
||||
|
||||
half3 attenuatedLightColor = mainLight.color * (mainLight.distanceAttenuation * mainLight.shadowAttenuation);
|
||||
|
||||
MixRealtimeAndBakedGI(mainLight, water.diffuseNormal, inputData.bakedGI, shadowStrength.xxxx);
|
||||
|
||||
/*
|
||||
//PBR shading
|
||||
BRDFData brdfData;
|
||||
InitializeBRDFData(surfaceData.albedo, surfaceData.metallic, surfaceData.specular, surfaceData.smoothness, surfaceData.alpha, brdfData);
|
||||
|
||||
half3 diffuseColor = GlobalIllumination(brdfData, inputData.bakedGI, shadowStrength, inputData.water.diffuseNormal, inputData.viewDirectionWS);
|
||||
diffuseColor += LightingPhysicallyBased(brdfData, mainLight, water.diffuseNormal, inputData.viewDirectionWS);
|
||||
*/
|
||||
|
||||
half3 diffuseColor = inputData.bakedGI + LightingLambert(attenuatedLightColor, mainLight.direction, water.diffuseNormal);
|
||||
|
||||
#if _ADDITIONAL_LIGHTS //Per pixel lights
|
||||
#ifndef _SPECULARHIGHLIGHTS_OFF
|
||||
half specularPower = (_PointSpotLightReflectionSize * SPECULAR_POWER_RCP);
|
||||
specularPower = lerp(8.0, 1.0, _PointSpotLightReflectionSize) * _PointSpotLightReflectionStrength;
|
||||
#endif
|
||||
|
||||
uint pixelLightCount = GetAdditionalLightsCount();
|
||||
#if _LIGHT_LAYERS && UNITY_VERSION >= 202220
|
||||
uint meshRenderingLayers = GetMeshRenderingLayer();
|
||||
#endif
|
||||
|
||||
LIGHT_LOOP_BEGIN(pixelLightCount)
|
||||
#if UNITY_VERSION >= 202110 //URP 11+
|
||||
Light light = GetAdditionalLight(lightIndex, inputData.positionWS, shadowStrength.xxxx);
|
||||
#else
|
||||
Light light = GetAdditionalLight(lightIndex, inputData.positionWS);
|
||||
#endif
|
||||
|
||||
#if _LIGHT_LAYERS && UNITY_VERSION >= 202220
|
||||
if (IsMatchingLightLayer(light.layerMask, meshRenderingLayers))
|
||||
#endif
|
||||
{
|
||||
#if _ADVANCED_SHADING
|
||||
#if _CAUSTICS && !_LIGHT_COOKIES //Actually want to skip this when using cookies. Since they can be used for caustics instead
|
||||
//Light attenuation adds caustics, mask by shadows
|
||||
causticsAttentuation += GetLightIntensity(light) * (light.distanceAttenuation * light.shadowAttenuation) * _PointSpotLightReflectionStrength * (1-water.fog);
|
||||
#endif
|
||||
|
||||
#if _TRANSLUCENCY
|
||||
//Keep settings from main light pass, override these
|
||||
translucencyData.directionalLight = false;
|
||||
translucencyData.lightDir = light.direction;
|
||||
translucencyData.lightColor = light.color * light.distanceAttenuation;
|
||||
translucencyData.strength *= light.shadowAttenuation;
|
||||
translucencyData.exponent *= light.distanceAttenuation;
|
||||
|
||||
ApplyTranslucency(translucencyData, surfaceData.emission.rgb);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if UNITY_VERSION >= 202110 && _ADDITIONAL_LIGHT_SHADOWS //URP 11+
|
||||
AdjustShadowStrength(light, shadowStrength, vFace);
|
||||
#endif
|
||||
|
||||
half3 attenuatedLightColor = light.color * (light.distanceAttenuation * light.shadowAttenuation);
|
||||
diffuseColor += LightingLambert(attenuatedLightColor, light.direction, water.diffuseNormal);
|
||||
|
||||
#ifndef _SPECULARHIGHLIGHTS_OFF
|
||||
//Note: View direction fetched again using the function that takes orthographic projection into account
|
||||
surfaceData.specular += SpecularReflection(light, normalize(GetWorldSpaceViewDir(inputData.positionWS)), water.waveNormal, water.tangentWorldNormal, _PointSpotLightReflectionDistortion, lerp(4096, 64, _PointSpotLightReflectionSize), specularPower);
|
||||
#endif
|
||||
}
|
||||
LIGHT_LOOP_END
|
||||
#endif
|
||||
|
||||
#ifdef _ADDITIONAL_LIGHTS_VERTEX //Previous calculated in vertex stage
|
||||
diffuseColor += inputData.vertexLighting;
|
||||
#endif
|
||||
|
||||
#else //Unlit
|
||||
const half3 diffuseColor = 1;
|
||||
#endif
|
||||
|
||||
#if _CAUSTICS
|
||||
surfaceData.emission.rgb += water.caustics * causticsAttentuation;
|
||||
#endif
|
||||
|
||||
float3 color = (surfaceData.albedo.rgb * diffuseColor) + surfaceData.emission.rgb + surfaceData.specular;
|
||||
|
||||
#ifndef _ENVIRONMENTREFLECTIONS_OFF
|
||||
//Reflections blend in on top of everything
|
||||
color = lerp(color, water.reflections.rgb, water.reflectionMask * water.reflectionLighting);
|
||||
sceneColor = lerp(sceneColor, water.reflections.rgb, water.reflectionMask * water.reflectionLighting);
|
||||
#endif
|
||||
|
||||
#if _REFRACTION
|
||||
//Ensure the same effects are applied to the underwater scene color. Otherwise not visible on clear water
|
||||
sceneColor += surfaceData.emission.rgb + surfaceData.specular;
|
||||
#endif
|
||||
|
||||
//Debug
|
||||
//return float4(surfaceData.emission.rgb, 1.0);
|
||||
|
||||
|
||||
return color;
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b00528185b78b1847970f677dd2f6b64
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
142
LocalPackages/StylizedWater2/Shaders/Libraries/Reflections.hlsl
Normal file
142
LocalPackages/StylizedWater2/Shaders/Libraries/Reflections.hlsl
Normal file
@@ -0,0 +1,142 @@
|
||||
#ifndef WATER_REFLECTIONS_INCLUDED
|
||||
#define WATER_REFLECTIONS_INCLUDED
|
||||
|
||||
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
|
||||
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"
|
||||
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareDepthTexture.hlsl"
|
||||
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareOpaqueTexture.hlsl"
|
||||
|
||||
#define AIR_RI 1.000293
|
||||
|
||||
//Schlick's BRDF fresnel
|
||||
float ReflectionFresnel(float3 worldNormal, float3 viewDir, float exponent)
|
||||
{
|
||||
float cosTheta = saturate(dot(worldNormal, viewDir));
|
||||
return pow(max(0.0, AIR_RI - cosTheta), exponent);
|
||||
}
|
||||
|
||||
float AttenuateSSR(float2 uv)
|
||||
{
|
||||
float offset = min(1.0 - max(uv.x, uv.y), min(uv.x, uv.y));
|
||||
|
||||
float result = offset / (0.1);
|
||||
result = saturate(result);
|
||||
|
||||
return pow(result, 0.5);
|
||||
}
|
||||
|
||||
void RaymarchSSR(float3 origin, float3 direction, uint samples, half stepSize, half thickness, out half2 sampleUV, out half valid, out half outOfBounds)
|
||||
{
|
||||
sampleUV = 0;
|
||||
valid = 0;
|
||||
outOfBounds = 0;
|
||||
|
||||
direction *= stepSize;
|
||||
const half rcpStepCount = rcp(samples);
|
||||
|
||||
UNITY_LOOP
|
||||
for(uint i = 0; i <= samples; i++)
|
||||
{
|
||||
origin += direction;
|
||||
direction *= 1+stepSize;
|
||||
|
||||
//View-space to screen-space UV
|
||||
sampleUV = ComputeNormalizedDeviceCoordinates(origin, GetViewToHClipMatrix());
|
||||
|
||||
if (any(sampleUV.xy < 0) || any(sampleUV.xy > 1))
|
||||
{
|
||||
outOfBounds = 1;
|
||||
valid = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
outOfBounds = AttenuateSSR(sampleUV);
|
||||
|
||||
//Sample Mip0, gradient sampling cannot work with loops
|
||||
float deviceDepth = SAMPLE_TEXTURE2D_X_LOD(_CameraDepthTexture, sampler_CameraDepthTexture, sampleUV, 0).r;
|
||||
|
||||
//Calculate view-space position from UV and depth
|
||||
//Not using the ComputeViewSpacePosition function, since this negates the Z-component
|
||||
float3 samplePos = ComputeWorldSpacePosition(sampleUV, deviceDepth, UNITY_MATRIX_I_P);
|
||||
|
||||
if(distance(samplePos.z, origin.z) > length(direction) * thickness) continue;
|
||||
|
||||
if(samplePos.z > origin.z)
|
||||
{
|
||||
valid = 1;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TEXTURE2D_X(_PlanarReflection);
|
||||
SAMPLER(sampler_PlanarReflection);
|
||||
|
||||
float3 SampleReflectionProbes(float3 reflectionVector, float3 positionWS, float smoothness, float2 screenPos)
|
||||
{
|
||||
float3 probes = float3(0,0,0);
|
||||
|
||||
#if UNITY_VERSION >= 202220
|
||||
probes = GlossyEnvironmentReflection(reflectionVector, positionWS, smoothness, 1.0, screenPos.xy).rgb;
|
||||
#elif UNITY_VERSION >= 202120
|
||||
probes = GlossyEnvironmentReflection(reflectionVector, positionWS, smoothness, 1.0).rgb;
|
||||
#else
|
||||
probes = GlossyEnvironmentReflection(reflectionVector, smoothness, 1.0).rgb;
|
||||
#endif
|
||||
|
||||
return probes;
|
||||
}
|
||||
|
||||
bool _WaterSSREnabled;
|
||||
float4 _WaterSSRParams;
|
||||
//X: Steps
|
||||
//Y: Step size
|
||||
//Z: Thickness
|
||||
|
||||
#define SSR_SAMPLES 12
|
||||
#define SSR_STEPSIZE 0.5
|
||||
#define SSR_MAX_DISTANCE 100
|
||||
#define SSR_THICKNESS 1.0
|
||||
|
||||
float3 SampleReflections(float3 reflectionVector, float smoothness, float4 screenPos, float3 positionWS, float3 normalWS, float3 viewDir, float2 pixelOffset, bool planarReflectionsEnabled)
|
||||
{
|
||||
#if !_RIVER || UNITY_VERSION >= 202220
|
||||
screenPos.xy += pixelOffset.xy * lerp(1.0, 0.1, unity_OrthoParams.w);
|
||||
screenPos /= screenPos.w;
|
||||
#endif
|
||||
|
||||
const float3 probes = SampleReflectionProbes(reflectionVector, positionWS, smoothness, screenPos.xy);
|
||||
|
||||
float3 reflections = probes;
|
||||
|
||||
#if !_DISABLE_DEPTH_TEX
|
||||
if(_WaterSSREnabled)
|
||||
{
|
||||
const float3 positionVS = TransformWorldToView(positionWS);
|
||||
const float3 direction = TransformWorldToViewDir(reflectionVector);
|
||||
|
||||
float2 ssrUV = 0;
|
||||
half ssrRayMask, ssrEdgeMask = 0;
|
||||
|
||||
RaymarchSSR(positionVS, direction, SSR_SAMPLES, SSR_STEPSIZE, SSR_THICKNESS, ssrUV, ssrRayMask, ssrEdgeMask);
|
||||
|
||||
const float3 reflectionSS = SampleSceneColor(ssrUV);
|
||||
|
||||
reflections = lerp(reflections, reflectionSS, ssrRayMask * ssrEdgeMask);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if !_RIVER //Planar reflections are pointless on curved surfaces, skip
|
||||
if(planarReflectionsEnabled)
|
||||
{
|
||||
float4 planarReflections = SAMPLE_TEXTURE2D_X_LOD(_PlanarReflection, sampler_PlanarReflection, screenPos.xy, 0);
|
||||
//Terrain add-pass can output negative alpha values. Clamp as a safeguard against this
|
||||
planarReflections.a = saturate(planarReflections.a);
|
||||
|
||||
reflections = lerp(reflections, planarReflections.rgb, planarReflections.a);
|
||||
}
|
||||
#endif
|
||||
|
||||
return reflections;
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 514aea7da9c74dce94cd9b7e39204796
|
||||
timeCreated: 1701010589
|
||||
176
LocalPackages/StylizedWater2/Shaders/Libraries/Tesselation.hlsl
Normal file
176
LocalPackages/StylizedWater2/Shaders/Libraries/Tesselation.hlsl
Normal file
@@ -0,0 +1,176 @@
|
||||
//Stylized Water 2
|
||||
//Staggart Creations (http://staggart.xyz)
|
||||
//Copyright protected under Unity Asset Store EULA
|
||||
|
||||
#if defined(SHADER_API_XBOXONE) || defined(SHADER_API_PSSL)
|
||||
// AMD recommends this value for GCN http://amd-dev.wpengine.netdna-cdn.com/wordpress/media/2013/05/GCNPerformanceTweets.pdf
|
||||
#define MAX_TESSELLATION_FACTORS 15.0
|
||||
#else
|
||||
#define MAX_TESSELLATION_FACTORS 64.0
|
||||
#endif
|
||||
|
||||
#if defined(SHADER_API_GLES2)
|
||||
#warning Current graphics API does not support tessellation, falling back to non-tessellated shader automatically.
|
||||
#else
|
||||
#define UNITY_CAN_COMPILE_TESSELLATION
|
||||
#endif
|
||||
|
||||
struct TessellationFactors
|
||||
{
|
||||
float edge[3] : SV_TessFactor;
|
||||
float inside : SV_InsideTessFactor;
|
||||
};
|
||||
|
||||
struct VertexControl
|
||||
{
|
||||
float4 positionOS : INTERNALTESSPOS;
|
||||
float4 normalOS : NORMAL;
|
||||
float4 tangentOS : TANGENT;
|
||||
float4 uv : TEXCOORD0;
|
||||
float4 color : COLOR;
|
||||
|
||||
#ifdef LIGHTMAP_ON
|
||||
float2 staticLightmapUV : TEXCOORD1;
|
||||
#endif
|
||||
#ifdef DYNAMICLIGHTMAP_ON
|
||||
float2 dynamicLightmapUV : TEXCOORD2;
|
||||
#endif
|
||||
|
||||
UNITY_VERTEX_INPUT_INSTANCE_ID
|
||||
};
|
||||
|
||||
VertexControl VertexTessellation(Attributes input)
|
||||
{
|
||||
VertexControl output;
|
||||
UNITY_SETUP_INSTANCE_ID(input);
|
||||
UNITY_TRANSFER_INSTANCE_ID(input, output);
|
||||
|
||||
output.positionOS = input.positionOS;
|
||||
output.normalOS = input.normalOS;
|
||||
output.tangentOS = input.tangentOS;
|
||||
output.uv.xy = input.uv.xy;
|
||||
output.uv.z = _TimeParameters.x;
|
||||
output.uv.w = 0;
|
||||
output.color = input.color;
|
||||
|
||||
#ifdef LIGHTMAP_ON
|
||||
output.staticLightmapUV = input.staticLightmapUV.xy * unity_LightmapST.xy + unity_LightmapST.zw;
|
||||
#endif
|
||||
#ifdef DYNAMICLIGHTMAP_ON
|
||||
output.dynamicLightmapUV = input.dynamicLightmapUV.xy * unity_DynamicLightmapST.xy + unity_DynamicLightmapST.zw;
|
||||
#endif
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
float CalcDistanceTessFactor(float4 positionOS, float minDist, float maxDist, float tess)
|
||||
{
|
||||
float3 positionWS = TransformObjectToWorld(positionOS.xyz).xyz;
|
||||
float dist = distance(positionWS, GetCurrentViewPosition());
|
||||
|
||||
float f = (1.0-saturate((dist - minDist) / (maxDist - minDist)) + 0.001) * tess;
|
||||
|
||||
#if DYNAMIC_EFFECTS_ENABLED
|
||||
//Doesn't seem to work somehow
|
||||
//f += SampleDynamicEffectsDisplacement(positionWS.xyz) * tess;
|
||||
#endif
|
||||
|
||||
return f;
|
||||
}
|
||||
|
||||
float4 CalcTriEdgeTessFactors (float3 triVertexFactors)
|
||||
{
|
||||
float4 tess;
|
||||
tess.x = 0.5 * (triVertexFactors.y + triVertexFactors.z);
|
||||
tess.y = 0.5 * (triVertexFactors.x + triVertexFactors.z);
|
||||
tess.z = 0.5 * (triVertexFactors.x + triVertexFactors.y);
|
||||
tess.w = (triVertexFactors.x + triVertexFactors.y + triVertexFactors.z) / 3.0f;
|
||||
return tess;
|
||||
}
|
||||
|
||||
float4 DistanceBasedTess(float4 v0, float4 v1, float4 v2, float tess, float minDist, float maxDist)
|
||||
{
|
||||
float3 f;
|
||||
f.x = CalcDistanceTessFactor(v0, minDist, maxDist, tess);
|
||||
f.y = CalcDistanceTessFactor(v1, minDist, maxDist, tess);
|
||||
f.z = CalcDistanceTessFactor(v2, minDist, maxDist, tess);
|
||||
|
||||
//Don't use the Core RP version, creates cracks on edges
|
||||
return CalcTriEdgeTessFactors(f);
|
||||
}
|
||||
|
||||
TessellationFactors HullConstant(InputPatch<VertexControl, 3> patch)
|
||||
{
|
||||
TessellationFactors output;
|
||||
|
||||
float4 tf = DistanceBasedTess(patch[0].positionOS, patch[1].positionOS, patch[2].positionOS, _TessValue, _TessMin, _TessMax);
|
||||
|
||||
UNITY_SETUP_INSTANCE_ID(patch[0]);
|
||||
|
||||
output.edge[0] = tf.x;
|
||||
output.edge[1] = tf.y;
|
||||
output.edge[2] = tf.z;
|
||||
output.inside = tf.w;
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
[maxtessfactor(MAX_TESSELLATION_FACTORS)]
|
||||
[domain("tri")]
|
||||
[partitioning("fractional_odd")]
|
||||
[outputtopology("triangle_cw")]
|
||||
[patchconstantfunc("HullConstant")]
|
||||
[outputcontrolpoints(3)]
|
||||
VertexControl Hull(InputPatch<VertexControl, 3> input, uint id : SV_OutputControlPointID)
|
||||
{
|
||||
return input[id];
|
||||
}
|
||||
|
||||
#define TESSELLATION_INTERPOLATE_BARY_URP(name, bary) output.name = input[0].name * bary.x + input[1].name * bary.y + input[2].name * bary.z
|
||||
|
||||
[domain("tri")]
|
||||
Varyings Domain(TessellationFactors factors, OutputPatch<VertexControl, 3> input, float3 baryCoords : SV_DomainLocation)
|
||||
{
|
||||
Attributes output = (Attributes)0;
|
||||
|
||||
TESSELLATION_INTERPOLATE_BARY_URP(positionOS, baryCoords);
|
||||
TESSELLATION_INTERPOLATE_BARY_URP(uv, baryCoords);
|
||||
TESSELLATION_INTERPOLATE_BARY_URP(normalOS, baryCoords);
|
||||
TESSELLATION_INTERPOLATE_BARY_URP(tangentOS, baryCoords);
|
||||
TESSELLATION_INTERPOLATE_BARY_URP(color, baryCoords);
|
||||
|
||||
#if defined(LIGHTMAP_ON)
|
||||
TESSELLATION_INTERPOLATE_BARY_URP(staticLightmapUV, baryCoords);
|
||||
#endif
|
||||
#if defined(DYNAMICLIGHTMAP_ON)
|
||||
TESSELLATION_INTERPOLATE_BARY_URP(dynamicLightmapUV, baryCoords);
|
||||
#endif
|
||||
|
||||
//Tessellation does not work entirely correct with GPU instancing
|
||||
UNITY_TRANSFER_INSTANCE_ID(input[0], output);
|
||||
|
||||
#if !defined(SHADERPASS_DISPLACEMENT) //Displacement will be calculated per pixel
|
||||
#if _WAVES && defined(TESSELLATION_ON)
|
||||
//Required to repeat these
|
||||
VertexNormalInputs normalInput = GetVertexNormalInputs(output.normalOS.xyz, output.tangentOS);
|
||||
float3 positionWS = TransformObjectToWorld(output.positionOS.xyz);
|
||||
float4 vertexColor = GetVertexColor(output.color.rgba, float4(_IntersectionSource > 0 ? 1 : 0, _VertexColorDepth, _VertexColorWaveFlattening, _VertexColorFoam));
|
||||
|
||||
//Returns mesh or world-space UV
|
||||
float2 uv = GetSourceUV(output.uv.xy, positionWS.xz, _WorldSpaceUV);
|
||||
|
||||
//Vertex animation
|
||||
WaveInfo waves = GetWaveInfo(uv, TIME_VERTEX * _WaveSpeed, _WaveHeight, lerp(1, 0, vertexColor.b), _WaveFadeDistance.x, _WaveFadeDistance.y);
|
||||
|
||||
//Offset in direction of normals (only when using mesh uv)
|
||||
if(_WorldSpaceUV == 0) waves.position *= normalInput.normalWS.xyz;
|
||||
|
||||
positionWS += waves.position;
|
||||
|
||||
output.positionOS.xyz = TransformWorldToObject(positionWS);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
//Wave animation is skipped here
|
||||
return LitPassVertex(output);
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 83f5ec8d7ddc76f48aa74737ebb32082
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
87
LocalPackages/StylizedWater2/Shaders/Libraries/URP.hlsl
Normal file
87
LocalPackages/StylizedWater2/Shaders/Libraries/URP.hlsl
Normal file
@@ -0,0 +1,87 @@
|
||||
//Stylized Water 2
|
||||
//Staggart Creations (http://staggart.xyz)
|
||||
//Copyright protected under Unity Asset Store EULA
|
||||
|
||||
#ifndef PIPELINE_INCLUDED
|
||||
#define PIPELINE_INCLUDED
|
||||
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
|
||||
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"
|
||||
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/ShaderVariablesFunctions.hlsl"
|
||||
|
||||
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Color.hlsl"
|
||||
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/UnityInstancing.hlsl"
|
||||
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/SurfaceInput.hlsl"
|
||||
|
||||
#ifdef POST_PROCESSING //These would have the core blit library included
|
||||
#define UNITY_CORE_SAMPLERS_INCLUDED
|
||||
#endif
|
||||
|
||||
#ifndef UNITY_CORE_SAMPLERS_INCLUDED //Backwards compatibility for <2023.1+
|
||||
#define UNITY_CORE_SAMPLERS_INCLUDED
|
||||
|
||||
SamplerState sampler_LinearClamp;
|
||||
SamplerState sampler_PointClamp;
|
||||
SamplerState sampler_PointRepeat;
|
||||
SamplerState sampler_LinearRepeat;
|
||||
#endif
|
||||
|
||||
#ifndef _DISABLE_DEPTH_TEX
|
||||
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareDepthTexture.hlsl"
|
||||
#endif
|
||||
|
||||
#if _REFRACTION || UNDERWATER_ENABLED
|
||||
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareOpaqueTexture.hlsl"
|
||||
#endif
|
||||
|
||||
#if UNITY_VERSION < 202120 //Unity 2021.2 (URP 12)
|
||||
real InitializeInputDataFog(float4 positionWS, real vertFogFactor)
|
||||
{
|
||||
#if defined(SHADER_STAGE_FRAGMENT)
|
||||
//Older versions calculate the fog factor on a per-vertex basis
|
||||
return vertFogFactor;
|
||||
#else
|
||||
return ComputeFogFactor(vertFogFactor);
|
||||
#endif
|
||||
}
|
||||
|
||||
//Otherwise declared in ShaderVariablesFunctions.hlsl
|
||||
float LinearDepthToEyeDepth(float rawDepth)
|
||||
{
|
||||
#if UNITY_REVERSED_Z
|
||||
return _ProjectionParams.z - (_ProjectionParams.z - _ProjectionParams.y) * rawDepth;
|
||||
#else
|
||||
return _ProjectionParams.y + (_ProjectionParams.z - _ProjectionParams.y) * rawDepth;
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
// Deprecated in URP 11+ https://github.com/Unity-Technologies/Graphics/pull/2529. Keep function for backwards compatibility
|
||||
// Compute Normalized Device Coordinate here (this is normally done in GetVertexPositionInputs, but clip and world-space coords are done manually already)
|
||||
#if UNITY_VERSION >= 202110 && !defined(UNITY_SHADER_VARIABLES_FUNCTIONS_DEPRECATED_INCLUDED)
|
||||
float4 ComputeScreenPos(float4 positionCS)
|
||||
{
|
||||
return ComputeNormalizedDeviceCoordinates(positionCS);
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if UNITY_VERSION <= 202010 //Unity 2019 (URP v7+8)
|
||||
//Not available in older versions
|
||||
float3 GetCurrentViewPosition()
|
||||
{
|
||||
return _WorldSpaceCameraPos.xyz;
|
||||
}
|
||||
|
||||
float3 GetWorldSpaceViewDir(float3 positionWS)
|
||||
{
|
||||
return normalize(GetCurrentViewPosition() - positionWS);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if UNITY_VERSION <= 202110
|
||||
#define LIGHT_LOOP_BEGIN(lightCount) \
|
||||
for (uint lightIndex = 0; lightIndex < pixelLightCount; ++lightIndex) { \
|
||||
if (lightIndex >= (uint)lightCount) break;
|
||||
|
||||
#define LIGHT_LOOP_END }
|
||||
#endif
|
||||
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ef61e0415f55fd54b8d11ca946597330
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
156
LocalPackages/StylizedWater2/Shaders/Libraries/Vertex.hlsl
Normal file
156
LocalPackages/StylizedWater2/Shaders/Libraries/Vertex.hlsl
Normal file
@@ -0,0 +1,156 @@
|
||||
//Stylized Water 2
|
||||
//Staggart Creations (http://staggart.xyz)
|
||||
//Copyright protected under Unity Asset Store EULA
|
||||
|
||||
struct Attributes
|
||||
{
|
||||
float4 positionOS : POSITION;
|
||||
float4 uv : TEXCOORD0;
|
||||
float4 normalOS : NORMAL;
|
||||
float4 tangentOS : TANGENT;
|
||||
float4 color : COLOR0;
|
||||
float2 staticLightmapUV : TEXCOORD1;
|
||||
float2 dynamicLightmapUV : TEXCOORD2;
|
||||
UNITY_VERTEX_INPUT_INSTANCE_ID
|
||||
};
|
||||
|
||||
struct Varyings
|
||||
{
|
||||
float4 uv : TEXCOORD0;
|
||||
|
||||
half4 fogFactorAndVertexLight : TEXCOORD1; // x: fogFactor, yzw: vertex light
|
||||
|
||||
#if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR) //No shadow cascades
|
||||
float4 shadowCoord : TEXCOORD2;
|
||||
#endif
|
||||
|
||||
//wPos.x in w-component
|
||||
float4 normalWS : NORMAL;
|
||||
#if _NORMALMAP
|
||||
//wPos.y in w-component
|
||||
float4 tangent : TANGENT;
|
||||
//wPos.z in w-component
|
||||
float4 bitangent : TEXCOORD4;
|
||||
#else
|
||||
float3 positionWS : TEXCOORD4;
|
||||
#endif
|
||||
|
||||
float4 screenPos : TEXCOORD5;
|
||||
|
||||
DECLARE_LIGHTMAP_OR_SH(staticLightmapUV, vertexSH, 8);
|
||||
#ifdef DYNAMICLIGHTMAP_ON
|
||||
float2 dynamicLightmapUV : TEXCOORD9; // Dynamic lightmap UVs
|
||||
#endif
|
||||
|
||||
float4 positionCS : SV_POSITION;
|
||||
float4 color : COLOR0;
|
||||
|
||||
UNITY_VERTEX_INPUT_INSTANCE_ID
|
||||
UNITY_VERTEX_OUTPUT_STEREO
|
||||
};
|
||||
|
||||
Varyings LitPassVertex(Attributes input)
|
||||
{
|
||||
Varyings output = (Varyings)0;
|
||||
|
||||
UNITY_SETUP_INSTANCE_ID(input);
|
||||
UNITY_TRANSFER_INSTANCE_ID(input, output);
|
||||
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output);
|
||||
|
||||
#if defined(CURVEDWORLD_IS_INSTALLED) && !defined(CURVEDWORLD_DISABLED_ON)
|
||||
#if defined(CURVEDWORLD_NORMAL_TRANSFORMATION_ON)
|
||||
CURVEDWORLD_TRANSFORM_VERTEX_AND_NORMAL(input.positionOS, input.normalOS.xyz, input.tangentOS)
|
||||
#else
|
||||
CURVEDWORLD_TRANSFORM_VERTEX(input.positionOS)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
output.uv.xy = input.uv.xy;
|
||||
output.uv.z = _TimeParameters.x;
|
||||
output.uv.w = 0;
|
||||
|
||||
float3 positionWS = TransformObjectToWorld(input.positionOS.xyz);
|
||||
float3 offset = 0;
|
||||
|
||||
VertexNormalInputs normalInput = GetVertexNormalInputs(input.normalOS.xyz, input.tangentOS);
|
||||
|
||||
if(_WorldSpaceUV > 0)
|
||||
{
|
||||
//Tangents are to be in world-space as well. Otherwise the rotation of the water plane also rotates the tangents
|
||||
normalInput.tangentWS = real3(1.0, 0.0, 0.0);
|
||||
normalInput.bitangentWS = real3(0.0, 0.0, 1.0);
|
||||
}
|
||||
|
||||
float4 vertexColor = GetVertexColor(input.color.rgba, float4(_IntersectionSource > 0 ? 1 : 0, _VertexColorDepth, _VertexColorWaveFlattening, _VertexColorFoam));
|
||||
|
||||
#if !defined(SHADERPASS_DISPLACEMENT) //Displacement will be calculated per pixel
|
||||
#if _WAVES && !defined(TESSELLATION_ON)
|
||||
float2 uv = GetSourceUV(input.uv.xy, positionWS.xz, _WorldSpaceUV);
|
||||
|
||||
//Vertex animation
|
||||
WaveInfo waves = GetWaveInfo(uv, TIME_VERTEX * _WaveSpeed, _WaveHeight, lerp(1, 0, vertexColor.b), _WaveFadeDistance.x, _WaveFadeDistance.y);
|
||||
//Offset in direction of normals (only when using mesh uv)
|
||||
if(_WorldSpaceUV == 0) waves.position *= normalInput.normalWS.xyz;
|
||||
|
||||
offset += waves.position.xyz;
|
||||
#endif
|
||||
|
||||
//SampleWaveSimulationVertex(positionWS, positionWS.y);
|
||||
|
||||
#if DYNAMIC_EFFECTS_ENABLED
|
||||
float4 effectsData = SampleDynamicEffectsData(positionWS.xyz + offset.xyz);
|
||||
|
||||
half falloff = 1.0;
|
||||
#if defined(TESSELLATION_ON)
|
||||
falloff = saturate(1.0 - (distance(positionWS.xyz, GetCurrentViewPosition() - _TessMin)) / (_TessMax - _TessMin));
|
||||
#endif
|
||||
|
||||
offset.y += effectsData[DE_DISPLACEMENT_CHANNEL] * falloff;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
//Apply vertex displacements
|
||||
positionWS += offset;
|
||||
|
||||
output.positionCS = TransformWorldToHClip(positionWS);
|
||||
half fogFactor = InitializeInputDataFog(float4(positionWS, 1.0), output.positionCS.z);
|
||||
|
||||
output.screenPos = ComputeScreenPos(output.positionCS);
|
||||
|
||||
output.normalWS = float4(normalInput.normalWS, positionWS.x);
|
||||
#if _NORMALMAP
|
||||
output.tangent = float4(normalInput.tangentWS, positionWS.y);
|
||||
output.bitangent = float4(normalInput.bitangentWS, positionWS.z);
|
||||
#else
|
||||
output.positionWS = positionWS.xyz;
|
||||
#endif
|
||||
|
||||
//Lambert shading
|
||||
half3 vertexLight = 0;
|
||||
#ifdef _ADDITIONAL_LIGHTS_VERTEX
|
||||
vertexLight = VertexLighting(positionWS, normalInput.normalWS);
|
||||
#endif
|
||||
|
||||
output.fogFactorAndVertexLight = half4(fogFactor, vertexLight);
|
||||
output.color = vertexColor;
|
||||
|
||||
OUTPUT_LIGHTMAP_UV(input.staticLightmapUV, unity_LightmapST, output.staticLightmapUV);
|
||||
#ifdef DYNAMICLIGHTMAP_ON
|
||||
output.dynamicLightmapUV = input.dynamicLightmapUV.xy * unity_DynamicLightmapST.xy + unity_DynamicLightmapST.zw;
|
||||
#endif
|
||||
|
||||
#if UNITY_VERSION >= 202320 //Note: actually available from 2023.1.7+ (URP 15.0.8)
|
||||
OUTPUT_SH4(positionWS, output.normalWS.xyz, GetWorldSpaceNormalizeViewDir(positionWS), output.vertexSH);
|
||||
#else
|
||||
OUTPUT_SH(output.normalWS.xyz, output.vertexSH);
|
||||
#endif
|
||||
|
||||
#if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR)
|
||||
VertexPositionInputs vertexInput = (VertexPositionInputs)0;
|
||||
vertexInput.positionWS = positionWS;
|
||||
vertexInput.positionCS = output.positionCS;
|
||||
output.shadowCoord = GetShadowCoord(vertexInput);
|
||||
#endif
|
||||
|
||||
return output;
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d9350adeb5309174e8998330f5bc90b2
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
111
LocalPackages/StylizedWater2/Shaders/Libraries/Waves.hlsl
Normal file
111
LocalPackages/StylizedWater2/Shaders/Libraries/Waves.hlsl
Normal file
@@ -0,0 +1,111 @@
|
||||
//Stylized Water 2
|
||||
//Staggart Creations (http://staggart.xyz)
|
||||
//Copyright protected under Unity Asset Store EULA
|
||||
|
||||
#if !_FLAT_SHADING && (!defined(SHADER_STAGE_VERTEX) || !defined(SHADER_STAGE_DOMAIN)) //Skip normal calculations, would be calculated in pixel shader
|
||||
#define CALCULATE_NORMALS
|
||||
#endif
|
||||
|
||||
struct WaveInfo
|
||||
{
|
||||
float3 position;
|
||||
float3 normal;
|
||||
};
|
||||
|
||||
float3 GerstnerOffset4(float2 xzVtx, float4 steepness, float4 amp, float4 freq, float4 speed, float4 dirAB, float4 dirCD)
|
||||
{
|
||||
float3 offsets;
|
||||
|
||||
float4 AB = steepness.xxyy * dirAB.xyzw * amp.xxyy;
|
||||
float4 CD = steepness.zzww * dirCD.xyzw * amp.zzww;
|
||||
|
||||
float4 dotABCD = freq.xyzw * float4(dot(dirAB.xy, xzVtx), dot(dirAB.zw, xzVtx), dot(dirCD.xy, xzVtx), dot(dirCD.zw, xzVtx));
|
||||
|
||||
float4 COS = cos(dotABCD + speed);
|
||||
float4 SIN = sin(dotABCD + speed);
|
||||
|
||||
offsets.x = dot(COS, float4(AB.xz, CD.xz));
|
||||
offsets.z = dot(COS, float4(AB.yw, CD.yw));
|
||||
offsets.y = dot(SIN, amp); //Remap to only positive values;
|
||||
|
||||
return offsets;
|
||||
}
|
||||
|
||||
float3 GerstnerNormal4(float2 xzVtx, float4 amp, float4 freq, float4 speed, float4 dirAB, float4 dirCD)
|
||||
{
|
||||
float3 nrml = float3(0, 2.0, 0);
|
||||
|
||||
float4 AB = freq.xxyy * amp.xxyy * dirAB.xyzw;
|
||||
float4 CD = freq.zzww * amp.zzww * dirCD.xyzw;
|
||||
|
||||
float4 dotABCD = freq.xyzw * float4(dot(dirAB.xy, xzVtx), dot(dirAB.zw, xzVtx), dot(dirCD.xy, xzVtx), dot(dirCD.zw, xzVtx));
|
||||
|
||||
float4 COS = cos(dotABCD + speed);
|
||||
|
||||
nrml.x -= dot(COS, float4(AB.xz, CD.xz));
|
||||
nrml.z -= dot(COS, float4(AB.yw, CD.yw));
|
||||
|
||||
nrml.xz *= _WaveNormalStr;
|
||||
nrml = normalize(nrml);
|
||||
|
||||
return nrml;
|
||||
}
|
||||
|
||||
void Gerstner(inout float3 offs, inout float3 nrml,
|
||||
float2 position,
|
||||
float4 amplitude, float4 frequency, float4 steepness,
|
||||
float4 speed, float4 directionAB, float4 directionCD)
|
||||
{
|
||||
offs += GerstnerOffset4(position, steepness, amplitude, frequency, speed, directionAB, directionCD);
|
||||
#ifdef CALCULATE_NORMALS
|
||||
nrml += GerstnerNormal4(position, amplitude, frequency, speed, directionAB, directionCD);
|
||||
#endif
|
||||
}
|
||||
|
||||
#define WAVE_COUNT _WaveCount
|
||||
#define MAX_WAVE_COUNT 5
|
||||
|
||||
|
||||
#define STEEPNESS_SCALE 0.01
|
||||
|
||||
//v1.1.8+
|
||||
WaveInfo GetWaveInfo(float2 position, float2 time, float height, float mask, float fadeStart, float fadeEnd)
|
||||
{
|
||||
WaveInfo waves = (WaveInfo)0;
|
||||
|
||||
float4 amp = float4(0.3, 0.35, 0.25, 0.25);
|
||||
float4 freq = float4(1.3, 1.35, 1.25, 1.25) * (1-_WaveDistance) * 3.0;
|
||||
const float4 speed = float4(1.2* time.x, 1.375* time.y, 1.1 * time.x, time.y) ; //Pre-multiplied with time
|
||||
const float4 dir1 = float4(0.3, 0.85, 0.85, 0.25) * _WaveDirection;
|
||||
const float4 dir2 = float4(0.1, 0.9, -0.5, -0.5) * _WaveDirection;
|
||||
const float4 steepness = float4(12.0, 12.0, 12.0, 12.0) * _WaveSteepness * lerp(1.0, MAX_WAVE_COUNT, 1/WAVE_COUNT);
|
||||
|
||||
//Distance based scalar
|
||||
float pixelDist = length(GetCurrentViewPosition().xz - position.xy);
|
||||
float fadeFactor = saturate((fadeEnd - pixelDist ) / (fadeEnd-fadeStart));
|
||||
|
||||
for (uint i = 0; i <= WAVE_COUNT; i++)
|
||||
{
|
||||
float t = 1+((float)i / (float)WAVE_COUNT);
|
||||
freq *= t;
|
||||
amp *= fadeFactor;
|
||||
|
||||
Gerstner(/*out*/ waves.position, /*out*/ waves.normal, position, amp, freq, steepness, speed, dir1, dir2);
|
||||
}
|
||||
|
||||
waves.normal = normalize(waves.normal);
|
||||
//Average
|
||||
waves.position.y /= WAVE_COUNT;
|
||||
//waves.normal.xz *= WAVE_COUNT;
|
||||
|
||||
waves.position.xz *= STEEPNESS_SCALE * height * mask;
|
||||
waves.position.y *= height * mask;
|
||||
|
||||
return waves;
|
||||
}
|
||||
|
||||
//Depricated
|
||||
WaveInfo GetWaveInfo(float2 position, float2 time, float fadeStart, float fadeEnd)
|
||||
{
|
||||
return GetWaveInfo(position, time, 1.0, 1.0, fadeStart, fadeEnd);
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0e6f483902e4602438fa139ed0ae575b
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,480 @@
|
||||
//Stylized Water 2
|
||||
//Staggart Creations (http://staggart.xyz)
|
||||
//Copyright protected under Unity Asset Store EULA
|
||||
|
||||
%asset_version%
|
||||
%unity_version%
|
||||
%compiler_version%
|
||||
|
||||
%shader_name%
|
||||
{
|
||||
Properties
|
||||
{
|
||||
//Rendering
|
||||
[Toggle] _ZWrite("Depth writing", Float) = 0
|
||||
[Toggle] _ZClip("Camera frustum clipping", Float) = 1
|
||||
[Enum(UnityEngine.Rendering.CullMode)] _Cull("Cull faces", Float) = 2
|
||||
[MaterialEnum(Simple, 0,Advanced, 1)] _ShadingMode("Shading mode", Float) = 1
|
||||
|
||||
[MaterialEnum(Mesh UV,0,World XZ projected ,1)]_WorldSpaceUV("UV Coordinates", Float) = 1
|
||||
_Direction("Animation direction", Vector) = (0,-1,0,0)
|
||||
_Speed("Animation Speed", Float) = 1
|
||||
|
||||
_SlopeAngleThreshold("Angle° threshold", Range(0 , 90)) = 15
|
||||
_SlopeAngleFalloff("Angle° falloff", Range(15 , 90)) = 25
|
||||
_SlopeStretching("Slope UV stretch", Range(0 , 1)) = 0.5
|
||||
_SlopeSpeed("Slope speed multiplier", Float) = 2
|
||||
_SlopeFoam("River slope foam", Range(0 , 3)) = 1
|
||||
|
||||
//Color + Transparency
|
||||
[HDR]_BaseColor("Deep", Color) = (0, 0.44, 0.62, 1)
|
||||
[HDR]_ShallowColor("Shallow", Color) = (0.1, 0.9, 0.89, 0.02)
|
||||
[PowerSlider(3)] _ColorAbsorption("Color Absorption", Range(0 , 1)) = 0
|
||||
_WaveTint("Wave tint", Range( -0.1 , 0.1)) = 0
|
||||
[HDR]_HorizonColor("Horizon", Color) = (0.84, 1, 1, 0.15)
|
||||
_HorizonDistance("Horizon Distance", Range(0.01 , 32)) = 8
|
||||
[Toggle] _VertexColorDepth("Vertex color (G) depth", Float) = 0
|
||||
_DepthVertical("View Depth", Range(0.01 , 16)) = 4
|
||||
_DepthHorizontal("Vertical Height Depth", Range(0.01 , 8)) = 1
|
||||
[Toggle] _DepthExp("Exponential Blend", Float) = 1
|
||||
_EdgeFade("Edge Fade", Float) = 0.1
|
||||
_ShadowStrength("Shadow Strength", Range(0 , 1)) = 1
|
||||
|
||||
//_Smoothness("Smoothness", Range(0.0, 1.0)) = 0.9
|
||||
//_Metallic("Metallic", Range(0.0, 1.0)) = 0.0
|
||||
|
||||
_TranslucencyStrength("Translucency Strength", Range(0 , 3)) = 1
|
||||
_TranslucencyStrengthDirect("Translucency Strength (Direct)", Range(0 , 0.5)) = 0.05
|
||||
_TranslucencyExp("Translucency Exponent", Range(1 , 32)) = 4
|
||||
_TranslucencyCurvatureMask("Translucency Curvature mask", Range(0, 1)) = 0.75
|
||||
_TranslucencyReflectionMask("Translucency Reflection mask", Range(0, 1)) = 1
|
||||
|
||||
//Underwater
|
||||
_CausticsBrightness("Brightness", Float) = 2
|
||||
_CausticsTiling("Tiling", Float) = 0.5
|
||||
_CausticsSpeed("Speed multiplier", Float) = 0.1
|
||||
_CausticsDistortion("Distortion", Range(0, 1)) = 0.15
|
||||
[NoScaleOffset][SingleLineTexture]_CausticsTex("Caustics RGB", 2D) = "black" {}
|
||||
|
||||
_UnderwaterSurfaceSmoothness("Underwater Surface Smoothness", Range(0, 1)) = 0.8
|
||||
_UnderwaterRefractionOffset("Underwater Refraction Offset", Range(0, 1)) = 0.2
|
||||
|
||||
_RefractionStrength("Refraction Strength", Range(0, 1)) = 0.1
|
||||
_RefractionChromaticAberration("Refraction Chromatic Aberration)", Range(0, 1)) = 1
|
||||
|
||||
//Intersection Foam
|
||||
[MaterialEnum(Depth Texture,0,Vertex Color (R),1,Depth Texture and Vertex Color,2)] _IntersectionSource("Intersection source", Float) = 0
|
||||
[MaterialEnum(None,0,Sharp,1,Smooth,2)] _IntersectionStyle("Intersection style", Float) = 1
|
||||
|
||||
[NoScaleOffset][SingleLineTexture]_IntersectionNoise("Intersection noise", 2D) = "white" {}
|
||||
_IntersectionColor("Color", Color) = (1,1,1,1)
|
||||
_IntersectionLength("Distance", Range(0.01 , 5)) = 2
|
||||
_IntersectionClipping("Cutoff", Range(0.01, 1)) = 0.5
|
||||
_IntersectionFalloff("Falloff", Range(0.01 , 1)) = 0.5
|
||||
_IntersectionTiling("Noise Tiling", float) = 0.2
|
||||
_IntersectionSpeed("Speed multiplier", float) = 0.1
|
||||
_IntersectionRippleDist("Ripple distance", float) = 32
|
||||
_IntersectionRippleStrength("Ripple Strength", Range(0 , 1)) = 0.5
|
||||
|
||||
//Surface Foam
|
||||
[NoScaleOffset][SingleLineTexture]_FoamTex("Foam Mask", 2D) = "black" {}
|
||||
_FoamColor("Color", Color) = (1,1,1,1)
|
||||
_FoamSpeed("Speed multiplier", float) = 0.1
|
||||
_FoamSubSpeed("Speed multiplier (sub-layer)", float) = -0.25
|
||||
_FoamBaseAmount("Base amount", Range(0 , 1)) = 0
|
||||
_FoamClipping("Clipping", Range(0 , 0.999)) = 0
|
||||
_FoamWaveAmount("Wave crest amount", Range(0 , 2)) = 0
|
||||
_FoamTiling("Tiling", Vector) = (0.1, 0.1, 0, 0)
|
||||
_FoamSubTiling("Tiling (sub-layer)", float) = 0.5
|
||||
_FoamDistortion("Distortion", Range(0, 3)) = 0
|
||||
[Toggle] _VertexColorFoam("Vertex color (A) foam", Float) = 0
|
||||
|
||||
[NoScaleOffset][SingleLineTexture] _FoamTexDynamic("Foam (Dynamic)", 2D) = "white" {}
|
||||
_FoamTilingDynamic("Tiling (Dynamic)", float) = 0.1
|
||||
_FoamSubTilingDynamic("Tiling (sub-layer)", float) = 2
|
||||
_FoamSpeedDynamic("Speed multiplier", float) = 0.1
|
||||
_FoamSubSpeedDynamic("Speed multiplier (sub-layer)", float) = -0.1
|
||||
|
||||
//Normals
|
||||
[NoScaleOffset][Normal][SingleLineTexture]_BumpMap("Normals", 2D) = "bump" {}
|
||||
[NoScaleOffset][Normal][SingleLineTexture]_BumpMapSlope("Normals (River slopes)", 2D) = "bump" {}
|
||||
_NormalTiling("Tiling", Vector) = (0.5, 0.5, 0, 0)
|
||||
_NormalSubTiling("Tiling (sub-layer)", Float) = 0.5
|
||||
_NormalStrength("Strength", Range(0 , 1)) = 0.135
|
||||
_NormalSpeed("Speed multiplier", Float) = 0.2
|
||||
_NormalSubSpeed("Speed multiplier (sub-layer)", Float) = -0.5
|
||||
|
||||
[NoScaleOffset][Normal][SingleLineTexture]_BumpMapLarge("Normals (Distance)", 2D) = "bump" {}
|
||||
_DistanceNormalsFadeDist("Distance normals blend (Start/End)", Vector) = (100, 300, 0, 0)
|
||||
_DistanceNormalsTiling("Distance normals: Tiling multiplier", Float) = 0.15
|
||||
|
||||
_SparkleIntensity("Sparkle Intensity", Range(0 , 10)) = 00
|
||||
_SparkleSize("Sparkle Size", Range( 0 , 1)) = 0.280
|
||||
|
||||
//Light Reflections
|
||||
[PowerSlider(0.1)] _SunReflectionSize("Sun Size", Range(0 , 1)) = 0.5
|
||||
_SunReflectionStrength("Sun Strength", Float) = 10
|
||||
_SunReflectionDistortion("Sun Distortion", Range(0 ,2)) = 0.49
|
||||
_PointSpotLightReflectionStrength("Point/spot light strength", Float) = 10
|
||||
[PowerSlider(0.1)] _PointSpotLightReflectionSize("Point/spot light size", Range(0 , 1)) = 0
|
||||
_PointSpotLightReflectionDistortion("Point/spot light distortion", Range(0, 1)) = 0.5
|
||||
|
||||
//World Reflections
|
||||
_ReflectionStrength("Strength", Range(0, 1)) = 1
|
||||
_ReflectionDistortion("Distortion", Range(0, 1)) = 0.05
|
||||
_ReflectionBlur("Probe Blur Factor", Range(0, 1)) = 0
|
||||
_ReflectionFresnel("Curvature mask", Range(0.01, 20)) = 5
|
||||
_ReflectionLighting("Lighting influence", Range(0, 1)) = 0
|
||||
_PlanarReflection("Planar Reflections", 2D) = "" {} //Instanced
|
||||
_PlanarReflectionsEnabled("Planar Enabled", float) = 0 //Instanced
|
||||
|
||||
//Waves
|
||||
_WaveSpeed("Speed", Float) = 2
|
||||
_WaveHeight("Height", Range(0 , 10)) = 0.25
|
||||
[Toggle] _VertexColorWaveFlattening("Vertex color (B) wave flattening", Float) = 0
|
||||
|
||||
_WaveNormalStr("Normal Strength", Range(0 , 32)) = 0.5
|
||||
_WaveDistance("Distance", Range(0 , 1)) = 0.8
|
||||
_WaveFadeDistance("Wave fade distance (Start/End)", Vector) = (150, 300, 0, 0)
|
||||
|
||||
_WaveSteepness("Steepness", Range(0 , 5)) = 0.1
|
||||
_WaveCount("Count", Range(1 , 5)) = 1
|
||||
_WaveDirection("Direction", vector) = (1,1,1,1)
|
||||
|
||||
//Keyword states
|
||||
[ToggleOff(_UNLIT)] _LightingOn("Enable lighting", Float) = 1
|
||||
[ToggleOff(_RECEIVE_SHADOWS_OFF)] _ReceiveShadows("Recieve Shadows", Float) = 1
|
||||
|
||||
[Toggle(_FLAT_SHADING)] _FlatShadingOn("Flat shading", Float) = 0
|
||||
[Toggle(_TRANSLUCENCY)] _TranslucencyOn("Enable translucency shading", Float) = 1
|
||||
[Toggle(_REFRACTION)] _RefractionOn("_REFRACTION", Float) = 1
|
||||
[Toggle(_RIVER)] _RiverModeOn("River Mode", Float) = 0
|
||||
[Toggle(_CAUSTICS)] _CausticsOn("Caustics ON", Float) = 1
|
||||
[ToggleOff(_SPECULARHIGHLIGHTS_OFF)] _SpecularReflectionsOn("Specular Reflections", Float) = 1
|
||||
[ToggleOff(_ENVIRONMENTREFLECTIONS_OFF)] _EnvironmentReflectionsOn("Environment Reflections", Float) = 1
|
||||
[Toggle(_NORMALMAP)] _NormalMapOn("Normal maps", Float) = 1
|
||||
[Toggle(_DISTANCE_NORMALS)] _DistanceNormalsOn("Distance normal map", Float) = 1
|
||||
[Toggle(_FOAM)] _FoamOn("Foam", Float) = 1
|
||||
[Toggle(_DISABLE_DEPTH_TEX)] _DisableDepthTexture("Disable depth texture", Float) = 0
|
||||
[Toggle(_WAVES)] _WavesOn("_WAVES", Float) = 0
|
||||
|
||||
%tessellation_properties%
|
||||
|
||||
//[CurvedWorldBendSettings] _CurvedWorldBendSettings("0,5|1|1", Vector) = (0, 0, 0, 0)
|
||||
|
||||
//Purely here so the _BaseColor gets multiplied with a white color during lightmapping
|
||||
[MainTexture] [HideInInspector] _BaseMap("Albedo", 2D) = "white" {}
|
||||
|
||||
[HideInInspector][NoScaleOffset]unity_Lightmaps("unity_Lightmaps", 2DArray) = "" {}
|
||||
[HideInInspector][NoScaleOffset]unity_LightmapsInd("unity_LightmapsInd", 2DArray) = "" {}
|
||||
[HideInInspector][NoScaleOffset]unity_ShadowMasks("unity_ShadowMasks", 2DArray) = "" {}
|
||||
}
|
||||
|
||||
SubShader
|
||||
{
|
||||
Tags
|
||||
{
|
||||
"RenderType" = "Transparent"
|
||||
"RenderPipeline" = "UniversalPipeline"
|
||||
"UniversalMaterialType" = "Lit"
|
||||
"IgnoreProjector" = "True"
|
||||
"Queue" = "Transparent+%render_queue_offset%"
|
||||
}
|
||||
|
||||
HLSLINCLUDE
|
||||
//Custom directives:
|
||||
%custom_directives%
|
||||
|
||||
//Curved World 2020 directives:
|
||||
//#pragma shader_feature_local CURVEDWORLD_BEND_TYPE_CLASSICRUNNER_X_POSITIVE CURVEDWORLD_BEND_TYPE_LITTLEPLANET_Y
|
||||
//#define CURVEDWORLD_BEND_ID_1
|
||||
//#pragma shader_feature_local CURVEDWORLD_DISABLED_ON
|
||||
//#pragma shader_feature_local CURVEDWORLD_NORMAL_TRANSFORMATION_ON
|
||||
|
||||
ENDHLSL
|
||||
|
||||
Pass
|
||||
{
|
||||
Name "ForwardLit"
|
||||
Tags { "LightMode"="UniversalForward" }
|
||||
|
||||
Blend SrcAlpha OneMinusSrcAlpha, One OneMinusSrcAlpha
|
||||
ZWrite [_ZWrite]
|
||||
Cull [_Cull]
|
||||
ZTest LEqual
|
||||
ZClip [_ZClip]
|
||||
|
||||
%stencil%
|
||||
|
||||
HLSLPROGRAM
|
||||
%pragma_target%
|
||||
%pragma_renderers%
|
||||
|
||||
#pragma multi_compile_instancing
|
||||
#pragma instancing_options renderinglayer
|
||||
#if UNITY_VERSION >= 202220
|
||||
#include_with_pragmas "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DOTS.hlsl"
|
||||
#endif
|
||||
|
||||
#define _SURFACE_TYPE_TRANSPARENT 1
|
||||
|
||||
// Material Keywords
|
||||
#pragma shader_feature_local _NORMALMAP
|
||||
#pragma shader_feature_local _WAVES
|
||||
#pragma shader_feature_local _FLAT_SHADING
|
||||
#pragma shader_feature_local _RECEIVE_SHADOWS_OFF
|
||||
#pragma shader_feature_local _RIVER
|
||||
#pragma shader_feature_local_fragment _DISABLE_DEPTH_TEX
|
||||
#pragma shader_feature_local_fragment _REFRACTION
|
||||
#pragma shader_feature_local_fragment _ADVANCED_SHADING
|
||||
#pragma shader_feature_local_fragment _UNLIT
|
||||
#pragma shader_feature_local_fragment _CAUSTICS
|
||||
#pragma shader_feature_local_fragment _DISTANCE_NORMALS
|
||||
#pragma shader_feature_local_fragment _FOAM
|
||||
#pragma shader_feature_local_fragment _TRANSLUCENCY
|
||||
#pragma shader_feature_local_fragment _SPECULARHIGHLIGHTS_OFF
|
||||
#pragma shader_feature_local_fragment _ENVIRONMENTREFLECTIONS_OFF
|
||||
#pragma shader_feature_local_fragment _ _SHARP_INERSECTION _SMOOTH_INTERSECTION
|
||||
|
||||
//Multi-compile variants for installed extensions
|
||||
%multi_compile underwater rendering%
|
||||
%multi_compile dynamic effects%
|
||||
|
||||
#if _RIVER
|
||||
#undef _WAVES
|
||||
#undef UNDERWATER_ENABLED
|
||||
#endif
|
||||
|
||||
//Required to differentiate between skybox and scene geometry
|
||||
#if UNDERWATER_ENABLED
|
||||
#undef _DISABLE_DEPTH_TEX
|
||||
#endif
|
||||
|
||||
#include_library "Libraries/URP.hlsl"
|
||||
//#include "Assets/Amazing Assets/Curved World/Shaders/Core/CurvedWorldTransform.cginc"
|
||||
|
||||
//Tying specific features and operations to advanced shading
|
||||
#if _ADVANCED_SHADING
|
||||
#define RESAMPLE_REFRACTION_DEPTH 1
|
||||
#define PHYSICAL_REFRACTION 1
|
||||
//#define HQ_CAUSTICS 1
|
||||
|
||||
#if _REFRACTION //Requires opaque texture
|
||||
#define COLOR_ABSORPTION 1
|
||||
#endif
|
||||
|
||||
//Mask caustics by shadows cast on scene geometry. Doubles the shadow sampling cost
|
||||
//Note: needs depth texture to reconstruct the world position from depth
|
||||
#if _CAUSTICS && defined(MAIN_LIGHT_CALCULATE_SHADOWS) && !_DISABLE_DEPTH_TEX
|
||||
#define SCENE_SHADOWMASK 1
|
||||
#endif
|
||||
|
||||
#if !_DISABLE_DEPTH_TEX && _CAUSTICS || UNDERWATER_ENABLED
|
||||
//Compose a mask for pixels against the skybox
|
||||
#define DEPTH_MASK 1
|
||||
#endif
|
||||
#endif
|
||||
|
||||
//Universal Pipeline keywords
|
||||
%multi_compile_shadows%
|
||||
%multi_compile_light_cookies%
|
||||
|
||||
#pragma multi_compile _ _ADDITIONAL_LIGHTS_VERTEX _ADDITIONAL_LIGHTS
|
||||
#pragma multi_compile_fragment _ _SHADOWS_SOFT
|
||||
#pragma multi_compile_fragment _ _ADDITIONAL_LIGHT_SHADOWS //URP 11+
|
||||
|
||||
//URP 12+ only (2021.2+)
|
||||
#pragma multi_compile_fragment _ _REFLECTION_PROBE_BLENDING
|
||||
#pragma multi_compile_fragment _ _REFLECTION_PROBE_BOX_PROJECTION
|
||||
#pragma multi_compile_fragment _ DEBUG_DISPLAY
|
||||
#pragma multi_compile_fragment _ _LIGHT_LAYERS
|
||||
#pragma multi_compile _ _CLUSTERED_RENDERING
|
||||
|
||||
//URP 14+ (2022.2+)
|
||||
#pragma multi_compile _ _FORWARD_PLUS
|
||||
#if UNITY_VERSION >= 202220
|
||||
#include_with_pragmas "Packages/com.unity.render-pipelines.universal/ShaderLibrary/RenderingLayers.hlsl"
|
||||
#endif
|
||||
|
||||
//URP 15+ (2023.1+)
|
||||
#pragma multi_compile _ EVALUATE_SH_MIXED EVALUATE_SH_VERTEX
|
||||
|
||||
//Unity defined keywords
|
||||
#pragma multi_compile _ LIGHTMAP_SHADOW_MIXING
|
||||
#pragma multi_compile _ SHADOWS_SHADOWMASK
|
||||
//#pragma multi_compile _ DIRLIGHTMAP_COMBINED //Surface normals are animated, so pointless
|
||||
#pragma multi_compile _ LIGHTMAP_ON
|
||||
#pragma multi_compile _ DYNAMICLIGHTMAP_ON
|
||||
#if UNITY_VERSION >= 202310
|
||||
#include_with_pragmas "Packages/com.unity.render-pipelines.universal/ShaderLibrary/ProbeVolumeVariants.hlsl"
|
||||
#endif
|
||||
|
||||
|
||||
//Defines
|
||||
#define SHADERPASS_FORWARD
|
||||
|
||||
%tessellation_directives%
|
||||
|
||||
#include_library "Libraries/Input.hlsl"
|
||||
|
||||
#include_library "Libraries/Common.hlsl"
|
||||
|
||||
//Fog rendering (integration)
|
||||
%define_fog_integration%
|
||||
%include_fog_integration_library%
|
||||
#include_library "Libraries/Fog.hlsl"
|
||||
|
||||
#include_library "Libraries/Waves.hlsl"
|
||||
#include_library "Libraries/Lighting.hlsl"
|
||||
#include_library "Libraries/Reflections.hlsl"
|
||||
|
||||
#ifdef UNDERWATER_ENABLED
|
||||
#include_library "Underwater/UnderwaterFog.hlsl"
|
||||
#include_library "Underwater/UnderwaterShading.hlsl"
|
||||
#endif
|
||||
|
||||
#include_library "Libraries/Features.hlsl"
|
||||
#include_library "Libraries/Foam.hlsl"
|
||||
#include_library "Libraries/Caustics.hlsl"
|
||||
|
||||
#ifdef DYNAMIC_EFFECTS_ENABLED
|
||||
#include_library "DynamicEffects/DynamicEffects.hlsl"
|
||||
#endif
|
||||
|
||||
#include_library "Libraries/Vertex.hlsl"
|
||||
|
||||
#if defined(TESSELLATION_ON)
|
||||
#include_library "Libraries/Tesselation.hlsl"
|
||||
#define VertexOutput VertexControl
|
||||
#else
|
||||
#define VertexOutput Varyings
|
||||
#endif
|
||||
|
||||
#pragma vertex Vertex
|
||||
VertexOutput Vertex(Attributes v)
|
||||
{
|
||||
#if defined(TESSELLATION_ON)
|
||||
return VertexTessellation(v);
|
||||
#else
|
||||
return LitPassVertex(v);
|
||||
#endif
|
||||
}
|
||||
|
||||
#pragma fragment ForwardPassFragment
|
||||
#include_library "Libraries/ForwardPass.hlsl"
|
||||
|
||||
//#include "UnityCG.cginc" //Test
|
||||
#if defined(UNITY_SHADER_VARIABLES_INCLUDED) || defined(UNITY_CG_INCLUDED)
|
||||
#error "Fatal error: a shader library from the Built-in Render Pipeline was compiled into the shader. This is most likely caused by the fog integration, make absolutely sure it is URP-compatible!"
|
||||
#endif
|
||||
|
||||
ENDHLSL
|
||||
}
|
||||
|
||||
//Currently unused, except for custom render passes (such as depth texture injection)
|
||||
Pass
|
||||
{
|
||||
Name "Depth or Displacement"
|
||||
Tags { "LightMode" = "DepthOnly" }
|
||||
|
||||
ZWrite On
|
||||
//ColorMask RG
|
||||
Cull Off
|
||||
|
||||
HLSLPROGRAM
|
||||
%pragma_target%
|
||||
%pragma_renderers%
|
||||
|
||||
#pragma multi_compile_instancing
|
||||
#pragma instancing_options renderinglayer
|
||||
#if UNITY_VERSION >= 202220
|
||||
#include_with_pragmas "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DOTS.hlsl"
|
||||
#endif
|
||||
|
||||
#pragma shader_feature_local _WAVES
|
||||
|
||||
%tessellation_directives%
|
||||
|
||||
#include_library "Libraries/URP.hlsl"
|
||||
//#include "Assets/Amazing Assets/Curved World/Shaders/Core/CurvedWorldTransform.cginc"
|
||||
|
||||
#include_library "Libraries/Input.hlsl"
|
||||
|
||||
#include_library "Libraries/Common.hlsl"
|
||||
#include_library "Libraries/Fog.hlsl"
|
||||
#include_library "Libraries/Waves.hlsl"
|
||||
|
||||
#pragma multi_compile_fragment _ WATER_DISPLACEMENT_PASS
|
||||
|
||||
#if !WATER_DISPLACEMENT_PASS
|
||||
#define SHADERPASS_DEPTHONLY
|
||||
#endif
|
||||
|
||||
#if WATER_DISPLACEMENT_PASS
|
||||
#define SHADERPASS_DISPLACEMENT
|
||||
#endif
|
||||
|
||||
%multi_compile dynamic effects%
|
||||
#ifdef DYNAMIC_EFFECTS_ENABLED
|
||||
#include_library "DynamicEffects/DynamicEffects.hlsl"
|
||||
#endif
|
||||
|
||||
#include_library "Libraries/Vertex.hlsl"
|
||||
|
||||
#if defined(TESSELLATION_ON)
|
||||
#include_library "Libraries/Tesselation.hlsl"
|
||||
#define VertexOutput VertexControl
|
||||
#else
|
||||
#define VertexOutput Varyings
|
||||
#endif
|
||||
|
||||
#pragma vertex Vertex
|
||||
VertexOutput Vertex(Attributes v)
|
||||
{
|
||||
#if defined(TESSELLATION_ON)
|
||||
return VertexTessellation(v);
|
||||
#else
|
||||
return LitPassVertex(v);
|
||||
#endif
|
||||
}
|
||||
|
||||
#pragma fragment DepthOnlyFragment
|
||||
float4 DepthOnlyFragment(Varyings input, FRONT_FACE_TYPE vFace : FRONT_FACE_SEMANTIC) : SV_TARGET
|
||||
{
|
||||
UNITY_SETUP_INSTANCE_ID(input);
|
||||
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);
|
||||
|
||||
float depth = input.positionCS.z;
|
||||
|
||||
#if WATER_DISPLACEMENT_PASS
|
||||
float3 positionWS = input.positionWS.xyz;
|
||||
|
||||
float2 uv = GetSourceUV(input.uv.xy, positionWS.xz, _WorldSpaceUV);
|
||||
float4 vertexColor = input.color; //Mask already applied in vertex shader
|
||||
WaveInfo waves = GetWaveInfo(uv, TIME * _WaveSpeed, _WaveHeight, lerp(1, 0, vertexColor.b), _WaveFadeDistance.x, _WaveFadeDistance.y);
|
||||
|
||||
float3 offset = 0;
|
||||
|
||||
offset.y += waves.position.y;
|
||||
|
||||
#if DYNAMIC_EFFECTS_ENABLED
|
||||
float4 dynamicEffectsData = SampleDynamicEffectsData(positionWS.xyz);
|
||||
|
||||
//Why?
|
||||
dynamicEffectsData.r *= 0.1;
|
||||
|
||||
offset.y += dynamicEffectsData.r;
|
||||
#endif
|
||||
|
||||
depth = positionWS.y + offset.y;
|
||||
#endif
|
||||
|
||||
return float4(depth, vFace, 0, 0);
|
||||
}
|
||||
ENDHLSL
|
||||
}
|
||||
}
|
||||
|
||||
CustomEditor "StylizedWater2.MaterialUI"
|
||||
Fallback "Hidden/InternalErrorShader"
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d7b0192b9bf19c949900035fa781fdc4
|
||||
ScriptedImporter:
|
||||
internalIDToNameTable: []
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
script: {fileID: 11500000, guid: 531a3ff0802e4acbaef16e2b9d97fd66, type: 3}
|
||||
template: {instanceID: 0}
|
||||
settings:
|
||||
shaderName: Standard
|
||||
hidden: 0
|
||||
type: 0
|
||||
autoIntegration: 1
|
||||
fogIntegration: 1
|
||||
quadNormalMapSamples: 0
|
||||
customIncludeDirectives:
|
||||
- enabled: 1
|
||||
type: 0
|
||||
value: float _MyParameter;
|
||||
- enabled: 0
|
||||
type: 3
|
||||
value: QUAD_NORMAL_SAMPLES
|
||||
- enabled: 0
|
||||
type: 3
|
||||
value: PIXELIZE_UV
|
||||
- enabled: 0
|
||||
type: 3
|
||||
value: INTERSECTION_REFRACTION
|
||||
- enabled: 0
|
||||
type: 3
|
||||
value: DIRECTIONAL_CAUSTICS
|
||||
dependencies:
|
||||
- Assets/StylizedWater2/Shaders/Libraries/URP.hlsl
|
||||
- Assets/StylizedWater2/Shaders/Libraries/Input.hlsl
|
||||
- Assets/StylizedWater2/Shaders/Libraries/Common.hlsl
|
||||
- Assets/StylizedWater2/Shaders/Libraries/Fog.hlsl
|
||||
- Assets/StylizedWater2/Shaders/Libraries/Waves.hlsl
|
||||
- Assets/StylizedWater2/Shaders/Libraries/Lighting.hlsl
|
||||
- Assets/StylizedWater2/Shaders/Underwater/UnderwaterFog.hlsl
|
||||
- Assets/StylizedWater2/Shaders/Underwater/UnderwaterShading.hlsl
|
||||
- Assets/StylizedWater2/Shaders/Libraries/Features.hlsl
|
||||
- Assets/StylizedWater2/Shaders/Libraries/Foam.hlsl
|
||||
- Assets/StylizedWater2/Shaders/Libraries/Caustics.hlsl
|
||||
- Assets/StylizedWater2/Shaders/DynamicEffects/DynamicEffects.hlsl
|
||||
- Assets/StylizedWater2/Shaders/Libraries/Vertex.hlsl
|
||||
- Assets/StylizedWater2/Shaders/Libraries/Tesselation.hlsl
|
||||
- Assets/StylizedWater2/Shaders/Libraries/ForwardPass.hlsl
|
||||
8
LocalPackages/StylizedWater2/Shaders/SubGraphs.meta
Normal file
8
LocalPackages/StylizedWater2/Shaders/SubGraphs.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 44bdc7e3bf4ba7549853a2048225613c
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,6 @@
|
||||
# Sample Water Height
|
||||
Requires the Stylized Water 2 render feature to be active and the Displacement Prepass functionality enabled on it.
|
||||
|
||||
If so, the water geometry's height (including any displacement effects) are rendered into a buffer.
|
||||
|
||||
This sub-graph allows other shaders to sample the water's height information this way. May be used for various effects
|
||||
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3bbcc008d31f4e54498c850c47e3a275
|
||||
TextScriptImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,338 @@
|
||||
{
|
||||
"m_SGVersion": 3,
|
||||
"m_Type": "UnityEditor.ShaderGraph.GraphData",
|
||||
"m_ObjectId": "76d35e7e619d42e2aaafebc8ef6f3093",
|
||||
"m_Properties": [
|
||||
{
|
||||
"m_Id": "26abb75110b74b5788e84f3884bb5b9b"
|
||||
}
|
||||
],
|
||||
"m_Keywords": [],
|
||||
"m_Dropdowns": [],
|
||||
"m_CategoryData": [
|
||||
{
|
||||
"m_Id": "180fc64b34054e409bb3cb076f3c929a"
|
||||
}
|
||||
],
|
||||
"m_Nodes": [
|
||||
{
|
||||
"m_Id": "480dd4e30e674d20adf554f043aec179"
|
||||
},
|
||||
{
|
||||
"m_Id": "e31739b3fc354a59b9d0f62f82928767"
|
||||
},
|
||||
{
|
||||
"m_Id": "5169eb9d62a84eaf9cb37762b34fdaba"
|
||||
}
|
||||
],
|
||||
"m_GroupDatas": [],
|
||||
"m_StickyNoteDatas": [
|
||||
{
|
||||
"m_Id": "22fe41e0edba44469681ff48f924d5b7"
|
||||
}
|
||||
],
|
||||
"m_Edges": [
|
||||
{
|
||||
"m_OutputSlot": {
|
||||
"m_Node": {
|
||||
"m_Id": "5169eb9d62a84eaf9cb37762b34fdaba"
|
||||
},
|
||||
"m_SlotId": 0
|
||||
},
|
||||
"m_InputSlot": {
|
||||
"m_Node": {
|
||||
"m_Id": "e31739b3fc354a59b9d0f62f82928767"
|
||||
},
|
||||
"m_SlotId": 0
|
||||
}
|
||||
},
|
||||
{
|
||||
"m_OutputSlot": {
|
||||
"m_Node": {
|
||||
"m_Id": "e31739b3fc354a59b9d0f62f82928767"
|
||||
},
|
||||
"m_SlotId": 1
|
||||
},
|
||||
"m_InputSlot": {
|
||||
"m_Node": {
|
||||
"m_Id": "480dd4e30e674d20adf554f043aec179"
|
||||
},
|
||||
"m_SlotId": 1
|
||||
}
|
||||
}
|
||||
],
|
||||
"m_VertexContext": {
|
||||
"m_Position": {
|
||||
"x": 0.0,
|
||||
"y": 0.0
|
||||
},
|
||||
"m_Blocks": []
|
||||
},
|
||||
"m_FragmentContext": {
|
||||
"m_Position": {
|
||||
"x": 0.0,
|
||||
"y": 0.0
|
||||
},
|
||||
"m_Blocks": []
|
||||
},
|
||||
"m_PreviewData": {
|
||||
"serializedMesh": {
|
||||
"m_SerializedMesh": "{\"mesh\":{\"instanceID\":0}}",
|
||||
"m_Guid": ""
|
||||
},
|
||||
"preventRotation": false
|
||||
},
|
||||
"m_Path": "Sub Graphs",
|
||||
"m_GraphPrecision": 1,
|
||||
"m_PreviewMode": 2,
|
||||
"m_OutputNode": {
|
||||
"m_Id": "480dd4e30e674d20adf554f043aec179"
|
||||
},
|
||||
"m_ActiveTargets": []
|
||||
}
|
||||
|
||||
{
|
||||
"m_SGVersion": 0,
|
||||
"m_Type": "UnityEditor.ShaderGraph.CategoryData",
|
||||
"m_ObjectId": "180fc64b34054e409bb3cb076f3c929a",
|
||||
"m_Name": "",
|
||||
"m_ChildObjectList": [
|
||||
{
|
||||
"m_Id": "26abb75110b74b5788e84f3884bb5b9b"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
{
|
||||
"m_SGVersion": 0,
|
||||
"m_Type": "UnityEditor.ShaderGraph.StickyNoteData",
|
||||
"m_ObjectId": "22fe41e0edba44469681ff48f924d5b7",
|
||||
"m_Title": "Usage note",
|
||||
"m_Content": "For this to return any data the Stylized Water 2 render feature must be active on the current renderer.\n\nAnd the \"Displacement Prepass\" option must be enabled.",
|
||||
"m_TextSize": 0,
|
||||
"m_Theme": 0,
|
||||
"m_Position": {
|
||||
"serializedVersion": "2",
|
||||
"x": -471.0,
|
||||
"y": -264.0,
|
||||
"width": 258.5189208984375,
|
||||
"height": 135.0
|
||||
},
|
||||
"m_Group": {
|
||||
"m_Id": ""
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
"m_SGVersion": 0,
|
||||
"m_Type": "UnityEditor.ShaderGraph.Vector1MaterialSlot",
|
||||
"m_ObjectId": "234c6a1822174833a15cf2979860bb36",
|
||||
"m_Id": 1,
|
||||
"m_DisplayName": "height",
|
||||
"m_SlotType": 1,
|
||||
"m_Hidden": false,
|
||||
"m_ShaderOutputName": "height",
|
||||
"m_StageCapability": 3,
|
||||
"m_Value": 0.0,
|
||||
"m_DefaultValue": 0.0,
|
||||
"m_Labels": []
|
||||
}
|
||||
|
||||
{
|
||||
"m_SGVersion": 0,
|
||||
"m_Type": "UnityEditor.ShaderGraph.Vector1MaterialSlot",
|
||||
"m_ObjectId": "24eaf6c6562a477b99080b45c3be2702",
|
||||
"m_Id": 1,
|
||||
"m_DisplayName": "Height",
|
||||
"m_SlotType": 0,
|
||||
"m_Hidden": false,
|
||||
"m_ShaderOutputName": "Height",
|
||||
"m_StageCapability": 3,
|
||||
"m_Value": 0.0,
|
||||
"m_DefaultValue": 0.0,
|
||||
"m_Labels": []
|
||||
}
|
||||
|
||||
{
|
||||
"m_SGVersion": 1,
|
||||
"m_Type": "UnityEditor.ShaderGraph.Internal.Vector3ShaderProperty",
|
||||
"m_ObjectId": "26abb75110b74b5788e84f3884bb5b9b",
|
||||
"m_Guid": {
|
||||
"m_GuidSerialized": "9edc1bf0-53e0-4109-84bc-f54bcd72a140"
|
||||
},
|
||||
"m_Name": "World Position",
|
||||
"m_DefaultRefNameVersion": 1,
|
||||
"m_RefNameGeneratedByDisplayName": "World Position",
|
||||
"m_DefaultReferenceName": "_World_Position",
|
||||
"m_OverrideReferenceName": "",
|
||||
"m_GeneratePropertyBlock": true,
|
||||
"m_UseCustomSlotLabel": false,
|
||||
"m_CustomSlotLabel": "",
|
||||
"m_Precision": 0,
|
||||
"overrideHLSLDeclaration": false,
|
||||
"hlslDeclarationOverride": 0,
|
||||
"m_Hidden": false,
|
||||
"m_Value": {
|
||||
"x": 0.0,
|
||||
"y": 0.0,
|
||||
"z": 0.0,
|
||||
"w": 0.0
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
"m_SGVersion": 0,
|
||||
"m_Type": "UnityEditor.ShaderGraph.SubGraphOutputNode",
|
||||
"m_ObjectId": "480dd4e30e674d20adf554f043aec179",
|
||||
"m_Group": {
|
||||
"m_Id": ""
|
||||
},
|
||||
"m_Name": "Output",
|
||||
"m_DrawState": {
|
||||
"m_Expanded": true,
|
||||
"m_Position": {
|
||||
"serializedVersion": "2",
|
||||
"x": -195.0,
|
||||
"y": -122.0,
|
||||
"width": 88.0,
|
||||
"height": 77.0
|
||||
}
|
||||
},
|
||||
"m_Slots": [
|
||||
{
|
||||
"m_Id": "24eaf6c6562a477b99080b45c3be2702"
|
||||
}
|
||||
],
|
||||
"synonyms": [],
|
||||
"m_Precision": 0,
|
||||
"m_PreviewExpanded": true,
|
||||
"m_PreviewMode": 0,
|
||||
"m_CustomColors": {
|
||||
"m_SerializableColors": []
|
||||
},
|
||||
"IsFirstSlotValid": true
|
||||
}
|
||||
|
||||
{
|
||||
"m_SGVersion": 0,
|
||||
"m_Type": "UnityEditor.ShaderGraph.PropertyNode",
|
||||
"m_ObjectId": "5169eb9d62a84eaf9cb37762b34fdaba",
|
||||
"m_Group": {
|
||||
"m_Id": ""
|
||||
},
|
||||
"m_Name": "Property",
|
||||
"m_DrawState": {
|
||||
"m_Expanded": true,
|
||||
"m_Position": {
|
||||
"serializedVersion": "2",
|
||||
"x": -640.0,
|
||||
"y": -79.0,
|
||||
"width": 153.0,
|
||||
"height": 34.0
|
||||
}
|
||||
},
|
||||
"m_Slots": [
|
||||
{
|
||||
"m_Id": "7031ac0f15d6433193753c90272138f5"
|
||||
}
|
||||
],
|
||||
"synonyms": [],
|
||||
"m_Precision": 0,
|
||||
"m_PreviewExpanded": true,
|
||||
"m_PreviewMode": 0,
|
||||
"m_CustomColors": {
|
||||
"m_SerializableColors": []
|
||||
},
|
||||
"m_Property": {
|
||||
"m_Id": "26abb75110b74b5788e84f3884bb5b9b"
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
"m_SGVersion": 0,
|
||||
"m_Type": "UnityEditor.ShaderGraph.Vector3MaterialSlot",
|
||||
"m_ObjectId": "635824bf074747859de54a01319623c7",
|
||||
"m_Id": 0,
|
||||
"m_DisplayName": "positionWS",
|
||||
"m_SlotType": 0,
|
||||
"m_Hidden": false,
|
||||
"m_ShaderOutputName": "positionWS",
|
||||
"m_StageCapability": 3,
|
||||
"m_Value": {
|
||||
"x": 0.0,
|
||||
"y": 0.0,
|
||||
"z": 0.0
|
||||
},
|
||||
"m_DefaultValue": {
|
||||
"x": 0.0,
|
||||
"y": 0.0,
|
||||
"z": 0.0
|
||||
},
|
||||
"m_Labels": []
|
||||
}
|
||||
|
||||
{
|
||||
"m_SGVersion": 0,
|
||||
"m_Type": "UnityEditor.ShaderGraph.Vector3MaterialSlot",
|
||||
"m_ObjectId": "7031ac0f15d6433193753c90272138f5",
|
||||
"m_Id": 0,
|
||||
"m_DisplayName": "World Position",
|
||||
"m_SlotType": 1,
|
||||
"m_Hidden": false,
|
||||
"m_ShaderOutputName": "Out",
|
||||
"m_StageCapability": 3,
|
||||
"m_Value": {
|
||||
"x": 0.0,
|
||||
"y": 0.0,
|
||||
"z": 0.0
|
||||
},
|
||||
"m_DefaultValue": {
|
||||
"x": 0.0,
|
||||
"y": 0.0,
|
||||
"z": 0.0
|
||||
},
|
||||
"m_Labels": []
|
||||
}
|
||||
|
||||
{
|
||||
"m_SGVersion": 1,
|
||||
"m_Type": "UnityEditor.ShaderGraph.CustomFunctionNode",
|
||||
"m_ObjectId": "e31739b3fc354a59b9d0f62f82928767",
|
||||
"m_Group": {
|
||||
"m_Id": ""
|
||||
},
|
||||
"m_Name": "SampleWaterHeight (Custom Function)",
|
||||
"m_DrawState": {
|
||||
"m_Expanded": true,
|
||||
"m_Position": {
|
||||
"serializedVersion": "2",
|
||||
"x": -476.0,
|
||||
"y": -122.0,
|
||||
"width": 268.0,
|
||||
"height": 245.0
|
||||
}
|
||||
},
|
||||
"m_Slots": [
|
||||
{
|
||||
"m_Id": "635824bf074747859de54a01319623c7"
|
||||
},
|
||||
{
|
||||
"m_Id": "234c6a1822174833a15cf2979860bb36"
|
||||
}
|
||||
],
|
||||
"synonyms": [
|
||||
"code",
|
||||
"HLSL"
|
||||
],
|
||||
"m_Precision": 1,
|
||||
"m_PreviewExpanded": false,
|
||||
"m_PreviewMode": 0,
|
||||
"m_CustomColors": {
|
||||
"m_SerializableColors": []
|
||||
},
|
||||
"m_SourceType": 0,
|
||||
"m_FunctionName": "SampleWaterHeight",
|
||||
"m_FunctionSource": "1318138c4ac146af86a745a7082ac2a8",
|
||||
"m_FunctionBody": "Enter function body here..."
|
||||
}
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: dd22fdca3349c96428d4bdb4219a1210
|
||||
ScriptedImporter:
|
||||
internalIDToNameTable: []
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
script: {fileID: 11500000, guid: 60072b568d64c40a485e0fc55012dc9f, type: 3}
|
||||
70
LocalPackages/StylizedWater2/Shaders/WaterCutoutMask.shader
Normal file
70
LocalPackages/StylizedWater2/Shaders/WaterCutoutMask.shader
Normal file
@@ -0,0 +1,70 @@
|
||||
Shader "Stylized Water 2/Cutout"
|
||||
{
|
||||
Properties
|
||||
{
|
||||
//[CurvedWorldBendSettings] _CurvedWorldBendSettings("0|1|1", Vector) = (0, 0, 0, 0)
|
||||
}
|
||||
SubShader
|
||||
{
|
||||
PackageRequirements
|
||||
{
|
||||
"com.unity.render-pipelines.core": "10.3.2"
|
||||
"com.unity.render-pipelines.universal": "10.3.2"
|
||||
}
|
||||
Tags { "RenderPipeline" = "UniversalPipeline" "Queue" = "Transparent-1" }
|
||||
ColorMask 0
|
||||
ZWrite On
|
||||
|
||||
Pass
|
||||
{
|
||||
Name "Depth mask"
|
||||
|
||||
HLSLPROGRAM
|
||||
#pragma multi_compile_instancing
|
||||
|
||||
#include "Libraries/URP.hlsl"
|
||||
//#define CURVEDWORLD_BEND_TYPE_CLASSICRUNNER_X_POSITIVE
|
||||
//#define CURVEDWORLD_BEND_ID_1
|
||||
//#pragma shader_feature_local CURVEDWORLD_DISABLED_ON
|
||||
//#include "Assets/Amazing Assets/Curved World/Shaders/Core/CurvedWorldTransform.cginc"
|
||||
|
||||
struct Attributes
|
||||
{
|
||||
float4 positionOS : POSITION;
|
||||
UNITY_VERTEX_INPUT_INSTANCE_ID
|
||||
};
|
||||
|
||||
struct Varyings
|
||||
{
|
||||
float4 positionCS : SV_POSITION;
|
||||
|
||||
UNITY_VERTEX_INPUT_INSTANCE_ID
|
||||
UNITY_VERTEX_OUTPUT_STEREO
|
||||
};
|
||||
|
||||
#pragma vertex vert
|
||||
#pragma fragment frag
|
||||
|
||||
Varyings vert(Attributes input)
|
||||
{
|
||||
Varyings output = (Varyings)0;
|
||||
|
||||
UNITY_SETUP_INSTANCE_ID(input);
|
||||
UNITY_TRANSFER_INSTANCE_ID(input, output);
|
||||
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output);
|
||||
|
||||
#if defined(CURVEDWORLD_IS_INSTALLED) && !defined(CURVEDWORLD_DISABLED_ON)
|
||||
CURVEDWORLD_TRANSFORM_VERTEX(input.positionOS)
|
||||
#endif
|
||||
|
||||
output.positionCS = TransformObjectToHClip(input.positionOS.xyz);
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
half4 frag() : SV_Target { return 0; }
|
||||
|
||||
ENDHLSL
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e514f2e4744b19b4391655cd17b5db89
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user