hellcat-nardo-felidal/Assets/Dragon/Materials/OptimizedShaders/Blush/CGI_PoiVertexManipulations.cginc

77 lines
4.1 KiB
HLSL
Raw Normal View History

2023-09-10 04:16:23 +00:00
#ifndef POI_VERTEX_MANIPULATION
#define POI_VERTEX_MANIPULATION
#include "/CGI_PoiMath.cginc"
float4 _VertexManipulationLocalTranslation;
float4 _VertexManipulationLocalRotation;
float4 _VertexManipulationLocalScale;
float4 _VertexManipulationWorldTranslation;
float _VertexManipulationHeight;
float _VertexManipulationHeightBias;
#if defined(PROP_VERTEXMANIPULATIONHEIGHTMASK) || !defined(OPTIMIZER_ENABLED)
sampler2D _VertexManipulationHeightMask; float4 _VertexManipulationHeightMask_ST;
#endif
float2 _VertexManipulationHeightPan;
float _EnableVertexGlitch;
float _VertexGlitchThreshold;
float _VertexGlitchFrequency;
float _VertexGlitchStrength;
float _VertexRoundingDivision;
float _VertexRoundingEnabled;
void applyLocalVertexTransformation(inout float3 normal, inout float4 tangent, inout float4 vertex)
{
normal = rotate_with_quaternion(normal, float4(0,0,0,1).xyz);
tangent.xyz = rotate_with_quaternion(tangent.xyz, float4(0,0,0,1).xyz);
vertex = transform(vertex, float4(0,0,0,1), float4(0,0,0,1), float4(1,1,1,1));
}
void applyLocalVertexTransformation(inout float3 normal, inout float4 vertex)
{
normal = rotate_with_quaternion(normal, float4(0,0,0,1).xyz);
vertex = transform(vertex, float4(0,0,0,1), float4(0,0,0,1), float4(1,1,1,1));
}
void applyWorldVertexTransformation(inout float4 worldPos, inout float4 localPos, inout float3 worldNormal, float2 uv)
{
#if defined(PROP_VERTEXMANIPULATIONHEIGHTMASK) || !defined(OPTIMIZER_ENABLED)
float3 heightOffset = (tex2Dlod(_VertexManipulationHeightMask, float4(TRANSFORM_TEX(uv, _VertexManipulationHeightMask) + float4(0,0,0,0) * _Time.x, 0, 0)).r - (0.0 /*_VertexManipulationHeightBias*/)) * (0.0 /*_VertexManipulationHeight*/) * worldNormal;
#else
float3 heightOffset = (0.0 /*_VertexManipulationHeight*/) * worldNormal;
#endif
worldPos.rgb += float4(0,0,0,1).xyz/* * float4(0,0,0,1).w*/ + heightOffset;
localPos.xyz = mul(unity_WorldToObject, worldPos).xyz;
}
void applyWorldVertexTransformationShadow(inout float4 worldPos, inout float4 localPos, float3 worldNormal, float2 uv)
{
#if defined(PROP_VERTEXMANIPULATIONHEIGHTMASK) || !defined(OPTIMIZER_ENABLED)
float3 heightOffset = (tex2Dlod(_VertexManipulationHeightMask, float4(TRANSFORM_TEX(uv, _VertexManipulationHeightMask) + float4(0,0,0,0) * _Time.x, 0, 0)).r - (0.0 /*_VertexManipulationHeightBias*/)) * (0.0 /*_VertexManipulationHeight*/) * worldNormal;
#else
float3 heightOffset = (0.0 /*_VertexManipulationHeight*/) * worldNormal;
#endif
worldPos.rgb += float4(0,0,0,1).xyz/* * float4(0,0,0,1).w*/ + heightOffset;
localPos.xyz = mul(unity_WorldToObject, worldPos).xyz;
}
void applyVertexRounding(inout float4 worldPos, inout float4 localPos)
{
if ((0.0 /*_VertexRoundingEnabled*/))
{
worldPos.xyz = (ceil(worldPos.xyz * (500.0 /*_VertexRoundingDivision*/)) / (500.0 /*_VertexRoundingDivision*/)) - 1 / (500.0 /*_VertexRoundingDivision*/) * .5;
localPos = mul(unity_WorldToObject, worldPos);
}
}
void applyVertexGlitching(inout float4 worldPos, inout float4 localPos)
{
if(_EnableVertexGlitch)
{
float3 forward = getCameraPosition() - mul(unity_ObjectToWorld, float4(0, 0, 0, 1)).xyz;
forward.y = 0;
forward = normalize(forward);
float3 glitchDirection = normalize(cross(float3(0, 1, 0), forward));
float glitchAmount = frac(sin(dot(_Time.xy + worldPos.y, float2(12.9898, 78.233))) * 43758.5453123) * 2 - 1;
float time = _Time.y * _VertexGlitchFrequency;
float randomGlitch = (sin(time) + sin(2.2 * time + 5.52) + sin(2.9 * time + 0.93) + sin(4.6 * time + 8.94)) / 4;
worldPos.xyz += glitchAmount * glitchDirection * (_VertexGlitchStrength * .01) * step(_VertexGlitchThreshold, randomGlitch);
localPos = mul(unity_WorldToObject, worldPos);
}
}
#endif