Merge remote-tracking branch 'upstream/master' into new_login

This commit is contained in:
hiker 2014-02-16 15:11:50 +11:00
commit c2b4f42c93
118 changed files with 580 additions and 552 deletions

View File

@ -1,4 +1,4 @@
#version 130
#version 330
uniform sampler2D tex;
in vec2 uv;

View File

@ -1,4 +1,4 @@
#version 130
#version 330
uniform mat4 ModelViewMatrix;
uniform mat4 ProjectionMatrix;
uniform vec3 Position;

View File

@ -1,4 +1,4 @@
#version 130
#version 330
uniform sampler2D tex;
uniform float low;

View File

@ -1,4 +1,4 @@
#version 130
#version 330
uniform sampler2D tex;
in vec2 uv;

View File

@ -1,4 +1,4 @@
#version 130
#version 330 compatibility
uniform float power;
uniform sampler2D tex;

View File

@ -14,7 +14,7 @@
// 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.
#version 130
#version 330
uniform sampler2D tex;
uniform float transparency;
in vec2 uv;

View File

@ -17,7 +17,7 @@
// Creates a bubble (wave) effect by distorting the texture depending on time
#version 130
#version 330
uniform mat4 ModelViewProjectionMatrix;
uniform float time;

View File

@ -1,4 +1,4 @@
#version 130
#version 330 compatibility
uniform sampler2D tex;
uniform sampler2D caustictex;
uniform vec2 dir;

View File

@ -1,4 +1,4 @@
#version 130
#version 330 compatibility
uniform sampler2D tex;
uniform sampler2D oldtex;
uniform vec2 pixel;

View File

@ -1,4 +1,4 @@
#version 130
#version 330
uniform sampler2D tex;
uniform vec3 inlevel;
uniform vec2 outlevel;

View File

@ -1,4 +1,4 @@
#version 130
#version 330
uniform ivec4 color;
out vec4 FragColor;

View File

@ -1,4 +1,4 @@
#version 130
#version 330
uniform vec2 center;
uniform vec2 size;

View File

@ -1,4 +1,4 @@
#version 130
#version 330
uniform vec3 col;
out vec4 FragColor;

View File

@ -1,4 +1,4 @@
#version 130
#version 330
uniform sampler2D tex;
in vec2 uv;

View File

@ -1,4 +1,4 @@
#version 130
#version 330
uniform vec2 center;
uniform vec2 size;
uniform vec2 texcenter;

View File

@ -1,4 +1,4 @@
#version 130
#version 330
uniform sampler2D Albedo;
uniform sampler2D Detail;
uniform sampler2D DiffuseMap;

View File

@ -1,4 +1,4 @@
#version 130
#version 330
uniform sampler2D tex;
uniform vec2 dir;
uniform vec2 dir2;

View File

@ -1,4 +1,4 @@
#version 130
#version 330
uniform mat4 ModelViewProjectionMatrix;
uniform mat4 ModelViewMatrix;

View File

@ -1,4 +1,4 @@
#version 130
#version 330 compatibility
uniform mat4 ModelViewProjectionMatrix;
void main() {

View File

@ -1,4 +1,4 @@
#version 130
#version 330
uniform mat4 ProjectionMatrix;
uniform mat4 ViewMatrix;

View File

@ -1,4 +1,4 @@
#version 130
#version 330
uniform sampler2D tex;
uniform float fogmax;

View File

@ -1,4 +1,4 @@
#version 130
#version 330
uniform sampler2D tex;
uniform vec2 pixel;

View File

@ -1,4 +1,4 @@
#version 130
#version 330
uniform sampler2D tex;
uniform vec2 pixel;

View File

@ -1,4 +1,4 @@
#version 130
#version 330
uniform sampler2D tex;
uniform vec2 pixel;

View File

@ -1,4 +1,4 @@
#version 130
#version 330
uniform sampler2D tex;
uniform vec2 pixel;

View File

@ -1,4 +1,4 @@
#version 130
#version 330
uniform sampler2D tex;
in vec2 uv;

View File

@ -1,4 +1,4 @@
#version 130
#version 330 compatibility
uniform sampler2D tex;
uniform vec3 col;
out vec4 FragColor;

View File

@ -1,4 +1,4 @@
#version 130
#version 330 compatibility
uniform sampler2D tex;
uniform vec2 sunpos;

View File

@ -1,4 +1,4 @@
#version 130
#version 330
uniform vec3 windDir;
uniform mat4 ModelViewProjectionMatrix;
uniform mat4 TransposeInverseModelView;

View File

@ -1,4 +1,4 @@
#version 130
#version 330
uniform vec3 windDir;
uniform mat4 ModelViewProjectionMatrix;

View File

@ -1,4 +1,4 @@
#version 130
#version 330 compatibility
uniform sampler2D tex;
uniform vec2 texsize;

View File

@ -1,4 +1,4 @@
#version 130
#version 330 compatibility
#define MAX_SEARCH_STEPS 8.0
#define MAX_DISTANCE 33.0

View File

@ -1,4 +1,4 @@
#version 130
#version 330 compatibility
in vec4 offset[2];
in vec2 uv;

View File

@ -1,4 +1,4 @@
#version 130
#version 330 compatibility
in vec4 offset[2];
in vec2 uv;
out vec4 FragColor;

View File

@ -1,4 +1,4 @@
#version 130
#version 330 compatibility
uniform vec2 PIXEL_SIZE;
uniform mat4 ModelViewProjectionMatrix;

View File

@ -21,7 +21,7 @@
// The actual boost amount (which linearly scales the blur to be shown).
// should be in the range [0.0, 1.0], though a larger value might make
// the blurring too string. Atm we are using [0, 0.5].
#version 130
#version 330 compatibility
uniform float boost_amount;
// The color buffer to use.

View File

@ -17,7 +17,7 @@
// motion_blur.vert
#version 130
#version 330 compatibility
void main()
{

View File

@ -1,4 +1,4 @@
#version 130
#version 330 compatibility
uniform sampler2D tex1;
uniform sampler2D tex2;

View File

@ -1,4 +1,4 @@
#version 130
#version 330
uniform sampler2D normalMap;
noperspective in vec3 tangent;

View File

@ -1,4 +1,4 @@
#version 130
#version 330
uniform mat4 ModelViewProjectionMatrix;
uniform mat4 TransposeInverseModelView;

View File

@ -1,4 +1,4 @@
#version 130
#version 330
noperspective in vec3 nor;
out vec2 EncodedNormal;

View File

@ -1,4 +1,4 @@
#version 130
#version 330
uniform mat4 ModelViewProjectionMatrix;
uniform mat4 TransposeInverseModelView;

View File

@ -1,4 +1,4 @@
#version 130
#version 330
uniform sampler2D Albedo;
uniform sampler2D DiffuseMap;
uniform sampler2D SpecularMap;

View File

@ -1,4 +1,4 @@
#version 130
#version 330
uniform mat4 ModelViewProjectionMatrix;
in vec3 Position;

View File

@ -1,4 +1,4 @@
#version 130
#version 330
uniform sampler2D tex;
in vec2 uv;
out vec4 FragColor;

View File

@ -1,4 +1,4 @@
#version 130
#version 330
uniform sampler2D tex;
uniform sampler2D lighttex;
uniform int hastex;

View File

@ -1,4 +1,4 @@
#version 130
#version 330
uniform mat4 ModelViewProjectionMatrix;
uniform mat4 TransposeInverseModelView;
uniform mat4 TextureMatrix0;

View File

@ -1,4 +1,4 @@
#version 130
#version 330
uniform sampler2D tex;
uniform int hastex;
uniform float objectid;

View File

@ -1,4 +1,4 @@
#version 130
#version 330
uniform sampler2D Albedo;
uniform sampler2D DiffuseMap;
uniform sampler2D SpecularMap;

View File

@ -1,4 +1,4 @@
#version 130
#version 330
uniform mat4 ModelViewProjectionMatrix;
uniform mat4 TransposeInverseModelView;

View File

@ -1,4 +1,4 @@
#version 130
#version 330
uniform sampler2D tex;
noperspective in vec3 nor;

View File

@ -1,4 +1,4 @@
#version 130
#version 330
uniform sampler2D tex;
noperspective in vec3 nor;

View File

@ -1,4 +1,4 @@
#version 130
#version 330
uniform mat4 ModelViewProjectionMatrix;
uniform mat4 TransposeInverseModelView;

View File

@ -1,4 +1,4 @@
#version 130
#version 330
uniform sampler2D Albedo;
uniform sampler2D DiffuseMap;
uniform sampler2D SpecularMap;

View File

@ -1,4 +1,4 @@
#version 130
#version 330
uniform sampler2D tex;
uniform sampler2D dtex;
uniform mat4 invproj;

View File

@ -1,4 +1,4 @@
#version 130
#version 330
uniform mat4 ProjectionMatrix;
uniform mat4 ViewMatrix;

View File

@ -1,4 +1,4 @@
#version 140
#version 330
uniform int dt;
uniform mat4 sourcematrix;
uniform int level;

View File

@ -1,4 +1,4 @@
#version 130
#version 330 compatibility
uniform sampler2D tex;
out vec4 FragColor;

View File

@ -1,5 +1,5 @@
// Passthrough shader for drawQuad()
#version 130
#version 330 compatibility
out vec2 uv;

View File

@ -1,7 +1,8 @@
#version 130
#version 330
uniform sampler2D tex;
uniform vec2 pixel;
in vec2 uv;
out vec4 FragColor;
// Separated penumbra, horizontal
@ -9,8 +10,8 @@ void main()
{
float sum = 0.0;
vec4 tmp;
float X = gl_TexCoord[0].x;
float Y = gl_TexCoord[0].y;
float X = uv.x;
float Y = uv.y;
float width = 0.0;
float zsum = 0.00001;

View File

@ -1,7 +1,8 @@
#version 130
#version 330
uniform sampler2D tex;
uniform vec2 pixel;
in vec2 uv;
out vec4 FragColor;
// Separated penumbra, vertical
@ -10,8 +11,8 @@ void main()
{
float sum = 0.0;
vec4 tmp;
float X = gl_TexCoord[0].x;
float Y = gl_TexCoord[0].y;
float X = uv.x;
float Y = uv.y;
float width = 0.0;
float zsum = 0.00001;

View File

@ -1,4 +1,4 @@
#version 130
#version 330
uniform int dt;
uniform mat4 sourcematrix;
uniform int level;

View File

@ -1,4 +1,4 @@
#version 130
#version 330
uniform sampler2D ntex;
uniform sampler2D dtex;

View File

@ -1,4 +1,4 @@
#version 130
#version 330
uniform sampler2D tex;
uniform sampler2D dtex;

View File

@ -1,4 +1,4 @@
#version 130
#version 330
uniform sampler2D tex;
uniform sampler2D normals_and_depth;
uniform mat4 invproj;

View File

@ -1,4 +1,4 @@
#version 130
#version 330
uniform float screenw;
void main()

View File

@ -1,4 +1,4 @@
#version 130
#version 330
uniform float time;
uniform vec3 campos;
uniform mat4 viewm;

View File

@ -1,4 +1,4 @@
#version 130
#version 330
in vec2 Position;
in vec2 Texcoord;

24
data/shaders/shadow.geom Normal file
View File

@ -0,0 +1,24 @@
#version 330
uniform mat4 ModelViewProjectionMatrix[4];
layout(triangles) in;
layout(triangle_strip, max_vertices=12) out;
in vec2 tc[3];
out vec2 uv;
void main(void)
{
for (int j = 0; j<4; j++)
{
gl_Layer = j;
for(int i=0; i<3; i++)
{
uv = tc[i];
gl_Position = ModelViewProjectionMatrix[j] * gl_in[i].gl_Position;
EmitVertex();
}
EndPrimitive();
}
}

14
data/shaders/shadow.vert Normal file
View File

@ -0,0 +1,14 @@
#version 330
in vec3 Position;
in vec2 Texcoord;
out vec2 tc;
void main(void)
{
tc = Texcoord;
gl_Position = vec4(Position, 1.);
}

View File

@ -1,15 +1,17 @@
#version 130
#version 330
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, gl_TexCoord[0].xy).xyz;
val[1] = texture(quarter, gl_TexCoord[0].xy).xyz;
val[2] = texture(eighth, gl_TexCoord[0].xy).xyz;
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;

View File

@ -1,4 +1,4 @@
#version 130
#version 330 compatibility
uniform sampler2D ntex;
uniform sampler2D ctex;
uniform vec3 campos;

View File

@ -1,4 +1,4 @@
#version 130
#version 330 compatibility
uniform sampler2D dtex;
uniform mat4 ipvmat;
uniform mat4 shadowmat;

View File

@ -1,4 +1,4 @@
#version 130
#version 330 compatibility
uniform sampler2D tex;
uniform int hastex;
uniform int viz;

View File

@ -1,4 +1,4 @@
#version 130
#version 330 compatibility
uniform sampler2D warpx;
uniform sampler2D warpy;

View File

@ -1,4 +1,4 @@
#version 130
#version 330 compatibility
uniform sampler2D tex;
uniform int size;
uniform vec2 pixel;

View File

@ -1,4 +1,4 @@
#version 130
#version 330 compatibility
uniform sampler2D tex;
uniform int size;
uniform vec2 pixel;

View File

@ -16,7 +16,7 @@
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
// skinning.vert
#version 130
#version 330 compatibility
#define MAX_JOINT_NUM 36
#define MAX_LIGHT_NUM 8

View File

@ -14,7 +14,7 @@
// 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.
#version 130
#version 330 compatibility
uniform sampler2D tex;
uniform sampler2D glow_tex;
uniform float transparency;

View File

@ -17,7 +17,7 @@
// Creates a bubble (wave) effect by distorting the texture depending on time
#version 130
#version 330 compatibility
uniform mat4 ModelViewProjectionMatrix;
uniform float time;

View File

@ -1,4 +1,4 @@
#version 130
#version 330
uniform sampler2D tex_layout;
uniform sampler2D tex_detail0;
uniform sampler2D tex_detail1;

View File

@ -15,7 +15,7 @@
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#version 130
#version 330
uniform mat4 ModelViewProjectionMatrix;
uniform mat4 TransposeInverseModelView;

View File

@ -1,4 +1,4 @@
#version 130
#version 330
uniform sampler2D ntex;
uniform sampler2D dtex;
uniform sampler2D noise_texture;

View File

@ -1,4 +1,4 @@
#version 130
#version 330
uniform sampler2D ntex;
uniform sampler2D dtex;
//uniform sampler2D cloudtex;

View File

@ -1,18 +1,14 @@
#version 130
#version 330
uniform sampler2D ntex;
uniform sampler2D dtex;
uniform sampler2DShadow shadowtex0;
uniform sampler2DShadow shadowtex1;
uniform sampler2DShadow shadowtex2;
uniform sampler2DArrayShadow shadowtex;
//uniform sampler2D warpx;
///uniform sampler2D warpy;
uniform vec3 direction;
uniform vec3 col;
uniform mat4 invproj;
uniform mat4 shadowmat0;
uniform mat4 shadowmat1;
uniform mat4 shadowmat2;
uniform mat4 shadowmat[4];
//uniform int hasclouds;
//uniform vec2 wind;
//uniform float shadowoffset;
@ -28,13 +24,18 @@ vec3 DecodeNormal(vec2 n)
return vec3(xy,z);
}
float getShadowFactor(vec3 pos, float bias)
float getShadowFactor(vec3 pos, float bias, int index)
{
if (pos.z < 10.)
{
vec4 shadowcoord = (shadowmat0 * vec4(pos, 1.0));
shadowcoord /= shadowcoord.w;
vec2 shadowtexcoord = shadowcoord.xy * 0.5 + 0.5;
const vec2 shadowoffset[] = {
vec2(-1., -1.),
vec2(-1., 1.),
vec2(1., -1.),
vec2(1., 1.)
};
vec4 shadowcoord = (shadowmat[index] * vec4(pos, 1.0));
shadowcoord /= shadowcoord.w;
vec2 shadowtexcoord = shadowcoord.xy * 0.5 + 0.5;
// shadowcoord = (shadowcoord * 0.5) + vec3(0.5);
// float movex = decdepth(texture(warpx, shadowcoord.xy));
@ -43,24 +44,14 @@ float getShadowFactor(vec3 pos, float bias)
// float dy = movey * 2.0 - 1.0;
// shadowcoord.xy += vec2(dx, dy);*/
//float shadowmapz = 2. * texture(shadowtex, vec3(shadowtexcoord, shadowcoord.z).x - 1.;
// bias += smoothstep(0.001, 0.1, moved) * 0.014; // According to the warping
return texture(shadowtex0, vec3(shadowtexcoord, 0.5 * (shadowcoord.z + bias * 0.001) + 0.5));
}
else if (pos.z < 60)
//float shadowmapz = 2. * texture(shadowtex, vec3(shadowtexcoord, shadowcoord.z).x - 1.;
// bias += smoothstep(0.001, 0.1, moved) * 0.014; // According to the warping
float sum = 0.;
for (int i = 0; i < 4; i++)
{
vec4 shadowcoord = (shadowmat1 * vec4(pos, 1.0));
shadowcoord /= shadowcoord.w;
vec2 shadowtexcoord = shadowcoord.xy * 0.5 + 0.5;
return texture(shadowtex1, vec3(shadowtexcoord, 0.5 * (shadowcoord.z + bias * 0.001) + 0.5));
}
else
{
vec4 shadowcoord = (shadowmat2 * vec4(pos, 1.0));
shadowcoord /= shadowcoord.w;
vec2 shadowtexcoord = shadowcoord.xy * 0.5 + 0.5;
return texture(shadowtex2, vec3(shadowtexcoord, 0.5 * (shadowcoord.z + bias) + 0.5));
sum += texture(shadowtex, vec4(shadowtexcoord + 0.0005 * shadowoffset[i], float(index), 0.5 * (shadowcoord.z + bias * 0.001) + 0.5));
}
return sum / 4.;
}
void main() {
@ -93,7 +84,30 @@ void main() {
// Shadows
float bias = 0.002 * tan(acos(NdotL)); // According to the slope
bias = clamp(bias, 0.001, 0.014);
float factor = getShadowFactor(xpos.xyz, bias);
float factor;
if (xpos.z < 20.)
factor = getShadowFactor(xpos.xyz, bias, 0);
else if (xpos.z < 25.)
{
float a = getShadowFactor(xpos.xyz, bias, 0), b = getShadowFactor(xpos.xyz, bias, 1);
factor = mix(a, b, (xpos.z - 20.) / 5.);
}
else if (xpos.z < 50.)
factor = getShadowFactor(xpos.xyz, bias, 1);
else if (xpos.z < 60.)
{
float a = getShadowFactor(xpos.xyz, bias, 1), b = getShadowFactor(xpos.xyz, bias, 2);
factor = mix(a, b, (xpos.z - 50.) / 10.);
}
else if (xpos.z < 100.)
factor = getShadowFactor(xpos.xyz, bias, 2);
else if (xpos.z < 120.)
{
float a = getShadowFactor(xpos.xyz, bias, 2), b = getShadowFactor(xpos.xyz, bias, 3);
factor = mix(a, b, (xpos.z - 100.) / 20.);
}
else
factor = getShadowFactor(xpos.xyz, bias, 3);
Diff = vec4(factor * NdotL * col, 1.);
Spec = vec4(factor * Specular * col, 1.);
return;

View File

@ -1,4 +1,4 @@
#version 130
#version 330
uniform sampler2D tex;
in vec2 uv;

View File

@ -1,4 +1,4 @@
#version 130
#version 330
uniform vec2 center;
uniform vec2 size;
uniform vec2 texcenter;

View File

@ -1,4 +1,4 @@
#version 130
#version 330
uniform sampler2D tex;
in vec2 uv;

View File

@ -1,4 +1,4 @@
#version 130
#version 330
uniform mat4 ModelViewProjectionMatrix;
in vec3 Position;

View File

@ -1,4 +1,4 @@
#version 130
#version 330
uniform sampler2D tex;
uniform float fogmax;

View File

@ -1,4 +1,4 @@
#version 130
#version 330
uniform sampler2D DiffuseMap;
uniform sampler2D SpecularMap;
uniform sampler2D SSAO;

View File

@ -1,4 +1,4 @@
#version 130
#version 330
uniform mat4 ModelViewProjectionMatrix;
in vec3 Position;

View File

@ -1,6 +1,6 @@
// Shader based on work by Fabien Sanglard
// Released under the terms of CC-BY 3.0
#version 130
#version 330 compatibility
uniform sampler2D BumpTex1; // Normal map 1
uniform sampler2D BumpTex2; // Normal map 2
uniform sampler2D DecalTex; //The texture

View File

@ -1,6 +1,6 @@
// Shader based on work by Fabien Sanglard
// Released under the terms of CC-BY 3.0
#version 130
#version 330 compatibility
uniform float speed;
uniform float height;
uniform float waveLength;

View File

@ -1,4 +1,4 @@
#version 130
#version 330
out vec4 FragColor;
void main()
{

View File

@ -744,9 +744,8 @@ bool CIrrDeviceLinux::createWindow()
int context_attribs[] =
{
GLX_CONTEXT_MAJOR_VERSION_ARB, 3,
GLX_CONTEXT_MINOR_VERSION_ARB, 0,
// Uncomment to discard deprecated features
//GLX_CONTEXT_FLAGS_ARB , GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB,
GLX_CONTEXT_MINOR_VERSION_ARB, 3,
GLX_CONTEXT_PROFILE_MASK_ARB, GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB, //GLX_CONTEXT_CORE_PROFILE_BIT_ARB
GLX_CONTEXT_FLAGS_ARB, GLX_CONTEXT_DEBUG_BIT_ARB,
None
};

View File

@ -412,9 +412,9 @@ bool COpenGLDriver::initDriver(CIrrDeviceWin32* device)
int iAttribs[] =
{
WGL_CONTEXT_MAJOR_VERSION_ARB, 3,
WGL_CONTEXT_MINOR_VERSION_ARB, 1,
//WGL_CONTEXT_FLAGS_ARB, WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB,
WGL_CONTEXT_MINOR_VERSION_ARB, 3,
WGL_CONTEXT_FLAGS_ARB, WGL_CONTEXT_DEBUG_BIT_ARB,
WGL_CONTEXT_PROFILE_MASK_ARB, WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB, //WGL_CONTEXT_CORE_PROFILE_BIT_ARB
0
};
hrc=wglCreateContextAttribs_ARB(HDc, 0, iAttribs);

View File

@ -255,6 +255,35 @@ GLuint LoadProgram(const char * vertex_file_path, const char * fragment_file_pat
return ProgramID;
}
GLuint LoadProgram(const char * vertex_file_path, const char * geometry_file_path, const char * fragment_file_path) {
GLuint VertexShaderID = LoadShader(vertex_file_path, GL_VERTEX_SHADER);
GLuint FragmentShaderID = LoadShader(fragment_file_path, GL_FRAGMENT_SHADER);
GLuint GeometryShaderID = LoadShader(geometry_file_path, GL_GEOMETRY_SHADER);
GLuint ProgramID = glCreateProgram();
glAttachShader(ProgramID, VertexShaderID);
glAttachShader(ProgramID, GeometryShaderID);
glAttachShader(ProgramID, FragmentShaderID);
glLinkProgram(ProgramID);
GLint Result = GL_FALSE;
int InfoLogLength;
glGetProgramiv(ProgramID, GL_LINK_STATUS, &Result);
if (Result == GL_FALSE) {
glGetProgramiv(ProgramID, GL_INFO_LOG_LENGTH, &InfoLogLength);
char *ErrorMessage = new char[InfoLogLength];
glGetProgramInfoLog(ProgramID, InfoLogLength, NULL, ErrorMessage);
printf(ErrorMessage);
delete[] ErrorMessage;
}
glDeleteShader(VertexShaderID);
glDeleteShader(GeometryShaderID);
glDeleteShader(FragmentShaderID);
return ProgramID;
}
GLuint LoadTFBProgram(const char * vertex_file_path, const char **varyings, unsigned varyingscount) {
GLuint Shader = LoadShader(vertex_file_path, GL_VERTEX_SHADER);
GLuint Program = glCreateProgram();
@ -276,12 +305,13 @@ GLuint LoadTFBProgram(const char * vertex_file_path, const char **varyings, unsi
return Program;
}
GLuint getTextureGLuint(irr::video::ITexture *tex) {
return static_cast<irr::video::COpenGLTexture*>(tex)->getOpenGLTextureName();
}
void bindUniformToTextureUnit(GLuint location, GLuint texid, unsigned textureUnit) {
glActiveTexture(GL_TEXTURE0 + textureUnit);
glBindTexture(GL_TEXTURE_2D, texid);
glUniform1i(location, textureUnit);
GLuint getDepthTexture(irr::video::ITexture *tex) {
assert(tex->isRenderTarget());
return static_cast<irr::video::COpenGLFBOTexture*>(tex)->DepthBufferTexture;
}
void setTexture(unsigned TextureUnit, GLuint TextureId, GLenum MagFilter, GLenum MinFilter, bool allowAF)

View File

@ -20,8 +20,8 @@
void initGL();
GLuint LoadProgram(const char * vertex_file_path, const char * fragment_file_path);
GLuint LoadProgram(const char * vertex_file_path, const char * geometry_file_path, const char * fragment_file_path);
GLuint LoadTFBProgram(const char * vertex_file_path, const char **varyings, unsigned varyingscount);
void bindUniformToTextureUnit(GLuint location, GLuint texid, unsigned textureUnit);
void setTexture(unsigned TextureUnit, GLuint TextureId, GLenum MagFilter, GLenum MinFilter, bool allowAF = false);
// already includes glext.h, which defines useful GL constants.
@ -90,6 +90,9 @@ extern PFNGLDEBUGMESSAGECALLBACKARBPROC glDebugMessageCallbackARB;
#include <rect.h>
#include "utils/vec3.hpp"
GLuint getTextureGLuint(irr::video::ITexture *tex);
GLuint getDepthTexture(irr::video::ITexture *tex);
void draw2DImage(const irr::video::ITexture* texture, const irr::core::rect<s32>& destRect,
const irr::core::rect<s32>& sourceRect, const irr::core::rect<s32>* clipRect,
const irr::video::SColor* const colors, bool useAlphaChannelOfTexture);

View File

@ -6,41 +6,8 @@
#include <IParticleSystemSceneNode.h>
#include "guiengine/engine.hpp"
GLuint getTextureGLuint(irr::video::ITexture *tex) {
return static_cast<irr::video::COpenGLTexture*>(tex)->getOpenGLTextureName();
}
#define COMPONENTCOUNT 8
GPUParticle::GPUParticle(scene::ISceneNode *parent, scene::ISceneManager* mgr, ITexture *tex)
: scene::ISceneNode(parent, mgr, -1) {
fakemat.Lighting = false;
fakemat.ZWriteEnable = false;
fakemat.MaterialType = irr_driver->getShader(ES_RAIN);
fakemat.Thickness = 200;
fakemat.setTexture(0, tex);
fakemat.BlendOperation = video::EBO_NONE;
setAutomaticCulling(0);
}
void GPUParticle::render() {
simulate();
draw();
// We need to force irrlicht to update its internal states
irr::video::IVideoDriver * const drv = irr_driver->getVideoDriver();
drv->setMaterial(fakemat);
static_cast<irr::video::COpenGLDriver*>(drv)->setRenderStates3DMode();
}
void GPUParticle::OnRegisterSceneNode() {
if (
(irr_driver->getRenderPass() & irr::scene::ESNRP_TRANSPARENT) == irr::scene::ESNRP_TRANSPARENT)
{
SceneManager->registerNodeForRendering(this, irr::scene::ESNRP_TRANSPARENT);
}
ISceneNode::OnRegisterSceneNode();
}
scene::IParticleSystemSceneNode *ParticleSystemProxy::addParticleNode(
bool withDefaultEmitter, ISceneNode* parent, s32 id,
const core::vector3df& position,
@ -65,13 +32,6 @@ ParticleSystemProxy::ParticleSystemProxy(bool createDefaultEmitter,
const core::vector3df& position,
const core::vector3df& rotation,
const core::vector3df& scale) : CParticleSystemSceneNode(createDefaultEmitter, parent, mgr, id, position, rotation, scale), m_alpha_additive(false) {
fakemat.Lighting = false;
fakemat.ZWriteEnable = false;
fakemat.MaterialType = irr_driver->getShader(ES_RAIN);
fakemat.setTexture(0, getMaterial(0).getTexture(0));
fakemat.BlendOperation = video::EBO_NONE;
fakemat.FrontfaceCulling = false;
fakemat.BackfaceCulling = false;
glGenBuffers(1, &initial_values_buffer);
glGenBuffers(2, tfb_buffers);
glGenBuffers(1, &quaternionsbuffer);
@ -607,103 +567,4 @@ void ParticleSystemProxy::OnRegisterSceneNode()
SceneManager->registerNodeForRendering(this, scene::ESNRP_TRANSPARENT_EFFECT);
ISceneNode::OnRegisterSceneNode();
}
}
RainNode::RainNode(scene::ISceneManager* mgr, ITexture *tex)
: GPUParticle(0, mgr, tex)
{
RenderProgram = LoadProgram(file_manager->getAsset("shaders/rain.vert").c_str(), file_manager->getAsset("shaders/rain.frag").c_str());
loc_screenw = glGetUniformLocation(RenderProgram, "screenw");
loc_screen = glGetUniformLocation(RenderProgram, "screen");
loc_invproj = glGetUniformLocation(RenderProgram, "invproj");
texloc_tex = glGetUniformLocation(RenderProgram, "tex");
texloc_normal_and_depths = glGetUniformLocation(RenderProgram, "normals_and_depth");
const char *varyings[] = { "currentPosition" };
SimulationProgram = LoadTFBProgram(file_manager->getAsset("shaders/rainsim.vert").c_str(), varyings, 1);
loc_campos = glGetUniformLocation(SimulationProgram, "campos");
loc_viewm = glGetUniformLocation(SimulationProgram, "viewm");
loc_time = glGetUniformLocation(SimulationProgram, "time");
count = 2500;
area = 3500;
u32 i;
float x, y, z, vertices[7500];
for (i = 0; i < count; i++)
{
x = ((rand() % area) - area / 2) / 100.0f;
y = ((rand() % 2400)) / 100.0f;
z = ((rand() % area) - area / 2) / 100.0f;
vertices[3 * i] = x;
vertices[3 * i + 1] = y;
vertices[3 * i + 2] = z;
}
texture = getTextureGLuint(tex);
normal_and_depth = getTextureGLuint(irr_driver->getRTT(RTT_NORMAL_AND_DEPTH));
glGenBuffers(2, tfb_vertex_buffer);
glBindBuffer(GL_ARRAY_BUFFER, tfb_vertex_buffer[0]);
glBufferData(GL_ARRAY_BUFFER, 3 * count * sizeof(float), vertices, GL_STREAM_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, tfb_vertex_buffer[1]);
glBufferData(GL_ARRAY_BUFFER, 3 * count * sizeof(float), 0, GL_STREAM_DRAW);
box.addInternalPoint(vector3df((float)(-area / 2)));
box.addInternalPoint(vector3df((float)(area / 2)));
}
void RainNode::simulate() {
glUseProgram(SimulationProgram);
const float time = irr_driver->getDevice()->getTimer()->getTime() / 90.0f;
const irr::core::matrix4 viewm = irr_driver->getVideoDriver()->getTransform(irr::video::ETS_VIEW);
const irr::core::vector3df campos = irr_driver->getSceneManager()->getActiveCamera()->getPosition();
glEnable(GL_RASTERIZER_DISCARD);
glEnableVertexAttribArray(0);
glBindBuffer(GL_ARRAY_BUFFER, tfb_vertex_buffer[0]);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0);
glBindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER, 0, tfb_vertex_buffer[1]);
glUniformMatrix4fv(loc_viewm, 1, GL_FALSE, viewm.pointer());
glUniform1f(loc_time, time);
glUniform3f(loc_campos, campos.X, campos.Y, campos.Z);
glBeginTransformFeedback(GL_POINTS);
glDrawArrays(GL_POINTS, 0, count);
glEndTransformFeedback();
glDisable(GL_RASTERIZER_DISCARD);
}
void RainNode::draw() {
const float screenw = (float)UserConfigParams::m_width;
glEnable(GL_VERTEX_PROGRAM_POINT_SIZE);
glEnable(GL_POINT_SPRITE);
glUseProgram(RenderProgram);
glEnableVertexAttribArray(0);
glBindBuffer(GL_ARRAY_BUFFER, tfb_vertex_buffer[1]);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0);
float screen[2] = {
(float)UserConfigParams::m_width,
(float)UserConfigParams::m_height
};
irr::core::matrix4 invproj = irr_driver->getVideoDriver()->getTransform(irr::video::ETS_PROJECTION);
invproj.makeInverse();
bindUniformToTextureUnit(texloc_tex, texture, 0);
bindUniformToTextureUnit(texloc_normal_and_depths, normal_and_depth, 1);
glUniformMatrix4fv(loc_invproj, 1, GL_FALSE, invproj.pointer());
glUniform2f(loc_screen, screen[0], screen[1]);
glUniform1f(loc_screenw, screenw);
glDrawArrays(GL_POINTS, 0, count);
glDisableVertexAttribArray(0);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glActiveTexture(GL_TEXTURE0);
glDisable(GL_VERTEX_PROGRAM_POINT_SIZE);
}
const core::aabbox3d<f32>& RainNode::getBoundingBox() const
{
return box;
}
}

Some files were not shown because too many files have changed in this diff Show More