Quantcast
Viewing latest article 26
Browse Latest Browse All 169

Can someone please help me simulate wind in this shader I'm working on?

So, I'm using a shader along with a c# script to instantiate grass meshes in my scene. The C# script provides the positions where the grass should be created at and passes it to the positions buffer in my shader. That's all working well enough, but I want to add simple wind simulation to the grass, but I don't know how to do it. Any help would mean so much. Here is my shader: Shader "Unlit/Grass" { Properties { _MainTex ("Albedo (RGB)", 2D) = "white" {} _Albedo1 ("Albedo 1", Color) = (1, 1, 1) _Albedo2 ("Albedo 2", Color) = (1, 1, 1) _AOColor ("Ambient Occlusion", Color) = (1, 1, 1) _TipColor ("Tip Color", Color) = (1, 1, 1) _Scale ("Scale", Range(0.0, 2.0)) = 0.0 } SubShader { Tags { "RenderType"="Opaque" } LOD 100 Cull Off HLSLINCLUDE #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl" #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl" CBUFFER_START(UnityPerMaterial) float4 _Albedo1, _Albedo2, _AOColor, _TipColor, _WorldSize; float _Scale; CBUFFER_END StructuredBuffer positionBuffer; struct VertexInput { float4 position : POSITION; float2 uv : TEXCOORD0; }; struct VertexOutput { float4 position : SV_POSITION; float2 uv : TEXCOORD0; }; ENDHLSL Pass { HLSLPROGRAM #pragma vertex vert #pragma fragment frag VertexOutput vert(VertexInput i, uint instanceID : SV_InstanceID) { float3 data = positionBuffer[instanceID]; float3 localPosition = i.position.xyz; float3 worldPosition = data.xyz + localPosition; VertexOutput o; o.position = mul(UNITY_MATRIX_VP, float4(worldPosition, 1.0f)); o.uv = i.uv; return o; } float4 frag(VertexOutput i) : SV_Target { float4 col = lerp(_Albedo1, _Albedo2, i.uv.y); float4 ao = lerp(_AOColor, 1.0f, i.uv.y); float4 tip = lerp(0.0f, _TipColor, i.uv.y * i.uv.y * (1.0f + _Scale)); return (col + tip) * ao; } ENDHLSL } } } TIA!

Viewing latest article 26
Browse Latest Browse All 169

Trending Articles