Files
MinFt/Client/LocalPackages/zzwater/shaders/libs/Common.hlsl
2026-04-27 12:07:32 +08:00

65 lines
1.6 KiB
HLSL

#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