//////////////////////////////////////////////// // // particle shaders // //////////////////////////////////////////////// // wobbles the vertices of an explosion sphere // and generates all texcoords // and blends the edge color // and modulates the texture explosionshader = [ shader 0 $arg1 [ //:fog in vec4 vvertex, vcolor; uniform mat4 explosionmatrix; uniform vec3 center; uniform float millis; in vec2 vtexcoord0; uniform vec4 texgenS, texgenT; @(? (>= (strstr $arg1 "soft") 0) [ uniform vec2 lineardepthscale; out float lineardepth; ]) out vec4 color; out vec2 texcoord0, texcoord1, texcoord2; void main(void) { vec4 wobble = vec4(vvertex.xyz*(1.0 + 0.5*abs(fract(dot(vvertex.xyz, center) + millis*2.0) - 0.5)), vvertex.w); gl_Position = explosionmatrix * wobble; @(? (>= (strstr $arg1 "soft") 0) [ lineardepth = dot(lineardepthscale, gl_Position.zw); ]) color = vcolor; texcoord0 = vtexcoord0; vec2 texgen = vec2(dot(texgenS, vvertex), dot(texgenT, vvertex)); texcoord1 = texgen; texcoord2 = 0.5*texgen - millis*0.5; } ] [ @(if (>= (strstr $arg1 "soft") 0) [result [ @(gfetchdefs tex2) uniform vec3 softparams; in float lineardepth; ]]) in vec4 color; in vec2 texcoord0, texcoord1, texcoord2; uniform sampler2D tex0; uniform vec2 blendparams; layout(location = 0) out vec4 fragcolor; void main(void) { vec2 dtc = texcoord0 + texture(tex0, texcoord2).xy*0.1; // use color texture as noise to distort texcoords vec4 diffuse = texture(tex0, dtc); float blend = max(pow(clamp(1.0 - dot(texcoord1, texcoord1), 0.0, 1.0), blendparams.x), blendparams.y); diffuse *= blend*4.0; // dup alpha into RGB channels + intensify and over saturate diffuse.b += 0.5 - blend*0.5; // blue tint @(if (>= (strstr $arg1 "soft") 0) [result [ fragcolor.rgb = diffuse.rgb * color.rgb; @(gdepthunpack depth [gfetch(tex2, gl_FragCoord.xy)]) fragcolor.a = diffuse.a * max(clamp((depth - lineardepth)*softparams.x - softparams.y, 0.0, 1.0) * color.a, softparams.z); ]] [result [ fragcolor = diffuse * color; ]]) } ] ] explosionshader "explosion" explosionshader "explosionsoft" shader 0 "particlenotexture" [ //:fog in vec4 vvertex, vcolor; uniform mat4 camprojmatrix; uniform vec4 colorscale; out vec4 color; void main(void) { gl_Position = camprojmatrix * vvertex; color = vcolor * colorscale; } ] [ in vec4 color; layout(location = 0) out vec4 fragcolor; void main(void) { fragcolor = color; } ] shader 0 "particletext" [ //:fog in vec4 vvertex, vcolor; in vec2 vtexcoord0; uniform mat4 camprojmatrix; uniform float ldrscale; out vec4 color; out vec2 texcoord0; void main(void) { gl_Position = camprojmatrix * vvertex; texcoord0 = vtexcoord0; color = vec4(vcolor.rgb * ldrscale, vcolor.a); } ] [ uniform vec4 textparams; uniform sampler2D tex0; in vec4 color; in vec2 texcoord0; layout(location = 0) out vec4 fragcolor; void main(void) { float dist = texture(tex0, texcoord0).r; float border = smoothstep(textparams.x, textparams.y, dist); float outline = smoothstep(textparams.z, textparams.w, dist); fragcolor = vec4(color.rgb * outline, color.a * border); } ] particleshader = [ shader 0 $arg1 [ //:fog in vec4 vvertex, vcolor; in vec2 vtexcoord0; uniform mat4 camprojmatrix; uniform vec4 colorscale; out vec4 color; out vec2 texcoord0; @(? (>= (strstr $arg1 "soft") 0) [ uniform vec2 lineardepthscale; out float lineardepth; out vec2 surface; ]) void main(void) { gl_Position = camprojmatrix * vvertex; texcoord0 = vtexcoord0; color = vcolor * colorscale; @(? (>= (strstr $arg1 "soft") 0) [ lineardepth = dot(lineardepthscale, gl_Position.zw); surface = vtexcoord0.xy*2.82842712474619 - 1.4142135623731; ]) } ] [ @(if (>= (strstr $arg1 "soft") 0) [result [ @(gfetchdefs tex2) uniform vec3 softparams; in float lineardepth; in vec2 surface; ]]) uniform sampler2D tex0; in vec4 color; in vec2 texcoord0; layout(location = 0) out vec4 fragcolor; void main(void) { vec4 diffuse = texture(tex0, texcoord0); @(if (>= (strstr $arg1 "soft") 0) [result [ @(gdepthunpack depth [gfetch(tex2, gl_FragCoord.xy)]) diffuse.a *= clamp((depth - lineardepth)*softparams.x - softparams.y - dot(surface, surface), 0.0, 1.0); ]]) fragcolor = diffuse * color; } ] ] particleshader "particle" particleshader "particlesoft"