This commit is contained in:
2025-11-28 23:13:44 +05:30
commit a3a8e79709
7360 changed files with 1156074 additions and 0 deletions

View File

@ -0,0 +1,24 @@
uniform sampler2D colorTex;
uniform float sx;
void main (void)
{
vec3 bloom = vec3(0.0, 0.0, 0.0);
const float hdrScale = 1.5;
const int kernelSize = 10;
const float invScale = 1.0 / (hdrScale * float(kernelSize));
for (int x = -kernelSize; x <= kernelSize; x++)
{
float s = gl_TexCoord[0].s + x * sx;
float t = gl_TexCoord[0].t;
vec3 color = texture2D(colorTex, vec2(s,t)).rgb;
float luminance = dot(color, vec3(0.2125, 0.7154, 0.0721));
if (luminance > 1.0)
{
bloom += color * ((kernelSize+1) - abs(float(x)));
}
}
gl_FragColor = vec4(bloom * invScale, 1.0);
}

View File

@ -0,0 +1,30 @@
uniform sampler2D colorTex;
uniform sampler2D blurTex;
uniform float sy;
void main (void)
{
const float hdrScale = 1.5;
const int kernelSize = 10;
const float invScale = 1.0 / (hdrScale * float(kernelSize) * 100.0);
vec3 colorP = texture2D(colorTex, gl_TexCoord[0]).rgb;
vec3 bloom = vec3(0.0, 0.0, 0.0);
for (int y = -kernelSize; y <= kernelSize; y++)
{
float s = gl_TexCoord[0].s;
float t = gl_TexCoord[0].t + y * sy;
vec3 color = texture2D(blurTex, vec2(s,t)).rgb;
float luminance = dot(color, vec3(0.2125, 0.7154, 0.0721));
if (luminance > 1.0)
{
bloom += color * ((kernelSize+1) - abs(float(y)));
}
}
vec3 hdrColor = invScale * bloom + colorP;
vec3 toneMappedColor = 2.0 * hdrColor / (hdrColor + vec3(1.0));
gl_FragColor = vec4(toneMappedColor, 1.0);
}

View File

@ -0,0 +1,529 @@
uniform sampler3D ttt3D;
uniform float extraNoiseScale = 1.0f;
uniform float noiseScale = 0.03f;
float noise(float p) {
return texture3D(ttt3D, vec3(p*noiseScale*extraNoiseScale, 0.5, 0.5)).x;
}
float noise(float p, float q) {
return texture3D(ttt3D, vec3(p*noiseScale*extraNoiseScale, q*noiseScale*extraNoiseScale, 0.5)).x;
}
float snoise(float p) {
return noise(p)*2.0f - 1.0f;
}
float snoise(float p, float q) {
return noise(p, q)*2.0f - 1.0f;
}
float boxstep(float a, float b, float x) {
return (clamp(((x)-(a)) / ((b)-(a)), 0, 1));
}
uniform float Ka = 1;
uniform float Kd = 0.75;
uniform float Ks = 0.15;
uniform float roughness = 0.025;
uniform vec3 specularcolor = vec3(1, 1, 1);
uniform float ringscale = 0;
uniform float grainscale = 0;
uniform float txtscale = 1;
uniform float plankspertile = 4;
uniform vec3 lightwood = vec3(0.57, 0.292, 0.125);
uniform vec3 darkwood = vec3(0.275, 0.15, 0.06);
uniform vec3 groovecolor = vec3(.05, .04, .015);
//uniform float plankwidth = .05;
uniform float plankwidth = .2;
uniform float groovewidth = 0.001;
uniform float plankvary = 0.8;
uniform float grainy = 1;
uniform float wavy = 0.08;
uniform float MINFILTERWIDTH = 1.0e-7;
vec3 myTexture3D_0(vec3 p)
{
float r;
float r2;
float whichrow;
float whichplank;
float swidth;
float twidth;
float fwidth;
float ss;
float tt;
float w;
float h;
float fade;
float ttt;
vec3 Ct;
vec3 woodcolor;
float groovy;
float PGWIDTH;
float PGHEIGHT;
float GWF;
float GHF;
float tilewidth;
float whichtile;
float tmp;
float planklength;
PGWIDTH = plankwidth + groovewidth;
planklength = PGWIDTH * plankspertile - groovewidth;
PGHEIGHT = planklength + groovewidth;
GWF = groovewidth*0.5 / PGWIDTH;
GHF = groovewidth*0.5 / PGHEIGHT;
// Determine how wide in s-t space one pixel projects to
float s = p.x;
float t = p.y;
float du = 1.0;
float dv = 1.0;
swidth = (max(abs(dFdx(s)*du) + abs(dFdy(s)*dv), MINFILTERWIDTH) /
PGWIDTH) * txtscale;
twidth = (max(abs(dFdx(t)*du) + abs(dFdy(t)*dv), MINFILTERWIDTH) /
PGHEIGHT) * txtscale;
fwidth = max(swidth, twidth);
ss = (txtscale * s) / PGWIDTH;
whichrow = floor(ss);
tt = (txtscale * t) / PGHEIGHT;
whichplank = floor(tt);
if (mod(whichrow / plankspertile + whichplank, 2) >= 1) {
ss = txtscale * t / PGWIDTH;
whichrow = floor(ss);
tt = txtscale * s / PGHEIGHT;
whichplank = floor(tt);
tmp = swidth; swidth = twidth; twidth = tmp;
}
ss -= whichrow;
tt -= whichplank;
whichplank += 20 * (whichrow + 10);
if (swidth >= 1)
w = 1 - 2 * GWF;
else w = clamp(boxstep(GWF - swidth, GWF, ss), max(1 - GWF / swidth, 0), 1)
- clamp(boxstep(1 - GWF - swidth, 1 - GWF, ss), 0, 2 * GWF / swidth);
if (twidth >= 1)
h = 1 - 2 * GHF;
else h = clamp(boxstep(GHF - twidth, GHF, tt), max(1 - GHF / twidth, 0), 1)
- clamp(boxstep(1 - GHF - twidth, 1 - GHF, tt), 0, 2 * GHF / twidth);
// This would be the non-antialiased version:
//w = step (GWF,ss) - step(1-GWF,ss);
//h = step (GHF,tt) - step(1-GHF,tt);
groovy = w*h;
// Add the ring patterns
fade = smoothstep(1 / ringscale, 8 / ringscale, fwidth);
if (fade < 0.999) {
ttt = tt / 4 + whichplank / 28.38 + wavy * noise(8 * ss, tt / 4);
r = ringscale * noise(ss - whichplank, ttt);
r -= floor(r);
r = 0.3 + 0.7*smoothstep(0.2, 0.55, r)*(1 - smoothstep(0.75, 0.8, r));
r = (1 - fade)*r + 0.65*fade;
// Multiply the ring pattern by the fine grain
fade = smoothstep(2 / grainscale, 8 / grainscale, fwidth);
if (fade < 0.999) {
r2 = 1.3 - noise(ss*grainscale, (tt*grainscale / 4));
r2 = grainy * r2*r2 + (1 - grainy);
r *= (1 - fade)*r2 + (0.75*fade);
}
else r *= 0.75;
}
else r = 0.4875;
// Mix the light and dark wood according to the grain pattern
woodcolor = lerp(lightwood, darkwood, r);
// Add plank-to-plank variation in overall color
woodcolor *= (1 - plankvary / 2 + plankvary * noise(whichplank + 0.5));
Ct = lerp(groovecolor, woodcolor, groovy);
return Ct;
}
float noise3D_1(vec3 p)
{
return texture3D(ttt3D, p).x*2.0f - 1.0f;
}
float turbulence_1(vec3 p, int octaves, float lacunarity, float gain) {
float freq = 1.0f;
float amp = 0.8f;
float sum = 0.0f;
for (int i = 0; i<octaves; i++) {
sum += abs(noise3D_1(p*freq))*amp;
freq *= lacunarity;
amp *= gain;
}
return sum;
}
float spike_1(float c, float w, float x) {
return smoothstep(c - w, c, x) * smoothstep(c + w, c, x);
}
vec3 myTexture3D_1(vec3 p)
{
float noiseScale = 0.1f*extraNoiseScale;
float noise = turbulence_1(p*noiseScale, 3, 3.0f, 0.5f);
//noise = turbulence(p*noiseScale + vec3(noise, noise, noise*0.3)*0.01f, 8, 3.0f, 0.5f);
//noise = spike(0.35f, 0.05f, noise);
//noise = noise;
vec3 base = lerp(vec3(164, 148, 108)*1.63 / 255, vec3(178, 156, 126)*1.73 / 255, spike_1(0.5f, 0.3f, turbulence_1(p*noiseScale*0.7f + vec3(noise*0.5, noise, noise)*0.011f, 2, 2.0f, 0.5f)));
//vec3 b2 = lerp(base, vec3(0.0f, 0.0f, 0.0f), noise);
vec3 b2 = lerp(base, vec3(173, 160, 121)*1.73 / 255, noise);
return b2*0.75f;
}
vec3 myTexture3DCom(vec3 p, float mat) {
// Depend on material ID
if (mat < 0.5f) {
//return myTexture3D_0(p);
return vec3(173, 160, 151) *0.85/ 255;
//return lightwood*1.3;
}
else
if (mat < 1.5f) {
//return myTexture3D_1(p);
return vec3(173, 100, 21)*1.73 / 255;
} else {
return vec3(1.0f, 0.0f, 0.0f);
}
}
// scene reflection
uniform float reflectionCoeff = 0.0f;
uniform float specularCoeff = 0.0f;
uniform sampler2DRect reflectionTex;
// Shadow map
uniform float shadowAmbient = 0.0;
uniform float hdrScale = 5.0;
uniform sampler2D texture;
uniform sampler2DArrayShadow stex;
uniform sampler2DArrayShadow stex2;
uniform sampler2DArrayShadow stex3;
uniform samplerCube skyboxTex;
uniform vec2 texSize; // x - size, y - 1/size
uniform vec4 far_d;
// Spot lights
uniform vec3 spotLightDir;
uniform vec3 spotLightPos;
uniform float spotLightCosineDecayBegin;
uniform float spotLightCosineDecayEnd;
uniform vec3 spotLightDir2;
uniform vec3 spotLightPos2;
uniform float spotLightCosineDecayBegin2;
uniform float spotLightCosineDecayEnd2;
uniform vec3 spotLightDir3;
uniform vec3 spotLightPos3;
uniform float spotLightCosineDecayBegin3;
uniform float spotLightCosineDecayEnd3;
uniform vec3 parallelLightDir;
uniform float shadowAdd;
uniform int useTexture;
uniform int numShadows;
uniform float roughnessScale;
uniform vec3 ambientColor;
uniform sampler2DArray diffuseTexArray;
uniform sampler2DArray bumpTexArray;
uniform sampler2DArray specularTexArray;
uniform sampler2DArray emissiveReflectSpecPowerTexArray;
uniform vec2 shadowTaps[12];
float shadowCoeff1(float bscale)
{
int index = 3;
if(gl_FragCoord.z < far_d.x)
index = 0;
else if(gl_FragCoord.z < far_d.y)
index = 1;
else if(gl_FragCoord.z < far_d.z)
index = 2;
vec4 shadow_coord = gl_TextureMatrix[index]*vec4(gl_TexCoord[1].xyz, 1);
shadow_coord.w = shadow_coord.z + shadowAdd*bscale;
// tell glsl in which layer to do the look up
shadow_coord.z = float(index);
// Gaussian 3x3 filter
// return shadow2DArray(stex, shadow_coord).x;
/*
const float X = 1.0f;
float ret = shadow2DArray(stex, shadow_coord).x * 0.25;
ret += shadow2DArrayOffset(stex, shadow_coord, ivec2( -X, -X)).x * 0.0625;
ret += shadow2DArrayOffset(stex, shadow_coord, ivec2( -X, 0)).x * 0.125;
ret += shadow2DArrayOffset(stex, shadow_coord, ivec2( -X, X)).x * 0.0625;
ret += shadow2DArrayOffset(stex, shadow_coord, ivec2( 0, -X)).x * 0.125;
ret += shadow2DArrayOffset(stex, shadow_coord, ivec2( 0, X)).x * 0.125;
ret += shadow2DArrayOffset(stex, shadow_coord, ivec2( X, -X)).x * 0.0625;
ret += shadow2DArrayOffset(stex, shadow_coord, ivec2( X, 0)).x * 0.125;
ret += shadow2DArrayOffset(stex, shadow_coord, ivec2( X, X)).x * 0.0625;
return ret;*/
const int numTaps = 6;
float radius = 0.0003f/pow(2,index);
float s = 0.0f;
for (int i = 0; i < numTaps; i++)
{
s += shadow2DArray(stex, shadow_coord + vec4(shadowTaps[i] * radius, 0.0f, 0.0f)).r;
}
s /= numTaps;
return s;
}
float shadowCoeff2()
{
const int index = 1;
//int index = 3;
//if(gl_FragCoord.z < far_d.x)
// index = 0;
//else if(gl_FragCoord.z < far_d.y)
// index = 1;
//else if(gl_FragCoord.z < far_d.z)
// index = 2;
vec4 shadow_coord = gl_TextureMatrix[index]*vec4(gl_TexCoord[1].xyz, 1);
shadow_coord.w = shadow_coord.z + shadowAdd;
shadow_coord.z = float(0);
// return shadow2DArray(stex, shadow_coord).x;
const float X = 1.0f;
float ret = shadow2DArray(stex2, shadow_coord).x * 0.25;
ret += shadow2DArrayOffset(stex2, shadow_coord, ivec2( -X, -X)).x * 0.0625;
ret += shadow2DArrayOffset(stex2, shadow_coord, ivec2( -X, 0)).x * 0.125;
ret += shadow2DArrayOffset(stex2, shadow_coord, ivec2( -X, X)).x * 0.0625;
ret += shadow2DArrayOffset(stex2, shadow_coord, ivec2( 0, -X)).x * 0.125;
ret += shadow2DArrayOffset(stex2, shadow_coord, ivec2( 0, X)).x * 0.125;
ret += shadow2DArrayOffset(stex2, shadow_coord, ivec2( X, -X)).x * 0.0625;
ret += shadow2DArrayOffset(stex2, shadow_coord, ivec2( X, 0)).x * 0.125;
ret += shadow2DArrayOffset(stex2, shadow_coord, ivec2( X, X)).x * 0.0625;
return ret;
}
float shadowCoeff3()
{
const int index = 2;
//int index = 3;
//if(gl_FragCoord.z < far_d.x)
// index = 0;
//else if(gl_FragCoord.z < far_d.y)
// index = 1;
//else if(gl_FragCoord.z < far_d.z)
// index = 2;
vec4 shadow_coord = gl_TextureMatrix[index]*vec4(gl_TexCoord[1].xyz, 1);
shadow_coord.w = shadow_coord.z + shadowAdd;
shadow_coord.z = float(0);
// return shadow2DArray(stex, shadow_coord).x;
const float X = 1.0f;
float ret = shadow2DArray(stex3, shadow_coord).x * 0.25;
ret += shadow2DArrayOffset(stex3, shadow_coord, ivec2( -X, -X)).x * 0.0625;
ret += shadow2DArrayOffset(stex3, shadow_coord, ivec2( -X, 0)).x * 0.125;
ret += shadow2DArrayOffset(stex3, shadow_coord, ivec2( -X, X)).x * 0.0625;
ret += shadow2DArrayOffset(stex3, shadow_coord, ivec2( 0, -X)).x * 0.125;
ret += shadow2DArrayOffset(stex3, shadow_coord, ivec2( 0, X)).x * 0.125;
ret += shadow2DArrayOffset(stex3, shadow_coord, ivec2( X, -X)).x * 0.0625;
ret += shadow2DArrayOffset(stex3, shadow_coord, ivec2( X, 0)).x * 0.125;
ret += shadow2DArrayOffset(stex3, shadow_coord, ivec2( X, X)).x * 0.0625;
return ret;
}
uniform float RollOff = 0.5f;
uniform float fresnelBias = 0.0;
uniform float fresnelScale = 1.0;
uniform float fresnelPower = 3.0; // 5.0 is physically correct
void main()
{
/*
int index = 3;
if(gl_FragCoord.z < far_d.x)
index = 0;
else if(gl_FragCoord.z < far_d.y)
index = 1;
else if(gl_FragCoord.z < far_d.z)
index = 2;
if (index == 3) gl_FragColor = vec4(1,0,0,1);
if (index == 2) gl_FragColor = vec4(0,1,0,1);
if (index == 1) gl_FragColor = vec4(0,0,1,1);
if (index == 0) gl_FragColor = vec4(1,1,0,1);
return;*/
/*
int index = 3;
if(gl_FragCoord.z < far_d.x)
index = 0;
else if(gl_FragCoord.z < far_d.y)
index = 1;
else if(gl_FragCoord.z < far_d.z)
index = 2;
vec4 shadow_coord = gl_TextureMatrix[index]*vec4(gl_TexCoord[1].xyz, 1);
shadow_coord.w = shadow_coord.z + shadowAdd;
// tell glsl in which layer to do the look up
shadow_coord.z = float(index)*0.33333333f;
gl_FragColor = vec4(shadow_coord.xyz,1.0f);
return;
*/
//// TODO, expose this as user parameter
const float skyLightIntensity = 0.2;
const float rimLightIntensity = 0.3;
vec3 normal = normalize(gl_TexCoord[2].xyz);
vec3 t0 = gl_TexCoord[3].xyz;
vec3 t1 = gl_TexCoord[4].xyz;
vec3 diffuseMat;
vec3 specularMat;
vec3 bump;
vec3 emissiveReflectSpecPow;
// read in material color for diffuse, specular, bump, emmisive
// 3D texture
diffuseMat = myTexture3DCom(gl_TexCoord[0].xyz, gl_TexCoord[6].w);
//diffuseMat = myTexture3D(gl_TexCoord[0].xyz);//texture3D(ttt3D, gl_TexCoord[0].xyz);
//diffuseMat = texture3D(ttt3D, gl_TexCoord[0].xyz);
specularMat = vec3(1.0);
bump = texture2D(texture, gl_TexCoord[5].xy).xyz;
if (dot(bump,bump) < 0.01) bump = vec3(0.5,0.5,1);
emissiveReflectSpecPow = vec3(0.0,0.0,0.0);
// apply bump to the normal
bump = (bump - vec3(0.5,0.5,0.5)) * 2.0f;
bump.xy *= roughnessScale*0.1;
float sc = 1.0f;
normal = normalize(t0*bump.x + t1*bump.y + sc*normal * bump.z);
//gl_FragColor.xyz = normal*0.5 + vec3(0.5,0.5,0.5);
//gl_FragColor.w = 1;
//return;
vec3 eyeVec = normalize(gl_TexCoord[1].xyz);
// apply gamma correction for diffuse textures
//diffuseMat = pow(diffuseMat, 0.45);
float specularPower = emissiveReflectSpecPow.b*255.0f + 1.0f;
// TODO - fix this
specularPower = 10.0f;
float emissive = 0.0f;
float reflectivity = emissiveReflectSpecPow.b;
float fresnel = fresnelBias + fresnelScale*pow(1.0 - max(0.0, dot(normal, eyeVec)), fresnelPower);
float specular = 0.0f;
vec3 skyNormal = reflect(eyeVec, normal);
vec3 skyColor = skyLightIntensity * textureCube(skyboxTex, skyNormal).rgb;
vec3 ambientSkyColor = diffuseMat * skyColor;
vec3 diffuseColor = vec3(0.0, 0.0, 0.0);
if (numShadows >= 1) {
vec3 lightColor = hdrScale * vec3(1.0, 1.0, 1.0);
vec3 shadowColor = vec3(0.4, 0.4, 0.7); // colored shadow
//vec3 lvec = normalize(spotLightDir);
vec3 lvec = normalize(spotLightPos - gl_TexCoord[1].xyz);
float ldn = max(0.0f, dot(normal, lvec));
float cosine = dot(lvec, spotLightDir);
float intensity = smoothstep(spotLightCosineDecayBegin, spotLightCosineDecayEnd, cosine);
float bscale = 1;//1.0f-ldn;
float shadowC = shadowCoeff1(bscale);
//gl_FragColor = vec4(shadowC,shadowC,shadowC,1.0f);
//return;
vec3 irradiance = shadowC * ldn * lightColor;
// diffuse irradiance
diffuseColor += diffuseMat * irradiance*intensity;
// add colored shadow
diffuseColor += (1.0 - shadowC*ldn) * shadowAmbient * shadowColor * diffuseMat*intensity;
vec3 r = reflect(lvec, normal);
specular += pow(max(0.0, dot(r, eyeVec)), specularPower)*shadowC*intensity;
}
// add rim light
if (numShadows >= 2) {
vec3 lightColor = hdrScale * vec3(1.0, 1.0, 1.0);
vec3 lvec = normalize(spotLightDir2);
float ldn = max(0.0f, dot(normal, lvec));
vec3 irradiance = ldn * lightColor;
// diffuse irradiance
diffuseColor += diffuseMat * irradiance;
}
vec3 color = vec3(0.0, 0.0, 0.0);
color += diffuseColor;
color += ambientSkyColor;
color += specular*specularMat;
color += hdrScale * emissive * diffuseMat;
//vec3 reflectColor = diffuseMat * texture2DRect(reflectionTex, gl_FragCoord.xy).rgb;
//color = reflectionCoeff * reflectColor + (1.0f - reflectionCoeff) * color;
color = (fresnel * skyColor + (1.0 - fresnel) * color) * reflectivity + (1.0 - reflectivity) * color;
gl_FragColor.rgb = color;
gl_FragColor.w = gl_Color.w;
float fog = clamp(gl_Fog.scale*(gl_Fog.end+gl_TexCoord[1].z), 0.0, 1.0);
vec4 fogCol = gl_Fog.color;
gl_FragColor = mix(fogCol, gl_FragColor, fog);
}

View File

@ -0,0 +1,79 @@
uniform float uvScale = 1.0f;
uniform sampler2D transTex;
uniform int transTexSize;
uniform float iTransTexSize;
uniform float bumpTextureUVScale;
//attribute mat4 transformmatrix;
void main()
{
int ti = (int)(gl_MultiTexCoord0.w);
//int ti = tq;
int tpr = transTexSize / 4;
int row = ti / tpr;
int col = (ti - row*tpr)*4;
float fx = (col+0.5f)*iTransTexSize;
float fy = (row+0.5f)*iTransTexSize;
vec4 r0 = texture2D(transTex, vec2(fx,fy));
vec4 r1 = texture2D(transTex, vec2(fx+iTransTexSize,fy));
vec4 r2 = texture2D(transTex, vec2(fx+iTransTexSize*2.0f,fy));
vec4 r3 = texture2D(transTex, vec2(fx+iTransTexSize*3.0f,fy));
// vec4 r3 = vec4(0,0,0,1);
vec3 offset = vec3(r0.w, r1.w, r2.w);
r0.w = 0.0f;
r1.w = 0.0f;
r2.w = 0.0f;
float material = r3.w;
r3.w = 1.0f;
mat4 transformmatrix = mat4(r0,r1,r2,r3);
mat4 mvp = gl_ModelViewMatrix * transformmatrix;
mat4 mvpt = gl_ModelViewMatrixInverseTranspose * transformmatrix;
vec4 t0 = vec4(gl_MultiTexCoord0.xyz, 0.0f);
vec4 t1 = vec4(cross(gl_Normal.xyz, t0.xyz), 0.0f);
// mat4 mvp = gl_ModelViewMatrix;
// mat4 mvpt = gl_ModelViewMatrixInverseTranspose;
vec4 eyeSpacePos = mvp * gl_Vertex;
//eyeSpacePos.y += gl_InstanceID * 0.2f;
//gl_TexCoord[0].xyz = gl_MultiTexCoord0.xyz*uvScale;
vec3 coord3d = gl_Vertex.xyz + offset;
gl_TexCoord[0].xyz = (coord3d)*uvScale;
gl_TexCoord[1] = eyeSpacePos;
gl_FrontColor = gl_Color;
gl_Position = gl_ProjectionMatrix*eyeSpacePos;
gl_TexCoord[2] = mvpt * vec4(gl_Normal.xyz,0.0);
gl_TexCoord[3] = mvpt * t0;
gl_TexCoord[4].xyz = mvpt * t1;
gl_TexCoord[5].xy = vec2(dot(coord3d, t0.xyz), dot(coord3d, t1.xyz))*bumpTextureUVScale*2;
gl_TexCoord[6].xyz = vec3(gl_MultiTexCoord1.xy, material);
gl_TexCoord[6].y = 1.0 - gl_TexCoord[6].y;
float MAX_3D_TEX = 8.0;
if (gl_TexCoord[6].x >= 5.0f) {
// 2D Tex
gl_TexCoord[6].x -= 5.0f;
gl_TexCoord[6].z = floor(gl_TexCoord[6].z / MAX_3D_TEX);
} else {
gl_TexCoord[6].z -= floor(gl_TexCoord[6].z / MAX_3D_TEX)*MAX_3D_TEX;
gl_TexCoord[6].z -= 100.0f;
}
gl_TexCoord[6].w = floor(fract(material / MAX_3D_TEX)*MAX_3D_TEX + 0.5f);
gl_ClipVertex = vec4(eyeSpacePos.xyz, 1.0f);
}

View File

@ -0,0 +1,309 @@
uniform sampler3D ttt3D;
uniform float extraNoiseScale = 1.0f;
float noise3D(vec3 p)
{
return texture3D(ttt3D, p).x*2.0f - 1.0f;
}
float turbulence(vec3 p, int octaves, float lacunarity, float gain) {
float freq = 1.0f;
float amp = 0.8f;
float sum = 0.0f;
for(int i=0; i<octaves; i++) {
sum += abs(noise3D(p*freq))*amp;
freq *= lacunarity;
amp *= gain;
}
return sum;
}
float spike(float c, float w, float x) {
return smoothstep(c-w, c, x) * smoothstep(c+w, c, x);
}
vec3 myTexture3D(vec3 p)
{
float noiseScale = 0.1f*extraNoiseScale;
float noise = turbulence(p*noiseScale, 3, 3.0f, 0.5f);
//noise = turbulence(p*noiseScale + vec3(noise, noise, noise*0.3)*0.01f, 8, 3.0f, 0.5f);
//noise = spike(0.35f, 0.05f, noise);
//noise = noise;
vec3 base = lerp(vec3(164,148,108)*1.63/255, vec3(178,156,126)*1.73/255, spike(0.5f, 0.3f, turbulence(p*noiseScale*0.7f + vec3(noise*0.5, noise, noise)*0.011f, 2, 2.0f, 0.5f)));
//vec3 b2 = lerp(base, vec3(0.0f, 0.0f, 0.0f), noise);
vec3 b2 = lerp(base, vec3(173, 160, 121)*1.73/255, noise);
return b2;
}
// scene reflection
uniform float reflectionCoeff = 0.0f;
uniform float specularCoeff = 0.0f;
uniform sampler2DRect reflectionTex;
// Shadow map
uniform float shadowAmbient = 0.0;
uniform float hdrScale = 5.0;
uniform sampler2D texture;
uniform sampler2DArrayShadow stex;
uniform sampler2DArrayShadow stex2;
uniform sampler2DArrayShadow stex3;
uniform samplerCube skyboxTex;
uniform vec2 texSize; // x - size, y - 1/size
uniform vec4 far_d;
// Spot lights
uniform vec3 spotLightDir;
uniform vec3 spotLightPos;
uniform float spotLightCosineDecayBegin;
uniform float spotLightCosineDecayEnd;
uniform vec3 spotLightDir2;
uniform vec3 spotLightPos2;
uniform float spotLightCosineDecayBegin2;
uniform float spotLightCosineDecayEnd2;
uniform vec3 spotLightDir3;
uniform vec3 spotLightPos3;
uniform float spotLightCosineDecayBegin3;
uniform float spotLightCosineDecayEnd3;
uniform vec3 parallelLightDir;
uniform float shadowAdd;
uniform int useTexture;
uniform int numShadows;
uniform float roughnessScale;
uniform vec3 ambientColor;
uniform sampler2DArray diffuseTexArray;
uniform sampler2DArray bumpTexArray;
uniform sampler2DArray specularTexArray;
uniform sampler2DArray emissiveReflectSpecPowerTexArray;
float shadowCoeff1()
{
const int index = 0;
//int index = 3;
//
//if(gl_FragCoord.z < far_d.x)
// index = 0;
//else if(gl_FragCoord.z < far_d.y)
// index = 1;
//else if(gl_FragCoord.z < far_d.z)
// index = 2;
vec4 shadow_coord = gl_TextureMatrix[index]*vec4(gl_TexCoord[1].xyz, 1);
shadow_coord.w = shadow_coord.z + shadowAdd;
// tell glsl in which layer to do the look up
shadow_coord.z = float(index);
// Gaussian 3x3 filter
// return shadow2DArray(stex, shadow_coord).x;
const float X = 1.0f;
float ret = shadow2DArray(stex, shadow_coord).x * 0.25;
ret += shadow2DArrayOffset(stex, shadow_coord, ivec2( -X, -X)).x * 0.0625;
ret += shadow2DArrayOffset(stex, shadow_coord, ivec2( -X, 0)).x * 0.125;
ret += shadow2DArrayOffset(stex, shadow_coord, ivec2( -X, X)).x * 0.0625;
ret += shadow2DArrayOffset(stex, shadow_coord, ivec2( 0, -X)).x * 0.125;
ret += shadow2DArrayOffset(stex, shadow_coord, ivec2( 0, X)).x * 0.125;
ret += shadow2DArrayOffset(stex, shadow_coord, ivec2( X, -X)).x * 0.0625;
ret += shadow2DArrayOffset(stex, shadow_coord, ivec2( X, 0)).x * 0.125;
ret += shadow2DArrayOffset(stex, shadow_coord, ivec2( X, X)).x * 0.0625;
return ret;
}
float shadowCoeff2()
{
const int index = 1;
//int index = 3;
//if(gl_FragCoord.z < far_d.x)
// index = 0;
//else if(gl_FragCoord.z < far_d.y)
// index = 1;
//else if(gl_FragCoord.z < far_d.z)
// index = 2;
vec4 shadow_coord = gl_TextureMatrix[index]*vec4(gl_TexCoord[1].xyz, 1);
shadow_coord.w = shadow_coord.z + shadowAdd;
shadow_coord.z = float(0);
// return shadow2DArray(stex, shadow_coord).x;
const float X = 1.0f;
float ret = shadow2DArray(stex2, shadow_coord).x * 0.25;
ret += shadow2DArrayOffset(stex2, shadow_coord, ivec2( -X, -X)).x * 0.0625;
ret += shadow2DArrayOffset(stex2, shadow_coord, ivec2( -X, 0)).x * 0.125;
ret += shadow2DArrayOffset(stex2, shadow_coord, ivec2( -X, X)).x * 0.0625;
ret += shadow2DArrayOffset(stex2, shadow_coord, ivec2( 0, -X)).x * 0.125;
ret += shadow2DArrayOffset(stex2, shadow_coord, ivec2( 0, X)).x * 0.125;
ret += shadow2DArrayOffset(stex2, shadow_coord, ivec2( X, -X)).x * 0.0625;
ret += shadow2DArrayOffset(stex2, shadow_coord, ivec2( X, 0)).x * 0.125;
ret += shadow2DArrayOffset(stex2, shadow_coord, ivec2( X, X)).x * 0.0625;
return ret;
}
float shadowCoeff3()
{
const int index = 2;
//int index = 3;
//if(gl_FragCoord.z < far_d.x)
// index = 0;
//else if(gl_FragCoord.z < far_d.y)
// index = 1;
//else if(gl_FragCoord.z < far_d.z)
// index = 2;
vec4 shadow_coord = gl_TextureMatrix[index]*vec4(gl_TexCoord[1].xyz, 1);
shadow_coord.w = shadow_coord.z + shadowAdd;
shadow_coord.z = float(0);
// return shadow2DArray(stex, shadow_coord).x;
const float X = 1.0f;
float ret = shadow2DArray(stex3, shadow_coord).x * 0.25;
ret += shadow2DArrayOffset(stex3, shadow_coord, ivec2( -X, -X)).x * 0.0625;
ret += shadow2DArrayOffset(stex3, shadow_coord, ivec2( -X, 0)).x * 0.125;
ret += shadow2DArrayOffset(stex3, shadow_coord, ivec2( -X, X)).x * 0.0625;
ret += shadow2DArrayOffset(stex3, shadow_coord, ivec2( 0, -X)).x * 0.125;
ret += shadow2DArrayOffset(stex3, shadow_coord, ivec2( 0, X)).x * 0.125;
ret += shadow2DArrayOffset(stex3, shadow_coord, ivec2( X, -X)).x * 0.0625;
ret += shadow2DArrayOffset(stex3, shadow_coord, ivec2( X, 0)).x * 0.125;
ret += shadow2DArrayOffset(stex3, shadow_coord, ivec2( X, X)).x * 0.0625;
return ret;
}
uniform float RollOff = 0.5f;
uniform float fresnelBias = 0.0;
uniform float fresnelScale = 1.0;
uniform float fresnelPower = 3.0; // 5.0 is physically correct
void main()
{
//// TODO, expose this as user parameter
const float skyLightIntensity = 0.2;
const float rimLightIntensity = 0.3;
vec3 normal = normalize(gl_TexCoord[2].xyz);
vec3 t0 = gl_TexCoord[3].xyz;
vec3 t1 = gl_TexCoord[4].xyz;
vec3 diffuseMat;
vec3 specularMat;
vec3 bump;
vec3 emissiveReflectSpecPow;
// read in material color for diffuse, specular, bump, emmisive
if (gl_TexCoord[6].z >= 0.0f) {
// 2D texture
diffuseMat = texture2DArray(diffuseTexArray, gl_TexCoord[6].xyz).rgb;
//specularMat = texture2DArray(specularTexArray, gl_TexCoord[6].xyz).rgb; // TODO Does not seem to work
specularMat = vec3(1.0f);
bump = texture2DArray(bumpTexArray, gl_TexCoord[6].xyz).xyz;
if (dot(bump,bump) < 0.01) bump = vec3(0.5,0.5,1);
emissiveReflectSpecPow = texture2DArray(emissiveReflectSpecPowerTexArray, gl_TexCoord[6].xyz).xyz;
} else {
// 3D texture
diffuseMat = myTexture3D(gl_TexCoord[0].xyz) * vec3(0.5,0.5,0.5);//texture3D(ttt3D, gl_TexCoord[0].xyz);
specularMat = vec3(1.0);
bump = texture2D(texture, gl_TexCoord[5].xy).xyz;
if (dot(bump,bump) < 0.01) bump = vec3(0.5,0.5,1);
emissiveReflectSpecPow = vec3(0.0,0.0,0.0);
}
// apply bump to the normal
bump = (bump - vec3(0.5,0.5,0.5)) * 2.0f;
bump.xy *= roughnessScale*2;
float sc = 1.0f;
normal = normalize(t0*bump.x + t1*bump.y + sc*normal * bump.z);
vec3 eyeVec = normalize(gl_TexCoord[1].xyz);
// apply gamma correction for diffuse textures
diffuseMat = pow(diffuseMat, 0.45);
float specularPower = emissiveReflectSpecPow.b*255.0f + 1.0f;
// TODO - fix this
specularPower = 10.0f;
float emissive = emissiveReflectSpecPow.r*10.0f;
float reflectivity = emissiveReflectSpecPow.b;
float fresnel = fresnelBias + fresnelScale*pow(1.0 - max(0.0, dot(normal, eyeVec)), fresnelPower);
float specular = 0.0f;
vec3 skyNormal = reflect(eyeVec, normal);
vec3 skyColor = skyLightIntensity * textureCube(skyboxTex, skyNormal).rgb;
vec3 ambientSkyColor = diffuseMat * skyColor;
vec3 diffuseColor = vec3(0.0, 0.0, 0.0);
if (numShadows >= 1) {
vec3 lightColor = hdrScale * vec3(1.0, 0.9, 0.9);
vec3 shadowColor = vec3(0.4, 0.4, 0.9); // colored shadow
vec3 lvec = normalize(spotLightDir);
float ldn = max(0.0f, dot(normal, lvec));
float shadowC = shadowCoeff1();
vec3 irradiance = shadowC * ldn * lightColor;
// diffuse irradiance
diffuseColor += diffuseMat * irradiance;
// add colored shadow
diffuseColor += (1.0 - shadowC) * shadowAmbient * shadowColor * diffuseMat;
vec3 r = reflect(lvec, normal);
specular += pow(max(0.0, dot(r,eyeVec)), specularPower)*shadowC;
}
// add rim light
if (numShadows >= 2) {
vec3 lightColor = rimLightIntensity * vec3(1.0, 0.9, 0.9);
vec3 lvec = normalize(spotLightDir2);
float ldn = max(0.0f, dot(normal, lvec));
vec3 irradiance = ldn * lightColor;
// diffuse irradiance
diffuseColor += diffuseMat * irradiance;
}
vec3 color = vec3(0.0, 0.0, 0.0);
color += diffuseColor;
color += ambientSkyColor;
color += specular*specularMat;
//color += hdrScale * emissive * diffuseMat;
//vec3 reflectColor = diffuseMat * texture2DRect(reflectionTex, gl_FragCoord.xy).rgb;
//color = reflectionCoeff * reflectColor + (1.0f - reflectionCoeff) * color;
//color = (fresnel * skyColor + (1.0 - fresnel) * color) * reflectivity + (1.0 - reflectivity) * color;
gl_FragColor.rgb = color;
gl_FragColor.w = gl_Color.w;
float fog = clamp(gl_Fog.scale*(gl_Fog.end+gl_TexCoord[1].z), 0.0, 1.0);
vec4 fogCol = gl_Fog.color;
gl_FragColor = mix(fogCol, gl_FragColor, fog);
}

View File

@ -0,0 +1,44 @@
uniform float uvScale = 1.0f;
attribute mat4 transformmatrix;
uniform float bumpTextureUVScale;
void main()
{
mat4 mvp = gl_ModelViewMatrix * transformmatrix;
mat4 mvpt = gl_ModelViewMatrixInverseTranspose * transformmatrix;
//mat4 mvp2 = gl_ModelViewMatrix * transformmatrix;
//mat4 mvp = gl_ModelViewMatrix;
//mat4 mvpt = gl_ModelViewMatrixInverseTranspose;
vec4 eyeSpacePos = mvp * gl_Vertex;
vec4 t0 = vec4(gl_MultiTexCoord0.xyz, 0.0f);
vec4 t1 = vec4(cross(gl_Normal.xyz, t0.xyz), 0.0f);
vec3 coord3d = gl_Vertex.xyz;
gl_TexCoord[0].xyz = (coord3d)*uvScale;
gl_TexCoord[1] = eyeSpacePos;
gl_FrontColor = gl_Color;
gl_Position = gl_ProjectionMatrix*eyeSpacePos;
gl_TexCoord[2] = mvpt * vec4(gl_Normal.xyz,0.0);
gl_TexCoord[3] = mvpt * t0;
gl_TexCoord[4] = mvpt * t1;
gl_TexCoord[5].xy = vec2(dot(coord3d, t0.xyz), dot(coord3d, t1.xyz))*bumpTextureUVScale*2;
gl_TexCoord[6].xyz = vec3(0,0,-100); // TODO: 2D UV are 0 and material id is -100 (first 3D texture)
/*
//vec4 eyeSpacePos2 = mvp2 * gl_Vertex;
gl_TexCoord[0] = gl_MultiTexCoord0*uvScale;
gl_TexCoord[1] = eyeSpacePos;
gl_FrontColor = gl_Color;
//gl_FrontColor.x += eyeSpacePos2.x;
gl_Position = gl_ProjectionMatrix*eyeSpacePos;
gl_TexCoord[2] = mvpt * vec4(gl_Normal.xyz,0.0);
gl_ClipVertex = vec4(eyeSpacePos.xyz, 1.0f);
*/
}

View File

@ -0,0 +1,308 @@
// scene reflection
uniform float reflectionCoeff = 0.0f;
uniform float specularCoeff = 0.0f;
uniform sampler2DRect reflectionTex;
// Shadow map
uniform float shadowAmbient = 0.0;
uniform sampler2D texture;
uniform sampler2DArrayShadow stex;
uniform sampler2DArrayShadow stex2;
uniform sampler2DArrayShadow stex3;
uniform samplerCube skyboxTex;
uniform float hdrScale = 5.0;
uniform vec2 texSize; // x - size, y - 1/size
uniform vec4 far_d;
// Spot lights
uniform vec3 spotLightDir;
uniform vec3 spotLightPos;
uniform float spotLightCosineDecayBegin;
uniform float spotLightCosineDecayEnd;
uniform vec3 spotLightDir2;
uniform vec3 spotLightPos2;
uniform float spotLightCosineDecayBegin2;
uniform float spotLightCosineDecayEnd2;
uniform vec3 spotLightDir3;
uniform vec3 spotLightPos3;
uniform float spotLightCosineDecayBegin3;
uniform float spotLightCosineDecayEnd3;
uniform vec3 parallelLightDir;
uniform float shadowAdd;
uniform int useTexture;
uniform int numShadows;
uniform vec3 ambientColor;
uniform vec2 shadowTaps[12];
float shadowCoeff1()
{
//const int index = 0;
int index = 3;
if(gl_FragCoord.z < far_d.x)
index = 0;
else if(gl_FragCoord.z < far_d.y)
index = 1;
else if(gl_FragCoord.z < far_d.z)
index = 2;
vec4 shadow_coord = gl_TextureMatrix[index]*vec4(gl_TexCoord[1].xyz, 1);
shadow_coord.w = shadow_coord.z + shadowAdd;
// tell glsl in which layer to do the look up
shadow_coord.z = float(index);
// Gaussian 3x3 filter
// return shadow2DArray(stex, shadow_coord).x;
/*
const float X = 1.0f;
float ret = shadow2DArray(stex, shadow_coord).x * 0.25;
ret += shadow2DArrayOffset(stex, shadow_coord, ivec2( -X, -X)).x * 0.0625;
ret += shadow2DArrayOffset(stex, shadow_coord, ivec2( -X, 0)).x * 0.125;
ret += shadow2DArrayOffset(stex, shadow_coord, ivec2( -X, X)).x * 0.0625;
ret += shadow2DArrayOffset(stex, shadow_coord, ivec2( 0, -X)).x * 0.125;
ret += shadow2DArrayOffset(stex, shadow_coord, ivec2( 0, X)).x * 0.125;
ret += shadow2DArrayOffset(stex, shadow_coord, ivec2( X, -X)).x * 0.0625;
ret += shadow2DArrayOffset(stex, shadow_coord, ivec2( X, 0)).x * 0.125;
ret += shadow2DArrayOffset(stex, shadow_coord, ivec2( X, X)).x * 0.0625;
return ret;*/
const int numTaps = 12;
float radius = 0.0003f / pow(2, index);
float s = 0.0f;
for (int i = 0; i < numTaps; i++)
{
s += shadow2DArray(stex, shadow_coord + vec4(shadowTaps[i] * radius, 0.0f, 0.0f)).r;
}
s /= numTaps;
return s;
}
float shadowCoeff2()
{
const int index = 1;
//int index = 3;
//if(gl_FragCoord.z < far_d.x)
// index = 0;
//else if(gl_FragCoord.z < far_d.y)
// index = 1;
//else if(gl_FragCoord.z < far_d.z)
// index = 2;
vec4 shadow_coord = gl_TextureMatrix[index]*vec4(gl_TexCoord[1].xyz, 1);
shadow_coord.w = shadow_coord.z + shadowAdd;
shadow_coord.z = float(0);
// return shadow2DArray(stex, shadow_coord).x;
/*
const float X = 1.0f;
float ret = shadow2DArray(stex2, shadow_coord).x * 0.25;
ret += shadow2DArrayOffset(stex2, shadow_coord, ivec2( -X, -X)).x * 0.0625;
ret += shadow2DArrayOffset(stex2, shadow_coord, ivec2( -X, 0)).x * 0.125;
ret += shadow2DArrayOffset(stex2, shadow_coord, ivec2( -X, X)).x * 0.0625;
ret += shadow2DArrayOffset(stex2, shadow_coord, ivec2( 0, -X)).x * 0.125;
ret += shadow2DArrayOffset(stex2, shadow_coord, ivec2( 0, X)).x * 0.125;
ret += shadow2DArrayOffset(stex2, shadow_coord, ivec2( X, -X)).x * 0.0625;
ret += shadow2DArrayOffset(stex2, shadow_coord, ivec2( X, 0)).x * 0.125;
ret += shadow2DArrayOffset(stex2, shadow_coord, ivec2( X, X)).x * 0.0625;
return ret;*/
const int numTaps = 12;
float radius = 1.0f;
float s = 0.0f;
for (int i = 0; i < numTaps; i++)
{
s += shadow2DArray(stex, shadow_coord + vec4(shadowTaps[i] * radius, 0.0f, 0.0f)).r;
}
s /= numTaps;
return s;
}
float shadowCoeff3()
{
const int index = 2;
//int index = 3;
//if(gl_FragCoord.z < far_d.x)
// index = 0;
//else if(gl_FragCoord.z < far_d.y)
// index = 1;
//else if(gl_FragCoord.z < far_d.z)
// index = 2;
vec4 shadow_coord = gl_TextureMatrix[index]*vec4(gl_TexCoord[1].xyz, 1);
shadow_coord.w = shadow_coord.z + shadowAdd;
shadow_coord.z = float(0);
// return shadow2DArray(stex, shadow_coord).x;
/*
const float X = 1.0f;
float ret = shadow2DArray(stex3, shadow_coord).x * 0.25;
ret += shadow2DArrayOffset(stex3, shadow_coord, ivec2( -X, -X)).x * 0.0625;
ret += shadow2DArrayOffset(stex3, shadow_coord, ivec2( -X, 0)).x * 0.125;
ret += shadow2DArrayOffset(stex3, shadow_coord, ivec2( -X, X)).x * 0.0625;
ret += shadow2DArrayOffset(stex3, shadow_coord, ivec2( 0, -X)).x * 0.125;
ret += shadow2DArrayOffset(stex3, shadow_coord, ivec2( 0, X)).x * 0.125;
ret += shadow2DArrayOffset(stex3, shadow_coord, ivec2( X, -X)).x * 0.0625;
ret += shadow2DArrayOffset(stex3, shadow_coord, ivec2( X, 0)).x * 0.125;
ret += shadow2DArrayOffset(stex3, shadow_coord, ivec2( X, X)).x * 0.0625;
return ret;*/
const int numTaps = 12;
float radius = 0.02f;
float s = 0.0f;
for (int i = 0; i < numTaps; i++)
{
s += shadow2DArray(stex, shadow_coord + vec4(shadowTaps[i] * radius, 0.0f, 0.0f)).r;
}
s /= numTaps;
return s;
}
float filterwidth(float2 v)
{
float2 fw = max(abs(ddx(v)), abs(ddy(v)));
return max(fw.x, fw.y);
}
float2 bump(float2 x)
{
return (floor((x) / 2) + 2.f * max(((x) / 2) - floor((x) / 2) - .5f, 0.f));
}
float checker(float2 uv)
{
float width = filterwidth(uv);
float2 p0 = uv - 0.5 * width;
float2 p1 = uv + 0.5 * width;
float2 i = (bump(p1) - bump(p0)) / width;
return i.x * i.y + (1 - i.x) * (1 - i.y);
}
uniform float fresnelBias = 0.0;
uniform float fresnelScale = 1.0;
uniform float fresnelPower = 3.0; // 5.0 is physically correct
uniform float RollOff = 0.5f;
void main()
{
//// TODO, expose this as user parameter
const float skyLightIntensity = 0.2;
const float rimLightIntensity = 0.3;
vec3 diffuseMat;
vec3 specularMat;
vec3 emissiveReflectSpecPow;
specularMat = vec3(1.0);
emissiveReflectSpecPow = vec3(0.0,0.0,0.0);
vec3 normal = normalize(gl_TexCoord[2].xyz);
vec3 wnormal = normalize(gl_TexCoord[4].xyz);
// read in material color for diffuse, specular, bump, emmisive
// 3D texture
vec4 colorx;
if (useTexture > 0)
colorx = texture2D(texture, gl_TexCoord[0]);
else {
colorx = gl_Color;
colorx *= 1.0 - 0.25*checker(float2(gl_TexCoord[3].x, gl_TexCoord[3].z));
}
colorx = clamp(colorx,0,1);
diffuseMat = colorx.xyz*0.4;
//diffuseMat = myTexture3D(gl_TexCoord[0].xyz);//texture3D(ttt3D, gl_TexCoord[0].xyz);
//diffuseMat = texture3D(ttt3D, gl_TexCoord[0].xyz);
if (dot(normal, gl_TexCoord[1].xyz) > 0) {
normal.xyz *= -1;
}
//gl_FragColor.xyz = normal*0.5 + vec3(0.5,0.5,0.5);
//gl_FragColor.w = 1;
//return;
vec3 eyeVec = normalize(gl_TexCoord[1].xyz);
// apply gamma correction for diffuse textures
//diffuseMat = pow(diffuseMat, 0.45);
float specularPower = emissiveReflectSpecPow.b*255.0f + 1.0f;
// TODO - fix this
specularPower = 10.0f;
float emissive = 0.0f;
float reflectivity = emissiveReflectSpecPow.b;
float fresnel = fresnelBias + fresnelScale*pow(1.0 - max(0.0, dot(normal, eyeVec)), fresnelPower);
float specular = 0.0f;
vec3 skyNormal = reflect(eyeVec, normal);
vec3 skyColor = skyLightIntensity * textureCube(skyboxTex, skyNormal).rgb;
vec3 ambientSkyColor = diffuseMat * skyColor;
vec3 diffuseColor = vec3(0.0, 0.0, 0.0);
if (numShadows >= 1) {
vec3 lightColor = hdrScale * vec3(1.0, 1.0, 1.0);
vec3 shadowColor = vec3(0.4, 0.4, 0.7); // colored shadow
//vec3 lvec = normalize(spotLightDir);
vec3 lvec = normalize(spotLightPos - gl_TexCoord[1].xyz);
float cosine = dot(lvec, spotLightDir);
float intensity = smoothstep(spotLightCosineDecayBegin, spotLightCosineDecayEnd, cosine);
float ldn = max(0.0f, dot(normal, lvec));
float shadowC = shadowCoeff1();
//gl_FragColor = vec4(shadowC,shadowC,shadowC,1.0f);
//return;
vec3 irradiance = shadowC * ldn * lightColor;
// diffuse irradiance
diffuseColor += diffuseMat * irradiance*intensity;
// add colored shadow
diffuseColor += (1.0 - shadowC*ldn) * shadowAmbient * shadowColor * diffuseMat*intensity;
vec3 r = reflect(lvec, normal);
specular += pow(max(0.0, dot(r, eyeVec)), specularPower)*shadowC*intensity;
}
// add rim light
if (numShadows >= 2) {
vec3 lightColor = hdrScale * vec3(1.0, 1.0, 1.0);
vec3 lvec = normalize(spotLightDir2);
float ldn = max(0.0f, dot(normal, lvec));
vec3 irradiance = ldn * lightColor;
// diffuse irradiance
diffuseColor += diffuseMat * irradiance;
}
vec3 color = vec3(0.0, 0.0, 0.0);
color += diffuseColor;
color += ambientSkyColor;
color += specular*specularMat;
color += hdrScale * emissive * diffuseMat;
//vec3 reflectColor = diffuseMat * texture2DRect(reflectionTex, gl_FragCoord.xy).rgb;
//color = reflectionCoeff * reflectColor + (1.0f - reflectionCoeff) * color;
color = (fresnel * skyColor + (1.0 - fresnel) * color) * reflectivity + (1.0 - reflectivity) * color;
gl_FragColor.rgb = color;
gl_FragColor.w = gl_Color.w;
//float fog = clamp(gl_Fog.scale*(gl_Fog.end+gl_TexCoord[1].z), 0.0, 1.0);
//vec4 fogCol = gl_Fog.color;
float fog = clamp(gl_Fog.scale*(gl_Fog.end+gl_TexCoord[1].z), 0.0, 1.0);
vec4 fogCol = gl_Fog.color;
gl_FragColor = mix(fogCol, gl_FragColor, fog);
}

View File

@ -0,0 +1,13 @@
uniform float uvScale = 1.0f;
void main()
{
vec4 eyeSpacePos = gl_ModelViewMatrix * gl_Vertex;
gl_TexCoord[0] = gl_MultiTexCoord0*uvScale;
gl_TexCoord[1] = eyeSpacePos;
gl_FrontColor = gl_Color;
gl_Position = gl_ProjectionMatrix*eyeSpacePos;
gl_TexCoord[2] = gl_ModelViewMatrixInverseTranspose * vec4(gl_Normal.xyz,0.0);
gl_TexCoord[3].xyz = gl_Vertex.xyz;
gl_TexCoord[4].xyz = gl_Normal.xyz;
gl_ClipVertex = vec4(eyeSpacePos.xyz, 1.0f);
}

View File

@ -0,0 +1,38 @@
uniform sampler2D colorTex;
uniform sampler2D depthTex;
uniform float sx;
uniform float sy;
void main (void)
{
const float depthEnd = 0.993;
const float depthSize = 0.015;
vec3 colorP = texture2D(colorTex, gl_TexCoord[0]).rgb;
float depth = texture2D(depthTex, gl_TexCoord[0].st).r;
if ((depth - depthEnd) < depthSize)
{
const int depthKernelSize = 5;
vec3 colorSum = vec3(0.0);
float cnt = 0.0;
for (int x = -depthKernelSize; x <= depthKernelSize; x++)
for (int y = -depthKernelSize; y <= depthKernelSize; y++)
{
float s = gl_TexCoord[0].s + x * sy;
float t = gl_TexCoord[0].t + y * sy;
float scalex = ((depthKernelSize+1) - abs(float(x))) / depthKernelSize;
float scaley = ((depthKernelSize+1) - abs(float(y))) / depthKernelSize;
float scale = scalex * scaley;
vec3 color = texture2D(colorTex, vec2(s,t)).rgb;
colorSum += scale * color;
cnt += scale;
}
colorSum /= cnt;
float depthScale = pow(max(0.0f,min(1.0, ( abs(depth-depthEnd)) / depthSize)),1.5);
colorP = depthScale * colorSum + (1.0 - depthScale) * colorP;
}
gl_FragColor = vec4(colorP, 1.0);
}

View File

@ -0,0 +1,5 @@
void main(void)
{
gl_TexCoord[0] = gl_MultiTexCoord0;
gl_Position = gl_Vertex * 2.0 - 1.0;
}

View File

@ -0,0 +1,123 @@
uniform sampler2DArrayShadow stex;
uniform float shadowAmbient = 0.3;
float shadowCoef()
{
const int index = 0;
/*
int index = 3;
// find the appropriate depth map to look up in based on the depth of this fragment
if(gl_FragCoord.z < far_d.x)
index = 0;
else if(gl_FragCoord.z < far_d.y)
index = 1;
else if(gl_FragCoord.z < far_d.z)
index = 2;
*/
// transform this fragment's position from view space to scaled light clip space
// such that the xy coordinates are in [0;1]
// note there is no need to divide by w for othogonal light sources
vec4 shadow_coord = gl_TextureMatrix[index]*vec4(gl_TexCoord[2].xyz, 1);
shadow_coord.w = shadow_coord.z;
// tell glsl in which layer to do the look up
shadow_coord.z = float(index);
// Gaussian 3x3 filter
return shadow2DArray(stex, shadow_coord).x;
}
uniform float ispotMaxDist;
uniform vec3 spotOriginEye;
uniform sampler2D spot_a0123;
uniform sampler2D spot_b123;
uniform sampler2D smokeTex;
const float PI = 3.1415926535897932384626433832795;
const vec3 _2pik = vec3(2.0) * vec3(PI,2.0*PI,3.0*PI);
const vec3 factor_a = vec3(2.0*PI)*vec3(1.0,2.0,3.0);
const vec3 factor_b = vec3(2.0*PI)*vec3(1.0,2.0,3.0);
const vec3 value_1 = vec3(1.0);
uniform mat4 eyeToSpotMatrix;
void main()
{
//gl_FragColor = gl_Color;
//return;
/*
gl_FragColor = texture2D(smokeTex, gl_TexCoord[0].xy);
gl_FragColor.w = gl_FragColor.r;
gl_FragColor.xyz = vec3(1,1,1);
return;
*/
// calculate eye-space normal from texture coordinates
vec3 N;
N.xy = gl_TexCoord[0].xy*vec2(2.0, -2.0) + vec2(-1.0, 1.0);
float mag = dot(N.xy, N.xy);
if (mag > 1.0) discard; // kill pixels outside circle
float falloff = pow(1.0-mag,1.0);//exp(-mag);
//falloff = 1.0f;
float shadowC = shadowCoef();
vec3 shadowColor = vec3(0.4, 0.4, 0.9)*0.8;
// Also FOM
// vec4 projectionCoordinate = eyeToSpotMatrix*vec4(gl_TexCoord[2].xyz, 1.0f);
vec4 projectionCoordinate = eyeToSpotMatrix*vec4(gl_TexCoord[2].xyz, 1.0f);
//gl_FragColor.xyz = gl_TexCoord[3].xyz*0.25f;
//gl_FragColor.xyz = projectionCoordinate.xyz / projectionCoordinate.w;
//gl_FragColor.w = 1.0f;
//read Fourier series coefficients for color extinction on RGB
vec4 sR_a0123 = texture2DProj(spot_a0123,projectionCoordinate);
vec3 sR_b123 = texture2DProj(spot_b123,projectionCoordinate).rgb;
//gl_FragColor.xyz = sR_a0123.xyz;
//gl_FragColor.w = 1.0f;
//return;
//compute absolute and normalized distance (in spot depth range)
float distance2spotCenter = length(spotOriginEye-gl_TexCoord[2].xyz);//distance from spot origin to surfel in world space
float d = distance2spotCenter*ispotMaxDist;
//compute some value to recover the extinction coefficient using the Fourier series
vec3 sin_a123 = sin(factor_a*vec3(d));
vec3 cos_b123 = value_1-cos(factor_b*vec3(d));
//compute the extinction coefficients using Fourier
float att = (sR_a0123.r*d/2.0) + dot(sin_a123*(sR_a0123.gba/_2pik) ,value_1) + dot(cos_b123*(sR_b123.rgb/_2pik) ,value_1);
att = max(0.0f, att);
att = min(1.0f, att);
shadowC *= (1.0f-att);
float inS = shadowC;
shadowC = (shadowAmbient + (1.0f -shadowAmbient)*shadowC);
//....
if (gl_TexCoord[0].z > 1) shadowC = 1;
vec4 texColor = texture2D(smokeTex, gl_TexCoord[0].xy*0.25+gl_TexCoord[1].xy);
gl_FragColor.xyz = (texColor.x)*gl_Color.xyz*(shadowColor + (vec3(1.0f,1,1) -shadowColor)*shadowC);//*falloff;
gl_FragColor.w = gl_Color.w*texColor.r;
//float fog = clamp(gl_Fog.scale*(gl_Fog.end+gl_TexCoord[2].z), 0.0, 1.0);
//float fog = exp(-gl_Fog.density*(gl_TexCoord[0].z*gl_TexCoord[0].z));
//gl_FragColor = mix(gl_Fog.color, gl_FragColor, fog);
gl_FragColor.xyz *= 1.6f;
gl_FragColor.w *= max(min(falloff,1.0f),0.0f) * max(min(gl_TexCoord[0].w,1.0f),0.0f);
//gl_FragColor.w = 1;
//gl_FragColor.xyz = vec3(shadowC, shadowC, shadowC);
// gl_FragColor.w = 0.2f;
//gl_FragColor.w = falloff * gl_TexCoord[0].w;
//gl_FragColor.xyz = sR_a0123.xyz;
gl_FragColor.xyz *= ((gl_TexCoord[0].z)+inS*0.3)*0.7;
//gl_FragDepth = gl_FragCoord.z - (1-mag)*0.00002;
}

View File

@ -0,0 +1,116 @@
//#version 120\n
//#extension GL_EXT_geometry_shader4 : enable\n
uniform float pointRadius; // point size in world space
uniform float densityThreshold = 50.0;
uniform float idensityThreshold = 1.0 / 30.0;
uniform float pointShrink = 0.25;
uniform sampler2D meteorTex;
void main()
{
gl_FrontColor = gl_FrontColorIn[0];
float density = gl_TexCoordIn[0][1].x;
float life = gl_TexCoordIn[0][1].y;
gl_TexCoord[1].xy = 0.25f*vec2(gl_PrimitiveIDIn / 4, gl_PrimitiveIDIn % 4);
// scale down point size based on density
float factor = 1.0f;//density * idensityThreshold;
//smoothstep(0.0f, densityThreshold, density);
//density * idensityThreshold;
//clamp(density / 50.0f, 0, 1);
float pointSize = pointRadius*factor;//*(pointShrink + smoothstep(0.0, densityThreshold, density)*(1.0-pointShrink));
pointSize *= gl_TexCoordIn[0][3].x;
float tmp = gl_TexCoordIn[0][3].y;
float bb = 1.0f;
if (tmp > 0.5f) {
//gl_FrontColor = vec4(3*life,0,0,1);
// TODO: Meteor trail color here...
//vec2 fetchPos = vec2( min(max((3-lifeTime)/3,0),1), 0);
float val = 1-min(max((life-0.3)/0.2,0.01),0.99);
vec2 fetchPos = vec2(val, 0);
gl_FrontColor = texture2D(meteorTex, fetchPos);
if (gl_FrontColor.r > 0.5) bb += (gl_FrontColor.r-0.5)*(gl_FrontColor.r-0.5)*10;
}
// float pointSize = pointRadius;
// eye space
vec3 pos = gl_PositionIn[0].xyz;
vec3 pos2 = gl_TexCoordIn[0][0].xyz;
vec3 motion = pos - pos2;
vec3 dir = normalize(motion);
float len = length(motion);
vec3 x = dir * pointSize;
vec3 view = normalize(-pos);
vec3 y = normalize(cross(dir, view)) * pointSize;
float facing = dot(view, dir);
// check for very small motion to avoid jitter
float threshold = 0.01;
// if (len < threshold) {
if ((len < threshold) || (facing > 0.95) || (facing < -0.95)) {
pos2 = pos;
x = vec3(pointSize, 0.0, 0.0);
y = vec3(0.0, -pointSize, 0.0);
}
float angle = density;
float cv = cos(angle);
float sv = sin(angle);
vec3 xt = cv*x + sv*y;
vec3 yt = -sv*x + cv*y;
x = xt;
y = yt;
{
gl_TexCoord[0] = vec4(0, 0, bb, life);
gl_TexCoord[2] = vec4(pos + x + y, 1);
gl_Position = gl_ProjectionMatrix * gl_TexCoord[2];
gl_TexCoord[3] = gl_TexCoordIn[0][2];
EmitVertex();
gl_TexCoord[0] = vec4(0, 1, bb, life);
gl_TexCoord[2] = vec4(pos + x - y, 1);
gl_Position = gl_ProjectionMatrix * gl_TexCoord[2];
EmitVertex();
gl_TexCoord[0] = vec4(1, 0, bb, life);
gl_TexCoord[2] = vec4(pos2 - x + y, 1);
gl_Position = gl_ProjectionMatrix * gl_TexCoord[2];
EmitVertex();
gl_TexCoord[0] = vec4(1, 1, bb, life);
gl_TexCoord[2] = vec4(pos2 - x - y, 1);
gl_Position = gl_ProjectionMatrix * gl_TexCoord[2];
EmitVertex();
/*
gl_TexCoord[0] = vec4(0, 0, 0, life);
gl_TexCoord[2] = vec4(pos + x + y, 1);
gl_Position = gl_ProjectionMatrix * gl_TexCoord[2];
EmitVertex();
gl_TexCoord[0] = vec4(0, 1, 0, life);
gl_TexCoord[2] = vec4(pos + x - y, 1);
gl_Position = gl_ProjectionMatrix * gl_TexCoord[2];
EmitVertex();
gl_TexCoord[0] = vec4(1, 0, 0, life);
gl_TexCoord[2] = vec4(pos2 - x + y, 1);
gl_Position = gl_ProjectionMatrix * gl_TexCoord[2];
EmitVertex();
gl_TexCoord[0] = vec4(1, 1, 0, life);
gl_TexCoord[2] = vec4(pos2 - x - y, 1);
gl_Position = gl_ProjectionMatrix * gl_TexCoord[2];
EmitVertex();
*/
}
}

View File

@ -0,0 +1,19 @@
uniform float timestep = 0.02;
uniform vec3 eyeVel;
uniform float iStartFade = 1.0;
void main()
{
vec3 pos = gl_Vertex.xyz;
vec3 vel = gl_MultiTexCoord2.xyz;
//vel = vec3(10.0f,0.0f,0.0f);
vec3 pos2 = (pos - (vel+eyeVel)*timestep); // previous position
gl_Position = gl_ModelViewMatrix * vec4(pos, 1.0); // eye space
gl_TexCoord[0] = gl_ModelViewMatrix * vec4(pos2, 1.0);
gl_TexCoord[1].x = gl_MultiTexCoord1.x;
gl_TexCoord[1].y = max(0.0f, min(gl_MultiTexCoord3.x*iStartFade, 1.0f));
gl_TexCoord[2].xyz = pos;
gl_TexCoord[3] = gl_MultiTexCoord4;
gl_FrontColor = gl_Color;
}

View File

@ -0,0 +1,15 @@
uniform sampler2D ssaoTex;
uniform float sx;
void main (void)
{
float SSAO = 0.0;
for(int x = -4; x <= 4; x++)
{
SSAO += texture2D(ssaoTex,vec2(x * sx + gl_TexCoord[0].s,gl_TexCoord[0].t)).r * (5.0 - abs(float(x)));
}
gl_FragColor = vec4(vec3(SSAO / 25.0),1.0);
gl_FragColor.w = gl_FragColor.x;
}

View File

@ -0,0 +1,17 @@
uniform sampler2D ssaoTex;
uniform float sy;
void main (void)
{
float SSAO = 0.0;
for(int y = -4; y <= 4; y++)
{
SSAO += texture2D(ssaoTex,vec2(gl_TexCoord[0].s,y * sy + gl_TexCoord[0].t)).r * (5.0 - abs(float(y)));
}
gl_FragColor = vec4(vec3(pow(SSAO / 25.0,1.5)),1.0);
gl_FragColor.w = gl_FragColor.x;
//gl_FragColor = vec4(1,1,1,1);
}

View File

@ -0,0 +1,5 @@
void main(void)
{
gl_TexCoord[0] = gl_MultiTexCoord0;
gl_Position = gl_Vertex * 2.0 - 1.0;
}

View File

@ -0,0 +1,7 @@
void main()
{
gl_Position = gl_Vertex;
gl_TexCoord[0] = gl_MultiTexCoord0;
gl_TexCoord[1] = gl_Vertex;
gl_FrontColor = gl_Color;
}

View File

@ -0,0 +1,313 @@
uniform sampler3D ttt3D;
uniform float extraNoiseScale = 1.0f;
float noise3D(vec3 p)
{
return texture3D(ttt3D, p).x*2.0f - 1.0f;
}
float turbulence(vec3 p, int octaves, float lacunarity, float gain) {
float freq = 1.0f;
float amp = 0.8f;
float sum = 0.0f;
for(int i=0; i<octaves; i++) {
sum += abs(noise3D(p*freq))*amp;
freq *= lacunarity;
amp *= gain;
}
return sum;
}
float spike(float c, float w, float x) {
return smoothstep(c-w, c, x) * smoothstep(c+w, c, x);
}
vec3 myTexture3D(vec3 p)
{
float noiseScale = 0.1f*extraNoiseScale;
float noise = turbulence(p*noiseScale, 3, 3.0f, 0.5f);
//noise = turbulence(p*noiseScale + vec3(noise, noise, noise*0.3)*0.01f, 8, 3.0f, 0.5f);
//noise = spike(0.35f, 0.05f, noise);
//noise = noise;
vec3 base = lerp(vec3(164,148,108)*1.63/255, vec3(178,156,126)*1.73/255, spike(0.5f, 0.3f, turbulence(p*noiseScale*0.7f + vec3(noise*0.5, noise, noise)*0.011f, 2, 2.0f, 0.5f)));
//vec3 b2 = lerp(base, vec3(0.0f, 0.0f, 0.0f), noise);
vec3 b2 = lerp(base, vec3(173, 160, 121)*1.73/255, noise);
return b2;
}
// scene reflection
uniform float reflectionCoeff = 0.0f;
uniform float specularCoeff = 0.0f;
uniform sampler2DRect reflectionTex;
// Shadow map
uniform float shadowAmbient = 0.0;
uniform float hdrScale = 5.0;
uniform sampler2D texture;
uniform sampler2DArrayShadow stex;
uniform sampler2DArrayShadow stex2;
uniform sampler2DArrayShadow stex3;
uniform samplerCube skyboxTex;
uniform vec2 texSize; // x - size, y - 1/size
uniform vec4 far_d;
// Spot lights
uniform vec3 spotLightDir;
uniform vec3 spotLightPos;
uniform float spotLightCosineDecayBegin;
uniform float spotLightCosineDecayEnd;
uniform vec3 spotLightDir2;
uniform vec3 spotLightPos2;
uniform float spotLightCosineDecayBegin2;
uniform float spotLightCosineDecayEnd2;
uniform vec3 spotLightDir3;
uniform vec3 spotLightPos3;
uniform float spotLightCosineDecayBegin3;
uniform float spotLightCosineDecayEnd3;
uniform vec3 parallelLightDir;
uniform float shadowAdd;
uniform int useTexture;
uniform int numShadows;
uniform float roughnessScale;
uniform vec3 ambientColor;
uniform sampler2DArray diffuseTexArray;
uniform sampler2DArray bumpTexArray;
uniform sampler2DArray specularTexArray;
uniform sampler2DArray emissiveReflectSpecPowerTexArray;
float shadowCoeff1()
{
const int index = 0;
//int index = 3;
//
//if(gl_FragCoord.z < far_d.x)
// index = 0;
//else if(gl_FragCoord.z < far_d.y)
// index = 1;
//else if(gl_FragCoord.z < far_d.z)
// index = 2;
vec4 shadow_coord = gl_TextureMatrix[index]*vec4(gl_TexCoord[1].xyz, 1);
shadow_coord.w = shadow_coord.z + shadowAdd;
// tell glsl in which layer to do the look up
shadow_coord.z = float(index);
// Gaussian 3x3 filter
// return shadow2DArray(stex, shadow_coord).x;
const float X = 1.0f;
float ret = shadow2DArray(stex, shadow_coord).x * 0.25;
ret += shadow2DArrayOffset(stex, shadow_coord, ivec2( -X, -X)).x * 0.0625;
ret += shadow2DArrayOffset(stex, shadow_coord, ivec2( -X, 0)).x * 0.125;
ret += shadow2DArrayOffset(stex, shadow_coord, ivec2( -X, X)).x * 0.0625;
ret += shadow2DArrayOffset(stex, shadow_coord, ivec2( 0, -X)).x * 0.125;
ret += shadow2DArrayOffset(stex, shadow_coord, ivec2( 0, X)).x * 0.125;
ret += shadow2DArrayOffset(stex, shadow_coord, ivec2( X, -X)).x * 0.0625;
ret += shadow2DArrayOffset(stex, shadow_coord, ivec2( X, 0)).x * 0.125;
ret += shadow2DArrayOffset(stex, shadow_coord, ivec2( X, X)).x * 0.0625;
return ret;
}
float shadowCoeff2()
{
const int index = 1;
//int index = 3;
//if(gl_FragCoord.z < far_d.x)
// index = 0;
//else if(gl_FragCoord.z < far_d.y)
// index = 1;
//else if(gl_FragCoord.z < far_d.z)
// index = 2;
vec4 shadow_coord = gl_TextureMatrix[index]*vec4(gl_TexCoord[1].xyz, 1);
shadow_coord.w = shadow_coord.z + shadowAdd;
shadow_coord.z = float(0);
// return shadow2DArray(stex, shadow_coord).x;
const float X = 1.0f;
float ret = shadow2DArray(stex2, shadow_coord).x * 0.25;
ret += shadow2DArrayOffset(stex2, shadow_coord, ivec2( -X, -X)).x * 0.0625;
ret += shadow2DArrayOffset(stex2, shadow_coord, ivec2( -X, 0)).x * 0.125;
ret += shadow2DArrayOffset(stex2, shadow_coord, ivec2( -X, X)).x * 0.0625;
ret += shadow2DArrayOffset(stex2, shadow_coord, ivec2( 0, -X)).x * 0.125;
ret += shadow2DArrayOffset(stex2, shadow_coord, ivec2( 0, X)).x * 0.125;
ret += shadow2DArrayOffset(stex2, shadow_coord, ivec2( X, -X)).x * 0.0625;
ret += shadow2DArrayOffset(stex2, shadow_coord, ivec2( X, 0)).x * 0.125;
ret += shadow2DArrayOffset(stex2, shadow_coord, ivec2( X, X)).x * 0.0625;
return ret;
}
float shadowCoeff3()
{
const int index = 2;
//int index = 3;
//if(gl_FragCoord.z < far_d.x)
// index = 0;
//else if(gl_FragCoord.z < far_d.y)
// index = 1;
//else if(gl_FragCoord.z < far_d.z)
// index = 2;
vec4 shadow_coord = gl_TextureMatrix[index]*vec4(gl_TexCoord[1].xyz, 1);
shadow_coord.w = shadow_coord.z + shadowAdd;
shadow_coord.z = float(0);
// return shadow2DArray(stex, shadow_coord).x;
const float X = 1.0f;
float ret = shadow2DArray(stex3, shadow_coord).x * 0.25;
ret += shadow2DArrayOffset(stex3, shadow_coord, ivec2( -X, -X)).x * 0.0625;
ret += shadow2DArrayOffset(stex3, shadow_coord, ivec2( -X, 0)).x * 0.125;
ret += shadow2DArrayOffset(stex3, shadow_coord, ivec2( -X, X)).x * 0.0625;
ret += shadow2DArrayOffset(stex3, shadow_coord, ivec2( 0, -X)).x * 0.125;
ret += shadow2DArrayOffset(stex3, shadow_coord, ivec2( 0, X)).x * 0.125;
ret += shadow2DArrayOffset(stex3, shadow_coord, ivec2( X, -X)).x * 0.0625;
ret += shadow2DArrayOffset(stex3, shadow_coord, ivec2( X, 0)).x * 0.125;
ret += shadow2DArrayOffset(stex3, shadow_coord, ivec2( X, X)).x * 0.0625;
return ret;
}
uniform float RollOff = 0.5f;
uniform float fresnelBias = 0.0;
uniform float fresnelScale = 1.0;
uniform float fresnelPower = 3.0; // 5.0 is physically correct
void main()
{
//// TODO, expose this as user parameter
const float skyLightIntensity = 0.2;
const float rimLightIntensity = 0.3;
vec3 normal = normalize(gl_TexCoord[2].xyz);
vec3 t0 = gl_TexCoord[3].xyz;
vec3 t1 = gl_TexCoord[4].xyz;
vec3 diffuseMat;
vec3 specularMat;
vec3 bump;
vec3 emissiveReflectSpecPow;
// read in material color for diffuse, specular, bump, emmisive
if (gl_TexCoord[6].z >= 0.0f) {
// 2D texture
diffuseMat = texture2DArray(diffuseTexArray, gl_TexCoord[6].xyz).rgb;
//specularMat = texture2DArray(specularTexArray, gl_TexCoord[6].xyz).rgb; // TODO Does not seem to work
specularMat = vec3(1.0f);
bump = texture2DArray(bumpTexArray, gl_TexCoord[6].xyz).xyz;
if (dot(bump,bump) < 0.01) bump = vec3(0.5,0.5,1);
emissiveReflectSpecPow = texture2DArray(emissiveReflectSpecPowerTexArray, gl_TexCoord[6].xyz).xyz;
} else {
// 3D texture
diffuseMat = myTexture3D(gl_TexCoord[0].xyz) * vec3(0.5,0.5,0.5);//texture3D(ttt3D, gl_TexCoord[0].xyz);
specularMat = vec3(1.0);
bump = texture2D(texture, gl_TexCoord[5].xy).xyz;
if (dot(bump,bump) < 0.01) bump = vec3(0.5,0.5,1);
emissiveReflectSpecPow = vec3(0.0,0.0,0.0);
}
// apply bump to the normal
bump = (bump - vec3(0.5,0.5,0.5)) * 2.0f;
bump.xy *= roughnessScale*2;
float sc = 1.0f;
normal = normalize(t0*bump.x + t1*bump.y + sc*normal * bump.z);
//gl_FragColor.xyz = normal*0.5 + vec3(0.5,0.5,0.5);
//gl_FragColor.w = 1;
//return;
vec3 eyeVec = normalize(gl_TexCoord[1].xyz);
// apply gamma correction for diffuse textures
diffuseMat = pow(diffuseMat, 0.45);
float specularPower = emissiveReflectSpecPow.b*255.0f + 1.0f;
// TODO - fix this
specularPower = 10.0f;
float emissive = emissiveReflectSpecPow.r*10.0f;
float reflectivity = emissiveReflectSpecPow.b;
float fresnel = fresnelBias + fresnelScale*pow(1.0 - max(0.0, dot(normal, eyeVec)), fresnelPower);
float specular = 0.0f;
vec3 skyNormal = reflect(eyeVec, normal);
vec3 skyColor = skyLightIntensity * textureCube(skyboxTex, skyNormal).rgb;
vec3 ambientSkyColor = diffuseMat * skyColor;
vec3 diffuseColor = vec3(0.0, 0.0, 0.0);
if (numShadows >= 1) {
vec3 lightColor = hdrScale * vec3(1.0, 0.9, 0.9);
vec3 shadowColor = vec3(0.4, 0.4, 0.9); // colored shadow
vec3 lvec = normalize(spotLightDir);
float ldn = max(0.0f, dot(normal, lvec));
float shadowC = shadowCoeff1();
vec3 irradiance = shadowC * ldn * lightColor;
// diffuse irradiance
diffuseColor += diffuseMat * irradiance;
// add colored shadow
diffuseColor += (1.0 - shadowC) * shadowAmbient * shadowColor * diffuseMat;
vec3 r = reflect(lvec, normal);
specular += pow(max(0.0, dot(r,eyeVec)), specularPower)*shadowC;
}
// add rim light
if (numShadows >= 2) {
vec3 lightColor = rimLightIntensity * vec3(1.0, 0.9, 0.9);
vec3 lvec = normalize(spotLightDir2);
float ldn = max(0.0f, dot(normal, lvec));
vec3 irradiance = ldn * lightColor;
// diffuse irradiance
diffuseColor += diffuseMat * irradiance;
}
vec3 color = vec3(0.0, 0.0, 0.0);
color += diffuseColor;
color += ambientSkyColor;
color += specular*specularMat;
color += hdrScale * emissive * diffuseMat;
//vec3 reflectColor = diffuseMat * texture2DRect(reflectionTex, gl_FragCoord.xy).rgb;
//color = reflectionCoeff * reflectColor + (1.0f - reflectionCoeff) * color;
color = (fresnel * skyColor + (1.0 - fresnel) * color) * reflectivity + (1.0 - reflectivity) * color;
gl_FragColor.rgb = color;
gl_FragColor.w = gl_Color.w;
float fog = clamp(gl_Fog.scale*(gl_Fog.end+gl_TexCoord[1].z), 0.0, 1.0);
vec4 fogCol = gl_Fog.color;
gl_FragColor = mix(fogCol, gl_FragColor, fog);
}

View File

@ -0,0 +1,79 @@
uniform float uvScale = 1.0f;
uniform sampler2D transTex;
uniform int transTexSize;
uniform float iTransTexSize;
uniform float bumpTextureUVScale;
//attribute mat4 transformmatrix;
void main()
{
int ti = (int)(gl_MultiTexCoord0.w);
//int ti = tq;
int tpr = transTexSize / 4;
int row = ti / tpr;
int col = (ti - row*tpr)*4;
float fx = (col+0.5f)*iTransTexSize;
float fy = (row+0.5f)*iTransTexSize;
vec4 r0 = texture2D(transTex, vec2(fx,fy));
vec4 r1 = texture2D(transTex, vec2(fx+iTransTexSize,fy));
vec4 r2 = texture2D(transTex, vec2(fx+iTransTexSize*2.0f,fy));
vec4 r3 = texture2D(transTex, vec2(fx+iTransTexSize*3.0f,fy));
// vec4 r3 = vec4(0,0,0,1);
vec3 offset = vec3(r0.w, r1.w, r2.w);
r0.w = 0.0f;
r1.w = 0.0f;
r2.w = 0.0f;
float material = r3.w;
r3.w = 1.0f;
mat4 transformmatrix = mat4(r0,r1,r2,r3);
mat4 mvp = gl_ModelViewMatrix * transformmatrix;
mat4 mvpt = gl_ModelViewMatrixInverseTranspose * transformmatrix;
vec4 t0 = vec4(gl_MultiTexCoord0.xyz, 0.0f);
vec4 t1 = vec4(cross(gl_Normal.xyz, t0.xyz), 0.0f);
// mat4 mvp = gl_ModelViewMatrix;
// mat4 mvpt = gl_ModelViewMatrixInverseTranspose;
vec4 eyeSpacePos = mvp * gl_Vertex;
//eyeSpacePos.y += gl_InstanceID * 0.2f;
//gl_TexCoord[0].xyz = gl_MultiTexCoord0.xyz*uvScale;
vec3 coord3d = gl_Vertex.xyz + offset;
gl_TexCoord[0].xyz = (coord3d)*uvScale;
gl_TexCoord[1] = eyeSpacePos;
gl_FrontColor = gl_Color;
gl_Position = gl_ProjectionMatrix*eyeSpacePos;
gl_TexCoord[2] = mvpt * vec4(gl_Normal.xyz,0.0);
gl_TexCoord[3] = mvpt * t0;
gl_TexCoord[4].xyz = mvpt * t1;
gl_TexCoord[5].xy = vec2(dot(coord3d, t0.xyz), dot(coord3d, t1.xyz))*bumpTextureUVScale*2;
gl_TexCoord[6].xyz = vec3(gl_MultiTexCoord1.xy, material);
gl_TexCoord[6].y = 1.0 - gl_TexCoord[6].y;
float MAX_3D_TEX = 8.0;
if (gl_TexCoord[6].x >= 5.0f) {
// 2D Tex
gl_TexCoord[6].x -= 5.0f;
gl_TexCoord[6].z = floor(gl_TexCoord[6].z / MAX_3D_TEX);
} else {
gl_TexCoord[6].z -= floor(gl_TexCoord[6].z / MAX_3D_TEX)*MAX_3D_TEX;
gl_TexCoord[6].z -= 100.0f;
}
gl_ClipVertex = vec4(eyeSpacePos.xyz, 1.0f);
}

View File

@ -0,0 +1,8 @@
uniform sampler2DArrayShadow tex;
uniform float slice;
void main()
{
float v = shadow2DArray(tex, vec4(gl_TexCoord[0].xy,slice,10.001f));
gl_FragColor = vec4(v,v,v,1);
//gl_FragColor = vec4(1,0,0,1);
}