noise 2d grass shader w/ custom texture overlay
this is a 2d grass shader it.
Works on tilemaplayer
how to set it up:
for pixel perfect look leave it as it is BUT noise and noise2 for best look both should be cellular and domain warp should be on the rest do as you want with it.
also you should change around the Fractal and Cellular to your liking.
the noise should be diffrent from each other.
you can apply alpha by turning it on and setting the value.
if you want a smoother look change the “filter_nearest” to “filter_linear” inside the shader in noise and noise2.
color modifiers modify already existing texture.
Texture overlay part:
insert texture grass texture if you dont set it then it wont do anything(related to grass texture).
each color mul under texture is to said texture based on noise
it also changes the defult color of the texture
the texture NEEDS to be BLACK (0,0,0) AND WHITE(255,255,255)
note:
there is no 1 becuse i dont want to implement it.
Shader code
shader_type canvas_item;
uniform sampler2D noise:filter_nearest,repeat_enable;
uniform sampler2D noise2:filter_nearest,repeat_enable;
varying vec2 world_pos;
uniform float scale:hint_range(0.0, 10000.0, 20.0)=500.0;
//uniform float color_modifier:hint_range(0.0, 5.0, 0.01)=1.0;
uniform float color_modifier2:hint_range(0.0, 5.0, 0.01)=0.9;
uniform float color_modifier3:hint_range(0.0, 5.0, 0.01)=.8;
uniform float color_modifier4:hint_range(0.0, 5.0, 0.01)=0.85;
uniform float amount_covered:hint_range(0.0, 1.0, 0.01)=0.5;
uniform float alpha2:hint_range(0.0, 1.0, 0.01)=1.0;
uniform float alpha3:hint_range(0.0, 1.0, 0.01)=1.0;
uniform float alpha4:hint_range(0.0, 1.0, 0.01)=1.0;
//uniform bool col_alph1=false;
uniform bool col_alph2=false;
uniform bool col_alph3=false;
uniform bool col_alph4=false;
uniform sampler2D grass_tex:repeat_enable,filter_nearest;
uniform float grass_amount=16.0;
uniform float col_grass_mul:hint_range(0.0, 1.0, 0.01)=.97;
uniform float gr_mul_amount_added2:hint_range(-1.0, 1.0, 0.01)=0.05;
uniform float gr_mul_amount_added3:hint_range(-1.0, 1.0, 0.01)=0.05;
uniform float gr_mul_amount_added4:hint_range(-1.0, 1.0, 0.01)=0.04;
uniform sampler2D grass_tex2:repeat_enable,filter_nearest;
uniform float grass_amount2=16.0;
uniform float col_grass_mul2:hint_range(0.0, 1.0, 0.01)=.97;
uniform float gr_mul_amount_added22:hint_range(-1.0, 1.0, 0.001)=0.05;
uniform float gr_mul_amount_added32:hint_range(-1.0, 1.0, 0.001)=0.05;
uniform float gr_mul_amount_added42:hint_range(-1.0, 1.0, 0.001)=0.04;
void vertex(){
world_pos = (MODEL_MATRIX * vec4(VERTEX, 0.0, 1.0)).xy;
}
void fragment() {
vec4 noise_tex = texture(noise,world_pos/scale);
vec4 noise_tex2 = texture(noise2,world_pos/scale);
vec4 tex_tex = texture(TEXTURE,UV);
float ACM = 1.0;
float AAC = ACM-amount_covered;
float mult_gr=col_grass_mul;
float mult_gr2=col_grass_mul2;
if (noise_tex.r<=AAC)
if (col_alph2==true){
mult_gr+=gr_mul_amount_added2;
mult_gr2+=gr_mul_amount_added22;
COLOR = vec4(tex_tex.rgb*color_modifier2,alpha2);}
else{
mult_gr2+=gr_mul_amount_added22;
COLOR = vec4(tex_tex.rgb*color_modifier2,noise_tex.a);
mult_gr+=gr_mul_amount_added2;}
else if (noise_tex2.r>=AAC)
if (col_alph3==true){
mult_gr2+=gr_mul_amount_added32;
mult_gr+=gr_mul_amount_added3;
COLOR = vec4(tex_tex.rgb*color_modifier3,alpha3);}
else{
mult_gr2+=gr_mul_amount_added32;
mult_gr+=gr_mul_amount_added3;
COLOR = vec4(tex_tex.rgb*color_modifier3,noise_tex2.a);}
else if (noise_tex2.r<=AAC)
if (col_alph4==true){
mult_gr2+=gr_mul_amount_added42;
mult_gr+=gr_mul_amount_added4;
COLOR = vec4(tex_tex.rgb*color_modifier4,alpha4);}
else{
mult_gr2+=gr_mul_amount_added42;
mult_gr+=gr_mul_amount_added4;
COLOR = vec4(tex_tex.rgb*color_modifier4,noise_tex2.a);}
//special grass tex
vec4 special_grass_tex = texture(grass_tex,world_pos/grass_amount);
//special grass tex 2
vec4 special_grass_tex2 = texture(grass_tex2,world_pos/grass_amount2);
if (special_grass_tex.rgb==vec3(1.0))
COLOR *= vec4(mult_gr);
if (special_grass_tex2.rgb==vec3(1.0))
COLOR *= vec4(mult_gr2);
}



