Merged from master

This commit is contained in:
nixt 2014-02-07 23:40:09 +05:30
commit d1d83459d0
153 changed files with 3141 additions and 1891 deletions

8
.gitignore vendored
View File

@ -1,9 +1,11 @@
bld/
build/
build-32/
build-64/
build-win/
cmake_build/
dependencies/
CMakeFiles/
.config/
supertuxkart-64
@ -14,20 +16,26 @@ data/music
data/sfx
data/textures
data/tracks
data/.svn
*.o
*.d
*.a
*.patch
*.diff
*.obj
*.orig
*.rej
*.log
*.lib
*.tlog
*.pdb
*.dll
*.exe
*.vcxproj
*.vcxproj.filters
*.vcxproj.user
packets_log.txt
history.dat
README.dependencies

34
.travis.yml Normal file
View File

@ -0,0 +1,34 @@
# Travis-CI configuration file for SuperTuxKart
#
# Configuration manual:
# http://docs.travis-ci.com/user/build-configuration/
#
language: cpp
compiler:
- gcc
#- clang
git:
submodules: false
#branches:
# only:
# - master
before_install:
# UPDATE REPOS
- sudo apt-get update -qq
# INSTALL DEPENDENCIES
- sudo apt-get install autoconf automake build-essential cmake libogg-dev libvorbis-dev libopenal-dev libxxf86vm-dev libgl1-mesa-dev libglu1-mesa-dev libcurl4-openssl-dev libfribidi-dev libbluetooth-dev
script:
# BUILD COMMANDS
- ./tools/build-linux-travis.sh
notifications:
irc:
channels:
- "irc.freenode.org#stk"
skip_join: false
use_notice: true
template:
#- "[%{commit}: %{author}] %{message}"
#- "%{build_url}"
- "[%{repository}#%{branch} @%{commit}] %{author}): %{message}"
- "Diff: %{compare_url}"
- "Build: %{build_url}"

View File

@ -1,4 +1,6 @@
#SuperTuxKart
[![Build Status](https://travis-ci.org/supertuxkart/stk-code.png?branch=master)](https://travis-ci.org/supertuxkart/stk-code)
SuperTuxKart is a free kart racing game. It is focusing on fun and
not on realistic kart physics. Instruction can be found on the
in-game help page.

View File

@ -10,10 +10,10 @@
<box id="filter_box" width="97%" height="75" layout="vertical-row" align="center">
<div x="0" y="0" width="98%" height="100%" layout="horizontal-row" align="center">
<textbox id="filter_name" proportion="9" align="center" />
<textbox id="filter_name" proportion="7" align="center" />
<spacer width="10" />
<label text="Updated" align="center" I18N="In addons screen, in the filtering bar, to enable a filter that will show only recently updated items"/>
<spinner id="filter_date" proportion="5" align="center" min_value="0" wrap_around="true"/>
<spinner id="filter_date" proportion="8" align="center" min_value="0" wrap_around="true"/>
<label text="Rating >=" align="center" I18N="In addons screen, in the filtering bar, to enable a filter that will show only recently items with good rating"/>
<spinner id="filter_rating" proportion="3" align="center" min_value="0" wrap_around="true"/>
<icon-button id="filter_search" height="100%" icon="gui/search.png"/>

View File

@ -49,7 +49,7 @@
<icon-button id="cancel" width="64" height="64" icon="gui/main_quit.png"
I18N="Login dialog" text="Close" label_location="bottom"/>
</buttonbar>
<spacer height="20" width="20"/>
</box>
</div>

View File

@ -0,0 +1,10 @@
#version 130
uniform sampler2D tex;
in vec2 uv;
out vec4 FragColor;
void main(void)
{
FragColor = texture(tex, uv);
}

View File

@ -0,0 +1,16 @@
#version 130
uniform mat4 ModelViewMatrix;
uniform mat4 ProjectionMatrix;
uniform vec3 Position;
uniform vec2 Size;
in vec2 Corner;
in vec2 Texcoord;
out vec2 uv;
void main(void)
{
uv = Texcoord;
vec4 Center = ModelViewMatrix * vec4(Position, 1.);
gl_Position = ProjectionMatrix * (Center + vec4(Size * Corner, 0., 0.));
}

View File

@ -11,7 +11,7 @@ void main()
vec3 col = texture(tex, uv).xyz;
float luma = dot(weights, col);
col *= smoothstep(low, 0.9, luma);
col *= smoothstep(1., 2., luma);
FragColor = vec4(col, 1.0);
}

View File

@ -4,7 +4,6 @@ uniform vec2 size;
in vec2 position;
void main()
{
gl_Position = vec4(position * size + center, 0., 1.);

View File

@ -0,0 +1,24 @@
#version 130
uniform sampler2D Albedo;
uniform sampler2D Detail;
uniform sampler2D DiffuseMap;
uniform sampler2D SpecularMap;
uniform sampler2D SSAO;
uniform vec2 screen;
uniform vec3 ambient;
in vec2 uv;
in vec2 uv_bis;
out vec4 FragColor;
void main(void)
{
vec2 tc = gl_FragCoord.xy / screen;
vec4 color = texture(Albedo, uv);
vec4 detail = texture(Detail, uv_bis);
color *= detail;
vec3 DiffuseComponent = texture(DiffuseMap, tc).xyz;
vec3 SpecularComponent = texture(SpecularMap, tc).xyz;
float ao = texture(SSAO, tc).x;
vec3 LightFactor = ao * ambient + DiffuseComponent + SpecularComponent * (1. - color.a);
FragColor = vec4(color.xyz * LightFactor * ao, 1.);
}

View File

@ -7,7 +7,6 @@ uniform float endH;
uniform float start;
uniform float end;
uniform vec3 col;
uniform vec3 campos;
uniform mat4 ipvmat;
in vec2 uv;
@ -15,18 +14,17 @@ out vec4 FragColor;
void main()
{
float z = texture(tex, uv).a;
float z = texture(tex, uv).x;
vec3 tmp = vec3(gl_TexCoord[0].xy, z);
vec3 tmp = vec3(uv, z);
tmp = tmp * 2.0 - 1.0;
vec4 xpos = vec4(tmp, 1.0);
xpos = ipvmat * xpos;
xpos.xyz /= xpos.w;
float dist = distance(campos, xpos.xyz);
float dist = length(xpos.xyz);
float fog = smoothstep(start, end, dist);
fog *= 1.0 - smoothstep(startH, endH, xpos.y);
fog = min(fog, fogmax);

View File

@ -1,21 +0,0 @@
#version 130
uniform sampler2D diffuse;
uniform sampler2D specular;
uniform sampler2D ambient_occlusion;
uniform sampler2D specular_map;
uniform vec3 ambient;
in vec2 uv;
out vec4 FragColor;
void main()
{
vec2 texc = uv;
vec3 diffuse = texture(diffuse, texc).xyz;
vec3 spec = texture(specular, texc).xyz;
float specmap = texture(specular_map, texc).x;
float ao = texture(ambient_occlusion, texc).x;
FragColor = vec4(diffuse + spec * specmap + ao * ambient, 1.0);
}

View File

@ -4,7 +4,13 @@ uniform sampler2D normalMap;
noperspective in vec3 tangent;
noperspective in vec3 bitangent;
in vec2 uv;
out vec4 FragColor;
out vec2 EncodedNormal;
// from Crytek "a bit more deferred CryEngine"
vec2 EncodeNormal(vec3 n)
{
return normalize(n.xy) * sqrt(n.z * 0.5 + 0.5);
}
void main()
{
@ -15,8 +21,6 @@ void main()
vec3 Frag_normal = normalize(cross(Frag_tangent, bitangent));
vec3 Frag_bitangent = cross(Frag_normal, Frag_tangent);
vec3 FragmentNormal = TS_normal.x * Frag_tangent + TS_normal.y * Frag_bitangent - TS_normal.z * Frag_normal;
FragmentNormal = normalize(FragmentNormal);
FragColor = vec4(0.5 * FragmentNormal + 0.5, gl_FragCoord.z);
vec3 FragmentNormal = TS_normal.x * Frag_tangent + TS_normal.y * Frag_bitangent - TS_normal.z * Frag_normal;
EncodedNormal = 0.5 * EncodeNormal(normalize(FragmentNormal)) + 0.5;
}

View File

@ -1,8 +1,14 @@
#version 130
noperspective in vec3 nor;
out vec4 FragColor;
out vec2 EncodedNormal;
// from Crytek "a bit more deferred CryEngine"
vec2 EncodeNormal(vec3 n)
{
return normalize(n.xy) * sqrt(n.z * 0.5 + 0.5);
}
void main(void)
{
FragColor = vec4(0.5 * normalize(nor) + 0.5, gl_FragCoord.z);
EncodedNormal = 0.5 * EncodeNormal(normalize(nor)) + 0.5;
}

View File

@ -5,6 +5,7 @@ uniform sampler2D SpecularMap;
uniform sampler2D SSAO;
uniform vec2 screen;
uniform vec3 ambient;
in vec2 uv;
out vec4 FragColor;
@ -16,6 +17,6 @@ void main(void)
vec3 SpecularComponent = texture(SpecularMap, tc).xyz;
float ao = texture(SSAO, tc).x;
vec3 LightFactor = ao * ambient + DiffuseComponent + SpecularComponent * (1. - color.a);
FragColor = vec4(color.xyz * LightFactor * ao, 1.);
FragColor = vec4(color.xyz * LightFactor * (0.4 + ao*0.6), 1.);
//FragColor = vec4(color.xyz * LightFactor, 1.);
}

View File

@ -3,10 +3,13 @@ uniform mat4 ModelViewProjectionMatrix;
in vec3 Position;
in vec2 Texcoord;
in vec2 SecondTexcoord;
out vec2 uv;
out vec2 uv_bis;
void main(void)
{
uv = Texcoord;
uv_bis = SecondTexcoord;
gl_Position = ModelViewProjectionMatrix * vec4(Position, 1.);
}

View File

@ -0,0 +1,11 @@
#version 130
uniform sampler2D tex;
in vec2 uv;
out vec4 FragColor;
void main(void)
{
vec4 color = texture(tex, uv);
if (color.a < 0.5) discard;
FragColor = vec4(color.xyz, 1.);
}

View File

@ -1,35 +1,26 @@
#version 130
uniform sampler2D tex;
uniform int hastex;
uniform float objectid;
uniform sampler2D Albedo;
uniform sampler2D DiffuseMap;
uniform sampler2D SpecularMap;
uniform sampler2D SSAO;
uniform vec2 screen;
uniform vec3 ambient;
noperspective in vec3 nor;
noperspective in vec3 eyenor;
noperspective in vec3 viewpos;
out vec4 Albedo;
out vec4 NormalDepth;
out vec4 Specular;
noperspective in vec3 normal;
in vec2 uv;
out vec4 FragColor;
void main() {
float rim = 1.0 - dot(eyenor, viewpos);
float rim = 1.0 - dot(normal, vec3(0., 0., -1));
rim = smoothstep(0.5, 1.5, rim) * 0.35;
vec4 color;
if (hastex != 0) {
vec4 col = texture(tex, gl_TexCoord[0].xy);
if (col.a < 0.1)
discard;
col.xyz += rim;
color = col;
} else {
color = gl_Color + vec4(vec3(rim), 0.0);
}
Albedo = vec4(color.xyz, 1.);
NormalDepth = vec4(0.5 * normalize(nor) + 0.5, gl_FragCoord.z);
Specular = vec4(1. - color.a);
vec4 color = texture(Albedo, uv);
vec2 tc = gl_FragCoord.xy / screen;
vec3 DiffuseComponent = texture(DiffuseMap, tc).xyz;
vec3 SpecularComponent = texture(SpecularMap, tc).xyz;
float ao = texture(SSAO, tc).x;
vec3 LightFactor = ao * ambient + DiffuseComponent + SpecularComponent * (1. - color.a);
FragColor = vec4(color.xyz * LightFactor + rim, 1.);
}

View File

@ -1,15 +1,16 @@
#version 130
uniform mat4 ModelViewProjectionMatrix;
uniform mat4 TransposeInverseModelView;
noperspective out vec3 nor;
noperspective out vec3 eyenor;
noperspective out vec3 viewpos;
in vec3 Position;
in vec3 Normal;
in vec2 Texcoord;
in vec4 Color;
out vec2 uv;
noperspective out vec3 normal;
void main() {
nor = gl_NormalMatrix * gl_Normal;
eyenor = gl_NormalMatrix * gl_Normal;
viewpos = -normalize((gl_ModelViewMatrix * gl_Vertex).xyz);
gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0;
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
gl_FrontColor = gl_Color;
normal = (TransposeInverseModelView * vec4(Normal, 0)).xyz;
uv = Texcoord;
gl_Position = ModelViewProjectionMatrix * vec4(Position, 1.);
}

View File

@ -3,12 +3,18 @@ uniform sampler2D tex;
noperspective in vec3 nor;
in vec2 uv;
out vec4 NormalDepth;
out vec2 EncodedNormal;
// from Crytek "a bit more deferred CryEngine"
vec2 EncodeNormal(vec3 n)
{
return normalize(n.xy) * sqrt(n.z * 0.5 + 0.5);
}
void main() {
vec4 col = texture(tex, uv);
if (col.a < 0.5)
discard;
NormalDepth = vec4(0.5 * normalize(nor) + 0.5, gl_FragCoord.z);
EncodedNormal = 0.5 * EncodeNormal(normalize(nor)) + 0.5;
}

View File

@ -1,6 +1,6 @@
#version 130
uniform sampler2D tex;
uniform sampler2D normals_and_depth;
uniform sampler2D dtex;
uniform mat4 invproj;
uniform vec2 screen;
@ -13,13 +13,12 @@ void main(void)
{
vec2 xy = gl_FragCoord.xy / screen;
float FragZ = gl_FragCoord.z;
float EnvZ = texture(normals_and_depth, xy).a;
float EnvZ = texture(dtex, xy).x;
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.);
float alpha = clamp((EnvPos.z - FragmentPos.z) * 0.3, 0., 1.);
color = texture(tex, tc);
color.a *= alpha * smoothstep(1., 0.8, lf);
}

View File

@ -1,5 +1,6 @@
#version 130
uniform sampler2D ntex;
uniform sampler2D dtex;
uniform vec4 center[16];
uniform vec4 col[16];
@ -12,13 +13,22 @@ in vec2 uv;
out vec4 Diffuse;
out vec4 Specular;
vec3 DecodeNormal(vec2 n)
{
float z = dot(n, n) * 2. - 1.;
vec2 xy = normalize(n) * sqrt(1. - z * z);
return vec3(xy,z);
}
void main() {
vec2 texc = uv;
float z = texture(ntex, texc).a;
float z = texture(dtex, texc).x;
vec3 norm = normalize(DecodeNormal(2. * texture(ntex, texc).xy - 1.));
vec4 xpos = 2.0 * vec4(texc, z, 1.0) - 1.0f;
xpos = invproj * xpos;
xpos /= xpos.w;
vec3 eyedir = normalize(xpos.xyz);
vec3 diffuse = vec3(0.), specular = vec3(0.);
@ -31,9 +41,6 @@ void main() {
float att = energy[i] * 200. / (4. * 3.14 * d * d);
float spec_att = (energy[i] + 10.) * 200. / (4. * 3.14 * d * d);
vec3 norm = texture(ntex, texc).xyz;
norm = (norm - 0.5) * 2.0;
// Light Direction
vec3 L = normalize(xpos.xyz - light_pos);
@ -41,7 +48,7 @@ void main() {
diffuse += NdotL * light_col * att;
// Reflected light dir
vec3 R = reflect(-L, norm);
float RdotE = max(0.0, dot(R, normalize(xpos.xyz)));
float RdotE = max(0.0, dot(R, eyedir));
float Specular = pow(RdotE, spec);
specular += Specular * light_col * spec_att;
}

View File

@ -1,34 +1,42 @@
#version 130
uniform sampler2D normals_and_depth;
uniform sampler2D ntex;
uniform sampler2D dtex;
uniform sampler2D noise_texture;
uniform mat4 invprojm;
uniform mat4 projm;
uniform vec4 samplePoints[16];
in vec2 uv;
out vec4 FragColor;
out float ao;
const float strengh = 4.;
const float radius = .4f;
#define SAMPLES 8
#define SAMPLES 16
const float invSamples = strengh / SAMPLES;
vec3 rand(vec2 co)
{
return texture(noise_texture, co).xyz;
return texture(noise_texture, co*20.16).xyz;
}
vec3 DecodeNormal(vec2 n)
{
float z = dot(n, n) * 2. - 1.;
vec2 xy = normalize(n) * sqrt(1. - z * z);
return vec3(xy,z);
}
void main(void)
{
vec4 cur = texture(normals_and_depth, uv);
float curdepth = texture(normals_and_depth, uv).a;
vec4 cur = texture(ntex, uv);
float curdepth = texture(dtex, uv).x;
vec4 FragPos = invprojm * (2.0f * vec4(uv, curdepth, 1.0f) - 1.0f);
FragPos /= FragPos.w;
// get the normal of current fragment
vec3 norm = normalize(cur.xyz * vec3(2.0) - vec3(1.0));
vec3 norm = normalize(DecodeNormal(2. * texture(ntex, uv).xy - 1.));
// Workaround for nvidia and skyboxes
float len = dot(vec3(1.0), abs(cur.xyz));
if (len < 0.2 || curdepth > 0.999) discard;
@ -48,7 +56,7 @@ void main(void)
bool isInsideTexture = (sampleProj.x > -1.) && (sampleProj.x < 1.) && (sampleProj.y > -1.) && (sampleProj.y < 1.);
// get the depth of the occluder fragment
float occluderFragmentDepth = texture(normals_and_depth, (sampleProj.xy * 0.5) + 0.5).a;
float occluderFragmentDepth = texture(dtex, (sampleProj.xy * 0.5) + 0.5).x;
// Position of the occluder fragment in worldSpace
vec4 occluderPos = invprojm * vec4(sampleProj.xy, 2.0 * occluderFragmentDepth - 1.0, 1.0f);
occluderPos /= occluderPos.w;
@ -57,8 +65,5 @@ void main(void)
bl += isOccluded ? smoothstep(radius, 0, distance(samplePos, FragPos)) : 0.;
}
// output the result
float ao = 1.0 - bl * invSamples;
FragColor = vec4(ao);
ao = 1.0 - bl * invSamples;
}

View File

@ -1,5 +1,6 @@
#version 130
uniform sampler2D ntex;
uniform sampler2D dtex;
//uniform sampler2D cloudtex;
uniform vec3 direction;
@ -13,8 +14,15 @@ out vec4 Diff;
out vec4 Spec;
out vec4 SpecularMap;
vec3 DecodeNormal(vec2 n)
{
float z = dot(n, n) * 2. - 1.;
vec2 xy = normalize(n) * sqrt(1. - z * z);
return vec3(xy,z);
}
void main() {
float z = texture(ntex, uv).a;
float z = texture(dtex, uv).x;
vec4 xpos = 2.0 * vec4(uv, z, 1.0) - 1.0;
xpos = invproj * xpos;
xpos.xyz /= xpos.w;
@ -27,8 +35,7 @@ void main() {
return;
}
vec3 norm = texture(ntex, uv).xyz;
norm = (norm - 0.5) * 2.0;
vec3 norm = normalize(DecodeNormal(2. * texture(ntex, uv).xy - 1.));
// Normalized on the cpu
vec3 L = direction;

View File

@ -0,0 +1,32 @@
#version 130
uniform sampler2D tex;
uniform float fogmax;
uniform float startH;
uniform float endH;
uniform float start;
uniform float end;
uniform vec3 col;
uniform mat4 ipvmat;
uniform vec2 screen;
in vec2 uv;
out vec4 FragColor;
void main()
{
vec4 color = texture(tex, uv);
vec3 tmp = vec3(gl_FragCoord.xy / screen, gl_FragCoord.z);
tmp = 2. * tmp - 1.;
vec4 xpos = vec4(tmp, 1.0);
xpos = ipvmat * xpos;
xpos.xyz /= xpos.w;
float dist = length(xpos.xyz);
float fog = smoothstep(start, end, dist);
fog = min(fog, fogmax);
FragColor = vec4(vec4(col, 0.) * fog + color *(1. - fog));
}

View File

@ -2,10 +2,11 @@
Name=SuperTuxKart
Icon=@PREFIX@/share/pixmaps/supertuxkart_128.png
GenericName=A kart racing game
GenericName[de_DE]=Ein Kart-Rennspiel
GenericName[fr_FR]=Un jeu de karting
GenericName[de]=Ein Kart-Rennspiel
GenericName[fr]=Un jeu de karting
GenericName[gl]=Xogo de carreiras con karts
GenericName[ro_RO]=Un joc de curse cu carturi
GenericName[pl]=Wyścigi gokartów
GenericName[ro]=Un joc de curse cu carturi
Exec=@PREFIX@/@STK_INSTALL_BINARY_DIR@/supertuxkart --no-console
Terminal=false
StartupNotify=false

View File

@ -82,7 +82,7 @@ void btRigidBody::setupRigidBody(const btRigidBody::btRigidBodyConstructionInfo&
setCollisionShape( constructionInfo.m_collisionShape );
m_debugBodyId = uniqueId++;
btAssert(constructionInfo.m_mass>=0);
setMassProps(constructionInfo.m_mass, constructionInfo.m_localInertia);
updateInertiaTensor();

View File

@ -173,7 +173,7 @@ namespace scene
\return The newly created clone of this node. */
virtual ISceneNode* clone(ISceneNode* newParent=0, ISceneManager* newManager=0);
private:
protected:
//! Get a static mesh for the current frame of this animated mesh
IMesh* getMeshForCurrentFrame();

View File

@ -79,7 +79,7 @@ public:
//! Creates a clone of this scene node and its children.
virtual ISceneNode* clone(ISceneNode* newParent=0, ISceneManager* newManager=0);
private:
protected:
//! Size.Width is the bottom edge width
core::dimension2d<f32> Size;

View File

@ -210,11 +210,13 @@ CIrrDeviceLinux::~CIrrDeviceLinux()
}
#if defined(_IRR_COMPILE_WITH_X11_) && defined(_DEBUG)
#if defined(_IRR_COMPILE_WITH_X11_)
static bool XErrorSignaled = false;
int IrrPrintXError(Display *display, XErrorEvent *event)
{
char msg[256];
char msg2[256];
XErrorSignaled = true;
snprintf(msg, 256, "%d", event->request_code);
XGetErrorDatabaseText(display, "XRequest", msg, "unknown", msg2, 256);
@ -370,10 +372,8 @@ void IrrPrintXGrabError(int grabResult, const c8 * grabCommand )
bool CIrrDeviceLinux::createWindow()
{
#ifdef _IRR_COMPILE_WITH_X11_
#ifdef _DEBUG
os::Printer::log("Creating X window...", ELL_INFORMATION);
XSetErrorHandler(IrrPrintXError);
#endif
display = XOpenDisplay(0);
if (!display)
@ -750,12 +750,22 @@ bool CIrrDeviceLinux::createWindow()
GLX_CONTEXT_FLAGS_ARB, GLX_CONTEXT_DEBUG_BIT_ARB,
None
};
PFNGLXCREATECONTEXTATTRIBSARBPROC glXCreateContextAttribsARB = 0;
glXCreateContextAttribsARB = (PFNGLXCREATECONTEXTATTRIBSARBPROC)
glXGetProcAddressARB( (const GLubyte *) "glXCreateContextAttribsARB" );
// create glx context
Context = glXCreateContextAttribsARB(display, glxFBConfig, 0, True, context_attribs);
if (XErrorSignaled)
{
int context_attribs[] =
{
GLX_CONTEXT_MAJOR_VERSION_ARB, 2,
GLX_CONTEXT_MINOR_VERSION_ARB, 1,
None
};
Context = glXCreateContextAttribsARB(display, glxFBConfig, 0, True, context_attribs);
XErrorSignaled = false;
}
if (Context)
{
if (!glXMakeContextCurrent(display, glxWin, glxWin, Context))

View File

@ -2583,8 +2583,8 @@ void COpenGLDriver::setRenderStates3DMode()
ResetRenderStates = true;
#ifdef GL_EXT_clip_volume_hint
if (FeatureAvailable[IRR_EXT_clip_volume_hint])
glHint(GL_CLIP_VOLUME_CLIPPING_HINT_EXT, GL_NICEST);
// if (FeatureAvailable[IRR_EXT_clip_volume_hint])
// glHint(GL_CLIP_VOLUME_CLIPPING_HINT_EXT, GL_NICEST);
#endif
}
@ -3241,8 +3241,8 @@ void COpenGLDriver::setRenderStates2DMode(bool alpha, bool texture, bool alphaCh
}
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
#ifdef GL_EXT_clip_volume_hint
if (FeatureAvailable[IRR_EXT_clip_volume_hint])
glHint(GL_CLIP_VOLUME_CLIPPING_HINT_EXT, GL_FASTEST);
// if (FeatureAvailable[IRR_EXT_clip_volume_hint])
// glHint(GL_CLIP_VOLUME_CLIPPING_HINT_EXT, GL_FASTEST);
#endif
}
@ -4397,12 +4397,6 @@ IImage* COpenGLDriver::createScreenShot(video::ECOLOR_FORMAT format, video::E_RE
if (target==video::ERT_MULTI_RENDER_TEXTURES || target==video::ERT_RENDER_TEXTURE || target==video::ERT_STEREO_BOTH_BUFFERS)
return 0;
// allows to read pixels in top-to-bottom order
#ifdef GL_MESA_pack_invert
if (FeatureAvailable[IRR_MESA_pack_invert])
glPixelStorei(GL_PACK_INVERT_MESA, GL_TRUE);
#endif
if (format==video::ECF_UNKNOWN)
format=getColorFormat();
GLenum fmt;
@ -4542,11 +4536,6 @@ IImage* COpenGLDriver::createScreenShot(video::ECOLOR_FORMAT format, video::E_RE
glReadBuffer(GL_BACK);
}
#ifdef GL_MESA_pack_invert
if (FeatureAvailable[IRR_MESA_pack_invert])
glPixelStorei(GL_PACK_INVERT_MESA, GL_FALSE);
else
#endif
if (pixels)
{
// opengl images are horizontally flipped, so we have to fix that here.

View File

@ -61,9 +61,9 @@
#include <GL/gl.h>
#include <GL/glx.h>
#if defined(_IRR_OPENGL_USE_EXTPOINTER_)
#include "glext.h"
#include <GL/glext.h>
#undef GLX_ARB_get_proc_address // avoid problems with local glxext.h
#include "glxext.h"
#include <GL/glxext.h>
#endif
#endif

View File

@ -898,6 +898,7 @@ bool COpenGLFBODepthTexture::attach(ITexture* renderTex)
return false;
}
rtt->DepthTexture=this;
rtt->DepthBufferTexture = DepthRenderBuffer;
grab(); // grab the depth buffer, not the RTT
rtt->unbindRTT();
return true;

View File

@ -167,6 +167,7 @@ public:
virtual void unbindRTT();
ITexture* DepthTexture;
GLuint DepthBufferTexture;
protected:
GLuint ColorFrameBuffer;
};

View File

@ -214,7 +214,7 @@ public:
//! Returns type of the scene node
virtual ESCENE_NODE_TYPE getType() const { return ESNT_PARTICLE_SYSTEM; }
private:
protected:
void reallocateBuffers();

View File

@ -60,6 +60,8 @@ src/graphics/show_curve.cpp
src/graphics/skid_marks.cpp
src/graphics/slip_stream.cpp
src/graphics/stars.cpp
src/graphics/stkanimatedmesh.cpp
src/graphics/stkbillboard.cpp
src/graphics/stkmesh.cpp
src/graphics/sun.cpp
src/graphics/water.cpp
@ -363,6 +365,7 @@ src/graphics/CBatchingMesh.hpp
src/graphics/explosion.hpp
src/graphics/glow.hpp
src/graphics/glwrap.hpp
src/graphics/gpuparticles.hpp
src/graphics/hardware_skinning.hpp
src/graphics/hit_effect.hpp
src/graphics/hit_sfx.hpp
@ -392,6 +395,8 @@ src/graphics/show_curve.hpp
src/graphics/skid_marks.hpp
src/graphics/slip_stream.hpp
src/graphics/stars.hpp
src/graphics/stkanimatedmesh.hpp
src/graphics/stkbillboard.hpp
src/graphics/stkmesh.hpp
src/graphics/sun.hpp
src/graphics/water.hpp

View File

@ -131,13 +131,14 @@ MapAchievement::MapAchievement(const AchievementInfo * info)
// ============================================================================
void MapAchievement::load(XMLNode * input)
{
std::string achieved("");
bool achieved = false;
input->get("achieved", &achieved);
if(achieved == "true")
if(achieved)
{
m_achieved = true;
return;
}
std::vector<XMLNode*> xml_entries;
input->getNodes("entry", xml_entries);
for (unsigned int n=0; n < xml_entries.size(); n++)

View File

@ -103,6 +103,8 @@ void AchievementsManager::parseAssetFile()
if(num_nodes != m_achievements_info.size())
Log::error("AchievementsManager::parseAchievements",
"Multiple achievements with the same id!");
delete root;
}

View File

@ -311,7 +311,7 @@ void AddonsManager::checkInstalledAddons()
if(n<0) continue;
if(!m_addons_list.getData()[n].isInstalled())
{
Log::info("[addons] Marking '%s' as being installed.\n",
Log::info("[addons] Marking '%s' as being installed.",
kp->getIdent().c_str());
m_addons_list.getData()[n].setInstalled(true);
something_was_changed = true;
@ -330,7 +330,7 @@ void AddonsManager::checkInstalledAddons()
if(n<0) continue;
if(!m_addons_list.getData()[n].isInstalled())
{
Log::info("[addons] Marking '%s' as being installed.\n",
Log::info("[addons] Marking '%s' as being installed.",
track->getIdent().c_str());
m_addons_list.getData()[n].setInstalled(true);
something_was_changed = true;

View File

@ -240,7 +240,7 @@ void GameSlot::save(std::ofstream& out, const std::string& name)
{
out << " <gameslot playerID=\"" << m_player_unique_id.c_str()
<< "\" kart=\"" << m_kart_ident.c_str()
<< "\" firstTime=\"" << (m_first_time ? "true" : "false")
<< "\" firstTime=\"" << StringUtils::toString(m_first_time)
<< "\"> <!-- " << name.c_str() << " -->\n";
std::map<std::string, Challenge*>::const_iterator i;
for(i = m_challenges_state.begin();

View File

@ -36,9 +36,9 @@ PlayerProfile::PlayerProfile(const core::stringw& name) :
#endif
int64_t unique_id = generateUniqueId(core::stringc(name.c_str()).c_str());
std::ostringstream tostring;
tostring << std::hex << unique_id;
m_unique_id = tostring.str();
std::ostringstream to_string;
to_string << std::hex << unique_id;
m_unique_id = to_string.str();
}
//------------------------------------------------------------------------------
@ -67,19 +67,26 @@ PlayerProfile::PlayerProfile(const XMLNode* node) :
#ifdef DEBUG
m_magic_number = 0xABCD1234;
#endif
}
} // PlayerProfile
//------------------------------------------------------------------------------
void PlayerProfile::incrementUseFrequency()
{
if (m_is_guest_account) m_use_frequency = -1;
else m_use_frequency++;
}
} // incrementUseFrequency
//------------------------------------------------------------------------------
int64_t PlayerProfile::generateUniqueId(const char* playerName)
int64_t PlayerProfile::generateUniqueId(const char* player_name)
{
// First create a simple hash based on he player name
int hash = 0;
for (int n=0; player_name[n] != 0; n++)
{
hash += (hash << (hash & 0xF)) ^ player_name[n];
}
return ((int64_t)(StkTime::getTimeSinceEpoch()) << 32) |
((rand() << 16) & 0xFFFF0000) |
(StringUtils::simpleHash(playerName) & 0xFFFF);
}
((rand() << 16) & 0xFFFF0000) |
hash;
} // generateUniqueId

View File

@ -183,8 +183,8 @@ void GroupUserConfigParam::addChild(UserConfigParam* child)
// ============================================================================
template<typename T>
ListUserConfigParam<T>::ListUserConfigParam(const char* param_name,
template<typename T, typename U>
ListUserConfigParam<T, U>::ListUserConfigParam(const char* param_name,
const char* comment)
{
m_param_name = param_name;
@ -193,8 +193,8 @@ ListUserConfigParam<T>::ListUserConfigParam(const char* param_name,
} // ListUserConfigParam
// ============================================================================
template<typename T>
ListUserConfigParam<T>::ListUserConfigParam(const char* param_name,
template<typename T, typename U>
ListUserConfigParam<T,U>::ListUserConfigParam(const char* param_name,
const char* comment,
int nb_elements,
...)
@ -207,13 +207,13 @@ ListUserConfigParam<T>::ListUserConfigParam(const char* param_name,
va_list arguments;
va_start ( arguments, nb_elements );
for ( int i = 0; i < nb_elements; i++ )
m_elements.push_back(va_arg ( arguments, T ));
m_elements.push_back(T(va_arg ( arguments, U )));
va_end ( arguments ); // Cleans up the list
} // ListUserConfigParam
// ============================================================================
template<typename T>
ListUserConfigParam<T>::ListUserConfigParam(const char* param_name,
template<typename T, typename U>
ListUserConfigParam<T, U>::ListUserConfigParam(const char* param_name,
GroupUserConfigParam* group,
const char* comment)
{
@ -223,8 +223,8 @@ ListUserConfigParam<T>::ListUserConfigParam(const char* param_name,
} // ListUserConfigParam
// ============================================================================
template<typename T>
ListUserConfigParam<T>::ListUserConfigParam(const char* param_name,
template<typename T, typename U>
ListUserConfigParam<T, U>::ListUserConfigParam(const char* param_name,
GroupUserConfigParam* group,
const char* comment,
int nb_elements,
@ -243,8 +243,8 @@ ListUserConfigParam<T>::ListUserConfigParam(const char* param_name,
} // ListUserConfigParam
// ----------------------------------------------------------------------------
template<typename T>
void ListUserConfigParam<T>::write(XMLWriter& stream) const
template<typename T, typename U>
void ListUserConfigParam<T, U>::write(XMLWriter& stream) const
{
const int elts_amount = m_elements.size();
@ -256,7 +256,7 @@ void ListUserConfigParam<T>::write(XMLWriter& stream) const
// actual elements
for (int n=0; n<elts_amount; n++)
{
stream << L" " << n << "=\"" << m_elements[n] << "\"\n";
stream << L" " << n << "=\"" << m_elements[n].c_str() << "\"\n";
}
stream << L" >\n";
stream << L" </" << m_param_name.c_str() << ">\n\n";
@ -264,20 +264,8 @@ void ListUserConfigParam<T>::write(XMLWriter& stream) const
// ----------------------------------------------------------------------------
// Write your own convert function depending on the type of list you use.
void convert(std::string str, char** str2)
{
*str2 = (char*)(malloc(str.size()+1));
strcpy(*str2, str.c_str());
}
// Write your own equals function depending on the type of list you use.
bool equals(char* str1, char* str2)
{
return (strcmp(str1, str2) == 0);
}
template<typename T>
void ListUserConfigParam<T>::findYourDataInAChildOf(const XMLNode* node)
template<typename T, typename U>
void ListUserConfigParam<T, U>::findYourDataInAChildOf(const XMLNode* node)
{
const XMLNode* child = node->getNode( m_param_name );
if (child == NULL)
@ -292,16 +280,15 @@ void ListUserConfigParam<T>::findYourDataInAChildOf(const XMLNode* node)
for (int n=0; n<attr_count; n++)
{
T elt;
std::ostringstream oss;
oss << n;
std::string str;
child->get( oss.str(), &str);
convert(str, &elt);
child->get( StringUtils::toString(n), &str);
StringUtils::fromString<T>(str, elt);
// check if the element is already there :
bool there = false;
for (unsigned int i = 0; i < m_elements.size(); i++)
{
if (equals(m_elements[i], elt))
if (elt == m_elements[i])
{
there = true;
break;
@ -309,7 +296,6 @@ void ListUserConfigParam<T>::findYourDataInAChildOf(const XMLNode* node)
}
if (!there)
{
Log::info("ListUserConfigParam", "New data : %s, \"%s\"", str.c_str(), elt);
m_elements.push_back(elt);
}
}
@ -317,21 +303,21 @@ void ListUserConfigParam<T>::findYourDataInAChildOf(const XMLNode* node)
} // findYourDataInAChildOf
// ----------------------------------------------------------------------------
template<typename T>
void ListUserConfigParam<T>::findYourDataInAnAttributeOf(const XMLNode* node)
template<typename T, typename U>
void ListUserConfigParam<T, U>::findYourDataInAnAttributeOf(const XMLNode* node)
{
} // findYourDataInAnAttributeOf
// ----------------------------------------------------------------------------
template<typename T>
void ListUserConfigParam<T>::addElement(T element)
template<typename T, typename U>
void ListUserConfigParam<T,U>::addElement(T element)
{
m_elements.push_back(element);
} // findYourDataInAnAttributeOf
// ----------------------------------------------------------------------------
template<typename T>
irr::core::stringw ListUserConfigParam<T>::toString() const
template<typename T, typename U>
irr::core::stringw ListUserConfigParam<T,U>::toString() const
{
return "";
} // toString

View File

@ -99,7 +99,7 @@ public:
}; // GroupUserConfigParam
// ============================================================================
template<typename T>
template<typename T, typename U>
class ListUserConfigParam : public UserConfigParam
{
std::vector<T> m_elements;
@ -135,7 +135,7 @@ public:
float& operator=(const ListUserConfigParam& v)
{ m_elements = std::vector<T>(v); return m_elements; }
}; // ListUserConfigParam
typedef ListUserConfigParam<char*> StringListUserConfigParam;
typedef ListUserConfigParam<std::string, const char*> StringListUserConfigParam;
// ============================================================================
class IntUserConfigParam : public UserConfigParam
@ -541,7 +541,7 @@ namespace UserConfigParams
"stun.counterpath.net",
"stun.endigovoip.com",
"stun.ekiga.net",
"stun.ideasip.com" ,
"stun.ideasip.com",
"stun.internetcalls.com",
"stun.ipns.com",
"stun.noc.ams-ix.net",

View File

@ -254,13 +254,6 @@ void ColorizeProvider::OnSetConstants(IMaterialRendererServices *srv, int)
//-------------------------------------
void GlowProvider::OnSetConstants(IMaterialRendererServices *srv, int)
{
srv->setVertexShaderConstant("res", m_res, 2);
}
//-------------------------------------
void ObjectPassProvider::OnSetConstants(IMaterialRendererServices *srv, int)
{
core::matrix4 ModelViewProjectionMatrix = srv->getVideoDriver()->getTransform(ETS_PROJECTION);

View File

@ -328,23 +328,6 @@ private:
//
class GlowProvider: public CallBase
{
public:
virtual void OnSetConstants(video::IMaterialRendererServices *srv, int);
void setResolution(int x, int y)
{
m_res[0] = (float)x;
m_res[1] = (float)y;
}
private:
float m_res[2];
};
//
class ObjectPassProvider: public CallBase
{
public:

View File

@ -39,15 +39,6 @@ GlowNode::GlowNode(scene::ISceneManager* mgr, float radius): ISceneNode(mgr->get
{
if (!sphere)
{
mat.Lighting = false;
mat.MaterialType = irr_driver->getShader(ES_GLOW);
mat.setTexture(0, irr_driver->getRTT(RTT_QUARTER1));
mat.TextureLayer[0].TextureWrapU =
mat.TextureLayer[0].TextureWrapV = ETC_CLAMP_TO_EDGE;
mat.setFlag(EMF_TRILINEAR_FILTER, true);
mat.BlendOperation = EBO_ADD;
sphere = mgr->getGeometryCreator()->createSphereMesh(1, 4, 4);
box = sphere->getBoundingBox();
}
@ -65,10 +56,5 @@ void GlowNode::render()
void GlowNode::OnRegisterSceneNode()
{
if (IsVisible)
{
SceneManager->registerNodeForRendering(this, ESNRP_TRANSPARENT);
}
ISceneNode::OnRegisterSceneNode();
}

View File

@ -2,6 +2,7 @@
#include "irr_driver.hpp"
#include <fstream>
#include <string>
#include "config/user_config.hpp"
#ifdef _IRR_WINDOWS_API_
#define IRR_OGL_LOAD_EXTENSION(X) wglGetProcAddress(reinterpret_cast<const char*>(X))
@ -55,8 +56,6 @@ PFNGLVERTEXATTRIBIPOINTERPROC glVertexAttribIPointer;
PFNGLDEBUGMESSAGECALLBACKARBPROC glDebugMessageCallbackARB;
#endif
static GLuint quad_buffer;
static GLuint ColoredVertex;
static bool is_gl_init = false;
//#define ARB_DEBUG_OUTPUT
@ -185,27 +184,6 @@ void initGL()
#ifdef ARB_DEBUG_OUTPUT
glDebugMessageCallbackARB((GLDEBUGPROCARB)debugCallback, NULL);
#endif
const float quad_vertex[] = {
-1., -1., -1., 1., // UpperLeft
-1., 1., -1., -1., // LowerLeft
1., -1., 1., 1., // UpperRight
1., 1., 1., -1., // LowerRight
};
glGenBuffers(1, &quad_buffer);
glBindBuffer(GL_ARRAY_BUFFER, quad_buffer);
glBufferData(GL_ARRAY_BUFFER, 16 * sizeof(float), quad_vertex, GL_STATIC_DRAW);
const unsigned quad_color[] = {
0, 0, 0, 255,
255, 0, 0, 255,
0, 255, 0, 255,
0, 0, 255, 255,
};
glGenBuffers(1, &ColoredVertex);
glBindBuffer(GL_ARRAY_BUFFER, ColoredVertex);
glBufferData(GL_ARRAY_BUFFER, 16 * sizeof(unsigned), quad_color, GL_DYNAMIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, 0);
}
// Mostly from shader tutorial
@ -296,7 +274,7 @@ void bindUniformToTextureUnit(GLuint location, GLuint texid, unsigned textureUni
glUniform1i(location, textureUnit);
}
void setTexture(unsigned TextureUnit, GLuint TextureId, GLenum MagFilter, GLenum MinFilter)
void setTexture(unsigned TextureUnit, GLuint TextureId, GLenum MagFilter, GLenum MinFilter, bool allowAF)
{
glActiveTexture(GL_TEXTURE0 + TextureUnit);
glBindTexture(GL_TEXTURE_2D, TextureId);
@ -304,31 +282,9 @@ void setTexture(unsigned TextureUnit, GLuint TextureId, GLenum MagFilter, GLenum
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, MinFilter);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, allowAF ? UserConfigParams::m_anisotropic : 0);
}
static GLuint TexturedQuadShader;
static GLuint TexturedQuadAttribPosition;
static GLuint TexturedQuadAttribTexCoord;
static GLuint TexturedQuadUniformTex;
static GLuint TexturedQuadUniformCenter;
static GLuint TexturedQuadUniformSize;
static GLuint TexturedQuadUniformTexcenter;
static GLuint TexturedQuadUniformTexsize;
static GLuint TQvao;
static GLuint ColorTexturedQuadShader;
static GLuint ColorTexturedQuadAttribPosition;
static GLuint ColorTexturedQuadAttribTexCoord;
static GLuint ColorTexturedQuadAttribColor;
static GLuint ColorTexturedQuadUniformTex;
static GLuint ColorTexturedQuadUniformCenter;
static GLuint ColorTexturedQuadUniformSize;
static GLuint ColorTexturedQuadUniformTexcenter;
static GLuint ColorTexturedQuadUniformTexsize;
static GLuint CTQvao;
static void drawTexColoredQuad(const video::ITexture *texture, const video::SColor *col, float width, float height,
float center_pos_x, float center_pos_y, float tex_center_pos_x, float tex_center_pos_y,
float tex_width, float tex_height)
@ -340,42 +296,15 @@ static void drawTexColoredQuad(const video::ITexture *texture, const video::SCol
col[3].getRed(), col[3].getGreen(), col[3].getBlue(), col[3].getAlpha(),
};
if (!ColorTexturedQuadShader) {
ColorTexturedQuadShader = LoadProgram(file_manager->getAsset("shaders/colortexturedquad.vert").c_str(), file_manager->getAsset("shaders/colortexturedquad.frag").c_str());
ColorTexturedQuadAttribPosition = glGetAttribLocation(ColorTexturedQuadShader, "position");
ColorTexturedQuadAttribTexCoord = glGetAttribLocation(ColorTexturedQuadShader, "texcoord");
ColorTexturedQuadAttribColor = glGetAttribLocation(ColorTexturedQuadShader, "color");
ColorTexturedQuadUniformTex = glGetUniformLocation(ColorTexturedQuadShader, "tex");
ColorTexturedQuadUniformCenter = glGetUniformLocation(ColorTexturedQuadShader, "center");
ColorTexturedQuadUniformSize = glGetUniformLocation(ColorTexturedQuadShader, "size");
ColorTexturedQuadUniformTexcenter = glGetUniformLocation(ColorTexturedQuadShader, "texcenter");
ColorTexturedQuadUniformTexsize = glGetUniformLocation(ColorTexturedQuadShader, "texsize");
glGenVertexArrays(1, &CTQvao);
glBindVertexArray(CTQvao);
glEnableVertexAttribArray(ColorTexturedQuadAttribPosition);
glEnableVertexAttribArray(ColorTexturedQuadAttribTexCoord);
glEnableVertexAttribArray(ColorTexturedQuadAttribColor);
glBindBuffer(GL_ARRAY_BUFFER, quad_buffer);
glVertexAttribPointer(ColorTexturedQuadAttribPosition, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float), 0);
glVertexAttribPointer(ColorTexturedQuadAttribTexCoord, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float), (GLvoid *)(2 * sizeof(float)));
glBindBuffer(GL_ARRAY_BUFFER, ColoredVertex);
glVertexAttribIPointer(ColorTexturedQuadAttribColor, 4, GL_UNSIGNED_INT, 4 * sizeof(unsigned), 0);
glBindVertexArray(0);
}
glBindBuffer(GL_ARRAY_BUFFER, ColoredVertex);
glBindBuffer(GL_ARRAY_BUFFER, UIShader::ColoredTextureRectShader::colorvbo);
glBufferSubData(GL_ARRAY_BUFFER, 0, 16 * sizeof(unsigned), colors);
glUseProgram(ColorTexturedQuadShader);
glBindVertexArray(CTQvao);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, static_cast<const irr::video::COpenGLTexture*>(texture)->getOpenGLTextureName());
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glUniform1i(ColorTexturedQuadUniformTex, 0);
glUniform2f(ColorTexturedQuadUniformCenter, center_pos_x, center_pos_y);
glUniform2f(ColorTexturedQuadUniformSize, width, height);
glUniform2f(ColorTexturedQuadUniformTexcenter, tex_center_pos_x, tex_center_pos_y);
glUniform2f(ColorTexturedQuadUniformTexsize, tex_width, tex_height);
glUseProgram(UIShader::ColoredTextureRectShader::Program);
glBindVertexArray(UIShader::ColoredTextureRectShader::vao);
setTexture(0, static_cast<const irr::video::COpenGLTexture*>(texture)->getOpenGLTextureName(), GL_LINEAR, GL_LINEAR);
UIShader::TextureRectShader::setUniforms(center_pos_x, center_pos_y, width, height, tex_center_pos_x, tex_center_pos_y, tex_width, tex_height, 0);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
glBindVertexArray(0);
glBindBuffer(GL_ARRAY_BUFFER, 0);
@ -385,36 +314,12 @@ void drawTexQuad(const video::ITexture *texture, float width, float height,
float center_pos_x, float center_pos_y, float tex_center_pos_x, float tex_center_pos_y,
float tex_width, float tex_height)
{
if (!TexturedQuadShader) {
TexturedQuadShader = LoadProgram(file_manager->getAsset("shaders/texturedquad.vert").c_str(), file_manager->getAsset("shaders/texturedquad.frag").c_str());
glUseProgram(UIShader::TextureRectShader::Program);
glBindVertexArray(UIShader::TextureRectShader::vao);
setTexture(0, static_cast<const irr::video::COpenGLTexture*>(texture)->getOpenGLTextureName(), GL_LINEAR, GL_LINEAR);
UIShader::TextureRectShader::setUniforms(center_pos_x, center_pos_y, width, height, tex_center_pos_x, tex_center_pos_y, tex_width, tex_height, 0);
TexturedQuadAttribPosition = glGetAttribLocation(TexturedQuadShader, "position");
TexturedQuadAttribTexCoord = glGetAttribLocation(TexturedQuadShader, "texcoord");
TexturedQuadUniformTex = glGetUniformLocation(TexturedQuadShader, "tex");
TexturedQuadUniformCenter = glGetUniformLocation(TexturedQuadShader, "center");
TexturedQuadUniformSize = glGetUniformLocation(TexturedQuadShader, "size");
TexturedQuadUniformTexcenter = glGetUniformLocation(TexturedQuadShader, "texcenter");
TexturedQuadUniformTexsize = glGetUniformLocation(TexturedQuadShader, "texsize");
glGenVertexArrays(1, &TQvao);
glBindVertexArray(TQvao);
glEnableVertexAttribArray(TexturedQuadAttribPosition);
glEnableVertexAttribArray(TexturedQuadAttribTexCoord);
glBindBuffer(GL_ARRAY_BUFFER, quad_buffer);
glVertexAttribPointer(TexturedQuadAttribPosition, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float), 0);
glVertexAttribPointer(TexturedQuadAttribTexCoord, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float), (GLvoid *)(2 * sizeof(float)));
glBindVertexArray(0);
}
glUseProgram(TexturedQuadShader);
glBindVertexArray(TQvao);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, static_cast<const irr::video::COpenGLTexture*>(texture)->getOpenGLTextureName());
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glUniform1i(TexturedQuadUniformTex, 0);
glUniform2f(TexturedQuadUniformCenter, center_pos_x, center_pos_y);
glUniform2f(TexturedQuadUniformSize, width, height);
glUniform2f(TexturedQuadUniformTexcenter, tex_center_pos_x, tex_center_pos_y);
glUniform2f(TexturedQuadUniformTexsize, tex_width, tex_height);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
glBindVertexArray(0);
glBindBuffer(GL_ARRAY_BUFFER, 0);
@ -458,6 +363,10 @@ void draw2DImage(const video::ITexture* texture, const core::rect<s32>& destRect
float tex_height = sourceRect.LowerRightCorner.Y - sourceRect.UpperLeftCorner.Y;
tex_height /= ss.Height * 2.;
if (texture->isRenderTarget()) {
tex_height = - tex_height;
}
const f32 invW = 1.f / static_cast<f32>(ss.Width);
const f32 invH = 1.f / static_cast<f32>(ss.Height);
const core::rect<f32> tcoords(
@ -466,8 +375,6 @@ void draw2DImage(const video::ITexture* texture, const core::rect<s32>& destRect
sourceRect.LowerRightCorner.X * invW,
sourceRect.LowerRightCorner.Y *invH);
initGL();
if (useAlphaChannelOfTexture)
{
glEnable(GL_BLEND);
@ -486,12 +393,6 @@ void draw2DImage(const video::ITexture* texture, const core::rect<s32>& destRect
glUseProgram(0);
}
static GLuint ColoredQuadShader;
static GLuint ColoredQuadUniformCenter;
static GLuint ColoredQuadUniformSize;
static GLuint ColoredQuadUniformColor;
static GLuint CQvao;
void GL32_draw2DRectangle(video::SColor color, const core::rect<s32>& position,
const core::rect<s32>* clip)
{
@ -517,8 +418,6 @@ void GL32_draw2DRectangle(video::SColor color, const core::rect<s32>& position,
float height = position.LowerRightCorner.Y - position.UpperLeftCorner.Y;
height /= screen_h;
initGL();
if (color.getAlpha() < 255)
{
glEnable(GL_BLEND);
@ -529,24 +428,10 @@ void GL32_draw2DRectangle(video::SColor color, const core::rect<s32>& position,
glDisable(GL_BLEND);
}
if (!ColoredQuadShader)
{
ColoredQuadShader = LoadProgram(file_manager->getAsset("shaders/coloredquad.vert").c_str(), file_manager->getAsset("shaders/coloredquad.frag").c_str());
ColoredQuadUniformColor = glGetUniformLocation(ColoredQuadShader, "color");
ColoredQuadUniformCenter = glGetUniformLocation(ColoredQuadShader, "center");
ColoredQuadUniformSize = glGetUniformLocation(ColoredQuadShader, "size");
glGenVertexArrays(1, &CQvao);
glBindVertexArray(CQvao);
glEnableVertexAttribArray(0);
glBindBuffer(GL_ARRAY_BUFFER, quad_buffer);
glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float), 0);
glBindVertexArray(0);
}
glUseProgram(ColoredQuadShader);
glBindVertexArray(CQvao);
glUniform2f(ColoredQuadUniformCenter, center_pos_x, center_pos_y);
glUniform2f(ColoredQuadUniformSize, width, height);
glUniform4i(ColoredQuadUniformColor, color.getRed(), color.getGreen(), color.getBlue(), color.getAlpha());
glUseProgram(UIShader::ColoredRectShader::Program);
glBindVertexArray(UIShader::ColoredRectShader::vao);
UIShader::ColoredRectShader::setUniforms(center_pos_x, center_pos_y, width, height, color);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindVertexArray(0);

View File

@ -22,7 +22,7 @@ void initGL();
GLuint LoadProgram(const char * vertex_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);
void setTexture(unsigned TextureUnit, GLuint TextureId, GLenum MagFilter, GLenum MinFilter, bool allowAF = false);
// already includes glext.h, which defines useful GL constants.
// COpenGLDriver has already loaded the extension GL functions we use (e.g glBeginQuery)

File diff suppressed because it is too large Load Diff

View File

@ -1,97 +0,0 @@
#ifndef GPUPARTICLES_H
#define GPUPARTICLES_H
#include "graphics/glwrap.hpp"
#include "../lib/irrlicht/source/Irrlicht/CParticleSystemSceneNode.h"
#include <ISceneManager.h>
#include <IParticleSystemSceneNode.h>
namespace irr { namespace video{ class ITexture; } }
GLuint getTextureGLuint(irr::video::ITexture *tex);
class GPUParticle : public scene::ISceneNode
{
protected:
video::SMaterial fakemat;
virtual void simulate() = 0;
virtual void draw() = 0;
public:
GPUParticle(scene::ISceneNode *parent, scene::ISceneManager* mgr,
video::ITexture *tex);
virtual void render();
virtual void OnRegisterSceneNode();
};
class ParticleSystemProxy : public scene::CParticleSystemSceneNode {
protected:
video::SMaterial fakemat;
GLuint tfb_buffers[2], initial_values_buffer, heighmapbuffer, heightmaptexture, quaternionsbuffer;
GLuint current_simulation_vao, non_current_simulation_vao;
GLuint current_hm_simulation_vao, non_currenthm__simulation_vao;
GLuint current_rendering_vao, non_current_rendering_vao;
GLuint current_rendering_flip_vao, non_current_rendering_flip_vao;
bool m_alpha_additive, has_height_map, flip;
float size_increase_factor, track_x, track_z, track_x_len, track_z_len;
static GLuint quad_vertex_buffer;
GLuint texture, normal_and_depth;
unsigned count;
static void SimpleParticleVAOBind(GLuint PositionBuffer);
static void FlipParticleVAOBind(GLuint PositionBuffer, GLuint QuaternionBuffer);
static void SimpleSimulationBind(GLuint PositionBuffer, GLuint InitialValuesBuffer);
static void HeightmapSimulationBind(GLuint PositionBuffer, GLuint InitialValuesBuffer);
void simulateHeightmap();
void simulateNoHeightmap();
void drawFlip();
void drawNotFlip();
virtual void simulate();
virtual void draw();
void generateParticlesFromPointEmitter(scene::IParticlePointEmitter *);
void generateParticlesFromBoxEmitter(scene::IParticleBoxEmitter *);
void generateParticlesFromSphereEmitter(scene::IParticleSphereEmitter *);
public:
static IParticleSystemSceneNode *addParticleNode(
bool withDefaultEmitter = true, ISceneNode* parent = 0, s32 id = -1,
const core::vector3df& position = core::vector3df(0, 0, 0),
const core::vector3df& rotation = core::vector3df(0, 0, 0),
const core::vector3df& scale = core::vector3df(1.0f, 1.0f, 1.0f));
ParticleSystemProxy(bool createDefaultEmitter,
ISceneNode* parent, scene::ISceneManager* mgr, s32 id,
const core::vector3df& position,
const core::vector3df& rotation,
const core::vector3df& scale);
~ParticleSystemProxy();
virtual void setEmitter(scene::IParticleEmitter* emitter);
virtual void render();
void setAlphaAdditive(bool);
void setIncreaseFactor(float);
void setHeightmap(const std::vector<std::vector<float> >&, float, float, float, float);
void setFlip();
};
class RainNode : public GPUParticle
{
protected:
GLuint SimulationProgram, RenderProgram, tfb_vertex_buffer[2];
unsigned count;
GLuint texture, normal_and_depth;
GLuint loc_campos, loc_viewm, loc_time;
GLuint loc_screenw, loc_screen, loc_invproj, texloc_tex, texloc_normal_and_depths;
s32 area;
core::aabbox3d<f32> box;
virtual void simulate();
virtual void draw();
public:
RainNode(scene::ISceneManager* mgr, video::ITexture *tex);
virtual const core::aabbox3d<f32>& getBoundingBox() const;
virtual u32 getMaterialCount() const { return 1; }
};
#endif // GPUPARTICLES_H

View File

@ -0,0 +1,98 @@
#ifndef GPUPARTICLES_H
#define GPUPARTICLES_H
#include "graphics/glwrap.hpp"
#include "../lib/irrlicht/source/Irrlicht/CParticleSystemSceneNode.h"
#include <ISceneManager.h>
#include <IParticleSystemSceneNode.h>
namespace irr { namespace video{ class ITexture; } }
GLuint getTextureGLuint(irr::video::ITexture *tex);
class GPUParticle : public scene::ISceneNode
{
protected:
video::SMaterial fakemat;
virtual void simulate() = 0;
virtual void draw() = 0;
public:
GPUParticle(scene::ISceneNode *parent, scene::ISceneManager* mgr,
video::ITexture *tex);
virtual void render();
virtual void OnRegisterSceneNode();
};
class ParticleSystemProxy : public scene::CParticleSystemSceneNode {
protected:
video::SMaterial fakemat;
GLuint tfb_buffers[2], initial_values_buffer, heighmapbuffer, heightmaptexture, quaternionsbuffer;
GLuint current_simulation_vao, non_current_simulation_vao;
GLuint current_hm_simulation_vao, non_currenthm__simulation_vao;
GLuint current_rendering_vao, non_current_rendering_vao;
GLuint current_rendering_flip_vao, non_current_rendering_flip_vao;
bool m_alpha_additive, has_height_map, flip;
float size_increase_factor, track_x, track_z, track_x_len, track_z_len;
static GLuint quad_vertex_buffer;
GLuint texture;
unsigned count;
static void SimpleParticleVAOBind(GLuint PositionBuffer);
static void FlipParticleVAOBind(GLuint PositionBuffer, GLuint QuaternionBuffer);
static void SimpleSimulationBind(GLuint PositionBuffer, GLuint InitialValuesBuffer);
static void HeightmapSimulationBind(GLuint PositionBuffer, GLuint InitialValuesBuffer);
void simulateHeightmap();
void simulateNoHeightmap();
void drawFlip();
void drawNotFlip();
virtual void simulate();
virtual void draw();
void generateParticlesFromPointEmitter(scene::IParticlePointEmitter *);
void generateParticlesFromBoxEmitter(scene::IParticleBoxEmitter *);
void generateParticlesFromSphereEmitter(scene::IParticleSphereEmitter *);
public:
static IParticleSystemSceneNode *addParticleNode(
bool withDefaultEmitter = true, ISceneNode* parent = 0, s32 id = -1,
const core::vector3df& position = core::vector3df(0, 0, 0),
const core::vector3df& rotation = core::vector3df(0, 0, 0),
const core::vector3df& scale = core::vector3df(1.0f, 1.0f, 1.0f));
ParticleSystemProxy(bool createDefaultEmitter,
ISceneNode* parent, scene::ISceneManager* mgr, s32 id,
const core::vector3df& position,
const core::vector3df& rotation,
const core::vector3df& scale);
~ParticleSystemProxy();
virtual void setEmitter(scene::IParticleEmitter* emitter);
virtual void render();
virtual void OnRegisterSceneNode();
void setAlphaAdditive(bool);
void setIncreaseFactor(float);
void setHeightmap(const std::vector<std::vector<float> >&, float, float, float, float);
void setFlip();
};
class RainNode : public GPUParticle
{
protected:
GLuint SimulationProgram, RenderProgram, tfb_vertex_buffer[2];
unsigned count;
GLuint texture, normal_and_depth;
GLuint loc_campos, loc_viewm, loc_time;
GLuint loc_screenw, loc_screen, loc_invproj, texloc_tex, texloc_normal_and_depths;
s32 area;
core::aabbox3d<f32> box;
virtual void simulate();
virtual void draw();
public:
RainNode(scene::ISceneManager* mgr, video::ITexture *tex);
virtual const core::aabbox3d<f32>& getBoundingBox() const;
virtual u32 getMaterialCount() const { return 1; }
};
#endif // GPUPARTICLES_H

View File

@ -32,6 +32,8 @@
#include "graphics/referee.hpp"
#include "graphics/shaders.hpp"
#include "graphics/shadow_importance.hpp"
#include "graphics/stkanimatedmesh.hpp"
#include "graphics/stkbillboard.hpp"
#include "graphics/stkmesh.hpp"
#include "graphics/sun.hpp"
#include "graphics/rtts.hpp"
@ -140,16 +142,21 @@ void IrrDriver::reset()
if (m_glsl) m_post_processing->reset();
} // reset
void IrrDriver::setPhase(unsigned p)
void IrrDriver::setPhase(STKRenderingPass p)
{
phase = p;
}
unsigned IrrDriver::getPhase() const
STKRenderingPass IrrDriver::getPhase() const
{
return phase;
}
void IrrDriver::IncreaseObjectCount()
{
object_count[phase]++;
}
core::array<video::IRenderTarget> &IrrDriver::getMainSetup()
{
return m_mrt;
@ -650,8 +657,8 @@ void IrrDriver::applyResolutionSettings()
attachment_manager->removeTextures();
projectile_manager->removeTextures();
ItemManager::removeTextures();
kart_properties_manager -> unloadAllKarts();
powerup_manager-> unloadPowerups();
kart_properties_manager->unloadAllKarts();
powerup_manager->unloadPowerups();
Referee::cleanup();
ParticleKindManager::get()->cleanup();
delete input_manager;
@ -703,7 +710,6 @@ void IrrDriver::applyResolutionSettings()
file_manager->popTextureSearchPath();
KartPropertiesManager::addKartSearchDir(file_manager->getAddonsFile("karts"));
kart_properties_manager->loadAllKarts();
attachment_manager->loadModels();
@ -939,17 +945,6 @@ scene::IMeshSceneNode *IrrDriver::addMesh(scene::IMesh *mesh,
// ----------------------------------------------------------------------------
PerCameraNode *IrrDriver::addPerCameraMesh(scene::IMesh* mesh,
scene::ICameraSceneNode* camera,
scene::ISceneNode *parent)
{
scene::ISceneNode *node = m_scene_manager->addMeshSceneNode(mesh);
return new PerCameraNode((parent ? parent
: m_scene_manager->getRootSceneNode()),
m_scene_manager, -1, camera, node);
} // addMesh
PerCameraNode *IrrDriver::addPerCameraNode(scene::ISceneNode* node,
scene::ICameraSceneNode* camera,
scene::ISceneNode *parent)
@ -967,8 +962,17 @@ scene::ISceneNode *IrrDriver::addBillboard(const core::dimension2d< f32 > size,
video::ITexture *texture,
scene::ISceneNode* parent, bool alphaTesting)
{
scene::IBillboardSceneNode* node =
m_scene_manager->addBillboardSceneNode(parent, size);
scene::IBillboardSceneNode* node;
if (isGLSL())
{
if (!parent)
parent = m_scene_manager->getRootSceneNode();
node = new STKBillboard(parent, m_scene_manager, -1, vector3df(0., 0., 0.), size);
node->drop();
}
else
node = m_scene_manager->addBillboardSceneNode(parent, size);
assert(node->getMaterialCount() > 0);
node->setMaterialTexture(0, texture);
if(alphaTesting)
@ -1111,11 +1115,19 @@ void IrrDriver::removeTexture(video::ITexture *t)
*/
scene::IAnimatedMeshSceneNode *IrrDriver::addAnimatedMesh(scene::IAnimatedMesh *mesh, scene::ISceneNode* parent)
{
return m_scene_manager->addAnimatedMeshSceneNode(mesh, parent, -1,
if (!isGLSL())
return m_scene_manager->addAnimatedMeshSceneNode(mesh, parent, -1,
core::vector3df(0,0,0),
core::vector3df(0,0,0),
core::vector3df(1,1,1),
/*addIfMeshIsZero*/true);
if (!parent)
parent = m_scene_manager->getRootSceneNode();
scene::IAnimatedMeshSceneNode* node =
new STKAnimatedMesh(mesh, parent, m_scene_manager, -1, core::vector3df(0,0,0), core::vector3df(0,0,0), core::vector3df(1,1,1));
node->drop();
return node;
} // addAnimatedMesh
// ----------------------------------------------------------------------------
@ -1136,6 +1148,7 @@ scene::ISceneNode *IrrDriver::addSkyDome(video::ITexture *texture,
float texture_percent,
float sphere_percent)
{
Log::error("skybox", "Using deprecated SkyDome");
return m_scene_manager->addSkyDomeSceneNode(texture, hori_res, vert_res,
texture_percent,
sphere_percent);
@ -1155,11 +1168,17 @@ scene::ISceneNode *IrrDriver::addSkyDome(video::ITexture *texture,
scene::ISceneNode *IrrDriver::addSkyBox(const std::vector<video::ITexture*>
&texture)
{
SkyboxTextures = texture;
return m_scene_manager->addSkyBoxSceneNode(texture[0], texture[1],
texture[2], texture[3],
texture[4], texture[5]);
} // addSkyBox
void IrrDriver::suppressSkyBox()
{
SkyboxTextures.clear();
}
// ----------------------------------------------------------------------------
/** Adds a camera to the scene.
*/
@ -1427,15 +1446,15 @@ void IrrDriver::setAmbientLight(const video::SColor &light)
*/
void IrrDriver::displayFPS()
{
gui::IGUIFont* font = GUIEngine::getFont();
gui::IGUIFont* font = GUIEngine::getSmallFont();
if(UserConfigParams::m_artist_debug_mode)
{
GL32_draw2DRectangle(video::SColor(150, 96, 74, 196),core::rect< s32 >(75,0,1100,50),NULL);
GL32_draw2DRectangle(video::SColor(150, 96, 74, 196),core::rect< s32 >(75,0,1100,40),NULL);
}
else
{
GL32_draw2DRectangle(video::SColor(150, 96, 74, 196),core::rect< s32 >(75,0,900,50),NULL);
GL32_draw2DRectangle(video::SColor(150, 96, 74, 196),core::rect< s32 >(75,0,900,40),NULL);
}
// We will let pass some time to let things settle before trusting FPS counter
// even if we also ignore fps = 1, which tends to happen in first checks
@ -1484,12 +1503,15 @@ void IrrDriver::displayFPS()
if (low > kilotris) low = kilotris;
if (high < kilotris) high = kilotris;
static char buffer[64];
static char buffer[128];
if (UserConfigParams::m_artist_debug_mode)
{
sprintf(buffer, "FPS: %i/%i/%i - %.2f/%.2f/%.2f KTris - LightDst : ~%d",
min, fps, max, low, kilotris, high, m_last_light_bucket_distance);
sprintf(buffer, "FPS: %i/%i/%i - Objects (P1:%d P2:%d T:%d) KTris - LightDst : ~%d",
min, fps, max, object_count[SOLID_NORMAL_AND_DEPTH_PASS], object_count[SOLID_NORMAL_AND_DEPTH_PASS], object_count[TRANSPARENT_PASS], m_last_light_bucket_distance);
object_count[SOLID_NORMAL_AND_DEPTH_PASS] = 0;
object_count[SOLID_NORMAL_AND_DEPTH_PASS] = 0;
object_count[TRANSPARENT_PASS] = 0;
}
else
{
@ -2005,7 +2027,7 @@ void IrrDriver::RTTProvider::setupRTTScene(PtrVector<scene::IMesh, REF>& mesh,
m_camera->setPosition( core::vector3df(0.0, 20.0f, 70.0f) );
if (irr_driver->isGLSL())
m_camera->setUpVector( core::vector3df(0.0, -1.0, 0.0) );
m_camera->setUpVector( core::vector3df(0.0, 1.0, 0.0) );
else
m_camera->setUpVector( core::vector3df(0.0, 1.0, 0.0) );
m_camera->setTarget( core::vector3df(0, 10, 0.0f) );

View File

@ -63,6 +63,17 @@ class PostProcessing;
class LightNode;
class ShadowImportance;
enum STKRenderingPass
{
SOLID_NORMAL_AND_DEPTH_PASS,
SOLID_LIT_PASS,
TRANSPARENT_PASS,
GLOW_PASS,
DISPLACEMENT_PASS,
SHADOW_PASS,
PASS_COUNT,
};
/**
* \brief class that creates the irrLicht device and offers higher-level
* ways to manage the 3D scene
@ -102,6 +113,8 @@ private:
/** Matrixes used in several places stored here to avoid recomputation. */
core::matrix4 m_ViewMatrix, m_ProjMatrix, m_InvProjMatrix, m_ProjViewMatrix, m_InvProjViewMatrix;
std::vector<video::ITexture *> SkyboxTextures;
/** Flag to indicate if a resolution change is pending (which will be
* acted upon in the next update). None means no change, yes means
* change to new resolution and trigger confirmation dialog.
@ -152,7 +165,9 @@ private:
bool m_shadowviz;
bool m_lightviz;
bool m_distortviz;
/** Performance stats */
unsigned m_last_light_bucket_distance;
unsigned object_count[PASS_COUNT];
u32 m_renderpass;
u32 m_lensflare_query;
scene::IMeshSceneNode *m_sun_interposer;
@ -174,7 +189,7 @@ private:
std::vector<scene::ISceneNode *> m_background;
unsigned phase;
STKRenderingPass phase;
#ifdef DEBUG
/** Used to visualise skeletons. */
@ -196,6 +211,7 @@ private:
std::vector<GlowData>& glows,
const core::aabbox3df& cambox,
int cam);
void renderSkybox();
void renderLights(const core::aabbox3df& cambox,
scene::ICameraSceneNode * const camnode,
video::SOverrideMaterial &overridemat,
@ -208,8 +224,9 @@ public:
~IrrDriver();
void initDevice();
void reset();
void setPhase(unsigned);
unsigned getPhase() const;
void setPhase(STKRenderingPass);
STKRenderingPass getPhase() const;
void IncreaseObjectCount();
core::array<video::IRenderTarget> &getMainSetup();
void updateConfigIfRelevant();
void setAllMaterialFlags(scene::IMesh *mesh) const;
@ -243,9 +260,6 @@ public:
const video::SColor &color=video::SColor(128, 255, 255, 255));
scene::IMeshSceneNode*addMesh(scene::IMesh *mesh,
scene::ISceneNode *parent=NULL);
PerCameraNode *addPerCameraMesh(scene::IMesh* mesh,
scene::ICameraSceneNode* node,
scene::ISceneNode *parent = NULL);
PerCameraNode *addPerCameraNode(scene::ISceneNode* node,
scene::ICameraSceneNode* cam,
scene::ISceneNode *parent = NULL);
@ -259,6 +273,7 @@ public:
int vert_res, float texture_percent,
float sphere_percent);
scene::ISceneNode *addSkyBox(const std::vector<video::ITexture*> &texture_names);
void suppressSkyBox();
void removeNode(scene::ISceneNode *node);
void removeMeshFromCache(scene::IMesh *mesh);
void removeTexture(video::ITexture *t);
@ -417,6 +432,8 @@ public:
// ------------------------------------------------------------------------
void toggleLightViz() { m_lightviz = !m_lightviz; }
// ------------------------------------------------------------------------
bool getLightViz() { return m_lightviz; }
// ------------------------------------------------------------------------
bool getSSAOViz() { return m_ssaoviz; }
// ------------------------------------------------------------------------
void toggleShadowViz() { m_shadowviz = !m_shadowviz; }

View File

@ -66,8 +66,6 @@ public:
protected:
static core::aabbox3df box;
class ScreenQuad *sq;
//float m_radius;
float m_color[3];
float m_energy;

View File

@ -146,6 +146,7 @@ Material::Material(const XMLNode *node, int index, bool deprecated)
node->get("water-splash", &m_water_splash );
node->get("jump", &m_is_jump_texture );
node->get("has-gravity", &m_has_gravity );
if (m_collision_reaction != NORMAL)
{
@ -291,7 +292,7 @@ Material::Material(const XMLNode *node, int index, bool deprecated)
if (m_disable_z_write && !m_alpha_blending && !m_add)
{
Log::warn("material", "Disabling writes to z buffer only makes sense when compositing is blending or additive");
Log::warn("material", "Disabling writes to z buffer only makes sense when compositing is blending or additive (for %s)", m_texname.c_str());
m_disable_z_write = false;
}
@ -344,6 +345,10 @@ Material::Material(const XMLNode *node, int index, bool deprecated)
}
} // for i <node->getNumNodes()
if(m_has_gravity)
m_high_tire_adhesion = true;
install(/*is_full_path*/false);
} // Material
@ -410,6 +415,7 @@ void Material::init(unsigned int index)
m_is_heightmap = false;
m_water_splash = false;
m_is_jump_texture = false;
m_has_gravity = false;
for (int n=0; n<EMIT_KINDS_COUNT; n++)
{
@ -653,18 +659,14 @@ void Material::setMaterialProperties(video::SMaterial *m, scene::IMeshBuffer* m
}
if (!m_lighting && irr_driver->isGLSL() && !m_alpha_blending && !m_add)
{
// we abuse alpha blender a little here : in the shader-based pipeline,
// transparent objects are rendered after lighting has been applied.
// Therefore, pretending the object is transparent will have the effect
// of making it unaffected by lights
m_alpha_blending = true;
m_disable_z_write = false;
}
int modes = 0;
if (!m_lighting && irr_driver->isGLSL() && !m_alpha_blending && !m_add)
{
m->MaterialType = irr_driver->getShader(ES_OBJECT_UNLIT);
modes++;
}
if (m_alpha_testing)
{
m->MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF;

View File

@ -111,6 +111,11 @@ private:
* leaving it and being in the air. */
bool m_is_jump_texture;
/** True if driving on this texture should adjust the gravity of the kart
* to be along the normal of the triangle. This allows karts to drive e.g
* upside down. */
bool m_has_gravity;
/** Speed of the 'main' wave in the water shader. Only used if
m_graphical_effect == WATER_SHADER */
float m_water_shader_speed_1;
@ -312,6 +317,11 @@ public:
* jump animation. */
bool isJumpTexture() const { return m_is_jump_texture; }
// ------------------------------------------------------------------------
/** Returns true if this texture adjusts the gravity vector of the kart
* to be parallel to the normal of the triangle - which allows karts to
* e.g. drive upside down. */
bool hasGravity() const { return m_has_gravity; }
// ------------------------------------------------------------------------
/** Returns the zipper parametersfor the current material. */
void getZipperParameter(float *zipper_max_speed_increase,
float *zipper_duration,

View File

@ -28,7 +28,7 @@
#include "tracks/track.hpp"
#include "utils/constants.hpp"
#include "utils/helpers.hpp"
#include "graphics/gpuparticles.h"
#include "graphics/gpuparticles.hpp"
#include <SParticle.h>
#include <IParticleAffector.h>

View File

@ -164,12 +164,16 @@ ParticleKind::ParticleKind(const std::string file) : m_min_start_color(255,255,2
{
size->get("min", &m_min_size);
size->get("max", &m_max_size);
bool has_x = size->get("x-increase-factor", &m_scale_affector_factor_x) == 1;
bool has_y = size->get("y-increase-factor", &m_scale_affector_factor_y) == 1;
m_has_scale_affector = (has_x || has_y);
}
bool has_x = size->get("x-increase-factor", &m_scale_affector_factor_x)==1;
bool has_y = size->get("y-increase-factor", &m_scale_affector_factor_y)==1;
m_has_scale_affector = (has_x || has_y);
else
{
m_has_scale_affector = false;
}
//std::cout << "m_particle_size = " << m_particle_size << "\n";
//std::cout << "m_min_size = " << m_min_size << "\n";
//std::cout << "m_max_size = " << m_max_size << "\n";

View File

@ -57,7 +57,11 @@ PostProcessing::PostProcessing(IVideoDriver* video_driver)
io::IReadFile *areamap = irr_driver->getDevice()->getFileSystem()->
createMemoryReadFile((void *) AreaMap33, sizeof(AreaMap33),
"AreaMap33", false);
if (!areamap) Log::fatal("postprocessing", "Failed to load the areamap");
if (!areamap)
{
Log::fatal("postprocessing", "Failed to load the areamap");
return;
}
m_areamap = irr_driver->getVideoDriver()->getTexture(areamap);
areamap->drop();
@ -302,7 +306,7 @@ void renderColorLevel(ITexture *in)
glEnable(GL_DEPTH_TEST);
}
void PostProcessing::renderPointlight(ITexture *in, const std::vector<float> &positions, const std::vector<float> &colors, const std::vector<float> &energy)
void PostProcessing::renderPointlight(const std::vector<float> &positions, const std::vector<float> &colors, const std::vector<float> &energy)
{
glEnable(GL_BLEND);
glBlendEquation(GL_FUNC_ADD);
@ -312,18 +316,9 @@ void PostProcessing::renderPointlight(ITexture *in, const std::vector<float> &po
glUseProgram(FullScreenShader::PointLightShader::Program);
glBindVertexArray(FullScreenShader::PointLightShader::vao);
glUniform4fv(FullScreenShader::PointLightShader::uniform_center, 16, positions.data());
glUniform4fv(FullScreenShader::PointLightShader::uniform_col, 16, colors.data());
glUniform1fv(FullScreenShader::PointLightShader::uniform_energy, 16, energy.data());
glUniform1f(FullScreenShader::PointLightShader::uniform_spec, 200);
glUniformMatrix4fv(FullScreenShader::PointLightShader::uniform_invproj, 1, GL_FALSE, irr_driver->getInvProjMatrix().pointer());
glUniformMatrix4fv(FullScreenShader::PointLightShader::uniform_viewm, 1, GL_FALSE, irr_driver->getViewMatrix().pointer());
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, static_cast<irr::video::COpenGLTexture*>(in)->getOpenGLTextureName());
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glUniform1i(FullScreenShader::PointLightShader::uniform_ntex, 0);
setTexture(0, static_cast<irr::video::COpenGLTexture*>(irr_driver->getRTT(RTT_NORMAL_AND_DEPTH))->getOpenGLTextureName(), GL_NEAREST, GL_NEAREST);
setTexture(1, static_cast<irr::video::COpenGLFBOTexture*>(irr_driver->getRTT(RTT_NORMAL_AND_DEPTH))->DepthBufferTexture, GL_NEAREST, GL_NEAREST);
FullScreenShader::PointLightShader::setUniforms(irr_driver->getInvProjMatrix(), irr_driver->getViewMatrix(), positions, colors, energy, 200, 0, 1);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
glBindVertexArray(0);
@ -344,59 +339,13 @@ void PostProcessing::renderSunlight()
glUseProgram(FullScreenShader::SunLightShader::Program);
glBindVertexArray(FullScreenShader::SunLightShader::vao);
GLuint ntex_id = static_cast<irr::video::COpenGLTexture*>(irr_driver->getRTT(RTT_NORMAL_AND_DEPTH))->getOpenGLTextureName();
setTexture(0, ntex_id, GL_NEAREST, GL_NEAREST);
FullScreenShader::SunLightShader::setUniforms(cb->getPosition(), irr_driver->getInvProjMatrix(), cb->getRed(), cb->getGreen(), cb->getBlue(), 0);
setTexture(0, static_cast<irr::video::COpenGLTexture*>(irr_driver->getRTT(RTT_NORMAL_AND_DEPTH))->getOpenGLTextureName(), GL_NEAREST, GL_NEAREST);
setTexture(1, static_cast<irr::video::COpenGLFBOTexture*>(irr_driver->getRTT(RTT_NORMAL_AND_DEPTH))->DepthBufferTexture, GL_NEAREST, GL_NEAREST);
FullScreenShader::SunLightShader::setUniforms(cb->getPosition(), irr_driver->getInvProjMatrix(), cb->getRed(), cb->getGreen(), cb->getBlue(), 0, 1);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
glBindVertexArray(0);
}
void PostProcessing::renderLightbBlend(ITexture *diffuse, ITexture *specular, ITexture *ao, ITexture *specmap, bool debug)
{
const SColorf s = irr_driver->getSceneManager()->getAmbientLight();
glStencilFunc(GL_EQUAL, 1, ~0);
glEnable(GL_STENCIL_TEST);
glEnable(GL_BLEND);
glBlendEquation(GL_FUNC_ADD);
if (debug)
glBlendFunc(GL_ONE, GL_ZERO);
else
glBlendFunc(GL_DST_COLOR, GL_ZERO);
glDisable(GL_DEPTH_TEST);
glUseProgram(FullScreenShader::LightBlendShader::Program);
glBindVertexArray(FullScreenShader::LightBlendShader::vao);
glUniform3f(FullScreenShader::LightBlendShader::uniform_ambient, s.r, s.g, s.b);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, static_cast<irr::video::COpenGLTexture*>(diffuse)->getOpenGLTextureName());
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glUniform1i(FullScreenShader::LightBlendShader::uniform_diffuse, 0);
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, static_cast<irr::video::COpenGLTexture*>(specular)->getOpenGLTextureName());
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glUniform1i(FullScreenShader::LightBlendShader::uniform_specular, 1);
glActiveTexture(GL_TEXTURE2);
glBindTexture(GL_TEXTURE_2D, static_cast<irr::video::COpenGLTexture*>(ao)->getOpenGLTextureName());
glUniform1i(FullScreenShader::LightBlendShader::uniform_ambient_occlusion, 2);
glActiveTexture(GL_TEXTURE3);
glBindTexture(GL_TEXTURE_2D, static_cast<irr::video::COpenGLTexture*>(specmap)->getOpenGLTextureName());
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glUniform1i(FullScreenShader::LightBlendShader::uniform_specular_map, 3);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
glBindVertexArray(0);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
glEnable(GL_DEPTH_TEST);
glDisable(GL_BLEND);
glDisable(GL_STENCIL_TEST);
}
void PostProcessing::renderGaussian3Blur(video::ITexture *in, video::ITexture *temprtt, float inv_width, float inv_height)
{
@ -526,30 +475,18 @@ void PostProcessing::renderSSAO(const core::matrix4 &invprojm, const core::matri
{
glDisable(GL_DEPTH_TEST);
glDisable(GL_BLEND);
glDisable(GL_ALPHA_TEST);
if (!noise_tex)
noise_tex = irr_driver->getTexture(file_manager->getAsset("textures/noise.png").c_str());
glUseProgram(FullScreenShader::SSAOShader::Program);
glBindVertexArray(FullScreenShader::SSAOShader::vao);
glUniformMatrix4fv(FullScreenShader::SSAOShader::uniform_invprojm, 1, GL_FALSE, invprojm.pointer());
glUniformMatrix4fv(FullScreenShader::SSAOShader::uniform_projm, 1, GL_FALSE, projm.pointer());
glUniform4fv(FullScreenShader::SSAOShader::uniform_samplePoints, 16, FullScreenShader::SSAOShader::SSAOSamples);
setTexture(0, static_cast<irr::video::COpenGLTexture*>(irr_driver->getRTT(RTT_NORMAL_AND_DEPTH))->getOpenGLTextureName(), GL_NEAREST, GL_NEAREST);
setTexture(1, static_cast<irr::video::COpenGLFBOTexture*>(irr_driver->getRTT(RTT_NORMAL_AND_DEPTH))->DepthBufferTexture, GL_LINEAR, GL_LINEAR);
setTexture(2, static_cast<irr::video::COpenGLTexture*>(noise_tex)->getOpenGLTextureName(), GL_NEAREST, GL_NEAREST);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, static_cast<irr::video::COpenGLTexture*>(irr_driver->getRTT(RTT_NORMAL_AND_DEPTH))->getOpenGLTextureName());
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glUniform1i(FullScreenShader::SSAOShader::uniform_normals_and_depth, 0);
if (!noise_tex)
noise_tex = irr_driver->getTexture(file_manager->getAsset("textures/tarmac.jpg").c_str());
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, static_cast<irr::video::COpenGLTexture*>(noise_tex)->getOpenGLTextureName());
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glUniform1i(FullScreenShader::SSAOShader::uniform_noise_texture, 1);
FullScreenShader::SSAOShader::setUniforms(projm, invprojm, 0, 1, 2);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
glBindVertexArray(0);
@ -558,7 +495,7 @@ void PostProcessing::renderSSAO(const core::matrix4 &invprojm, const core::matri
glEnable(GL_DEPTH_TEST);
}
void PostProcessing::renderFog(const core::vector3df &campos, const core::matrix4 &ipvmat)
void PostProcessing::renderFog(const core::matrix4 &ipvmat)
{
irr_driver->getVideoDriver()->setRenderTarget(irr_driver->getRTT(RTT_COLOR), false, false);
const Track * const track = World::getWorld()->getTrack();
@ -571,9 +508,9 @@ void PostProcessing::renderFog(const core::vector3df &campos, const core::matrix
const float end = track->getFogEnd();
const SColor tmpcol = track->getFogColor();
const float col[3] = { tmpcol.getRed() / 255.0f,
core::vector3df col( tmpcol.getRed() / 255.0f,
tmpcol.getGreen() / 255.0f,
tmpcol.getBlue() / 255.0f };
tmpcol.getBlue() / 255.0f );
glDisable(GL_DEPTH_TEST);
glEnable(GL_BLEND);
@ -583,17 +520,8 @@ void PostProcessing::renderFog(const core::vector3df &campos, const core::matrix
glUseProgram(FullScreenShader::FogShader::Program);
glBindVertexArray(FullScreenShader::FogShader::vao);
glUniform1f(FullScreenShader::FogShader::uniform_fogmax, fogmax);
glUniform1f(FullScreenShader::FogShader::uniform_startH, startH);
glUniform1f(FullScreenShader::FogShader::uniform_endH, endH);
glUniform1f(FullScreenShader::FogShader::uniform_start, start);
glUniform1f(FullScreenShader::FogShader::uniform_end, end);
glUniform3f(FullScreenShader::FogShader::uniform_col, col[0], col[1], col[2]);
glUniform3f(FullScreenShader::FogShader::uniform_campos, campos.X, campos.Y, campos.Z);
glUniformMatrix4fv(FullScreenShader::FogShader::uniform_ipvmat, 1, GL_FALSE, ipvmat.pointer());
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, static_cast<irr::video::COpenGLTexture*>(irr_driver->getRTT(RTT_NORMAL_AND_DEPTH))->getOpenGLTextureName());
glUniform1i(FullScreenShader::FogShader::uniform_tex, 0);
setTexture(0, static_cast<irr::video::COpenGLFBOTexture*>(irr_driver->getRTT(RTT_NORMAL_AND_DEPTH))->DepthBufferTexture, GL_NEAREST, GL_NEAREST);
FullScreenShader::FogShader::setUniforms(ipvmat, fogmax, startH, endH, start, end, col, 0);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
glBindVertexArray(0);

View File

@ -73,12 +73,10 @@ public:
void update(float dt);
/** Generate diffuse and specular map */
void renderPointlight(video::ITexture *in, const std::vector<float> &positions, const std::vector<float> &colors, const std::vector<float> &energy);
void renderPointlight(const std::vector<float> &positions, const std::vector<float> &colors, const std::vector<float> &energy);
void renderSunlight();
/** Blend all light related map */
void renderLightbBlend(video::ITexture *diffuse, video::ITexture *specular, video::ITexture *ao, video::ITexture *specmap, bool debug);
void renderFog(const core::vector3df &campos, const core::matrix4 &ipvmat);
void renderFog(const core::matrix4 &ipvmat);
void renderSSAO(const core::matrix4 &invprojm, const core::matrix4 &projm);
/** Blur the in texture */

View File

@ -20,7 +20,7 @@
#include "audio/sfx_manager.hpp"
#include "graphics/camera.hpp"
#include "graphics/glwrap.hpp"
#include "graphics/gpuparticles.h"
#include "graphics/gpuparticles.hpp"
#include "graphics/irr_driver.hpp"
#include "graphics/material_manager.hpp"
#include "graphics/material.hpp"
@ -42,7 +42,7 @@ using namespace core;
// The rain manager
Rain::Rain(Camera *camera, irr::scene::ISceneNode* parent)
Rain::Rain(Camera *camera, irr::scene::ISceneNode* parent) : m_thunder_sound(0)
{
m_lightning = camera->getIndex()==0;

View File

@ -165,7 +165,7 @@ void IrrDriver::renderGLSL(float dt)
rg->preRenderCallback(camera); // adjusts start referee
const u32 bgnodes = m_background.size();
if (bgnodes)
/* if (bgnodes)
{
// If there are background nodes (3d skybox), draw them now.
m_video_driver->setRenderTarget(m_rtts->getRTT(RTT_COLOR), false, false);
@ -187,21 +187,19 @@ void IrrDriver::renderGLSL(float dt)
overridemat = prev;
m_video_driver->setRenderTarget(m_rtts->getRTT(RTT_COLOR), false, true);
}
}*/
// Fire up the MRT
m_video_driver->setRenderTarget(m_mrt, false, false);
irr_driver->getVideoDriver()->setRenderTarget(irr_driver->getRTT(RTT_NORMAL_AND_DEPTH), false, false);
PROFILER_PUSH_CPU_MARKER("- Solid Pass 1", 0xFF, 0x00, 0x00);
m_renderpass = scene::ESNRP_CAMERA | scene::ESNRP_SOLID;
irr_driver->setPhase(0);
glClear(GL_STENCIL_BUFFER_BIT);
glStencilFunc(GL_ALWAYS, 1, ~0);
glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);
glEnable(GL_STENCIL_TEST);
glDepthFunc(GL_LEQUAL);
glEnable(GL_DEPTH_TEST);
glDisable(GL_ALPHA_TEST);
glDepthMask(GL_TRUE);
glDisable(GL_BLEND);
irr_driver->setPhase(SOLID_NORMAL_AND_DEPTH_PASS);
m_scene_manager->drawAll(m_renderpass);
glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
glDisable(GL_STENCIL_TEST);
irr_driver->setProjMatrix(irr_driver->getVideoDriver()->getTransform(video::ETS_PROJECTION));
irr_driver->setViewMatrix(irr_driver->getVideoDriver()->getTransform(video::ETS_VIEW));
irr_driver->genProjViewMatrix();
@ -224,50 +222,53 @@ void IrrDriver::renderGLSL(float dt)
}
PROFILER_PUSH_CPU_MARKER("- Light", 0xFF, 0x00, 0x00);
PROFILER_PUSH_CPU_MARKER("- Light", 0x00, 0xFF, 0x00);
// Lights
renderLights(cambox, camnode, overridemat, cam, dt);
PROFILER_POP_CPU_MARKER();
PROFILER_PUSH_CPU_MARKER("- Solid Pass 2", 0xFF, 0x00, 0x00);
irr_driver->setPhase(1);
PROFILER_PUSH_CPU_MARKER("- Solid Pass 2", 0x00, 0x00, 0xFF);
irr_driver->setPhase(SOLID_LIT_PASS);
glEnable(GL_DEPTH_TEST);
glDisable(GL_ALPHA_TEST);
glDepthMask(GL_FALSE);
glDisable(GL_BLEND);
m_renderpass = scene::ESNRP_CAMERA | scene::ESNRP_SOLID;
glStencilFunc(GL_EQUAL, 0, ~0);
glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
glEnable(GL_STENCIL_TEST);
m_scene_manager->drawAll(m_renderpass);
glDisable(GL_STENCIL_TEST);
PROFILER_POP_CPU_MARKER();
PROFILER_PUSH_CPU_MARKER("- Glow", 0xFF, 0x00, 0x00);
if (World::getWorld()->getTrack()->isFogEnabled())
{
PROFILER_PUSH_CPU_MARKER("- Fog", 0xFF, 0x00, 0x00);
m_post_processing->renderFog(irr_driver->getInvProjMatrix());
PROFILER_POP_CPU_MARKER();
}
PROFILER_PUSH_CPU_MARKER("- Glow", 0xFF, 0xFF, 0x00);
// Render anything glowing.
if (!m_mipviz && !m_wireframe)
{
irr_driver->setPhase(2);
irr_driver->setPhase(GLOW_PASS);
renderGlow(overridemat, glows, cambox, cam);
} // end glow
PROFILER_POP_CPU_MARKER();
if (!bgnodes)
{
PROFILER_PUSH_CPU_MARKER("- Skybox", 0xFF, 0x00, 0x00);
if (!SkyboxTextures.empty())
{
PROFILER_PUSH_CPU_MARKER("- Skybox", 0xFF, 0x00, 0xFF);
renderSkybox();
PROFILER_POP_CPU_MARKER();
}
// If there are no BG nodes, it's more efficient to do the skybox here.
m_renderpass = scene::ESNRP_SKY_BOX;
m_scene_manager->drawAll(m_renderpass);
PROFILER_POP_CPU_MARKER();
}
PROFILER_PUSH_CPU_MARKER("- Lensflare/godray", 0xFF, 0x00, 0x00);
PROFILER_PUSH_CPU_MARKER("- Lensflare/godray", 0x00, 0xFF, 0xFF);
// Is the lens flare enabled & visible? Check last frame's query.
const bool hasflare = World::getWorld()->getTrack()->hasLensFlare();
const bool hasgodrays = World::getWorld()->getTrack()->hasGodRays();
if (hasflare | hasgodrays)
if (hasflare || hasgodrays)
{
irr::video::COpenGLDriver* gl_driver = (irr::video::COpenGLDriver*)m_device->getVideoDriver();
@ -292,27 +293,30 @@ void IrrDriver::renderGLSL(float dt)
}
PROFILER_POP_CPU_MARKER();
// We need to re-render camera due to the per-cam-node hack.
PROFILER_PUSH_CPU_MARKER("- Transparent Pass", 0xFF, 0x00, 0x00);
irr_driver->setPhase(3);
irr_driver->setPhase(TRANSPARENT_PASS);
m_renderpass = scene::ESNRP_CAMERA | scene::ESNRP_TRANSPARENT;
glEnable(GL_DEPTH_TEST);
glDisable(GL_ALPHA_TEST);
glDepthMask(GL_FALSE);
glEnable(GL_BLEND);
glBlendEquation(GL_FUNC_ADD);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glDisable(GL_CULL_FACE);
m_scene_manager->drawAll(m_renderpass);
PROFILER_POP_CPU_MARKER();
PROFILER_PUSH_CPU_MARKER("- Particles", 0xFF, 0x00, 0x00);
PROFILER_PUSH_CPU_MARKER("- Particles", 0xFF, 0xFF, 0x00);
m_renderpass = scene::ESNRP_CAMERA | scene::ESNRP_TRANSPARENT_EFFECT;
glDepthMask(GL_FALSE);
glDisable(GL_CULL_FACE);
glEnable(GL_BLEND);
glBlendEquation(GL_FUNC_ADD);
m_scene_manager->drawAll(m_renderpass);
PROFILER_POP_CPU_MARKER();
if (World::getWorld()->getTrack()->isFogEnabled())
{
PROFILER_PUSH_CPU_MARKER("- Fog", 0xFF, 0x00, 0x00);
m_post_processing->renderFog(camnode->getAbsolutePosition(), irr_driver->getInvProjViewMatrix());
PROFILER_POP_CPU_MARKER();
}
PROFILER_PUSH_CPU_MARKER("- Displacement", 0xFF, 0x00, 0x00);
PROFILER_PUSH_CPU_MARKER("- Displacement", 0x00, 0x00, 0xFF);
// Handle displacing nodes, if any
const u32 displacingcount = m_displacing.size();
if (displacingcount)
@ -339,7 +343,7 @@ void IrrDriver::renderGLSL(float dt)
World::getWorld()->getPhysics()->draw();
} // for i<world->getNumKarts()
PROFILER_PUSH_CPU_MARKER("Postprocessing", 0xFF, 0x00, 0x00);
PROFILER_PUSH_CPU_MARKER("Postprocessing", 0xFF, 0xFF, 0x00);
// Render the post-processed scene
m_post_processing->render();
PROFILER_POP_CPU_MARKER();
@ -361,8 +365,10 @@ void IrrDriver::renderGLSL(float dt)
PROFILER_POP_CPU_MARKER();
} // for i<getNumKarts
PROFILER_PUSH_CPU_MARKER("GUIEngine", 0x75, 0x75, 0x75);
// Either render the gui, or the global elements of the race gui.
GUIEngine::render(dt);
PROFILER_POP_CPU_MARKER();
// Render the profiler
if(UserConfigParams::m_profiler_enabled)
@ -375,7 +381,9 @@ void IrrDriver::renderGLSL(float dt)
drawDebugMeshes();
#endif
PROFILER_PUSH_CPU_MARKER("EndSccene", 0x45, 0x75, 0x45);
m_video_driver->endScene();
PROFILER_POP_CPU_MARKER();
getPostProcessing()->update(dt);
}
@ -632,10 +640,6 @@ void IrrDriver::renderGlow(video::SOverrideMaterial &overridemat,
const u32 glowcount = glows.size();
ColorizeProvider * const cb = (ColorizeProvider *) m_shaders->m_callbacks[ES_COLORIZE];
GlowProvider * const glowcb = (GlowProvider *) m_shaders->m_callbacks[ES_GLOW];
glowcb->setResolution(UserConfigParams::m_width,
UserConfigParams::m_height);
/* overridemat.Material.MaterialType = m_shaders->getShader(ES_COLORIZE);
overridemat.EnableFlags = video::EMF_MATERIAL_TYPE;
overridemat.EnablePasses = scene::ESNRP_SOLID;
@ -645,6 +649,11 @@ void IrrDriver::renderGlow(video::SOverrideMaterial &overridemat,
glStencilFunc(GL_ALWAYS, 1, ~0);
glEnable(GL_STENCIL_TEST);
glEnable(GL_DEPTH_TEST);
glDisable(GL_ALPHA_TEST);
glDepthMask(GL_FALSE);
glDisable(GL_BLEND);
for (u32 i = 0; i < glowcount; i++)
{
const GlowData &dat = glows[i];
@ -803,7 +812,7 @@ void IrrDriver::renderLights(const core::aabbox3df& cambox,
accumulatedLightColor.push_back(0.);
accumulatedLightEnergy.push_back(0.);
}
m_post_processing->renderPointlight(irr_driver->getRTT(RTT_NORMAL_AND_DEPTH) , accumulatedLightPos, accumulatedLightColor, accumulatedLightEnergy);
m_post_processing->renderPointlight(accumulatedLightPos, accumulatedLightColor, accumulatedLightEnergy);
// Handle SSAO
m_video_driver->setRenderTarget(irr_driver->getRTT(RTT_SSAO), true, false,
SColor(255, 255, 255, 255));
@ -818,8 +827,105 @@ void IrrDriver::renderLights(const core::aabbox3df& cambox,
m_post_processing->renderGaussian6Blur(irr_driver->getRTT(RTT_SSAO), irr_driver->getRTT(RTT_TMP4), 1.f / UserConfigParams::m_width, 1.f / UserConfigParams::m_height);
m_video_driver->setRenderTarget(m_rtts->getRTT(RTT_COLOR), false, false);
if (!m_mipviz)
m_post_processing->renderLightbBlend(m_rtts->getRTT(RTT_TMP1), m_rtts->getRTT(RTT_TMP2), m_rtts->getRTT(RTT_SSAO), m_rtts->getRTT(RTT_SPECULARMAP), m_lightviz);
}
static GLuint cubevao = 0;
static GLuint cubevbo;
static GLuint cubeidx;
static void createcubevao()
{
// From CSkyBoxSceneNode. Not optimal at all
float corners[] =
{
// top side
1., 1., -1., 1., 1.,
1., 1., 1., 0., 1.,
-1., 1., 1., 0., 0.,
-1., 1., -1., 1., 0.,
// Bottom side
1., -1., 1., 0., 0.,
1., -1., -1., 1., 0.,
-1., -1., -1., 1., 1.,
-1., -1., 1., 0., 1.,
// right side
1., -1, -1, 1., 1.,
1., -1, 1, 0., 1.,
1., 1., 1., 0., 0.,
1., 1., -1., 1., 0.,
// left side
-1., -1., 1., 1., 1.,
-1., -1., -1., 0., 1.,
-1., 1., -1., 0., 0.,
-1., 1., 1., 1., 0.,
// back side
-1., -1., -1., 1., 1.,
1., -1, -1., 0., 1.,
1, 1, -1., 0., 0.,
-1, 1, -1., 1., 0.,
// front side
1., -1., 1., 1., 1.,
-1., -1., 1., 0., 1.,
-1, 1., 1., 0., 0.,
1., 1., 1., 1., 0.,
};
int indices[] = {
0, 1, 2, 2, 3, 0,
4, 5, 6, 6, 7, 4,
8, 9, 10, 10, 11, 8,
12, 13, 14, 14, 15, 12,
16, 17, 18, 18, 19, 16,
20, 21, 22, 22, 23, 20
};
glGenBuffers(1, &cubevbo);
glGenBuffers(1, &cubeidx);
glGenVertexArrays(1, &cubevao);
glBindVertexArray(cubevao);
glBindBuffer(GL_ARRAY_BUFFER, cubevbo);
glBufferData(GL_ARRAY_BUFFER, 6 * 5 * 4 * sizeof(float), corners, GL_STATIC_DRAW);
glEnableVertexAttribArray(MeshShader::ObjectUnlitShader::attrib_position);
glEnableVertexAttribArray(MeshShader::ObjectUnlitShader::attrib_texcoord);
glVertexAttribPointer(MeshShader::ObjectUnlitShader::attrib_position, 3, GL_FLOAT, GL_FALSE, 5 * sizeof(float), 0);
glVertexAttribPointer(MeshShader::ObjectUnlitShader::attrib_texcoord, 2, GL_FLOAT, GL_FALSE, 5 * sizeof(float), (GLvoid *)(3 * sizeof(float)));
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, cubeidx);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, 6 * 6 * sizeof(int), indices, GL_STATIC_DRAW);
}
void IrrDriver::renderSkybox()
{
scene::ICameraSceneNode *camera = m_scene_manager->getActiveCamera();
if (!cubevao)
createcubevao();
glBindVertexArray(cubevao);
glDisable(GL_CULL_FACE);
assert(SkyboxTextures.size() == 6);
core::matrix4 transform = irr_driver->getProjViewMatrix();
core::matrix4 translate;
translate.setTranslation(camera->getAbsolutePosition());
// Draw the sky box between the near and far clip plane
const f32 viewDistance = (camera->getNearValue() + camera->getFarValue()) * 0.5f;
core::matrix4 scale;
scale.setScale(core::vector3df(viewDistance, viewDistance, viewDistance));
transform *= translate * scale;
for (unsigned i = 0; i < 6; i++)
{
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, static_cast<irr::video::COpenGLTexture*>(SkyboxTextures[i])->getOpenGLTextureName());
glUseProgram(MeshShader::ObjectUnlitShader::Program);
MeshShader::ObjectUnlitShader::setUniforms(transform, 0);
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, (GLvoid*) (6 * i * sizeof(int)));
}
glBindVertexArray(0);
}
// ----------------------------------------------------------------------------
@ -847,7 +953,12 @@ void IrrDriver::renderDisplacement(video::SOverrideMaterial &overridemat,
cb->update();
const int displacingcount = m_displacing.size();
irr_driver->setPhase(4);
irr_driver->setPhase(DISPLACEMENT_PASS);
glEnable(GL_DEPTH_TEST);
glDisable(GL_ALPHA_TEST);
glDepthMask(GL_FALSE);
glDisable(GL_BLEND);
for (int i = 0; i < displacingcount; i++)
{

View File

@ -67,7 +67,7 @@ RTT::RTT()
rtts[RTT_TMP2] = drv->addRenderTargetTexture(res, "rtt.tmp2", ECF_A8R8G8B8, stencil);
rtts[RTT_TMP3] = drv->addRenderTargetTexture(res, "rtt.tmp3", ECF_A8R8G8B8, stencil);
rtts[RTT_TMP4] = drv->addRenderTargetTexture(res, "rtt.tmp4", ECF_R8, stencil);
rtts[RTT_NORMAL_AND_DEPTH] = drv->addRenderTargetTexture(res, "rtt.normal_and_depth", ECF_A32B32G32R32F, stencil);
rtts[RTT_NORMAL_AND_DEPTH] = drv->addRenderTargetTexture(res, "rtt.normal_and_depth", ECF_G16R16F, stencil);
rtts[RTT_COLOR] = drv->addRenderTargetTexture(res, "rtt.color", ECF_A16B16G16R16F, stencil);
rtts[RTT_SPECULARMAP] = drv->addRenderTargetTexture(res, "rtt.specularmap", ECF_R8, stencil);

View File

@ -40,8 +40,6 @@ Shaders::Shaders()
m_callbacks[ES_GAUSSIAN3V] = m_callbacks[ES_GAUSSIAN3H] = new GaussianBlurProvider();
m_callbacks[ES_MIPVIZ] = new MipVizProvider();
m_callbacks[ES_COLORIZE] = new ColorizeProvider();
m_callbacks[ES_GLOW] = new GlowProvider();
m_callbacks[ES_OBJECTPASS] = new ObjectPassProvider();
m_callbacks[ES_SUNLIGHT] = new SunLightProvider();
m_callbacks[ES_MLAA_COLOR1] = new MLAAColor1Provider();
m_callbacks[ES_MLAA_BLEND2] = new MLAABlend2Provider();
@ -61,11 +59,10 @@ Shaders::Shaders()
loadShaders();
}
GLuint quad_vbo = 0;
GLuint quad_vbo;
static void initQuadVBO()
{
initGL();
const float quad_vertex[] = {
-1., -1., 0., 0., // UpperLeft
-1., 1., 0., 1., // LowerLeft
@ -78,6 +75,22 @@ static void initQuadVBO()
glBindBuffer(GL_ARRAY_BUFFER, 0);
}
// It should be possible to merge it with previous one...
GLuint quad_buffer;
static void initQuadBuffer()
{
const float quad_vertex[] = {
-1., -1., -1., 1., // UpperLeft
-1., 1., -1., -1., // LowerLeft
1., -1., 1., 1., // UpperRight
1., 1., 1., -1., // LowerRight
};
glGenBuffers(1, &quad_buffer);
glBindBuffer(GL_ARRAY_BUFFER, quad_buffer);
glBufferData(GL_ARRAY_BUFFER, 16 * sizeof(float), quad_vertex, GL_STATIC_DRAW);
}
void Shaders::loadShaders()
{
const std::string &dir = file_manager->getAsset(FileManager::SHADER, "");
@ -93,25 +106,20 @@ void Shaders::loadShaders()
memcpy(saved_shaders, m_shaders, sizeof(m_shaders));
// Ok, go
m_shaders[ES_NORMAL_MAP] = glslmat(dir + "normalmap.vert", dir + "normalmap.frag",
m_callbacks[ES_NORMAL_MAP], EMT_SOLID_2_LAYER);
m_shaders[ES_NORMAL_MAP_LIGHTMAP] = glslmat(dir + "normalmap.vert", dir + "normalmap.frag",
m_callbacks[ES_NORMAL_MAP_LIGHTMAP], EMT_SOLID_2_LAYER);
m_shaders[ES_NORMAL_MAP] = glsl_noinput(dir + "normalmap.vert", dir + "normalmap.frag");
m_shaders[ES_NORMAL_MAP_LIGHTMAP] = glsl_noinput(dir + "normalmap.vert", dir + "normalmap.frag");
m_shaders[ES_SKYBOX] = glslmat(dir + "skybox.vert", dir + "skybox.frag",
m_callbacks[ES_SKYBOX], EMT_TRANSPARENT_ALPHA_CHANNEL);
m_shaders[ES_SPLATTING] = glslmat(dir + "splatting.vert", dir + "splatting.frag",
m_callbacks[ES_SPLATTING], EMT_SOLID);
m_shaders[ES_SPLATTING] = glsl_noinput(dir + "splatting.vert", dir + "splatting.frag");
m_shaders[ES_WATER] = glslmat(dir + "water.vert", dir + "water.frag",
m_callbacks[ES_WATER], EMT_TRANSPARENT_ALPHA_CHANNEL);
m_shaders[ES_WATER_SURFACE] = glsl(dir + "water.vert", dir + "pass.frag",
m_callbacks[ES_WATER]);
m_shaders[ES_SPHERE_MAP] = glslmat(dir + "objectpass.vert", dir + "objectpass_spheremap.frag",
m_callbacks[ES_OBJECTPASS], EMT_SOLID);
m_shaders[ES_SPHERE_MAP] = glsl_noinput(dir + "objectpass.vert", dir + "objectpass_spheremap.frag");
m_shaders[ES_GRASS] = glslmat(dir + "grass.vert", dir + "grass.frag",
m_callbacks[ES_GRASS], EMT_TRANSPARENT_ALPHA_CHANNEL);
@ -140,20 +148,13 @@ void Shaders::loadShaders()
m_shaders[ES_COLORIZE_REF] = glslmat(std::string(""), dir + "colorize_ref.frag",
m_callbacks[ES_COLORIZE], EMT_SOLID);
m_shaders[ES_GLOW] = glslmat(std::string(""), dir + "glow.frag",
m_callbacks[ES_GLOW], EMT_TRANSPARENT_ALPHA_CHANNEL);
m_shaders[ES_OBJECTPASS] = glsl_noinput(dir + "objectpass.vert", dir + "objectpass.frag");
m_shaders[ES_OBJECT_UNLIT] = glsl_noinput(dir + "objectpass.vert", dir + "objectpass.frag");
m_shaders[ES_OBJECTPASS_REF] = glsl_noinput(dir + "objectpass.vert", dir + "objectpass_ref.frag");
m_shaders[ES_OBJECTPASS_RIMLIT] = glsl_noinput(dir + "objectpass_rimlit.vert", dir + "objectpass_rimlit.frag");
m_shaders[ES_OBJECTPASS] = glslmat(dir + "objectpass.vert", dir + "objectpass.frag",
m_callbacks[ES_OBJECTPASS], EMT_SOLID);
m_shaders[ES_OBJECTPASS_REF] = glslmat(dir + "objectpass.vert", dir + "objectpass_ref.frag",
m_callbacks[ES_OBJECTPASS], EMT_SOLID);
m_shaders[ES_OBJECTPASS_RIMLIT] = glslmat(dir + "objectpass_rimlit.vert", dir + "objectpass_rimlit.frag",
m_callbacks[ES_OBJECTPASS], EMT_SOLID);
m_shaders[ES_SUNLIGHT] = glslmat(std::string(""), dir + "sunlight.frag",
m_callbacks[ES_SUNLIGHT], EMT_SOLID);
m_shaders[ES_SUNLIGHT_SHADOW] = glslmat(dir + "pass.vert", dir + "sunlightshadow.frag",
m_callbacks[ES_SUNLIGHT], EMT_SOLID);
m_shaders[ES_SUNLIGHT] = glsl_noinput(std::string(""), dir + "sunlight.frag");
m_shaders[ES_SUNLIGHT_SHADOW] = glsl_noinput(dir + "pass.vert", dir + "sunlightshadow.frag");
m_shaders[ES_MLAA_COLOR1] = glsl(dir + "mlaa_offset.vert", dir + "mlaa_color1.frag",
m_callbacks[ES_MLAA_COLOR1]);
@ -222,6 +223,7 @@ void Shaders::loadShaders()
initGL();
initQuadVBO();
initQuadBuffer();
FullScreenShader::BloomBlendShader::init();
FullScreenShader::BloomShader::init();
FullScreenShader::ColorLevelShader::init();
@ -231,7 +233,6 @@ void Shaders::loadShaders()
FullScreenShader::Gaussian6HBlurShader::init();
FullScreenShader::Gaussian6VBlurShader::init();
FullScreenShader::GlowShader::init();
FullScreenShader::LightBlendShader::init();
FullScreenShader::PassThroughShader::init();
FullScreenShader::PointLightShader::init();
FullScreenShader::PPDisplaceShader::init();
@ -242,19 +243,27 @@ void Shaders::loadShaders()
MeshShader::ObjectPass1Shader::init();
MeshShader::ObjectRefPass1Shader::init();
MeshShader::ObjectPass2Shader::init();
MeshShader::DetailledObjectPass2Shader::init();
MeshShader::ObjectRimLimitShader::init();
MeshShader::UntexturedObjectShader::init();
MeshShader::ObjectRefPass2Shader::init();
MeshShader::ObjectUnlitShader::init();
MeshShader::SphereMapShader::init();
MeshShader::SplattingShader::init();
MeshShader::GrassPass1Shader::init();
MeshShader::GrassPass2Shader::init();
MeshShader::BubbleShader::init();
MeshShader::TransparentShader::init();
MeshShader::TransparentFogShader::init();
MeshShader::BillboardShader::init();
MeshShader::DisplaceShader::init();
ParticleShader::FlipParticleRender::init();
ParticleShader::HeightmapSimulationShader::init();
ParticleShader::SimpleParticleRender::init();
ParticleShader::SimpleSimulationShader::init();
UIShader::ColoredRectShader::init();
UIShader::ColoredTextureRectShader::init();
UIShader::TextureRectShader::init();
}
Shaders::~Shaders()
@ -369,6 +378,111 @@ namespace MeshShader
glUniform3f(uniform_ambient, s.r, s.g, s.b);
}
GLuint DetailledObjectPass2Shader::Program;
GLuint DetailledObjectPass2Shader::attrib_position;
GLuint DetailledObjectPass2Shader::attrib_texcoord;
GLuint DetailledObjectPass2Shader::attrib_second_texcoord;
GLuint DetailledObjectPass2Shader::uniform_MVP;
GLuint DetailledObjectPass2Shader::uniform_Albedo;
GLuint DetailledObjectPass2Shader::uniform_Detail;
GLuint DetailledObjectPass2Shader::uniform_DiffuseMap;
GLuint DetailledObjectPass2Shader::uniform_SpecularMap;
GLuint DetailledObjectPass2Shader::uniform_SSAO;
GLuint DetailledObjectPass2Shader::uniform_screen;
GLuint DetailledObjectPass2Shader::uniform_ambient;
void DetailledObjectPass2Shader::init()
{
Program = LoadProgram(file_manager->getAsset("shaders/object_pass2.vert").c_str(), file_manager->getAsset("shaders/detailledobject_pass2.frag").c_str());
attrib_position = glGetAttribLocation(Program, "Position");
attrib_texcoord = glGetAttribLocation(Program, "Texcoord");
attrib_second_texcoord = glGetAttribLocation(Program, "SecondTexcoord");
uniform_MVP = glGetUniformLocation(Program, "ModelViewProjectionMatrix");
uniform_Albedo = glGetUniformLocation(Program, "Albedo");
uniform_Detail = glGetUniformLocation(Program, "Detail");
uniform_DiffuseMap = glGetUniformLocation(Program, "DiffuseMap");
uniform_SpecularMap = glGetUniformLocation(Program, "SpecularMap");
uniform_SSAO = glGetUniformLocation(Program, "SSAO");
uniform_screen = glGetUniformLocation(Program, "screen");
uniform_ambient = glGetUniformLocation(Program, "ambient");
}
void DetailledObjectPass2Shader::setUniforms(const core::matrix4 &ModelViewProjectionMatrix, unsigned TU_Albedo, unsigned TU_detail, unsigned TU_DiffuseMap, unsigned TU_SpecularMap, unsigned TU_SSAO)
{
glUniformMatrix4fv(uniform_MVP, 1, GL_FALSE, ModelViewProjectionMatrix.pointer());
glUniform1i(uniform_Albedo, TU_Albedo);
glUniform1i(uniform_Detail, TU_detail);
glUniform1i(uniform_DiffuseMap, TU_DiffuseMap);
glUniform1i(uniform_SpecularMap, TU_SpecularMap);
glUniform1i(uniform_SSAO, TU_SSAO);
glUniform2f(uniform_screen, UserConfigParams::m_width, UserConfigParams::m_height);
const video::SColorf s = irr_driver->getSceneManager()->getAmbientLight();
glUniform3f(uniform_ambient, s.r, s.g, s.b);
}
GLuint ObjectUnlitShader::Program;
GLuint ObjectUnlitShader::attrib_position;
GLuint ObjectUnlitShader::attrib_texcoord;
GLuint ObjectUnlitShader::uniform_MVP;
GLuint ObjectUnlitShader::uniform_tex;
void ObjectUnlitShader::init()
{
Program = LoadProgram(file_manager->getAsset("shaders/object_pass2.vert").c_str(), file_manager->getAsset("shaders/object_unlit.frag").c_str());
attrib_position = glGetAttribLocation(Program, "Position");
attrib_texcoord = glGetAttribLocation(Program, "Texcoord");
uniform_MVP = glGetUniformLocation(Program, "ModelViewProjectionMatrix");
uniform_tex = glGetUniformLocation(Program, "tex");
}
void ObjectUnlitShader::setUniforms(const core::matrix4 &ModelViewProjectionMatrix, unsigned TU_tex)
{
glUniformMatrix4fv(uniform_MVP, 1, GL_FALSE, ModelViewProjectionMatrix.pointer());
glUniform1i(uniform_tex, TU_tex);
}
GLuint ObjectRimLimitShader::Program;
GLuint ObjectRimLimitShader::attrib_position;
GLuint ObjectRimLimitShader::attrib_texcoord;
GLuint ObjectRimLimitShader::attrib_normal;
GLuint ObjectRimLimitShader::uniform_MVP;
GLuint ObjectRimLimitShader::uniform_TIMV;
GLuint ObjectRimLimitShader::uniform_Albedo;
GLuint ObjectRimLimitShader::uniform_DiffuseMap;
GLuint ObjectRimLimitShader::uniform_SpecularMap;
GLuint ObjectRimLimitShader::uniform_SSAO;
GLuint ObjectRimLimitShader::uniform_screen;
GLuint ObjectRimLimitShader::uniform_ambient;
void ObjectRimLimitShader::init()
{
Program = LoadProgram(file_manager->getAsset("shaders/objectpass_rimlit.vert").c_str(), file_manager->getAsset("shaders/objectpass_rimlit.frag").c_str());
attrib_position = glGetAttribLocation(Program, "Position");
attrib_texcoord = glGetAttribLocation(Program, "Texcoord");
attrib_normal = glGetAttribLocation(Program, "Normal");
uniform_MVP = glGetUniformLocation(Program, "ModelViewProjectionMatrix");
uniform_TIMV = glGetUniformLocation(Program, "TransposeInverseModelView");
uniform_Albedo = glGetUniformLocation(Program, "Albedo");
uniform_DiffuseMap = glGetUniformLocation(Program, "DiffuseMap");
uniform_SpecularMap = glGetUniformLocation(Program, "SpecularMap");
uniform_SSAO = glGetUniformLocation(Program, "SSAO");
uniform_screen = glGetUniformLocation(Program, "screen");
uniform_ambient = glGetUniformLocation(Program, "ambient");
}
void ObjectRimLimitShader::setUniforms(const core::matrix4 &ModelViewProjectionMatrix, const core::matrix4 &TransposeInverseModelView, unsigned TU_Albedo, unsigned TU_DiffuseMap, unsigned TU_SpecularMap, unsigned TU_SSAO)
{
glUniformMatrix4fv(uniform_MVP, 1, GL_FALSE, ModelViewProjectionMatrix.pointer());
glUniformMatrix4fv(uniform_TIMV, 1, GL_FALSE, TransposeInverseModelView.pointer());
glUniform1i(uniform_Albedo, TU_Albedo);
glUniform1i(uniform_DiffuseMap, TU_DiffuseMap);
glUniform1i(uniform_SpecularMap, TU_SpecularMap);
glUniform1i(uniform_SSAO, TU_SSAO);
glUniform2f(uniform_screen, UserConfigParams::m_width, UserConfigParams::m_height);
const video::SColorf s = irr_driver->getSceneManager()->getAmbientLight();
glUniform3f(uniform_ambient, s.r, s.g, s.b);
}
GLuint UntexturedObjectShader::Program;
GLuint UntexturedObjectShader::attrib_position;
GLuint UntexturedObjectShader::attrib_color;
@ -665,6 +779,81 @@ namespace MeshShader
glUniform1i(uniform_tex, TU_tex);
}
GLuint TransparentFogShader::Program;
GLuint TransparentFogShader::attrib_position;
GLuint TransparentFogShader::attrib_texcoord;
GLuint TransparentFogShader::uniform_MVP;
GLuint TransparentFogShader::uniform_tex;
GLuint TransparentFogShader::uniform_fogmax;
GLuint TransparentFogShader::uniform_startH;
GLuint TransparentFogShader::uniform_endH;
GLuint TransparentFogShader::uniform_start;
GLuint TransparentFogShader::uniform_end;
GLuint TransparentFogShader::uniform_col;
GLuint TransparentFogShader::uniform_screen;
GLuint TransparentFogShader::uniform_ipvmat;
void TransparentFogShader::init()
{
Program = LoadProgram(file_manager->getAsset("shaders/transparent.vert").c_str(), file_manager->getAsset("shaders/transparentfog.frag").c_str());
attrib_position = glGetAttribLocation(Program, "Position");
attrib_texcoord = glGetAttribLocation(Program, "Texcoord");
uniform_MVP = glGetUniformLocation(Program, "ModelViewProjectionMatrix");
uniform_tex = glGetUniformLocation(Program, "tex");
uniform_fogmax = glGetUniformLocation(Program, "fogmax");
uniform_startH = glGetUniformLocation(Program, "startH");
uniform_endH = glGetUniformLocation(Program, "endH");
uniform_start = glGetUniformLocation(Program, "start");
uniform_end = glGetUniformLocation(Program, "end");
uniform_col = glGetUniformLocation(Program, "col");
uniform_screen = glGetUniformLocation(Program, "screen");
uniform_ipvmat = glGetUniformLocation(Program, "ipvmat");
}
void TransparentFogShader::setUniforms(const core::matrix4 &ModelViewProjectionMatrix, const core::matrix4 &ipvmat, float fogmax, float startH, float endH, float start, float end, const core::vector3df &col, const core::vector3df &campos, unsigned TU_tex)
{
glUniformMatrix4fv(uniform_MVP, 1, GL_FALSE, ModelViewProjectionMatrix.pointer());
glUniform1f(uniform_fogmax, fogmax);
glUniform1f(uniform_startH, startH);
glUniform1f(uniform_endH, endH);
glUniform1f(uniform_start, start);
glUniform1f(uniform_end, end);
glUniform3f(uniform_col, col.X, col.Y, col.Z);
glUniform2f(uniform_screen, UserConfigParams::m_width, UserConfigParams::m_height);
glUniformMatrix4fv(uniform_ipvmat, 1, GL_FALSE, ipvmat.pointer());
glUniform1i(uniform_tex, TU_tex);
}
GLuint BillboardShader::Program;
GLuint BillboardShader::attrib_corner;
GLuint BillboardShader::attrib_texcoord;
GLuint BillboardShader::uniform_MV;
GLuint BillboardShader::uniform_P;
GLuint BillboardShader::uniform_tex;
GLuint BillboardShader::uniform_Position;
GLuint BillboardShader::uniform_Size;
void BillboardShader::init()
{
Program = LoadProgram(file_manager->getAsset("shaders/billboard.vert").c_str(), file_manager->getAsset("shaders/billboard.frag").c_str());
attrib_corner = glGetAttribLocation(Program, "Corner");
attrib_texcoord = glGetAttribLocation(Program, "Texcoord");
uniform_MV = glGetUniformLocation(Program, "ModelViewMatrix");
uniform_P = glGetUniformLocation(Program, "ProjectionMatrix");
uniform_Position = glGetUniformLocation(Program, "Position");
uniform_Size = glGetUniformLocation(Program, "Size");
uniform_tex = glGetUniformLocation(Program, "tex");
}
void BillboardShader::setUniforms(const core::matrix4 &ModelViewMatrix, const core::matrix4 &ProjectionMatrix, const core::vector3df &Position, const core::dimension2d<float> &size, unsigned TU_tex)
{
glUniformMatrix4fv(uniform_MV, 1, GL_FALSE, ModelViewMatrix.pointer());
glUniformMatrix4fv(uniform_P, 1, GL_FALSE, ProjectionMatrix.pointer());
glUniform3f(uniform_Position, Position.X, Position.Y, Position.Z);
glUniform2f(uniform_Size, size.Width, size.Height);
glUniform1i(uniform_tex, TU_tex);
}
GLuint ColorizeShader::Program;
GLuint ColorizeShader::attrib_position;
GLuint ColorizeShader::uniform_MVP;
@ -818,7 +1007,7 @@ namespace ParticleShader
GLuint SimpleParticleRender::uniform_matrix;
GLuint SimpleParticleRender::uniform_viewmatrix;
GLuint SimpleParticleRender::uniform_tex;
GLuint SimpleParticleRender::uniform_normal_and_depths;
GLuint SimpleParticleRender::uniform_dtex;
GLuint SimpleParticleRender::uniform_screen;
GLuint SimpleParticleRender::uniform_invproj;
@ -837,17 +1026,17 @@ namespace ParticleShader
uniform_tex = glGetUniformLocation(Program, "tex");
uniform_invproj = glGetUniformLocation(Program, "invproj");
uniform_screen = glGetUniformLocation(Program, "screen");
uniform_normal_and_depths = glGetUniformLocation(Program, "normals_and_depth");
uniform_dtex = glGetUniformLocation(Program, "dtex");
}
void SimpleParticleRender::setUniforms(const core::matrix4 &ViewMatrix, const core::matrix4 &ProjMatrix, const core::matrix4 InvProjMatrix, float width, float height, unsigned TU_tex, unsigned TU_normal_and_depth)
void SimpleParticleRender::setUniforms(const core::matrix4 &ViewMatrix, const core::matrix4 &ProjMatrix, const core::matrix4 InvProjMatrix, float width, float height, unsigned TU_tex, unsigned TU_dtex)
{
glUniformMatrix4fv(uniform_invproj, 1, GL_FALSE, InvProjMatrix.pointer());
glUniform2f(uniform_screen, width, height);
glUniformMatrix4fv(uniform_matrix, 1, GL_FALSE, irr_driver->getProjMatrix().pointer());
glUniformMatrix4fv(uniform_viewmatrix, 1, GL_FALSE, irr_driver->getViewMatrix().pointer());
glUniform1i(uniform_tex, TU_tex);
glUniform1i(uniform_normal_and_depths, TU_normal_and_depth);
glUniform1i(uniform_dtex, TU_dtex);
}
GLuint FlipParticleRender::Program;
@ -861,7 +1050,7 @@ namespace ParticleShader
GLuint FlipParticleRender::uniform_matrix;
GLuint FlipParticleRender::uniform_viewmatrix;
GLuint FlipParticleRender::uniform_tex;
GLuint FlipParticleRender::uniform_normal_and_depths;
GLuint FlipParticleRender::uniform_dtex;
GLuint FlipParticleRender::uniform_screen;
GLuint FlipParticleRender::uniform_invproj;
@ -881,17 +1070,17 @@ namespace ParticleShader
uniform_tex = glGetUniformLocation(Program, "tex");
uniform_invproj = glGetUniformLocation(Program, "invproj");
uniform_screen = glGetUniformLocation(Program, "screen");
uniform_normal_and_depths = glGetUniformLocation(Program, "normals_and_depth");
uniform_dtex = glGetUniformLocation(Program, "dtex");
}
void FlipParticleRender::setUniforms(const core::matrix4 &ViewMatrix, const core::matrix4 &ProjMatrix, const core::matrix4 InvProjMatrix, float width, float height, unsigned TU_tex, unsigned TU_normal_and_depth)
void FlipParticleRender::setUniforms(const core::matrix4 &ViewMatrix, const core::matrix4 &ProjMatrix, const core::matrix4 InvProjMatrix, float width, float height, unsigned TU_tex, unsigned TU_dtex)
{
glUniformMatrix4fv(uniform_invproj, 1, GL_FALSE, InvProjMatrix.pointer());
glUniform2f(uniform_screen, width, height);
glUniformMatrix4fv(uniform_matrix, 1, GL_FALSE, irr_driver->getProjMatrix().pointer());
glUniformMatrix4fv(uniform_viewmatrix, 1, GL_FALSE, irr_driver->getViewMatrix().pointer());
glUniform1i(uniform_tex, TU_tex);
glUniform1i(uniform_normal_and_depths, TU_normal_and_depth);
glUniform1i(uniform_dtex, TU_dtex);
}
}
@ -966,6 +1155,7 @@ namespace FullScreenShader
GLuint PointLightShader::Program;
GLuint PointLightShader::uniform_ntex;
GLuint PointLightShader::uniform_dtex;
GLuint PointLightShader::uniform_center;
GLuint PointLightShader::uniform_col;
GLuint PointLightShader::uniform_energy;
@ -973,10 +1163,12 @@ namespace FullScreenShader
GLuint PointLightShader::uniform_invproj;
GLuint PointLightShader::uniform_viewm;
GLuint PointLightShader::vao;
void PointLightShader::init()
{
Program = LoadProgram(file_manager->getAsset("shaders/screenquad.vert").c_str(), file_manager->getAsset("shaders/pointlight.frag").c_str());
uniform_ntex = glGetUniformLocation(Program, "ntex");
uniform_dtex = glGetUniformLocation(Program, "dtex");
uniform_center = glGetUniformLocation(Program, "center[0]");
uniform_col = glGetUniformLocation(Program, "col[0]");
uniform_energy = glGetUniformLocation(Program, "energy[0]");
@ -986,8 +1178,22 @@ namespace FullScreenShader
vao = createVAO(Program);
}
void PointLightShader::setUniforms(const core::matrix4 &InvProjMatrix, const core::matrix4 &ViewMatrix, const std::vector<float> &positions, const std::vector<float> &colors, const std::vector<float> &energy, unsigned spec, unsigned TU_ntex, unsigned TU_dtex)
{
glUniform4fv(FullScreenShader::PointLightShader::uniform_center, 16, positions.data());
glUniform4fv(FullScreenShader::PointLightShader::uniform_col, 16, colors.data());
glUniform1fv(FullScreenShader::PointLightShader::uniform_energy, 16, energy.data());
glUniform1f(FullScreenShader::PointLightShader::uniform_spec, 200);
glUniformMatrix4fv(FullScreenShader::PointLightShader::uniform_invproj, 1, GL_FALSE, InvProjMatrix.pointer());
glUniformMatrix4fv(FullScreenShader::PointLightShader::uniform_viewm, 1, GL_FALSE, ViewMatrix.pointer());
glUniform1i(FullScreenShader::PointLightShader::uniform_ntex, TU_ntex);
glUniform1i(FullScreenShader::PointLightShader::uniform_dtex, TU_dtex);
}
GLuint SunLightShader::Program;
GLuint SunLightShader::uniform_ntex;
GLuint SunLightShader::uniform_dtex;
GLuint SunLightShader::uniform_direction;
GLuint SunLightShader::uniform_col;
GLuint SunLightShader::uniform_invproj;
@ -997,36 +1203,20 @@ namespace FullScreenShader
{
Program = LoadProgram(file_manager->getAsset("shaders/screenquad.vert").c_str(), file_manager->getAsset("shaders/sunlight.frag").c_str());
uniform_ntex = glGetUniformLocation(Program, "ntex");
uniform_dtex = glGetUniformLocation(Program, "dtex");
uniform_direction = glGetUniformLocation(Program, "direction");
uniform_col = glGetUniformLocation(Program, "col");
uniform_invproj = glGetUniformLocation(Program, "invproj");
vao = createVAO(Program);
}
void SunLightShader::setUniforms(const core::vector3df &direction, const core::matrix4 &InvProjMatrix, float r, float g, float b, unsigned TU_ntex)
void SunLightShader::setUniforms(const core::vector3df &direction, const core::matrix4 &InvProjMatrix, float r, float g, float b, unsigned TU_ntex, unsigned TU_dtex)
{
glUniformMatrix4fv(uniform_invproj, 1, GL_FALSE, InvProjMatrix.pointer());
glUniform3f(uniform_direction, direction.X, direction.Y, direction.Z);
glUniform3f(uniform_col, r, g, b);
glUniform1i(uniform_ntex, TU_ntex);
}
GLuint LightBlendShader::Program;
GLuint LightBlendShader::uniform_diffuse;
GLuint LightBlendShader::uniform_specular;
GLuint LightBlendShader::uniform_ambient_occlusion;
GLuint LightBlendShader::uniform_specular_map;
GLuint LightBlendShader::uniform_ambient;
GLuint LightBlendShader::vao;
void LightBlendShader::init()
{
Program = LoadProgram(file_manager->getAsset("shaders/screenquad.vert").c_str(), file_manager->getAsset("shaders/lightblend.frag").c_str());
uniform_diffuse = glGetUniformLocation(Program, "diffuse");
uniform_specular = glGetUniformLocation(Program, "specular");
uniform_ambient_occlusion = glGetUniformLocation(Program, "ambient_occlusion");
uniform_specular_map = glGetUniformLocation(Program, "specular_map");
uniform_ambient = glGetUniformLocation(Program, "ambient");
vao = createVAO(Program);
glUniform1i(uniform_dtex, TU_dtex);
}
GLuint Gaussian6HBlurShader::Program;
@ -1098,35 +1288,130 @@ namespace FullScreenShader
}
GLuint SSAOShader::Program;
GLuint SSAOShader::uniform_normals_and_depth;
GLuint SSAOShader::uniform_ntex;
GLuint SSAOShader::uniform_dtex;
GLuint SSAOShader::uniform_noise_texture;
GLuint SSAOShader::uniform_invprojm;
GLuint SSAOShader::uniform_projm;
GLuint SSAOShader::uniform_samplePoints;
GLuint SSAOShader::vao;
float SSAOShader::SSAOSamples[64];
void SSAOShader::init()
{
Program = LoadProgram(file_manager->getAsset("shaders/screenquad.vert").c_str(), file_manager->getAsset("shaders/ssao.frag").c_str());
uniform_normals_and_depth = glGetUniformLocation(Program, "normals_and_depth");
uniform_ntex = glGetUniformLocation(Program, "ntex");
uniform_dtex = glGetUniformLocation(Program, "dtex");
uniform_noise_texture = glGetUniformLocation(Program, "noise_texture");
uniform_invprojm = glGetUniformLocation(Program, "invprojm");
uniform_projm = glGetUniformLocation(Program, "projm");
uniform_samplePoints = glGetUniformLocation(Program, "samplePoints[0]");
vao = createVAO(Program);
for (unsigned i = 0; i < 16; i++) {
// Generate x/y component between -1 and 1
// SSAOSamples[4 * i] and SSAOSamples[4 * i + 1] can be negative
SSAOSamples[0] = 0.135061f;
SSAOSamples[1] = 0.207948f;
SSAOSamples[2] = 0.968770f;
SSAOSamples[3] = 0.983032f;
SSAOSamples[4] = 0.273456f;
SSAOSamples[5] = -0.805390f;
SSAOSamples[6] = 0.525898f;
SSAOSamples[7] = 0.942808f;
SSAOSamples[8] = 0.443450f;
SSAOSamples[9] = -0.803786f;
SSAOSamples[10] = 0.396585f;
SSAOSamples[11] = 0.007996f;
SSAOSamples[12] = 0.742420f;
SSAOSamples[13] = -0.620072f;
SSAOSamples[14] = 0.253621f;
SSAOSamples[15] = 0.284829f;
SSAOSamples[16] = 0.892464f;
SSAOSamples[17] = 0.046221f;
SSAOSamples[18] = 0.448744f;
SSAOSamples[19] = 0.753655f;
SSAOSamples[20] = 0.830350f;
SSAOSamples[21] = -0.043593f;
SSAOSamples[22] = 0.555535f;
SSAOSamples[23] = 0.357463f;
SSAOSamples[24] = -0.600612f;
SSAOSamples[25] = -0.536421f;
SSAOSamples[26] = 0.592889f;
SSAOSamples[27] = 0.670583f;
SSAOSamples[28] = -0.280658f;
SSAOSamples[29] = 0.674894f;
SSAOSamples[30] = 0.682458f;
SSAOSamples[31] = 0.553362f;
SSAOSamples[32] = -0.654493f;
SSAOSamples[33] = -0.140866f;
SSAOSamples[34] = 0.742830f;
SSAOSamples[35] = 0.699820f;
SSAOSamples[36] = 0.114730f;
SSAOSamples[37] = 0.873130f;
SSAOSamples[38] = 0.473794f;
SSAOSamples[39] = 0.483901f;
SSAOSamples[40] = 0.699167f;
SSAOSamples[41] = 0.632210f;
SSAOSamples[42] = 0.333879f;
SSAOSamples[43] = 0.010956f;
SSAOSamples[44] = 0.904603f;
SSAOSamples[45] = 0.393410f;
SSAOSamples[46] = 0.164080f;
SSAOSamples[47] = 0.780297f;
SSAOSamples[48] = 0.631662f;
SSAOSamples[49] = -0.405195f;
SSAOSamples[50] = 0.660924f;
SSAOSamples[51] = 0.865596f;
SSAOSamples[52] = -0.195668f;
SSAOSamples[53] = 0.629185f;
SSAOSamples[54] = 0.752223f;
SSAOSamples[55] = 0.019013f;
SSAOSamples[56] = -0.511316f;
SSAOSamples[57] = 0.635504f;
SSAOSamples[58] = 0.578524f;
SSAOSamples[59] = 0.605457f;
SSAOSamples[60] = -0.898843f;
SSAOSamples[61] = 0.067382f;
SSAOSamples[62] = 0.433061f;
SSAOSamples[63] = 0.772942f;
// Generate another random distribution, if needed
/* for (unsigned i = 0; i < 16; i++) {
// Use double to avoid denorm and get a true uniform distribution
// Generate z component between [0.1; 1] to avoid being too close from surface
double z = rand();
z /= RAND_MAX;
z = 0.1 + 0.9 * z;
// Now generate x,y on the unit circle
double x = rand();
x /= RAND_MAX;
x = 2 * x - 1;
double y = rand();
y /= RAND_MAX;
y = 2 * y - 1;
double xynorm = sqrt(x * x + y * y);
x /= xynorm;
y /= xynorm;
// Now resize x,y so that norm(x,y,z) is one
x *= sqrt(1. - z * z);
y *= sqrt(1. - z * z);
// compute z so that norm (x,y,z) is one
double z = sqrt(x * x + y * y);
// Norm factor
double w = rand();
w /= RAND_MAX;
@ -1134,7 +1419,18 @@ namespace FullScreenShader
SSAOSamples[4 * i + 1] = (float)y;
SSAOSamples[4 * i + 2] = (float)z;
SSAOSamples[4 * i + 3] = (float)w;
}
}*/
}
void SSAOShader::setUniforms(const core::matrix4& projm, const core::matrix4 &invprojm, unsigned TU_ntex, unsigned TU_dtex, unsigned TU_noise)
{
glUniformMatrix4fv(FullScreenShader::SSAOShader::uniform_invprojm, 1, GL_FALSE, invprojm.pointer());
glUniformMatrix4fv(FullScreenShader::SSAOShader::uniform_projm, 1, GL_FALSE, projm.pointer());
glUniform4fv(FullScreenShader::SSAOShader::uniform_samplePoints, 16, FullScreenShader::SSAOShader::SSAOSamples);
glUniform1i(FullScreenShader::SSAOShader::uniform_ntex, TU_ntex);
glUniform1i(FullScreenShader::SSAOShader::uniform_dtex, TU_dtex);
glUniform1i(FullScreenShader::SSAOShader::uniform_noise_texture, TU_noise);
}
GLuint FogShader::Program;
@ -1145,9 +1441,9 @@ namespace FullScreenShader
GLuint FogShader::uniform_start;
GLuint FogShader::uniform_end;
GLuint FogShader::uniform_col;
GLuint FogShader::uniform_campos;
GLuint FogShader::uniform_ipvmat;
GLuint FogShader::vao;
void FogShader::init()
{
Program = LoadProgram(file_manager->getAsset("shaders/screenquad.vert").c_str(), file_manager->getAsset("shaders/fog.frag").c_str());
@ -1158,8 +1454,145 @@ namespace FullScreenShader
uniform_start = glGetUniformLocation(Program, "start");
uniform_end = glGetUniformLocation(Program, "end");
uniform_col = glGetUniformLocation(Program, "col");
uniform_campos = glGetUniformLocation(Program, "campos");
uniform_ipvmat = glGetUniformLocation(Program, "ipvmat");
vao = createVAO(Program);
}
void FogShader::setUniforms(const core::matrix4 &ipvmat, float fogmax, float startH, float endH, float start, float end, const core::vector3df &col, unsigned TU_ntex)
{
glUniform1f(uniform_fogmax, fogmax);
glUniform1f(uniform_startH, startH);
glUniform1f(uniform_endH, endH);
glUniform1f(uniform_start, start);
glUniform1f(uniform_end, end);
glUniform3f(uniform_col, col.X, col.Y, col.Z);
glUniformMatrix4fv(uniform_ipvmat, 1, GL_FALSE, ipvmat.pointer());
glUniform1i(uniform_tex, TU_ntex);
}
}
namespace UIShader
{
GLuint TextureRectShader::Program;
GLuint TextureRectShader::attrib_position;
GLuint TextureRectShader::attrib_texcoord;
GLuint TextureRectShader::uniform_tex;
GLuint TextureRectShader::uniform_center;
GLuint TextureRectShader::uniform_size;
GLuint TextureRectShader::uniform_texcenter;
GLuint TextureRectShader::uniform_texsize;
GLuint TextureRectShader::vao;
void TextureRectShader::init()
{
Program = LoadProgram(file_manager->getAsset("shaders/texturedquad.vert").c_str(), file_manager->getAsset("shaders/texturedquad.frag").c_str());
attrib_position = glGetAttribLocation(Program, "position");
attrib_texcoord = glGetAttribLocation(Program, "texcoord");
uniform_tex = glGetUniformLocation(Program, "tex");
uniform_center = glGetUniformLocation(Program, "center");
uniform_size = glGetUniformLocation(Program, "size");
uniform_texcenter = glGetUniformLocation(Program, "texcenter");
uniform_texsize = glGetUniformLocation(Program, "texsize");
glGenVertexArrays(1, &vao);
glBindVertexArray(vao);
glEnableVertexAttribArray(attrib_position);
glEnableVertexAttribArray(attrib_texcoord);
glBindBuffer(GL_ARRAY_BUFFER, quad_buffer);
glVertexAttribPointer(attrib_position, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float), 0);
glVertexAttribPointer(attrib_texcoord, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float), (GLvoid *)(2 * sizeof(float)));
glBindVertexArray(0);
}
void TextureRectShader::setUniforms(float center_pos_x, float center_pos_y, float width, float height, float tex_center_pos_x, float tex_center_pos_y, float tex_width, float tex_height, unsigned TU_tex)
{
glUniform1i(uniform_tex, TU_tex);
glUniform2f(uniform_center, center_pos_x, center_pos_y);
glUniform2f(uniform_size, width, height);
glUniform2f(uniform_texcenter, tex_center_pos_x, tex_center_pos_y);
glUniform2f(uniform_texsize, tex_width, tex_height);
}
GLuint ColoredTextureRectShader::Program;
GLuint ColoredTextureRectShader::attrib_position;
GLuint ColoredTextureRectShader::attrib_texcoord;
GLuint ColoredTextureRectShader::attrib_color;
GLuint ColoredTextureRectShader::uniform_tex;
GLuint ColoredTextureRectShader::uniform_center;
GLuint ColoredTextureRectShader::uniform_size;
GLuint ColoredTextureRectShader::uniform_texcenter;
GLuint ColoredTextureRectShader::uniform_texsize;
GLuint ColoredTextureRectShader::colorvbo;
GLuint ColoredTextureRectShader::vao;
void ColoredTextureRectShader::init()
{
Program = LoadProgram(file_manager->getAsset("shaders/colortexturedquad.vert").c_str(), file_manager->getAsset("shaders/colortexturedquad.frag").c_str());
attrib_position = glGetAttribLocation(Program, "position");
attrib_texcoord = glGetAttribLocation(Program, "texcoord");
attrib_color = glGetAttribLocation(Program, "color");
uniform_tex = glGetUniformLocation(Program, "tex");
uniform_center = glGetUniformLocation(Program, "center");
uniform_size = glGetUniformLocation(Program, "size");
uniform_texcenter = glGetUniformLocation(Program, "texcenter");
uniform_texsize = glGetUniformLocation(Program, "texsize");
glGenVertexArrays(1, &vao);
glBindVertexArray(vao);
glEnableVertexAttribArray(attrib_position);
glEnableVertexAttribArray(attrib_texcoord);
glEnableVertexAttribArray(attrib_color);
glBindBuffer(GL_ARRAY_BUFFER, quad_buffer);
glVertexAttribPointer(attrib_position, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float), 0);
glVertexAttribPointer(attrib_texcoord, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float), (GLvoid *)(2 * sizeof(float)));
const unsigned quad_color[] = {
0, 0, 0, 255,
255, 0, 0, 255,
0, 255, 0, 255,
0, 0, 255, 255,
};
glGenBuffers(1, &colorvbo);
glBindBuffer(GL_ARRAY_BUFFER, colorvbo);
glBufferData(GL_ARRAY_BUFFER, 16 * sizeof(unsigned), quad_color, GL_DYNAMIC_DRAW);
glVertexAttribIPointer(attrib_color, 4, GL_UNSIGNED_INT, 4 * sizeof(unsigned), 0);
glBindVertexArray(0);
}
void ColoredTextureRectShader::setUniforms(float center_pos_x, float center_pos_y, float width, float height, float tex_center_pos_x, float tex_center_pos_y, float tex_width, float tex_height, unsigned TU_tex)
{
glUniform1i(uniform_tex, TU_tex);
glUniform2f(uniform_center, center_pos_x, center_pos_y);
glUniform2f(uniform_size, width, height);
glUniform2f(uniform_texcenter, tex_center_pos_x, tex_center_pos_y);
glUniform2f(uniform_texsize, tex_width, tex_height);
}
GLuint ColoredRectShader::Program;
GLuint ColoredRectShader::attrib_position;
GLuint ColoredRectShader::uniform_center;
GLuint ColoredRectShader::uniform_size;
GLuint ColoredRectShader::uniform_color;
GLuint ColoredRectShader::vao;
void ColoredRectShader::init()
{
Program = LoadProgram(file_manager->getAsset("shaders/coloredquad.vert").c_str(), file_manager->getAsset("shaders/coloredquad.frag").c_str());
attrib_position = glGetAttribLocation(Program, "position");
uniform_color = glGetUniformLocation(Program, "color");
uniform_center = glGetUniformLocation(Program, "center");
uniform_size = glGetUniformLocation(Program, "size");
glGenVertexArrays(1, &vao);
glBindVertexArray(vao);
glEnableVertexAttribArray(attrib_position);
glBindBuffer(GL_ARRAY_BUFFER, quad_buffer);
glVertexAttribPointer(attrib_position, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float), 0);
glBindVertexArray(0);
}
void ColoredRectShader::setUniforms(float center_pos_x, float center_pos_y, float width, float height, const video::SColor &color)
{
glUniform2f(uniform_center, center_pos_x, center_pos_y);
glUniform2f(uniform_size, width, height);
glUniform4i(uniform_color, color.getRed(), color.getGreen(), color.getBlue(), color.getAlpha());
}
}

View File

@ -59,6 +59,28 @@ public:
static void setUniforms(const core::matrix4 &ModelViewProjectionMatrix, unsigned TU_Albedo, unsigned TU_DiffuseMap, unsigned TU_SpecularMap, unsigned TU_SSAO);
};
class DetailledObjectPass2Shader
{
public:
static GLuint Program;
static GLuint attrib_position, attrib_texcoord, attrib_second_texcoord;
static GLuint uniform_MVP, uniform_Albedo, uniform_Detail, uniform_DiffuseMap, uniform_SpecularMap, uniform_SSAO, uniform_screen, uniform_ambient;
static void init();
static void setUniforms(const core::matrix4 &ModelViewProjectionMatrix, unsigned TU_Albedo, unsigned TU_detail, unsigned TU_DiffuseMap, unsigned TU_SpecularMap, unsigned TU_SSAO);
};
class ObjectRimLimitShader
{
public:
static GLuint Program;
static GLuint attrib_position, attrib_normal, attrib_texcoord;
static GLuint uniform_MVP, uniform_TIMV, uniform_Albedo, uniform_DiffuseMap, uniform_SpecularMap, uniform_SSAO, uniform_screen, uniform_ambient;
static void init();
static void setUniforms(const core::matrix4 &ModelViewProjectionMatrix, const core::matrix4 &TransposeInverseModelView, unsigned TU_Albedo, unsigned TU_DiffuseMap, unsigned TU_SpecularMap, unsigned TU_SSAO);
};
class UntexturedObjectShader
{
public:
@ -70,6 +92,17 @@ public:
static void setUniforms(const core::matrix4 &ModelViewProjectionMatrix, unsigned TU_DiffuseMap, unsigned TU_SpecularMap, unsigned TU_SSAO);
};
class ObjectUnlitShader
{
public:
static GLuint Program;
static GLuint attrib_position, attrib_texcoord;
static GLuint uniform_MVP, uniform_tex;
static void init();
static void setUniforms(const core::matrix4 &ModelViewProjectionMatrix, unsigned TU_tex);
};
class ObjectRefPass2Shader
{
public:
@ -158,6 +191,28 @@ public:
static void setUniforms(const core::matrix4 &ModelViewProjectionMatrix, unsigned TU_tex);
};
class TransparentFogShader
{
public:
static GLuint Program;
static GLuint attrib_position, attrib_texcoord;
static GLuint uniform_MVP, uniform_tex, uniform_fogmax, uniform_startH, uniform_endH, uniform_start, uniform_end, uniform_col, uniform_screen, uniform_ipvmat;
static void init();
static void setUniforms(const core::matrix4 &ModelViewProjectionMatrix, const core::matrix4 &ipvmat, float fogmax, float startH, float endH, float start, float end, const core::vector3df &col, const core::vector3df &campos, unsigned TU_tex);
};
class BillboardShader
{
public:
static GLuint Program;
static GLuint attrib_corner, attrib_texcoord;
static GLuint uniform_MV, uniform_P, uniform_tex, uniform_Position, uniform_Size;
static void init();
static void setUniforms(const core::matrix4 &ModelViewMatrix, const core::matrix4 &ProjectionMatrix, const core::vector3df &Position, const core::dimension2d<float> &size, unsigned TU_tex);
};
class ColorizeShader
{
@ -214,7 +269,7 @@ class SimpleParticleRender
public:
static GLuint Program;
static GLuint attrib_pos, attrib_lf, attrib_quadcorner, attrib_texcoord, attrib_sz;
static GLuint uniform_matrix, uniform_viewmatrix, uniform_tex, uniform_normal_and_depths, uniform_screen, uniform_invproj;
static GLuint uniform_matrix, uniform_viewmatrix, uniform_tex, uniform_dtex, uniform_screen, uniform_invproj;
static void init();
static void setUniforms(const core::matrix4 &ViewMatrix, const core::matrix4 &ProjMatrix, const core::matrix4 InvProjMatrix, float width, float height, unsigned TU_tex, unsigned TU_normal_and_depth);
@ -225,7 +280,7 @@ class FlipParticleRender
public:
static GLuint Program;
static GLuint attrib_pos, attrib_lf, attrib_quadcorner, attrib_texcoord, attrib_sz, attrib_rotationvec, attrib_anglespeed;
static GLuint uniform_matrix, uniform_viewmatrix, uniform_tex, uniform_normal_and_depths, uniform_screen, uniform_invproj;
static GLuint uniform_matrix, uniform_viewmatrix, uniform_tex, uniform_dtex, uniform_screen, uniform_invproj;
static void init();
static void setUniforms(const core::matrix4 &ViewMatrix, const core::matrix4 &ProjMatrix, const core::matrix4 InvProjMatrix, float width, float height, unsigned TU_tex, unsigned TU_normal_and_depth);
@ -279,31 +334,22 @@ class PointLightShader
{
public:
static GLuint Program;
static GLuint uniform_ntex, uniform_center, uniform_col, uniform_energy, uniform_spec, uniform_invproj, uniform_viewm;
static GLuint uniform_ntex, uniform_dtex, uniform_center, uniform_col, uniform_energy, uniform_spec, uniform_invproj, uniform_viewm;
static GLuint vao;
static void init();
static void setUniforms(const core::matrix4 &InvProjMatrix, const core::matrix4 &ViewMatrix, const std::vector<float> &positions, const std::vector<float> &colors, const std::vector<float> &energy, unsigned spec, unsigned TU_ntex, unsigned TU_dtex);
};
class SunLightShader
{
public:
static GLuint Program;
static GLuint uniform_ntex, uniform_direction, uniform_col, uniform_invproj;
static GLuint vao;
static void init();
static void setUniforms(const core::vector3df &direction, const core::matrix4 &InvProjMatrix, float r, float g, float b, unsigned TU_ntex);
};
class LightBlendShader
{
public:
static GLuint Program;
static GLuint uniform_diffuse, uniform_specular, uniform_ambient_occlusion, uniform_specular_map, uniform_ambient;
static GLuint uniform_ntex, uniform_dtex, uniform_direction, uniform_col, uniform_invproj;
static GLuint vao;
static void init();
static void setUniforms(const core::vector3df &direction, const core::matrix4 &InvProjMatrix, float r, float g, float b, unsigned TU_ntex, unsigned TU_dtex);
};
class Gaussian6HBlurShader
@ -370,25 +416,67 @@ class SSAOShader
{
public:
static GLuint Program;
static GLuint uniform_normals_and_depth, uniform_noise_texture, uniform_invprojm, uniform_projm, uniform_samplePoints;
static GLuint uniform_ntex, uniform_dtex, uniform_noise_texture, uniform_invprojm, uniform_projm, uniform_samplePoints;
static GLuint vao;
static float SSAOSamples[64];
static void init();
static void setUniforms(const core::matrix4& projm, const core::matrix4 &invprojm, unsigned TU_ntex, unsigned TU_dtex, unsigned TU_noise);
};
class FogShader
{
public:
static GLuint Program;
static GLuint uniform_tex, uniform_fogmax, uniform_startH, uniform_endH, uniform_start, uniform_end, uniform_col, uniform_campos, uniform_ipvmat;
static GLuint uniform_tex, uniform_fogmax, uniform_startH, uniform_endH, uniform_start, uniform_end, uniform_col, uniform_ipvmat;
static GLuint vao;
static void init();
static void setUniforms(const core::matrix4 &ipvmat, float fogmax, float startH, float endH, float start, float end, const core::vector3df &col, unsigned TU_ntex);
};
}
namespace UIShader
{
class TextureRectShader
{
public:
static GLuint Program;
static GLuint attrib_position, attrib_texcoord;
static GLuint uniform_tex, uniform_center, uniform_size, uniform_texcenter, uniform_texsize;
static GLuint vao;
static void init();
static void setUniforms(float center_pos_x, float center_pos_y, float width, float height, float tex_center_pos_x, float tex_center_pos_y, float tex_width, float tex_height, unsigned TU_tex);
};
class ColoredTextureRectShader
{
public:
static GLuint Program;
static GLuint attrib_position, attrib_texcoord, attrib_color;
static GLuint uniform_tex, uniform_center, uniform_size, uniform_texcenter, uniform_texsize;
static GLuint colorvbo;
static GLuint vao;
static void init();
static void setUniforms(float center_pos_x, float center_pos_y, float width, float height, float tex_center_pos_x, float tex_center_pos_y, float tex_width, float tex_height, unsigned TU_tex);
};
class ColoredRectShader
{
public:
static GLuint Program;
static GLuint attrib_position;
static GLuint uniform_center, uniform_size, uniform_color;
static GLuint vao;
static void init();
static void setUniforms(float center_pos_x, float center_pos_y, float width, float height, const video::SColor &color);
};
}
#define FOREACH_SHADER(ACT) \
ACT(ES_NORMAL_MAP) \
ACT(ES_NORMAL_MAP_LIGHTMAP) \
@ -407,7 +495,7 @@ public:
ACT(ES_MIPVIZ) \
ACT(ES_COLORIZE) \
ACT(ES_COLORIZE_REF) \
ACT(ES_GLOW) \
ACT(ES_OBJECT_UNLIT) \
ACT(ES_OBJECTPASS) \
ACT(ES_OBJECTPASS_REF) \
ACT(ES_SUNLIGHT) \

View File

@ -115,7 +115,7 @@ void ShowCurve::addPoint(const Vec3 &pnt)
// 4 sides of the 'tunnel', so all in all 24 indices.
irr::u16 *indices = new irr::u16[24];
m_buffer->append(vertices, 4, indices, 24);
delete indices;
delete[] indices;
indices = m_buffer->getIndices();
// index = first newly added index

View File

@ -0,0 +1,167 @@
#include "graphics/stkanimatedmesh.hpp"
#include <ISceneManager.h>
#include <IMaterialRenderer.h>
#include <ISkinnedMesh.h>
#include "graphics/irr_driver.hpp"
#include "config/user_config.hpp"
#include "modes/world.hpp"
#include "tracks/track.hpp"
using namespace irr;
STKAnimatedMesh::STKAnimatedMesh(irr::scene::IAnimatedMesh* mesh, irr::scene::ISceneNode* parent,
irr::scene::ISceneManager* mgr, s32 id,
const core::vector3df& position,
const core::vector3df& rotation,
const core::vector3df& scale) :
CAnimatedMeshSceneNode(mesh, parent, mgr, id, position, rotation, scale)
{
firstTime = true;
}
void STKAnimatedMesh::setMesh(scene::IAnimatedMesh* mesh)
{
firstTime = true;
GLmeshes.clear();
CAnimatedMeshSceneNode::setMesh(mesh);
}
void STKAnimatedMesh::drawTransparent(const GLMesh &mesh, video::E_MATERIAL_TYPE type)
{
assert(irr_driver->getPhase() == TRANSPARENT_PASS);
computeMVP(ModelViewProjectionMatrix);
if (World::getWorld()->getTrack()->isFogEnabled())
drawTransparentFogObject(mesh, ModelViewProjectionMatrix);
else
drawTransparentObject(mesh, ModelViewProjectionMatrix);
return;
}
void STKAnimatedMesh::drawSolid(const GLMesh &mesh, video::E_MATERIAL_TYPE type)
{
switch (irr_driver->getPhase())
{
case SOLID_NORMAL_AND_DEPTH_PASS:
{
computeMVP(ModelViewProjectionMatrix);
computeTIMV(TransposeInverseModelView);
if (type == irr_driver->getShader(ES_OBJECTPASS_REF))
drawObjectRefPass1(mesh, ModelViewProjectionMatrix, TransposeInverseModelView);
else
drawObjectPass1(mesh, ModelViewProjectionMatrix, TransposeInverseModelView);
break;
}
case SOLID_LIT_PASS:
{
if (type == irr_driver->getShader(ES_OBJECTPASS_REF))
drawObjectRefPass2(mesh, ModelViewProjectionMatrix);
else if (type == irr_driver->getShader(ES_OBJECTPASS_RIMLIT))
drawObjectRimLimit(mesh, ModelViewProjectionMatrix, TransposeInverseModelView);
else if (type == irr_driver->getShader(ES_OBJECT_UNLIT))
drawObjectUnlit(mesh, ModelViewProjectionMatrix);
else if (mesh.textures[1])
drawDetailledObjectPass2(mesh, ModelViewProjectionMatrix);
else
drawObjectPass2(mesh, ModelViewProjectionMatrix);
break;
}
default:
{
assert(0 && "wrong pass");
}
}
}
static bool
isObjectPass(video::E_MATERIAL_TYPE type)
{
if (type == irr_driver->getShader(ES_OBJECTPASS))
return true;
if (type == irr_driver->getShader(ES_OBJECTPASS_REF))
return true;
if (type == irr_driver->getShader(ES_OBJECTPASS_RIMLIT))
return true;
if (type == irr_driver->getShader(ES_OBJECT_UNLIT))
return true;
if (type == video::EMT_ONETEXTURE_BLEND)
return true;
if (type == video::EMT_TRANSPARENT_ADD_COLOR)
return true;
return false;
}
void STKAnimatedMesh::render()
{
video::IVideoDriver* driver = SceneManager->getVideoDriver();
bool isTransparentPass =
SceneManager->getSceneNodeRenderPass() == scene::ESNRP_TRANSPARENT;
++PassCount;
scene::IMesh* m = getMeshForCurrentFrame();
if (m)
{
Box = m->getBoundingBox();
}
else
{
Log::error("animated mesh", "Animated Mesh returned no mesh to render.");
return;
}
driver->setTransform(video::ETS_WORLD, AbsoluteTransformation);
if (firstTime)
for (u32 i = 0; i<m->getMeshBufferCount(); ++i)
{
scene::IMeshBuffer* mb = Mesh->getMeshBuffer(i);
GLmeshes.push_back(allocateMeshBuffer(mb));
}
firstTime = false;
// render original meshes
for (u32 i = 0; i<m->getMeshBufferCount(); ++i)
{
video::IMaterialRenderer* rnd = driver->getMaterialRenderer(Materials[i].MaterialType);
bool transparent = (rnd && rnd->isTransparent());
// only render transparent buffer if this is the transparent render pass
// and solid only in solid pass
if (transparent != isTransparentPass)
continue;
scene::IMeshBuffer* mb = m->getMeshBuffer(i);
const video::SMaterial& material = ReadOnlyMaterials ? mb->getMaterial() : Materials[i];
if (RenderFromIdentity)
driver->setTransform(video::ETS_WORLD, core::IdentityMatrix);
else if (Mesh->getMeshType() == scene::EAMT_SKINNED)
driver->setTransform(video::ETS_WORLD, AbsoluteTransformation * ((scene::SSkinMeshBuffer*)mb)->Transformation);
if (isObjectPass(material.MaterialType))
{
irr_driver->IncreaseObjectCount();
initvaostate(GLmeshes[i], material.MaterialType);
if (irr_driver->getPhase() == SOLID_NORMAL_AND_DEPTH_PASS)
{
glBindVertexArray(0);
glBindBuffer(GL_ARRAY_BUFFER, GLmeshes[i].vertex_buffer);
glBufferSubData(GL_ARRAY_BUFFER, 0, mb->getVertexCount() * GLmeshes[i].Stride, mb->getVertices());
}
if (isTransparentPass)
drawTransparent(GLmeshes[i], material.MaterialType);
else
drawSolid(GLmeshes[i], material.MaterialType);
}
else
{
#ifdef DEBUG
Log::warn("material", "Unhandled (animated) material type : %d", material.MaterialType);
#endif
continue;
}
}
}

View File

@ -0,0 +1,29 @@
#ifndef STKANIMATEDMESH_HPP
#define STKANIMATEDMESH_HPP
#include "../lib/irrlicht/source/Irrlicht/CAnimatedMeshSceneNode.h"
#include <IAnimatedMesh.h>
#include <irrTypes.h>
#include "graphics/stkmesh.hpp"
class STKAnimatedMesh : public irr::scene::CAnimatedMeshSceneNode
{
protected:
bool firstTime;
std::vector<GLMesh> GLmeshes;
core::matrix4 ModelViewProjectionMatrix, TransposeInverseModelView;
void drawSolid(const GLMesh &mesh, video::E_MATERIAL_TYPE type);
void drawTransparent(const GLMesh &mesh, video::E_MATERIAL_TYPE type);
public:
STKAnimatedMesh(irr::scene::IAnimatedMesh* mesh, irr::scene::ISceneNode* parent,
irr::scene::ISceneManager* mgr, irr::s32 id,
const irr::core::vector3df& position = irr::core::vector3df(0,0,0),
const irr::core::vector3df& rotation = irr::core::vector3df(0,0,0),
const irr::core::vector3df& scale = irr::core::vector3df(1.0f, 1.0f, 1.0f));
virtual void render();
virtual void setMesh(irr::scene::IAnimatedMesh* mesh);
};
#endif // STKANIMATEDMESH_HPP

View File

@ -0,0 +1,52 @@
#include "graphics/stkbillboard.hpp"
#include "graphics/glwrap.hpp"
#include "graphics/shaders.hpp"
#include "graphics/irr_driver.hpp"
using namespace irr;
static GLuint billboardvbo;
static GLuint billboardvao = 0;
static void createbillboardvao()
{
float quad[] = {
-.5, -.5, 0., 1.,
-.5, .5, 0., 0.,
.5, -.5, 1., 1.,
.5, .5, 1., 0.,
};
glGenBuffers(1, &billboardvbo);
glGenVertexArrays(1, &billboardvao);
glBindVertexArray(billboardvao);
glBindBuffer(GL_ARRAY_BUFFER, billboardvbo);
glBufferData(GL_ARRAY_BUFFER, 16 * sizeof(float), quad, GL_STATIC_DRAW);
glEnableVertexAttribArray(MeshShader::BillboardShader::attrib_corner);
glEnableVertexAttribArray(MeshShader::BillboardShader::attrib_texcoord);
glVertexAttribPointer(MeshShader::BillboardShader::attrib_corner, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float), 0);
glVertexAttribPointer(MeshShader::BillboardShader::attrib_texcoord, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float), (GLvoid*) (2 * sizeof(float)));
glBindVertexArray(0);
}
STKBillboard::STKBillboard(irr::scene::ISceneNode* parent, irr::scene::ISceneManager* mgr, irr::s32 id,
const irr::core::vector3df& position, const irr::core::dimension2d<irr::f32>& size,
irr::video::SColor colorTop, irr::video::SColor colorBottom) :
CBillboardSceneNode(parent, mgr, id, position, size, colorTop, colorBottom), IBillboardSceneNode(parent, mgr, id, position)
{
if (!billboardvao)
createbillboardvao();
}
void STKBillboard::render()
{
core::vector3df pos = getAbsolutePosition();
glBindVertexArray(billboardvao);
GLuint texid = static_cast<irr::video::COpenGLTexture*>(Material.getTexture(0))->getOpenGLTextureName();
setTexture(0, texid, GL_LINEAR, GL_LINEAR);
glUseProgram(MeshShader::BillboardShader::Program);
MeshShader::BillboardShader::setUniforms(irr_driver->getViewMatrix(), irr_driver->getProjMatrix(), pos, Size, 0);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
glBindVertexArray(0);
return;
}

View File

@ -0,0 +1,19 @@
#ifndef STKBILLBOARD_HPP
#define STKBILLBOARD_HPP
#include "../lib/irrlicht/source/Irrlicht/CBillboardSceneNode.h"
#include <IBillboardSceneNode.h>
#include <irrTypes.h>
class STKBillboard : public irr::scene::CBillboardSceneNode
{
public:
STKBillboard(irr::scene::ISceneNode* parent, irr::scene::ISceneManager* mgr, irr::s32 id,
const irr::core::vector3df& position, const irr::core::dimension2d<irr::f32>& size,
irr::video::SColor colorTop = irr::video::SColor(0xFFFFFFFF),
irr::video::SColor colorBottom = irr::video::SColor(0xFFFFFFFF));
virtual void render();
};
#endif

View File

@ -1,12 +1,15 @@
#include "stkmesh.hpp"
#include "graphics/irr_driver.hpp"
#include "tracks/track.hpp"
#include <ISceneManager.h>
#include <IMaterialRenderer.h>
#include "config/user_config.hpp"
#include "graphics/callbacks.hpp"
#include "utils/helpers.hpp"
#include "graphics/camera.hpp"
#include "modes/world.hpp"
static
GLuint createVAO(GLuint vbo, GLuint idx, GLuint attrib_position, GLuint attrib_texcoord, GLuint attrib_second_texcoord, GLuint attrib_normal, GLuint attrib_tangent, GLuint attrib_bitangent, GLuint attrib_color, size_t stride)
{
GLuint vao;
@ -58,13 +61,12 @@ GLuint createVAO(GLuint vbo, GLuint idx, GLuint attrib_position, GLuint attrib_t
return vao;
}
static
GLMesh allocateMeshBuffer(scene::IMeshBuffer* mb)
{
initGL();
GLMesh result = {};
if (!mb)
return result;
glBindVertexArray(0);
glGenBuffers(1, &(result.vertex_buffer));
glGenBuffers(1, &(result.index_buffer));
@ -118,6 +120,7 @@ GLMesh allocateMeshBuffer(scene::IMeshBuffer* mb)
break;
case scene::EPT_LINES:
result.PrimitiveType = GL_LINES;
break;
case scene::EPT_TRIANGLES:
result.PrimitiveType = GL_TRIANGLES;
break;
@ -147,31 +150,51 @@ STKMesh::STKMesh(irr::scene::IMesh* mesh, ISceneNode* parent, irr::scene::IScene
const irr::core::vector3df& scale) :
CMeshSceneNode(mesh, parent, mgr, id, position, rotation, scale)
{
for (u32 i=0; i<Mesh->getMeshBufferCount(); ++i)
createGLMeshes();
}
void STKMesh::createGLMeshes()
{
for (u32 i = 0; i<Mesh->getMeshBufferCount(); ++i)
{
scene::IMeshBuffer* mb = Mesh->getMeshBuffer(i);
GLmeshes.push_back(allocateMeshBuffer(mb));
}
}
void STKMesh::cleanGLMeshes()
{
for (u32 i = 0; i < GLmeshes.size(); ++i)
{
GLMesh mesh = GLmeshes[i];
if (!mesh.vertex_buffer)
continue;
if (mesh.vao_first_pass)
glDeleteVertexArrays(1, &(mesh.vao_first_pass));
if (mesh.vao_second_pass)
glDeleteVertexArrays(1, &(mesh.vao_second_pass));
if (mesh.vao_glow_pass)
glDeleteVertexArrays(1, &(mesh.vao_glow_pass));
if (mesh.vao_displace_pass)
glDeleteVertexArrays(1, &(mesh.vao_displace_pass));
glDeleteBuffers(1, &(mesh.vertex_buffer));
glDeleteBuffers(1, &(mesh.index_buffer));
}
GLmeshes.clear();
}
void STKMesh::setMesh(irr::scene::IMesh* mesh)
{
CMeshSceneNode::setMesh(mesh);
cleanGLMeshes();
createGLMeshes();
}
STKMesh::~STKMesh()
{
for (u32 i = 0; i < Mesh->getMeshBufferCount(); ++i)
{
scene::IMeshBuffer* mb = Mesh->getMeshBuffer(i);
if (!mb)
continue;
GLMesh mesh = GLmeshes[i];
glDeleteVertexArrays(1, &(mesh.vao_first_pass));
glDeleteVertexArrays(1, &(mesh.vao_second_pass));
glDeleteVertexArrays(1, &(mesh.vao_glow_pass));
glDeleteBuffers(1, &(mesh.vertex_buffer));
glDeleteBuffers(1, &(mesh.index_buffer));
}
cleanGLMeshes();
}
static
void computeMVP(core::matrix4 &ModelViewProjectionMatrix)
{
ModelViewProjectionMatrix = irr_driver->getVideoDriver()->getTransform(video::ETS_PROJECTION);
@ -179,7 +202,6 @@ void computeMVP(core::matrix4 &ModelViewProjectionMatrix)
ModelViewProjectionMatrix *= irr_driver->getVideoDriver()->getTransform(video::ETS_WORLD);
}
static
void computeTIMV(core::matrix4 &TransposeInverseModelView)
{
TransposeInverseModelView = irr_driver->getVideoDriver()->getTransform(video::ETS_VIEW);
@ -188,15 +210,12 @@ void computeTIMV(core::matrix4 &TransposeInverseModelView)
TransposeInverseModelView = TransposeInverseModelView.getTransposed();
}
void STKMesh::drawObjectPass1(const GLMesh &mesh)
void drawObjectPass1(const GLMesh &mesh, const core::matrix4 & ModelViewProjectionMatrix, const core::matrix4 &TransposeInverseModelView)
{
GLenum ptype = mesh.PrimitiveType;
GLenum itype = mesh.IndexType;
size_t count = mesh.IndexCount;
computeMVP(ModelViewProjectionMatrix);
computeTIMV(TransposeInverseModelView);
glUseProgram(MeshShader::ObjectPass1Shader::Program);
MeshShader::ObjectPass1Shader::setUniforms(ModelViewProjectionMatrix, TransposeInverseModelView);
@ -204,22 +223,22 @@ void STKMesh::drawObjectPass1(const GLMesh &mesh)
glDrawElements(ptype, count, itype, 0);
}
void STKMesh::drawObjectRefPass1(const GLMesh &mesh)
void drawObjectRefPass1(const GLMesh &mesh, const core::matrix4 & ModelViewProjectionMatrix, const core::matrix4 &TransposeInverseModelView)
{
glDisable(GL_CULL_FACE);
GLenum ptype = mesh.PrimitiveType;
GLenum itype = mesh.IndexType;
size_t count = mesh.IndexCount;
computeMVP(ModelViewProjectionMatrix);
computeTIMV(TransposeInverseModelView);
setTexture(0, mesh.textures[0], GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR);
setTexture(0, mesh.textures[0], GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR, true);
glUseProgram(MeshShader::ObjectRefPass1Shader::Program);
MeshShader::ObjectRefPass1Shader::setUniforms(ModelViewProjectionMatrix, TransposeInverseModelView, 0);
glBindVertexArray(mesh.vao_first_pass);
glDrawElements(ptype, count, itype, 0);
glEnable(GL_CULL_FACE);
}
static
@ -238,17 +257,13 @@ core::vector3df getWind()
return irr_driver->getWind() * strength;
}
void STKMesh::drawGrassPass1(const GLMesh &mesh)
void drawGrassPass1(const GLMesh &mesh, const core::matrix4 & ModelViewProjectionMatrix, const core::matrix4 &TransposeInverseModelView, core::vector3df windDir)
{
GLenum ptype = mesh.PrimitiveType;
GLenum itype = mesh.IndexType;
size_t count = mesh.IndexCount;
windDir = getWind();
computeMVP(ModelViewProjectionMatrix);
computeTIMV(TransposeInverseModelView);
setTexture(0, mesh.textures[0], GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR);
setTexture(0, mesh.textures[0], GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR, true);
glUseProgram(MeshShader::GrassPass1Shader::Program);
MeshShader::GrassPass1Shader::setUniforms(ModelViewProjectionMatrix, TransposeInverseModelView, windDir, 0);
@ -257,17 +272,14 @@ void STKMesh::drawGrassPass1(const GLMesh &mesh)
glDrawElements(ptype, count, itype, 0);
}
void STKMesh::drawNormalPass(const GLMesh &mesh)
void drawNormalPass(const GLMesh &mesh, const core::matrix4 & ModelViewProjectionMatrix, const core::matrix4 &TransposeInverseModelView)
{
GLenum ptype = mesh.PrimitiveType;
GLenum itype = mesh.IndexType;
size_t count = mesh.IndexCount;
computeMVP(ModelViewProjectionMatrix);
computeTIMV(TransposeInverseModelView);
assert(mesh.textures[1]);
setTexture(0, mesh.textures[1], GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR);
setTexture(0, mesh.textures[1], GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR, true);
glUseProgram(MeshShader::NormalMapShader::Program);
MeshShader::NormalMapShader::setUniforms(ModelViewProjectionMatrix, TransposeInverseModelView, 0);
@ -276,13 +288,13 @@ void STKMesh::drawNormalPass(const GLMesh &mesh)
glDrawElements(ptype, count, itype, 0);
}
void STKMesh::drawSphereMap(const GLMesh &mesh)
void drawSphereMap(const GLMesh &mesh, const core::matrix4 &ModelViewProjectionMatrix, const core::matrix4 &TransposeInverseModelView)
{
GLenum ptype = mesh.PrimitiveType;
GLenum itype = mesh.IndexType;
size_t count = mesh.IndexCount;
setTexture(0, mesh.textures[0], GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR);
setTexture(0, mesh.textures[0], GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR, true);
glUseProgram(MeshShader::SphereMapShader::Program);
MeshShader::SphereMapShader::setUniforms(ModelViewProjectionMatrix, TransposeInverseModelView, 0);
@ -291,27 +303,72 @@ void STKMesh::drawSphereMap(const GLMesh &mesh)
glDrawElements(ptype, count, itype, 0);
}
void STKMesh::drawSplatting(const GLMesh &mesh)
void drawSplatting(const GLMesh &mesh, const core::matrix4 &ModelViewProjectionMatrix)
{
GLenum ptype = mesh.PrimitiveType;
GLenum itype = mesh.IndexType;
size_t count = mesh.IndexCount;
// Texlayout
setTexture(0, mesh.textures[1], GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR);
setTexture(0, mesh.textures[1], 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);
}
//Tex detail0
setTexture(1, mesh.textures[2], GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR);
setTexture(1, mesh.textures[2], 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);
}
//Tex detail1
setTexture(2, mesh.textures[3], GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR);
setTexture(2, mesh.textures[3], 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);
}
//Tex detail2
setTexture(3, mesh.textures[4], GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR);
setTexture(3, mesh.textures[4], 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);
}
//Tex detail3
setTexture(4, mesh.textures[5], GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR);
setTexture(4, mesh.textures[5], 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);
}
// Diffuse
setTexture(5, static_cast<irr::video::COpenGLTexture*>(irr_driver->getRTT(RTT_TMP1))->getOpenGLTextureName(), GL_NEAREST, GL_NEAREST);
@ -320,6 +377,11 @@ void STKMesh::drawSplatting(const GLMesh &mesh)
// SSAO
setTexture(7, static_cast<irr::video::COpenGLTexture*>(irr_driver->getRTT(RTT_SSAO))->getOpenGLTextureName(), GL_NEAREST, GL_NEAREST);
if (!UserConfigParams::m_ssao)
{
GLint swizzleMask[] = {GL_ONE, GL_ONE, GL_ONE, GL_ONE};
glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_RGBA, swizzleMask);
}
glUseProgram(MeshShader::SplattingShader::Program);
MeshShader::SplattingShader::setUniforms(ModelViewProjectionMatrix, 0, 1, 2, 3, 4, 5, 6, 7);
@ -328,36 +390,66 @@ void STKMesh::drawSplatting(const GLMesh &mesh)
glDrawElements(ptype, count, itype, 0);
}
void STKMesh::drawObjectRefPass2(const GLMesh &mesh)
void drawObjectRefPass2(const GLMesh &mesh, const core::matrix4 &ModelViewProjectionMatrix)
{
glDisable(GL_CULL_FACE);
GLenum ptype = mesh.PrimitiveType;
GLenum itype = mesh.IndexType;
size_t count = mesh.IndexCount;
setTexture(0, mesh.textures[0], GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR);
setTexture(0, 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);
}
setTexture(1, static_cast<irr::video::COpenGLTexture*>(irr_driver->getRTT(RTT_TMP1))->getOpenGLTextureName(), GL_NEAREST, GL_NEAREST);
setTexture(2, static_cast<irr::video::COpenGLTexture*>(irr_driver->getRTT(RTT_TMP2))->getOpenGLTextureName(), GL_NEAREST, GL_NEAREST);
setTexture(3, static_cast<irr::video::COpenGLTexture*>(irr_driver->getRTT(RTT_SSAO))->getOpenGLTextureName(), GL_NEAREST, GL_NEAREST);
if (!UserConfigParams::m_ssao)
{
GLint swizzleMask[] = {GL_ONE, GL_ONE, GL_ONE, GL_ONE};
glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_RGBA, swizzleMask);
}
glUseProgram(MeshShader::ObjectRefPass2Shader::Program);
MeshShader::ObjectRefPass2Shader::setUniforms(ModelViewProjectionMatrix, 0, 1, 2, 3);
glBindVertexArray(mesh.vao_second_pass);
glDrawElements(ptype, count, itype, 0);
glEnable(GL_CULL_FACE);
}
void STKMesh::drawGrassPass2(const GLMesh &mesh)
void drawGrassPass2(const GLMesh &mesh, const core::matrix4 & ModelViewProjectionMatrix, core::vector3df windDir)
{
GLenum ptype = mesh.PrimitiveType;
GLenum itype = mesh.IndexType;
size_t count = mesh.IndexCount;
setTexture(0, mesh.textures[0], GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR);
setTexture(0, 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);
}
setTexture(1, static_cast<irr::video::COpenGLTexture*>(irr_driver->getRTT(RTT_TMP1))->getOpenGLTextureName(), GL_NEAREST, GL_NEAREST);
setTexture(2, static_cast<irr::video::COpenGLTexture*>(irr_driver->getRTT(RTT_TMP2))->getOpenGLTextureName(), GL_NEAREST, GL_NEAREST);
setTexture(3, static_cast<irr::video::COpenGLTexture*>(irr_driver->getRTT(RTT_SSAO))->getOpenGLTextureName(), GL_NEAREST, GL_NEAREST);
if (!UserConfigParams::m_ssao)
{
GLint swizzleMask[] = {GL_ONE, GL_ONE, GL_ONE, GL_ONE};
glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_RGBA, swizzleMask);
}
glUseProgram(MeshShader::GrassPass2Shader::Program);
MeshShader::GrassPass2Shader::setUniforms(ModelViewProjectionMatrix, windDir, 0, 1, 2, 3);
@ -366,7 +458,7 @@ void STKMesh::drawGrassPass2(const GLMesh &mesh)
glDrawElements(ptype, count, itype, 0);
}
void STKMesh::drawUntexturedObject(const GLMesh &mesh)
void drawUntexturedObject(const GLMesh &mesh, const core::matrix4 &ModelViewProjectionMatrix)
{
GLenum ptype = mesh.PrimitiveType;
GLenum itype = mesh.IndexType;
@ -375,42 +467,157 @@ void STKMesh::drawUntexturedObject(const GLMesh &mesh)
setTexture(0, static_cast<irr::video::COpenGLTexture*>(irr_driver->getRTT(RTT_TMP1))->getOpenGLTextureName(), GL_NEAREST, GL_NEAREST);
setTexture(1, static_cast<irr::video::COpenGLTexture*>(irr_driver->getRTT(RTT_TMP2))->getOpenGLTextureName(), GL_NEAREST, GL_NEAREST);
setTexture(2, static_cast<irr::video::COpenGLTexture*>(irr_driver->getRTT(RTT_SSAO))->getOpenGLTextureName(), GL_NEAREST, GL_NEAREST);
if (!UserConfigParams::m_ssao)
{
GLint swizzleMask[] = {GL_ONE, GL_ONE, GL_ONE, GL_ONE};
glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_RGBA, swizzleMask);
}
glUseProgram(MeshShader::UntexturedObjectShader::Program);
MeshShader::UntexturedObjectShader::setUniforms(ModelViewProjectionMatrix, 0, 1, 2);
glBindVertexArray(mesh.vao_second_pass);
glDrawElements(ptype, count, itype, 0);
}
void STKMesh::drawObjectPass2(const GLMesh &mesh)
{
GLenum ptype = mesh.PrimitiveType;
GLenum itype = mesh.IndexType;
size_t count = mesh.IndexCount;
setTexture(0, mesh.textures[0], GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR);
setTexture(1, static_cast<irr::video::COpenGLTexture*>(irr_driver->getRTT(RTT_TMP1))->getOpenGLTextureName(), GL_NEAREST, GL_NEAREST);
setTexture(2, static_cast<irr::video::COpenGLTexture*>(irr_driver->getRTT(RTT_TMP2))->getOpenGLTextureName(), GL_NEAREST, GL_NEAREST);
setTexture(3, static_cast<irr::video::COpenGLTexture*>(irr_driver->getRTT(RTT_SSAO))->getOpenGLTextureName(), GL_NEAREST, GL_NEAREST);
glUseProgram(MeshShader::ObjectPass2Shader::Program);
MeshShader::ObjectPass2Shader::setUniforms(ModelViewProjectionMatrix, 0, 1, 2, 3);
glBindVertexArray(mesh.vao_second_pass);
glDrawElements(ptype, count, itype, 0);
}
void STKMesh::drawTransparentObject(const GLMesh &mesh)
void drawObjectRimLimit(const GLMesh &mesh, const core::matrix4 &ModelViewProjectionMatrix, const core::matrix4 &TransposeInverseModelView)
{
GLenum ptype = mesh.PrimitiveType;
GLenum itype = mesh.IndexType;
size_t count = mesh.IndexCount;
computeMVP(ModelViewProjectionMatrix);
setTexture(0, mesh.textures[0], GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR);
setTexture(0, 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);
}
setTexture(1, static_cast<irr::video::COpenGLTexture*>(irr_driver->getRTT(RTT_TMP1))->getOpenGLTextureName(), GL_NEAREST, GL_NEAREST);
setTexture(2, static_cast<irr::video::COpenGLTexture*>(irr_driver->getRTT(RTT_TMP2))->getOpenGLTextureName(), GL_NEAREST, GL_NEAREST);
setTexture(3, static_cast<irr::video::COpenGLTexture*>(irr_driver->getRTT(RTT_SSAO))->getOpenGLTextureName(), GL_NEAREST, GL_NEAREST);
if (!UserConfigParams::m_ssao)
{
GLint swizzleMask[] = { GL_ONE, GL_ONE, GL_ONE, GL_ONE };
glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_RGBA, swizzleMask);
}
glUseProgram(MeshShader::ObjectRimLimitShader::Program);
MeshShader::ObjectRimLimitShader::setUniforms(ModelViewProjectionMatrix, TransposeInverseModelView, 0, 1, 2, 3);
glBindVertexArray(mesh.vao_second_pass);
glDrawElements(ptype, count, itype, 0);
}
void drawObjectUnlit(const GLMesh &mesh, const core::matrix4 &ModelViewProjectionMatrix)
{
GLenum ptype = mesh.PrimitiveType;
GLenum itype = mesh.IndexType;
size_t count = mesh.IndexCount;
setTexture(0, 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);
}
glUseProgram(MeshShader::ObjectUnlitShader::Program);
MeshShader::ObjectUnlitShader::setUniforms(ModelViewProjectionMatrix, 0);
glBindVertexArray(mesh.vao_second_pass);
glDrawElements(ptype, count, itype, 0);
}
void drawDetailledObjectPass2(const GLMesh &mesh, const core::matrix4 &ModelViewProjectionMatrix)
{
GLenum ptype = mesh.PrimitiveType;
GLenum itype = mesh.IndexType;
size_t count = mesh.IndexCount;
setTexture(0, 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);
}
setTexture(1, mesh.textures[1], GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR, true);
setTexture(2, static_cast<irr::video::COpenGLTexture*>(irr_driver->getRTT(RTT_TMP1))->getOpenGLTextureName(), GL_NEAREST, GL_NEAREST);
setTexture(3, static_cast<irr::video::COpenGLTexture*>(irr_driver->getRTT(RTT_TMP2))->getOpenGLTextureName(), GL_NEAREST, GL_NEAREST);
setTexture(4, static_cast<irr::video::COpenGLTexture*>(irr_driver->getRTT(RTT_SSAO))->getOpenGLTextureName(), GL_NEAREST, GL_NEAREST);
if (!UserConfigParams::m_ssao)
{
GLint swizzleMask[] = {GL_ONE, GL_ONE, GL_ONE, GL_ONE};
glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_RGBA, swizzleMask);
}
glUseProgram(MeshShader::DetailledObjectPass2Shader::Program);
MeshShader::DetailledObjectPass2Shader::setUniforms(ModelViewProjectionMatrix, 0, 1, 2, 3, 4);
glBindVertexArray(mesh.vao_second_pass);
glDrawElements(ptype, count, itype, 0);
}
void drawObjectPass2(const GLMesh &mesh, const core::matrix4 &ModelViewProjectionMatrix)
{
GLenum ptype = mesh.PrimitiveType;
GLenum itype = mesh.IndexType;
size_t count = mesh.IndexCount;
setTexture(0, 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);
}
setTexture(1, static_cast<irr::video::COpenGLTexture*>(irr_driver->getRTT(RTT_TMP1))->getOpenGLTextureName(), GL_NEAREST, GL_NEAREST);
setTexture(2, static_cast<irr::video::COpenGLTexture*>(irr_driver->getRTT(RTT_TMP2))->getOpenGLTextureName(), GL_NEAREST, GL_NEAREST);
setTexture(3, static_cast<irr::video::COpenGLTexture*>(irr_driver->getRTT(RTT_SSAO))->getOpenGLTextureName(), GL_NEAREST, GL_NEAREST);
if (!UserConfigParams::m_ssao)
{
GLint swizzleMask[] = { GL_ONE, GL_ONE, GL_ONE, GL_ONE };
glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_RGBA, swizzleMask);
}
glUseProgram(MeshShader::ObjectPass2Shader::Program);
MeshShader::ObjectPass2Shader::setUniforms(ModelViewProjectionMatrix, 0, 1, 2, 3);
glBindVertexArray(mesh.vao_second_pass);
glDrawElements(ptype, count, itype, 0);
}
void drawTransparentObject(const GLMesh &mesh, const core::matrix4 &ModelViewProjectionMatrix)
{
GLenum ptype = mesh.PrimitiveType;
GLenum itype = mesh.IndexType;
size_t count = mesh.IndexCount;
setTexture(0, mesh.textures[0], GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR, true);
glUseProgram(MeshShader::TransparentShader::Program);
MeshShader::TransparentShader::setUniforms(ModelViewProjectionMatrix, 0);
@ -419,7 +626,36 @@ void STKMesh::drawTransparentObject(const GLMesh &mesh)
glDrawElements(ptype, count, itype, 0);
}
void STKMesh::drawBubble(const GLMesh &mesh)
void drawTransparentFogObject(const GLMesh &mesh, const core::matrix4 &ModelViewProjectionMatrix)
{
GLenum ptype = mesh.PrimitiveType;
GLenum itype = mesh.IndexType;
size_t count = mesh.IndexCount;
const Track * const track = World::getWorld()->getTrack();
// This function is only called once per frame - thus no need for setters.
const float fogmax = track->getFogMax();
const float startH = track->getFogStartHeight();
const float endH = track->getFogEndHeight();
const float start = track->getFogStart();
const float end = track->getFogEnd();
const video::SColor tmpcol = track->getFogColor();
core::vector3df col(tmpcol.getRed() / 255.0f,
tmpcol.getGreen() / 255.0f,
tmpcol.getBlue() / 255.0f);
setTexture(0, mesh.textures[0], GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR, true);
glUseProgram(MeshShader::TransparentFogShader::Program);
MeshShader::TransparentFogShader::setUniforms(ModelViewProjectionMatrix, irr_driver->getInvProjMatrix(), fogmax, startH, endH, start, end, col, Camera::getCamera(0)->getCameraSceneNode()->getAbsolutePosition(), 0);
glBindVertexArray(mesh.vao_first_pass);
glDrawElements(ptype, count, itype, 0);
}
void drawBubble(const GLMesh &mesh, const core::matrix4 &ModelViewProjectionMatrix)
{
const float time = irr_driver->getDevice()->getTimer()->getTime() / 1000.0f;
float transparency = 1.;
@ -428,8 +664,7 @@ void STKMesh::drawBubble(const GLMesh &mesh)
GLenum itype = mesh.IndexType;
size_t count = mesh.IndexCount;
computeMVP(ModelViewProjectionMatrix);
setTexture(0, mesh.textures[0], GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR);
setTexture(0, mesh.textures[0], GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR, true);
glUseProgram(MeshShader::BubbleShader::Program);
MeshShader::BubbleShader::setUniforms(ModelViewProjectionMatrix, 0, time, transparency);
@ -441,10 +676,7 @@ void STKMesh::drawBubble(const GLMesh &mesh)
void STKMesh::drawGlow(const GLMesh &mesh)
{
ColorizeProvider * const cb = (ColorizeProvider *)irr_driver->getCallback(ES_COLORIZE);
glEnable(GL_DEPTH_TEST);
glDisable(GL_ALPHA_TEST);
glDepthMask(GL_FALSE);
glDisable(GL_BLEND);
GLenum ptype = mesh.PrimitiveType;
GLenum itype = mesh.IndexType;
size_t count = mesh.IndexCount;
@ -455,17 +687,12 @@ void STKMesh::drawGlow(const GLMesh &mesh)
glBindVertexArray(mesh.vao_glow_pass);
glDrawElements(ptype, count, itype, 0);
glBindVertexArray(0);
glBindBuffer(GL_ARRAY_BUFFER, 0);
}
void STKMesh::drawDisplace(const GLMesh &mesh)
{
DisplaceProvider * const cb = (DisplaceProvider *)irr_driver->getCallback(ES_DISPLACE);
glEnable(GL_DEPTH_TEST);
glDisable(GL_ALPHA_TEST);
glDepthMask(GL_FALSE);
glDisable(GL_BLEND);
GLenum ptype = mesh.PrimitiveType;
GLenum itype = mesh.IndexType;
size_t count = mesh.IndexCount;
@ -473,30 +700,26 @@ void STKMesh::drawDisplace(const GLMesh &mesh)
computeMVP(ModelViewProjectionMatrix);
core::matrix4 ModelViewMatrix = irr_driver->getVideoDriver()->getTransform(video::ETS_VIEW);
ModelViewMatrix *= irr_driver->getVideoDriver()->getTransform(video::ETS_WORLD);
setTexture(0, static_cast<irr::video::COpenGLTexture*>(irr_driver->getTexture(FileManager::TEXTURE, "displace.png"))->getOpenGLTextureName(), GL_LINEAR, GL_LINEAR);
setTexture(0, static_cast<irr::video::COpenGLTexture*>(irr_driver->getTexture(FileManager::TEXTURE, "displace.png"))->getOpenGLTextureName(), GL_LINEAR, GL_LINEAR, true);
glUseProgram(MeshShader::DisplaceShader::Program);
MeshShader::DisplaceShader::setUniforms(ModelViewProjectionMatrix, ModelViewMatrix, cb->getDirX(), cb->getDirY(), cb->getDir2X(), cb->getDir2Y(), 0);
glBindVertexArray(mesh.vao_displace_pass);
glDrawElements(ptype, count, itype, 0);
glBindVertexArray(0);
glBindBuffer(GL_ARRAY_BUFFER, 0);
}
void STKMesh::drawTransparent(const GLMesh &mesh, video::E_MATERIAL_TYPE type)
{
glEnable(GL_DEPTH_TEST);
glDisable(GL_ALPHA_TEST);
glDepthMask(GL_FALSE);
glEnable(GL_BLEND);
glBlendEquation(GL_FUNC_ADD);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glDisable(GL_CULL_FACE);
assert(irr_driver->getPhase() == TRANSPARENT_PASS);
if (type == video::EMT_TRANSPARENT_ALPHA_CHANNEL)
drawTransparentObject(mesh);
if (type == irr_driver->getShader(ES_BUBBLES))
drawBubble(mesh);
computeMVP(ModelViewProjectionMatrix);
if (type == irr_driver->getShader(ES_BUBBLES))
drawBubble(mesh, ModelViewProjectionMatrix);
else if (World::getWorld()->getTrack()->isFogEnabled())
drawTransparentFogObject(mesh, ModelViewProjectionMatrix);
else
drawTransparentObject(mesh, ModelViewProjectionMatrix);
return;
}
@ -504,49 +727,43 @@ void STKMesh::drawSolid(const GLMesh &mesh, video::E_MATERIAL_TYPE type)
{
switch (irr_driver->getPhase())
{
case 0:
case SOLID_NORMAL_AND_DEPTH_PASS:
{
irr_driver->getVideoDriver()->setRenderTarget(irr_driver->getRTT(RTT_NORMAL_AND_DEPTH), false, false);
windDir = getWind();
glStencilFunc(GL_ALWAYS, 0, ~0);
glEnable(GL_DEPTH_TEST);
glDisable(GL_ALPHA_TEST);
glDepthMask(GL_TRUE);
glDisable(GL_BLEND);
computeMVP(ModelViewProjectionMatrix);
computeTIMV(TransposeInverseModelView);
if (type == irr_driver->getShader(ES_NORMAL_MAP))
drawNormalPass(mesh);
drawNormalPass(mesh, ModelViewProjectionMatrix, TransposeInverseModelView);
else if (type == irr_driver->getShader(ES_OBJECTPASS_REF))
drawObjectRefPass1(mesh);
drawObjectRefPass1(mesh, ModelViewProjectionMatrix, TransposeInverseModelView);
else if (type == irr_driver->getShader(ES_GRASS) || type == irr_driver->getShader(ES_GRASS_REF))
drawGrassPass1(mesh);
drawGrassPass1(mesh, ModelViewProjectionMatrix, TransposeInverseModelView, windDir);
else
drawObjectPass1(mesh);
glStencilFunc(GL_ALWAYS, 1, ~0);
irr_driver->getVideoDriver()->setRenderTarget(irr_driver->getMainSetup(), false, false);
drawObjectPass1(mesh, ModelViewProjectionMatrix, TransposeInverseModelView);
break;
}
case 1:
case SOLID_LIT_PASS:
{
irr_driver->getVideoDriver()->setRenderTarget(irr_driver->getRTT(RTT_COLOR), false, false);
glEnable(GL_DEPTH_TEST);
glDisable(GL_ALPHA_TEST);
glDepthMask(GL_FALSE);
glDisable(GL_BLEND);
if (type == irr_driver->getShader(ES_SPHERE_MAP))
drawSphereMap(mesh);
drawSphereMap(mesh, ModelViewProjectionMatrix, TransposeInverseModelView);
else if (type == irr_driver->getShader(ES_SPLATTING))
drawSplatting(mesh);
drawSplatting(mesh, ModelViewProjectionMatrix);
else if (type == irr_driver->getShader(ES_OBJECTPASS_REF))
drawObjectRefPass2(mesh);
drawObjectRefPass2(mesh, ModelViewProjectionMatrix);
else if (type == irr_driver->getShader(ES_GRASS) || type == irr_driver->getShader(ES_GRASS_REF))
drawGrassPass2(mesh);
drawGrassPass2(mesh, ModelViewProjectionMatrix, windDir);
else if (type == irr_driver->getShader(ES_OBJECTPASS_RIMLIT))
drawObjectRimLimit(mesh, ModelViewProjectionMatrix, TransposeInverseModelView);
else if (type == irr_driver->getShader(ES_OBJECT_UNLIT))
drawObjectUnlit(mesh, ModelViewProjectionMatrix);
else if (mesh.textures[1] && type != irr_driver->getShader(ES_NORMAL_MAP))
drawDetailledObjectPass2(mesh, ModelViewProjectionMatrix);
else if (!mesh.textures[0])
drawUntexturedObject(mesh);
drawUntexturedObject(mesh, ModelViewProjectionMatrix);
else
drawObjectPass2(mesh);
drawObjectPass2(mesh, ModelViewProjectionMatrix);
break;
}
default:
@ -562,6 +779,8 @@ static bool isObject(video::E_MATERIAL_TYPE type)
return true;
if (type == irr_driver->getShader(ES_OBJECTPASS_REF))
return true;
if (type == irr_driver->getShader(ES_OBJECTPASS_RIMLIT))
return true;
if (type == irr_driver->getShader(ES_NORMAL_MAP))
return true;
if (type == irr_driver->getShader(ES_SPHERE_MAP))
@ -574,16 +793,22 @@ static bool isObject(video::E_MATERIAL_TYPE type)
return true;
if (type == irr_driver->getShader(ES_BUBBLES))
return true;
if (type == irr_driver->getShader(ES_OBJECT_UNLIT))
return true;
if (type == video::EMT_TRANSPARENT_ALPHA_CHANNEL)
return true;
if (type == video::EMT_ONETEXTURE_BLEND)
return true;
if (type == video::EMT_TRANSPARENT_ADD_COLOR)
return true;
return false;
}
static void initvaostate(GLMesh &mesh, video::E_MATERIAL_TYPE type)
void initvaostate(GLMesh &mesh, video::E_MATERIAL_TYPE type)
{
switch (irr_driver->getPhase())
{
case 0: // Solid Pass 1
case SOLID_NORMAL_AND_DEPTH_PASS:
if (mesh.vao_first_pass)
return;
if (type == irr_driver->getShader(ES_NORMAL_MAP))
@ -607,7 +832,7 @@ static void initvaostate(GLMesh &mesh, video::E_MATERIAL_TYPE type)
MeshShader::ObjectPass1Shader::attrib_position, -1, -1, MeshShader::ObjectPass1Shader::attrib_normal, -1, -1, -1, mesh.Stride);
}
return;
case 1: // Solid pass 2
case SOLID_LIT_PASS:
if (mesh.vao_second_pass)
return;
if (type == irr_driver->getShader(ES_SPHERE_MAP))
@ -625,11 +850,26 @@ static void initvaostate(GLMesh &mesh, video::E_MATERIAL_TYPE type)
mesh.vao_second_pass = createVAO(mesh.vertex_buffer, mesh.index_buffer,
MeshShader::ObjectRefPass2Shader::attrib_position, MeshShader::ObjectRefPass2Shader::attrib_texcoord, -1, -1, -1, -1, -1, mesh.Stride);
}
else if (type == irr_driver->getShader(ES_OBJECTPASS_RIMLIT))
{
mesh.vao_second_pass = createVAO(mesh.vertex_buffer, mesh.index_buffer,
MeshShader::ObjectRimLimitShader::attrib_position, MeshShader::ObjectRimLimitShader::attrib_texcoord, -1, MeshShader::ObjectRimLimitShader::attrib_normal, -1, -1, -1, mesh.Stride);
}
else if (type == irr_driver->getShader(ES_GRASS) || type == irr_driver->getShader(ES_GRASS_REF))
{
mesh.vao_second_pass = createVAO(mesh.vertex_buffer, mesh.index_buffer,
MeshShader::GrassPass2Shader::attrib_position, MeshShader::GrassPass2Shader::attrib_texcoord, -1, -1, -1, -1, MeshShader::GrassPass2Shader::attrib_color, mesh.Stride);
}
else if (type == irr_driver->getShader(ES_OBJECT_UNLIT))
{
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);
}
else if (mesh.textures[1])
{
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);
}
else if (!mesh.textures[0])
{
mesh.vao_second_pass = createVAO(mesh.vertex_buffer, mesh.index_buffer,
@ -641,12 +881,12 @@ static void initvaostate(GLMesh &mesh, video::E_MATERIAL_TYPE type)
MeshShader::ObjectPass2Shader::attrib_position, MeshShader::ObjectPass2Shader::attrib_texcoord, -1, -1, -1, -1, -1, mesh.Stride);
}
return;
case 2: // Glow
case GLOW_PASS:
if (mesh.vao_glow_pass)
return;
mesh.vao_glow_pass = createVAO(mesh.vertex_buffer, mesh.index_buffer, MeshShader::ColorizeShader::attrib_position, -1, -1, -1, -1, -1, -1, mesh.Stride);
return;
case 3: // Transparent
case TRANSPARENT_PASS:
if (mesh.vao_first_pass)
return;
if (type == irr_driver->getShader(ES_BUBBLES))
@ -654,13 +894,18 @@ static void initvaostate(GLMesh &mesh, video::E_MATERIAL_TYPE type)
mesh.vao_first_pass = createVAO(mesh.vertex_buffer, mesh.index_buffer,
MeshShader::BubbleShader::attrib_position, MeshShader::BubbleShader::attrib_texcoord, -1, -1, -1, -1, -1, mesh.Stride);
}
else if (type == video::EMT_TRANSPARENT_ALPHA_CHANNEL)
else if (World::getWorld()->getTrack()->isFogEnabled())
{
mesh.vao_first_pass = createVAO(mesh.vertex_buffer, mesh.index_buffer,
MeshShader::TransparentFogShader::attrib_position, MeshShader::TransparentFogShader::attrib_texcoord, -1, -1, -1, -1, -1, mesh.Stride);
}
else
{
mesh.vao_first_pass = createVAO(mesh.vertex_buffer, mesh.index_buffer,
MeshShader::TransparentShader::attrib_position, MeshShader::TransparentShader::attrib_texcoord, -1, -1, -1, -1, -1, mesh.Stride);
}
return;
case 4:
case DISPLACEMENT_PASS:
if (mesh.vao_displace_pass)
return;
mesh.vao_displace_pass = createVAO(mesh.vertex_buffer, mesh.index_buffer, MeshShader::DisplaceShader::attrib_position, MeshShader::DisplaceShader::attrib_texcoord, MeshShader::DisplaceShader::attrib_second_texcoord, -1, -1, -1, -1, mesh.Stride);
@ -695,7 +940,7 @@ void STKMesh::render()
if (isTransparentPass != transparent)
continue;
if (irr_driver->getPhase() == 4)
if (irr_driver->getPhase() == DISPLACEMENT_PASS)
{
initvaostate(GLmeshes[i], material.MaterialType);
drawDisplace(GLmeshes[i]);
@ -703,34 +948,27 @@ void STKMesh::render()
}
if (!isObject(material.MaterialType))
{
driver->setMaterial(material);
driver->drawMeshBuffer(mb);
#ifdef DEBUG
Log::warn("material", "Unhandled (static) material type : %d", material.MaterialType);
#endif
continue;
}
// only render transparent buffer if this is the transparent render pass
// and solid only in solid pass
if (irr_driver->getPhase() == 2)
if (irr_driver->getPhase() == GLOW_PASS)
{
initvaostate(GLmeshes[i], material.MaterialType);
drawGlow(GLmeshes[i]);
}
else
{
irr_driver->IncreaseObjectCount();
initvaostate(GLmeshes[i], material.MaterialType);
if (transparent)
drawTransparent(GLmeshes[i], material.MaterialType);
else
drawSolid(GLmeshes[i], material.MaterialType);
glBindVertexArray(0);
glBindBuffer(GL_ARRAY_BUFFER, 0);
video::SMaterial material;
material.MaterialType = irr_driver->getShader(ES_RAIN);
material.BlendOperation = video::EBO_NONE;
material.ZWriteEnable = true;
material.Lighting = false;
irr_driver->getVideoDriver()->setMaterial(material);
static_cast<irr::video::COpenGLDriver*>(irr_driver->getVideoDriver())->setRenderStates3DMode();
}
}
}

View File

@ -22,6 +22,34 @@ struct GLMesh {
size_t Stride;
};
GLuint createVAO(GLuint vbo, GLuint idx, GLuint attrib_position, GLuint attrib_texcoord, GLuint attrib_second_texcoord, GLuint attrib_normal, GLuint attrib_tangent, GLuint attrib_bitangent, GLuint attrib_color, size_t stride);
GLMesh allocateMeshBuffer(scene::IMeshBuffer* mb);
void initvaostate(GLMesh &mesh, video::E_MATERIAL_TYPE type);
void computeMVP(core::matrix4 &ModelViewProjectionMatrix);
void computeTIMV(core::matrix4 &TransposeInverseModelView);
// Pass 1 shader (ie shaders that outputs normals and depth)
void drawObjectPass1(const GLMesh &mesh, const core::matrix4 & ModelViewProjectionMatrix, const core::matrix4 &TransposeInverseModelView);
void drawNormalPass(const GLMesh &mesh, const core::matrix4 & ModelViewProjectionMatrix, const core::matrix4 &TransposeInverseModelView);
void drawObjectRefPass1(const GLMesh &mesh, const core::matrix4 & ModelViewProjectionMatrix, const core::matrix4 &TransposeInverseModelView);
void drawGrassPass1(const GLMesh &mesh, const core::matrix4 & ModelViewProjectionMatrix, const core::matrix4 &TransposeInverseModelView, core::vector3df windDir);
// Pass 2 shader (ie shaders that outputs final color)
void drawDetailledObjectPass2(const GLMesh &mesh, const core::matrix4 &ModelViewProjectionMatrix);
void drawObjectPass2(const GLMesh &mesh, const core::matrix4 &ModelViewProjectionMatrix);
void drawUntexturedObject(const GLMesh &mesh, const core::matrix4 &ModelViewProjectionMatrix);
void drawObjectRefPass2(const GLMesh &mesh, const core::matrix4 &ModelViewProjectionMatrix);
void drawSphereMap(const GLMesh &mesh, const core::matrix4 &ModelViewProjectionMatrix, const core::matrix4 &TransposeInverseModelView);
void drawSplatting(const GLMesh &mesh, const core::matrix4 &ModelViewProjectionMatrix);
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);
void drawObjectUnlit(const GLMesh &mesh, const core::matrix4 &ModelViewProjectionMatrix);
// Forward pass (for transparents meshes)
void drawTransparentObject(const GLMesh &mesh, const core::matrix4 &ModelViewProjectionMatrix);
void drawTransparentFogObject(const GLMesh &mesh, const core::matrix4 &ModelViewProjectionMatrix);
void drawBubble(const GLMesh &mesh, const core::matrix4 &ModelViewProjectionMatrix);
class STKMesh : public irr::scene::CMeshSceneNode
{
protected:
@ -31,33 +59,18 @@ protected:
void drawSolid(const GLMesh &mesh, video::E_MATERIAL_TYPE type);
void drawTransparent(const GLMesh &mesh, video::E_MATERIAL_TYPE type);
// Pass 1 shader (ie shaders that outputs normals and depth)
void drawObjectPass1(const GLMesh &mesh);
void drawNormalPass(const GLMesh &mesh);
void drawObjectRefPass1(const GLMesh &mesh);
void drawGrassPass1(const GLMesh &mesh);
// Pass 2 shader (ie shaders that outputs final color)
void drawSphereMap(const GLMesh &mesh);
void drawSplatting(const GLMesh &mesh);
void drawObjectPass2(const GLMesh &mesh);
void drawObjectRefPass2(const GLMesh &mesh);
void drawGrassPass2(const GLMesh &mesh);
void drawUntexturedObject(const GLMesh &mesh);
// Forward pass (for transparents meshes)
void drawTransparentObject(const GLMesh &mesh);
void drawBubble(const GLMesh &mesh);
// Misc passes shaders (glow, displace...)
void drawGlow(const GLMesh &mesh);
void drawDisplace(const GLMesh &mesh);
void createGLMeshes();
void cleanGLMeshes();
public:
STKMesh(irr::scene::IMesh* mesh, ISceneNode* parent, irr::scene::ISceneManager* mgr, irr::s32 id,
const irr::core::vector3df& position = irr::core::vector3df(0,0,0),
const irr::core::vector3df& rotation = irr::core::vector3df(0,0,0),
const irr::core::vector3df& scale = irr::core::vector3df(1.0f, 1.0f, 1.0f));
virtual void render();
virtual void setMesh(irr::scene::IMesh* mesh);
~STKMesh();
};

View File

@ -754,7 +754,6 @@ namespace GUIEngine
// ------------------------------------------------------------------------
Widget* getFocusForPlayer(const unsigned int playerID)
{
assert(playerID >= 0);
assert(playerID < MAX_PLAYER_COUNT);
return g_focus_for_player[playerID];
@ -773,7 +772,6 @@ namespace GUIEngine
bool isFocusedForPlayer(const Widget* w, const unsigned int playerID)
{
assert(w != NULL);
assert(playerID >= 0);
assert(playerID < MAX_PLAYER_COUNT);
// If no focus

View File

@ -47,20 +47,23 @@ using namespace GUIEngine;
// ----------------------------------------------------------------------------
ModalDialog::ModalDialog(const float percentWidth, const float percentHeight, ModalDialogLocation location)
ModalDialog::ModalDialog(const float percentWidth, const float percentHeight,
ModalDialogLocation location)
{
m_dialog_location = location;
m_init = false;
m_percent_width = percentWidth;
m_percent_height = percentHeight;
}
m_init = false;
m_percent_width = percentWidth;
m_percent_height = percentHeight;
m_irrlicht_window = NULL;
} // ModalDialog
// ----------------------------------------------------------------------------
void ModalDialog::loadFromFile(const char* xmlFile)
{
doInit();
std::string path = file_manager->getAssetChecked(FileManager::GUI,xmlFile, true);
std::string path = file_manager->getAssetChecked(FileManager::GUI,xmlFile,
true);
IXMLReader* xml = file_manager->createXMLReader(path);
Screen::parseScreenFileDiv(xml, m_widgets, m_irrlicht_window);
@ -75,7 +78,7 @@ void ModalDialog::loadFromFile(const char* xmlFile)
addWidgetsRecursively(m_widgets);
init();
}
} // loadFromFile
// ----------------------------------------------------------------------------
@ -86,7 +89,8 @@ void ModalDialog::doInit()
pointer_was_shown = irr_driver->isPointerShown();
irr_driver->showPointer();
const core::dimension2d<u32>& frame_size = GUIEngine::getDriver()->getCurrentRenderTargetSize();
const core::dimension2d<u32>& frame_size =
GUIEngine::getDriver()->getCurrentRenderTargetSize();
const int w = (int)(frame_size.Width* m_percent_width);
const int h = (int)(frame_size.Height* m_percent_height);
@ -122,18 +126,20 @@ void ModalDialog::doInit()
if (modalWindow != NULL)
{
delete modalWindow;
Log::warn("GUIEngine", "Showing a modal dialog while the previous one is still open. Destroying the previous dialog.");
Log::warn("GUIEngine", "Showing a modal dialog while the previous one "
"is still open. Destroying the previous dialog.");
}
modalWindow = this;
m_irrlicht_window = GUIEngine::getGUIEnv()->addWindow(m_area, true /* modal */);
m_irrlicht_window = GUIEngine::getGUIEnv()->addWindow(m_area,
true /* modal */);
GUIEngine::getSkin()->m_dialog = true;
GUIEngine::getSkin()->m_dialog_size = 0.0f;
m_previous_mode=input_manager->getMode();
input_manager->setMode(InputManager::MENU);
}
} // doInit
// ----------------------------------------------------------------------------
@ -162,7 +168,7 @@ ModalDialog::~ModalDialog()
// to the deleted widgets will be gone, but some widgets
// may want to perform additional cleanup at this time
elementsWereDeleted();
}
} // ~ModalDialog
// ----------------------------------------------------------------------------
@ -176,9 +182,10 @@ void ModalDialog::clearWindow()
elementsWereDeleted();
m_widgets.clearAndDeleteAll();
m_irrlicht_window->remove();
if(m_irrlicht_window)
m_irrlicht_window->remove();
m_irrlicht_window = GUIEngine::getGUIEnv()->addWindow( m_area, true /* modal */ );
}
} // clearWindow
// ----------------------------------------------------------------------------
@ -188,34 +195,34 @@ void ModalDialog::dismiss()
modalWindow = NULL;
if(GUIEngine::getCurrentScreen() != NULL)
GUIEngine::getCurrentScreen()->onDialogClose();
}
} // dismiss
// ----------------------------------------------------------------------------
void ModalDialog::onEnterPressed()
{
if(modalWindow != NULL) modalWindow->onEnterPressedInternal();
}
} // onEnterPressed
// ----------------------------------------------------------------------------
bool ModalDialog::isADialogActive()
{
return modalWindow != NULL;
}
} // isADialogActive
// ----------------------------------------------------------------------------
ModalDialog* ModalDialog::getCurrent()
{
return modalWindow;
}
} // getCurrent
// ----------------------------------------------------------------------------
void ModalDialog::onEnterPressedInternal()
{
}
} // onEnterPressedInternal
// ----------------------------------------------------------------------------

View File

@ -2144,6 +2144,8 @@ core::recti Skin::draw3DWindowBackground(IGUIElement *element,
const core::recti *clip,
core::recti* checkClientArea)
{
if (ModalDialog::getCurrent() == NULL) return rect;
drawBGFadeColor();
// draw frame

View File

@ -313,7 +313,6 @@ void DynamicRibbonWidget::buildInternalStructure()
elem->remove();
m_children.erase(i);
i--;
if (i<0) i = 0;
}
}
m_rows.clearWithoutDeleting(); // rows already deleted above, don't double-delete

View File

@ -42,6 +42,7 @@ ListWidget::ListWidget() : Widget(WTYPE_LIST)
m_selected_column = NULL;
m_sort_desc = false;
m_sort_default = true;
m_sort_col = 0;
}
// -----------------------------------------------------------------------------
@ -209,16 +210,16 @@ void ListWidget::addItem( const std::string& internal_name,
// -----------------------------------------------------------------------------
void ListWidget::addItem(const std::string& internal_name,
PtrVector<ListCell> * contents)
const std::vector<ListCell>& contents)
{
// May only be called AFTER this widget has been add()ed
assert(m_element != NULL);
ListItem newItem;
newItem.m_internal_name = internal_name;
for(int i = 0; i < (int)contents->size(); i++)
for (unsigned int i = 0; i < contents.size(); i++)
{
newItem.m_contents.push_back(*contents->get(i));
newItem.m_contents.push_back(contents[i]);
}
CGUISTKListBox* list = getIrrlichtElement<CGUISTKListBox>();

View File

@ -132,7 +132,7 @@ namespace GUIEngine
bool center = false);
void addItem( const std::string& internal_name,
PtrVector<ListCell> * contents);
const std::vector<ListCell>& contents);
/**
* \brief erases all items in the list

View File

@ -730,7 +730,6 @@ void RibbonWidget::setLabel(const unsigned int id, irr::core::stringw new_name)
// ignore this call for ribbons without labels
if (m_labels.size() == 0) return;
assert(id >= 0);
assert(id < m_labels.size());
m_labels[id].setText( new_name.c_str() );
m_text = new_name;

View File

@ -24,11 +24,13 @@
#include "config/player.hpp"
#include "config/user_config.hpp"
#include "graphics/irr_driver.hpp"
#include "input/wiimote_manager.hpp"
#include "io/file_manager.hpp"
#include "states_screens/kart_selection.hpp"
#include "states_screens/state_manager.hpp"
#include "utils/log.hpp"
#include "utils/translation.hpp"
#include "input/wiimote_manager.hpp"
#define INPUT_MODE_DEBUG 0
@ -56,18 +58,18 @@ bool DeviceManager::initialize()
if(UserConfigParams::logMisc())
{
printf("Initializing Device Manager\n");
printf("---------------------------\n");
Log::info("Device manager","Initializing Device Manager");
Log::info("-","---------------------------");
}
deserialize();
// Assign a configuration to the keyboard, or create one if we haven't yet
if(UserConfigParams::logMisc()) printf("Initializing keyboard support.\n");
if(UserConfigParams::logMisc()) Log::info("Device manager","Initializing keyboard support.");
if (m_keyboard_configs.size() == 0)
{
if(UserConfigParams::logMisc())
printf("No keyboard configuration exists, creating one.\n");
Log::info("Device manager","No keyboard configuration exists, creating one.");
m_keyboard_configs.push_back(new KeyboardConfig());
created = true;
}
@ -79,13 +81,13 @@ bool DeviceManager::initialize()
}
if(UserConfigParams::logMisc())
printf("Initializing gamepad support.\n");
Log::info("Device manager","Initializing gamepad support.");
irr_driver->getDevice()->activateJoysticks(m_irrlicht_gamepads);
int num_gamepads = m_irrlicht_gamepads.size();
if(UserConfigParams::logMisc())
{
printf("Irrlicht reports %d gamepads are attached to the system.\n",
Log::info("Device manager","Irrlicht reports %d gamepads are attached to the system.",
num_gamepads);
}
@ -109,19 +111,19 @@ bool DeviceManager::initialize()
if (UserConfigParams::logMisc())
{
printf("#%d: %s detected...", id, name.c_str());
Log::info("Device manager","#%d: %s detected...", id, name.c_str());
}
// Returns true if new configuration was created
if (getConfigForGamepad(id, name, &gamepadConfig) == true)
{
if(UserConfigParams::logMisc())
printf("creating new configuration.\n");
Log::info("Device manager","creating new configuration.");
created = true;
}
else
{
if(UserConfigParams::logMisc())
printf("using existing configuration.\n");
Log::info("Device manager","using existing configuration.");
}
gamepadConfig->setPlugged();
@ -440,12 +442,12 @@ bool DeviceManager::deserialize()
static std::string filepath = file_manager->getUserConfigFile(INPUT_FILE_NAME);
if(UserConfigParams::logMisc())
printf("Deserializing input.xml...\n");
Log::info("Device manager","Deserializing input.xml...");
if(!file_manager->fileExists(filepath))
{
if(UserConfigParams::logMisc())
printf("Warning: no configuration file exists.\n");
Log::warn("Device manager","No configuration file exists.");
}
else
{
@ -499,15 +501,15 @@ bool DeviceManager::deserialize()
{
if(keyboard_config != NULL)
if(!keyboard_config->deserializeAction(xml))
std::cerr << "Ignoring an ill-formed keyboard action in input config.\n";
Log::error("Device manager","Ignoring an ill-formed keyboard action in input config.");
}
else if(reading_now == GAMEPAD)
{
if(gamepad_config != NULL)
if(!gamepad_config->deserializeAction(xml))
std::cerr << "Ignoring an ill-formed gamepad action in input config.\n";
Log::error("Device manager","Ignoring an ill-formed gamepad action in input config.");
}
else std::cerr << "Warning: An action is placed in an unexpected area in the input config file.\n";
else Log::warn("Device manager","An action is placed in an unexpected area in the input config file.");
}
}
break;
@ -534,7 +536,7 @@ bool DeviceManager::deserialize()
if(UserConfigParams::logMisc())
{
printf("Found %d keyboard and %d gamepad configurations.\n",
Log::info("Device manager","Found %d keyboard and %d gamepad configurations.",
m_keyboard_configs.size(), m_gamepad_configs.size());
}
@ -557,7 +559,7 @@ bool DeviceManager::deserialize()
void DeviceManager::serialize()
{
static std::string filepath = file_manager->getUserConfigFile(INPUT_FILE_NAME);
if(UserConfigParams::logMisc()) printf("Serializing input.xml...\n");
if(UserConfigParams::logMisc()) Log::info("Device manager","Serializing input.xml...");
std::ofstream configfile;
@ -565,8 +567,7 @@ void DeviceManager::serialize()
if(!configfile.is_open())
{
std::cerr << "Failed to open " << filepath.c_str()
<< " for writing, controls won't be saved\n";
Log::error("Device manager","Failed to open %s for writing, controls won't be saved",filepath.c_str());
return;
}
@ -584,7 +585,7 @@ void DeviceManager::serialize()
configfile << "</input>\n";
configfile.close();
if(UserConfigParams::logMisc()) printf("Serialization complete.\n\n");
if(UserConfigParams::logMisc()) Log::info("Device manager","Serialization complete.");
} // serialize
// -----------------------------------------------------------------------------

View File

@ -79,7 +79,7 @@ struct Input
Input()
: m_type(IT_NONE), m_device_id(0), m_button_id(0),
m_axis_direction(0), m_character(0)
m_axis_direction(0), m_axis_range(Input::AR_FULL), m_character(0)
{
// Nothing to do.
}
@ -109,7 +109,7 @@ struct Input
*/
Input(InputType ntype, int deviceID , int btnID = 0, int axisDirection= 0)
: m_type(ntype), m_device_id(deviceID), m_button_id(btnID),
m_axis_direction(axisDirection)
m_axis_direction(axisDirection), m_axis_range(Input::AR_FULL)
{
// Nothing to do.
}

View File

@ -258,24 +258,16 @@ bool GamePadDevice::processAndMapInput(Input::InputType type, const int id,
if (!m_axis_ok[id]) return false;
}
if (m_configuration != NULL)
if (mode == InputManager::INGAME)
{
if (mode == InputManager::INGAME)
{
success = m_configuration->getGameAction(type, id, value, action);
}
else if (abs(*value) > Input::MAX_VALUE/2)
{
// bindings can only be accessed in game and menu modes
assert(mode == InputManager::MENU);
success = m_configuration->getMenuAction(type, id, value, action);
}
success = m_configuration->getGameAction(type, id, value, action);
}
else
else if (abs(*value) > Input::MAX_VALUE/2)
{
fprintf(stderr, "processAndMapInput() called on improperly "
"initialized GamePadDevice\n");
abort();
// bindings can only be accessed in game and menu modes
assert(mode == InputManager::MENU);
success = m_configuration->getMenuAction(type, id, value, action);
}
return success;

View File

@ -53,6 +53,7 @@ Attachment::Attachment(AbstractKart* kart)
m_bomb_sound = NULL;
m_bubble_explode_sound = NULL;
m_node_scale = 1.0f;
m_initial_speed = 0.0f;
// If we attach a NULL mesh, we get a NULL scene node back. So we
// have to attach some kind of mesh, but make it invisible.

View File

@ -46,10 +46,6 @@ class Flyable : public Moveable, public TerrainInfo
public:
private:
bool m_has_hit_something;
/** This flag is used to avoid that a rocket explodes mode than once.
* It can happen that more than one collision between a rocket and
* a track or kart is reported by the physics. */
bool m_exploded;
/** If this flag is set, the up velocity of the kart will not be
* adjusted in case that the objects is too high or too low above the

View File

@ -187,9 +187,6 @@ private:
/** A 'ping' sound effect to be played when the ball hits the ground. */
SFXBase *m_ping_sfx;
/** Sound effect to be played when a ball hits a kart. */
SFXBase *m_hit_sfx;
void computeTarget();
void updateDistanceToTarget();
unsigned int getSuccessorToHitTarget(unsigned int node_index,

View File

@ -42,8 +42,7 @@ private:
RB_TO_KART, /**< Rubber band is attached to a kart hit. */
RB_TO_TRACK} /**< Rubber band is attached to track. */
m_attached_state;
/** True if plunger was fired backwards. */
bool m_is_backward;
/** If rubber band is attached to track, the coordinates. */
Vec3 m_hit_position;
/** The plunger the rubber band is attached to. */

View File

@ -856,8 +856,7 @@ bool SkiddingAI::handleSelectedItem(float kart_aim_angle, Vec3 *aim_point)
// If the item is unavailable or has been switched into a bad item
// stop aiming for it.
if(m_item_to_collect->getDisableTime()>0 ||
m_item_to_collect->getType() == Item::ITEM_BANANA ||
m_item_to_collect->getType() == Item::ITEM_BANANA )
m_item_to_collect->getType() == Item::ITEM_BANANA )
return false;
const Vec3 &xyz = m_item_to_collect->getXYZ();
@ -1066,7 +1065,7 @@ void SkiddingAI::evaluateItems(const Item *item, float kart_aim_angle,
// fall through: if we have enough space to store a big
// container, we can also store a small container, and
// finally fall through to the bonus box code.
case Item::ITEM_NITRO_SMALL: avoid = false; break;
case Item::ITEM_NITRO_SMALL: avoid = false;
// Only collect nitro, if it can actually be stored.
if (m_kart->getEnergy() +
m_kart->getKartProperties()->getNitroSmallContainer()
@ -2359,7 +2358,7 @@ void SkiddingAI::setSteering(float angle, float dt)
m_controls->m_skid = KartControl::SC_NONE;
#ifdef DEBUG
if(m_ai_debug)
Log::info("SkiddingAI", "'%s' wrong steering, stop skid.\n",
Log::info("SkiddingAI", "'%s' wrong steering, stop skid.",
m_kart->getIdent().c_str());
#endif
}
@ -2374,7 +2373,7 @@ void SkiddingAI::setSteering(float angle, float dt)
{
#ifdef DEBUG
if(m_ai_debug)
Log::info("SkiddingAI", "%s steering too much (%f).\n",
Log::info("SkiddingAI", "%s steering too much (%f).",
m_kart->getIdent().c_str(), steer_fraction);
#endif
m_controls->m_skid = KartControl::SC_NONE;

View File

@ -409,7 +409,7 @@ void Kart::reset()
}
m_terrain_info->update(getXYZ());
m_terrain_info->update(getTrans());
// Reset is also called when the kart is created, at which time
// m_controller is not yet defined, so this has to be tested here.
@ -1102,16 +1102,19 @@ void Kart::update(float dt)
if (!m_flying)
{
// When really on air, free fly, when near ground, try to glide / adjust for landing
// If zipped, be stable, so ramp+zipper can allow nice jumps without scripting the fly
if(!isNearGround() &&
m_max_speed->getSpeedIncreaseTimeLeft(MaxSpeed::MS_INCREASE_ZIPPER)<=0.0f )
// When really on air, free fly, when near ground, try to glide /
// adjust for landing. If zipped, be stable, so ramp+zipper can
// allow nice jumps without scripting the fly
// Also disable he upright constraint when gravity is changed by
// the terrain
if( (!isNearGround() &&
m_max_speed->getSpeedIncreaseTimeLeft(MaxSpeed::MS_INCREASE_ZIPPER)<=0.0f ) ||
(getMaterial() && getMaterial()->hasGravity()) )
m_uprightConstraint->setLimit(M_PI);
else
m_uprightConstraint->setLimit(m_kart_properties->getUprightTolerance());
}
// TODO: hiker said this probably will be moved to btKart or so when updating bullet engine.
// Neutralize any yaw change if the kart leaves the ground, so the kart falls more or less
// straight after jumping, but still allowing some "boat shake" (roll and pitch).
@ -1177,22 +1180,27 @@ void Kart::update(float dt)
m_skid_sound->position ( getXYZ() );
m_boing_sound->position ( getXYZ() );
// Check if a kart is (nearly) upside down and not moving much --> automatic rescue
if(World::getWorld()->getTrack()->isAutoRescueEnabled() &&
// Check if a kart is (nearly) upside down and not moving much -->
// automatic rescue
// But only do this if auto-rescue is enabled (i.e. it will be disabled in
// battle mode), and the material the kart is driving on does not have
// gravity (which can
if(World::getWorld()->getTrack()->isAutoRescueEnabled() &&
(!m_terrain_info->getMaterial() ||
!m_terrain_info->getMaterial()->hasGravity()) &&
!getKartAnimation() && fabs(getRoll())>60*DEGREE_TO_RAD &&
fabs(getSpeed())<3.0f )
{
new RescueAnimation(this, /*is_auto_rescue*/true);
}
btTransform trans=getTrans();
// Add a certain epsilon (0.3) to the height of the kart. This avoids
// problems of the ray being cast from under the track (which happened
// e.g. on tux tollway when jumping down from the ramp, when the chassis
// partly tunnels through the track). While tunneling should not be
// happening (since Z velocity is clamped), the epsilon is left in place
// just to be on the safe side (it will not hit the chassis itself).
Vec3 pos_plus_epsilon = trans.getOrigin()+btVector3(0,0.3f,0);
Vec3 epsilon(0,0.3f,0);
// Make sure that the ray doesn't hit the kart. This is done by
// resetting the collision filter group, so that this collision
@ -1203,7 +1211,8 @@ void Kart::update(float dt)
old_group = m_body->getBroadphaseHandle()->m_collisionFilterGroup;
m_body->getBroadphaseHandle()->m_collisionFilterGroup = 0;
}
m_terrain_info->update(pos_plus_epsilon);
m_terrain_info->update(getTrans(), epsilon);
if(m_body->getBroadphaseHandle())
{
m_body->getBroadphaseHandle()->m_collisionFilterGroup = old_group;
@ -1212,6 +1221,10 @@ void Kart::update(float dt)
const Material* material=m_terrain_info->getMaterial();
if (!material) // kart falling off the track
{
Vec3 gravity(0, -9.8f, 0);
btRigidBody *body = getVehicle()->getRigidBody();
body->setGravity(gravity);
// let kart fall a bit before rescuing
const Vec3 *min, *max;
World::getWorld()->getTrack()->getAABB(&min, &max);
@ -1221,6 +1234,16 @@ void Kart::update(float dt)
}
else
{
Vec3 gravity(0.0f, -9.8f, 0.0f);
btRigidBody *body = getVehicle()->getRigidBody();
// If the material should overwrite the gravity,
if(material->hasGravity())
{
Vec3 normal = m_terrain_info->getNormal();
gravity = normal * -9.8f;
}
body->setGravity(gravity);
handleMaterialSFX(material);
if (material->isDriveReset() && isOnGround())
new RescueAnimation(this);
@ -1237,7 +1260,7 @@ void Kart::update(float dt)
#ifdef DEBUG
if(UserConfigParams::m_material_debug)
{
Log::info("Kart","%s\tfraction %f\ttime %f.\n",
Log::info("Kart","%s\tfraction %f\ttime %f.",
material->getTexFname().c_str(),
material->getMaxSpeedFraction(),
material->getSlowDownTime() );
@ -1704,7 +1727,7 @@ void Kart::crashed(const Material *m, const Vec3 &normal)
// Add a counter to make it easier to see if a new line of
// output was added.
static int counter=0;
Log::info("Kart","Kart %s hit track: %d material %s.\n",
Log::info("Kart","Kart %s hit track: %d material %s.",
getIdent().c_str(), counter++,
m ? m->getTexFname().c_str() : "None");
}
@ -1805,7 +1828,7 @@ void Kart::crashed(const Material *m, const Vec3 &normal)
m_body->applyCentralImpulse( -4000.0f*push );
m_bounce_back_time = 2.0f;
core::stringw msg = _("You need more points\nto enter this challenge!");
core::stringw msg = _("You need more points\nto enter this challenge!\nCheck the minimap for\navailable challenges.");
std::vector<core::stringw> parts = StringUtils::split(msg, '\n', false);
// For now, until we have scripting, special-case the overworld... (TODO)
@ -2038,7 +2061,7 @@ void Kart::updatePhysics(float dt)
updateEngineSFX();
#ifdef XX
Log::info("Kart","forward %f %f %f %f side %f %f %f %f angVel %f %f %f heading %f\n"
Log::info("Kart","forward %f %f %f %f side %f %f %f %f angVel %f %f %f heading %f"
,m_vehicle->m_forwardImpulse[0]
,m_vehicle->m_forwardImpulse[1]
,m_vehicle->m_forwardImpulse[2]
@ -2565,16 +2588,17 @@ void Kart::setOnScreenText(const wchar_t *text)
// FIXME: Titlefont is the only font guaranteed to be loaded if STK
// is started without splash screen (since "Loading" is shown even in this
// case). A smaller font would be better
sm->addBillboardTextSceneNode(GUIEngine::getFont() ? GUIEngine::getFont()
// TODO: Add support in the engine for BillboardText or find a replacement
/*sm->addBillboardTextSceneNode(GUIEngine::getFont() ? GUIEngine::getFont()
: GUIEngine::getTitleFont(),
text,
getNode(),
core::dimension2df(textsize.Width/55.0f,
textsize.Height/55.0f),
core::vector3df(0.0f, 1.5f, 0.0f),
-1 /* id */,
-1, // id
video::SColor(255, 255, 225, 0),
video::SColor(255, 255, 89, 0));
video::SColor(255, 255, 89, 0));*/
// No need to store the reference to the billboard scene node:
// It has one reference to the parent, and will get deleted
// when the parent is deleted.

View File

@ -255,8 +255,8 @@ public:
/** Returns the position of a wheel relative to the kart.
* \param i Index of the wheel: 0=front right, 1 = front left, 2 = rear
* right, 3 = rear left. */
const Vec3& getWheelGraphicsPosition(int i) const
{assert(i>=0 && i<4); return m_wheel_graphics_position[i];}
const Vec3& getWheelGraphicsPosition(unsigned int i) const
{assert(i<4); return m_wheel_graphics_position[i];}
// ------------------------------------------------------------------------
/** Returns the position of wheels relative to the kart.
*/
@ -268,20 +268,20 @@ public:
* karts more stable.
* \param i Index of the wheel: 0=front right, 1 = front left, 2 = rear
* right, 3 = rear left. */
const Vec3& getWheelPhysicsPosition(int i) const
{assert(i>=0 && i<4); return m_wheel_physics_position[i];}
const Vec3& getWheelPhysicsPosition(unsigned int i) const
{assert(i<4); return m_wheel_physics_position[i];}
// ------------------------------------------------------------------------
/** Returns the radius of the graphical wheels.
* \param i Index of the wheel: 0=front right, 1 = front left, 2 = rear
* right, 3 = rear left. */
float getWheelGraphicsRadius(int i) const
{assert(i>=0 && i<4); return m_wheel_graphics_radius[i]; }
float getWheelGraphicsRadius(unsigned int i) const
{assert(i<4); return m_wheel_graphics_radius[i]; }
// ------------------------------------------------------------------------
/** Returns the position of nitro emitter relative to the kart.
* \param i Index of the emitter: 0 = right, 1 = left
*/
const Vec3& getNitroEmittersPositon(unsigned int i) const
{ assert(i>=0 && i<2); return m_nitro_emitter_position[i]; }
{ assert(i<2); return m_nitro_emitter_position[i]; }
// ------------------------------------------------------------------------
/** Returns true if kart has nitro emitters */
const bool hasNitroEmitters() const

View File

@ -64,6 +64,9 @@ void KartPropertiesManager::addKartSearchDir(const std::string &s)
} // addKartSearchDir
//-----------------------------------------------------------------------------
/** Removes all karts from the KartPropertiesManager, so that they can be
* reloade. This is necessary after a change of the screen resolution.
*/
void KartPropertiesManager::unloadAllKarts()
{
m_karts_properties.clearAndDeleteAll();
@ -71,23 +74,8 @@ void KartPropertiesManager::unloadAllKarts()
m_kart_available.clear();
m_groups_2_indices.clear();
m_all_groups.clear();
m_kart_search_path.clear();
} // unloadAllKarts
//-----------------------------------------------------------------------------
/** Reloads all karts, i.e. reloads the meshes and textures. This is used
* when changing the screen resolution.
*/
void KartPropertiesManager::reLoadAllKarts()
{
m_karts_properties.clearAndDeleteAll();
m_selected_karts.clear();
m_kart_available.clear();
m_groups_2_indices.clear();
m_all_groups.clear();
loadAllKarts(false);
} // reLoadAllKarts
//-----------------------------------------------------------------------------
/** Remove a kart from the kart manager.
* \param id The kart id (i.e. name of the directory) to remove.

View File

@ -77,7 +77,6 @@ public:
bool loadKart (const std::string &dir);
void loadAllKarts (bool loading_icon = true);
void unloadAllKarts ();
void reLoadAllKarts ();
void removeKart(const std::string &id);
const std::vector<int> getKartsInGroup (const std::string& g);
bool kartAvailable(int kartid);

View File

@ -180,14 +180,12 @@ float Skidding::getSteeringWhenSkidding(float steering) const
float f = (steering - m_skid_reduce_turn_min)
/ m_skid_reduce_turn_delta;
return f *2.0f-1.0f;
break;
}
case SKID_ACCUMULATE_LEFT:
{
float f = (steering + m_skid_reduce_turn_min)
/ m_skid_reduce_turn_delta;
return 2.0f * f +1.0f;
break;
}
} // switch m_skid_state
return 0; // keep compiler quiet

View File

@ -45,6 +45,7 @@ m_frame_count(0)
{
m_curr_time = 0;
m_prev_time = 0;
m_throttle_fps = true;
} // MainLoop
//-----------------------------------------------------------------------------
@ -78,12 +79,14 @@ float MainLoop::getLimitedDt()
// When in menus, reduce FPS much, it's not necessary to push to the maximum for plain menus
const int max_fps = (StateManager::get()->throttleFPS() ? 35 : UserConfigParams::m_max_fps);
const int current_fps = (int)(1000.0f/dt);
if( current_fps > max_fps && !ProfileWorld::isProfileMode())
if (m_throttle_fps && current_fps > max_fps && !ProfileWorld::isProfileMode())
{
int wait_time = 1000/max_fps - 1000/current_fps;
if(wait_time < 1) wait_time = 1;
PROFILER_PUSH_CPU_MARKER("Throttle framerate", 0, 0, 0);
StkTime::sleep(wait_time);
PROFILER_POP_CPU_MARKER();
}
else break;
}
@ -122,7 +125,9 @@ void MainLoop::run()
if (World::getWorld()) // race is active if world exists
{
PROFILER_PUSH_CPU_MARKER("Update race", 0, 255, 255);
updateRace(dt);
PROFILER_POP_CPU_MARKER();
} // if race is active
// We need to check again because update_race may have requested
@ -132,18 +137,15 @@ void MainLoop::run()
// enabled.
if (!m_abort && !ProfileWorld::isNoGraphics())
{
PROFILER_PUSH_CPU_MARKER("Music manager update", 0x7F, 0x00, 0x00);
PROFILER_PUSH_CPU_MARKER("Music/input/GUI", 0x7F, 0x00, 0x00);
music_manager->update(dt);
PROFILER_POP_CPU_MARKER();
PROFILER_PUSH_CPU_MARKER("Input manager update", 0x00, 0x7F, 0x00);
input_manager->update(dt);
PROFILER_POP_CPU_MARKER();
#ifdef ENABLE_WIIUSE
wiimote_manager->update();
#endif
PROFILER_PUSH_CPU_MARKER("Update GUI widgets", 0x7F, 0x7F, 0x00);
GUIEngine::update(dt);
PROFILER_POP_CPU_MARKER();

View File

@ -29,6 +29,7 @@ class MainLoop
{
private:
bool m_abort;
bool m_throttle_fps;
int m_frame_count;
Uint32 m_curr_time;
@ -40,6 +41,7 @@ public:
~MainLoop();
void run();
void abort();
void setThrottleFPS(bool throttle) { m_throttle_fps = throttle; }
// ------------------------------------------------------------------------
/** Returns true if STK is to be stoppe. */
bool isAborted() const { return m_abort; }

View File

@ -164,15 +164,6 @@ void OverWorld::getKartsDisplayInfo(
assert(false);
} // getKartsDisplayInfo
//-----------------------------------------------------------------------------
/** Override the base class method to change behavior. We don't want wrong
* direction messages in the overworld since there is no direction there.
* \param i Kart id.
*/
void OverWorld::checkForWrongDirection(unsigned int i)
{
} // checkForWrongDirection
//-----------------------------------------------------------------------------
void OverWorld::createRaceGUI()

View File

@ -54,8 +54,6 @@ public:
/** Returns if this race mode has laps. */
virtual bool raceHasLaps() OVERRIDE { return false; }
// ------------------------------------------------------------------------
virtual void checkForWrongDirection(unsigned int i) OVERRIDE;
// ------------------------------------------------------------------------
/** The overworld is not a race per se so it's never over */
virtual bool isRaceOver() OVERRIDE { return false; }
// ------------------------------------------------------------------------

View File

@ -116,7 +116,7 @@ void SoccerWorld::reset()
continue;
obj->reset();
obj->getPhysics()->reset();
obj->getPhysicalObject()->reset();
}
if (m_goal_sound != NULL &&
@ -205,7 +205,7 @@ void SoccerWorld::onCheckGoalTriggered(bool first_goal)
continue;
obj->reset();
obj->getPhysics()->reset();
obj->getPhysicalObject()->reset();
}
//Resetting the ball triggers the goal check line one more time.

View File

@ -354,7 +354,7 @@ void ThreeStrikesBattle::update(float dt)
getTrack()->getTrackObjectManager()->insertObject(tire_obj);
// FIXME: orient the force relative to kart orientation
tire_obj->getPhysics()->getBody()
tire_obj->getPhysicalObject()->getBody()
->applyCentralForce(btVector3(60.0f, 0.0f, 0.0f));
m_insert_tire--;

View File

@ -953,7 +953,6 @@ void World::updateHighscores(int* best_highscore_rank, int* best_finish_time,
continue;
if (!m_karts[index[pos]]->hasFinishedRace()) continue;
assert(index[pos] >= 0);
assert(index[pos] < m_karts.size());
Kart *k = (Kart*)m_karts[index[pos]];

View File

@ -202,7 +202,7 @@ public:
// ------------------------------------------------------------------------
/** Returns the number of rescue positions on a given track and game
* mode. */
virtual unsigned int getNumberOfRescuePositions() const OVERRIDE = 0;
virtual unsigned int getNumberOfRescuePositions() const = 0;
// ------------------------------------------------------------------------
/** Determines the rescue position index of the specified kart. */
virtual unsigned int getRescuePositionIndex(AbstractKart *kart) = 0;

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