Merge branch 'master' of https://github.com/supertuxkart/stk-code into devel
This commit is contained in:
@@ -1,24 +0,0 @@
|
||||
uniform sampler2D Albedo;
|
||||
uniform sampler2D caustictex;
|
||||
uniform vec2 dir;
|
||||
uniform vec2 dir2;
|
||||
|
||||
#if __VERSION__ >= 130
|
||||
in vec2 uv;
|
||||
out vec4 FragColor;
|
||||
#else
|
||||
varying vec2 uv;
|
||||
#define FragColor gl_FragColor
|
||||
#endif
|
||||
|
||||
vec3 getLightFactor(float specMapValue);
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 color = texture(Albedo, uv);
|
||||
float caustic = texture(caustictex, uv + dir).x;
|
||||
float caustic2 = texture(caustictex, (uv.yx + dir2 * vec2(-0.6, 0.3)) * vec2(0.6)).x;
|
||||
|
||||
vec3 LightFactor = getLightFactor(1.) + caustic * caustic2 * 10;
|
||||
FragColor = vec4(color.xyz * LightFactor, 1.);
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
uniform sampler2D tex;
|
||||
uniform sampler2D oldtex;
|
||||
uniform vec2 pixel;
|
||||
uniform vec2 multi;
|
||||
uniform int size;
|
||||
|
||||
out vec4 FragColor;
|
||||
|
||||
void main()
|
||||
{
|
||||
float res = 0.0;
|
||||
vec2 tc = gl_TexCoord[0].xy;
|
||||
// tc.y = 1.0 - tc.y;
|
||||
tc *= multi;
|
||||
|
||||
for (int i = 0; i < size; i++)
|
||||
{
|
||||
float col = texture(tex, tc).x;
|
||||
res = max(col, res);
|
||||
|
||||
tc += pixel;
|
||||
}
|
||||
|
||||
float old = texture(oldtex, gl_TexCoord[0].xy).x;
|
||||
|
||||
FragColor = vec4(mix(old, res, 0.7));
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
uniform sampler2D tex1;
|
||||
uniform sampler2D tex2;
|
||||
|
||||
out vec4 FragColor;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 col1 = texture(tex1, gl_TexCoord[0].xy);
|
||||
vec4 col2 = vec4(vec3(texture(tex2, gl_TexCoord[0].xy).x), 1.0);
|
||||
|
||||
FragColor = col1 * col2;
|
||||
}
|
||||
@@ -1,60 +0,0 @@
|
||||
uniform sampler2D tex;
|
||||
uniform vec2 pixel;
|
||||
|
||||
#if __VERSION__ >= 130
|
||||
in vec2 uv;
|
||||
out vec4 FragColor;
|
||||
#else
|
||||
varying vec2 uv;
|
||||
#define FragColor gl_FragColor
|
||||
#endif
|
||||
|
||||
// Separated penumbra, horizontal
|
||||
|
||||
void main()
|
||||
{
|
||||
float sum = 0.0;
|
||||
vec4 tmp;
|
||||
float X = uv.x;
|
||||
float Y = uv.y;
|
||||
float width = 0.0;
|
||||
float zsum = 0.00001;
|
||||
|
||||
tmp = texture(tex, vec2(X - 5.13333 * pixel.x, Y));
|
||||
sum += tmp.x * 0.00640869;
|
||||
zsum += tmp.z;
|
||||
width += tmp.y;
|
||||
|
||||
tmp = texture(tex, vec2(X - 3.26667 * pixel.x, Y));
|
||||
sum += tmp.x * 0.083313;
|
||||
zsum += tmp.z;
|
||||
width += tmp.y;
|
||||
|
||||
tmp = texture(tex, vec2(X - 1.4 * pixel.x, Y));
|
||||
sum += tmp.x * 0.305481;
|
||||
zsum += tmp.z;
|
||||
width += tmp.y;
|
||||
|
||||
tmp = texture(tex, vec2(X, Y));
|
||||
sum += tmp.x * 0.209473;
|
||||
zsum += tmp.z;
|
||||
width += tmp.y;
|
||||
|
||||
tmp = texture(tex, vec2(X + 1.4 * pixel.x, Y));
|
||||
sum += tmp.x * 0.305481;
|
||||
zsum += tmp.z;
|
||||
width += tmp.y;
|
||||
|
||||
tmp = texture(tex, vec2(X + 3.26667 * pixel.x, Y));
|
||||
sum += tmp.x * 0.083313;
|
||||
zsum += tmp.z;
|
||||
width += tmp.y;
|
||||
|
||||
tmp = texture(tex, vec2(X + 5.13333 * pixel.x, Y));
|
||||
sum += tmp.x * 0.00640869;
|
||||
zsum += tmp.z;
|
||||
width += tmp.y;
|
||||
|
||||
float hasz = step(0.7, zsum);
|
||||
FragColor = vec4(sum, (width / zsum) * hasz, hasz, 1.0);
|
||||
}
|
||||
@@ -1,61 +0,0 @@
|
||||
uniform sampler2D tex;
|
||||
uniform vec2 pixel;
|
||||
|
||||
#if __VERSION__ >= 130
|
||||
in vec2 uv;
|
||||
out vec4 FragColor;
|
||||
#else
|
||||
varying vec2 uv;
|
||||
#define FragColor gl_FragColor
|
||||
#endif
|
||||
|
||||
|
||||
// Separated penumbra, vertical
|
||||
|
||||
void main()
|
||||
{
|
||||
float sum = 0.0;
|
||||
vec4 tmp;
|
||||
float X = uv.x;
|
||||
float Y = uv.y;
|
||||
float width = 0.0;
|
||||
float zsum = 0.00001;
|
||||
|
||||
tmp = texture(tex, vec2(X, Y - 5.13333 * pixel.y));
|
||||
sum += tmp.x * 0.00640869;
|
||||
zsum += tmp.z;
|
||||
width += tmp.y;
|
||||
|
||||
tmp = texture(tex, vec2(X, Y - 3.26667 * pixel.y));
|
||||
sum += tmp.x * 0.083313;
|
||||
zsum += tmp.z;
|
||||
width += tmp.y;
|
||||
|
||||
tmp = texture(tex, vec2(X, Y - 1.4 * pixel.y));
|
||||
sum += tmp.x * 0.305481;
|
||||
zsum += tmp.z;
|
||||
width += tmp.y;
|
||||
|
||||
tmp = texture(tex, vec2(X, Y));
|
||||
sum += tmp.x * 0.209473;
|
||||
zsum += tmp.z;
|
||||
width += tmp.y;
|
||||
|
||||
tmp = texture(tex, vec2(X, Y + 1.4 * pixel.y));
|
||||
sum += tmp.x * 0.305481;
|
||||
zsum += tmp.z;
|
||||
width += tmp.y;
|
||||
|
||||
tmp = texture(tex, vec2(X, Y + 3.26667 * pixel.y));
|
||||
sum += tmp.x * 0.083313;
|
||||
zsum += tmp.z;
|
||||
width += tmp.y;
|
||||
|
||||
tmp = texture(tex, vec2(X, Y + 5.13333 * pixel.y));
|
||||
sum += tmp.x * 0.00640869;
|
||||
zsum += tmp.z;
|
||||
width += tmp.y;
|
||||
|
||||
float hasz = step(0.7, zsum);
|
||||
FragColor = vec4(sum, (width / zsum) * hasz, hasz, 1.0);
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
uniform sampler2D tex;
|
||||
uniform sampler2D normals_and_depth;
|
||||
uniform mat4 invproj;
|
||||
uniform vec2 screen;
|
||||
|
||||
out vec4 FragColor;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec2 xy = gl_FragCoord.xy / screen;
|
||||
float FragZ = gl_FragCoord.z;
|
||||
float EnvZ = texture(normals_and_depth, xy).a;
|
||||
vec4 FragmentPos = invproj * (2. * vec4(xy, FragZ, 1.0) - 1.);
|
||||
FragmentPos /= FragmentPos.w;
|
||||
vec4 EnvPos = invproj * (2. * vec4(xy, EnvZ, 1.0) - 1.);
|
||||
EnvPos /= EnvPos.w;
|
||||
float len = dot(vec3(1.0), abs(texture(normals_and_depth, xy).xyz));
|
||||
float alpha = (len < 0.2) ? 1. : clamp((EnvPos.z - FragmentPos.z) * 0.3, 0., 1.);
|
||||
FragColor = texture(tex, gl_PointCoord.xy);
|
||||
FragColor.a *= alpha;
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
uniform float screenw;
|
||||
|
||||
void main()
|
||||
{
|
||||
const float size = 0.5;
|
||||
|
||||
vec4 eyepos = gl_Vertex;
|
||||
vec4 projCorner = gl_ProjectionMatrix * vec4(vec2(size), eyepos.z, eyepos.w);
|
||||
|
||||
gl_PointSize = screenw * projCorner.x / projCorner.w;
|
||||
gl_Position = gl_ProjectionMatrix * eyepos;
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
uniform float time;
|
||||
uniform vec3 campos;
|
||||
uniform mat4 viewm;
|
||||
|
||||
in vec3 initialPosition;
|
||||
out vec3 currentPosition;
|
||||
|
||||
void main()
|
||||
{
|
||||
// This simulation will run accurately for a bit under five days.
|
||||
vec4 start = vec4(initialPosition, 1.0);
|
||||
start.y -= time;
|
||||
|
||||
// How many times has it fell?
|
||||
float count = floor(start.y / 24.0);
|
||||
start.x += sin(count);
|
||||
start.z += cos(count);
|
||||
|
||||
vec2 signs = sign(start.xz);
|
||||
start.xz = mod(start.xz, 17.5) * signs;
|
||||
|
||||
start.y = mod(start.y, 24.0) - 3.0;
|
||||
|
||||
start.xyz += campos;
|
||||
|
||||
currentPosition = (viewm * start).xyz;
|
||||
gl_Position = vec4(0.);
|
||||
}
|
||||
@@ -1,47 +0,0 @@
|
||||
uniform sampler2D halft; // half is a reserved word
|
||||
uniform sampler2D quarter;
|
||||
uniform sampler2D eighth;
|
||||
|
||||
in vec2 uv;
|
||||
out vec4 FragColor;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec3 val[3];
|
||||
val[0] = texture(halft, uv).xyz;
|
||||
val[1] = texture(quarter, uv).xyz;
|
||||
val[2] = texture(eighth, uv).xyz;
|
||||
|
||||
// Find the first level with a penumbra value
|
||||
int i;
|
||||
float q = 0.0;
|
||||
float outval = 1.0;
|
||||
|
||||
float hasshadow = dot(vec3(1.0), vec3(val[0].z, val[1].z, val[2].z));
|
||||
|
||||
if (hasshadow > 0.9)
|
||||
{
|
||||
for (i = 0; i < 3; i++)
|
||||
{
|
||||
if (val[i].z > 0.9)
|
||||
{
|
||||
q = val[i].y;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
q *= 8.0;
|
||||
q = max(1.0, q);
|
||||
q = log2(q);
|
||||
q = min(1.9, q);
|
||||
|
||||
// q is now between 0 and 1.9.
|
||||
int down = int(floor(q));
|
||||
int up = down + 1;
|
||||
float interp = q - float(down);
|
||||
|
||||
outval = 1.0 - mix(val[down].x, val[up].x, interp);
|
||||
}
|
||||
|
||||
FragColor = vec4(vec3(outval), 1.0);
|
||||
}
|
||||
@@ -1,71 +0,0 @@
|
||||
uniform sampler2D ntex;
|
||||
uniform sampler2D ctex;
|
||||
uniform vec3 campos;
|
||||
uniform int low;
|
||||
|
||||
in vec3 wpos;
|
||||
in vec2 texc;
|
||||
out vec4 FragColor;
|
||||
|
||||
float luminanceImp()
|
||||
{
|
||||
// A full-res fetch kills on low-end
|
||||
if (low > 0) return 1.0;
|
||||
|
||||
const vec3 weights = vec3(0.2126, 0.7152, 0.0722); // ITU-R BT. 709
|
||||
vec3 col = texture(ctex, texc).xyz;
|
||||
|
||||
float luma = dot(weights, col);
|
||||
|
||||
// Dark surfaces need less resolution
|
||||
float f = smoothstep(0.1, 0.4, luma);
|
||||
f = max(0.05, f);
|
||||
|
||||
return f;
|
||||
}
|
||||
|
||||
float normalImp(vec3 normal)
|
||||
{
|
||||
vec3 camdir = normalize(campos - wpos);
|
||||
vec3 N = normalize(normal);
|
||||
|
||||
// Boost surfaces facing the viewer directly
|
||||
float f = 2.0 * max(0.0, dot(N, camdir));
|
||||
|
||||
return f;
|
||||
}
|
||||
|
||||
float depthImp(float linearz)
|
||||
{
|
||||
/* const float skip = 0.7;
|
||||
|
||||
float f = min(linearz, skip);
|
||||
f *= 1.0/skip;*/
|
||||
|
||||
float z = log(1.0 + linearz * 9.0) / log(10.0);
|
||||
|
||||
float f = 1.0 - (z * 0.9);
|
||||
|
||||
return f;
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 ntmp = texture(ntex, texc);
|
||||
vec3 normal = ntmp.xyz * 2.0 - 1.0;
|
||||
float linearz = ntmp.a;
|
||||
|
||||
float importance = normalImp(normal) * depthImp(linearz) * luminanceImp();
|
||||
importance = clamp(importance, 0.0, 1.0);
|
||||
|
||||
float low = step(0.001, importance);
|
||||
|
||||
// Quantize it
|
||||
const float steps = 16.0;
|
||||
importance *= steps;
|
||||
importance = ceil(importance) * low;
|
||||
importance /= steps;
|
||||
|
||||
FragColor = vec4(importance);
|
||||
gl_FragDepth = 1.0 - importance;
|
||||
}
|
||||
@@ -1,30 +0,0 @@
|
||||
uniform sampler2D dtex;
|
||||
uniform mat4 ipvmat;
|
||||
uniform mat4 shadowmat;
|
||||
|
||||
out vec3 wpos;
|
||||
out vec2 texc;
|
||||
|
||||
float decdepth(vec4 rgba) {
|
||||
return dot(rgba, vec4(1.0, 1.0/255.0, 1.0/65025.0, 1.0/16581375.0));
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
texc = gl_Vertex.xy / vec2(32767.0);
|
||||
float z = decdepth(vec4(texture(dtex, texc).xyz, 0.0));
|
||||
|
||||
vec3 tmp = vec3(texc, z);
|
||||
tmp = tmp * 2.0 - 1.0;
|
||||
|
||||
vec4 xpos = vec4(tmp, 1.0);
|
||||
xpos = ipvmat * xpos;
|
||||
xpos.xyz /= xpos.w;
|
||||
|
||||
wpos = xpos.xyz;
|
||||
|
||||
// Now we have this pixel's world-space position. Convert to shadow space.
|
||||
vec4 pos = shadowmat * vec4(xpos.xyz, 1.0);
|
||||
|
||||
gl_Position = pos;
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
uniform sampler2D tex;
|
||||
uniform int hastex;
|
||||
uniform int viz;
|
||||
uniform int wireframe;
|
||||
uniform float objectid;
|
||||
|
||||
in vec2 uv;
|
||||
out vec4 FragColor;
|
||||
|
||||
vec4 encdepth(float v) {
|
||||
vec4 enc = vec4(1.0, 255.0, 65025.0, 16581375.0) * v;
|
||||
enc = fract(enc);
|
||||
enc -= enc.yzww * vec4(1.0/255.0, 1.0/255.0, 1.0/255.0, 0.0);
|
||||
return enc;
|
||||
}
|
||||
|
||||
void main() {
|
||||
|
||||
if (hastex != 0) {
|
||||
float alpha = texture(tex, uv).a;
|
||||
|
||||
if (alpha < 0.5)
|
||||
discard;
|
||||
}
|
||||
|
||||
if (viz < 1)
|
||||
{
|
||||
FragColor = vec4(encdepth(gl_FragCoord.z).xyz, objectid);
|
||||
}
|
||||
else {
|
||||
if (wireframe > 0)
|
||||
FragColor = vec4(1.0);
|
||||
else
|
||||
FragColor = texture(tex, uv);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,27 +0,0 @@
|
||||
uniform sampler2D warpx;
|
||||
uniform sampler2D warpy;
|
||||
|
||||
out vec2 uv;
|
||||
|
||||
float decdepth(vec4 rgba) {
|
||||
return dot(rgba, vec4(1.0, 1.0/255.0, 1.0/65025.0, 1.0/16581375.0));
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 pos = gl_ModelViewProjectionMatrix * gl_Vertex;
|
||||
uv = gl_MultiTexCoord0.xy;
|
||||
|
||||
vec2 tc = pos.xy * vec2(0.5) + vec2(0.5);
|
||||
|
||||
float movex = decdepth(texture(warpx, tc));
|
||||
float movey = decdepth(texture(warpy, tc));
|
||||
|
||||
float dx = movex * 2.0 - 1.0;
|
||||
float dy = movey * 2.0 - 1.0;
|
||||
|
||||
dx *= 2.0;
|
||||
dy *= 2.0;
|
||||
|
||||
gl_Position = pos + vec4(dx, dy, vec2(0.0));
|
||||
}
|
||||
@@ -1,56 +0,0 @@
|
||||
uniform sampler2D tex;
|
||||
uniform int size;
|
||||
uniform vec2 pixel;
|
||||
|
||||
out vec4 FragColor;
|
||||
|
||||
vec4 encdepth(float v) {
|
||||
vec4 enc = vec4(1.0, 255.0, 65025.0, 16581375.0) * v;
|
||||
enc = fract(enc);
|
||||
enc -= enc.yzww * vec4(1.0/255.0, 1.0/255.0, 1.0/255.0, 0.0);
|
||||
return enc;
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
vec2 origtc = gl_TexCoord[0].xy;
|
||||
|
||||
// Get total sum
|
||||
float first = 1.0, last = 0.0;
|
||||
float lower = 0.0;
|
||||
float total = 0.0;
|
||||
vec2 tc = 0.5 * pixel;
|
||||
|
||||
for (int i = 0; i < size; i++)
|
||||
{
|
||||
float col = texture(tex, tc).x;
|
||||
|
||||
lower += col * step(tc.x, origtc.x);
|
||||
total += col;
|
||||
|
||||
if (col > 0.0001)
|
||||
{
|
||||
first = min(first, tc.x);
|
||||
last = max(last, tc.x);
|
||||
}
|
||||
|
||||
tc += pixel;
|
||||
}
|
||||
|
||||
float res = (lower / total) - origtc.x;
|
||||
|
||||
// Outside the edges?
|
||||
if (origtc.x <= first)
|
||||
{
|
||||
res = origtc.x * -2.1;
|
||||
}
|
||||
else if (origtc.x >= last)
|
||||
{
|
||||
res = (1.0 - origtc.x) * 2.1;
|
||||
}
|
||||
|
||||
res = res * 0.5 + 0.5;
|
||||
res = clamp(res, 0.01, 0.99);
|
||||
|
||||
FragColor = encdepth(res);
|
||||
}
|
||||
@@ -1,56 +0,0 @@
|
||||
uniform sampler2D tex;
|
||||
uniform int size;
|
||||
uniform vec2 pixel;
|
||||
|
||||
out vec4 FragColor;
|
||||
|
||||
vec4 encdepth(float v) {
|
||||
vec4 enc = vec4(1.0, 255.0, 65025.0, 16581375.0) * v;
|
||||
enc = fract(enc);
|
||||
enc -= enc.yzww * vec4(1.0/255.0, 1.0/255.0, 1.0/255.0, 0.0);
|
||||
return enc;
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
vec2 origtc = gl_TexCoord[0].xy;
|
||||
|
||||
// Get total sum
|
||||
float first = 1.0, last = 0.0;
|
||||
float lower = 0.0;
|
||||
float total = 0.0;
|
||||
vec2 tc = pixel * 0.5;
|
||||
|
||||
for (int i = 0; i < size; i++)
|
||||
{
|
||||
float col = texture(tex, tc).x;
|
||||
|
||||
lower += col * step(tc.y, origtc.y);
|
||||
total += col;
|
||||
|
||||
if (col > 0.0001)
|
||||
{
|
||||
first = min(first, tc.y);
|
||||
last = max(last, tc.y);
|
||||
}
|
||||
|
||||
tc += pixel;
|
||||
}
|
||||
|
||||
float res = (lower / total) - origtc.y;
|
||||
|
||||
// Outside the edges?
|
||||
if (origtc.y <= first)
|
||||
{
|
||||
res = origtc.y * -2.1;
|
||||
}
|
||||
else if (origtc.y >= last)
|
||||
{
|
||||
res = (1.0 - origtc.y) * 2.1;
|
||||
}
|
||||
|
||||
res = res * 0.5 + 0.5;
|
||||
res = clamp(res, 0.01, 0.99);
|
||||
|
||||
FragColor = encdepth(res);
|
||||
}
|
||||
@@ -255,126 +255,6 @@ void SunLightProvider::OnSetConstants(IMaterialRendererServices *srv, int)
|
||||
|
||||
//-------------------------------------
|
||||
|
||||
|
||||
void ShadowPassProvider::OnSetConstants(IMaterialRendererServices *srv, int)
|
||||
{
|
||||
const int hastex = mat.TextureLayer[0].Texture != NULL;
|
||||
srv->setVertexShaderConstant("hastex", &hastex, 1);
|
||||
|
||||
int viz = irr_driver->getShadowViz();
|
||||
srv->setVertexShaderConstant("viz", &viz, 1);
|
||||
|
||||
int wireframe = mat.Wireframe;
|
||||
srv->setVertexShaderConstant("wireframe", &wireframe, 1);
|
||||
|
||||
float objectid = 0;
|
||||
if (hastex)
|
||||
{
|
||||
const stringc name = mat.TextureLayer[0].Texture->getName().getPath();
|
||||
objectid = shash8((const u8 *) name.c_str(), name.size()) / 255.0f;
|
||||
}
|
||||
srv->setVertexShaderConstant("objectid", &objectid, 1);
|
||||
|
||||
//if (!firstdone)
|
||||
// Can't use the firstdone optimization, as this callback is used for multiple shaders
|
||||
{
|
||||
int tex = 0;
|
||||
srv->setVertexShaderConstant("tex", &tex, 1);
|
||||
|
||||
tex = 1;
|
||||
srv->setVertexShaderConstant("warpx", &tex, 1);
|
||||
tex = 2;
|
||||
srv->setVertexShaderConstant("warpy", &tex, 1);
|
||||
|
||||
firstdone = true;
|
||||
}
|
||||
}
|
||||
|
||||
//-------------------------------------
|
||||
|
||||
void ShadowImportanceProvider::OnSetConstants(IMaterialRendererServices *srv, int)
|
||||
{
|
||||
srv->setVertexShaderConstant("shadowmat", m_shadowmat.pointer(), 16);
|
||||
srv->setVertexShaderConstant("ipvmat", m_invprojview.pointer(), 16);
|
||||
|
||||
srv->setVertexShaderConstant("campos", m_campos, 3);
|
||||
|
||||
int low = UserConfigParams::m_shadows == 1;
|
||||
srv->setVertexShaderConstant("low", &low, 1);
|
||||
|
||||
if (!firstdone)
|
||||
{
|
||||
int tex = 0;
|
||||
srv->setVertexShaderConstant("ntex", &tex, 1);
|
||||
|
||||
tex = 1;
|
||||
srv->setVertexShaderConstant("dtex", &tex, 1);
|
||||
|
||||
tex = 2;
|
||||
srv->setVertexShaderConstant("ctex", &tex, 1);
|
||||
|
||||
firstdone = true;
|
||||
}
|
||||
}
|
||||
|
||||
//-------------------------------------
|
||||
|
||||
void CollapseProvider::OnSetConstants(IMaterialRendererServices *srv, int)
|
||||
{
|
||||
srv->setVertexShaderConstant("pixel", m_pixel, 2);
|
||||
srv->setVertexShaderConstant("multi", m_multi, 2);
|
||||
srv->setVertexShaderConstant("size", &m_size, 1);
|
||||
|
||||
//if (!firstdone)
|
||||
// Can't use the firstdone optimization, as this callback is used for multiple shaders
|
||||
{
|
||||
int tex = 0;
|
||||
srv->setVertexShaderConstant("tex", &tex, 1);
|
||||
|
||||
tex = 1;
|
||||
srv->setVertexShaderConstant("oldtex", &tex, 1);
|
||||
|
||||
firstdone = true;
|
||||
}
|
||||
}
|
||||
|
||||
//-------------------------------------
|
||||
|
||||
void MultiplyProvider::OnSetConstants(IMaterialRendererServices *srv, int)
|
||||
{
|
||||
if (!firstdone)
|
||||
{
|
||||
int tex = 0;
|
||||
srv->setVertexShaderConstant("tex1", &tex, 1);
|
||||
|
||||
tex = 1;
|
||||
srv->setVertexShaderConstant("tex2", &tex, 1);
|
||||
|
||||
firstdone = true;
|
||||
}
|
||||
}
|
||||
|
||||
//-------------------------------------
|
||||
|
||||
void ShadowGenProvider::OnSetConstants(IMaterialRendererServices *srv, int)
|
||||
{
|
||||
if (!firstdone)
|
||||
{
|
||||
int tex = 0;
|
||||
srv->setVertexShaderConstant("halft", &tex, 1);
|
||||
|
||||
tex = 1;
|
||||
srv->setVertexShaderConstant("quarter", &tex, 1);
|
||||
|
||||
tex = 2;
|
||||
srv->setVertexShaderConstant("eighth", &tex, 1);
|
||||
|
||||
firstdone = true;
|
||||
}
|
||||
}
|
||||
|
||||
//-------------------------------------
|
||||
|
||||
void DisplaceProvider::OnSetConstants(IMaterialRendererServices *srv, int)
|
||||
{
|
||||
|
||||
|
||||
@@ -426,98 +426,6 @@ private:
|
||||
|
||||
//
|
||||
|
||||
class ShadowPassProvider: public CallBase
|
||||
{
|
||||
public:
|
||||
virtual void OnSetConstants(video::IMaterialRendererServices *srv, int);
|
||||
};
|
||||
|
||||
//
|
||||
|
||||
class ShadowImportanceProvider: public CallBase
|
||||
{
|
||||
public:
|
||||
virtual void OnSetConstants(video::IMaterialRendererServices *srv, int);
|
||||
|
||||
void updateIPVMatrix()
|
||||
{
|
||||
// Update the IPV matrix, only once per frame since it's costly
|
||||
const video::IVideoDriver * const drv = irr_driver->getVideoDriver();
|
||||
|
||||
const core::vector3df &campos =
|
||||
irr_driver->getSceneManager()->getActiveCamera()->getAbsolutePosition();
|
||||
m_campos[0] = campos.X;
|
||||
m_campos[1] = campos.Y;
|
||||
m_campos[2] = campos.Z;
|
||||
|
||||
m_invprojview = drv->getTransform(video::ETS_PROJECTION);
|
||||
m_invprojview *= drv->getTransform(video::ETS_VIEW);
|
||||
m_invprojview.makeInverse();
|
||||
}
|
||||
|
||||
void setShadowMatrix(const core::matrix4 &mat)
|
||||
{
|
||||
m_shadowmat = mat;
|
||||
}
|
||||
|
||||
private:
|
||||
core::matrix4 m_invprojview, m_shadowmat;
|
||||
float m_campos[3];
|
||||
};
|
||||
|
||||
//
|
||||
|
||||
class CollapseProvider: public CallBase
|
||||
{
|
||||
public:
|
||||
virtual void OnSetConstants(video::IMaterialRendererServices *srv, int);
|
||||
|
||||
void setResolution(const int x, const int y)
|
||||
{
|
||||
m_pixel[0] = 1.0f / x;
|
||||
m_pixel[1] = 1.0f / y;
|
||||
|
||||
m_multi[0] = m_multi[1] = 1;
|
||||
|
||||
if (x < 2 || y < 2)
|
||||
{
|
||||
u32 i;
|
||||
for (i = 0; i < 2; i++)
|
||||
{
|
||||
// No increase for the other direction
|
||||
if (m_pixel[i] > 0.9f) m_pixel[i] = m_multi[i] = 0;
|
||||
}
|
||||
|
||||
std::swap(m_multi[0], m_multi[1]);
|
||||
}
|
||||
|
||||
m_size = (int)std::max(x, y);
|
||||
}
|
||||
|
||||
private:
|
||||
float m_pixel[2];
|
||||
int m_size;
|
||||
float m_multi[2];
|
||||
};
|
||||
|
||||
//
|
||||
|
||||
class MultiplyProvider: public CallBase
|
||||
{
|
||||
public:
|
||||
virtual void OnSetConstants(video::IMaterialRendererServices *srv, int);
|
||||
};
|
||||
|
||||
//
|
||||
|
||||
class ShadowGenProvider: public CallBase
|
||||
{
|
||||
public:
|
||||
virtual void OnSetConstants(video::IMaterialRendererServices *srv, int);
|
||||
};
|
||||
|
||||
//
|
||||
|
||||
class DisplaceProvider: public CallBase
|
||||
{
|
||||
public:
|
||||
|
||||
@@ -529,14 +529,23 @@ FrameBuffer::FrameBuffer(const std::vector<GLuint> &RTTs, size_t w, size_t h) :
|
||||
assert(result == GL_FRAMEBUFFER_COMPLETE_EXT);
|
||||
}
|
||||
|
||||
FrameBuffer::FrameBuffer(const std::vector<GLuint> &RTTs, GLuint DS, size_t w, size_t h) :
|
||||
FrameBuffer::FrameBuffer(const std::vector<GLuint> &RTTs, GLuint DS, size_t w, size_t h, bool layered) :
|
||||
DepthTexture(DS), RenderTargets(RTTs), width(w), height(h)
|
||||
{
|
||||
glGenFramebuffers(1, &fbo);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, fbo);
|
||||
for (unsigned i = 0; i < RTTs.size(); i++)
|
||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + i, GL_TEXTURE_2D, RTTs[i], 0);
|
||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_TEXTURE_2D, DS, 0);
|
||||
if (layered)
|
||||
{
|
||||
for (unsigned i = 0; i < RTTs.size(); i++)
|
||||
glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + i, RTTs[i], 0);
|
||||
glFramebufferTexture(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, DS, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
for (unsigned i = 0; i < RTTs.size(); i++)
|
||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + i, GL_TEXTURE_2D, RTTs[i], 0);
|
||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_TEXTURE_2D, DS, 0);
|
||||
}
|
||||
GLenum result = glCheckFramebufferStatus(GL_FRAMEBUFFER);
|
||||
assert(result == GL_FRAMEBUFFER_COMPLETE_EXT);
|
||||
}
|
||||
|
||||
@@ -191,7 +191,7 @@ private:
|
||||
public:
|
||||
FrameBuffer();
|
||||
FrameBuffer(const std::vector <GLuint> &RTTs, size_t w, size_t h);
|
||||
FrameBuffer(const std::vector <GLuint> &RTTs, GLuint DS, size_t w, size_t h);
|
||||
FrameBuffer(const std::vector <GLuint> &RTTs, GLuint DS, size_t w, size_t h, bool layered = false);
|
||||
~FrameBuffer();
|
||||
void Bind();
|
||||
std::vector<GLuint> &getRTT() { return RenderTargets; }
|
||||
|
||||
@@ -31,7 +31,6 @@
|
||||
#include "graphics/post_processing.hpp"
|
||||
#include "graphics/referee.hpp"
|
||||
#include "graphics/shaders.hpp"
|
||||
#include "graphics/shadow_importance.hpp"
|
||||
#include "graphics/stkanimatedmesh.hpp"
|
||||
#include "graphics/stkbillboard.hpp"
|
||||
#include "graphics/stkmeshscenenode.hpp"
|
||||
@@ -477,7 +476,6 @@ void IrrDriver::initDevice()
|
||||
if(m_glsl)
|
||||
{
|
||||
m_shaders = new Shaders();
|
||||
m_shadow_importance = new ShadowImportance();
|
||||
|
||||
m_mrt.clear();
|
||||
m_mrt.reallocate(2);
|
||||
|
||||
@@ -202,8 +202,6 @@ private:
|
||||
float m_lwhite;
|
||||
/** RTTs. */
|
||||
RTT *m_rtts;
|
||||
/** Shadow importance. */
|
||||
ShadowImportance *m_shadow_importance;
|
||||
std::vector<core::matrix4> sun_ortho_matrix;
|
||||
|
||||
/** Additional details to be shown in case that a texture is not found.
|
||||
|
||||
@@ -852,13 +852,6 @@ void Material::setMaterialProperties(video::SMaterial *m, scene::IMeshBuffer* m
|
||||
m->MaterialType = video::EMT_SOLID;
|
||||
}
|
||||
}
|
||||
if (m_graphical_effect == GE_CAUSTICS && irr_driver->isGLSL())
|
||||
{
|
||||
m->MaterialType = irr_driver->getShader(ES_CAUSTICS);
|
||||
|
||||
m->setTexture(1, irr_driver->getTexture(FileManager::SHADER,
|
||||
"caustics.png"));
|
||||
}
|
||||
|
||||
|
||||
// Modify lightmap materials so that vertex colors are taken into account.
|
||||
|
||||
@@ -33,7 +33,6 @@
|
||||
#include "graphics/rtts.hpp"
|
||||
#include "graphics/screenquad.hpp"
|
||||
#include "graphics/shaders.hpp"
|
||||
#include "graphics/shadow_importance.hpp"
|
||||
#include "graphics/stkmeshscenenode.hpp"
|
||||
#include "graphics/stkinstancedscenenode.hpp"
|
||||
#include "graphics/wind.hpp"
|
||||
@@ -706,17 +705,31 @@ void IrrDriver::computeCameraMatrix(scene::ICameraSceneNode * const camnode, siz
|
||||
|
||||
void IrrDriver::renderShadows()
|
||||
{
|
||||
GroupedFPSM<FPSM_DEFAULT>::reset();
|
||||
GroupedFPSM<FPSM_ALPHA_REF_TEXTURE>::reset();
|
||||
GroupedFPSM<FPSM_NORMAL_MAP>::reset();
|
||||
irr_driver->setPhase(SHADOW_PASS);
|
||||
glDisable(GL_BLEND);
|
||||
glEnable(GL_POLYGON_OFFSET_FILL);
|
||||
glPolygonOffset(1.5, 0.);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, m_rtts->getShadowFBO());
|
||||
glViewport(0, 0, 1024, 1024);
|
||||
m_rtts->getShadowFBO().Bind();
|
||||
glClear(GL_DEPTH_BUFFER_BIT);
|
||||
glDrawBuffer(GL_NONE);
|
||||
|
||||
glBindBufferBase(GL_UNIFORM_BUFFER, 0, SharedObject::ViewProjectionMatrixesUBO);
|
||||
|
||||
m_scene_manager->drawAll(scene::ESNRP_SOLID);
|
||||
|
||||
glUseProgram(MeshShader::ShadowShader::Program);
|
||||
for (unsigned i = 0; i < GroupedFPSM<FPSM_DEFAULT>::MeshSet.size(); ++i)
|
||||
drawShadow(*GroupedFPSM<FPSM_DEFAULT>::MeshSet[i], GroupedFPSM<FPSM_DEFAULT>::MVPSet[i]);
|
||||
for (unsigned i = 0; i < GroupedFPSM<FPSM_NORMAL_MAP>::MeshSet.size(); ++i)
|
||||
drawShadow(*GroupedFPSM<FPSM_NORMAL_MAP>::MeshSet[i], GroupedFPSM<FPSM_NORMAL_MAP>::MVPSet[i]);
|
||||
|
||||
glUseProgram(MeshShader::RefShadowShader::Program);
|
||||
for (unsigned i = 0; i < GroupedFPSM<FPSM_ALPHA_REF_TEXTURE>::MeshSet.size(); ++i)
|
||||
drawShadowRef(*GroupedFPSM<FPSM_ALPHA_REF_TEXTURE>::MeshSet[i], GroupedFPSM<FPSM_ALPHA_REF_TEXTURE>::MVPSet[i]);
|
||||
|
||||
glDisable(GL_POLYGON_OFFSET_FILL);
|
||||
|
||||
glViewport(0, 0, UserConfigParams::m_width, UserConfigParams::m_height);
|
||||
|
||||
@@ -53,6 +53,7 @@ static GLuint generateFBO(GLuint ColorAttachement, GLuint DepthAttachement)
|
||||
|
||||
RTT::RTT(size_t width, size_t height)
|
||||
{
|
||||
m_shadow_FBO = NULL;
|
||||
initGL();
|
||||
using namespace video;
|
||||
using namespace core;
|
||||
@@ -107,61 +108,108 @@ RTT::RTT(size_t width, size_t height)
|
||||
RenderTargetTextures[RTT_TMP_128] = generateRTT(shadowsize3, GL_RGBA16F, GL_BGR, GL_FLOAT);
|
||||
RenderTargetTextures[RTT_LOG_LUMINANCE] = generateRTT(shadowsize0, GL_R16F, GL_RED, GL_FLOAT);
|
||||
|
||||
std::vector<GLuint> somevector;
|
||||
somevector.push_back(RenderTargetTextures[RTT_SSAO]);
|
||||
|
||||
FrameBuffers.push_back(new FrameBuffer(std::vector<GLuint> {RenderTargetTextures[RTT_SSAO]}, res.Width, res.Height));
|
||||
FrameBuffers.push_back(new FrameBuffer(somevector, res.Width, res.Height));
|
||||
// Clear this FBO to 1s so that if no SSAO is computed we can still use it.
|
||||
glClearColor(1., 1., 1., 1.);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
|
||||
FrameBuffers.push_back(new FrameBuffer(std::vector<GLuint> {RenderTargetTextures[RTT_NORMAL_AND_DEPTH]}, DepthStencilTexture, res.Width, res.Height));
|
||||
FrameBuffers.push_back(new FrameBuffer(std::vector<GLuint> {RenderTargetTextures[RTT_TMP1], RenderTargetTextures[RTT_TMP2]}, DepthStencilTexture, res.Width, res.Height));
|
||||
FrameBuffers.push_back(new FrameBuffer(std::vector<GLuint> {RenderTargetTextures[RTT_COLOR]}, DepthStencilTexture, res.Width, res.Height));
|
||||
FrameBuffers.push_back(new FrameBuffer(std::vector<GLuint> {RenderTargetTextures[RTT_LOG_LUMINANCE]}, res.Width, res.Height));
|
||||
FrameBuffers.push_back(new FrameBuffer(std::vector<GLuint> {RenderTargetTextures[RTT_MLAA_COLORS]}, res.Width, res.Height));
|
||||
FrameBuffers.push_back(new FrameBuffer(std::vector<GLuint> {RenderTargetTextures[RTT_TMP1]}, DepthStencilTexture, res.Width, res.Height));
|
||||
FrameBuffers.push_back(new FrameBuffer(std::vector<GLuint> {RenderTargetTextures[RTT_TMP2]}, DepthStencilTexture, res.Width, res.Height));
|
||||
FrameBuffers.push_back(new FrameBuffer(std::vector<GLuint> {RenderTargetTextures[RTT_TMP4]}, res.Width, res.Height));
|
||||
FrameBuffers.push_back(new FrameBuffer(std::vector<GLuint> {RenderTargetTextures[RTT_LINEAR_DEPTH]}, res.Width, res.Height));
|
||||
FrameBuffers.push_back(new FrameBuffer(std::vector<GLuint> {RenderTargetTextures[RTT_HALF1]}, half.Width, half.Height));
|
||||
FrameBuffers.push_back(new FrameBuffer(std::vector<GLuint> {RenderTargetTextures[RTT_HALF2]}, half.Width, half.Height));
|
||||
FrameBuffers.push_back(new FrameBuffer(std::vector<GLuint> {RenderTargetTextures[RTT_QUARTER1]}, quarter.Width, quarter.Height));
|
||||
FrameBuffers.push_back(new FrameBuffer(std::vector<GLuint> {RenderTargetTextures[RTT_QUARTER2]}, quarter.Width, quarter.Height));
|
||||
FrameBuffers.push_back(new FrameBuffer(std::vector<GLuint> {RenderTargetTextures[RTT_EIGHTH1]}, eighth.Width, eighth.Height));
|
||||
FrameBuffers.push_back(new FrameBuffer(std::vector<GLuint> {RenderTargetTextures[RTT_EIGHTH2]}, eighth.Width, eighth.Height));
|
||||
FrameBuffers.push_back(new FrameBuffer(std::vector<GLuint> {RenderTargetTextures[RTT_DISPLACE]}, DepthStencilTexture, res.Width, res.Height));
|
||||
FrameBuffers.push_back(new FrameBuffer(std::vector<GLuint> {RenderTargetTextures[RTT_BLOOM_1024]}, 1024, 1024));
|
||||
FrameBuffers.push_back(new FrameBuffer(std::vector<GLuint> {RenderTargetTextures[RTT_BLOOM_512]}, 512, 512));
|
||||
FrameBuffers.push_back(new FrameBuffer(std::vector<GLuint> {RenderTargetTextures[RTT_TMP_512]}, 512, 512));
|
||||
FrameBuffers.push_back(new FrameBuffer(std::vector<GLuint> {RenderTargetTextures[RTT_BLOOM_256]}, 256, 256));
|
||||
FrameBuffers.push_back(new FrameBuffer(std::vector<GLuint> {RenderTargetTextures[RTT_TMP_256]}, 256, 256));
|
||||
FrameBuffers.push_back(new FrameBuffer(std::vector<GLuint> {RenderTargetTextures[RTT_BLOOM_128]}, 128, 128));
|
||||
FrameBuffers.push_back(new FrameBuffer(std::vector<GLuint> {RenderTargetTextures[RTT_TMP_128]}, 128, 128));
|
||||
somevector.clear();
|
||||
somevector.push_back(RenderTargetTextures[RTT_NORMAL_AND_DEPTH]);
|
||||
FrameBuffers.push_back(new FrameBuffer(somevector, DepthStencilTexture, res.Width, res.Height));
|
||||
somevector.clear();
|
||||
somevector.push_back(RenderTargetTextures[RTT_TMP1]);
|
||||
somevector.push_back(RenderTargetTextures[RTT_TMP2]);
|
||||
FrameBuffers.push_back(new FrameBuffer(somevector, DepthStencilTexture, res.Width, res.Height));
|
||||
somevector.clear();
|
||||
somevector.push_back(RenderTargetTextures[RTT_COLOR]);
|
||||
FrameBuffers.push_back(new FrameBuffer(somevector, DepthStencilTexture, res.Width, res.Height));
|
||||
somevector.clear();
|
||||
somevector.push_back(RenderTargetTextures[RTT_LOG_LUMINANCE]);
|
||||
FrameBuffers.push_back(new FrameBuffer(somevector, res.Width, res.Height));
|
||||
somevector.clear();
|
||||
somevector.push_back(RenderTargetTextures[RTT_MLAA_COLORS]);
|
||||
FrameBuffers.push_back(new FrameBuffer(somevector, res.Width, res.Height));
|
||||
somevector.clear();
|
||||
somevector.push_back(RenderTargetTextures[RTT_TMP1]);
|
||||
FrameBuffers.push_back(new FrameBuffer(somevector, DepthStencilTexture, res.Width, res.Height));
|
||||
somevector.clear();
|
||||
somevector.push_back(RenderTargetTextures[RTT_TMP2]);
|
||||
FrameBuffers.push_back(new FrameBuffer(somevector, DepthStencilTexture, res.Width, res.Height));
|
||||
somevector.clear();
|
||||
somevector.push_back(RenderTargetTextures[RTT_TMP4]);
|
||||
FrameBuffers.push_back(new FrameBuffer(somevector, res.Width, res.Height));
|
||||
somevector.clear();
|
||||
somevector.push_back(RenderTargetTextures[RTT_LINEAR_DEPTH]);
|
||||
FrameBuffers.push_back(new FrameBuffer(somevector, res.Width, res.Height));
|
||||
somevector.clear();
|
||||
somevector.push_back(RenderTargetTextures[RTT_HALF1]);
|
||||
FrameBuffers.push_back(new FrameBuffer(somevector, half.Width, half.Height));
|
||||
somevector.clear();
|
||||
somevector.push_back(RenderTargetTextures[RTT_HALF2]);
|
||||
FrameBuffers.push_back(new FrameBuffer(somevector, half.Width, half.Height));
|
||||
somevector.clear();
|
||||
somevector.push_back(RenderTargetTextures[RTT_QUARTER1]);
|
||||
FrameBuffers.push_back(new FrameBuffer(somevector, quarter.Width, quarter.Height));
|
||||
somevector.clear();
|
||||
somevector.push_back(RenderTargetTextures[RTT_QUARTER2]);
|
||||
FrameBuffers.push_back(new FrameBuffer(somevector, quarter.Width, quarter.Height));
|
||||
somevector.clear();
|
||||
somevector.push_back(RenderTargetTextures[RTT_EIGHTH1]);
|
||||
FrameBuffers.push_back(new FrameBuffer(somevector, eighth.Width, eighth.Height));
|
||||
somevector.clear();
|
||||
somevector.push_back(RenderTargetTextures[RTT_EIGHTH2]);
|
||||
FrameBuffers.push_back(new FrameBuffer(somevector, eighth.Width, eighth.Height));
|
||||
somevector.clear();
|
||||
somevector.push_back(RenderTargetTextures[RTT_DISPLACE]);
|
||||
FrameBuffers.push_back(new FrameBuffer(somevector, DepthStencilTexture, res.Width, res.Height));
|
||||
somevector.clear();
|
||||
somevector.push_back(RenderTargetTextures[RTT_BLOOM_1024]);
|
||||
FrameBuffers.push_back(new FrameBuffer(somevector, 1024, 1024));
|
||||
somevector.clear();
|
||||
somevector.push_back(RenderTargetTextures[RTT_BLOOM_512]);
|
||||
FrameBuffers.push_back(new FrameBuffer(somevector, 512, 512));
|
||||
somevector.clear();
|
||||
somevector.push_back(RenderTargetTextures[RTT_TMP_512]);
|
||||
FrameBuffers.push_back(new FrameBuffer(somevector, 512, 512));
|
||||
somevector.clear();
|
||||
somevector.push_back(RenderTargetTextures[RTT_BLOOM_256]);
|
||||
FrameBuffers.push_back(new FrameBuffer(somevector, 256, 256));
|
||||
somevector.clear();
|
||||
somevector.push_back(RenderTargetTextures[RTT_TMP_256]);
|
||||
FrameBuffers.push_back(new FrameBuffer(somevector, 256, 256));
|
||||
somevector.clear();
|
||||
somevector.push_back(RenderTargetTextures[RTT_BLOOM_128]);
|
||||
FrameBuffers.push_back(new FrameBuffer(somevector, 128, 128));
|
||||
somevector.clear();
|
||||
somevector.push_back(RenderTargetTextures[RTT_TMP_128]);
|
||||
FrameBuffers.push_back(new FrameBuffer(somevector, 128, 128));
|
||||
|
||||
if (irr_driver->getGLSLVersion() >= 150)
|
||||
{
|
||||
glGenFramebuffers(1, &shadowFBO);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, shadowFBO);
|
||||
glGenTextures(1, &shadowColorTex);
|
||||
glBindTexture(GL_TEXTURE_2D_ARRAY, shadowColorTex);
|
||||
glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_R8, 1024, 1024, 4, 0, GL_RED, GL_UNSIGNED_BYTE, 0);
|
||||
glGenTextures(1, &shadowDepthTex);
|
||||
glBindTexture(GL_TEXTURE_2D_ARRAY, shadowDepthTex);
|
||||
glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_DEPTH_COMPONENT24, 1024, 1024, 4, 0, GL_DEPTH_COMPONENT, GL_FLOAT, 0);
|
||||
glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, shadowColorTex, 0);
|
||||
glFramebufferTexture(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, shadowDepthTex, 0);
|
||||
GLenum result = glCheckFramebufferStatus(GL_FRAMEBUFFER);
|
||||
assert(result == GL_FRAMEBUFFER_COMPLETE_EXT);
|
||||
glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_DEPTH_STENCIL, 1024, 1024, 4, 0, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, 0);
|
||||
|
||||
somevector.clear();
|
||||
somevector.push_back(shadowColorTex);
|
||||
m_shadow_FBO = new FrameBuffer(somevector, shadowDepthTex, 1024, 1024, true);
|
||||
}
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
}
|
||||
|
||||
RTT::~RTT()
|
||||
{
|
||||
delete m_shadow_FBO;
|
||||
glDeleteTextures(RTT_COUNT, RenderTargetTextures);
|
||||
glDeleteTextures(1, &DepthStencilTexture);
|
||||
if (irr_driver->getGLSLVersion() >= 150)
|
||||
{
|
||||
glDeleteFramebuffers(1, &shadowFBO);
|
||||
glDeleteTextures(1, &shadowColorTex);
|
||||
glDeleteTextures(1, &shadowDepthTex);
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ public:
|
||||
RTT(size_t width, size_t height);
|
||||
~RTT();
|
||||
|
||||
unsigned getShadowFBO() const { return shadowFBO; }
|
||||
FrameBuffer &getShadowFBO() { return *m_shadow_FBO; }
|
||||
unsigned getShadowDepthTex() const { return shadowDepthTex; }
|
||||
|
||||
unsigned getDepthStencilTexture() const { return DepthStencilTexture; }
|
||||
@@ -48,7 +48,8 @@ private:
|
||||
PtrVector<FrameBuffer> FrameBuffers;
|
||||
unsigned DepthStencilTexture;
|
||||
|
||||
unsigned shadowFBO, shadowColorTex, shadowDepthTex;
|
||||
unsigned shadowColorTex, shadowDepthTex;
|
||||
FrameBuffer* m_shadow_FBO;
|
||||
|
||||
LEAK_CHECK();
|
||||
};
|
||||
|
||||
@@ -42,11 +42,6 @@ Shaders::Shaders()
|
||||
m_callbacks[ES_MIPVIZ] = new MipVizProvider();
|
||||
m_callbacks[ES_COLORIZE] = new ColorizeProvider();
|
||||
m_callbacks[ES_SUNLIGHT] = new SunLightProvider();
|
||||
m_callbacks[ES_SHADOWPASS] = new ShadowPassProvider();
|
||||
m_callbacks[ES_SHADOW_IMPORTANCE] = new ShadowImportanceProvider();
|
||||
m_callbacks[ES_COLLAPSE] = new CollapseProvider();
|
||||
m_callbacks[ES_MULTIPLY_ADD] = new MultiplyProvider();
|
||||
m_callbacks[ES_SHADOWGEN] = new ShadowGenProvider();
|
||||
m_callbacks[ES_DISPLACE] = new DisplaceProvider();
|
||||
|
||||
for (s32 i = 0; i < ES_COUNT; i++)
|
||||
@@ -212,9 +207,6 @@ void Shaders::loadShaders()
|
||||
m_shaders[ES_BUBBLES] = glslmat(dir + "pass.vert", dir + "pass.frag",
|
||||
m_callbacks[ES_BUBBLES], EMT_TRANSPARENT_ALPHA_CHANNEL);
|
||||
|
||||
m_shaders[ES_RAIN] = glslmat(dir + "pass.vert", dir + "pass.frag",
|
||||
m_callbacks[ES_RAIN], EMT_TRANSPARENT_ALPHA_CHANNEL);
|
||||
|
||||
m_shaders[ES_MOTIONBLUR] = glsl(dir + "pass.vert", dir + "pass.frag",
|
||||
m_callbacks[ES_MOTIONBLUR]);
|
||||
|
||||
@@ -236,32 +228,6 @@ void Shaders::loadShaders()
|
||||
|
||||
m_shaders[ES_SUNLIGHT] = glsl_noinput(dir + "pass.vert", dir + "pass.frag");
|
||||
|
||||
m_shaders[ES_SHADOWPASS] = glsl(dir + "pass.vert", dir + "pass.frag",
|
||||
m_callbacks[ES_SHADOWPASS]);
|
||||
|
||||
m_shaders[ES_SHADOW_IMPORTANCE] = glsl(dir + "pass.vert", dir + "pass.frag",
|
||||
m_callbacks[ES_SHADOW_IMPORTANCE]);
|
||||
|
||||
m_shaders[ES_COLLAPSE] = glsl(dir + "pass.vert", dir + "pass.frag",
|
||||
m_callbacks[ES_COLLAPSE]);
|
||||
m_shaders[ES_SHADOW_WARPH] = glsl(dir + "pass.vert", dir + "pass.frag",
|
||||
m_callbacks[ES_COLLAPSE]);
|
||||
m_shaders[ES_SHADOW_WARPV] = glsl(dir + "pass.vert", dir + "pass.frag",
|
||||
m_callbacks[ES_COLLAPSE]);
|
||||
|
||||
m_shaders[ES_MULTIPLY_ADD] = glslmat(dir + "pass.vert", dir + "pass.frag",
|
||||
m_callbacks[ES_MULTIPLY_ADD], EMT_ONETEXTURE_BLEND);
|
||||
|
||||
m_shaders[ES_PENUMBRAH] = glslmat(dir + "pass.vert", dir + "pass.frag",
|
||||
m_callbacks[ES_GAUSSIAN3H], EMT_SOLID);
|
||||
m_shaders[ES_PENUMBRAV] = glslmat(dir + "pass.vert", dir + "pass.frag",
|
||||
m_callbacks[ES_GAUSSIAN3H], EMT_SOLID);
|
||||
m_shaders[ES_SHADOWGEN] = glslmat(dir + "pass.vert", dir + "pass.frag",
|
||||
m_callbacks[ES_SHADOWGEN], EMT_SOLID);
|
||||
|
||||
m_shaders[ES_CAUSTICS] = glslmat(dir + "pass.vert", dir + "pass.frag",
|
||||
m_callbacks[ES_CAUSTICS], EMT_SOLID);
|
||||
|
||||
m_shaders[ES_DISPLACE] = glsl(dir + "pass.vert", dir + "pass.frag",
|
||||
m_callbacks[ES_DISPLACE]);
|
||||
|
||||
@@ -345,7 +311,6 @@ void Shaders::loadShaders()
|
||||
MeshShader::SplattingShader::init();
|
||||
MeshShader::GrassPass1Shader::init();
|
||||
MeshShader::GrassPass2Shader::init();
|
||||
MeshShader::CausticsShader::init();
|
||||
MeshShader::BubbleShader::init();
|
||||
MeshShader::TransparentShader::init();
|
||||
MeshShader::TransparentFogShader::init();
|
||||
@@ -1267,54 +1232,6 @@ namespace MeshShader
|
||||
glUniform3f(uniform_ambient, s.r, s.g, s.b);
|
||||
}
|
||||
|
||||
GLuint CausticsShader::Program;
|
||||
GLuint CausticsShader::attrib_position;
|
||||
GLuint CausticsShader::attrib_texcoord;
|
||||
GLuint CausticsShader::uniform_MVP;
|
||||
GLuint CausticsShader::uniform_dir;
|
||||
GLuint CausticsShader::uniform_dir2;
|
||||
GLuint CausticsShader::uniform_ambient;
|
||||
GLuint CausticsShader::TU_Albedo;
|
||||
GLuint CausticsShader::TU_caustictex;
|
||||
|
||||
void CausticsShader::init()
|
||||
{
|
||||
Program = LoadProgram(
|
||||
GL_VERTEX_SHADER, file_manager->getAsset("shaders/object_pass.vert").c_str(),
|
||||
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/utils/getLightFactor.frag").c_str(),
|
||||
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/caustics.frag").c_str());
|
||||
attrib_position = glGetAttribLocation(Program, "Position");
|
||||
attrib_texcoord = glGetAttribLocation(Program, "Texcoord");
|
||||
uniform_MVP = glGetUniformLocation(Program, "ModelViewProjectionMatrix");
|
||||
uniform_dir = glGetUniformLocation(Program, "dir");
|
||||
uniform_dir2 = glGetUniformLocation(Program, "dir2");
|
||||
GLuint uniform_Albedo = glGetUniformLocation(Program, "Albedo");
|
||||
GLuint uniform_caustictex = glGetUniformLocation(Program, "caustictex");
|
||||
GLuint uniform_DiffuseMap = glGetUniformLocation(Program, "DiffuseMap");
|
||||
GLuint uniform_SpecularMap = glGetUniformLocation(Program, "SpecularMap");
|
||||
GLuint uniform_SSAO = glGetUniformLocation(Program, "SSAO");
|
||||
uniform_ambient = glGetUniformLocation(Program, "ambient");
|
||||
TU_Albedo = 3;
|
||||
TU_caustictex = 4;
|
||||
|
||||
glUseProgram(Program);
|
||||
glUniform1i(uniform_DiffuseMap, 0);
|
||||
glUniform1i(uniform_SpecularMap, 1);
|
||||
glUniform1i(uniform_SSAO, 2);
|
||||
glUniform1i(uniform_Albedo, TU_Albedo);
|
||||
glUniform1i(uniform_caustictex, TU_caustictex);
|
||||
glUseProgram(0);
|
||||
}
|
||||
|
||||
void CausticsShader::setUniforms(const core::matrix4 &ModelViewProjectionMatrix, const core::vector2df &dir, const core::vector2df &dir2, const core::vector2df &screen)
|
||||
{
|
||||
glUniformMatrix4fv(uniform_MVP, 1, GL_FALSE, ModelViewProjectionMatrix.pointer());
|
||||
glUniform2f(uniform_dir, dir.X, dir.Y);
|
||||
glUniform2f(uniform_dir2, dir2.X, dir2.Y);
|
||||
const video::SColorf s = irr_driver->getSceneManager()->getAmbientLight();
|
||||
glUniform3f(uniform_ambient, s.r, s.g, s.b);
|
||||
}
|
||||
|
||||
GLuint BubbleShader::Program;
|
||||
GLuint BubbleShader::attrib_position;
|
||||
GLuint BubbleShader::attrib_texcoord;
|
||||
|
||||
@@ -269,18 +269,6 @@ public:
|
||||
static void setUniforms(const core::matrix4 &ModelMatrix);
|
||||
};
|
||||
|
||||
class CausticsShader
|
||||
{
|
||||
public:
|
||||
static GLuint Program;
|
||||
static GLuint attrib_position, attrib_texcoord;
|
||||
static GLuint uniform_MVP, uniform_dir, uniform_dir2, uniform_ambient;
|
||||
static GLuint TU_Albedo, TU_caustictex;
|
||||
|
||||
static void init();
|
||||
static void setUniforms(const core::matrix4 &ModelViewProjectionMatrix, const core::vector2df &dir, const core::vector2df &dir2, const core::vector2df &screen);
|
||||
};
|
||||
|
||||
class BubbleShader
|
||||
{
|
||||
public:
|
||||
@@ -901,7 +889,6 @@ public:
|
||||
ACT(ES_GRASS) \
|
||||
ACT(ES_GRASS_REF) \
|
||||
ACT(ES_BUBBLES) \
|
||||
ACT(ES_RAIN) \
|
||||
ACT(ES_MOTIONBLUR) \
|
||||
ACT(ES_GAUSSIAN3H) \
|
||||
ACT(ES_GAUSSIAN3V) \
|
||||
@@ -912,16 +899,6 @@ public:
|
||||
ACT(ES_OBJECTPASS_REF) \
|
||||
ACT(ES_SUNLIGHT) \
|
||||
ACT(ES_OBJECTPASS_RIMLIT) \
|
||||
ACT(ES_SHADOWPASS) \
|
||||
ACT(ES_SHADOW_IMPORTANCE) \
|
||||
ACT(ES_COLLAPSE) \
|
||||
ACT(ES_SHADOW_WARPH) \
|
||||
ACT(ES_SHADOW_WARPV) \
|
||||
ACT(ES_MULTIPLY_ADD) \
|
||||
ACT(ES_PENUMBRAH) \
|
||||
ACT(ES_PENUMBRAV) \
|
||||
ACT(ES_SHADOWGEN) \
|
||||
ACT(ES_CAUSTICS) \
|
||||
ACT(ES_DISPLACE) \
|
||||
ACT(ES_PASSFAR) \
|
||||
|
||||
|
||||
@@ -1,168 +0,0 @@
|
||||
//
|
||||
// SuperTuxKart - a fun racing game with go-kart
|
||||
// Copyright (C) 2013 Lauri Kasanen
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License
|
||||
// as published by the Free Software Foundation; either version 3
|
||||
// of the License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
#include "config/user_config.hpp"
|
||||
#include "graphics/glwrap.hpp"
|
||||
#include "graphics/irr_driver.hpp"
|
||||
#include "graphics/large_mesh_buffer.hpp"
|
||||
#include "graphics/material_manager.hpp"
|
||||
#include "graphics/material.hpp"
|
||||
#include "graphics/per_camera_node.hpp"
|
||||
#include "graphics/shadow_importance.hpp"
|
||||
#include "graphics/shaders.hpp"
|
||||
#include "graphics/rtts.hpp"
|
||||
#include "utils/vs.hpp"
|
||||
|
||||
#include <ISceneManager.h>
|
||||
|
||||
using namespace video;
|
||||
using namespace scene;
|
||||
using namespace core;
|
||||
|
||||
// The actual ShadowImportance node
|
||||
class ShadowImportanceNode: public scene::ISceneNode
|
||||
{
|
||||
public:
|
||||
ShadowImportanceNode(scene::ISceneManager* mgr)
|
||||
: scene::ISceneNode(0, mgr, -1)
|
||||
{
|
||||
mat.Lighting = false;
|
||||
mat.ZWriteEnable = false;
|
||||
mat.MaterialType = irr_driver->getShader(ES_SHADOW_IMPORTANCE);
|
||||
|
||||
// mat.setTexture(0, irr_driver->getRTT(RTT_NORMAL_AND_DEPTH));
|
||||
// mat.setTexture(2, irr_driver->getRTT(RTT_COLOR));
|
||||
|
||||
mat.setFlag(EMF_BILINEAR_FILTER, false);
|
||||
|
||||
u32 i;
|
||||
for (i = 0; i < MATERIAL_MAX_TEXTURES; i++)
|
||||
{
|
||||
mat.TextureLayer[i].TextureWrapU =
|
||||
mat.TextureLayer[i].TextureWrapV = ETC_CLAMP_TO_EDGE;
|
||||
}
|
||||
|
||||
// Low shadows only back-project every other pixel
|
||||
const u32 incr = UserConfigParams::m_shadows < 2 ? 2 : 1;
|
||||
|
||||
count = (UserConfigParams::m_width * UserConfigParams::m_height) / (incr * incr);
|
||||
|
||||
// Fill in the mesh buffer
|
||||
buf.Vertices.clear();
|
||||
buf.Indices.clear();
|
||||
|
||||
buf.Vertices.set_used(count);
|
||||
buf.Indices.set_used(count);
|
||||
|
||||
buf.Primitive = EPT_POINTS;
|
||||
buf.setHardwareMappingHint(EHM_STATIC);
|
||||
|
||||
const float halfx = 0.5f / UserConfigParams::m_width;
|
||||
const float halfy = 0.5f / UserConfigParams::m_height;
|
||||
|
||||
list = glGenLists(1);
|
||||
|
||||
s32 x, y;
|
||||
i = 0;
|
||||
glNewList(list, GL_COMPILE);
|
||||
glBegin(GL_POINTS);
|
||||
for (x = 0; x < UserConfigParams::m_width; x += incr)
|
||||
{
|
||||
const float xpos = ((float) x) / UserConfigParams::m_width + halfx;
|
||||
|
||||
for (y = 0; y < UserConfigParams::m_height; y += incr)
|
||||
{
|
||||
const float ypos = ((float) y) / UserConfigParams::m_height + halfy;
|
||||
|
||||
buf.Indices[i] = i;
|
||||
buf.Vertices[i] = S3DVertex(xpos, ypos, 0, 0, 0, 0,
|
||||
SColor(255, 255, 255, 255), 0, 0);
|
||||
|
||||
glVertex2s((int)roundf(xpos * 32767), (int)roundf(ypos * 32767));
|
||||
i++;
|
||||
}
|
||||
}
|
||||
glEnd();
|
||||
glEndList();
|
||||
|
||||
box.addInternalPoint(vector3df(-1));
|
||||
box.addInternalPoint(vector3df(1));
|
||||
}
|
||||
|
||||
~ShadowImportanceNode()
|
||||
{
|
||||
}
|
||||
|
||||
virtual void render()
|
||||
{
|
||||
IVideoDriver * const drv = irr_driver->getVideoDriver();
|
||||
drv->setMaterial(mat);
|
||||
|
||||
drv->setTransform(ETS_WORLD, IdentityMatrix);
|
||||
|
||||
// drv->drawMeshBuffer(&buf);
|
||||
// Setup the env for drawing our list by drawing one point
|
||||
drv->drawVertexPrimitiveList(buf.getVertices(), 1, buf.getIndices(), 1,
|
||||
EVT_STANDARD, EPT_POINTS);
|
||||
glCallList(list);
|
||||
}
|
||||
|
||||
virtual const core::aabbox3d<f32>& getBoundingBox() const
|
||||
{
|
||||
return box;
|
||||
}
|
||||
|
||||
virtual void OnRegisterSceneNode()
|
||||
{
|
||||
ISceneNode::OnRegisterSceneNode();
|
||||
}
|
||||
|
||||
virtual u32 getMaterialCount() const { return 1; }
|
||||
virtual video::SMaterial& getMaterial(u32 i) { return mat; }
|
||||
|
||||
private:
|
||||
video::SMaterial mat;
|
||||
core::aabbox3d<f32> box;
|
||||
u32 count;
|
||||
GLuint list;
|
||||
|
||||
scene::LargeMeshBuffer buf;
|
||||
};
|
||||
|
||||
// The ShadowImportance manager
|
||||
|
||||
ShadowImportance::ShadowImportance()
|
||||
{
|
||||
m_node = new ShadowImportanceNode(irr_driver->getSceneManager());
|
||||
m_node->setAutomaticCulling(0);
|
||||
} // ShadowImportance
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
ShadowImportance::~ShadowImportance()
|
||||
{
|
||||
m_node->drop(); // drop STK's reference
|
||||
m_node->remove(); // Then remove it from the scene graph.
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
void ShadowImportance::render()
|
||||
{
|
||||
m_node->render();
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
//
|
||||
// SuperTuxKart - a fun racing game with go-kart
|
||||
// Copyright (C) 2013 Lauri Kasanen
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License
|
||||
// as published by the Free Software Foundation; either version 3
|
||||
// of the License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
#ifndef HEADER_SHADOW_IMPORTANCE_HPP
|
||||
#define HEADER_SHADOW_IMPORTANCE_HPP
|
||||
|
||||
#include <vector3d.h>
|
||||
namespace irr
|
||||
{
|
||||
namespace video { class SMaterial; class ITexture; }
|
||||
namespace scene { class ICameraSceneNode; class ISceneNode; }
|
||||
}
|
||||
using namespace irr;
|
||||
|
||||
class ShadowImportance
|
||||
{
|
||||
scene::ISceneNode *m_node;
|
||||
|
||||
public:
|
||||
ShadowImportance();
|
||||
~ShadowImportance();
|
||||
|
||||
void render();
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -143,7 +143,7 @@ void STKAnimatedMesh::render()
|
||||
continue;
|
||||
}
|
||||
|
||||
if (irr_driver->getPhase() == SOLID_NORMAL_AND_DEPTH_PASS)
|
||||
if (irr_driver->getPhase() == SOLID_NORMAL_AND_DEPTH_PASS || irr_driver->getPhase() == SHADOW_PASS)
|
||||
{
|
||||
ModelViewProjectionMatrix = computeMVP(AbsoluteTransformation);
|
||||
TransposeInverseModelView = computeTIMV(AbsoluteTransformation);
|
||||
@@ -225,23 +225,6 @@ void STKAnimatedMesh::render()
|
||||
return;
|
||||
}
|
||||
|
||||
if (irr_driver->getPhase() == SHADOW_PASS)
|
||||
{
|
||||
if (!GeometricMesh[FPSM_DEFAULT].empty())
|
||||
glUseProgram(MeshShader::ShadowShader::Program);
|
||||
|
||||
GLMesh* mesh;
|
||||
for_in(mesh, GeometricMesh[FPSM_DEFAULT])
|
||||
drawShadow(*mesh, AbsoluteTransformation);
|
||||
|
||||
if (!GeometricMesh[FPSM_ALPHA_REF_TEXTURE].empty())
|
||||
glUseProgram(MeshShader::RefShadowShader::Program);
|
||||
|
||||
for_in(mesh, GeometricMesh[FPSM_ALPHA_REF_TEXTURE])
|
||||
drawShadowRef(*mesh, AbsoluteTransformation);
|
||||
return;
|
||||
}
|
||||
|
||||
if (irr_driver->getPhase() == TRANSPARENT_PASS)
|
||||
{
|
||||
ModelViewProjectionMatrix = computeMVP(AbsoluteTransformation);
|
||||
|
||||
@@ -35,8 +35,6 @@ ShadedMaterial MaterialTypeToShadedMaterial(video::E_MATERIAL_TYPE type, video::
|
||||
return SM_GRASS;
|
||||
else if (type == irr_driver->getShader(ES_OBJECT_UNLIT))
|
||||
return SM_UNLIT;
|
||||
else if (type == irr_driver->getShader(ES_CAUSTICS))
|
||||
return SM_CAUSTICS;
|
||||
else if (textures[1] && type != irr_driver->getShader(ES_NORMAL_MAP))
|
||||
return SM_DETAILS;
|
||||
else if (!textures[0])
|
||||
@@ -427,39 +425,6 @@ void drawObjectRefPass2(const GLMesh &mesh, const core::matrix4 &ModelViewProjec
|
||||
|
||||
static video::ITexture *CausticTex = 0;
|
||||
|
||||
void drawCaustics(const GLMesh &mesh, const core::matrix4 & ModelViewProjectionMatrix, core::vector2df dir, core::vector2df dir2)
|
||||
{
|
||||
irr_driver->IncreaseObjectCount();
|
||||
GLenum ptype = mesh.PrimitiveType;
|
||||
GLenum itype = mesh.IndexType;
|
||||
size_t count = mesh.IndexCount;
|
||||
|
||||
compressTexture(mesh.textures[0], true);
|
||||
setTexture(MeshShader::CausticsShader::TU_Albedo, getTextureGLuint(mesh.textures[0]), GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR, true);
|
||||
if (irr_driver->getLightViz())
|
||||
{
|
||||
GLint swizzleMask[] = { GL_ONE, GL_ONE, GL_ONE, GL_ALPHA };
|
||||
glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_RGBA, swizzleMask);
|
||||
}
|
||||
else
|
||||
{
|
||||
GLint swizzleMask[] = { GL_RED, GL_GREEN, GL_BLUE, GL_ALPHA };
|
||||
glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_RGBA, swizzleMask);
|
||||
}
|
||||
if (!CausticTex)
|
||||
CausticTex = irr_driver->getTexture(file_manager->getAsset("textures/caustics.png").c_str());
|
||||
compressTexture(CausticTex, false);
|
||||
setTexture(MeshShader::CausticsShader::TU_caustictex, getTextureGLuint(CausticTex), GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR, true);
|
||||
|
||||
MeshShader::CausticsShader::setUniforms(ModelViewProjectionMatrix, dir, dir2,
|
||||
core::vector2df(float(UserConfigParams::m_width),
|
||||
float(UserConfigParams::m_height)));
|
||||
|
||||
assert(mesh.vao_second_pass);
|
||||
glBindVertexArray(mesh.vao_second_pass);
|
||||
glDrawElements(ptype, count, itype, 0);
|
||||
}
|
||||
|
||||
void drawGrassPass2(const GLMesh &mesh, const core::matrix4 & ModelViewProjectionMatrix, core::vector3df windDir)
|
||||
{
|
||||
irr_driver->IncreaseObjectCount();
|
||||
@@ -732,8 +697,6 @@ bool isObject(video::E_MATERIAL_TYPE type)
|
||||
return true;
|
||||
if (type == irr_driver->getShader(ES_OBJECT_UNLIT))
|
||||
return true;
|
||||
if (type == irr_driver->getShader(ES_CAUSTICS))
|
||||
return true;
|
||||
if (type == video::EMT_TRANSPARENT_ALPHA_CHANNEL)
|
||||
return true;
|
||||
if (type == video::EMT_ONETEXTURE_BLEND)
|
||||
@@ -804,10 +767,6 @@ void initvaostate(GLMesh &mesh, GeometricMaterial GeoMat, ShadedMaterial ShadedM
|
||||
mesh.vao_second_pass = createVAO(mesh.vertex_buffer, mesh.index_buffer,
|
||||
MeshShader::ObjectUnlitShader::attrib_position, MeshShader::ObjectUnlitShader::attrib_texcoord, -1, -1, -1, -1, -1, mesh.Stride);
|
||||
break;
|
||||
case SM_CAUSTICS:
|
||||
mesh.vao_second_pass = createVAO(mesh.vertex_buffer, mesh.index_buffer,
|
||||
MeshShader::CausticsShader::attrib_position, MeshShader::CausticsShader::attrib_texcoord, -1, -1, -1, -1, -1, mesh.Stride);
|
||||
break;
|
||||
case SM_DETAILS:
|
||||
mesh.vao_second_pass = createVAO(mesh.vertex_buffer, mesh.index_buffer,
|
||||
MeshShader::DetailledObjectPass2Shader::attrib_position, MeshShader::DetailledObjectPass2Shader::attrib_texcoord, MeshShader::DetailledObjectPass2Shader::attrib_second_texcoord, -1, -1, -1, -1, mesh.Stride);
|
||||
|
||||
@@ -26,7 +26,6 @@ enum ShadedMaterial
|
||||
SM_SPLATTING,
|
||||
SM_GRASS,
|
||||
SM_UNLIT,
|
||||
SM_CAUSTICS,
|
||||
SM_DETAILS,
|
||||
SM_UNTEXTURED,
|
||||
SM_COUNT
|
||||
@@ -124,7 +123,6 @@ void drawUntexturedObject(const GLMesh &mesh, const core::matrix4 &ModelViewProj
|
||||
void drawObjectRefPass2(const GLMesh &mesh, const core::matrix4 &ModelViewProjectionMatrix, const core::matrix4 &TextureMatrix);
|
||||
void drawSphereMap(const GLMesh &mesh, const core::matrix4 &ModelViewProjectionMatrix, const core::matrix4 &TransposeInverseModelView);
|
||||
void drawSplatting(const GLMesh &mesh, const core::matrix4 &ModelViewProjectionMatrix);
|
||||
void drawCaustics(const GLMesh &mesh, const core::matrix4 &ModelViewProjectionMatrix, core::vector2df dir, core::vector2df dir2);
|
||||
void drawGrassPass2(const GLMesh &mesh, const core::matrix4 & ModelViewProjectionMatrix, core::vector3df windDir);
|
||||
void drawObjectRimLimit(const GLMesh &mesh, const core::matrix4 &ModelViewProjectionMatrix, const core::matrix4 &TransposeInverseModelView, const core::matrix4 &TextureMatrix);
|
||||
void drawObjectUnlit(const GLMesh &mesh, const core::matrix4 &ModelViewProjectionMatrix);
|
||||
|
||||
@@ -236,28 +236,6 @@ void STKMeshSceneNode::drawSolidPass2(const GLMesh &mesh, ShadedMaterial type)
|
||||
case SM_UNLIT:
|
||||
drawObjectUnlit(mesh, ModelViewProjectionMatrix);
|
||||
break;
|
||||
case SM_CAUSTICS:
|
||||
{
|
||||
const float time = irr_driver->getDevice()->getTimer()->getTime() / 1000.0f;
|
||||
const float speed = World::getWorld()->getTrack()->getCausticsSpeed();
|
||||
|
||||
float strength = time;
|
||||
strength = fabsf(noise2d(strength / 10.0f)) * 0.006f + 0.001f;
|
||||
|
||||
vector3df wind = irr_driver->getWind() * strength * speed;
|
||||
caustic_dir.X += wind.X;
|
||||
caustic_dir.Y += wind.Z;
|
||||
|
||||
strength = time * 0.56f + sinf(time);
|
||||
strength = fabsf(noise2d(0.0, strength / 6.0f)) * 0.0095f + 0.001f;
|
||||
|
||||
wind = irr_driver->getWind() * strength * speed;
|
||||
wind.rotateXZBy(cosf(time));
|
||||
caustic_dir2.X += wind.X;
|
||||
caustic_dir2.Y += wind.Z;
|
||||
drawCaustics(mesh, ModelViewProjectionMatrix, caustic_dir, caustic_dir2);
|
||||
break;
|
||||
}
|
||||
case SM_DETAILS:
|
||||
drawDetailledObjectPass2(mesh, ModelViewProjectionMatrix);
|
||||
break;
|
||||
@@ -335,7 +313,7 @@ void STKMeshSceneNode::render()
|
||||
GLmeshes[i].TextureMatrix = getMaterial(i).getTextureMatrix(0);
|
||||
}
|
||||
|
||||
if (irr_driver->getPhase() == SOLID_NORMAL_AND_DEPTH_PASS)
|
||||
if (irr_driver->getPhase() == SOLID_NORMAL_AND_DEPTH_PASS || irr_driver->getPhase() == SHADOW_PASS)
|
||||
{
|
||||
if (reload_each_frame)
|
||||
glDisable(GL_CULL_FACE);
|
||||
@@ -365,10 +343,13 @@ void STKMeshSceneNode::render()
|
||||
GroupedFPSM<FPSM_NORMAL_MAP>::TIMVSet.push_back(invmodel);
|
||||
}
|
||||
|
||||
if (!GeometricMesh[FPSM_GRASS].empty())
|
||||
glUseProgram(MeshShader::GrassPass1Shader::Program);
|
||||
for_in(mesh, GeometricMesh[FPSM_GRASS])
|
||||
drawSolidPass1(*mesh, FPSM_GRASS);
|
||||
if (irr_driver->getPhase() == SOLID_NORMAL_AND_DEPTH_PASS)
|
||||
{
|
||||
if (!GeometricMesh[FPSM_GRASS].empty())
|
||||
glUseProgram(MeshShader::GrassPass1Shader::Program);
|
||||
for_in(mesh, GeometricMesh[FPSM_GRASS])
|
||||
drawSolidPass1(*mesh, FPSM_GRASS);
|
||||
}
|
||||
|
||||
if (reload_each_frame)
|
||||
glEnable(GL_CULL_FACE);
|
||||
@@ -446,34 +427,6 @@ void STKMeshSceneNode::render()
|
||||
for_in(mesh, ShadedMesh[SM_GRASS])
|
||||
drawSolidPass2(*mesh, SM_GRASS);
|
||||
|
||||
if (!ShadedMesh[SM_CAUSTICS].empty())
|
||||
glUseProgram(MeshShader::CausticsShader::Program);
|
||||
for_in(mesh, ShadedMesh[SM_CAUSTICS])
|
||||
drawSolidPass2(*mesh, SM_CAUSTICS);
|
||||
|
||||
if (reload_each_frame)
|
||||
glEnable(GL_CULL_FACE);
|
||||
return;
|
||||
}
|
||||
|
||||
if (irr_driver->getPhase() == SHADOW_PASS)
|
||||
{
|
||||
if (reload_each_frame)
|
||||
glDisable(GL_CULL_FACE);
|
||||
|
||||
GLMesh* mesh;
|
||||
if (!GeometricMesh[FPSM_DEFAULT].empty() || !GeometricMesh[FPSM_NORMAL_MAP].empty())
|
||||
glUseProgram(MeshShader::ShadowShader::Program);
|
||||
for_in(mesh, GeometricMesh[FPSM_DEFAULT])
|
||||
drawShadow(*mesh, AbsoluteTransformation);
|
||||
for_in(mesh, GeometricMesh[FPSM_NORMAL_MAP])
|
||||
drawShadow(*mesh, AbsoluteTransformation);
|
||||
|
||||
if (!GeometricMesh[FPSM_ALPHA_REF_TEXTURE].empty())
|
||||
glUseProgram(MeshShader::RefShadowShader::Program);
|
||||
for_in(mesh, GeometricMesh[FPSM_ALPHA_REF_TEXTURE])
|
||||
drawShadowRef(*mesh, AbsoluteTransformation);
|
||||
|
||||
if (reload_each_frame)
|
||||
glEnable(GL_CULL_FACE);
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user