Skip to content

Instantly share code, notes, and snippets.

@mattatz
Last active April 3, 2022 14:09
Show Gist options
  • Save mattatz/3a4d7d02300abeb9b48b to your computer and use it in GitHub Desktop.
Save mattatz/3a4d7d02300abeb9b48b to your computer and use it in GitHub Desktop.
Simple Line Integral Convolution shader for Unity.
Shader "Mattaz/LIC" {
Properties {
_VectorFieldTex ("Vector Field Texture", 2D) = "white" {}
_NoiseTex ("Noise Texture", 2D) = "white" {}
_FlowLength ("Flow Length", int) = 10
}
SubShader {
Tags { "RenderType"="Opaque" }
LOD 200
CGINCLUDE
#include "UnityCG.cginc"
sampler2D _VectorFieldTex;
float4 _VectorFieldTex_TexelSize;
sampler2D _NoiseTex;
int _FlowLength;
float4 frag (v2f_img IN) : COLOR {
float3 col = tex2D(_NoiseTex, IN.uv);
int w = 0;
float2 v = (tex2D(_VectorFieldTex, IN.uv).xy - 0.5) * 2;
v.x *= _VectorFieldTex_TexelSize.x;
v.y *= _VectorFieldTex_TexelSize.y;
float2 st0 = IN.uv;
for(int i = 0; i < _FlowLength; i++) {
st0 += v;
float3 n = tex2D(_NoiseTex, st0).rgb;
col += n;
w++;
}
float2 st1 = IN.uv;
for(int i = 0; i < _FlowLength; i++) {
st1 -= v;
float3 n = tex2D(_NoiseTex, st1).rgb;
col += n;
w++;
}
col /= w;
return float4(col, 1);
}
ENDCG
Pass {
CGPROGRAM
#pragma vertex vert_img
#pragma fragment frag
ENDCG
}
}
FallBack "Diffuse"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment