Merge branch 'master' of github.com:supertuxkart/stk-code

This commit is contained in:
hiker 2014-08-11 13:20:07 +10:00
commit 7684ee74bd
22 changed files with 422 additions and 335 deletions

View File

@ -1,7 +1,40 @@
<?xml version="1.0" encoding="UTF-8"?>
<stkgui>
<div x="2%" y="10%" width="96%" height="80%" layout="vertical-row" >
<label id="title" width="100%"/>
<gauge id="value_slider" min_value="0" max_value="100" width="100%" />
<div proportion="1" width="100%" layout="horizontal-row">
<label id="Red" text="Red"/>
<spacer width="25"/>
<gauge id="red_slider" min_value="0" max_value="100" proportion="1"/>
</div>
<div proportion="1" width="100%" layout="horizontal-row">
<label id="Green" text="Green"/>
<spacer width="25"/>
<gauge id="green_slider" min_value="0" max_value="100" proportion="1"/>
</div>
<div proportion="1" width="100%" layout="horizontal-row">
<label id="Blue" text="Blue"/>
<spacer width="25"/>
<gauge id="blue_slider" min_value="0" max_value="100" proportion="1"/>
</div>
<div proportion="1" width="100%" layout="horizontal-row">
<label id="SSAO radius" text="SSAO Radius"/>
<spacer width="50"/>
<gauge id="ssao_radius" min_value="0" max_value="100" proportion="1" />
</div>
<div proportion="1" width="100%" layout="horizontal-row">
<label id="SSAO k" text="SSAO K"/>
<spacer width="25"/>
<gauge id="ssao_k" min_value="0" max_value="100" proportion="1"/>
</div>
<div proportion="1" width="100%" layout="horizontal-row">
<label id="SSAO Sigma" text="SSAO sigma"/>
<spacer width="50"/>
<gauge id="ssao_sigma" min_value="0" max_value="100" proportion="1"/>
</div>
</div>
</stkgui>

View File

@ -0,0 +1,22 @@
layout(triangles) in;
layout(line_strip, max_vertices = 6) out;
in vec3 nor[];
void main()
{
for(int i=0; i < gl_in.length(); i++)
{
vec4 pos = gl_in[i].gl_Position;
gl_Position = pos;
EmitVertex();
vec3 normal = normalize(nor[i]);
pos = inverse(ProjectionMatrix) * pos;
pos /= pos.w;
gl_Position = ProjectionMatrix * (pos + .2 * vec4(normal, 0.));
EmitVertex();
EndPrimitive();
}
}

View File

@ -3,10 +3,6 @@ uniform sampler2D tex_detail0;
uniform sampler2D tex_detail1;
uniform sampler2D tex_detail2;
uniform sampler2D tex_detail3;
uniform sampler2D DiffuseMap;
uniform sampler2D SpecularMap;
uniform sampler2D SSAO;
uniform vec3 ambient;
#if __VERSION__ >= 130
in vec2 uv;
@ -18,26 +14,22 @@ varying vec2 uv_bis;
#define FragColor gl_FragColor
#endif
vec3 getLightFactor(float specMapValue);
void main() {
// Splatting part
vec4 splatting = texture(tex_layout, uv_bis);
vec4 detail0 = texture(tex_detail0, uv);
vec4 detail1 = texture(tex_detail1, uv);
vec4 detail2 = texture(tex_detail2, uv);
vec4 detail3 = texture(tex_detail3, uv);
vec4 detail4 = vec4(0.0);
// Splatting part
vec4 splatting = texture(tex_layout, uv_bis);
vec4 detail0 = texture(tex_detail0, uv);
vec4 detail1 = texture(tex_detail1, uv);
vec4 detail2 = texture(tex_detail2, uv);
vec4 detail3 = texture(tex_detail3, uv);
vec4 detail4 = vec4(0.0);
vec4 splatted = splatting.r * detail0 +
splatting.g * detail1 +
splatting.b * detail2 +
max(0., (1.0 - splatting.r - splatting.g - splatting.b)) * detail3;
vec4 splatted = splatting.r * detail0 +
splatting.g * detail1 +
splatting.b * detail2 +
max(0., (1.0 - splatting.r - splatting.g - splatting.b)) * detail3;
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;
FragColor = vec4(splatted.xyz * LightFactor, 1.);
vec3 LightFactor = getLightFactor(1.);
FragColor = vec4(splatted.xyz * LightFactor, 1.);
}

View File

@ -2,15 +2,14 @@
// and improvements here http://graphics.cs.williams.edu/papers/SAOHPG12/
uniform sampler2D dtex;
uniform vec4 samplePoints[16];
uniform float radius = 1.;
uniform float k = 1.5;
uniform float sigma = 1.;
out float AO;
const float sigma = 1.;
const float tau = 7.;
const float beta = 0.002;
const float epsilon = .00001;
const float radius = 1.;
const float k = 1.5;
#define SAMPLES 16

View File

@ -669,7 +669,6 @@ void Camera::activate()
{
irr::scene::ISceneManager *sm = irr_driver->getSceneManager();
sm->setActiveCamera(m_camera);
sm->setAmbientLight(m_ambient_light);
irr_driver->getVideoDriver()->setViewPort(m_viewport);
} // activate

View File

@ -1621,11 +1621,17 @@ void IrrDriver::onUnloadWorld()
/** Sets the ambient light.
* \param light The colour of the light to set.
*/
void IrrDriver::setAmbientLight(const video::SColor &light)
void IrrDriver::setAmbientLight(const video::SColorf &light)
{
m_scene_manager->setAmbientLight(light);
m_SH_dirty = true;
} // setAmbientLight
video::SColorf IrrDriver::getAmbientLight() const
{
return m_scene_manager->getAmbientLight();
}
// ----------------------------------------------------------------------------
/** Displays the FPS on the screen.
*/

View File

@ -213,8 +213,6 @@ private:
Shaders *m_shaders;
/** Wind. */
Wind *m_wind;
float m_exposure;
float m_lwhite;
/** RTTs. */
RTT *m_rtts;
std::vector<core::matrix4> sun_ortho_matrix;
@ -291,25 +289,7 @@ public:
return hasVSLayer;
}
float getExposure() const
{
return m_exposure;
}
void setExposure(float v)
{
m_exposure = v;
}
float getLwhite() const
{
return m_lwhite;
}
void setLwhite(float v)
{
m_lwhite = v;
}
video::SColorf getAmbientLight() const;
struct GlowData {
scene::ISceneNode * node;
@ -364,6 +344,10 @@ private:
STKRenderingPass m_phase;
float m_ssao_radius;
float m_ssao_k;
float m_ssao_sigma;
#ifdef DEBUG
/** Used to visualise skeletons. */
std::vector<irr::scene::IAnimatedMeshSceneNode*> m_debug_meshes;
@ -378,6 +362,7 @@ private:
void renderGLSL(float dt);
void renderSolidFirstPass();
void renderSolidSecondPass();
void renderNormalsVisualisation();
void renderTransparent();
void renderParticles();
void computeSunVisibility();
@ -411,7 +396,7 @@ public:
const std::string& mask_path);
void displayFPS();
bool OnEvent(const irr::SEvent &event);
void setAmbientLight(const video::SColor &light);
void setAmbientLight(const video::SColorf &light);
std::string generateSmallerTextures(const std::string& dir);
std::string getSmallerTexture(const std::string& texture);
video::ITexture *getTexture(FileManager::AssetType type,
@ -698,6 +683,36 @@ public:
const core::matrix4 &getProjViewMatrix() const { return m_ProjViewMatrix; }
const core::matrix4 &getInvProjViewMatrix() const { return m_InvProjViewMatrix; }
const core::vector2df &getCurrentScreenSize() const { return m_current_screen_size; }
// ------------------------------------------------------------------------
float getSSAORadius() const
{
return m_ssao_radius;
}
void setSSAORadius(float v)
{
m_ssao_radius = v;
}
float getSSAOK() const
{
return m_ssao_k;
}
void setSSAOK(float v)
{
m_ssao_k = v;
}
float getSSAOSigma() const
{
return m_ssao_sigma;
}
void setSSAOSigma(float v)
{
m_ssao_sigma = v;
}
#ifdef DEBUG
/** Removes debug meshes. */
void clearDebugMesh() { m_debug_meshes.clear(); }

View File

@ -525,16 +525,13 @@ void PostProcessing::renderSSAO()
if (!noise_tex)
noise_tex = irr_driver->getTexture(file_manager->getAsset("textures/noise.png").c_str());
glUseProgram(FullScreenShader::SSAOShader::Program);
glBindVertexArray(FullScreenShader::SSAOShader::vao);
glUseProgram(FullScreenShader::SSAOShader::getInstance()->Program);
glBindVertexArray(FullScreenShader::SSAOShader::getInstance()->vao);
setTexture(0, irr_driver->getRenderTargetTexture(RTT_LINEAR_DEPTH), GL_LINEAR, GL_LINEAR_MIPMAP_NEAREST);
setTexture(FullScreenShader::SSAOShader::getInstance()->TU_dtex, irr_driver->getRenderTargetTexture(RTT_LINEAR_DEPTH), GL_LINEAR, GL_LINEAR_MIPMAP_NEAREST);
glGenerateMipmap(GL_TEXTURE_2D);
setTexture(1, getTextureGLuint(noise_tex), GL_LINEAR, GL_LINEAR);
FullScreenShader::SSAOShader::setUniforms(core::vector2df(float(UserConfigParams::m_width),
float(UserConfigParams::m_height)),
0, 1);
FullScreenShader::SSAOShader::getInstance()->setUniforms(irr_driver->getSSAORadius(), irr_driver->getSSAOK(), irr_driver->getSSAOSigma());
glDrawArrays(GL_TRIANGLES, 0, 3);
}
@ -647,11 +644,11 @@ static void toneMap(FrameBuffer &fbo, GLuint rtt)
static void renderDoF(FrameBuffer &fbo, GLuint rtt)
{
fbo.Bind();
glUseProgram(FullScreenShader::DepthOfFieldShader::Program);
glBindVertexArray(FullScreenShader::DepthOfFieldShader::vao);
setTexture(0, rtt, GL_LINEAR, GL_LINEAR);
setTexture(1, irr_driver->getDepthStencilTexture(), GL_NEAREST, GL_NEAREST);
FullScreenShader::DepthOfFieldShader::setUniforms(0, 1);
glUseProgram(FullScreenShader::DepthOfFieldShader::getInstance()->Program);
glBindVertexArray(FullScreenShader::DepthOfFieldShader::getInstance()->vao);
setTexture(FullScreenShader::DepthOfFieldShader::getInstance()->TU_tex, rtt, GL_LINEAR, GL_LINEAR);
setTexture(FullScreenShader::DepthOfFieldShader::getInstance()->TU_depth, irr_driver->getDepthStencilTexture(), GL_NEAREST, GL_NEAREST);
FullScreenShader::DepthOfFieldShader::getInstance()->setUniforms();
glDrawArrays(GL_TRIANGLES, 0, 3);
}

View File

@ -41,6 +41,7 @@
#include "items/item_manager.hpp"
#include "modes/world.hpp"
#include "physics/physics.hpp"
#include "physics/triangle_mesh.hpp"
#include "tracks/track.hpp"
#include "utils/constants.hpp"
#include "utils/helpers.hpp"
@ -318,6 +319,13 @@ void IrrDriver::renderScene(scene::ICameraSceneNode * const camnode, unsigned po
renderSolidSecondPass();
PROFILER_POP_CPU_MARKER();
if (getNormals())
{
m_rtts->getFBO(FBO_NORMAL_AND_DEPTHS).Bind();
renderNormalsVisualisation();
m_rtts->getFBO(FBO_COLORS).Bind();
}
if (UserConfigParams::m_dynamic_lights && World::getWorld() != NULL &&
World::getWorld()->isFogEnabled())
{
@ -594,8 +602,12 @@ void IrrDriver::computeCameraMatrix(scene::ICameraSceneNode * const camnode, siz
if (World::getWorld() && World::getWorld()->getTrack())
{
const Vec3 *vmin, *vmax;
World::getWorld()->getTrack()->getAABB(&vmin, &vmax);
btVector3 btmin, btmax;
if (World::getWorld()->getTrack()->getPtrTriangleMesh())
{
World::getWorld()->getTrack()->getTriangleMesh().getCollisionShape().getAabb(btTransform::getIdentity(), btmin, btmax);
}
const Vec3 vmin = btmin , vmax = btmax;
// Build the 3 ortho projection (for the 3 shadow resolution levels)
for (unsigned i = 0; i < 4; i++)
@ -633,7 +645,7 @@ void IrrDriver::computeCameraMatrix(scene::ICameraSceneNode * const camnode, siz
memcpy(m_shadows_cam[i], tmp, 24 * sizeof(float));
const core::aabbox3df smallcambox = camnode->
getViewFrustum()->getBoundingBox();
core::aabbox3df trackbox(vmin->toIrrVector(), vmax->toIrrVector() -
core::aabbox3df trackbox(vmin.toIrrVector(), vmax.toIrrVector() -
core::vector3df(0, 30, 0));
// Set up a nice ortho projection that contains our camera frustum
@ -670,7 +682,7 @@ void IrrDriver::computeCameraMatrix(scene::ICameraSceneNode * const camnode, siz
}
{
core::aabbox3df trackbox(vmin->toIrrVector(), vmax->toIrrVector() -
core::aabbox3df trackbox(vmin.toIrrVector(), vmax.toIrrVector() -
core::vector3df(0, 30, 0));
if (trackbox.MinEdge.X != trackbox.MaxEdge.X &&
trackbox.MinEdge.Y != trackbox.MaxEdge.Y &&

View File

@ -332,6 +332,41 @@ void IrrDriver::renderSolidSecondPass()
}
}
template<enum E_VERTEX_TYPE VertexType, typename... TupleType>
static void renderMeshNormals(std::vector<STK::Tuple<TupleType...> > &meshes)
{
glUseProgram(MeshShader::NormalVisualizer::getInstance()->Program);
glBindVertexArray(getVAO(VertexType));
for (unsigned i = 0; i < meshes.size(); i++)
{
GLMesh &mesh = *(STK::tuple_get<0>(meshes[i]));
if (mesh.VAOType != VertexType)
{
#ifdef DEBUG
Log::error("Materials", "Wrong vertex Type associed to pass 2 (hint texture : %s)", mesh.textures[0]->getName().getPath().c_str());
#endif
continue;
}
draw(MeshShader::NormalVisualizer::getInstance(), STK::tuple_get<0>(meshes[i]), STK::tuple_get<1>(meshes[i]), STK::tuple_get<2>(meshes[i]), video::SColor(255, 0, 255, 0));
}
}
void IrrDriver::renderNormalsVisualisation()
{
renderMeshNormals<video::EVT_STANDARD>(ListMatDefault::Arguments);
renderMeshNormals<video::EVT_STANDARD>(ListMatAlphaRef::Arguments);
renderMeshNormals<video::EVT_STANDARD>(ListMatSphereMap::Arguments);
// renderMeshNormals<video::EVT_STANDARD>(ListMatGrass::Arguments);
renderMeshNormals<video::EVT_2TCOORDS>(ListMatDetails::Arguments);
renderMeshNormals<video::EVT_STANDARD>(ListMatUnlit::Arguments);
renderMeshNormals<video::EVT_2TCOORDS>(ListMatSplatting::Arguments);
renderMeshNormals<video::EVT_TANGENTS>(ListMatNormalMap::Arguments);
}
static video::ITexture *displaceTex = 0;
void IrrDriver::renderTransparent()

View File

@ -378,6 +378,14 @@ static void testSH(unsigned char *color[6], size_t width, size_t height,
}
}
static void swapPixels(char *old_img, char *new_img, unsigned stride, unsigned old_i, unsigned old_j, unsigned new_i, unsigned new_j)
{
new_img[4 * (stride * new_i + new_j)] = old_img[4 * (stride * old_i + old_j)];
new_img[4 * (stride * new_i + new_j) + 1] = old_img[4 * (stride * old_i + old_j) + 1];
new_img[4 * (stride * new_i + new_j) + 2] = old_img[4 * (stride * old_i + old_j) + 2];
new_img[4 * (stride * new_i + new_j) + 3] = old_img[4 * (stride * old_i + old_j) + 3];
}
/** Generate an opengl cubemap texture from 6 2d textures.
Out of legacy the sequence of textures maps to :
- 1st texture maps to GL_TEXTURE_CUBE_MAP_POSITIVE_Y
@ -421,6 +429,19 @@ GLuint generateCubeMapFromTextures(const std::vector<video::ITexture *> &texture
image->copyToScaling(rgba[i], w, h);
image->drop();
if (i == 2 || i == 3)
{
char *tmp = new char[w * h * 4];
memcpy(tmp, rgba[i], w * h * 4);
for (unsigned x = 0; x < w; x++)
{
for (unsigned y = 0; y < h; y++)
{
swapPixels(tmp, rgba[i], h, x, y, (w - y - 1), x);
}
}
}
glBindTexture(GL_TEXTURE_CUBE_MAP, result);
if (UserConfigParams::m_texture_compression)
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, GL_COMPRESSED_SRGB_ALPHA, w, h, 0, GL_BGRA, GL_UNSIGNED_BYTE, (GLvoid*)rgba[i]);
@ -485,8 +506,7 @@ void IrrDriver::generateDiffuseCoefficients()
int sh_w = 16;
int sh_h = 16;
const video::SColorf& ambientf = irr_driver->getSceneManager()->getAmbientLight();
video::SColor ambient = ambientf.toSColor();
video::SColor ambient = m_scene_manager->getAmbientLight().toSColor();
unsigned char *sh_rgba[6];
for (unsigned i = 0; i < 6; i++)

View File

@ -375,7 +375,6 @@ void Shaders::loadShaders()
initShadowVPMUBO();
FullScreenShader::BloomBlendShader::init();
FullScreenShader::BloomShader::init();
FullScreenShader::DepthOfFieldShader::init();
FullScreenShader::FogShader::init();
FullScreenShader::Gaussian17TapHShader::init();
FullScreenShader::ComputeGaussian17TapHShader::init();
@ -389,7 +388,6 @@ void Shaders::loadShaders()
FullScreenShader::PassThroughShader::init();
FullScreenShader::LayerPassThroughShader::init();
FullScreenShader::LinearizeDepthShader::init();
FullScreenShader::SSAOShader::init();
FullScreenShader::DiffuseEnvMapShader::init();
FullScreenShader::RadianceHintsConstructionShader::init();
FullScreenShader::RHDebug::init();
@ -573,6 +571,11 @@ void glUniform3fWraper(GLuint a, float b, float c, float d)
glUniform3f(a, b, c, d);
}
void glUniform4iWraper(GLuint a, int b, int c, int d, int e)
{
glUniform4i(a, b, c, d, e);
}
void glUniform2fWraper(GLuint a, float b, float c)
{
glUniform2f(a, b, c);
@ -879,6 +882,7 @@ namespace MeshShader
{
Program = LoadProgram(
GL_VERTEX_SHADER, file_manager->getAsset("shaders/object_pass.vert").c_str(),
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/utils/getLightFactor.frag").c_str(),
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/splatting.frag").c_str());
AssignUniforms("ModelMatrix");
TU_tex_layout = 3;
@ -1229,6 +1233,18 @@ namespace MeshShader
glUniform1i(uniform_tex, TU_tex);
}
NormalVisualizer::NormalVisualizer()
{
Program = LoadProgram(
GL_VERTEX_SHADER, file_manager->getAsset("shaders/object_pass.vert").c_str(),
GL_GEOMETRY_SHADER, file_manager->getAsset("shaders/normal_visualizer.geom").c_str(),
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/coloredquad.frag").c_str());
AssignUniforms("ModelMatrix", "InverseModelMatrix", "color");
GLuint uniform_ViewProjectionMatrixesUBO = glGetUniformBlockIndex(Program, "MatrixesData");
glUniformBlockBinding(Program, uniform_ViewProjectionMatrixesUBO, 0);
}
GLuint ViewFrustrumShader::Program;
GLuint ViewFrustrumShader::attrib_position;
GLuint ViewFrustrumShader::uniform_color;
@ -1603,29 +1619,20 @@ namespace FullScreenShader
vao = createFullScreenVAO(Program);
}
GLuint DepthOfFieldShader::Program;
GLuint DepthOfFieldShader::uniform_tex;
GLuint DepthOfFieldShader::uniform_depth;
GLuint DepthOfFieldShader::vao;
void DepthOfFieldShader::init()
DepthOfFieldShader::DepthOfFieldShader()
{
Program = LoadProgram(
GL_VERTEX_SHADER, file_manager->getAsset("shaders/screenquad.vert").c_str(),
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/dof.frag").c_str());
uniform_tex = glGetUniformLocation(Program, "tex");
uniform_depth = glGetUniformLocation(Program, "dtex");
TU_tex = 0;
TU_depth = 1;
AssignUniforms();
AssignTextureUnit(Program, TexUnit(TU_tex, "tex"), TexUnit(TU_depth, "dtex"));
vao = createFullScreenVAO(Program);
GLuint uniform_ViewProjectionMatrixesUBO = glGetUniformBlockIndex(Program, "MatrixesData");
glUniformBlockBinding(Program, uniform_ViewProjectionMatrixesUBO, 0);
}
void DepthOfFieldShader::setUniforms(unsigned TU_tex, unsigned TU_dtex)
{
glUniform1i(uniform_tex, TU_tex);
glUniform1i(uniform_depth, TU_dtex);
}
SunLightShader::SunLightShader()
{
Program = LoadProgram(
@ -1996,152 +2003,20 @@ namespace FullScreenShader
vao = createVAO(Program);
}
GLuint SSAOShader::Program;
GLuint SSAOShader::uniform_ntex;
GLuint SSAOShader::uniform_dtex;
GLuint SSAOShader::uniform_noise_texture;
GLuint SSAOShader::uniform_samplePoints;
GLuint SSAOShader::vao;
float SSAOShader::SSAOSamples[64];
void SSAOShader::init()
SSAOShader::SSAOShader()
{
Program = LoadProgram(
GL_VERTEX_SHADER, file_manager->getAsset("shaders/screenquad.vert").c_str(),
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/utils/decodeNormal.frag").c_str(),
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/utils/getPosFromUVDepth.frag").c_str(),
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/ssao.frag").c_str());
uniform_ntex = glGetUniformLocation(Program, "ntex");
uniform_dtex = glGetUniformLocation(Program, "dtex");
uniform_noise_texture = glGetUniformLocation(Program, "noise_texture");
uniform_samplePoints = glGetUniformLocation(Program, "samplePoints[0]");
TU_dtex = 0;
AssignTextureUnit(Program, TexUnit(TU_dtex, "dtex"));
AssignUniforms("radius", "k", "sigma");
vao = createFullScreenVAO(Program);
GLuint uniform_ViewProjectionMatrixesUBO = glGetUniformBlockIndex(Program, "MatrixesData");
glUniformBlockBinding(Program, uniform_ViewProjectionMatrixesUBO, 0);
// 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);
// Norm factor
double w = rand();
w /= RAND_MAX;
SSAOSamples[4 * i] = (float)x;
SSAOSamples[4 * i + 1] = (float)y;
SSAOSamples[4 * i + 2] = (float)z;
SSAOSamples[4 * i + 3] = (float)w;
}*/
}
void SSAOShader::setUniforms(const core::vector2df &screen, unsigned TU_dtex, unsigned TU_noise)
{
if (irr_driver->needUBOWorkaround())
bypassUBO(Program);
glUniform4fv(uniform_samplePoints, 16, SSAOSamples);
glUniform1i(uniform_dtex, TU_dtex);
glUniform1i(uniform_noise_texture, TU_noise);
}
GLuint FogShader::Program;

View File

@ -51,6 +51,7 @@ public:
void glUniformMatrix4fvWraper(GLuint, size_t, unsigned, const float *mat);
void glUniform3fWraper(GLuint, float, float, float);
void glUniform4iWraper(GLuint, int, int, int, int);
void glUniform2fWraper(GLuint a, float b, float c);
void glUniform1fWrapper(GLuint, float);
bool needsUBO();
@ -79,6 +80,13 @@ struct UniformHelper
setUniformsHelper<N + 1>(uniforms, arg...);
}
template<unsigned N = 0, typename... Args>
static void setUniformsHelper(const std::vector<GLuint> &uniforms, const video::SColor &col, Args... arg)
{
glUniform4iWraper(uniforms[N], col.getRed(), col.getGreen(), col.getBlue(), col.getAlpha());
setUniformsHelper<N + 1>(uniforms, arg...);
}
template<unsigned N = 0, typename... Args>
static void setUniformsHelper(const std::vector<GLuint> &uniforms, const core::vector3df &v, Args... arg)
{
@ -407,6 +415,12 @@ public:
static void setUniforms(const core::matrix4 &ModelMatrix, const core::vector2df &screen, unsigned TU_tex);
};
class NormalVisualizer : public ShaderHelperSingleton<NormalVisualizer, core::matrix4, core::matrix4, video::SColor>
{
public:
NormalVisualizer();
};
class ViewFrustrumShader
{
public:
@ -537,15 +551,13 @@ public:
ToneMapShader();
};
class DepthOfFieldShader
class DepthOfFieldShader : public ShaderHelperSingleton<DepthOfFieldShader>
{
public:
static GLuint Program;
static GLuint uniform_tex, uniform_depth;
static GLuint vao;
GLuint TU_tex, TU_depth;
GLuint vao;
static void init();
static void setUniforms(unsigned TU_tex, unsigned TU_depth);
DepthOfFieldShader();
};
class SunLightShader : public ShaderHelperSingleton<SunLightShader, core::vector3df, video::SColorf>
@ -729,16 +741,13 @@ public:
static void init();
};
class SSAOShader
class SSAOShader : public ShaderHelperSingleton<SSAOShader, float, float, float>
{
public:
static GLuint Program;
static GLuint uniform_ntex, uniform_dtex, uniform_noise_texture, uniform_samplePoints;
static GLuint vao;
static float SSAOSamples[64];
static void init();
static void setUniforms(const core::vector2df &screen, unsigned TU_dtex, unsigned TU_noise);
GLuint TU_dtex;
GLuint vao;
SSAOShader();
};
class FogShader

View File

@ -119,6 +119,27 @@ void STKInstancedSceneNode::addInstance(const core::vector3df &origin, const cor
instance_pos.push_back(scale.Z);
}
core::matrix4 STKInstancedSceneNode::getInstanceTransform(int id)
{
core::matrix4 mat;
int offset = id * 9;
mat.setTranslation(core::vector3df(
instance_pos[offset],
instance_pos[offset + 1],
instance_pos[offset + 2]));
mat.setRotationDegrees(core::vector3df(
instance_pos[offset + 3],
instance_pos[offset + 4],
instance_pos[offset + 5]));
mat.setScale(core::vector3df(
instance_pos[offset + 6],
instance_pos[offset + 7],
instance_pos[offset + 8]));
return mat;
}
static void drawFSPMDefault(GLMesh &mesh, size_t instance_count)
{
irr_driver->IncreaseObjectCount();

View File

@ -28,6 +28,10 @@ public:
virtual void render();
void addInstance(const core::vector3df &origin, const core::vector3df &orientation, const core::vector3df &scale);
int getInstanceCount() const { return instance_pos.size() / 9; }
core::matrix4 getInstanceTransform(int id);
void instanceGrab() { m_ref_count++; }
void instanceDrop()
{

View File

@ -19,6 +19,7 @@
#include "graphics/irr_driver.hpp"
#include "guiengine/engine.hpp"
#include "guiengine/scalable_font.hpp"
#include "guiengine/widgets/spinner_widget.hpp"
#include "io/file_manager.hpp"
#include "utils/string_utils.hpp"
@ -161,6 +162,10 @@ void SpinnerWidget::add()
label->setText(m_labels[m_value].c_str() );
}
if (widget_size.getHeight() < GUIEngine::getFontHeight())
{
label->setOverrideFont(GUIEngine::getSmallFont());
}
}

View File

@ -574,7 +574,7 @@ void PhysicalObject::hit(const Material *m, const Vec3 &normal)
if(isSoccerBall() && m != NULL &&
m->getCollisionReaction() == Material::PUSH_SOCCER_BALL)
{
m_body->applyCentralImpulse(normal * 100.0f);
m_body->applyCentralImpulse(normal * m_mass * 5.0f);
}
} // hit

View File

@ -32,30 +32,19 @@ using namespace GUIEngine;
// ------------------------------------------------------------------------------------------------------
DebugSliderDialog::DebugSliderDialog(std::string id, irr::core::stringw msg) :
ModalDialog(0.85f, 0.25f, MODAL_DIALOG_LOCATION_BOTTOM)
DebugSliderDialog::DebugSliderDialog() : ModalDialog(0.85f, 0.25f, MODAL_DIALOG_LOCATION_BOTTOM)
{
//if (StateManager::get()->getGameState() == GUIEngine::GAME)
//{
// World::getWorld()->schedulePause(World::IN_GAME_MENU_PHASE);
//}
m_id = id;
m_fade_background = false;
loadFromFile("debug_slider.stkgui");
}
LabelWidget* message = getWidget<LabelWidget>("title");
message->setText( msg.c_str(), false );
float val;
if (m_id == "lwhite")
val = irr_driver->getLwhite() * 10.f;
if (m_id == "exposure")
val = irr_driver->getExposure() * 100.f;
getWidget<SpinnerWidget>("value_slider")->setValue(int(val));
void DebugSliderDialog::setSliderHook(std::string id, unsigned min, unsigned max, std::function<int()> G, std::function<void(int)> S)
{
getWidget<SpinnerWidget>(id.c_str())->setValue(G());
getWidget<SpinnerWidget>(id.c_str())->setMin(min);
getWidget<SpinnerWidget>(id.c_str())->setMax(max);
Setters[id] = S;
}
// ------------------------------------------------------------------------------------------------------
@ -78,18 +67,12 @@ void DebugSliderDialog::onEnterPressedInternal()
GUIEngine::EventPropagation DebugSliderDialog::processEvent(const std::string& eventSource)
{
if (eventSource == "value_slider")
{
int value = getWidget<SpinnerWidget>("value_slider")->getValue();
Log::info("DebugSlider", "Value for <%s> : %i", m_id.c_str(), value);
if (m_id == "lwhite")
irr_driver->setLwhite(value / 10.f);
if (m_id == "exposure")
irr_driver->setExposure(value / 100.f);
return GUIEngine::EVENT_BLOCK;
}
return GUIEngine::EVENT_LET;
if (Setters.find(eventSource) == Setters.end())
return GUIEngine::EVENT_LET;
int value = getWidget<SpinnerWidget>(eventSource.c_str())->getValue();
Log::info("DebugSlider", "Value for <%s> : %i", eventSource.c_str(), value);
Setters[eventSource](value);
return GUIEngine::EVENT_BLOCK;
}
// ------------------------------------------------------------------------------------------------------

View File

@ -22,6 +22,7 @@
#include "guiengine/modaldialog.hpp"
#include "utils/cpp2011.hpp"
#include "utils/leak_check.hpp"
#include <functional>
/**
* \brief For internal value tweaking
@ -32,18 +33,18 @@ class DebugSliderDialog : public GUIEngine::ModalDialog
private:
std::string m_id;
std::map<std::string, std::function<void(int)> >Setters;
public:
DebugSliderDialog();
DebugSliderDialog(std::string id, ::core::stringw msg);
~DebugSliderDialog();
void setSliderHook(std::string id, unsigned min, unsigned max, std::function<int()> G, std::function<void(int)> S);
virtual void onEnterPressedInternal() OVERRIDE;
virtual void onUpdate(float dt) OVERRIDE;
GUIEngine::EventPropagation processEvent(const std::string& eventSource);
};

View File

@ -37,6 +37,7 @@
#include "graphics/particle_emitter.hpp"
#include "graphics/particle_kind.hpp"
#include "graphics/particle_kind_manager.hpp"
#include "graphics/stkinstancedscenenode.hpp"
#include "graphics/stk_text_billboard.hpp"
#include "guiengine/scalable_font.hpp"
#include "io/file_manager.hpp"
@ -430,8 +431,6 @@ void Track::cleanup()
//-----------------------------------------------------------------------------
void Track::loadTrackInfo()
{
irr_driver->setLwhite(1.);
irr_driver->setExposure(0.09f);
// Default values
m_use_fog = false;
m_fog_max = 1.0f;
@ -447,6 +446,9 @@ void Track::loadTrackInfo()
m_sun_specular_color = video::SColor(255, 255, 255, 255);
m_sun_diffuse_color = video::SColor(255, 255, 255, 255);
m_sun_position = core::vector3df(0, 0, 0);
irr_driver->setSSAORadius(1.);
irr_driver->setSSAOK(1.5);
irr_driver->setSSAOSigma(1.);
XMLNode *root = file_manager->createXMLTree(m_filename);
if(!root || root->getName()!="track")
@ -728,10 +730,25 @@ void Track::convertTrackToBullet(scene::ISceneNode *node)
"This track contains an empty LOD group.");
return;
}
node->updateAbsolutePosition();
}
node->updateAbsolutePosition();
std::vector<core::matrix4> matrices;
STKInstancedSceneNode* instancing_node = dynamic_cast<STKInstancedSceneNode*>(node);
if (instancing_node != NULL)
{
int count = instancing_node->getInstanceCount();
for (int i = 0; i < count; i++)
{
matrices.push_back(instancing_node->getInstanceTransform(i));
}
}
else
{
matrices.push_back(node->getAbsoluteTransformation());
}
const core::vector3df &pos = node->getAbsolutePosition();
@ -773,14 +790,15 @@ void Track::convertTrackToBullet(scene::ISceneNode *node)
return;
} // switch node->getType()
core::matrix4 mat;
mat.setRotationDegrees(hpr);
mat.setTranslation(pos);
core::matrix4 mat_scale;
// Note that we can't simply call mat.setScale, since this would
// overwrite the elements on the diagonal, making any rotation incorrect.
mat_scale.setScale(scale);
mat *= mat_scale;
//core::matrix4 mat;
//mat.setRotationDegrees(hpr);
//mat.setTranslation(pos);
//core::matrix4 mat_scale;
//// Note that we can't simply call mat.setScale, since this would
//// overwrite the elements on the diagonal, making any rotation incorrect.
//mat_scale.setScale(scale);
//mat *= mat_scale;
for(unsigned int i=0; i<mesh->getMeshBufferCount(); i++)
{
scene::IMeshBuffer *mb = mesh->getMeshBuffer(i);
@ -834,59 +852,80 @@ void Track::convertTrackToBullet(scene::ISceneNode *node)
if (mb->getVertexType() == video::EVT_STANDARD)
{
irr::video::S3DVertex* mbVertices=(video::S3DVertex*)mb->getVertices();
for(unsigned int j=0; j<mb->getIndexCount(); j+=3)
for (unsigned int matrix_index = 0; matrix_index < matrices.size(); matrix_index++)
{
for(unsigned int k=0; k<3; k++)
for (unsigned int j = 0; j < mb->getIndexCount(); j += 3)
{
int indx=mbIndices[j+k];
core::vector3df v = mbVertices[indx].Pos;
mat.transformVect(v);
vertices[k]=v;
normals[k]=mbVertices[indx].Normal;
} // for k
if(tmesh) tmesh->addTriangle(vertices[0], vertices[1],
vertices[2], normals[0],
normals[1], normals[2],
material );
} // for j
for (unsigned int k = 0; k < 3; k++)
{
int indx = mbIndices[j + k];
core::vector3df v = mbVertices[indx].Pos;
matrices[matrix_index].transformVect(v);
vertices[k] = v;
normals[k] = mbVertices[indx].Normal;
} // for k
if (tmesh)
{
tmesh->addTriangle(vertices[0], vertices[1],
vertices[2], normals[0],
normals[1], normals[2],
material);
}
} // for j
} // for matrix_index
}
else if (mb->getVertexType() == video::EVT_2TCOORDS)
{
irr::video::S3DVertex2TCoords* mbVertices = (video::S3DVertex2TCoords*)mb->getVertices();
for(unsigned int j=0; j<mb->getIndexCount(); j+=3)
for (unsigned int matrix_index = 0; matrix_index < matrices.size(); matrix_index++)
{
for(unsigned int k=0; k<3; k++)
for (unsigned int j = 0; j < mb->getIndexCount(); j += 3)
{
int indx=mbIndices[j+k];
core::vector3df v = mbVertices[indx].Pos;
mat.transformVect(v);
vertices[k]=v;
normals[k]=mbVertices[indx].Normal;
} // for k
if(tmesh) tmesh->addTriangle(vertices[0], vertices[1],
vertices[2], normals[0],
normals[1], normals[2],
material );
} // for j
for (unsigned int k = 0; k < 3; k++)
{
int indx = mbIndices[j + k];
core::vector3df v = mbVertices[indx].Pos;
matrices[matrix_index].transformVect(v);
vertices[k] = v;
normals[k] = mbVertices[indx].Normal;
} // for k
if (tmesh)
{
tmesh->addTriangle(vertices[0], vertices[1],
vertices[2], normals[0],
normals[1], normals[2],
material);
}
} // for j
} // for matrix_index
}
else if (mb->getVertexType() == video::EVT_TANGENTS)
{
irr::video::S3DVertexTangents* mbVertices = (video::S3DVertexTangents*)mb->getVertices();
for(unsigned int j=0; j<mb->getIndexCount(); j+=3)
for (unsigned int matrix_index = 0; matrix_index < matrices.size(); matrix_index++)
{
for(unsigned int k=0; k<3; k++)
for (unsigned int j = 0; j < mb->getIndexCount(); j += 3)
{
int indx=mbIndices[j+k];
core::vector3df v = mbVertices[indx].Pos;
mat.transformVect(v);
vertices[k]=v;
normals[k]=mbVertices[indx].Normal;
} // for k
if(tmesh) tmesh->addTriangle(vertices[0], vertices[1],
vertices[2], normals[0],
normals[1], normals[2],
material );
} // for j
for (unsigned int k = 0; k < 3; k++)
{
int indx = mbIndices[j + k];
core::vector3df v = mbVertices[indx].Pos;
matrices[matrix_index].transformVect(v);
vertices[k] = v;
normals[k] = mbVertices[indx].Normal;
} // for k
if (tmesh)
{
tmesh->addTriangle(vertices[0], vertices[1],
vertices[2], normals[0],
normals[1], normals[2],
material);
}
} // for j
} // for matrix_index
}
} // for i<getMeshBufferCount

View File

@ -548,6 +548,7 @@ public:
float getCameraFar() const { return m_camera_far; }
// ------------------------------------------------------------------------
/** Returns the triangle mesh for this track. */
const TriangleMesh *getPtrTriangleMesh() const { return m_track_mesh; }
const TriangleMesh& getTriangleMesh() const {return *m_track_mesh; }
// ------------------------------------------------------------------------
/** Returns the graphical effect mesh for this track. */

View File

@ -83,8 +83,7 @@ enum DebugMenuCommand
DEBUG_TOGGLE_GUI,
DEBUG_HIDE_KARTS,
DEBUG_THROTTLE_FPS,
DEBUG_TWEAK_SHADER_EXPOSURE,
DEBUG_TWEAK_SHADER_LWHITE
DEBUG_VISUAL_VALUES,
};
// -----------------------------------------------------------------------------
@ -188,10 +187,7 @@ bool onEvent(const SEvent &event)
sub->addItem(L"Anvil", DEBUG_ATTACHMENT_ANVIL);
sub->addItem(L"Parachute", DEBUG_ATTACHMENT_PARACHUTE);
//mnu->addItem(L"Adjust shaders >", -1, true, true);
//sub = mnu->getSubMenu(3);
//sub->addItem(L"Exposure", DEBUG_TWEAK_SHADER_EXPOSURE);
//sub->addItem(L"LWhite", DEBUG_TWEAK_SHADER_LWHITE);
mnu->addItem(L"Adjust values", DEBUG_VISUAL_VALUES);
mnu->addItem(L"Profiler",DEBUG_PROFILER);
if (UserConfigParams::m_profiler_enabled)
@ -438,13 +434,36 @@ bool onEvent(const SEvent &event)
kart->getNode()->setVisible(false);
}
}
else if (cmdID == DEBUG_TWEAK_SHADER_EXPOSURE)
else if (cmdID == DEBUG_VISUAL_VALUES)
{
new DebugSliderDialog("exposure", "Exposure");
}
else if (cmdID == DEBUG_TWEAK_SHADER_LWHITE)
{
new DebugSliderDialog("lwhite", "LWhite");
DebugSliderDialog *dsd = new DebugSliderDialog();
dsd->setSliderHook( "red_slider", 0, 255, [](){ return irr_driver->getAmbientLight().r * 255.; },
[](int v){
video::SColorf ambient = irr_driver->getAmbientLight();
ambient.setColorComponentValue(0, v / 255.);
irr_driver->setAmbientLight(ambient); }
);
dsd->setSliderHook("green_slider", 0, 255, [](){ return irr_driver->getAmbientLight().g * 255.; },
[](int v){
video::SColorf ambient = irr_driver->getAmbientLight();
ambient.setColorComponentValue(1, v / 255.);
irr_driver->setAmbientLight(ambient); }
);
dsd->setSliderHook("blue_slider", 0, 255, [](){ return irr_driver->getAmbientLight().b * 255.; },
[](int v){
video::SColorf ambient = irr_driver->getAmbientLight();
ambient.setColorComponentValue(2, v / 255.);
irr_driver->setAmbientLight(ambient); }
);
dsd->setSliderHook("ssao_radius", 0, 100, [](){ return irr_driver->getSSAORadius() * 10; },
[](int v){irr_driver->setSSAORadius(v / 10.); }
);
dsd->setSliderHook("ssao_k", 0, 100, [](){ return irr_driver->getSSAOK() * 10; },
[](int v){irr_driver->setSSAOK(v / 10.); }
);
dsd->setSliderHook("ssao_sigma", 0, 100, [](){ return irr_driver->getSSAOSigma() * 10; },
[](int v){irr_driver->setSSAOSigma(v / 10.); }
);
}
}