[M] random by world pos

This commit is contained in:
2025-03-05 22:04:25 +08:00
parent a1b10ded5c
commit cb050e34d2
3 changed files with 482 additions and 37 deletions

View File

@@ -4,10 +4,6 @@ Shader "zzwater/testshader"
Properties
{
_MainTex ("Albedo (RGB)", 2D) = "white" {}
_SwayFreq("Sway Frequency", Range(0,10)) = 1.0
_SubFreq("sub Frequency", Range(0,100)) = 1.0
_SwayIntensity("Sway Intensity", Range(0,2)) = 0.1
_WindDir("Wind Direction", Vector) = (1,0,0,0)
}
SubShader
@@ -35,54 +31,38 @@ Shader "zzwater/testshader"
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"
sampler2D _MainTex;
float4 _MainTex_ST;
struct Attributes {
float4 positionOS : POSITION;
float2 uv : TEXCOORD0;
float3 normalOS : NORMAL;
float4 color : COLOR;
};
struct Varyings
{
float4 positionHCS : SV_POSITION;
float2 uv : TEXCOORD0;
float3 normalWS : TEXCOORD1;
float4 color : TEXCOORD2;
float r1 : TEXCOORD3;
float3 phase: TEXTCOORD1;
};
sampler2D _MainTex;
float4 _MainTex_ST;
half _SwayFreq;
half _SubFreq;
half _SwayIntensity;
float4 _WindDir;
Varyings vert (Attributes v)
{
Varyings o;
o.positionHCS = TransformObjectToHClip(v.positionOS.xyz);
o.normalWS = TransformObjectToWorldNormal(v.normalOS);
float4x4 mx = GetObjectToWorldMatrix();
o.positionHCS = TransformObjectToHClip(v.positionOS);
float factor = dot(float3(mx[0].w, mx[1].w, mx[2].w), 1);
o.phase = sin(_Time.y * factor);
o.uv = TRANSFORM_TEX(v.uv, _MainTex);
o.color = v.color;
//o.r1 = dot(unity_ObjectToWorld[3].xyz, 1);;
float3 positionWS = TransformObjectToWorld(v.positionOS.xyz);
o.r1 = frac(dot(positionWS, 1));
return o;
}
half4 frag (Varyings i) : SV_Target
{
half4 albedo = tex2D(_MainTex, i.uv);
//clip(albedo.a - 0.5);
return half4(i.r1,0,0, 1.0);
return half4(albedo.rgb, 1.0);
//Light mainLight = GetMainLight(TransformWorldToShadowCoord(i.positionHCS));
// 简易光照模型[^2]
//half3 diffuse = mainLight.color * saturate(dot(i.normalWS, mainLight.direction));
//return half4(albedo.rgb * diffuse, 1.0);
clip(albedo.a - 0.5);
return float4(i.phase.xxx, 1);
}
ENDHLSL
}