Use a fullscreen pass for skybox
This commit is contained in:
parent
70e8b4c854
commit
f22cf2a05e
@ -4,7 +4,7 @@ out vec4 FragColor;
|
|||||||
|
|
||||||
void main(void)
|
void main(void)
|
||||||
{
|
{
|
||||||
vec3 eyedir = gl_FragCoord.xyz / vec3(screen, 1.);
|
vec3 eyedir = vec3(gl_FragCoord.xy / screen, 1.);
|
||||||
eyedir = 2.0 * eyedir - 1.0;
|
eyedir = 2.0 * eyedir - 1.0;
|
||||||
vec4 tmp = (InverseProjectionMatrix * vec4(eyedir, 1.));
|
vec4 tmp = (InverseProjectionMatrix * vec4(eyedir, 1.));
|
||||||
tmp /= tmp.w;
|
tmp /= tmp.w;
|
||||||
|
10
data/shaders/sky.vert
Normal file
10
data/shaders/sky.vert
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
#if __VERSION__ >= 330
|
||||||
|
layout(location = 0) in vec3 Position;
|
||||||
|
#else
|
||||||
|
in vec3 Position;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
gl_Position = vec4(Position, 1.);
|
||||||
|
}
|
@ -380,27 +380,18 @@ void IrrDriver::renderSkybox(const scene::ICameraSceneNode *camera)
|
|||||||
{
|
{
|
||||||
if (SkyboxTextures.empty())
|
if (SkyboxTextures.empty())
|
||||||
return;
|
return;
|
||||||
glBindVertexArray(MeshShader::SkyboxShader::getInstance()->cubevao);
|
|
||||||
glEnable(GL_DEPTH_TEST);
|
glEnable(GL_DEPTH_TEST);
|
||||||
glDisable(GL_CULL_FACE);
|
glDisable(GL_CULL_FACE);
|
||||||
assert(SkyboxTextures.size() == 6);
|
assert(SkyboxTextures.size() == 6);
|
||||||
|
|
||||||
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));
|
|
||||||
core::matrix4 transform = translate * scale;
|
|
||||||
core::matrix4 invtransform;
|
|
||||||
transform.getInverse(invtransform);
|
|
||||||
glDisable(GL_BLEND);
|
glDisable(GL_BLEND);
|
||||||
|
|
||||||
glUseProgram(MeshShader::SkyboxShader::getInstance()->Program);
|
glUseProgram(MeshShader::SkyboxShader::getInstance()->Program);
|
||||||
MeshShader::SkyboxShader::getInstance()->setUniforms(transform);
|
glBindVertexArray(MeshShader::SkyboxShader::getInstance()->vao);
|
||||||
|
MeshShader::SkyboxShader::getInstance()->setUniforms();
|
||||||
|
|
||||||
MeshShader::SkyboxShader::getInstance()->SetTextureUnits(SkyboxCubeMap);
|
MeshShader::SkyboxShader::getInstance()->SetTextureUnits(SkyboxCubeMap);
|
||||||
|
|
||||||
glDrawElements(GL_TRIANGLES, 6 * 6, GL_UNSIGNED_INT, 0);
|
glDrawArrays(GL_TRIANGLES, 0, 3);
|
||||||
glBindVertexArray(0);
|
glBindVertexArray(0);
|
||||||
}
|
}
|
||||||
|
@ -336,66 +336,19 @@ static void initBillboardVBO()
|
|||||||
glBufferData(GL_ARRAY_BUFFER, 16 * sizeof(float), quad, GL_STATIC_DRAW);
|
glBufferData(GL_ARRAY_BUFFER, 16 * sizeof(float), quad, GL_STATIC_DRAW);
|
||||||
}
|
}
|
||||||
|
|
||||||
GLuint SharedObject::cubevbo = 0;
|
GLuint SharedObject::skytrivbo = 0;
|
||||||
GLuint SharedObject::cubeindexes = 0;
|
|
||||||
|
|
||||||
static void initCubeVBO()
|
static void initSkyTriVBO()
|
||||||
{
|
{
|
||||||
// From CSkyBoxSceneNode
|
const float tri_vertex[] = {
|
||||||
float corners[] =
|
|
||||||
{
|
|
||||||
// top side
|
|
||||||
1., 1., -1.,
|
|
||||||
1., 1., 1.,
|
|
||||||
-1., 1., 1.,
|
|
||||||
-1., 1., -1.,
|
|
||||||
|
|
||||||
// Bottom side
|
|
||||||
1., -1., 1.,
|
|
||||||
1., -1., -1.,
|
|
||||||
-1., -1., -1.,
|
|
||||||
-1., -1., 1.,
|
-1., -1., 1.,
|
||||||
|
-1., 3., 1.,
|
||||||
// right side
|
3., -1., 1.,
|
||||||
1., -1, -1,
|
|
||||||
1., -1, 1,
|
|
||||||
1., 1., 1.,
|
|
||||||
1., 1., -1.,
|
|
||||||
|
|
||||||
// left side
|
|
||||||
-1., -1., 1.,
|
|
||||||
-1., -1., -1.,
|
|
||||||
-1., 1., -1.,
|
|
||||||
-1., 1., 1.,
|
|
||||||
|
|
||||||
// back side
|
|
||||||
-1., -1., -1.,
|
|
||||||
1., -1, -1.,
|
|
||||||
1, 1, -1.,
|
|
||||||
-1, 1, -1.,
|
|
||||||
|
|
||||||
// front side
|
|
||||||
1., -1., 1.,
|
|
||||||
-1., -1., 1.,
|
|
||||||
-1, 1., 1.,
|
|
||||||
1., 1., 1.,
|
|
||||||
};
|
|
||||||
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, &SharedObject::cubevbo);
|
glGenBuffers(1, &SharedObject::skytrivbo);
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, SharedObject::cubevbo);
|
glBindBuffer(GL_ARRAY_BUFFER, SharedObject::skytrivbo);
|
||||||
glBufferData(GL_ARRAY_BUFFER, 6 * 4 * 3 * sizeof(float), corners, GL_STATIC_DRAW);
|
glBufferData(GL_ARRAY_BUFFER, 3 * 3 * sizeof(float), tri_vertex, GL_STATIC_DRAW);
|
||||||
|
|
||||||
glGenBuffers(1, &SharedObject::cubeindexes);
|
|
||||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, SharedObject::cubeindexes);
|
|
||||||
glBufferData(GL_ELEMENT_ARRAY_BUFFER, 6 * 6 * sizeof(int), indices, GL_STATIC_DRAW);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
GLuint SharedObject::frustrumvbo = 0;
|
GLuint SharedObject::frustrumvbo = 0;
|
||||||
@ -535,7 +488,7 @@ void Shaders::loadShaders()
|
|||||||
initQuadVBO();
|
initQuadVBO();
|
||||||
initQuadBuffer();
|
initQuadBuffer();
|
||||||
initBillboardVBO();
|
initBillboardVBO();
|
||||||
initCubeVBO();
|
initSkyTriVBO();
|
||||||
initFrustrumVBO();
|
initFrustrumVBO();
|
||||||
initShadowVPMUBO();
|
initShadowVPMUBO();
|
||||||
initLightingDataUBO();
|
initLightingDataUBO();
|
||||||
@ -1417,17 +1370,16 @@ namespace MeshShader
|
|||||||
SkyboxShader::SkyboxShader()
|
SkyboxShader::SkyboxShader()
|
||||||
{
|
{
|
||||||
Program = LoadProgram(OBJECT,
|
Program = LoadProgram(OBJECT,
|
||||||
GL_VERTEX_SHADER, file_manager->getAsset("shaders/object_pass.vert").c_str(),
|
GL_VERTEX_SHADER, file_manager->getAsset("shaders/sky.vert").c_str(),
|
||||||
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/sky.frag").c_str());
|
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/sky.frag").c_str());
|
||||||
AssignUniforms("ModelMatrix");
|
AssignUniforms();
|
||||||
AssignSamplerNames(Program, 0, "tex");
|
AssignSamplerNames(Program, 0, "tex");
|
||||||
|
|
||||||
glGenVertexArrays(1, &cubevao);
|
glGenVertexArrays(1, &vao);
|
||||||
glBindVertexArray(cubevao);
|
glBindVertexArray(vao);
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, SharedObject::cubevbo);
|
glBindBuffer(GL_ARRAY_BUFFER, SharedObject::skytrivbo);
|
||||||
glEnableVertexAttribArray(0);
|
glEnableVertexAttribArray(0);
|
||||||
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), 0);
|
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), 0);
|
||||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, SharedObject::cubeindexes);
|
|
||||||
glBindVertexArray(0);
|
glBindVertexArray(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,7 +30,7 @@ class SharedObject
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static GLuint billboardvbo;
|
static GLuint billboardvbo;
|
||||||
static GLuint cubevbo, cubeindexes, frustrumvbo, frustrumindexes, ParticleQuadVBO;
|
static GLuint skytrivbo, frustrumvbo, frustrumindexes, ParticleQuadVBO;
|
||||||
static GLuint ViewProjectionMatrixesUBO, LightingDataUBO;
|
static GLuint ViewProjectionMatrixesUBO, LightingDataUBO;
|
||||||
static GLuint FullScreenQuadVAO;
|
static GLuint FullScreenQuadVAO;
|
||||||
static GLuint UIVAO;
|
static GLuint UIVAO;
|
||||||
@ -281,11 +281,11 @@ public:
|
|||||||
DisplaceShader();
|
DisplaceShader();
|
||||||
};
|
};
|
||||||
|
|
||||||
class SkyboxShader : public ShaderHelperSingleton<SkyboxShader, core::matrix4>, public TextureRead<Trilinear_cubemap>
|
class SkyboxShader : public ShaderHelperSingleton<SkyboxShader>, public TextureRead<Trilinear_cubemap>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
SkyboxShader();
|
SkyboxShader();
|
||||||
GLuint cubevao;
|
GLuint vao;
|
||||||
};
|
};
|
||||||
|
|
||||||
class NormalVisualizer : public ShaderHelperSingleton<NormalVisualizer, video::SColor>
|
class NormalVisualizer : public ShaderHelperSingleton<NormalVisualizer, video::SColor>
|
||||||
|
Loading…
Reference in New Issue
Block a user