Added KRSkyBox as new KRNode instance

--HG--
extra : convert_revision : svn%3A7752d6cf-9f14-4ad2-affc-04f1e67b81a5/trunk%4078
This commit is contained in:
mike
2012-08-23 23:18:45 +00:00
parent 4b7163aa48
commit bbfb04347c
4 changed files with 115 additions and 1 deletions

View File

@@ -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 = "<group>"; };
1000469C15E6EF550053B072 /* KRSkyBox.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = KRSkyBox.h; path = Classes/KRSkyBox.h; sourceTree = "<group>"; };
E414BAE11435557300A668C4 /* KRInstance.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; lineEnding = 0; name = KRInstance.h; path = Classes/KRInstance.h; sourceTree = "<group>"; 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 = "<group>"; 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 = "<group>"; 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 = "<group>";
@@ -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;
};

View File

@@ -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);

View File

@@ -0,0 +1,70 @@
//
// KRSkyBox.cpp
// KREngine
//
// Created by Michael Ilich on 2012-08-23.
// Copyright (c) 2012 Kearwood Software. All rights reserved.
//
#include <iostream>
#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

View File

@@ -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 <iostream>
#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