From bbfb04347c29d04ff8daf5152cc0b6c50cedf474 Mon Sep 17 00:00:00 2001 From: mike Date: Thu, 23 Aug 2012 23:18:45 +0000 Subject: [PATCH] Added KRSkyBox as new KRNode instance --HG-- extra : convert_revision : svn%3A7752d6cf-9f14-4ad2-affc-04f1e67b81a5/trunk%4078 --- KREngine/KREngine.xcodeproj/project.pbxproj | 8 +++ KREngine/KREngine/Classes/KRNode.h | 3 +- KREngine/KREngine/Classes/KRSkyBox.cpp | 70 +++++++++++++++++++++ KREngine/KREngine/Classes/KRSkyBox.h | 35 +++++++++++ 4 files changed, 115 insertions(+), 1 deletion(-) create mode 100644 KREngine/KREngine/Classes/KRSkyBox.cpp create mode 100644 KREngine/KREngine/Classes/KRSkyBox.h diff --git a/KREngine/KREngine.xcodeproj/project.pbxproj b/KREngine/KREngine.xcodeproj/project.pbxproj index 82b407e..a7afab0 100644 --- a/KREngine/KREngine.xcodeproj/project.pbxproj +++ b/KREngine/KREngine.xcodeproj/project.pbxproj @@ -7,6 +7,8 @@ objects = { /* Begin PBXBuildFile section */ + 1000469D15E6EF550053B072 /* KRSkyBox.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1000469B15E6EF550053B072 /* KRSkyBox.cpp */; }; + 1000469E15E6EF550053B072 /* KRSkyBox.h in Headers */ = {isa = PBXBuildFile; fileRef = 1000469C15E6EF550053B072 /* KRSkyBox.h */; }; E414BAE21435557300A668C4 /* KRInstance.h in Headers */ = {isa = PBXBuildFile; fileRef = E414BAE11435557300A668C4 /* KRInstance.h */; }; E414BAE51435558900A668C4 /* KRInstance.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E414BAE41435558800A668C4 /* KRInstance.cpp */; }; E414BAE7143557D200A668C4 /* KRScene.h in Headers */ = {isa = PBXBuildFile; fileRef = E414BAE6143557D200A668C4 /* KRScene.h */; }; @@ -159,6 +161,8 @@ /* End PBXBuildRule section */ /* Begin PBXFileReference section */ + 1000469B15E6EF550053B072 /* KRSkyBox.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = KRSkyBox.cpp; path = Classes/KRSkyBox.cpp; sourceTree = ""; }; + 1000469C15E6EF550053B072 /* KRSkyBox.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = KRSkyBox.h; path = Classes/KRSkyBox.h; sourceTree = ""; }; E414BAE11435557300A668C4 /* KRInstance.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; lineEnding = 0; name = KRInstance.h; path = Classes/KRInstance.h; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.objcpp; }; E414BAE41435558800A668C4 /* KRInstance.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; lineEnding = 0; name = KRInstance.cpp; path = Classes/KRInstance.cpp; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.cpp; }; E414BAE6143557D200A668C4 /* KRScene.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; lineEnding = 0; name = KRScene.h; path = Classes/KRScene.h; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.objcpp; }; @@ -392,6 +396,8 @@ E4F975351536221C00FD60B2 /* KRNode.cpp */, E414BAE6143557D200A668C4 /* KRScene.h */, E414BAE81435585A00A668C4 /* KRScene.cpp */, + 1000469C15E6EF550053B072 /* KRSkyBox.h */, + 1000469B15E6EF550053B072 /* KRSkyBox.cpp */, ); name = "Scene Graph"; sourceTree = ""; @@ -562,6 +568,7 @@ E42CB1EC158446940066E0D8 /* KRQuaternion.h in Headers */, E43B0ACB15DDBB8500A5CB9F /* KRNotified.h in Headers */, E43B0AD815DDCA0F00A5CB9F /* KRContextObject.h in Headers */, + 1000469E15E6EF550053B072 /* KRSkyBox.h in Headers */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -720,6 +727,7 @@ E42CB1F0158446AB0066E0D8 /* KRQuaternion.cpp in Sources */, E43B0AC915DDBB8500A5CB9F /* KRNotified.cpp in Sources */, E43B0AD615DDCA0F00A5CB9F /* KRContextObject.cpp in Sources */, + 1000469D15E6EF550053B072 /* KRSkyBox.cpp in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/KREngine/KREngine/Classes/KRNode.h b/KREngine/KREngine/Classes/KRNode.h index b87dc45..3296853 100644 --- a/KREngine/KREngine/Classes/KRNode.h +++ b/KREngine/KREngine/Classes/KRNode.h @@ -32,7 +32,8 @@ public: RENDER_PASS_DEFERRED_OPAQUE, RENDER_PASS_FORWARD_TRANSPARENT, RENDER_PASS_FLARES, - RENDER_PASS_SHADOWMAP + RENDER_PASS_SHADOWMAP, + RENDER_PASS_SKYBOX }; KRNode(KRContext &context, std::string name); diff --git a/KREngine/KREngine/Classes/KRSkyBox.cpp b/KREngine/KREngine/Classes/KRSkyBox.cpp new file mode 100644 index 0000000..b8a1a38 --- /dev/null +++ b/KREngine/KREngine/Classes/KRSkyBox.cpp @@ -0,0 +1,70 @@ +// +// KRSkyBox.cpp +// KREngine +// +// Created by Michael Ilich on 2012-08-23. +// Copyright (c) 2012 Kearwood Software. All rights reserved. +// + +#include + +#include "KRSkyBox.h" +#import "KRShader.h" +#import "KRContext.h" +#import "KRMat4.h" +#import "KRResource.h" + +KRSkyBox::KRSkyBox(KRContext &context, std::string name) : KRNode(context, name) +{ + +} + +KRSkyBox::~KRSkyBox() +{ + +} + +std::string KRSkyBox::getElementName() { + return "sky_box"; +} + +#if TARGET_OS_IPHONE + +void KRSkyBox::render(KRCamera *pCamera, KRContext *pContext, KRBoundingVolume &frustrumVolume, KRMat4 &viewMatrix, KRVector3 &cameraPosition, KRNode::RenderPass renderPass) { + + if(renderPass == KRNode::RENDER_PASS_SKYBOX) { + // Skybox is rendered on the final pass of the deferred renderer + + KRMat4 projectionMatrix = pCamera->getProjectionMatrix(); + + KRMat4 mvpmatrix = m_modelMatrix * viewMatrix * projectionMatrix; + KRMat4 matModelToView = viewMatrix * m_modelMatrix; + matModelToView.transpose(); + matModelToView.invert(); + + KRShader *pShader = pContext->getShaderManager()->getShader("sky_box", pCamera, false, false, false, 0, false, false, false, false, false, false, false, false, renderPass); + + pShader->bind(pCamera, matModelToView, mvpmatrix, cameraPosition, NULL, NULL, NULL, 0, renderPass); + + // Disable z-buffer write + glDepthMask(GL_FALSE); + + // Disable z-buffer test + glDisable(GL_DEPTH_TEST); + + // Render a full screen quad + static const GLfloat squareVertices[] = { + -1.0f, -1.0f, + 1.0f, -1.0f, + -1.0f, 1.0f, + 1.0f, 1.0f, + }; + + glBindBuffer(GL_ARRAY_BUFFER, 0); + glVertexAttribPointer(KRShader::KRENGINE_ATTRIB_VERTEX, 2, GL_FLOAT, 0, 0, squareVertices); + glEnableVertexAttribArray(KRShader::KRENGINE_ATTRIB_VERTEX); + glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); + } +} + +#endif \ No newline at end of file diff --git a/KREngine/KREngine/Classes/KRSkyBox.h b/KREngine/KREngine/Classes/KRSkyBox.h new file mode 100644 index 0000000..ae042c9 --- /dev/null +++ b/KREngine/KREngine/Classes/KRSkyBox.h @@ -0,0 +1,35 @@ +// +// KRSkyBox.h +// KREngine +// +// Created by Michael Ilich on 2012-08-23. +// Copyright (c) 2012 Kearwood Software. All rights reserved. +// + +#ifndef __KREngine__KRSkyBox__ +#define __KREngine__KRSkyBox__ + +#include +#import "KRMat4.h" +#import "KRNode.h" + +class KRSkyBox : public KRNode { + +public: + + KRSkyBox(KRContext &context, std::string name); + virtual ~KRSkyBox(); + + virtual std::string getElementName(); + +#if TARGET_OS_IPHONE + + virtual void render(KRCamera *pCamera, KRContext *pContext, KRBoundingVolume &frustrumVolume, KRMat4 &viewMatrix, KRVector3 &cameraPosition, KRNode::RenderPass renderPass); +#endif + +private: + KRMat4 m_modelMatrix; +}; + + +#endif \ No newline at end of file