备份CatanBuilding瘦身独立工程

This commit is contained in:
JSD\13999
2026-05-26 16:15:54 +08:00
commit 2d0e6a61b7
12001 changed files with 2431925 additions and 0 deletions

View File

@@ -0,0 +1,64 @@
#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.
//#define TIME_FRAG_INPUT input.uv.z
//#define TIME_VERTEX_OUTPUT output.uv.z
//#define TIME ((TIME_FRAG_INPUT * _Speed) * -_Direction.xy)
//#define TIME_VERTEX ((TIME_VERTEX_OUTPUT * _Speed) * -_Direction.xy)
#define TIME_VERTEX ((_TimeParameters.x * _Speed) * -_Direction.xy)
#define HORIZONTAL_DISPLACEMENT_SCALAR 0.01
#define UP_VECTOR float3(0,1,0)
#define RAD2DEGREE 57.29578
struct WaterSurface
{
float3 positionWS;
float3 viewDelta; //Un-normalized view direction,
float3 viewDir;
//Normal from the base geometry, in world-space
float3 vertexNormal;
float3 tangentNormal;
float3 tangentWorldNormal;
float3 albedo;
float3 offset;
float alpha;
float fog;
float edgeFade;
float intersection;
float3 reflections;
float reflectionMask;
};
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 (FAR_CLIP - NEAR_CLIP)
//Return depth based on the used technique (buffer, vertex color, baked texture)
SceneDepth SampleDepth(float2 uv)
{
SceneDepth depth = (SceneDepth)0;
float raw = SampleSceneDepth(uv);
depth.raw = raw;
depth.eye = LinearEyeDepth(raw, _ZBufferParams);
depth.linear01 = Linear01Depth(raw, _ZBufferParams) * DEPTH_SCALAR;
return depth;
}
#endif

View File

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

View File

@@ -0,0 +1,235 @@
struct SceneData
{
float4 positionNDC; //Unnormalized
float2 screenPos; //Normalized and no refraction
float3 positionWS;
float3 color;
float refractionMask;
float viewDepth;
float verticalDepth;
};
// Project from eye space to world space
#define WorldPosFromDepth(NDCw, depth, viewDir) -(depth.eye * (viewDir/NDCw) - _WorldSpaceCameraPos)
//Linear depth difference between scene and current (transparent) geometry pixel
#define SurfaceDepth(depth, positionCS) depth.eye - LinearEyeDepth(positionCS.z, _ZBufferParams)
void PopulateSceneData(inout SceneData scene, in Varyings input, in WaterSurface water)
{
const float2 screenPos = input.positionNDC.xy / input.positionNDC.w;
scene.positionNDC = input.positionNDC;
scene.screenPos = screenPos;
//Default for disabled depth texture scene.viewDepth = 1;
scene.verticalDepth = 1;
#ifdef _REFRACTION
SceneDepth depth = SampleDepth(screenPos);
float3 positionWS = WorldPosFromDepth(input.positionNDC.w, depth, water.viewDelta);
float viewDepth = SurfaceDepth(depth, input.positionCS);
const float2 refractionOffset = input.normalWS.xz * 0.5 * _RefractionStrength;
SceneDepth depthRefract = SampleDepth(screenPos + refractionOffset);
float3 positionWSRefract = WorldPosFromDepth(input.positionNDC.w, depthRefract, water.viewDelta);
float viewDepthRefract = SurfaceDepth(depthRefract, input.positionCS);
float mask = saturate(viewDepth) * saturate(viewDepthRefract);
scene.positionWS = lerp(positionWS, positionWSRefract, mask);
scene.viewDepth = lerp(viewDepth, viewDepthRefract, mask);
//Distance to opaque geometry in normal direction
scene.verticalDepth = length((water.positionWS - scene.positionWS) * water.vertexNormal);
scene.color = SampleSceneColor(screenPos + refractionOffset * mask);
scene.refractionMask = mask;
#else
SceneDepth depth = SampleDepth(screenPos);
scene.positionWS = WorldPosFromDepth(input.positionNDC.w, depth, water.viewDelta);
scene.viewDepth = SurfaceDepth(depth, input.positionCS);
scene.verticalDepth = length((water.positionWS - scene.positionWS) * water.vertexNormal);
scene.color = SampleSceneColor(screenPos);
scene.refractionMask = 0;
#endif
}
float GetWaterDensity(SceneData scene, float heightScalar, float viewDepthScalar)
{
const float viewDepth = scene.viewDepth;
const float verticalDepth = scene.verticalDepth;
const float depthAttenuation = 1.0 - exp(-viewDepth * viewDepthScalar * 0.1);
const float heightAttenuation = saturate(verticalDepth * heightScalar);
return max(depthAttenuation, heightAttenuation);
}
float4 ForwardPassFragment(Varyings input) : SV_Target
{
WaterSurface water = (WaterSurface)0;
SceneData scene = (SceneData)0;
float3 normalWS = normalize(input.normalWS.xyz);
float3 WorldTangent = input.tangent.xyz;
float3 WorldBiTangent = input.bitangent.xyz;
//wPos.x in w-component
float3 positionWS = float3(input.normalWS.w, input.tangent.w, input.bitangent.w);
water.alpha = 1.0;
water.positionWS = positionWS;
water.viewDelta = _WorldSpaceCameraPos - positionWS;
float3 viewDir = normalize(water.viewDelta);
water.viewDir = viewDir;
water.vertexNormal = normalize(input.normalWS.xyz);
//Normal
water.tangentNormal = float3(0.5, 0.5, 1);
water.tangentWorldNormal = normalWS;
half VdotN = 1.0 - saturate(dot(viewDir, normalWS));
half4 shadowMask = 1.0;
float4 shadowCoords = float4(0, 0, 0, 0);
Light mainLight = GetMainLight(shadowCoords, water.positionWS, shadowMask);
PopulateSceneData(scene, input, water);
//return float4(scene.verticalDepth.xxx, 1);
//return float4(saturate(scene.viewDepth).xxx, 1);
//return float4(scene.color, 1);
water.fog = GetWaterDensity(scene, _DepthHorizontal, _DepthVertical);
//Albedo
float4 baseColor = lerp(_ShallowColor, _BaseColor, water.fog);
water.fog *= baseColor.a;
water.alpha = baseColor.a;
float fresnel = saturate(pow(VdotN, _HorizonDistance)) * _HorizonColor.a;
water.albedo = lerp(baseColor.rgb, _HorizonColor.rgb, fresnel);
water.edgeFade = saturate(scene.verticalDepth / (_EdgeFade * 0.01));
water.alpha *= water.edgeFade;
// Wave Mesure
#if _INTERSECTION || _WAVE_FOAM
float waveMesure = (positionWS.y - _WaveMesureMin) / (_WaveMesureMax - _WaveMesureMin);
float2 nUV = positionWS.xz * _IntersectionTiling;
float foamTexNoise = SAMPLE_TEXTURE2D(_IntersectionNoise, sampler_IntersectionNoise, nUV + TIME_VERTEX/_IntersectionTiling * _IntersectionSpeed).r;
float interSecGradient = 1-saturate(exp(scene.verticalDepth) / _IntersectionLength);
#endif
#ifdef _WAVE_FOAM
// remap wave from [_WaveFoamClipping,1] to [0,1]
//float waveFoamNoise = (waveMesure - _WaveFoamClipping) / (1 - _WaveFoamClipping) * foamTexNoise;
float waveFoamNoise = smoothstep(_WaveFoamClipping.x, _WaveFoamClipping.y, waveMesure * foamTexNoise);
//return float4(waveFoamNoise.xxx, 1);
#else
float waveFoamNoise = 0;
#endif
/* ========
// Intercection
=========== */
#ifdef _INTERSECTION
float intersecMesure = waveMesure * interSecGradient;
float dist = saturate(interSecGradient / _IntersectionFalloff);
float intersecNoise = saturate(foamTexNoise + intersecMesure) * dist + dist;
intersecNoise = smoothstep(_IntersectionClipping, 1, intersecNoise);
#else
float intersecNoise = 0;
#endif
#if _INTERSECTION || _WAVE_FOAM
float noise = saturate(intersecNoise + waveFoamNoise);
water.albedo.rgb = lerp(water.albedo.rgb, _IntersectionColor.rgb, noise);
water.alpha = saturate(water.alpha + interSecGradient);
#else
float noise = 0;
#endif
/* ========
// Causitcs
=========== */
#ifdef _CAUSTICS
float2 cuv = positionWS.xz * _CausticsTiling;
float coffset = TIME_VERTEX/_CausticsTiling * _CausticsSpeed;
float3 caustics1 = SAMPLE_TEXTURE2D(_CausticsTex, sampler_CausticsTex, cuv + coffset).rgb;
float3 caustics2 = SAMPLE_TEXTURE2D(_CausticsTex, sampler_CausticsTex, cuv*0.8 - coffset).rgb;
// Limit distance from cam and verticalDepth
float3 causticsDensity = saturate((1-length(water.viewDelta) / _CausticsClipping.x) * smoothstep(_CausticsClipping.y,1, scene.verticalDepth));
float3 caustics = min(caustics1, caustics2) * _CausticsBrightness * causticsDensity;
#endif
/* ========
// Reflection Prob
=========== */
half3 reflectionVector = reflect(-viewDir, normalWS);
water.reflections = GlossyEnvironmentReflection(reflectionVector, water.positionWS, _ReflectionBlur, 1 ,scene.screenPos.xy);
//Schlick's BRDF fresnel AIR_RI = 1.000293
float cosTheta = saturate(dot(normalWS, viewDir));
water.reflectionMask = pow(max(0.0, 1.000293 - cosTheta), _ReflectionFresnel) * _ReflectionStrength;
water.albedo = lerp(water.albedo, water.reflections.rgb, water.reflectionMask - noise);
// =================== Make ApplyLight simple =========================
// =====Translucency Begin========
float3 lightDir = mainLight.direction;
float3 lightColor = mainLight.color;
float3 emission = 0;
float3 specular = 0;
float scatteringMask = saturate(water.fog + water.edgeFade);
half incident = saturate(dot(lightDir, normalWS)) * _TranslucencyStrengthDirect;
const float lightIntensity = lightColor.r * 0.3 + lightColor.g * 0.59 + lightColor.b * 0.11;
half attenuation = incident * scatteringMask * lightIntensity;
#ifdef _CAUSTICS
emission += lerp(caustics * lightIntensity, _ShallowColor.rgb, attenuation) * mainLight.distanceAttenuation;
#else
emission = lerp(0, _ShallowColor.rgb, attenuation) * mainLight.distanceAttenuation;
#endif
// =====Translucency End========
#ifdef _LIGHT_COLOR
// LightingLambert Light applied here
half3 attenuatedLightColor = lightColor * (mainLight.distanceAttenuation * mainLight.shadowAttenuation);
half3 diffuseColor = LightingLambert(attenuatedLightColor, lightDir, normalWS) + _GlossyEnvironmentColor.rgb * _AmbientStrength;
float3 finalColor = (water.albedo * diffuseColor ) + emission + specular;
#else
float3 finalColor = (water.albedo ) + emission + specular;
#endif
finalColor = lerp(finalColor, _IntersectionColor.rgb, noise);
// =================== Make ApplyLight simple end =========================
finalColor = lerp(scene.color, finalColor, water.fog + noise);
//Apply fog
half fogCoord = InitializeInputDataFog(float4(positionWS,1), input.fogFactor);
finalColor = MixFog(finalColor, fogCoord);
return float4(finalColor, water.alpha);
}

View File

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

View File

@@ -0,0 +1,69 @@
TEXTURE2D(_IntersectionNoise);
SAMPLER(sampler_IntersectionNoise);
TEXTURE2D(_CausticsTex);
SAMPLER(sampler_CausticsTex);
CBUFFER_START(UnityPerMaterial)
float2 _Direction;
float _Speed;
half _AmbientStrength;
#ifdef TESSELLATION_ON
float _TessValue;
float _TessMin;
float _TessMax;
#endif
//Color + Transparency
half4 _BaseColor;
half4 _ShallowColor;
float4 _HorizonColor;
half _HorizonDistance;
float _DepthVertical;
float _DepthHorizontal;
half _EdgeFade;
half _TranslucencyStrengthDirect;
//Reflection + Refraction
float _ReflectionBlur;
float _ReflectionFresnel;
float _ReflectionStrength;
float _RefractionStrength;
//Intercection
float4 _IntersectionColor;
float _IntersectionLength;
half _IntersectionTiling;
half _IntersectionSpeed;
half2 _IntersectionClipping;
half _IntersectionFalloff;
// Wave foam
half _WaveMesureMin;
half _WaveMesureMax;
half2 _WaveFoamClipping;
// Caustics
half _CausticsBrightness;
float _CausticsTiling;
half _CausticsSpeed;
half2 _CausticsClipping;
//Waves
float _WaveSpeed;
half _WaveHeight;
half _WaveNormalStr;
float _WaveDistance;
half2 _WaveFadeDistance;
float _WaveSteepness;
uint _WaveCount;
half4 _WaveDirection;
CBUFFER_END

View File

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

View File

@@ -0,0 +1,168 @@
//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 Attributes
{
float4 positionOS : POSITION;
float4 normalOS : NORMAL;
float4 tangentOS : TANGENT;
UNITY_VERTEX_INPUT_INSTANCE_ID
};
struct Varyings
{
half fogFactor : TEXCOORD1;
//wPos.x in w-component
float4 normalWS : NORMAL;
//wPos.y in w-component
float4 tangent : TANGENT;
//wPos.z in w-component
float4 bitangent : TEXCOORD4;
float4 positionNDC : TEXCOORD5;
float4 positionCS : SV_POSITION;
UNITY_VERTEX_INPUT_INSTANCE_ID
};
struct TessellationFactors
{
float edge[3] : SV_TessFactor;
float inside : SV_InsideTessFactor;
};
struct VertexControl
{
float4 positionOS : INTERNALTESSPOS;
float4 normalOS : NORMAL;
float4 tangentOS : TANGENT;
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;
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;
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) IN.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 IN = (Attributes)0;
Varyings output = (Varyings)0;
TESSELLATION_INTERPOLATE_BARY_URP(positionOS, baryCoords);
TESSELLATION_INTERPOLATE_BARY_URP(normalOS, baryCoords);
TESSELLATION_INTERPOLATE_BARY_URP(tangentOS, baryCoords);
//Tessellation does not work entirely correct with GPU instancing
UNITY_TRANSFER_INSTANCE_ID(input[0], output);
VertexNormalInputs normalInput = GetVertexNormalInputs(IN.normalOS.xyz, IN.tangentOS);
float3 positionWS = TransformObjectToWorld(IN.positionOS.xyz);
WaveInfo waves = GetWaveInfo(positionWS.xz, TIME_VERTEX * _WaveSpeed, _WaveHeight, 1, _WaveFadeDistance.x, _WaveFadeDistance.y);
positionWS += waves.position;
float4 positionCS = TransformWorldToHClip(positionWS);
output.positionCS = positionCS;
float4 ndc = positionCS * 0.5f;
ndc.xy = float2(ndc.x, ndc.y * _ProjectionParams.x) + ndc.w;
ndc.zw = positionCS.zw;
output.positionNDC = ndc;
output.normalWS = float4(waves.normal, positionWS.x);
output.tangent = float4(normalInput.tangentWS, positionWS.y);
output.bitangent = float4(normalInput.bitangentWS, positionWS.z);
output.fogFactor = ComputeFogFactor(positionCS.z);
return output;
}

View File

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

View File

@@ -0,0 +1,35 @@
//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
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareDepthTexture.hlsl"
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareOpaqueTexture.hlsl"
#endif

View File

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

View File

@@ -0,0 +1,64 @@
struct Attributes
{
float4 positionOS : POSITION;
float4 normalOS : NORMAL;
float4 tangentOS : TANGENT;
UNITY_VERTEX_INPUT_INSTANCE_ID
};
struct Varyings
{
half fogFactor : TEXCOORD1;
//wPos.x in w-component
float4 normalWS : NORMAL;
//wPos.y in w-component
float4 tangent : TANGENT;
//wPos.z in w-component
float4 bitangent : TEXCOORD4;
float4 positionNDC : TEXCOORD5;
float4 positionCS : SV_POSITION;
UNITY_VERTEX_INPUT_INSTANCE_ID
};
Varyings LitPassVertex(Attributes input)
{
Varyings output = (Varyings)0;
UNITY_SETUP_INSTANCE_ID(input);
UNITY_TRANSFER_INSTANCE_ID(input, output);
float3 positionWS = TransformObjectToWorld(input.positionOS.xyz);
VertexNormalInputs normalInput = GetVertexNormalInputs(input.normalOS.xyz, input.tangentOS);
//WaveInfo waves = GetWaveInfo(uv, TIME_VERTEX * _WaveSpeed, _WaveHeight, lerp(1, 0, vertexColor.b), _WaveFadeDistance.x, _WaveFadeDistance.y);
WaveInfo waves = GetWaveInfo(positionWS.xz, TIME_VERTEX * _WaveSpeed, _WaveHeight, 1, _WaveFadeDistance.x, _WaveFadeDistance.y);
//waves.normal = normalInput.normalWS;
//waves.position = 0;
//Apply vertex displacements
positionWS += waves.position.xyz;
float4 positionCS = TransformWorldToHClip(positionWS);
output.positionCS = positionCS;
float4 ndc = positionCS * 0.5f;
ndc.xy = float2(ndc.x, ndc.y * _ProjectionParams.x) + ndc.w;
ndc.zw = positionCS.zw;
output.positionNDC = ndc;
output.normalWS = float4(waves.normal, positionWS.x);
output.tangent = float4(normalInput.tangentWS, positionWS.y);
output.bitangent = float4(normalInput.bitangentWS, positionWS.z);
output.fogFactor = ComputeFogFactor(positionCS.z);
return output;
}

View File

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

View File

@@ -0,0 +1,28 @@
//UNITY_SHADER_NO_UPGRADE
#ifndef WATER_OBJ_INCLUDE
#define WATER_OBJ_INCLUDE
#ifndef GET_TF_FROM_M
#define GET_TF_FROM_M(m) dot(float3(m[0].w, m[1].w, m[2].w),1)
#endif
inline float3 GetObjWaveDisplacement(float3 positionOS, float4 waterDir, float freq, float intensity, float factor)
{
float3 positionWS = TransformObjectToWorld(positionOS);
float objFreq = _Time.y * freq + positionWS.y ;
float objPhase = objFreq + GET_TF_FROM_M(GetObjectToWorldMatrix()) * waterDir.w;
float branchPhase = objPhase + dot(positionOS.xyz,1);
float offset = sin(objPhase) + cos(branchPhase);
return normalize(waterDir.xyz) * offset * factor * intensity;
}
void GGetObjWaveDisplacement_float(float3 positionOS, float4 waterDir, float freq, float intensity, float factor, out float3 Out)
{
Out = GetObjWaveDisplacement(positionOS, waterDir, freq, intensity, factor);
}
#endif //WATER_OBJ_INCLUDE

View File

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

View File

@@ -0,0 +1,102 @@
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);
nrml += GerstnerNormal4(position, amplitude, frequency, speed, directionAB, directionCD);
}
#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);
}

View File

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

View File

@@ -0,0 +1,56 @@
//UNITY_SHADER_NO_UPGRADE
#ifndef WIND_ANIM_INCLUDE
#define WIND_ANIM_INCLUDE
inline float4 SmoothCurve( float4 x ) {
return x * x *( 3.0 - 2.0 * x );
}
inline float4 TriangleWave( float4 x ) {
return abs( frac( x + 0.5 ) * 2.0 - 1.0 );
}
inline float4 SmoothTriangleWave( float4 x ) {
return SmoothCurve( TriangleWave( x ) );
}
inline float4 ClothWindAnim(float4 pos, float3 normal, float4 animParams,float4 wind,float2 time)
{
// animParams.x = branch phase
// animParams.y = edge flutter factor
// animParams.z = primary factor
// animParams.w = secondary factor
float fDetailAmp = 0.1f;
float fBranchAmp = 0.3f;
// Phases (object, vertex, branch)
float fObjPhase = dot(unity_ObjectToWorld[3].xyz, 1);
float fBranchPhase = fObjPhase + animParams.x;
float fVtxPhase = dot(pos.xyz, animParams.y + fBranchPhase);
// x is used for edges; y is used for branches
float2 vWavesIn = time + float2(fVtxPhase, fBranchPhase );
// 1.975, 0.793, 0.375, 0.193 are good frequencies
float4 vWaves = (frac( vWavesIn.xxyy * float4(1.975, 0.793, 0.375, 0.193) ) * 2.0 - 1.0);
vWaves = SmoothTriangleWave( vWaves );
float2 vWavesSum = vWaves.xz + vWaves.yw;
// Edge (xz) and branch bending (y)
float3 bend = animParams.y * fDetailAmp * normal.xyz;
bend.y = animParams.w * fBranchAmp;
pos.xyz += ((vWavesSum.xyx * bend)*wind.w + (wind.xyz * vWavesSum.y * animParams.w)) * wind.w;
// Primary bending
// Displace position
pos.xyz += animParams.z * wind.xyz;
return pos;
}
#endif //WIND_ANIM_INCLUDE

View File

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