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
35033503
35043504 skybox = skyStage->getSkybox();
35053505 if (skybox) {
3506− skybox->render(batch, *(qApp->getDisplayViewFrustum()));
3506+ skybox->render(batch, *(args->_viewFrustum));
35073507 }
35083508 }
35093509 }
libraries/gpu/src/gpu/Transform.slh+1−1
@@ -135,7 +135,7 @@ TransformCamera getTransformCamera() { · 134 unmodified lines
135135
136136 <@func transformClipToEyeDir(cameraTransform, clipPos, eyeDir)@>
137137 { // 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
139139 }
140140 <@endfunc@>
141141
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
7171
7272 void Skybox::render(gpu::Batch& batch, const ViewFrustum& viewFrustum, const Skybox& skybox) {
7373 // Create the static shared elements used to render the skybox
74− static gpu::BufferPointer theBuffer;
75− static gpu::Stream::FormatPointer theFormat;
7674 static gpu::BufferPointer theConstants;
7775 static gpu::PipelinePointer thePipeline;
7876 const int SKYBOX_SKYMAP_SLOT = 0;
7977 const int SKYBOX_CONSTANTS_SLOT = 0;
8078 static std::once_flag once;
8179 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−
9080 {
9181 auto skyVS = gpu::Shader::createVertex(std::string(Skybox_vert));
9282 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
115105 batch.setProjectionTransform(projMat);
116106 batch.setViewTransform(viewTransform);
117107 batch.setModelTransform(Transform()); // only for Mac
118− batch.setInputBuffer(gpu::Stream::POSITION, theBuffer, 0, 8);
119− batch.setInputFormat(theFormat);
120108
121109 gpu::TexturePointer skymap;
122110 if (skybox.getCubemap() && skybox.getCubemap()->isDefined()) {
libraries/model/src/model/Skybox.slv+10−5
@@ -11,21 +11,26 @@ · 10 unmodified lines
1111 // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
1212 //
1313
14−
15−<@include gpu/Inputs.slh@>
16−
1714 <@include gpu/Transform.slh@>
1815
1916 <$declareStandardTransform()$>
2017
2118 out vec3 _normal;
2219
23−void main(void) {
20+void 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+
2430 // standard transform
2531 TransformCamera cam = getTransformCamera();
2632 vec3 clipDir = vec3(inPosition.xy, 0.0);
2733 vec3 eyeDir;
28−
2934 <$transformClipToEyeDir(cam, clipDir, eyeDir)$>
3035 <$transformEyeToWorldDir(cam, eyeDir, _normal)$>
3136
libraries/procedural/src/procedural/ProceduralSkybox.cpp+0−10
@@ -51,14 +51,6 @@ void ProceduralSkybox::render(gpu::Batch& batch, const ViewFrustum& viewFrustum, · 50 unmodified lines
5151 static gpu::Stream::FormatPointer theFormat;
5252
5353 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−
6254 glm::mat4 projMat;
6355 viewFrustum.evalProjectionMatrix(projMat);
6456
@@ -67,8 +59,6 @@ void ProceduralSkybox::render(gpu::Batch& batch, const ViewFrustum& viewFrustum, · 2 unmodified lines
6759 batch.setProjectionTransform(projMat);
6860 batch.setViewTransform(viewTransform);
6961 batch.setModelTransform(Transform()); // only for Mac
70− batch.setInputBuffer(gpu::Stream::POSITION, theBuffer, 0, 8);
71− batch.setInputFormat(theFormat);
7262
7363 if (skybox.getCubemap() && skybox.getCubemap()->isDefined()) {
7464 batch.setResourceTexture(0, skybox.getCubemap());