KRCamera's have been moved into the scene graph.

--HG--
extra : convert_revision : svn%3A7752d6cf-9f14-4ad2-affc-04f1e67b81a5/trunk%40198
This commit is contained in:
kearwood
2012-12-20 22:08:41 +00:00
parent 042ce94ef1
commit a3ebbd4fd7
20 changed files with 621 additions and 490 deletions

View File

@@ -69,6 +69,10 @@
E44F380D1682734C00399B5D /* PVRException.h in Headers */ = {isa = PBXBuildFile; fileRef = E44F38061682734C00399B5D /* PVRException.h */; };
E44F380E1682734C00399B5D /* PVRTexLibGlobals.h in Headers */ = {isa = PBXBuildFile; fileRef = E44F38071682734C00399B5D /* PVRTexLibGlobals.h */; };
E44F380F1682734C00399B5D /* PVRTGlobal.h in Headers */ = {isa = PBXBuildFile; fileRef = E44F38081682734C00399B5D /* PVRTGlobal.h */; };
E44F38241683B23000399B5D /* KRRenderSettings.h in Headers */ = {isa = PBXBuildFile; fileRef = E44F38231683B22C00399B5D /* KRRenderSettings.h */; };
E44F38251683B23000399B5D /* KRRenderSettings.h in Headers */ = {isa = PBXBuildFile; fileRef = E44F38231683B22C00399B5D /* KRRenderSettings.h */; };
E44F38281683B24800399B5D /* KRRenderSettings.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E44F38271683B24400399B5D /* KRRenderSettings.cpp */; };
E44F38291683B24800399B5D /* KRRenderSettings.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E44F38271683B24400399B5D /* KRRenderSettings.cpp */; };
E460292616681CFF00261BB9 /* KRTextureAnimated.h in Headers */ = {isa = PBXBuildFile; fileRef = E460292516681CFE00261BB9 /* KRTextureAnimated.h */; };
E460292816681D1000261BB9 /* KRTextureAnimated.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E460292716681D1000261BB9 /* KRTextureAnimated.cpp */; };
E460292B16682BF700261BB9 /* libfbxsdk-2013.3-static.a in Frameworks */ = {isa = PBXBuildFile; fileRef = E460292916682BD900261BB9 /* libfbxsdk-2013.3-static.a */; };
@@ -298,6 +302,8 @@
E44F38061682734C00399B5D /* PVRException.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = PVRException.h; path = "../../../../../../../../../Applications/PVR SDK Package/Utilities/PVRTexLib/PVRException.h"; sourceTree = "<group>"; };
E44F38071682734C00399B5D /* PVRTexLibGlobals.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = PVRTexLibGlobals.h; path = "../../../../../../../../../Applications/PVR SDK Package/Utilities/PVRTexLib/PVRTexLibGlobals.h"; sourceTree = "<group>"; };
E44F38081682734C00399B5D /* PVRTGlobal.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = PVRTGlobal.h; path = "../../../../../../../../../Applications/PVR SDK Package/Utilities/PVRTexLib/PVRTGlobal.h"; sourceTree = "<group>"; };
E44F38231683B22C00399B5D /* KRRenderSettings.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = KRRenderSettings.h; path = Classes/KRRenderSettings.h; sourceTree = "<group>"; };
E44F38271683B24400399B5D /* KRRenderSettings.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = KRRenderSettings.cpp; path = Classes/KRRenderSettings.cpp; sourceTree = "<group>"; };
E45772F113C9A13C0037BEEA /* ShadowShader.vsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; lineEnding = 0; name = ShadowShader.vsh; path = Shaders/ShadowShader.vsh; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.glsl; };
E45772F213C9A13C0037BEEA /* ShadowShader.fsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; name = ShadowShader.fsh; path = Shaders/ShadowShader.fsh; sourceTree = "<group>"; };
E45772F313C9A13C0037BEEA /* PostShader.fsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; name = PostShader.fsh; path = Shaders/PostShader.fsh; sourceTree = "<group>"; };
@@ -698,6 +704,8 @@
E48C696C15374A1500232E28 /* Scene Graph Nodes */ = {
isa = PBXGroup;
children = (
E48B3CBF14393E2F000C50E2 /* KRCamera.cpp */,
E48B3CBC14393DF5000C50E2 /* KRCamera.h */,
E4324BA916444DCB0043185B /* Particle Systems */,
E414BAE11435557300A668C4 /* KRInstance.h */,
E414BAE41435558800A668C4 /* KRInstance.cpp */,
@@ -771,8 +779,6 @@
E4924C2515EE95E800B965C6 /* KROctree.h */,
E4924C2915EE96AA00B965C6 /* KROctreeNode.cpp */,
E4924C2A15EE96AA00B965C6 /* KROctreeNode.h */,
E48B3CBF14393E2F000C50E2 /* KRCamera.cpp */,
E48B3CBC14393DF5000C50E2 /* KRCamera.h */,
E48C697115374F7E00232E28 /* KRContext.cpp */,
E48C696E15374F5A00232E28 /* KRContext.h */,
E43B0AD415DDCA0C00A5CB9F /* KRContextObject.cpp */,
@@ -787,6 +793,8 @@
E4CA11771639CC8E005D9400 /* KRViewport.cpp */,
E4C454B7167BD235003586CD /* KRHitInfo.h */,
E4C454BA167BD248003586CD /* KRHitInfo.cpp */,
E44F38231683B22C00399B5D /* KRRenderSettings.h */,
E44F38271683B24400399B5D /* KRRenderSettings.cpp */,
);
name = Classes;
sourceTree = "<group>";
@@ -902,6 +910,7 @@
E4C454AC167BB8EC003586CD /* KRModelCube.h in Headers */,
E4C454B2167BC04C003586CD /* KRModelSphere.h in Headers */,
E4C454B8167BD236003586CD /* KRHitInfo.h in Headers */,
E44F38241683B23000399B5D /* KRRenderSettings.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -971,6 +980,7 @@
E44F380D1682734C00399B5D /* PVRException.h in Headers */,
E44F380E1682734C00399B5D /* PVRTexLibGlobals.h in Headers */,
E44F380F1682734C00399B5D /* PVRTGlobal.h in Headers */,
E44F38251683B23000399B5D /* KRRenderSettings.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -1108,6 +1118,7 @@
E4C454AF167BB8FC003586CD /* KRModelCube.cpp in Sources */,
E4C454B5167BC05C003586CD /* KRModelSphere.cpp in Sources */,
E4C454BB167BD248003586CD /* KRHitInfo.cpp in Sources */,
E44F38281683B24800399B5D /* KRRenderSettings.cpp in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -1168,6 +1179,7 @@
E4C454B0167BB8FC003586CD /* KRModelCube.cpp in Sources */,
E4C454B6167BC05C003586CD /* KRModelSphere.cpp in Sources */,
E4C454BC167BD248003586CD /* KRHitInfo.cpp in Sources */,
E44F38291683B24800399B5D /* KRRenderSettings.cpp in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};

View File

@@ -161,7 +161,7 @@ void KRAnimationAttribute::setCurveName(const std::string &curve_name)
KRNode *KRAnimationAttribute::getTarget()
{
if(m_target == NULL) {
m_target = getContext().getSceneManager()->getFirstScene()->getRootNode()->findChild(m_target_name); // FINDME, HACK! - This won't work with multiple scenes in a context; we should move the animations out of KRAnimationManager and attach them to the parent nodes of the animated KRNode's
m_target = getContext().getSceneManager()->getFirstScene()->getRootNode()->find<KRNode>(m_target_name); // FINDME, HACK! - This won't work with multiple scenes in a context; we should move the animations out of KRAnimationManager and attach them to the parent nodes of the animated KRNode's
}
return m_target;
}

View File

@@ -1,5 +1,5 @@
//
// KRSettings.cpp
// KRCamera.cpp
// KREngine
//
// Copyright 2012 Kearwood Gilbert. All rights reserved.
@@ -41,62 +41,14 @@
#import "KRStockGeometry.h"
#import "KRDirectionalLight.h"
KRCamera::KRCamera(KRContext &context) : KRContextObject(context) {
KRCamera::KRCamera(KRScene &scene, std::string name) : KRNode(scene, name) {
m_particlesAbsoluteTime = 0.0f;
backingWidth = 0;
backingHeight = 0;
volumetricBufferWidth = 0;
volumetricBufferHeight = 0;
m_pSkyBoxTexture = NULL;
float const PI = 3.141592653589793f;
float const D2R = PI * 2 / 360;
bShowShadowBuffer = false;
bShowOctree = false;
bShowDeferred = false;
bEnablePerPixel = true;
bEnableDiffuseMap = true;
bEnableNormalMap = true;
bEnableSpecMap = true;
bEnableReflectionMap = true;
bEnableReflection = true;
bDebugPSSM = false;
bEnableAmbient = true;
bEnableDiffuse = true;
bEnableSpecular = true;
bEnableLightMap = true;
bDebugSuperShiny = false;
bEnableDeferredLighting = true;
dAmbientR = 0.0f;
dAmbientG = 0.0f;
dAmbientB = 0.0f;
dSunR = 1.0f;
dSunG = 1.0f;
dSunB = 1.0f;
perspective_fov = 45.0 * D2R;
perspective_nearz = 5.0f;
perspective_farz = 100.0f;
dof_quality = 0;
dof_depth = 0.05f;
dof_falloff = 0.05f;
bEnableFlash = false;
flash_intensity = 1.0f;
flash_depth = 0.7f;
flash_falloff = 0.5f;
bEnableVignette = false;
vignette_radius = 0.4f;
vignette_falloff = 1.0f;
m_cShadowBuffers = 0;
compositeDepthTexture = 0;
compositeColorTexture = 0;
lightAccumulationTexture = 0;
@@ -105,86 +57,32 @@ KRCamera::KRCamera(KRContext &context) : KRContextObject(context) {
volumetricLightAccumulationBuffer = 0;
volumetricLightAccumulationTexture = 0;
m_iFrame = 0;
m_skyBoxName = "";
m_pSkyBoxTexture = NULL;
volumetric_environment_enable = false;
volumetric_environment_downsample = 2;
volumetric_environment_max_distance = 1000.0f;
volumetric_environment_quality = (50 - 5.0) / 495.0f;
volumetric_environment_intensity = 0.9f;
fog_near = 500.0f;
fog_far = 5000.0f;
fog_density = 0.0005f;
fog_color = KRVector3(0.45, 0.45, 0.5);
fog_type = 0;
dust_particle_intensity = 0.25f;
dust_particle_enable = false;
}
KRCamera::~KRCamera() {
destroyBuffers();
}
KRMat4 KRCamera::getProjectionMatrix() {
KRMat4 projectionMatrix;
projectionMatrix.perspective(perspective_fov, m_viewportSize.x / m_viewportSize.y, perspective_nearz, perspective_farz);
return projectionMatrix;
}
const KRVector2 &KRCamera::getViewportSize() {
return m_viewportSize;
}
void KRCamera::setViewportSize(const KRVector2 &size) {
m_viewportSize = size;
}
KRVector3 KRCamera::getPosition() const {
return m_position;
}
void KRCamera::setPosition(const KRVector3 &position) {
m_position = position;
}
void KRCamera::renderFrame(KRScene &scene, KRMat4 &viewMatrix, float deltaTime)
void KRCamera::renderFrame(float deltaTime)
{
if(m_iFrame == 0) {
if(scene.getFirstLight() == NULL) {
scene.addDefaultLights();
}
}
KRMat4 viewMatrix = KRMat4::Invert(getModelMatrix());
GLint defaultFBO;
GLDEBUG(glGetIntegerv(GL_FRAMEBUFFER_BINDING, &defaultFBO));
createBuffers();
setViewportSize(KRVector2(backingWidth, backingHeight));
m_viewport = KRViewport(getViewportSize(), viewMatrix, getProjectionMatrix());
settings.setViewportSize(KRVector2(backingWidth, backingHeight));
KRMat4 projectionMatrix;
projectionMatrix.perspective(settings.perspective_fov, settings.m_viewportSize.x / settings.m_viewportSize.y, settings.perspective_nearz, settings.perspective_farz);
m_viewport = KRViewport(settings.getViewportSize(), viewMatrix, projectionMatrix);
renderFrame(scene, deltaTime);
renderFrame(getScene(), deltaTime);
GLDEBUG(glBindFramebuffer(GL_FRAMEBUFFER, defaultFBO));
renderPost();
m_iFrame++;
}
void KRCamera::renderFrame(KRScene &scene, float deltaTime) {
KRVector3 vecCameraDirection = m_viewport.getCameraDirection();
@@ -193,7 +91,7 @@ void KRCamera::renderFrame(KRScene &scene, float deltaTime) {
// KRViewport shadowViewports[KRENGINE_MAX_SHADOW_BUFFERS];
// int cShadows = 0;
if(bEnableDeferredLighting) {
if(settings.bEnableDeferredLighting) {
// ----====---- Opaque Geometry, Deferred rendering Pass 1 ----====----
// Set render target
@@ -340,8 +238,8 @@ void KRCamera::renderFrame(KRScene &scene, float deltaTime) {
GLDEBUG(glDepthFunc(GL_LEQUAL));
GLDEBUG(glDepthRangef(0.0, 1.0));
if(!m_pSkyBoxTexture && m_skyBoxName.length()) {
m_pSkyBoxTexture = getContext().getTextureManager()->getTextureCube(m_skyBoxName.c_str());
if(!m_pSkyBoxTexture && settings.m_skyBoxName.length()) {
m_pSkyBoxTexture = getContext().getTextureManager()->getTextureCube(settings.m_skyBoxName.c_str());
}
if(m_pSkyBoxTexture) {
@@ -407,10 +305,10 @@ void KRCamera::renderFrame(KRScene &scene, float deltaTime) {
// ----====---- Volumetric Lighting ----====----
if(volumetric_environment_enable) {
if(settings.volumetric_environment_enable) {
KRViewport volumetricLightingViewport = KRViewport(KRVector2(volumetricBufferWidth, volumetricBufferHeight), m_viewport.getViewMatrix(), m_viewport.getProjectionMatrix());
if(volumetric_environment_downsample != 0) {
if(settings.volumetric_environment_downsample != 0) {
// Set render target
GLDEBUG(glBindFramebuffer(GL_FRAMEBUFFER, volumetricLightAccumulationBuffer));
GLDEBUG(glClearColor(0.0f, 0.0f, 0.0f, 0.0f));
@@ -433,7 +331,7 @@ void KRCamera::renderFrame(KRScene &scene, float deltaTime) {
scene.render(this, m_viewport.getVisibleBounds(), volumetricLightingViewport, KRNode::RENDER_PASS_VOLUMETRIC_EFFECTS_ADDITIVE, false);
if(volumetric_environment_downsample != 0) {
if(settings.volumetric_environment_downsample != 0) {
// Set render target
GLDEBUG(glBindFramebuffer(GL_FRAMEBUFFER, compositeFramebuffer));
GLDEBUG(glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, compositeDepthTexture, 0));
@@ -446,7 +344,7 @@ void KRCamera::renderFrame(KRScene &scene, float deltaTime) {
// ----====---- Debug Overlay ----====----
if(bShowOctree) {
if(settings.bShowOctree) {
// Enable z-buffer test
GLDEBUG(glEnable(GL_DEPTH_TEST));
GLDEBUG(glDepthRangef(0.0, 1.0));
@@ -463,8 +361,6 @@ void KRCamera::renderFrame(KRScene &scene, float deltaTime) {
KRShader *pVisShader = getContext().getShaderManager()->getShader("visualize_overlay", this, std::vector<KRLight *>(), 0, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, KRNode::RENDER_PASS_FORWARD_TRANSPARENT);
KRMat4 projectionMatrix = getProjectionMatrix();
m_pContext->getModelManager()->bindVBO((void *)KRENGINE_VBO_3D_CUBE, KRENGINE_VBO_3D_CUBE_SIZE, true, false, false, false, false, false, false);
for(std::map<KRAABB, int>::iterator itr=m_viewport.getVisibleBounds().begin(); itr != m_viewport.getVisibleBounds().end(); itr++) {
KRMat4 matModel = KRMat4();
@@ -562,9 +458,9 @@ void KRCamera::createBuffers() {
}
int targetVolumetricBufferWidth = 0;
int targetVolumetricBufferHeight = 0;
if(volumetric_environment_enable && volumetric_environment_downsample != 0) {
targetVolumetricBufferWidth = renderBufferWidth >> volumetric_environment_downsample;
targetVolumetricBufferHeight = renderBufferHeight >> volumetric_environment_downsample;
if(settings.volumetric_environment_enable && settings.volumetric_environment_downsample != 0) {
targetVolumetricBufferWidth = renderBufferWidth >> settings.volumetric_environment_downsample;
targetVolumetricBufferHeight = renderBufferHeight >> settings.volumetric_environment_downsample;
}
@@ -676,7 +572,7 @@ void KRCamera::renderPost()
GLDEBUG(glActiveTexture(GL_TEXTURE1));
GLDEBUG(glBindTexture(GL_TEXTURE_2D, compositeColorTexture));
if(volumetric_environment_enable) {
if(settings.volumetric_environment_enable) {
m_pContext->getTextureManager()->selectTexture(2, NULL);
GLDEBUG(glActiveTexture(GL_TEXTURE2));
GLDEBUG(glBindTexture(GL_TEXTURE_2D, volumetricLightAccumulationTexture));
@@ -724,7 +620,7 @@ void KRCamera::renderPost()
const char *szText = m_debug_text.c_str();
const char *szText = settings.m_debug_text.c_str();
if(*szText) {
KRShader *fontShader = m_pContext->getShaderManager()->getShader("debug_font", this, std::vector<KRLight *>(), 0, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, KRNode::RENDER_PASS_FORWARD_TRANSPARENT);
@@ -771,28 +667,3 @@ void KRCamera::renderPost()
}
void KRCamera::setSkyBox(const std::string &skyBoxName) {
m_pSkyBoxTexture = NULL;
m_skyBoxName = skyBoxName;
}
float KRCamera::getPerspectiveNearZ()
{
return perspective_nearz;
}
float KRCamera::getPerspectiveFarZ()
{
return perspective_farz;
}
void KRCamera::setPerspectiveNear(float v)
{
if(perspective_nearz != v) {
perspective_nearz = v;
}
}
void KRCamera::setPerpsectiveFarZ(float v)
{
if(perspective_farz != v) {
perspective_farz = v;
}
}

View File

@@ -42,105 +42,27 @@
#import "KRTexture.h"
#import "KRContext.h"
#import "KRViewport.h"
#import "KRRenderSettings.h"
class KRInstance;
class KRScene;
class KRViewport;
class KRCamera : public KRContextObject {
class KRCamera : public KRNode {
public:
KRCamera(KRContext &context);
KRCamera(KRScene &scene, std::string name);
virtual ~KRCamera();
void renderFrame(float deltaTime);
KRRenderSettings settings;
private:
void createBuffers();
GLint backingWidth, backingHeight;
GLint volumetricBufferWidth, volumetricBufferHeight;
void renderFrame(KRScene &scene, KRMat4 &viewMatrix, float deltaTime);
KRVector3 getPosition() const;
void setPosition(const KRVector3 &position);
KRMat4 getProjectionMatrix();
const KRVector2 &getViewportSize();
void setViewportSize(const KRVector2 &size);
bool bEnablePerPixel;
bool bEnableDiffuseMap;
bool bEnableNormalMap;
bool bEnableSpecMap;
bool bEnableReflectionMap;
bool bEnableReflection;
bool bEnableLightMap;
bool bDebugPSSM;
bool bDebugSuperShiny;
bool bShowShadowBuffer;
bool bShowOctree;
bool bShowDeferred;
bool bEnableAmbient;
bool bEnableDiffuse;
bool bEnableSpecular;
bool bEnableDeferredLighting;
float dSunR;
float dSunG;
float dSunB;
float dAmbientR;
float dAmbientG;
float dAmbientB;
float perspective_fov;
int dof_quality;
float dof_depth;
float dof_falloff;
bool bEnableFlash;
float flash_intensity;
float flash_depth;
float flash_falloff;
bool bEnableVignette;
float vignette_radius;
float vignette_falloff;
KRVector2 m_viewportSize;
int m_cShadowBuffers;
std::string m_debug_text;
void setSkyBox(const std::string &skyBoxName);
float getPerspectiveNearZ();
float getPerspectiveFarZ();
void setPerspectiveNear(float v);
void setPerpsectiveFarZ(float v);
bool volumetric_environment_enable;
int volumetric_environment_downsample;
float volumetric_environment_max_distance;
float volumetric_environment_quality;
float volumetric_environment_intensity;
float fog_near;
float fog_far;
float fog_density;
KRVector3 fog_color;
int fog_type; // 0 = no fog, 1 = linear, 2 = exponential, 3 = exponential squared
float dust_particle_intensity;
bool dust_particle_enable;
private:
KRVector3 m_position;
void createBuffers();
float perspective_nearz;
float perspective_farz;
int m_iFrame;
GLuint compositeFramebuffer, compositeDepthTexture, compositeColorTexture;
GLuint lightAccumulationBuffer, lightAccumulationTexture;
@@ -153,10 +75,7 @@ private:
void renderFrame(KRScene &scene, float deltaTime);
std::string m_skyBoxName;
KRTexture *m_pSkyBoxTexture;
KRViewport m_viewport;
float m_particlesAbsoluteTime;

View File

@@ -8,11 +8,14 @@
#ifndef KREngine_KREngine_common_h
#define KREngine_KREngine_common_h
#ifndef KRENGINE_COMMON_H
#define KRENGINE_COMMON_H
#define KRENGINE_MAX_TEXTURE_UNITS 8
float const PI = 3.141592653589793f;
float const D2R = PI * 2 / 360;
#import <stdint.h>
#import <vector>
#import <string>
@@ -50,3 +53,7 @@ while( (e=glGetError()) != GL_NO_ERROR) \
fprintf(stderr, "Error at line number %d, in file %s. glGetError() returned %i for call %s\n",__LINE__, __FILE__, e, #x ); \
} \
}
#include "KRVector3.h"
#include "KRVector2.h"

View File

@@ -49,7 +49,6 @@ typedef enum KREngineParameterType {KRENGINE_PARAMETER_INT, KRENGINE_PARAMETER_F
@property(nonatomic, readonly) NSDictionary *parameter_names;
@property(nonatomic, assign) KRContext *context;
@property(nonatomic, assign) KRCamera *camera;
@property(nonatomic, retain) NSString *debug_text;
- (id)init;

View File

@@ -44,15 +44,15 @@ using namespace std;
@interface KREngine (PrivateMethods)
@interface KREngine() {
KRRenderSettings _settings;
}
- (BOOL)loadShaders;
- (BOOL)loadResource:(NSString *)path;
@end
@implementation KREngine
@synthesize debug_text = _debug_text;
float const PI = 3.141592653589793f;
+ (KREngine *)sharedInstance
{
@@ -93,11 +93,9 @@ float const PI = 3.141592653589793f;
KRContext::KRENGINE_MAX_TEXTURE_THROUGHPUT = 32000000;
}
_camera = NULL;
_context = NULL;
if ((self = [super init])) {
_context = new KRContext();
_camera = new KRCamera(*_context);
_parameter_names = [@{
@"camera_fov" : @0,
@"shadow_quality" : @1,
@@ -169,9 +167,14 @@ float const PI = 3.141592653589793f;
- (void)renderScene: (KRScene *)pScene WithViewMatrix: (KRMat4)viewMatrix AndDeltaTime: (float)deltaTime
{
_context->startFrame(deltaTime);
_camera->renderFrame(*pScene, viewMatrix, deltaTime);
_context->endFrame(deltaTime);
KRCamera *camera = pScene->find<KRCamera>();
if(camera) {
camera->settings = _settings;
KRMat4 invView = KRMat4::Invert(viewMatrix);
camera->setLocalRotation(KRMat4::DotNoTranslate(invView, KRVector3::Forward()));
camera->setLocalTranslation(KRMat4::Dot(invView, KRVector3::Zero()));
}
pScene->renderFrame(deltaTime);
}
- (BOOL)loadShaders
@@ -198,9 +201,6 @@ float const PI = 3.141592653589793f;
- (void)dealloc
{
[_parameter_names release]; _parameter_names = nil;
if(_camera) {
delete _camera; _camera = NULL;
}
if(_context) {
delete _context; _context = NULL;
}
@@ -329,54 +329,54 @@ float const PI = 3.141592653589793f;
-(float)getParameterValueWithIndex: (int)i
{
float values[48] = {
_camera->perspective_fov,
(float)_camera->m_cShadowBuffers,
_camera->bEnablePerPixel ? 1.0f : 0.0f,
_camera->bEnableDiffuseMap ? 1.0f : 0.0f,
_camera->bEnableNormalMap ? 1.0f : 0.0f,
_camera->bEnableSpecMap ? 1.0f : 0.0f,
_camera->bEnableReflectionMap ? 1.0f : 0.0f,
_camera->bEnableLightMap ? 1.0f : 0.0f,
_settings.perspective_fov,
(float)_settings.m_cShadowBuffers,
_settings.bEnablePerPixel ? 1.0f : 0.0f,
_settings.bEnableDiffuseMap ? 1.0f : 0.0f,
_settings.bEnableNormalMap ? 1.0f : 0.0f,
_settings.bEnableSpecMap ? 1.0f : 0.0f,
_settings.bEnableReflectionMap ? 1.0f : 0.0f,
_settings.bEnableLightMap ? 1.0f : 0.0f,
[self getAmbientTemperature],
[self getAmbientIntensity],
[self getSunTemperature],
[self getSunIntensity],
_camera->dof_quality,
_camera->dof_depth,
_camera->dof_falloff,
_camera->bEnableFlash ? 1.0f : 0.0f,
_camera->flash_intensity,
_camera->flash_depth,
_camera->flash_falloff,
_camera->bEnableVignette ? 1.0f : 0.0f,
_camera->vignette_radius,
_camera->vignette_falloff,
_camera->bShowShadowBuffer ? 1.0f : 0.0f,
_camera->bDebugPSSM ? 1.0f : 0.0f,
_camera->bEnableAmbient ? 1.0f : 0.0f,
_camera->bEnableDiffuse ? 1.0f : 0.0f,
_camera->bEnableSpecular ? 1.0f : 0.0f,
_camera->bEnableReflection ? 1.0f : 0.0f,
_camera->bDebugSuperShiny ? 1.0f : 0.0f,
_camera->bShowOctree ? 1.0f : 0.0f,
_camera->bShowDeferred ? 1.0f : 0.0f,
_camera->bEnableDeferredLighting ? 1.0f : 0.0f,
_camera->getPerspectiveNearZ(),
_camera->getPerspectiveFarZ(),
_camera->volumetric_environment_enable,
5 - _camera->volumetric_environment_downsample,
_camera->volumetric_environment_max_distance,
_camera->volumetric_environment_quality,
_camera->volumetric_environment_intensity,
_camera->fog_type,
_camera->fog_near,
_camera->fog_far,
_camera->fog_density,
_camera->fog_color.x,
_camera->fog_color.y,
_camera->fog_color.z,
_camera->dust_particle_enable,
_camera->dust_particle_intensity
_settings.dof_quality,
_settings.dof_depth,
_settings.dof_falloff,
_settings.bEnableFlash ? 1.0f : 0.0f,
_settings.flash_intensity,
_settings.flash_depth,
_settings.flash_falloff,
_settings.bEnableVignette ? 1.0f : 0.0f,
_settings.vignette_radius,
_settings.vignette_falloff,
_settings.bShowShadowBuffer ? 1.0f : 0.0f,
_settings.bDebugPSSM ? 1.0f : 0.0f,
_settings.bEnableAmbient ? 1.0f : 0.0f,
_settings.bEnableDiffuse ? 1.0f : 0.0f,
_settings.bEnableSpecular ? 1.0f : 0.0f,
_settings.bEnableReflection ? 1.0f : 0.0f,
_settings.bDebugSuperShiny ? 1.0f : 0.0f,
_settings.bShowOctree ? 1.0f : 0.0f,
_settings.bShowDeferred ? 1.0f : 0.0f,
_settings.bEnableDeferredLighting ? 1.0f : 0.0f,
_settings.getPerspectiveNearZ(),
_settings.getPerspectiveFarZ(),
_settings.volumetric_environment_enable,
5 - _settings.volumetric_environment_downsample,
_settings.volumetric_environment_max_distance,
_settings.volumetric_environment_quality,
_settings.volumetric_environment_intensity,
_settings.fog_type,
_settings.fog_near,
_settings.fog_far,
_settings.fog_density,
_settings.fog_color.x,
_settings.fog_color.y,
_settings.fog_color.z,
_settings.dust_particle_enable,
_settings.dust_particle_intensity
};
return values[i];
}
@@ -386,28 +386,28 @@ float const PI = 3.141592653589793f;
// NSLog(@"Set Parameter: (%s, %f)", [[self getParameterNameWithIndex: i] UTF8String], v);
switch(i) {
case 0: // FOV
_camera->perspective_fov = v;
_settings.perspective_fov = v;
break;
case 1: // Shadow Quality
_camera->m_cShadowBuffers = (int)v;
_settings.m_cShadowBuffers = (int)v;
break;
case 2:
_camera->bEnablePerPixel = bNewBoolVal;
_settings.bEnablePerPixel = bNewBoolVal;
break;
case 3:
_camera->bEnableDiffuseMap = bNewBoolVal;
_settings.bEnableDiffuseMap = bNewBoolVal;
break;
case 4:
_camera->bEnableNormalMap = bNewBoolVal;
_settings.bEnableNormalMap = bNewBoolVal;
break;
case 5:
_camera->bEnableSpecMap = bNewBoolVal;
_settings.bEnableSpecMap = bNewBoolVal;
break;
case 6:
_camera->bEnableReflectionMap = bNewBoolVal;
_settings.bEnableReflectionMap = bNewBoolVal;
break;
case 7:
_camera->bEnableLightMap = bNewBoolVal;
_settings.bEnableLightMap = bNewBoolVal;
break;
case 8:
[self setAmbientTemperature:v];
@@ -422,152 +422,152 @@ float const PI = 3.141592653589793f;
[self setSunIntensity:v];
break;
case 12:
if(_camera->dof_quality != (int)v) {
_camera->dof_quality = (int)v;
if(_settings.dof_quality != (int)v) {
_settings.dof_quality = (int)v;
}
break;
case 13:
if(_camera->dof_depth != v) {
_camera->dof_depth = v;
if(_settings.dof_depth != v) {
_settings.dof_depth = v;
}
break;
case 14:
if(_camera->dof_falloff != v) {
_camera->dof_falloff = v;
if(_settings.dof_falloff != v) {
_settings.dof_falloff = v;
}
break;
case 15:
if(_camera->bEnableFlash != bNewBoolVal) {
_camera->bEnableFlash = bNewBoolVal;
if(_settings.bEnableFlash != bNewBoolVal) {
_settings.bEnableFlash = bNewBoolVal;
}
break;
case 16:
if(_camera->flash_intensity != v) {
_camera->flash_intensity = v;
if(_settings.flash_intensity != v) {
_settings.flash_intensity = v;
}
break;
case 17:
if(_camera->flash_depth != v) {
_camera->flash_depth = v;
if(_settings.flash_depth != v) {
_settings.flash_depth = v;
}
break;
case 18:
if(_camera->flash_falloff != v) {
_camera->flash_falloff = v;
if(_settings.flash_falloff != v) {
_settings.flash_falloff = v;
}
break;
case 19:
if(_camera->bEnableVignette != bNewBoolVal) {
_camera->bEnableVignette = bNewBoolVal;
if(_settings.bEnableVignette != bNewBoolVal) {
_settings.bEnableVignette = bNewBoolVal;
}
break;
case 20:
if(_camera->vignette_radius != v) {
_camera->vignette_radius = v;
if(_settings.vignette_radius != v) {
_settings.vignette_radius = v;
}
break;
case 21:
if(_camera->vignette_falloff != v) {
_camera->vignette_falloff = v;
if(_settings.vignette_falloff != v) {
_settings.vignette_falloff = v;
}
break;
case 22:
if(_camera->bShowShadowBuffer != bNewBoolVal) {
_camera->bShowShadowBuffer = bNewBoolVal;
if(_settings.bShowShadowBuffer != bNewBoolVal) {
_settings.bShowShadowBuffer = bNewBoolVal;
}
break;
case 23:
if(_camera->bDebugPSSM != bNewBoolVal) {
_camera->bDebugPSSM = bNewBoolVal;
if(_settings.bDebugPSSM != bNewBoolVal) {
_settings.bDebugPSSM = bNewBoolVal;
}
break;
case 24:
if(_camera->bEnableAmbient != bNewBoolVal) {
_camera->bEnableAmbient = bNewBoolVal;
if(_settings.bEnableAmbient != bNewBoolVal) {
_settings.bEnableAmbient = bNewBoolVal;
}
break;
case 25:
if(_camera->bEnableDiffuse != bNewBoolVal) {
_camera->bEnableDiffuse = bNewBoolVal;
if(_settings.bEnableDiffuse != bNewBoolVal) {
_settings.bEnableDiffuse = bNewBoolVal;
}
break;
case 26:
if(_camera->bEnableSpecular != bNewBoolVal) {
_camera->bEnableSpecular = bNewBoolVal;
if(_settings.bEnableSpecular != bNewBoolVal) {
_settings.bEnableSpecular = bNewBoolVal;
}
break;
case 27:
if(_camera->bEnableReflection != bNewBoolVal) {
_camera->bEnableReflection = bNewBoolVal;
if(_settings.bEnableReflection != bNewBoolVal) {
_settings.bEnableReflection = bNewBoolVal;
}
break;
case 28:
if(_camera->bDebugSuperShiny != bNewBoolVal) {
_camera->bDebugSuperShiny = bNewBoolVal;
if(_settings.bDebugSuperShiny != bNewBoolVal) {
_settings.bDebugSuperShiny = bNewBoolVal;
}
break;
case 29:
if(_camera->bShowOctree != bNewBoolVal) {
_camera->bShowOctree = bNewBoolVal;
if(_settings.bShowOctree != bNewBoolVal) {
_settings.bShowOctree = bNewBoolVal;
}
break;
case 30:
if(_camera->bShowDeferred != bNewBoolVal) {
_camera->bShowDeferred = bNewBoolVal;
if(_settings.bShowDeferred != bNewBoolVal) {
_settings.bShowDeferred = bNewBoolVal;
}
break;
case 31:
if(_camera->bEnableDeferredLighting != bNewBoolVal) {
_camera->bEnableDeferredLighting = bNewBoolVal;
if(_settings.bEnableDeferredLighting != bNewBoolVal) {
_settings.bEnableDeferredLighting = bNewBoolVal;
}
break;
case 32:
_camera->setPerspectiveNear(v);
_settings.setPerspectiveNear(v);
break;
case 33:
_camera->setPerpsectiveFarZ(v);
_settings.setPerpsectiveFarZ(v);
break;
case 34:
_camera->volumetric_environment_enable = bNewBoolVal;
_settings.volumetric_environment_enable = bNewBoolVal;
break;
case 35:
_camera->volumetric_environment_downsample = 5 - (int)v;
_settings.volumetric_environment_downsample = 5 - (int)v;
break;
case 36:
_camera->volumetric_environment_max_distance = v;
_settings.volumetric_environment_max_distance = v;
break;
case 37:
_camera->volumetric_environment_quality = v;
_settings.volumetric_environment_quality = v;
break;
case 38:
_camera->volumetric_environment_intensity = v;
_settings.volumetric_environment_intensity = v;
break;
case 39:
_camera->fog_type = v;
_settings.fog_type = v;
break;
case 40:
_camera->fog_near = v;
_settings.fog_near = v;
break;
case 41:
_camera->fog_far = v;
_settings.fog_far = v;
break;
case 42:
_camera->fog_density = v;
_settings.fog_density = v;
break;
case 43:
_camera->fog_color.x = v;
_settings.fog_color.x = v;
break;
case 44:
_camera->fog_color.y = v;
_settings.fog_color.y = v;
break;
case 45:
_camera->fog_color.z = v;
_settings.fog_color.z = v;
break;
case 46:
_camera->dust_particle_enable = bNewBoolVal;
_settings.dust_particle_enable = bNewBoolVal;
break;
case 47:
_camera->dust_particle_intensity = v;
_settings.dust_particle_intensity = v;
break;
}
}
@@ -625,11 +625,11 @@ float const PI = 3.141592653589793f;
- (void)setNearZ: (float)dNearZ
{
_camera->setPerspectiveNear(dNearZ);
_settings.setPerspectiveNear(dNearZ);
}
- (void)setFarZ: (float)dFarZ
{
_camera->setPerpsectiveFarZ(dFarZ);
_settings.setPerpsectiveFarZ(dFarZ);
}
- (void)setDebug_text:(NSString *)value
@@ -638,7 +638,7 @@ float const PI = 3.141592653589793f;
_debug_text = value;
[_debug_text retain];
_camera->m_debug_text = value.UTF8String;
_settings.m_debug_text = value.UTF8String;
}
// ---===--- Sun Temperature and intensity ---===---
@@ -646,26 +646,28 @@ float const PI = 3.141592653589793f;
-(void) setSunTemperature:(float)t
{
float i = [self getSunIntensity];
_camera->dSunR = (t < 0.5f ? t * 2.0f : 1.0f) * i;
_camera->dSunG = (t < 0.5f ? t * 2.0f : (1.0f - t) * 2.0f) * i;
_camera->dSunB = (t < 0.5f ? 1.0f : (1.0f - t) * 2.0f) * i;
_settings.light_intensity = KRVector3(
(t < 0.5f ? t * 2.0f : 1.0f) * i,
(t < 0.5f ? t * 2.0f : (1.0f - t) * 2.0f) * i,
(t < 0.5f ? 1.0f : (1.0f - t) * 2.0f) * i
);
}
-(void) setSunIntensity:(float)i
{
float t = [self getSunTemperature];
_camera->dSunR = (t < 0.5f ? t * 2.0f : 1.0f) * i;
_camera->dSunG = (t < 0.5f ? t * 2.0f : (1.0f - t) * 2.0f) * i;
_camera->dSunB = (t < 0.5f ? 1.0f : (1.0f - t) * 2.0f) * i;
_settings.light_intensity = KRVector3(
(t < 0.5f ? t * 2.0f : 1.0f) * i,
(t < 0.5f ? t * 2.0f : (1.0f - t) * 2.0f) * i,
(t < 0.5f ? 1.0f : (1.0f - t) * 2.0f) * i
);
}
-(float) getSunIntensity
{
float i = _camera->dSunR;
if(_camera->dSunG > i) i = _camera->dSunG;
if(_camera->dSunB > i) i = _camera->dSunB;
float i = _settings.light_intensity[0];
if(_settings.light_intensity[1] > i) i = _settings.light_intensity[1];
if(_settings.light_intensity[2] > i) i = _settings.light_intensity[2];
return i;
}
@@ -673,12 +675,12 @@ float const PI = 3.141592653589793f;
{
float i = [self getSunIntensity];
if(i == 0.0f) return 0.5f; // Avoid division by zero; assume black has a colour temperature of 0.5
if(_camera->dSunB == i) {
if(_settings.light_intensity[2] == i) {
// Cold side, t < 0.5
return _camera->dSunR / i * 0.5f;
return _settings.light_intensity[0] / i * 0.5f;
} else {
// Warm side, t > 0.5
return 1.0f - (_camera->dSunB / i) * 0.5f;
return 1.0f - (_settings.light_intensity[2] / i) * 0.5f;
}
}
@@ -687,26 +689,28 @@ float const PI = 3.141592653589793f;
-(void) setAmbientTemperature:(float)t
{
float i = [self getAmbientIntensity];
_camera->dAmbientR = (t < 0.5f ? t * 2.0f : 1.0f) * i;
_camera->dAmbientG = (t < 0.5f ? t * 2.0f : (1.0f - t) * 2.0f) * i;
_camera->dAmbientB = (t < 0.5f ? 1.0f : (1.0f - t) * 2.0f) * i;
_settings.ambient_intensity = KRVector3(
(t < 0.5f ? t * 2.0f : 1.0f) * i,
(t < 0.5f ? t * 2.0f : (1.0f - t) * 2.0f) * i,
(t < 0.5f ? 1.0f : (1.0f - t) * 2.0f) * i
);
}
-(void) setAmbientIntensity:(float)i
{
float t = [self getAmbientTemperature];
_camera->dAmbientR = (t < 0.5f ? t * 2.0f : 1.0f) * i;
_camera->dAmbientG = (t < 0.5f ? t * 2.0f : (1.0f - t) * 2.0f) * i;
_camera->dAmbientB = (t < 0.5f ? 1.0f : (1.0f - t) * 2.0f) * i;
_settings.ambient_intensity = KRVector3(
(t < 0.5f ? t * 2.0f : 1.0f) * i,
(t < 0.5f ? t * 2.0f : (1.0f - t) * 2.0f) * i,
(t < 0.5f ? 1.0f : (1.0f - t) * 2.0f) * i
);
}
-(float) getAmbientIntensity
{
float i = _camera->dAmbientR;
if(_camera->dAmbientG > i) i = _camera->dAmbientG;
if(_camera->dAmbientB > i) i = _camera->dAmbientB;
float i = _settings.ambient_intensity[0];
if(_settings.ambient_intensity[1] > i) i = _settings.ambient_intensity[1];
if(_settings.ambient_intensity[2] > i) i = _settings.ambient_intensity[2];
return i;
}
@@ -714,12 +718,12 @@ float const PI = 3.141592653589793f;
{
float i = [self getAmbientIntensity];
if(i == 0.0f) return 0.5f; // Avoid division by zero; assume black has a colour temperature of 0.5
if(_camera->dAmbientB == i) {
if(_settings.ambient_intensity[2] == i) {
// Cold side, t < 0.5
return _camera->dAmbientR / i * 0.5f;
return _settings.ambient_intensity[0] / i * 0.5f;
} else {
// Warm side, t > 0.5
return 1.0f - (_camera->dAmbientB / i) * 0.5f;
return 1.0f - (_settings.ambient_intensity[2] / i) * 0.5f;
}
}

View File

@@ -75,7 +75,7 @@ void KRInstance::loadModel() {
std::vector<KRBone *> model_bones;
int bone_count = model->getBoneCount();
for(int bone_index=0; bone_index < bone_count; bone_index++) {
KRBone *matching_bone = dynamic_cast<KRBone *>(getScene().getRootNode()->findChild(model->getBoneName(bone_index)));
KRBone *matching_bone = dynamic_cast<KRBone *>(getScene().getRootNode()->find<KRNode>(model->getBoneName(bone_index)));
if(matching_bone) {
model_bones.push_back(matching_bone);
} else {
@@ -126,7 +126,7 @@ void KRInstance::render(KRCamera *pCamera, std::vector<KRLight *> &lights, const
m_pLightMap = getContext().getTextureManager()->getTexture(m_lightMap.c_str());
}
if(m_pLightMap && pCamera->bEnableLightMap && renderPass != RENDER_PASS_SHADOWMAP && renderPass != RENDER_PASS_GENERATE_SHADOWMAPS) {
if(m_pLightMap && pCamera->settings.bEnableLightMap && renderPass != RENDER_PASS_SHADOWMAP && renderPass != RENDER_PASS_GENERATE_SHADOWMAPS) {
m_pContext->getTextureManager()->selectTexture(5, m_pLightMap);
}

View File

@@ -164,12 +164,12 @@ void KRLight::render(KRCamera *pCamera, std::vector<KRLight *> &lights, const KR
KRNode::render(pCamera, lights, viewport, renderPass);
if(renderPass == KRNode::RENDER_PASS_GENERATE_SHADOWMAPS && (pCamera->volumetric_environment_enable || pCamera->dust_particle_enable || (pCamera->m_cShadowBuffers > 0 && m_casts_shadow))) {
if(renderPass == KRNode::RENDER_PASS_GENERATE_SHADOWMAPS && (pCamera->settings.volumetric_environment_enable || pCamera->settings.dust_particle_enable || (pCamera->settings.m_cShadowBuffers > 0 && m_casts_shadow))) {
allocateShadowBuffers(configureShadowBufferViewports(viewport));
renderShadowBuffers(pCamera);
}
if(renderPass == KRNode::RENDER_PASS_ADDITIVE_PARTICLES && pCamera->dust_particle_enable) {
if(renderPass == KRNode::RENDER_PASS_ADDITIVE_PARTICLES && pCamera->settings.dust_particle_enable) {
// Render brownian particles for dust floating in air
if(m_cShadowBuffers >= 1 && shadowValid[0] && m_dust_particle_density > 0.0f && m_dust_particle_size > 0.0f && m_dust_particle_intensity > 0.0f) {
float lod_coverage = getBounds().coverage(viewport.getViewProjectionMatrix(), viewport.getSize()); // This also checks the view frustrum culling
@@ -195,7 +195,7 @@ void KRLight::render(KRCamera *pCamera, std::vector<KRLight *> &lights, const KR
if(getContext().getShaderManager()->selectShader(*pCamera, pParticleShader, viewport, particleModelMatrix, this_light, 0, renderPass)) {
(m_color * pCamera->dust_particle_intensity * m_dust_particle_intensity * m_intensity).setUniform(pParticleShader->m_uniforms[KRShader::KRENGINE_UNIFORM_LIGHT_COLOR]);
(m_color * pCamera->settings.dust_particle_intensity * m_dust_particle_intensity * m_intensity).setUniform(pParticleShader->m_uniforms[KRShader::KRENGINE_UNIFORM_LIGHT_COLOR]);
KRMat4::DotWDiv(KRMat4::Invert(particleModelMatrix), KRVector3::Zero()).setUniform(pParticleShader->m_uniforms[KRShader::KRENGINE_UNIFORM_PARTICLE_ORIGIN]);
@@ -209,8 +209,8 @@ void KRLight::render(KRCamera *pCamera, std::vector<KRLight *> &lights, const KR
}
if(renderPass == KRNode::RENDER_PASS_VOLUMETRIC_EFFECTS_ADDITIVE && pCamera->volumetric_environment_enable && m_light_shafts) {
std::string shader_name = pCamera->volumetric_environment_downsample != 0 ? "volumetric_fog_downsampled" : "volumetric_fog";
if(renderPass == KRNode::RENDER_PASS_VOLUMETRIC_EFFECTS_ADDITIVE && pCamera->settings.volumetric_environment_enable && m_light_shafts) {
std::string shader_name = pCamera->settings.volumetric_environment_downsample != 0 ? "volumetric_fog_downsampled" : "volumetric_fog";
std::vector<KRLight *> this_light;
this_light.push_back(this);
@@ -219,14 +219,14 @@ void KRLight::render(KRCamera *pCamera, std::vector<KRLight *> &lights, const KR
if(getContext().getShaderManager()->selectShader(*pCamera, pFogShader, viewport, KRMat4(), this_light, 0, KRNode::RENDER_PASS_VOLUMETRIC_EFFECTS_ADDITIVE)) {
int slice_count = (int)(pCamera->volumetric_environment_quality * 495.0) + 5;
int slice_count = (int)(pCamera->settings.volumetric_environment_quality * 495.0) + 5;
float slice_near = -pCamera->getPerspectiveNearZ();
float slice_far = -pCamera->volumetric_environment_max_distance;
float slice_near = -pCamera->settings.getPerspectiveNearZ();
float slice_far = -pCamera->settings.volumetric_environment_max_distance;
float slice_spacing = (slice_far - slice_near) / slice_count;
KRVector2(slice_near, slice_spacing).setUniform(pFogShader->m_uniforms[KRShader::KRENGINE_UNIFORM_SLICE_DEPTH_SCALE]);
(m_color * pCamera->volumetric_environment_intensity * m_intensity * -slice_spacing / 1000.0f).setUniform(pFogShader->m_uniforms[KRShader::KRENGINE_UNIFORM_LIGHT_COLOR]);
(m_color * pCamera->settings.volumetric_environment_intensity * m_intensity * -slice_spacing / 1000.0f).setUniform(pFogShader->m_uniforms[KRShader::KRENGINE_UNIFORM_LIGHT_COLOR]);
m_pContext->getModelManager()->bindVBO((void *)m_pContext->getModelManager()->getVolumetricLightingVertexes(), KRModelManager::KRENGINE_MAX_VOLUMETRIC_PLANES * 6 * sizeof(KRModelManager::VolumetricLightingVertexData), true, false, false, false, false, false, false);
GLDEBUG(glDrawArrays(GL_TRIANGLES, 0, slice_count*6));

View File

@@ -220,7 +220,7 @@ bool KRMaterial::isTransparent() {
#if TARGET_OS_IPHONE
bool KRMaterial::bind(KRMaterial **prevBoundMaterial, char *szPrevShaderKey, KRCamera *pCamera, std::vector<KRLight *> &lights, const std::vector<KRBone *> &bones, const KRViewport &viewport, const KRMat4 &matModel, KRTexture *pLightMap, KRNode::RenderPass renderPass) {
bool bSameMaterial = *prevBoundMaterial == this;
bool bLightMap = pLightMap && pCamera->bEnableLightMap;
bool bLightMap = pLightMap && pCamera->settings.bEnableLightMap;
if(!m_pAmbientMap && m_ambientMap.size()) {
m_pAmbientMap = getContext().getTextureManager()->getTexture(m_ambientMap.c_str());
@@ -246,11 +246,11 @@ bool KRMaterial::bind(KRMaterial **prevBoundMaterial, char *szPrevShaderKey, KRC
KRVector2 default_offset = KRVector2(0.0f, 0.0f);
bool bHasReflection = m_reflectionColor != KRVector3(0.0f, 0.0f, 0.0f);
bool bDiffuseMap = m_pDiffuseMap != NULL && pCamera->bEnableDiffuseMap;
bool bNormalMap = m_pNormalMap != NULL && pCamera->bEnableNormalMap;
bool bSpecMap = m_pSpecularMap != NULL && pCamera->bEnableSpecMap;
bool bReflectionMap = m_pReflectionMap != NULL && pCamera->bEnableReflectionMap && pCamera->bEnableReflection && bHasReflection;
bool bReflectionCubeMap = m_pReflectionCube != NULL && pCamera->bEnableReflection && bHasReflection;
bool bDiffuseMap = m_pDiffuseMap != NULL && pCamera->settings.bEnableDiffuseMap;
bool bNormalMap = m_pNormalMap != NULL && pCamera->settings.bEnableNormalMap;
bool bSpecMap = m_pSpecularMap != NULL && pCamera->settings.bEnableSpecMap;
bool bReflectionMap = m_pReflectionMap != NULL && pCamera->settings.bEnableReflectionMap && pCamera->settings.bEnableReflection && bHasReflection;
bool bReflectionCubeMap = m_pReflectionCube != NULL && pCamera->settings.bEnableReflection && bHasReflection;
bool bAlphaTest = (m_alpha_mode == KRMATERIAL_ALPHA_MODE_TEST) && bDiffuseMap;
bool bAlphaBlend = (m_alpha_mode == KRMATERIAL_ALPHA_MODE_BLENDONESIDE) || (m_alpha_mode == KRMATERIAL_ALPHA_MODE_BLENDTWOSIDE);
@@ -265,7 +265,7 @@ bool KRMaterial::bind(KRMaterial **prevBoundMaterial, char *szPrevShaderKey, KRC
strcpy(szPrevShaderKey, pShader->getKey());
}
GLDEBUG(glUniform1f(pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_MATERIAL_SHININESS], pCamera->bDebugSuperShiny ? 20.0 : m_ns ));
GLDEBUG(glUniform1f(pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_MATERIAL_SHININESS], pCamera->settings.bDebugSuperShiny ? 20.0 : m_ns ));
// Bind bones
if(pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_BONE_TRANSFORMS] != -1) {
@@ -326,13 +326,13 @@ bool KRMaterial::bind(KRMaterial **prevBoundMaterial, char *szPrevShaderKey, KRC
}
if(!bSameAmbient) {
(m_ambientColor + KRVector3(pCamera->dAmbientR, pCamera->dAmbientG, pCamera->dAmbientB)).setUniform(pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_MATERIAL_AMBIENT]);
(m_ambientColor + pCamera->settings.ambient_intensity).setUniform(pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_MATERIAL_AMBIENT]);
}
if(!bSameDiffuse) {
if(renderPass == KRNode::RENDER_PASS_FORWARD_OPAQUE) {
// We pre-multiply the light color with the material color in the forward renderer
KRVector3(m_diffuseColor.x * pCamera->dSunR, m_diffuseColor.y * pCamera->dSunG, m_diffuseColor.z * pCamera->dSunB).setUniform(pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_MATERIAL_DIFFUSE]);
KRVector3(m_diffuseColor.x * pCamera->settings.light_intensity.x, m_diffuseColor.y * pCamera->settings.light_intensity.y, m_diffuseColor.z * pCamera->settings.light_intensity.z).setUniform(pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_MATERIAL_DIFFUSE]);
} else {
m_diffuseColor.setUniform(pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_MATERIAL_DIFFUSE]);
}
@@ -341,7 +341,7 @@ bool KRMaterial::bind(KRMaterial **prevBoundMaterial, char *szPrevShaderKey, KRC
if(!bSameSpecular) {
if(renderPass == KRNode::RENDER_PASS_FORWARD_OPAQUE) {
// We pre-multiply the light color with the material color in the forward renderer
KRVector3(m_specularColor.x * pCamera->dSunR, m_specularColor.y * pCamera->dSunG, m_specularColor.z * pCamera->dSunB).setUniform(pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_MATERIAL_SPECULAR]);
KRVector3(m_specularColor.x * pCamera->settings.light_intensity.x, m_specularColor.y * pCamera->settings.light_intensity.y, m_specularColor.z * pCamera->settings.light_intensity.z).setUniform(pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_MATERIAL_SPECULAR]);
} else {
m_specularColor.setUniform(pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_MATERIAL_SPECULAR]);
}

View File

@@ -373,17 +373,3 @@ void KRNode::SetAttribute(node_attribute_type attrib, float v)
}
}
KRNode *KRNode::findChild(const std::string &name)
{
if(m_name == name) {
return this;
} else {
for(std::vector<KRNode *>::iterator child_itr = m_childNodes.begin(); child_itr != m_childNodes.end(); child_itr++) {
KRNode *match = (*child_itr)->findChild(name);
if(match) return match;
}
}
return NULL;
}

View File

@@ -53,8 +53,6 @@ public:
void addChild(KRNode *child);
const std::vector<KRNode *> &getChildren();
KRNode *findChild(const std::string &name);
void setLocalTranslation(const KRVector3 &v, bool set_original = false);
void setLocalScale(const KRVector3 &v, bool set_original = false);
void setLocalRotation(const KRVector3 &v, bool set_original = false);
@@ -130,6 +128,43 @@ private:
KRScene *m_pScene;
public:
template <class T> T *find()
{
T *match = dynamic_cast<T *>(this);
if(match) {
return match;
}
for(std::vector<KRNode *>::const_iterator itr=m_childNodes.begin(); itr < m_childNodes.end(); ++itr) {
match = (*itr)->find<T>();
if(match) {
return match;
}
}
return NULL;
}
template <class T> T *find(const std::string &name)
{
T *match = dynamic_cast<T *>(this);
if(match) {
if(name.compare(match->getName())) {
return match;
}
}
for(std::vector<KRNode *>::const_iterator itr=m_childNodes.begin(); itr < m_childNodes.end(); ++itr) {
match = (*itr)->find<T>();
if(match) {
return match;
}
}
return NULL;
}
};

View File

@@ -47,7 +47,7 @@ void KRPointLight::render(KRCamera *pCamera, std::vector<KRLight *> &lights, con
KRLight::render(pCamera, lights, viewport, renderPass);
bool bVisualize = renderPass == KRNode::RENDER_PASS_FORWARD_TRANSPARENT && pCamera->bShowDeferred;
bool bVisualize = renderPass == KRNode::RENDER_PASS_FORWARD_TRANSPARENT && pCamera->settings.bShowDeferred;
if(renderPass == KRNode::RENDER_PASS_DEFERRED_LIGHTS || bVisualize) {
// Lights are rendered on the second pass of the deferred renderer
@@ -69,7 +69,7 @@ void KRPointLight::render(KRCamera *pCamera, std::vector<KRLight *> &lights, con
KRVector3 view_light_position = KRMat4::Dot(viewport.getViewMatrix(), light_position);
bool bInsideLight = view_light_position.sqrMagnitude() <= (influence_radius + pCamera->getPerspectiveNearZ()) * (influence_radius + pCamera->getPerspectiveNearZ());
bool bInsideLight = view_light_position.sqrMagnitude() <= (influence_radius + pCamera->settings.getPerspectiveNearZ()) * (influence_radius + pCamera->settings.getPerspectiveNearZ());
KRShader *pShader = getContext().getShaderManager()->getShader(bVisualize ? "visualize_overlay" : (bInsideLight ? "light_point_inside" : "light_point"), pCamera, this_light, 0, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, renderPass);

View File

@@ -0,0 +1,178 @@
//
// KRRenderSettings.cpp
// KREngine
//
// Created by Kearwood Gilbert on 2012-12-20.
// Copyright (c) 2012 Kearwood Software. All rights reserved.
//
#include "KRRenderSettings.h"
KRRenderSettings::KRRenderSettings()
{
bShowShadowBuffer = false;
bShowOctree = false;
bShowDeferred = false;
bEnablePerPixel = true;
bEnableDiffuseMap = true;
bEnableNormalMap = true;
bEnableSpecMap = true;
bEnableReflectionMap = true;
bEnableReflection = true;
bDebugPSSM = false;
bEnableAmbient = true;
bEnableDiffuse = true;
bEnableSpecular = true;
bEnableLightMap = true;
bDebugSuperShiny = false;
bEnableDeferredLighting = true;
ambient_intensity = KRVector3::Zero();
light_intensity = KRVector3::One();
perspective_fov = 45.0 * D2R;
perspective_nearz = 5.0f;
perspective_farz = 100.0f;
dof_quality = 0;
dof_depth = 0.05f;
dof_falloff = 0.05f;
bEnableFlash = false;
flash_intensity = 1.0f;
flash_depth = 0.7f;
flash_falloff = 0.5f;
bEnableVignette = false;
vignette_radius = 0.4f;
vignette_falloff = 1.0f;
m_cShadowBuffers = 0;
m_skyBoxName = "";
volumetric_environment_enable = false;
volumetric_environment_downsample = 2;
volumetric_environment_max_distance = 1000.0f;
volumetric_environment_quality = (50 - 5.0) / 495.0f;
volumetric_environment_intensity = 0.9f;
fog_near = 500.0f;
fog_far = 5000.0f;
fog_density = 0.0005f;
fog_color = KRVector3(0.45, 0.45, 0.5);
fog_type = 0;
dust_particle_intensity = 0.25f;
dust_particle_enable = false;
}
KRRenderSettings::~KRRenderSettings()
{
}
KRRenderSettings& KRRenderSettings::operator=(const KRRenderSettings &s)
{
bEnablePerPixel = s.bEnablePerPixel;
bEnableDiffuseMap = s.bEnableDiffuseMap;
bEnableNormalMap = s.bEnableNormalMap;
bEnableSpecMap = s.bEnableSpecMap;
bEnableReflectionMap = s.bEnableReflectionMap;
bEnableReflection=s.bEnableReflection;
bEnableLightMap=s.bEnableLightMap;
bDebugPSSM=s.bDebugPSSM;
bDebugSuperShiny=s.bDebugSuperShiny;
bShowShadowBuffer=s.bShowShadowBuffer;
bShowOctree=s.bShowOctree;
bShowDeferred=s.bShowDeferred;
bEnableAmbient=s.bEnableAmbient;
bEnableDiffuse=s.bEnableDiffuse;
bEnableSpecular=s.bEnableSpecular;
bEnableDeferredLighting=s.bEnableDeferredLighting;
light_intensity=s.light_intensity;
ambient_intensity=s.ambient_intensity;
perspective_fov=s.perspective_fov;
dof_quality=s.dof_quality;
dof_depth=s.dof_depth;
dof_falloff=s.dof_falloff;
bEnableFlash=s.bEnableFlash;
flash_intensity=s.flash_intensity;
flash_depth=s.flash_depth;
flash_falloff=s.flash_falloff;
bEnableVignette=s.bEnableVignette;
vignette_radius=s.vignette_radius;
vignette_falloff=s.vignette_falloff;
m_viewportSize=s.m_viewportSize;
m_cShadowBuffers=s.m_cShadowBuffers;
m_debug_text=s.m_debug_text;
volumetric_environment_enable=s.volumetric_environment_enable;
volumetric_environment_downsample=s.volumetric_environment_downsample;
volumetric_environment_max_distance=s.volumetric_environment_max_distance;
volumetric_environment_quality=s.volumetric_environment_quality;
volumetric_environment_intensity=s.volumetric_environment_intensity;
fog_near=s.fog_near;
fog_far=s.fog_far;
fog_density=s.fog_density;
fog_color=s.fog_color;
fog_type=s.fog_type;
dust_particle_intensity=s.dust_particle_intensity;
dust_particle_enable=s.dust_particle_enable;
perspective_nearz=s.perspective_nearz;
perspective_farz=s.perspective_farz;
m_skyBoxName=s.m_skyBoxName;
return *this;
}
const KRVector2 &KRRenderSettings::getViewportSize() {
return m_viewportSize;
}
void KRRenderSettings::setViewportSize(const KRVector2 &size) {
m_viewportSize = size;
}
void KRRenderSettings::setSkyBox(const std::string &skyBoxName) {
m_skyBoxName = skyBoxName;
}
float KRRenderSettings::getPerspectiveNearZ()
{
return perspective_nearz;
}
float KRRenderSettings::getPerspectiveFarZ()
{
return perspective_farz;
}
void KRRenderSettings::setPerspectiveNear(float v)
{
if(perspective_nearz != v) {
perspective_nearz = v;
}
}
void KRRenderSettings::setPerpsectiveFarZ(float v)
{
if(perspective_farz != v) {
perspective_farz = v;
}
}

View File

@@ -0,0 +1,91 @@
//
// KRRenderSettings.h
// KREngine
//
// Created by Kearwood Gilbert on 2012-12-20.
// Copyright (c) 2012 Kearwood Software. All rights reserved.
//
#ifndef KRRENDERSETTINGS_H
#define KRRENDERSETTINGS_H
#include "KREngine-common.h"
class KRRenderSettings {
public:
KRRenderSettings();
~KRRenderSettings();
// Overload assignment operator
KRRenderSettings& operator=(const KRRenderSettings &s);
const KRVector2 &getViewportSize();
void setViewportSize(const KRVector2 &size);
void setSkyBox(const std::string &skyBoxName);
float getPerspectiveNearZ();
float getPerspectiveFarZ();
void setPerspectiveNear(float v);
void setPerpsectiveFarZ(float v);
bool bEnablePerPixel;
bool bEnableDiffuseMap;
bool bEnableNormalMap;
bool bEnableSpecMap;
bool bEnableReflectionMap;
bool bEnableReflection;
bool bEnableLightMap;
bool bDebugPSSM;
bool bDebugSuperShiny;
bool bShowShadowBuffer;
bool bShowOctree;
bool bShowDeferred;
bool bEnableAmbient;
bool bEnableDiffuse;
bool bEnableSpecular;
bool bEnableDeferredLighting;
KRVector3 light_intensity;
KRVector3 ambient_intensity;
float perspective_fov;
int dof_quality;
float dof_depth;
float dof_falloff;
bool bEnableFlash;
float flash_intensity;
float flash_depth;
float flash_falloff;
bool bEnableVignette;
float vignette_radius;
float vignette_falloff;
KRVector2 m_viewportSize;
int m_cShadowBuffers;
std::string m_debug_text;
bool volumetric_environment_enable;
int volumetric_environment_downsample;
float volumetric_environment_max_distance;
float volumetric_environment_quality;
float volumetric_environment_intensity;
float fog_near;
float fog_far;
float fog_density;
KRVector3 fog_color;
int fog_type; // 0 = no fog, 1 = linear, 2 = exponential, 3 = exponential squared
float dust_particle_intensity;
bool dust_particle_enable;
float perspective_nearz;
float perspective_farz;
std::string m_skyBoxName;
private:
};
#endif

View File

@@ -731,6 +731,9 @@ void LoadNode(KFbxScene* pFbxScene, KRNode *parent_node, std::vector<KRResource
case KFbxNodeAttribute::eSkeleton:
new_node = LoadSkeleton(parent_node, resources, pNode);
break;
case KFbxNodeAttribute::eCamera:
new_node = LoadCamera(parent_node, resources, pNode);
break;
default:
{
if(pNode->GetChildCount() > 0) {
@@ -1174,6 +1177,14 @@ KRNode *LoadSkeleton(KRNode *parent_node, std::vector<KRResource *> &resources,
return new_bone;
}
KRNode *LoadCamera(KRNode *parent_node, std::vector<KRResource *> &resources, KFbxNode* pNode) {
FbxCamera *camera = (FbxCamera *)pNode->GetNodeAttribute();
const char *szName = pNode->GetName();
KRCamera *new_camera = new KRCamera(parent_node->getScene(), szName);
return new_camera;
}
KRNode *LoadLight(KRNode *parent_node, std::vector<KRResource *> &resources, KFbxNode* pNode) {
const GLfloat PI = 3.14159265;
const GLfloat d2r = PI * 2 / 360;

View File

@@ -58,9 +58,24 @@ KRScene::~KRScene() {
m_pRootNode = NULL;
}
#if TARGET_OS_IPHONE
void KRScene::renderFrame(float deltaTime) {
getContext().startFrame(deltaTime);
KRCamera *camera = find<KRCamera>();
if(camera == NULL) {
}
camera->renderFrame(deltaTime);
getContext().endFrame(deltaTime);
}
void KRScene::render(KRCamera *pCamera, std::map<KRAABB, int> &visibleBounds, const KRViewport &viewport, KRNode::RenderPass renderPass, bool new_frame) {
if(new_frame) {
// Expire cached occlusion test results.
// Cached "failed" results are expired on the next frame (marked with .second of -1)
@@ -76,11 +91,14 @@ void KRScene::render(KRCamera *pCamera, std::map<KRAABB, int> &visibleBounds, co
}
}
if(getFirstLight() == NULL) {
addDefaultLights();
}
std::vector<KRLight *> lights;
updateOctree();
pCamera->setSkyBox(m_skyBoxName); // This is temporary until the camera is moved into the scene graph
pCamera->settings.setSkyBox(m_skyBoxName); // This is temporary until the camera is moved into the scene graph
std::set<KRNode *> outerNodes = std::set<KRNode *>(m_nodeTree.getOuterSceneNodes()); // HACK - Copying the std::set as it is potentially modified as KRNode's update their bounds during the iteration. This is very expensive and will be eliminated in the future.
@@ -171,7 +189,7 @@ void KRScene::render(KROctreeNode *pOctreeNode, std::map<KRAABB, int> &visibleBo
if(!bVisible) {
// Assume bounding boxes are visible without occlusion test queries if the camera is inside the box.
// The near clipping plane of the camera is taken into consideration by expanding the match area
KRAABB cameraExtents = KRAABB(viewport.getCameraPosition() - KRVector3(pCamera->getPerspectiveNearZ()), viewport.getCameraPosition() + KRVector3(pCamera->getPerspectiveNearZ()));
KRAABB cameraExtents = KRAABB(viewport.getCameraPosition() - KRVector3(pCamera->settings.getPerspectiveNearZ()), viewport.getCameraPosition() + KRVector3(pCamera->settings.getPerspectiveNearZ()));
bVisible = octreeBounds.intersects(cameraExtents);
if(bVisible) {
// Record the frame number in which the camera was within the bounds
@@ -334,23 +352,6 @@ bool KRScene::save(KRDataBlock &data) {
return true;
}
KRLight *KRScene::findFirstLight(KRNode &node) {
KRLight *pLight = dynamic_cast<KRLight *>(&node);
if(pLight) {
return pLight;
} else {
const std::vector<KRNode *> children = node.getChildren();
for(std::vector<KRNode *>::const_iterator itr=children.begin(); itr < children.end(); ++itr) {
pLight = findFirstLight(*(*itr));
if(pLight) {
return pLight;
}
}
}
return NULL;
}
KRScene *KRScene::Load(KRContext &context, const std::string &name, KRDataBlock *data)
{
data->append((void *)"\0", 1); // Ensure data is null terminated, to read as a string safely
@@ -371,10 +372,12 @@ KRScene *KRScene::Load(KRContext &context, const std::string &name, KRDataBlock
return new_scene;
}
KRLight *KRScene::getFirstLight()
{
if(m_pFirstLight == NULL) {
m_pFirstLight = findFirstLight(*m_pRootNode);
m_pFirstLight = find<KRLight>();
}
return m_pFirstLight;
}

View File

@@ -52,6 +52,8 @@ public:
KRScene(KRContext &context, std::string name);
virtual ~KRScene();
virtual std::string getExtension();
virtual bool save(KRDataBlock &data);
@@ -64,7 +66,7 @@ public:
bool rayCast(const KRVector3 &v0, const KRVector3 &dir, KRHitInfo &hitinfo);
#if TARGET_OS_IPHONE
void renderFrame(float deltaTime);
void render(KRCamera *pCamera, std::map<KRAABB, int> &visibleBounds, const KRViewport &viewport, KRNode::RenderPass renderPass, bool new_frame);
void render(KROctreeNode *pOctreeNode, std::map<KRAABB, int> &visibleBounds, KRCamera *pCamera, std::vector<KRLight *> lights, const KRViewport &viewport, KRNode::RenderPass renderPass, std::vector<KROctreeNode *> &remainingOctrees, std::vector<KROctreeNode *> &remainingOctreesTestResults, std::vector<KROctreeNode *> &remainingOctreesTestResultsOnly, bool bOcclusionResultsPass, bool bOcclusionTestResultsOnly);
@@ -82,7 +84,6 @@ public:
KRAABB getRootOctreeBounds();
private:
KRLight *findFirstLight(KRNode &node);
KRNode *m_pRootNode;
KRLight *m_pFirstLight;
@@ -98,6 +99,20 @@ private:
void updateOctree();
std::string m_skyBoxName;
public:
template <class T> T *find()
{
if(m_pRootNode) return m_pRootNode->find<T>();
return NULL;
}
template <class T> T *find(const std::string &name)
{
if(m_pRootNode) return m_pRootNode->find<T>(name);
return NULL;
}
};

View File

@@ -259,7 +259,7 @@ bool KRShader::bind(KRCamera &camera, const KRViewport &viewport, const KRMat4 &
GLDEBUG(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE));
}
if(m_uniforms[KRENGINE_UNIFORM_SHADOWTEXTURE2] != -1 && cShadowBuffers > 1 && camera.m_cShadowBuffers > 1) {
if(m_uniforms[KRENGINE_UNIFORM_SHADOWTEXTURE2] != -1 && cShadowBuffers > 1 && camera.settings.m_cShadowBuffers > 1) {
m_pContext->getTextureManager()->selectTexture(4, NULL);
GLDEBUG(glActiveTexture(GL_TEXTURE4));
GLDEBUG(glBindTexture(GL_TEXTURE_2D, directional_light->getShadowTextures()[1]));
@@ -269,7 +269,7 @@ bool KRShader::bind(KRCamera &camera, const KRViewport &viewport, const KRMat4 &
GLDEBUG(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE));
}
if(m_uniforms[KRENGINE_UNIFORM_SHADOWTEXTURE3] != -1 && cShadowBuffers > 2 && camera.m_cShadowBuffers > 2) {
if(m_uniforms[KRENGINE_UNIFORM_SHADOWTEXTURE3] != -1 && cShadowBuffers > 2 && camera.settings.m_cShadowBuffers > 2) {
m_pContext->getTextureManager()->selectTexture(5, NULL);
GLDEBUG(glActiveTexture(GL_TEXTURE5));
GLDEBUG(glBindTexture(GL_TEXTURE_2D, directional_light->getShadowTextures()[2]));
@@ -391,20 +391,20 @@ bool KRShader::bind(KRCamera &camera, const KRViewport &viewport, const KRMat4 &
}
// Fog parameters
GLDEBUG(glUniform1f(m_uniforms[KRENGINE_UNIFORM_FOG_NEAR], camera.fog_near));
GLDEBUG(glUniform1f(m_uniforms[KRENGINE_UNIFORM_FOG_FAR], camera.fog_far));
GLDEBUG(glUniform1f(m_uniforms[KRENGINE_UNIFORM_FOG_DENSITY], camera.fog_density));
camera.fog_color.setUniform(m_uniforms[KRENGINE_UNIFORM_FOG_COLOR]);
GLDEBUG(glUniform1f(m_uniforms[KRENGINE_UNIFORM_FOG_NEAR], camera.settings.fog_near));
GLDEBUG(glUniform1f(m_uniforms[KRENGINE_UNIFORM_FOG_FAR], camera.settings.fog_far));
GLDEBUG(glUniform1f(m_uniforms[KRENGINE_UNIFORM_FOG_DENSITY], camera.settings.fog_density));
camera.settings.fog_color.setUniform(m_uniforms[KRENGINE_UNIFORM_FOG_COLOR]);
if(m_uniforms[KRENGINE_UNIFORM_FOG_SCALE] != -1) {
GLDEBUG(glUniform1f(m_uniforms[KRENGINE_UNIFORM_FOG_SCALE], 1.0f / (camera.fog_far - camera.fog_near)));
GLDEBUG(glUniform1f(m_uniforms[KRENGINE_UNIFORM_FOG_SCALE], 1.0f / (camera.settings.fog_far - camera.settings.fog_near)));
}
if(m_uniforms[KRENGINE_UNIFORM_DENSITY_PREMULTIPLIED_EXPONENTIAL] != -1) {
GLDEBUG(glUniform1f(m_uniforms[KRENGINE_UNIFORM_DENSITY_PREMULTIPLIED_EXPONENTIAL], -camera.fog_density * 1.442695f)); // -fog_density / log(2)
GLDEBUG(glUniform1f(m_uniforms[KRENGINE_UNIFORM_DENSITY_PREMULTIPLIED_EXPONENTIAL], -camera.settings.fog_density * 1.442695f)); // -fog_density / log(2)
}
if(m_uniforms[KRENGINE_UNIFORM_DENSITY_PREMULTIPLIED_SQUARED] != -1) {
GLDEBUG(glUniform1f(m_uniforms[KRENGINE_UNIFORM_DENSITY_PREMULTIPLIED_SQUARED], -camera.fog_density * camera.fog_density * 1.442695)); // -fog_density * fog_density / log(2)
GLDEBUG(glUniform1f(m_uniforms[KRENGINE_UNIFORM_DENSITY_PREMULTIPLIED_SQUARED], -camera.settings.fog_density * camera.settings.fog_density * 1.442695)); // -fog_density * fog_density / log(2)
}
// Sets the diffuseTexture variable to the first texture unit

View File

@@ -73,12 +73,12 @@ KRShader *KRShaderManager::getShader(const std::string &shader_name, KRCamera *p
}
}
if(iShadowQuality > pCamera->m_cShadowBuffers) {
iShadowQuality = pCamera->m_cShadowBuffers;
if(iShadowQuality > pCamera->settings.m_cShadowBuffers) {
iShadowQuality = pCamera->settings.m_cShadowBuffers;
}
char szKey[256];
sprintf(szKey, "%i_%i_%i_%i_%i_%d_%d_%d_%d_%d_%d_%d_%d_%d_%d_%d_%d_%d_%d_%d_%d_%d_%d_%d_%d_%d_%d_%d_%i_%s_%i_%d_%d_%f_%f_%f_%f_%f_%f_%f", light_directional_count, light_point_count, light_spot_count, bone_count, pCamera->fog_type, pCamera->bEnablePerPixel,bAlphaTest, bAlphaBlend, bDiffuseMap, bNormalMap, bSpecMap, bReflectionMap, bReflectionCubeMap, pCamera->bDebugPSSM, iShadowQuality, pCamera->bEnableAmbient, pCamera->bEnableDiffuse, pCamera->bEnableSpecular, bLightMap, bDiffuseMapScale, bSpecMapScale, bReflectionMapScale, bNormalMapScale, bDiffuseMapOffset, bSpecMapOffset, bReflectionMapOffset, bNormalMapOffset,pCamera->volumetric_environment_enable && pCamera->volumetric_environment_downsample != 0, renderPass, shader_name.c_str(),pCamera->dof_quality,pCamera->bEnableFlash,pCamera->bEnableVignette,pCamera->dof_depth,pCamera->dof_falloff,pCamera->flash_depth,pCamera->flash_falloff,pCamera->flash_intensity,pCamera->vignette_radius,pCamera->vignette_falloff);
sprintf(szKey, "%i_%i_%i_%i_%i_%d_%d_%d_%d_%d_%d_%d_%d_%d_%d_%d_%d_%d_%d_%d_%d_%d_%d_%d_%d_%d_%d_%d_%i_%s_%i_%d_%d_%f_%f_%f_%f_%f_%f_%f", light_directional_count, light_point_count, light_spot_count, bone_count, pCamera->settings.fog_type, pCamera->settings.bEnablePerPixel,bAlphaTest, bAlphaBlend, bDiffuseMap, bNormalMap, bSpecMap, bReflectionMap, bReflectionCubeMap, pCamera->settings.bDebugPSSM, iShadowQuality, pCamera->settings.bEnableAmbient, pCamera->settings.bEnableDiffuse, pCamera->settings.bEnableSpecular, bLightMap, bDiffuseMapScale, bSpecMapScale, bReflectionMapScale, bNormalMapScale, bDiffuseMapOffset, bSpecMapOffset, bReflectionMapOffset, bNormalMapOffset,pCamera->settings.volumetric_environment_enable && pCamera->settings.volumetric_environment_downsample != 0, renderPass, shader_name.c_str(),pCamera->settings.dof_quality,pCamera->settings.bEnableFlash,pCamera->settings.bEnableVignette,pCamera->settings.dof_depth,pCamera->settings.dof_falloff,pCamera->settings.flash_depth,pCamera->settings.flash_falloff,pCamera->settings.flash_intensity,pCamera->settings.vignette_radius,pCamera->settings.vignette_falloff);
KRShader *pShader = m_shaders[szKey];
@@ -120,13 +120,13 @@ KRShader *KRShaderManager::getShader(const std::string &shader_name, KRCamera *p
stream << "\n#define ALPHA_TEST " << (bAlphaTest ? "1" : "0");
stream << "\n#define ALPHA_BLEND " << (bAlphaBlend ? "1" : "0");
stream << "\n#define ENABLE_PER_PIXEL " << (pCamera->bEnablePerPixel ? "1" : "0");
stream << "\n#define DEBUG_PSSM " << (pCamera->bDebugPSSM ? "1" : "0");
stream << "\n#define ENABLE_PER_PIXEL " << (pCamera->settings.bEnablePerPixel ? "1" : "0");
stream << "\n#define DEBUG_PSSM " << (pCamera->settings.bDebugPSSM ? "1" : "0");
stream << "\n#define SHADOW_QUALITY " << iShadowQuality;
stream << "\n#define ENABLE_AMBIENT " << (pCamera->bEnableAmbient ? "1" : "0");
stream << "\n#define ENABLE_DIFFUSE " << (pCamera->bEnableDiffuse ? "1" : "0");
stream << "\n#define ENABLE_SPECULAR " << (pCamera->bEnableSpecular ? "1" : "0");
stream << "\n#define FOG_TYPE " << pCamera->fog_type;
stream << "\n#define ENABLE_AMBIENT " << (pCamera->settings.bEnableAmbient ? "1" : "0");
stream << "\n#define ENABLE_DIFFUSE " << (pCamera->settings.bEnableDiffuse ? "1" : "0");
stream << "\n#define ENABLE_SPECULAR " << (pCamera->settings.bEnableSpecular ? "1" : "0");
stream << "\n#define FOG_TYPE " << pCamera->settings.fog_type;
switch(renderPass) {
case KRNode::RENDER_PASS_DEFERRED_GBUFFER:
stream << "\n#define GBUFFER_PASS " << 1;
@@ -142,10 +142,10 @@ KRShader *KRShaderManager::getShader(const std::string &shader_name, KRCamera *p
break;
}
stream << "\n#define DOF_QUALITY " << pCamera->dof_quality;
stream << "\n#define ENABLE_FLASH " << (pCamera->bEnableFlash ? "1" : "0");
stream << "\n#define ENABLE_VIGNETTE " << (pCamera->bEnableVignette ? "1" : "0");
stream << "\n#define VOLUMETRIC_ENVIRONMENT_DOWNSAMPLED " << (pCamera->volumetric_environment_enable && pCamera->volumetric_environment_downsample != 0 ? "1" : "0");
stream << "\n#define DOF_QUALITY " << pCamera->settings.dof_quality;
stream << "\n#define ENABLE_FLASH " << (pCamera->settings.bEnableFlash ? "1" : "0");
stream << "\n#define ENABLE_VIGNETTE " << (pCamera->settings.bEnableVignette ? "1" : "0");
stream << "\n#define VOLUMETRIC_ENVIRONMENT_DOWNSAMPLED " << (pCamera->settings.volumetric_environment_enable && pCamera->settings.volumetric_environment_downsample != 0 ? "1" : "0");
@@ -153,13 +153,13 @@ KRShader *KRShaderManager::getShader(const std::string &shader_name, KRCamera *p
stream.precision(std::numeric_limits<long double>::digits10);
stream << "\n#define DOF_DEPTH " << pCamera->dof_depth;
stream << "\n#define DOF_FALLOFF " << pCamera->dof_falloff;
stream << "\n#define FLASH_DEPTH " << pCamera->flash_depth;
stream << "\n#define FLASH_FALLOFF " << pCamera->flash_falloff;
stream << "\n#define FLASH_INTENSITY " << pCamera->flash_intensity;
stream << "\n#define VIGNETTE_RADIUS " << pCamera->vignette_radius;
stream << "\n#define VIGNETTE_FALLOFF " << pCamera->vignette_falloff;
stream << "\n#define DOF_DEPTH " << pCamera->settings.dof_depth;
stream << "\n#define DOF_FALLOFF " << pCamera->settings.dof_falloff;
stream << "\n#define FLASH_DEPTH " << pCamera->settings.flash_depth;
stream << "\n#define FLASH_FALLOFF " << pCamera->settings.flash_falloff;
stream << "\n#define FLASH_INTENSITY " << pCamera->settings.flash_intensity;
stream << "\n#define VIGNETTE_RADIUS " << pCamera->settings.vignette_radius;
stream << "\n#define VIGNETTE_FALLOFF " << pCamera->settings.vignette_falloff;
stream << "\n";
std::string options = stream.str();