71 lines
2.2 KiB
INI
71 lines
2.2 KiB
INI
////////////////////////////////////////////////
|
|
//
|
|
// 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;
|
|
attribute vec4 vtangent;
|
|
uniform mat4 camprojmatrix;
|
|
uniform vec3 camera;
|
|
uniform vec3 grassmargin;
|
|
@(ginterpvert)
|
|
varying vec2 texcoord0;
|
|
varying vec4 colorscale;
|
|
varying vec2 bounds;
|
|
@(? (grassopt "b") [uniform vec4 blendmapparams; varying vec2 texcoord1;])
|
|
void main(void)
|
|
{
|
|
gl_Position = camprojmatrix * vvertex;
|
|
colorscale = vcolor;
|
|
texcoord0 = vtexcoord0;
|
|
vec2 camdir = (camera.xy - vvertex.xy) * grassmargin.y;
|
|
bounds = vec2(dot(camdir, vtangent.xy), dot(camdir, vtangent.zw)) + grassmargin.z;
|
|
@(? (grassopt "b") [
|
|
texcoord1 = (vvertex.xy - blendmapparams.xy)*blendmapparams.zw;
|
|
])
|
|
@(gdepthpackvert)
|
|
}
|
|
] [
|
|
uniform sampler2D tex0;
|
|
uniform float grasstest;
|
|
@(ginterpfrag)
|
|
varying vec2 texcoord0;
|
|
varying vec4 colorscale;
|
|
varying vec2 bounds;
|
|
@(? (grassopt "b") [uniform sampler2D tex1; varying vec2 texcoord1;])
|
|
void main(void)
|
|
{
|
|
vec4 color = texture2D(tex0, texcoord0) * colorscale;
|
|
color.a *= clamp(min(bounds.x, bounds.y), 0.0, 1.0);
|
|
@(? (grassopt "b") [
|
|
color.a *= texture2D(tex1, texcoord1).r;
|
|
])
|
|
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)
|
|
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")
|
|
]
|
|
|