History

Fix the broken skybox and simplify a bit the vertex shader used

samcake committed 10 years ago

Commit 68134aa1 parent 64dd36d5 files · +12 −29Browse files

Unified · Split

5 files
  1. interface/src/Application.cpp +1 −1
  2. libraries/gpu/src/gpu/Transform.slh +1 −1
  3. libraries/model/src/model/Skybox.cpp +0 −12
  4. libraries/model/src/model/Skybox.slv +10 −5
  5. libraries/procedural/src/procedural/ProceduralSkybox.cpp +0 −10
interface/src/Application.cpp+1−1
@@ -3503,7 +3503,7 @@ namespace render { · 3502 unmodified lines
3503 3503
3504 skybox = skyStage->getSkybox();3504 skybox = skyStage->getSkybox();
3505 if (skybox) {3505 if (skybox) {
3506 skybox->render(batch, *(qApp->getDisplayViewFrustum()));3506 skybox->render(batch, *(args->_viewFrustum));
3507 }3507 }
3508 }3508 }
3509 }3509 }
libraries/gpu/src/gpu/Transform.slh+1−1
@@ -135,7 +135,7 @@ TransformCamera getTransformCamera() { · 134 unmodified lines
135 135
136<@func transformClipToEyeDir(cameraTransform, clipPos, eyeDir)@>136<@func transformClipToEyeDir(cameraTransform, clipPos, eyeDir)@>
137 { // transformClipToEyeDir137 { // transformClipToEyeDir
138 <$eyeDir$> = vec3(<$cameraTransform$>._projectionInverse * vec4(<$clipPos$>.xyz, 0.0));138 <$eyeDir$> = vec3(<$cameraTransform$>._projectionInverse * vec4(<$clipPos$>.xyz, 1.0)); // Must be 1.0 here
139 }139 }
140<@endfunc@>140<@endfunc@>
141 141
libraries/model/src/model/Skybox.cpp+0−12
@@ -71,22 +71,12 @@ void Skybox::render(gpu::Batch& batch, const ViewFrustum& frustum) const { · 70 unmodified lines
71 71
72void Skybox::render(gpu::Batch& batch, const ViewFrustum& viewFrustum, const Skybox& skybox) {72void Skybox::render(gpu::Batch& batch, const ViewFrustum& viewFrustum, const Skybox& skybox) {
73 // Create the static shared elements used to render the skybox73 // Create the static shared elements used to render the skybox
74 static gpu::BufferPointer theBuffer;
75 static gpu::Stream::FormatPointer theFormat;
76 static gpu::BufferPointer theConstants;74 static gpu::BufferPointer theConstants;
77 static gpu::PipelinePointer thePipeline;75 static gpu::PipelinePointer thePipeline;
78 const int SKYBOX_SKYMAP_SLOT = 0;76 const int SKYBOX_SKYMAP_SLOT = 0;
79 const int SKYBOX_CONSTANTS_SLOT = 0;77 const int SKYBOX_CONSTANTS_SLOT = 0;
80 static std::once_flag once;78 static std::once_flag once;
81 std::call_once(once, [&] {79 std::call_once(once, [&] {
82 {
83 const float CLIP = 1.0f;
84 const glm::vec2 vertices[4] = { { -CLIP, -CLIP }, { CLIP, -CLIP }, { -CLIP, CLIP }, { CLIP, CLIP } };
85 theBuffer = std::make_shared<gpu::Buffer>(sizeof(vertices), (const gpu::Byte*) vertices);
86 theFormat = std::make_shared<gpu::Stream::Format>();
87 theFormat->setAttribute(gpu::Stream::POSITION, gpu::Stream::POSITION, gpu::Element(gpu::VEC2, gpu::FLOAT, gpu::XYZ));
88 }
89
90 {80 {
91 auto skyVS = gpu::Shader::createVertex(std::string(Skybox_vert));81 auto skyVS = gpu::Shader::createVertex(std::string(Skybox_vert));
92 auto skyFS = gpu::Shader::createPixel(std::string(Skybox_frag));82 auto skyFS = gpu::Shader::createPixel(std::string(Skybox_frag));
@@ -115,8 +105,6 @@ void Skybox::render(gpu::Batch& batch, const ViewFrustum& viewFrustum, const Sky · 22 unmodified lines
115 batch.setProjectionTransform(projMat);105 batch.setProjectionTransform(projMat);
116 batch.setViewTransform(viewTransform);106 batch.setViewTransform(viewTransform);
117 batch.setModelTransform(Transform()); // only for Mac107 batch.setModelTransform(Transform()); // only for Mac
118 batch.setInputBuffer(gpu::Stream::POSITION, theBuffer, 0, 8);
119 batch.setInputFormat(theFormat);
120 108
121 gpu::TexturePointer skymap;109 gpu::TexturePointer skymap;
122 if (skybox.getCubemap() && skybox.getCubemap()->isDefined()) {110 if (skybox.getCubemap() && skybox.getCubemap()->isDefined()) {
libraries/model/src/model/Skybox.slv+10−5
@@ -11,21 +11,26 @@ · 10 unmodified lines
11// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html11// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
12//12//
13 13
14
15<@include gpu/Inputs.slh@>
16
17<@include gpu/Transform.slh@>14<@include gpu/Transform.slh@>
18 15
19<$declareStandardTransform()$>16<$declareStandardTransform()$>
20 17
21out vec3 _normal;18out vec3 _normal;
22 19
23void main(void) { 20void main(void) {
21 const float depth = 0.0;
22 const vec4 UNIT_QUAD[4] = vec4[4](
23 vec4(-1.0, -1.0, depth, 1.0),
24 vec4(1.0, -1.0, depth, 1.0),
25 vec4(-1.0, 1.0, depth, 1.0),
26 vec4(1.0, 1.0, depth, 1.0)
27 );
28 vec4 inPosition = UNIT_QUAD[gl_VertexID];
29
24 // standard transform30 // standard transform
25 TransformCamera cam = getTransformCamera();31 TransformCamera cam = getTransformCamera();
26 vec3 clipDir = vec3(inPosition.xy, 0.0);32 vec3 clipDir = vec3(inPosition.xy, 0.0);
27 vec3 eyeDir;33 vec3 eyeDir;
28
29 <$transformClipToEyeDir(cam, clipDir, eyeDir)$>34 <$transformClipToEyeDir(cam, clipDir, eyeDir)$>
30 <$transformEyeToWorldDir(cam, eyeDir, _normal)$>35 <$transformEyeToWorldDir(cam, eyeDir, _normal)$>
31 36
libraries/procedural/src/procedural/ProceduralSkybox.cpp+0−10
@@ -51,14 +51,6 @@ void ProceduralSkybox::render(gpu::Batch& batch, const ViewFrustum& viewFrustum, · 50 unmodified lines
51 static gpu::Stream::FormatPointer theFormat;51 static gpu::Stream::FormatPointer theFormat;
52 52
53 if (skybox._procedural && skybox._procedural->_enabled && skybox._procedural->ready()) {53 if (skybox._procedural && skybox._procedural->_enabled && skybox._procedural->ready()) {
54 if (!theBuffer) {
55 const float CLIP = 1.0f;
56 const glm::vec2 vertices[4] = { { -CLIP, -CLIP }, { CLIP, -CLIP }, { -CLIP, CLIP }, { CLIP, CLIP } };
57 theBuffer = std::make_shared<gpu::Buffer>(sizeof(vertices), (const gpu::Byte*) vertices);
58 theFormat = std::make_shared<gpu::Stream::Format>();
59 theFormat->setAttribute(gpu::Stream::POSITION, gpu::Stream::POSITION, gpu::Element(gpu::VEC2, gpu::FLOAT, gpu::XYZ));
60 }
61
62 glm::mat4 projMat;54 glm::mat4 projMat;
63 viewFrustum.evalProjectionMatrix(projMat);55 viewFrustum.evalProjectionMatrix(projMat);
64 56
@@ -67,8 +59,6 @@ void ProceduralSkybox::render(gpu::Batch& batch, const ViewFrustum& viewFrustum, · 2 unmodified lines
67 batch.setProjectionTransform(projMat);59 batch.setProjectionTransform(projMat);
68 batch.setViewTransform(viewTransform);60 batch.setViewTransform(viewTransform);
69 batch.setModelTransform(Transform()); // only for Mac61 batch.setModelTransform(Transform()); // only for Mac
70 batch.setInputBuffer(gpu::Stream::POSITION, theBuffer, 0, 8);
71 batch.setInputFormat(theFormat);
72 62
73 if (skybox.getCubemap() && skybox.getCubemap()->isDefined()) {63 if (skybox.getCubemap() && skybox.getCubemap()->isDefined()) {
74 batch.setResourceTexture(0, skybox.getCubemap());64 batch.setResourceTexture(0, skybox.getCubemap());