From 63f948c822a817887e1aa923bdf45d0b83a5f225 Mon Sep 17 00:00:00 2001 From: yangxiao Date: Thu, 25 Jun 2015 15:01:39 +0800 Subject: [PATCH] modify skybox to projection space --- cocos/3d/CCSkybox.cpp | 21 ++----------------- cocos/renderer/ccShader_3D_Skybox.vert | 6 ++++-- .../Classes/Sprite3DTest/Sprite3DTest.cpp | 2 -- 3 files changed, 6 insertions(+), 23 deletions(-) diff --git a/cocos/3d/CCSkybox.cpp b/cocos/3d/CCSkybox.cpp index f40556afdb..97876b2c3e 100644 --- a/cocos/3d/CCSkybox.cpp +++ b/cocos/3d/CCSkybox.cpp @@ -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(); } diff --git a/cocos/renderer/ccShader_3D_Skybox.vert b/cocos/renderer/ccShader_3D_Skybox.vert index b7b039810b..8f3caf208a 100644 --- a/cocos/renderer/ccShader_3D_Skybox.vert +++ b/cocos/renderer/ccShader_3D_Skybox.vert @@ -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); } ); \ No newline at end of file diff --git a/tests/cpp-tests/Classes/Sprite3DTest/Sprite3DTest.cpp b/tests/cpp-tests/Classes/Sprite3DTest/Sprite3DTest.cpp index 2289ca7234..ec1c3735aa 100644 --- a/tests/cpp-tests/Classes/Sprite3DTest/Sprite3DTest.cpp +++ b/tests/cpp-tests/Classes/Sprite3DTest/Sprite3DTest.cpp @@ -2469,8 +2469,6 @@ void Sprite3DCubeMapTest::addNewSpriteWithCoords(Vec2 p) _skyBox->setTexture(_textureCube); addChild(_skyBox); - - _skyBox->setScale(700.f); } addChild(_camera);