Skip to content

Commit 7678dbe

Browse files
author
Cheng Xie
committed
fixed a skybox depth bug
1 parent ff1e97a commit 7678dbe

9 files changed

+16
-14
lines changed

diagram.png

196 KB
Loading

src/camera.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
Camera::Camera()
66
{
7-
near_ = 10;
7+
near_ = 1;
88
far_ = 10000;
99
aspectRatio_ = 1;
1010
heightAngle_ = 60;

src/fpscameracontroller.cpp

-7
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,6 @@ void FPSCameraController::mouseMoveEvent(QMouseEvent *event)
2222
if (rbuttonDown_) {
2323
QPoint mousePos = event->pos();
2424
QPoint delta = mousePos - oldMousePos_;
25-
26-
// QMatrix4x4& rotation;
27-
// rotation.rotate(-delta.x() * 0.5, {0, 1, 0});
28-
// camera_->setTransform(camera_->transform() * rotation);
29-
30-
//// rotation.setToIdentity();
31-
//// rotation.rotate(-delta.y() * 0.5, );
3225

3326
mat4& transform = camera_->transform();
3427
mat4 mat;

src/scene.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,16 @@ void Scene::initialize()
4040
material1->setShiness(50);
4141

4242
// Textures are owned by cache
43-
Texture* diffuseMap = TextureCache::getInstance()->acquire("heightmap1", TextureType::Texture2D);
43+
Texture* diffuseMap = TextureCache::getInstance()->acquire("frostmourne", TextureType::Texture2D);
4444
material1->setDiffuseMap(diffuseMap);
4545

4646
SceneObject* obj1 = new SceneObject;
47-
Mesh* mesh1 = MeshCache::getInstance()->acquire("cube");
47+
Mesh* mesh1 = MeshCache::getInstance()->acquire("frostmourne");
4848
obj1->setMesh(mesh1);
4949
obj1->setMaterial(material1);
5050

51-
obj1->transform().translate(20, 0, 0);
52-
obj1->transform().scale(5, 5, 5);
51+
obj1->transform().translate(20, 20, 0);
52+
obj1->transform().scale(20, 20, 20);
5353

5454
sceneObjects_.push_back(obj1);
5555

src/shaders/phong.vs

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ void main()
2121

2222
if (useHeightMap) {
2323
float height = texture(heightMap, uvL).x;
24-
position += normalL * height * 30;
24+
position += normalL * height * 50;
2525

2626
float turbulence = 0.1;
2727
const ivec3 off = ivec3(-1, 0, 1);

src/skyboxmaterial.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#include "skybox.h"
12
#include "skyboxmaterial.h"
23
#include "shader.h"
34
#include "shadercache.h"
@@ -22,5 +23,12 @@ void SkyboxMaterial::apply(DrawContext &context)
2223
assert(texture_);
2324

2425
texture_->apply(context, "cubeMap", 0);
26+
27+
glDepthMask(GL_FALSE);
28+
}
29+
30+
void SkyboxMaterial::endRender()
31+
{
32+
glDepthMask(GL_TRUE);
2533
}
2634

src/skyboxmaterial.h

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ class SkyboxMaterial : public Material
1111
void setTexture(Texture *texture);
1212

1313
virtual void apply(DrawContext &context) override;
14+
virtual void endRender() override;
1415

1516
private:
1617
Texture* texture_;

src/terrain.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ void Terrain::buildMesh()
2222
material->setAmbient({0.2, 0.2, 0.2});
2323
material->setDiffuse({0.7, 0.7, 0.2});
2424

25-
Texture* heightMap = TextureCache::getInstance()->acquire("heightmap2", TextureType::Texture2D);
25+
Texture* heightMap = TextureCache::getInstance()->acquire("heightmap1", TextureType::Texture2D);
2626
Texture* diffuseMap = TextureCache::getInstance()->acquire("terrain", TextureType::Texture2D);
2727

2828
material->setHeightMap(heightMap);

src/textures/frostmourne.jpg

117 KB
Loading

0 commit comments

Comments
 (0)