Sic Semper Selected Shaders

Particle Post Processing Vertex Shader:
uniform mat4 pMat;
uniform mat4 vMat;
uniform mat4 wMat;
attribute vec4 vPosition;
attribute vec3 vCenter;
attribute vec2 vTexCoords;
attribute float size;
attribute float heat;
varying vec2 texcoords;
varying vec2 center;
varying vec2 pos;
varying float s;
varying float strength;
void main()
{

gl_Position = pMat * vMat * wMat * vPosition;
texcoords = vTexCoords;
vec4 tcenter = pMat * vMat * wMat * vec4(vCenter, 1.0);
center = vec2((tcenter.x/tcenter.w + 1.0)/2.0, (tcenter.y/tcenter.w + 1.0)/2.0);
pos = vec2((gl_Position.x/gl_Position.w + 1.0)/2.0, (gl_Position.y/gl_Position.w + 1.0)/2.0);
vec4 stemp = pMat * vMat * wMat * vec4(size, size, size, 1.0);
s = stemp.x/stemp.w;
strength = heat;

}
Particle Post Processing Fragment Shader(Pseudo-Refraction):
precision mediump float;
uniform sampler2D tex;
uniform sampler2D bg;
uniform vec2 scene;
varying vec2 texcoords;
varying vec2 center;
varying vec2 pos;
varying float s;
varying float strength;
void main()
{

float r1 = texture2D(tex, texcoords).r;
vec2 dist = normalize(pos – center)*(1.0-r1);
//Real Refraction too costly on mobile GPU’s and looks about the same.
vec2 r = -dist*.02;
gl_FragColor = texture2D(bg,vec2(gl_FragCoord.x/scene.x, -1.0+gl_FragCoord.y/scene.y) + (r.xy*r1*strength));

}

Planet Vertex Shader:
uniform mat4 pMat;
uniform mat4 vMat;
uniform mat4 tMat;
uniform mat4 rMat;
uniform vec3 Ambiance;
attribute vec4 vPosition;
attribute vec3 vNormal;
attribute vec2 vTexCoords;
varying vec3 normal;
varying vec3 pos;
varying vec3 relpos;
varying vec3 ambiant_light;
varying vec2 texcoords;
void main()
{

mat4 pvMat = pMat * vMat;
mat4 pvwMat = pvMat * (tMat * rMat);
gl_Position = pvwMat*vPosition;
pos = (tMat*rMat * vPosition).xyz;
relpos = (vMat*tMat*rMat * vPosition).xyz;
normal = normalize((rMat*vec4(vNormal, 1.0)).xyz);
ambiant_light = Ambiance;
texcoords = vTexCoords;

}

Planet Fragment Shader(Per-Pixel Phong Shaded Lighting, using blue/green hue for specularity):
precision mediump float;
uniform sampler2D tex;
varying vec3 normal;
varying vec3 pos;
varying vec3 relpos;
varying vec3 ambiant_light;
varying vec2 texcoords;
void main()
{

vec4 texcolor = vec4(texture2D(tex, texcoords).rgb, 1.0);
vec3 lightdir = normalize(vec3(0.0, 0.0, 0.0) – pos);
vec3 reflectedVector = normalize(reflect(-lightdir, normal));
float specIntensity = max(0.0, dot(normalize(relpos-pos),reflectedVector));
if(dot(lightdir, normal) < 0.0)
specIntensity = 0.0;
float fSpec = pow(specIntensity*0.95, (texcolor.g) + 5.0*(texcolor.b));
gl_FragColor = texcolor * (max(dot(lightdir, normal), 0.0)) + vec4(texcolor.rgb*ambiant_light.rgb + vec3(fSpec, fSpec, fSpec), 0.0);

}

Advertisements
%d bloggers like this: