Last active
January 17, 2025 07:47
-
-
Save TarasOsiris/e0e6e6c3b8fdb0d8074b to your computer and use it in GitHub Desktop.
Flow Map Shader for Unity3D. Used with Sprites.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Shader "Custom/Flow Map" | |
{ | |
Properties | |
{ | |
[PerRendererData] _MainTex ("Sprite Texture", 2D) = "white" {} | |
_Color ("Tint", Color) = (1,1,1,1) | |
// Flow | |
_FlowMap ("Flow Map", 2D) = "white" {} | |
_FlowSpeed ("Flow Speed", float) = 0.05 | |
[MaterialToggle] PixelSnap ("Pixel snap", Float) = 0 | |
} | |
SubShader | |
{ | |
Tags | |
{ | |
"Queue"="Transparent" | |
"IgnoreProjector"="True" | |
"RenderType"="Transparent" | |
"PreviewType"="Plane" | |
"CanUseSpriteAtlas"="True" | |
} | |
Cull Off | |
Lighting Off | |
ZWrite Off | |
Blend One OneMinusSrcAlpha | |
Pass | |
{ | |
CGPROGRAM | |
#pragma vertex vert | |
#pragma fragment frag | |
#pragma multi_compile _ PIXELSNAP_ON | |
#include "UnityCG.cginc" | |
struct appdata_t | |
{ | |
float4 vertex : POSITION; | |
float4 color : COLOR; | |
float2 texcoord : TEXCOORD0; | |
}; | |
struct v2f | |
{ | |
float4 vertex : SV_POSITION; | |
fixed4 color : COLOR; | |
half2 texcoord : TEXCOORD0; | |
}; | |
fixed4 _Color; | |
v2f vert(appdata_t IN) | |
{ | |
v2f OUT; | |
OUT.vertex = mul(UNITY_MATRIX_MVP, IN.vertex); | |
OUT.texcoord = IN.texcoord; | |
OUT.color = IN.color * _Color; | |
#ifdef PIXELSNAP_ON | |
OUT.vertex = UnityPixelSnap (OUT.vertex); | |
#endif | |
return OUT; | |
} | |
sampler2D _MainTex; | |
sampler2D _FlowMap; | |
float _FlowSpeed; | |
fixed4 frag(v2f IN) : SV_Target | |
{ | |
float3 flowDir = tex2D(_FlowMap, IN.texcoord) * 2.0f - 1.0f; | |
flowDir *= _FlowSpeed; | |
float phase0 = frac(_Time[1] * 0.5f + 0.5f); | |
float phase1 = frac(_Time[1] * 0.5f + 1.0f); | |
half3 tex0 = tex2D(_MainTex, IN.texcoord + flowDir.xy * phase0); | |
half3 tex1 = tex2D(_MainTex, IN.texcoord + flowDir.xy * phase1); | |
float flowLerp = abs((0.5f - phase0) / 0.5f); | |
half3 finalColor = lerp(tex0, tex1, flowLerp); | |
fixed4 c = float4(finalColor, 1.0f) * IN.color; | |
c.rgb *= c.a; | |
return c; | |
} | |
ENDCG | |
} | |
} | |
} |
@ipud2 remove "[PerRendererData]" and it works just fine
additionally, you may want to comment out these either:
Cull Off
Lighting Off
ZWrite Off
Blend One OneMinusSrcAlpha
shit code dose not work!!!
You're kind of a jerk, and not very bright, apparently.
For what it's worth, I used this code in my own project and it works fine (with modifications to fit my specific needs).
you can test this code yourself,just do not work! ------------------ 原始邮件 ------------------
***@***.***>
发送时间: 2021年7月4日(星期天) 凌晨4:16
***@***.***>;
***@***.******@***.***>;
主题: Re: TarasOsiris/FlowMap.shader
It works, but not perfect, you can check my blog below
https://blog.csdn.net/weixinyi21cn/article/details/121017117
or you can read this paper: http://graphicsrunner.blogspot.com/2010/08/water-using-flow-maps.html
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
shit code dose not work!!!