modify skybox to projection space

This commit is contained in:
yangxiao 2015-06-25 15:01:39 +08:00
parent 9820e2e96b
commit 63f948c822
3 changed files with 6 additions and 23 deletions

View File

@ -176,12 +176,8 @@ void Skybox::onDraw(const Mat4& transform, uint32_t flags)
Vec4 color(_displayedColor.r / 255.f, _displayedColor.g / 255.f, _displayedColor.b / 255.f, 1.f);
state->setUniformVec4("u_color", color);
float scalf = (camera->getFarPlane() + camera->getNearPlane()) / 2;
state->setUniformFloat("u_scalef", scalf);
GLboolean depthFlag = glIsEnabled(GL_DEPTH_TEST);
GLint depthFunc;
glGetIntegerv(GL_DEPTH_FUNC, &depthFunc);
cameraModelMat.m[12] = cameraModelMat.m[13] = cameraModelMat.m[14] = 0;
state->setUniformMat4("u_cameraRot", cameraModelMat);
glEnable(GL_DEPTH_TEST);
RenderState::StateBlock::_defaultState->setDepthTest(true);
@ -189,11 +185,6 @@ void Skybox::onDraw(const Mat4& transform, uint32_t flags)
glDepthFunc(GL_LEQUAL);
RenderState::StateBlock::_defaultState->setDepthFunction(RenderState::DEPTH_LEQUAL);
GLboolean cullFlag = glIsEnabled(GL_CULL_FACE);
GLint cullMode;
glGetIntegerv(GL_CULL_FACE_MODE, &cullMode);
glEnable(GL_CULL_FACE);
RenderState::StateBlock::_defaultState->setCullFace(true);
@ -228,14 +219,6 @@ void Skybox::onDraw(const Mat4& transform, uint32_t flags)
CC_INCREMENT_GL_DRAWN_BATCHES_AND_VERTICES(1, 8);
glCullFace(cullMode);
if (!cullFlag)
glDisable(GL_CULL_FACE);
glDepthFunc(depthFunc);
if (!depthFlag)
glDisable(GL_DEPTH_TEST);
CHECK_GL_ERROR_DEBUG();
}

View File

@ -1,12 +1,14 @@
const char* cc3D_Skybox_vert = STRINGIFY(
uniform float u_scalef;
uniform mat4 u_cameraRot;
attribute vec3 a_position;
varying vec3 v_reflect;
void main(void)
{
v_reflect = a_position;
gl_Position = CC_MVPMatrix * vec4(u_scalef * a_position, 1.0);
vec4 reflect = u_cameraRot * vec4(a_position, 1.0);
v_reflect = reflect.xyz;
gl_Position = vec4(a_position.xy, 1.0 , 1.0);
}
);

View File

@ -2469,8 +2469,6 @@ void Sprite3DCubeMapTest::addNewSpriteWithCoords(Vec2 p)
_skyBox->setTexture(_textureCube);
addChild(_skyBox);
_skyBox->setScale(700.f);
}
addChild(_camera);