OctaCore/config/glsl/grass.cfg

71 lines
2.2 KiB
INI
Raw Permalink Normal View History

2020-04-15 18:39:17 +02:00
////////////////////////////////////////////////
//
// grass shaders
//
////////////////////////////////////////////////
// grasstype:
// b -> blendmap
grassopt = [ >= (strstr $grasstype $arg1) 0 ]
grassvariantshader = [
local grasstype
grasstype = $arg2
variantshader 0 $arg1 (? (grassopt "b") 0 -1) [
attribute vec4 vvertex, vcolor;
attribute vec2 vtexcoord0;
2020-09-11 02:54:14 +02:00
attribute vec4 vtangent;
2020-04-15 18:39:17 +02:00
uniform mat4 camprojmatrix;
2020-09-11 02:54:14 +02:00
uniform vec3 camera;
uniform vec3 grassmargin;
2020-04-15 18:39:17 +02:00
@(ginterpvert)
varying vec2 texcoord0;
varying vec4 colorscale;
2020-09-11 02:54:14 +02:00
varying vec2 bounds;
2020-04-15 18:39:17 +02:00
@(? (grassopt "b") [uniform vec4 blendmapparams; varying vec2 texcoord1;])
void main(void)
{
gl_Position = camprojmatrix * vvertex;
colorscale = vcolor;
2020-09-11 02:54:14 +02:00
texcoord0 = vtexcoord0;
vec2 camdir = (camera.xy - vvertex.xy) * grassmargin.y;
bounds = vec2(dot(camdir, vtangent.xy), dot(camdir, vtangent.zw)) + grassmargin.z;
2020-04-15 18:39:17 +02:00
@(? (grassopt "b") [
texcoord1 = (vvertex.xy - blendmapparams.xy)*blendmapparams.zw;
])
@(gdepthpackvert)
}
] [
uniform sampler2D tex0;
uniform float grasstest;
@(ginterpfrag)
varying vec2 texcoord0;
varying vec4 colorscale;
2020-09-11 02:54:14 +02:00
varying vec2 bounds;
2020-04-15 18:39:17 +02:00
@(? (grassopt "b") [uniform sampler2D tex1; varying vec2 texcoord1;])
void main(void)
{
vec4 color = texture2D(tex0, texcoord0) * colorscale;
2020-09-11 02:54:14 +02:00
color.a *= clamp(min(bounds.x, bounds.y), 0.0, 1.0);
2020-04-15 18:39:17 +02:00
@(? (grassopt "b") [
color.a *= texture2D(tex1, texcoord1).r;
])
2020-09-11 02:54:14 +02:00
vec2 coords = fract((gl_FragCoord.xy - 0.5)*0.5);
float dither = coords.x + 1.5*coords.y - 4.0*coords.x*coords.y + 0.25;
if(color.a <= grasstest * dither)
2020-04-15 18:39:17 +02:00
discard;
gcolor = vec4(color.rgb, 0.0);
@(gnormpack [vec3(0.5, 0.5, 1.0)])
@(gdepthpackfrag)
}
]
]
grassshader = [
shadername = (concatword "grass" $arg1)
grassvariantshader $shadername $arg1
grassvariantshader $shadername (concatword $arg1 "b")
]