2011-10-25 05:03:10 +00:00
|
|
|
//
|
|
|
|
|
// KREngine.mm
|
2012-03-15 20:09:01 +00:00
|
|
|
// KREngine
|
2011-10-25 05:03:10 +00:00
|
|
|
//
|
2012-03-15 20:09:01 +00:00
|
|
|
// Copyright 2012 Kearwood Gilbert. All rights reserved.
|
2011-10-25 06:16:47 +00:00
|
|
|
//
|
|
|
|
|
// Redistribution and use in source and binary forms, with or without modification, are
|
|
|
|
|
// permitted provided that the following conditions are met:
|
|
|
|
|
//
|
|
|
|
|
// 1. Redistributions of source code must retain the above copyright notice, this list of
|
|
|
|
|
// conditions and the following disclaimer.
|
|
|
|
|
//
|
|
|
|
|
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
|
|
|
|
// of conditions and the following disclaimer in the documentation and/or other materials
|
|
|
|
|
// provided with the distribution.
|
|
|
|
|
//
|
|
|
|
|
// THIS SOFTWARE IS PROVIDED BY KEARWOOD GILBERT ''AS IS'' AND ANY EXPRESS OR IMPLIED
|
|
|
|
|
// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
|
|
|
|
// FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL KEARWOOD GILBERT OR
|
|
|
|
|
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
|
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
|
|
|
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
|
|
|
|
// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
|
|
|
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
|
|
|
|
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
//
|
|
|
|
|
// The views and conclusions contained in the software and documentation are those of the
|
|
|
|
|
// authors and should not be interpreted as representing official policies, either expressed
|
|
|
|
|
// or implied, of Kearwood Gilbert.
|
2011-10-25 05:03:10 +00:00
|
|
|
//
|
|
|
|
|
|
2012-10-19 23:17:43 +00:00
|
|
|
#import <UIKit/UIKit.h>
|
|
|
|
|
|
2011-10-25 05:03:10 +00:00
|
|
|
#import "KREngine.h"
|
|
|
|
|
#import "KRVector3.h"
|
|
|
|
|
#import "KRScene.h"
|
2012-04-12 00:43:53 +00:00
|
|
|
#import "KRSceneManager.h"
|
2012-06-14 19:33:17 +00:00
|
|
|
#import "KRNode.h"
|
2011-10-25 05:03:10 +00:00
|
|
|
|
|
|
|
|
#import <string>
|
|
|
|
|
#import <sstream>
|
|
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@interface KREngine (PrivateMethods)
|
|
|
|
|
- (BOOL)loadShaders;
|
|
|
|
|
- (BOOL)loadResource:(NSString *)path;
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
|
|
@implementation KREngine
|
2012-08-15 21:26:06 +00:00
|
|
|
@synthesize debug_text = _debug_text;
|
2012-10-20 02:15:48 +00:00
|
|
|
float const PI = 3.141592653589793f;
|
2011-10-25 05:03:10 +00:00
|
|
|
|
2012-10-19 18:28:18 +00:00
|
|
|
|
|
|
|
|
+ (KREngine *)sharedInstance
|
|
|
|
|
{
|
|
|
|
|
static KREngine *sharedInstance = nil;
|
|
|
|
|
static dispatch_once_t onceToken;
|
|
|
|
|
dispatch_once(&onceToken, ^{
|
|
|
|
|
sharedInstance = [[KREngine alloc] init];
|
|
|
|
|
});
|
|
|
|
|
return sharedInstance;
|
|
|
|
|
}
|
|
|
|
|
|
2012-10-17 19:43:15 +00:00
|
|
|
- (id)init
|
2012-08-15 21:26:06 +00:00
|
|
|
{
|
2012-10-19 23:17:43 +00:00
|
|
|
BOOL isIpad = UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad;
|
|
|
|
|
BOOL isRetina = [[UIScreen mainScreen] scale] >= 2.0;
|
|
|
|
|
|
|
|
|
|
if(isIpad && isRetina) {
|
|
|
|
|
KRContext::KRENGINE_MAX_VBO_HANDLES = 10000;
|
|
|
|
|
KRContext::KRENGINE_MAX_VBO_MEM = 128000000 * 2;
|
|
|
|
|
KRContext::KRENGINE_MAX_SHADER_HANDLES = 100;
|
|
|
|
|
KRContext::KRENGINE_MAX_TEXTURE_HANDLES = 10000;
|
|
|
|
|
KRContext::KRENGINE_MAX_TEXTURE_MEM = 64000000 * 2;
|
|
|
|
|
KRContext::KRENGINE_TARGET_TEXTURE_MEM_MAX = 48000000 * 2;
|
|
|
|
|
KRContext::KRENGINE_TARGET_TEXTURE_MEM_MIN = 32000000 * 2;
|
|
|
|
|
KRContext::KRENGINE_MAX_TEXTURE_DIM = 2048;
|
|
|
|
|
KRContext::KRENGINE_MIN_TEXTURE_DIM = 64;
|
|
|
|
|
} else {
|
|
|
|
|
KRContext::KRENGINE_MAX_VBO_HANDLES = 10000;
|
|
|
|
|
KRContext::KRENGINE_MAX_VBO_MEM = 128000000;
|
|
|
|
|
KRContext::KRENGINE_MAX_SHADER_HANDLES = 100;
|
|
|
|
|
KRContext::KRENGINE_MAX_TEXTURE_HANDLES = 10000;
|
|
|
|
|
KRContext::KRENGINE_MAX_TEXTURE_MEM = 64000000;
|
|
|
|
|
KRContext::KRENGINE_TARGET_TEXTURE_MEM_MAX = 48000000;
|
|
|
|
|
KRContext::KRENGINE_TARGET_TEXTURE_MEM_MIN = 32000000;
|
|
|
|
|
KRContext::KRENGINE_MAX_TEXTURE_DIM = 2048;
|
|
|
|
|
KRContext::KRENGINE_MIN_TEXTURE_DIM = 64;
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-16 20:44:33 +00:00
|
|
|
_camera = NULL;
|
|
|
|
|
_context = NULL;
|
2011-10-25 05:03:10 +00:00
|
|
|
if ((self = [super init])) {
|
2012-08-16 20:44:33 +00:00
|
|
|
_context = new KRContext();
|
2012-10-17 19:43:15 +00:00
|
|
|
_camera = new KRCamera(*_context);
|
2012-08-23 16:55:46 +00:00
|
|
|
_parameter_names = [@{
|
2012-08-16 22:50:30 +00:00
|
|
|
@"camera_fov" : @0,
|
|
|
|
|
@"shadow_quality" : @1,
|
|
|
|
|
@"enable_per_pixel" : @2,
|
|
|
|
|
@"enable_diffuse_map" : @3,
|
|
|
|
|
@"enable_normal_map" : @4,
|
|
|
|
|
@"enable_spec_map" : @5,
|
|
|
|
|
@"enable_reflection_map" : @6,
|
|
|
|
|
@"enable_light_map" : @7,
|
2012-09-21 05:59:24 +00:00
|
|
|
@"ambient_temp" : @8,
|
|
|
|
|
@"ambient_intensity" : @9,
|
|
|
|
|
@"sun_temp": @10,
|
|
|
|
|
@"sun_intensity": @11,
|
|
|
|
|
@"dof_quality" : @12,
|
|
|
|
|
@"dof_depth" : @13,
|
|
|
|
|
@"dof_falloff" : @14,
|
|
|
|
|
@"flash_enable" : @15,
|
|
|
|
|
@"flash_intensity" : @16,
|
|
|
|
|
@"flash_depth" : @17,
|
|
|
|
|
@"flash_falloff" : @18,
|
|
|
|
|
@"vignette_enable" : @19,
|
|
|
|
|
@"vignette_radius" : @20,
|
|
|
|
|
@"vignette_falloff" : @21,
|
|
|
|
|
@"debug_shadowmap" : @22,
|
|
|
|
|
@"debug_pssm" : @23,
|
|
|
|
|
@"debug_enable_ambient" : @24,
|
|
|
|
|
@"debug_enable_diffuse" : @25,
|
|
|
|
|
@"debug_enable_specular" : @26,
|
2012-10-12 00:02:24 +00:00
|
|
|
@"debug_enable_reflection" : @27,
|
|
|
|
|
@"debug_super_shiny" : @28,
|
|
|
|
|
@"debug_octree" : @29,
|
|
|
|
|
@"debug_deferred" : @30,
|
2012-10-27 00:50:17 +00:00
|
|
|
@"enable_deferred_lighting" : @31,
|
|
|
|
|
@"near_clip" : @32,
|
|
|
|
|
@"far_clip" : @33
|
2012-08-23 16:55:46 +00:00
|
|
|
} copy];
|
2012-08-15 21:26:06 +00:00
|
|
|
[self loadShaders];
|
2011-10-25 05:03:10 +00:00
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return self;
|
|
|
|
|
}
|
|
|
|
|
|
2012-11-02 20:50:45 +00:00
|
|
|
- (void)renderScene: (KRScene *)pScene WithPosition: (KRVector3)position Yaw: (GLfloat)yaw Pitch: (GLfloat)pitch Roll: (GLfloat)roll AndDeltaTime: (float)deltaTime
|
2011-10-25 05:03:10 +00:00
|
|
|
{
|
|
|
|
|
KRMat4 viewMatrix;
|
|
|
|
|
viewMatrix.translate(-position.x, -position.y, -position.z);
|
|
|
|
|
viewMatrix.rotate(yaw, Y_AXIS);
|
|
|
|
|
viewMatrix.rotate(pitch, X_AXIS);
|
|
|
|
|
viewMatrix.rotate(roll, Z_AXIS);
|
2012-04-20 00:17:15 +00:00
|
|
|
|
2012-11-02 20:50:45 +00:00
|
|
|
[self renderScene: pScene WithViewMatrix: viewMatrix AndDeltaTime: deltaTime];
|
2011-10-25 05:03:10 +00:00
|
|
|
}
|
|
|
|
|
|
2012-11-02 20:50:45 +00:00
|
|
|
- (void)renderScene: (KRScene *)pScene WithViewMatrix: (KRMat4)viewMatrix AndDeltaTime: (float)deltaTime
|
2011-10-25 05:03:10 +00:00
|
|
|
{
|
2012-11-02 20:50:45 +00:00
|
|
|
_camera->renderFrame(*pScene, viewMatrix, deltaTime);
|
2011-10-25 05:03:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (BOOL)loadShaders
|
|
|
|
|
{
|
2012-04-13 23:24:07 +00:00
|
|
|
NSFileManager* fileManager = [NSFileManager defaultManager];
|
|
|
|
|
NSString *bundle_directory = [[NSBundle mainBundle] bundlePath];
|
|
|
|
|
for (NSString* fileName in [fileManager contentsOfDirectoryAtPath: bundle_directory error:nil]) {
|
2012-09-11 04:32:04 +00:00
|
|
|
if([fileName hasSuffix: @".vsh"] || [fileName hasSuffix: @".fsh"] || [fileName isEqualToString:@"font.pvr"]) {
|
2012-04-13 23:24:07 +00:00
|
|
|
NSString* path = [NSString stringWithFormat:@"%@/%@", bundle_directory, fileName];
|
2012-08-16 20:44:33 +00:00
|
|
|
_context->loadResource([path UTF8String]);
|
2012-04-13 23:24:07 +00:00
|
|
|
}
|
|
|
|
|
}
|
2011-10-25 05:03:10 +00:00
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (BOOL)loadResource:(NSString *)path
|
|
|
|
|
{
|
2012-08-16 20:44:33 +00:00
|
|
|
_context->loadResource([path UTF8String]);
|
2011-10-25 05:03:10 +00:00
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)dealloc
|
2012-04-12 00:43:53 +00:00
|
|
|
{
|
2012-08-16 22:50:30 +00:00
|
|
|
[_parameter_names release]; _parameter_names = nil;
|
2012-08-16 20:44:33 +00:00
|
|
|
if(_camera) {
|
|
|
|
|
delete _camera; _camera = NULL;
|
|
|
|
|
}
|
|
|
|
|
if(_context) {
|
|
|
|
|
delete _context; _context = NULL;
|
|
|
|
|
}
|
2011-10-25 05:03:10 +00:00
|
|
|
[super dealloc];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
-(int)getParameterCount
|
|
|
|
|
{
|
2012-10-27 00:50:17 +00:00
|
|
|
return 34;
|
2011-10-25 05:03:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
-(NSString *)getParameterNameWithIndex: (int)i
|
|
|
|
|
{
|
2012-08-16 22:50:30 +00:00
|
|
|
return [[self.parameter_names allKeysForObject:[NSNumber numberWithInt:i]] objectAtIndex:0];
|
2011-10-25 05:03:10 +00:00
|
|
|
}
|
2012-08-16 22:50:30 +00:00
|
|
|
|
2011-10-25 05:03:10 +00:00
|
|
|
-(NSString *)getParameterLabelWithIndex: (int)i
|
|
|
|
|
{
|
2012-10-27 00:50:17 +00:00
|
|
|
NSString *parameter_labels[34] = {
|
2011-10-25 05:03:10 +00:00
|
|
|
@"Camera FOV",
|
|
|
|
|
@"Shadow Quality (0 - 2)",
|
|
|
|
|
@"Enable per-pixel lighting",
|
|
|
|
|
@"Enable diffuse map",
|
|
|
|
|
@"Enable normal map",
|
|
|
|
|
@"Enable specular map",
|
2012-05-08 23:39:52 +00:00
|
|
|
@"Enable reflection map",
|
2012-04-12 06:25:44 +00:00
|
|
|
@"Enable light map",
|
2012-09-21 05:59:24 +00:00
|
|
|
@"Ambient Color Temp",
|
|
|
|
|
@"Ambient Intensity",
|
|
|
|
|
@"Sun Color Temp",
|
|
|
|
|
@"Sun Intensity",
|
2011-10-25 05:03:10 +00:00
|
|
|
@"DOF Quality",
|
|
|
|
|
@"DOF Depth",
|
|
|
|
|
@"DOF Falloff",
|
|
|
|
|
@"Enable Night/Flash Effect",
|
|
|
|
|
@"Flash Intensity",
|
|
|
|
|
@"Flash Depth",
|
|
|
|
|
@"Flash Falloff",
|
|
|
|
|
@"Enable Vignette",
|
|
|
|
|
@"Vignette Radius",
|
|
|
|
|
@"Vignette Falloff",
|
2012-03-29 19:39:28 +00:00
|
|
|
@"Debug - View Shadow Volume",
|
2011-10-25 05:03:10 +00:00
|
|
|
@"Debug - PSSM",
|
|
|
|
|
@"Debug - Enable Ambient",
|
|
|
|
|
@"Debug - Enable Diffuse",
|
|
|
|
|
@"Debug - Enable Specular",
|
2012-10-12 00:02:24 +00:00
|
|
|
@"Debug - Enable Reflections",
|
2012-04-13 01:13:18 +00:00
|
|
|
@"Debug - Super Shiny",
|
2012-09-11 03:06:35 +00:00
|
|
|
@"Debug - Octree Visualize",
|
2012-09-11 07:23:54 +00:00
|
|
|
@"Debug - Deferred Lights Visualize",
|
2012-10-27 00:50:17 +00:00
|
|
|
@"Enable Deferred Lighting",
|
|
|
|
|
@"Near Clip Plane",
|
|
|
|
|
@"Far Clip Plane"
|
2011-10-25 05:03:10 +00:00
|
|
|
};
|
|
|
|
|
return parameter_labels[i];
|
|
|
|
|
}
|
|
|
|
|
-(KREngineParameterType)getParameterTypeWithIndex: (int)i
|
|
|
|
|
{
|
2012-10-27 00:50:17 +00:00
|
|
|
KREngineParameterType types[34] = {
|
2012-04-13 01:13:18 +00:00
|
|
|
|
2011-10-25 05:03:10 +00:00
|
|
|
KRENGINE_PARAMETER_FLOAT,
|
|
|
|
|
KRENGINE_PARAMETER_INT,
|
|
|
|
|
KRENGINE_PARAMETER_BOOL,
|
|
|
|
|
KRENGINE_PARAMETER_BOOL,
|
|
|
|
|
KRENGINE_PARAMETER_BOOL,
|
|
|
|
|
KRENGINE_PARAMETER_BOOL,
|
2012-03-29 19:39:28 +00:00
|
|
|
KRENGINE_PARAMETER_BOOL,
|
2012-05-08 23:39:52 +00:00
|
|
|
KRENGINE_PARAMETER_BOOL,
|
2011-10-25 05:03:10 +00:00
|
|
|
KRENGINE_PARAMETER_FLOAT,
|
|
|
|
|
KRENGINE_PARAMETER_FLOAT,
|
|
|
|
|
KRENGINE_PARAMETER_FLOAT,
|
|
|
|
|
KRENGINE_PARAMETER_FLOAT,
|
|
|
|
|
KRENGINE_PARAMETER_INT,
|
|
|
|
|
KRENGINE_PARAMETER_FLOAT,
|
|
|
|
|
KRENGINE_PARAMETER_FLOAT,
|
|
|
|
|
KRENGINE_PARAMETER_BOOL,
|
|
|
|
|
KRENGINE_PARAMETER_FLOAT,
|
|
|
|
|
KRENGINE_PARAMETER_FLOAT,
|
|
|
|
|
KRENGINE_PARAMETER_FLOAT,
|
|
|
|
|
KRENGINE_PARAMETER_BOOL,
|
|
|
|
|
KRENGINE_PARAMETER_FLOAT,
|
|
|
|
|
KRENGINE_PARAMETER_FLOAT,
|
|
|
|
|
KRENGINE_PARAMETER_BOOL,
|
|
|
|
|
KRENGINE_PARAMETER_BOOL,
|
|
|
|
|
KRENGINE_PARAMETER_BOOL,
|
|
|
|
|
KRENGINE_PARAMETER_BOOL,
|
|
|
|
|
KRENGINE_PARAMETER_BOOL,
|
2012-04-13 01:13:18 +00:00
|
|
|
KRENGINE_PARAMETER_BOOL,
|
2012-09-11 03:06:35 +00:00
|
|
|
KRENGINE_PARAMETER_BOOL,
|
2012-09-11 07:23:54 +00:00
|
|
|
KRENGINE_PARAMETER_BOOL,
|
2012-10-12 00:02:24 +00:00
|
|
|
KRENGINE_PARAMETER_BOOL,
|
2012-10-27 00:50:17 +00:00
|
|
|
KRENGINE_PARAMETER_BOOL,
|
|
|
|
|
KRENGINE_PARAMETER_FLOAT,
|
|
|
|
|
KRENGINE_PARAMETER_FLOAT
|
2011-10-25 05:03:10 +00:00
|
|
|
};
|
|
|
|
|
return types[i];
|
|
|
|
|
}
|
2012-10-20 02:15:48 +00:00
|
|
|
-(float)getParameterValueWithIndex: (int)i
|
2011-10-25 05:03:10 +00:00
|
|
|
{
|
2012-10-27 00:50:17 +00:00
|
|
|
float values[34] = {
|
2012-08-16 20:44:33 +00:00
|
|
|
_camera->perspective_fov,
|
2012-10-20 02:15:48 +00:00
|
|
|
(float)_camera->m_cShadowBuffers,
|
2012-08-16 20:44:33 +00:00
|
|
|
_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,
|
2012-09-21 05:59:24 +00:00
|
|
|
[self getAmbientTemperature],
|
|
|
|
|
[self getAmbientIntensity],
|
|
|
|
|
[self getSunTemperature],
|
|
|
|
|
[self getSunIntensity],
|
2012-08-16 20:44:33 +00:00
|
|
|
_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,
|
2012-10-12 00:02:24 +00:00
|
|
|
_camera->bEnableReflection ? 1.0f : 0.0f,
|
2012-08-16 20:44:33 +00:00
|
|
|
_camera->bDebugSuperShiny ? 1.0f : 0.0f,
|
2012-09-11 03:06:35 +00:00
|
|
|
_camera->bShowOctree ? 1.0f : 0.0f,
|
2012-09-11 07:23:54 +00:00
|
|
|
_camera->bShowDeferred ? 1.0f : 0.0f,
|
2012-10-27 00:50:17 +00:00
|
|
|
_camera->bEnableDeferredLighting ? 1.0f : 0.0f,
|
|
|
|
|
_camera->getPerspectiveNearZ(),
|
|
|
|
|
_camera->getPerspectiveFarZ()
|
2011-10-25 05:03:10 +00:00
|
|
|
};
|
|
|
|
|
return values[i];
|
|
|
|
|
}
|
2012-10-20 02:15:48 +00:00
|
|
|
-(void)setParameterValueWithIndex: (int)i Value: (float)v
|
2011-10-25 05:03:10 +00:00
|
|
|
{
|
|
|
|
|
bool bNewBoolVal = v > 0.5;
|
|
|
|
|
NSLog(@"Set Parameter: (%s, %f)", [[self getParameterNameWithIndex: i] UTF8String], v);
|
|
|
|
|
switch(i) {
|
|
|
|
|
case 0: // FOV
|
2012-08-16 20:44:33 +00:00
|
|
|
_camera->perspective_fov = v;
|
2011-10-25 05:03:10 +00:00
|
|
|
break;
|
2012-08-15 21:26:06 +00:00
|
|
|
case 1: // Shadow Quality
|
2012-08-16 20:44:33 +00:00
|
|
|
_camera->m_cShadowBuffers = (int)v;
|
2011-10-25 05:03:10 +00:00
|
|
|
break;
|
2012-08-15 21:26:06 +00:00
|
|
|
case 2:
|
2012-08-16 20:44:33 +00:00
|
|
|
_camera->bEnablePerPixel = bNewBoolVal;
|
2011-10-25 05:03:10 +00:00
|
|
|
break;
|
2012-08-15 21:26:06 +00:00
|
|
|
case 3:
|
2012-08-16 20:44:33 +00:00
|
|
|
_camera->bEnableDiffuseMap = bNewBoolVal;
|
2011-10-25 05:03:10 +00:00
|
|
|
break;
|
2012-08-15 21:26:06 +00:00
|
|
|
case 4:
|
2012-08-16 20:44:33 +00:00
|
|
|
_camera->bEnableNormalMap = bNewBoolVal;
|
2011-10-25 05:03:10 +00:00
|
|
|
break;
|
2012-08-15 21:26:06 +00:00
|
|
|
case 5:
|
2012-08-16 20:44:33 +00:00
|
|
|
_camera->bEnableSpecMap = bNewBoolVal;
|
2011-10-25 05:03:10 +00:00
|
|
|
break;
|
2012-08-15 21:26:06 +00:00
|
|
|
case 6:
|
2012-08-16 20:44:33 +00:00
|
|
|
_camera->bEnableReflectionMap = bNewBoolVal;
|
2011-10-25 05:03:10 +00:00
|
|
|
break;
|
2012-08-15 21:26:06 +00:00
|
|
|
case 7:
|
2012-08-16 20:44:33 +00:00
|
|
|
_camera->bEnableLightMap = bNewBoolVal;
|
2011-10-25 05:03:10 +00:00
|
|
|
break;
|
2012-08-15 21:26:06 +00:00
|
|
|
case 8:
|
2012-09-21 05:59:24 +00:00
|
|
|
[self setAmbientTemperature:v];
|
2011-10-25 05:03:10 +00:00
|
|
|
break;
|
2012-08-15 21:26:06 +00:00
|
|
|
case 9:
|
2012-09-21 05:59:24 +00:00
|
|
|
[self setAmbientIntensity:v];
|
2011-10-25 05:03:10 +00:00
|
|
|
break;
|
2012-08-15 21:26:06 +00:00
|
|
|
case 10:
|
2012-09-21 05:59:24 +00:00
|
|
|
[self setSunTemperature:v];
|
2011-10-25 05:03:10 +00:00
|
|
|
break;
|
2012-08-15 21:26:06 +00:00
|
|
|
case 11:
|
2012-09-21 05:59:24 +00:00
|
|
|
[self setSunIntensity:v];
|
|
|
|
|
break;
|
2012-08-15 21:26:06 +00:00
|
|
|
case 12:
|
2012-08-16 20:44:33 +00:00
|
|
|
if(_camera->dof_quality != (int)v) {
|
|
|
|
|
_camera->dof_quality = (int)v;
|
2011-10-25 05:03:10 +00:00
|
|
|
}
|
|
|
|
|
break;
|
2012-09-21 05:59:24 +00:00
|
|
|
case 13:
|
2012-08-16 20:44:33 +00:00
|
|
|
if(_camera->dof_depth != v) {
|
|
|
|
|
_camera->dof_depth = v;
|
2011-10-25 05:03:10 +00:00
|
|
|
}
|
|
|
|
|
break;
|
2012-09-21 05:59:24 +00:00
|
|
|
case 14:
|
2012-08-16 20:44:33 +00:00
|
|
|
if(_camera->dof_falloff != v) {
|
|
|
|
|
_camera->dof_falloff = v;
|
2011-10-25 05:03:10 +00:00
|
|
|
}
|
|
|
|
|
break;
|
2012-09-21 05:59:24 +00:00
|
|
|
case 15:
|
2012-08-16 20:44:33 +00:00
|
|
|
if(_camera->bEnableFlash != bNewBoolVal) {
|
|
|
|
|
_camera->bEnableFlash = bNewBoolVal;
|
2011-10-25 05:03:10 +00:00
|
|
|
}
|
|
|
|
|
break;
|
2012-09-21 05:59:24 +00:00
|
|
|
case 16:
|
2012-08-16 20:44:33 +00:00
|
|
|
if(_camera->flash_intensity != v) {
|
|
|
|
|
_camera->flash_intensity = v;
|
2011-10-25 05:03:10 +00:00
|
|
|
}
|
|
|
|
|
break;
|
2012-09-21 05:59:24 +00:00
|
|
|
case 17:
|
2012-08-16 20:44:33 +00:00
|
|
|
if(_camera->flash_depth != v) {
|
|
|
|
|
_camera->flash_depth = v;
|
2011-10-25 05:03:10 +00:00
|
|
|
}
|
|
|
|
|
break;
|
2012-09-21 05:59:24 +00:00
|
|
|
case 18:
|
2012-08-16 20:44:33 +00:00
|
|
|
if(_camera->flash_falloff != v) {
|
|
|
|
|
_camera->flash_falloff = v;
|
2011-10-25 05:03:10 +00:00
|
|
|
}
|
|
|
|
|
break;
|
2012-09-21 05:59:24 +00:00
|
|
|
case 19:
|
2012-08-16 20:44:33 +00:00
|
|
|
if(_camera->bEnableVignette != bNewBoolVal) {
|
|
|
|
|
_camera->bEnableVignette = bNewBoolVal;
|
2011-10-25 05:03:10 +00:00
|
|
|
}
|
|
|
|
|
break;
|
2012-09-21 05:59:24 +00:00
|
|
|
case 20:
|
2012-08-16 20:44:33 +00:00
|
|
|
if(_camera->vignette_radius != v) {
|
|
|
|
|
_camera->vignette_radius = v;
|
2011-10-25 05:03:10 +00:00
|
|
|
}
|
|
|
|
|
break;
|
2012-09-21 05:59:24 +00:00
|
|
|
case 21:
|
2012-08-16 20:44:33 +00:00
|
|
|
if(_camera->vignette_falloff != v) {
|
|
|
|
|
_camera->vignette_falloff = v;
|
2011-10-25 05:03:10 +00:00
|
|
|
}
|
|
|
|
|
break;
|
2012-09-21 05:59:24 +00:00
|
|
|
case 22:
|
2012-08-16 20:44:33 +00:00
|
|
|
if(_camera->bShowShadowBuffer != bNewBoolVal) {
|
|
|
|
|
_camera->bShowShadowBuffer = bNewBoolVal;
|
2011-10-25 05:03:10 +00:00
|
|
|
}
|
|
|
|
|
break;
|
2012-09-21 05:59:24 +00:00
|
|
|
case 23:
|
2012-08-16 20:44:33 +00:00
|
|
|
if(_camera->bDebugPSSM != bNewBoolVal) {
|
|
|
|
|
_camera->bDebugPSSM = bNewBoolVal;
|
2011-10-25 05:03:10 +00:00
|
|
|
}
|
|
|
|
|
break;
|
2012-09-21 05:59:24 +00:00
|
|
|
case 24:
|
2012-08-16 20:44:33 +00:00
|
|
|
if(_camera->bEnableAmbient != bNewBoolVal) {
|
|
|
|
|
_camera->bEnableAmbient = bNewBoolVal;
|
2011-10-25 05:03:10 +00:00
|
|
|
}
|
|
|
|
|
break;
|
2012-09-21 05:59:24 +00:00
|
|
|
case 25:
|
2012-08-16 20:44:33 +00:00
|
|
|
if(_camera->bEnableDiffuse != bNewBoolVal) {
|
|
|
|
|
_camera->bEnableDiffuse = bNewBoolVal;
|
2011-10-25 05:03:10 +00:00
|
|
|
}
|
|
|
|
|
break;
|
2012-09-21 05:59:24 +00:00
|
|
|
case 26:
|
2012-08-16 20:44:33 +00:00
|
|
|
if(_camera->bEnableSpecular != bNewBoolVal) {
|
|
|
|
|
_camera->bEnableSpecular = bNewBoolVal;
|
2011-10-25 05:03:10 +00:00
|
|
|
}
|
|
|
|
|
break;
|
2012-09-21 05:59:24 +00:00
|
|
|
case 27:
|
2012-10-12 00:02:24 +00:00
|
|
|
if(_camera->bEnableReflection != bNewBoolVal) {
|
|
|
|
|
_camera->bEnableReflection = bNewBoolVal;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case 28:
|
2012-08-16 20:44:33 +00:00
|
|
|
if(_camera->bDebugSuperShiny != bNewBoolVal) {
|
|
|
|
|
_camera->bDebugSuperShiny = bNewBoolVal;
|
2011-10-25 05:03:10 +00:00
|
|
|
}
|
|
|
|
|
break;
|
2012-10-12 00:02:24 +00:00
|
|
|
case 29:
|
2012-09-11 03:06:35 +00:00
|
|
|
if(_camera->bShowOctree != bNewBoolVal) {
|
|
|
|
|
_camera->bShowOctree = bNewBoolVal;
|
|
|
|
|
}
|
|
|
|
|
break;
|
2012-10-12 00:02:24 +00:00
|
|
|
case 30:
|
2012-09-11 07:23:54 +00:00
|
|
|
if(_camera->bShowDeferred != bNewBoolVal) {
|
|
|
|
|
_camera->bShowDeferred = bNewBoolVal;
|
|
|
|
|
}
|
|
|
|
|
break;
|
2012-10-12 00:02:24 +00:00
|
|
|
case 31:
|
2012-08-16 20:44:33 +00:00
|
|
|
if(_camera->bEnableDeferredLighting != bNewBoolVal) {
|
|
|
|
|
_camera->bEnableDeferredLighting = bNewBoolVal;
|
2012-04-13 01:13:18 +00:00
|
|
|
}
|
2012-09-11 03:06:35 +00:00
|
|
|
break;
|
2012-10-27 00:50:17 +00:00
|
|
|
case 32:
|
|
|
|
|
_camera->setPerspectiveNear(v);
|
|
|
|
|
break;
|
|
|
|
|
case 33:
|
|
|
|
|
_camera->setPerpsectiveFarZ(v);
|
|
|
|
|
break;
|
2011-10-25 05:03:10 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-10-20 02:15:48 +00:00
|
|
|
-(float)getParameterMinWithIndex: (int)i
|
2011-10-25 05:03:10 +00:00
|
|
|
{
|
2012-10-27 00:50:17 +00:00
|
|
|
float minValues[34] = {
|
2012-09-11 03:06:35 +00:00
|
|
|
0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f,
|
2012-09-21 05:59:24 +00:00
|
|
|
0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f,
|
2012-09-11 03:06:35 +00:00
|
|
|
0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f,
|
2012-10-27 00:50:17 +00:00
|
|
|
0.0f, 0.0f, 0.0f, 0.0f, 0.5f, 50.0f
|
2012-09-11 03:06:35 +00:00
|
|
|
};
|
2012-09-21 05:59:24 +00:00
|
|
|
|
2011-10-25 05:03:10 +00:00
|
|
|
return minValues[i];
|
|
|
|
|
}
|
|
|
|
|
|
2012-10-20 02:15:48 +00:00
|
|
|
-(float)getParameterMaxWithIndex: (int)i
|
2011-10-25 05:03:10 +00:00
|
|
|
{
|
2012-10-27 00:50:17 +00:00
|
|
|
float maxValues[34] = {
|
2012-09-27 18:57:56 +00:00
|
|
|
PI, 3.0f, 1.0f, 1.0, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 10.0f,
|
2012-09-27 18:20:56 +00:00
|
|
|
1.0f, 10.0f, 2.0f, 1.0f, 1.0f, 1.0f, 5.0f, 1.0f,
|
2012-09-11 03:06:35 +00:00
|
|
|
0.5f, 1.0f, 2.0f, 2.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f,
|
2012-10-27 00:50:17 +00:00
|
|
|
1.0f, 1.0f, 1.0f, 1.0f, 1000.0f, 50000.0f
|
2012-09-11 03:06:35 +00:00
|
|
|
};
|
|
|
|
|
|
2011-10-25 05:03:10 +00:00
|
|
|
return maxValues[i];
|
|
|
|
|
}
|
|
|
|
|
|
2012-10-20 02:15:48 +00:00
|
|
|
-(void)setParameterValueWithName: (NSString *)name Value: (float)v
|
2011-10-25 05:03:10 +00:00
|
|
|
{
|
|
|
|
|
int cParameters = [self getParameterCount];
|
|
|
|
|
for(int i=0; i < cParameters; i++) {
|
|
|
|
|
if([[self getParameterNameWithIndex: i] caseInsensitiveCompare:name] == NSOrderedSame) {
|
|
|
|
|
[self setParameterValueWithIndex:i Value:v];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-23 22:43:26 +00:00
|
|
|
-(int)getParameterIndexWithName: (NSString *)name
|
|
|
|
|
{
|
|
|
|
|
int cParameters = [self getParameterCount];
|
|
|
|
|
for(int i=0; i < cParameters; i++) {
|
|
|
|
|
if([[self getParameterNameWithIndex:i] caseInsensitiveCompare:name] == NSOrderedSame)
|
|
|
|
|
{
|
|
|
|
|
return i;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return -1; // not found
|
|
|
|
|
}
|
|
|
|
|
|
2012-10-20 02:15:48 +00:00
|
|
|
- (void)setNearZ: (float)dNearZ
|
2011-10-25 05:03:10 +00:00
|
|
|
{
|
2012-10-20 01:10:57 +00:00
|
|
|
_camera->setPerspectiveNear(dNearZ);
|
2011-10-25 05:03:10 +00:00
|
|
|
}
|
2012-10-20 02:15:48 +00:00
|
|
|
- (void)setFarZ: (float)dFarZ
|
2011-10-25 05:03:10 +00:00
|
|
|
{
|
2012-10-20 01:10:57 +00:00
|
|
|
_camera->setPerpsectiveFarZ(dFarZ);
|
2011-10-25 05:03:10 +00:00
|
|
|
}
|
|
|
|
|
|
2012-08-15 21:26:06 +00:00
|
|
|
- (void)setDebug_text:(NSString *)value
|
2011-10-25 05:03:10 +00:00
|
|
|
{
|
2012-08-15 21:26:06 +00:00
|
|
|
[_debug_text release];
|
|
|
|
|
_debug_text = value;
|
|
|
|
|
[_debug_text retain];
|
|
|
|
|
|
2012-08-16 20:44:33 +00:00
|
|
|
_camera->m_debug_text = value.UTF8String;
|
2011-10-25 05:03:10 +00:00
|
|
|
}
|
|
|
|
|
|
2012-10-04 22:29:01 +00:00
|
|
|
// ---===--- Sun Temperature and intensity ---===---
|
2012-09-21 05:59:24 +00:00
|
|
|
|
2012-10-20 02:15:48 +00:00
|
|
|
-(void) setSunTemperature:(float)t
|
2012-09-21 05:59:24 +00:00
|
|
|
{
|
2012-10-20 02:15:48 +00:00
|
|
|
float i = [self getSunIntensity];
|
2012-09-21 05:59:24 +00:00
|
|
|
|
2012-10-04 22:29:01 +00:00
|
|
|
_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;
|
2012-09-21 05:59:24 +00:00
|
|
|
}
|
|
|
|
|
|
2012-10-20 02:15:48 +00:00
|
|
|
-(void) setSunIntensity:(float)i
|
2012-09-21 05:59:24 +00:00
|
|
|
{
|
2012-10-20 02:15:48 +00:00
|
|
|
float t = [self getSunTemperature];
|
2012-10-04 22:29:01 +00:00
|
|
|
|
|
|
|
|
_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;
|
2012-09-21 05:59:24 +00:00
|
|
|
}
|
|
|
|
|
|
2012-10-20 02:15:48 +00:00
|
|
|
-(float) getSunIntensity
|
2012-09-21 05:59:24 +00:00
|
|
|
{
|
2012-10-20 02:15:48 +00:00
|
|
|
float i = _camera->dSunR;
|
2012-10-04 22:29:01 +00:00
|
|
|
if(_camera->dSunG > i) i = _camera->dSunG;
|
|
|
|
|
if(_camera->dSunB > i) i = _camera->dSunB;
|
|
|
|
|
return i;
|
2012-09-21 05:59:24 +00:00
|
|
|
}
|
|
|
|
|
|
2012-10-20 02:15:48 +00:00
|
|
|
-(float) getSunTemperature
|
2012-09-21 05:59:24 +00:00
|
|
|
{
|
2012-10-20 02:15:48 +00:00
|
|
|
float i = [self getSunIntensity];
|
2012-10-04 22:29:01 +00:00
|
|
|
if(i == 0.0f) return 0.5f; // Avoid division by zero; assume black has a colour temperature of 0.5
|
|
|
|
|
if(_camera->dSunB == i) {
|
|
|
|
|
// Cold side, t < 0.5
|
|
|
|
|
return _camera->dSunR / i * 0.5f;
|
|
|
|
|
} else {
|
|
|
|
|
// Warm side, t > 0.5
|
|
|
|
|
return 1.0f - (_camera->dSunB / i) * 0.5f;
|
|
|
|
|
}
|
2012-09-21 05:59:24 +00:00
|
|
|
}
|
|
|
|
|
|
2012-10-04 22:29:01 +00:00
|
|
|
// ---===--- Ambient Temperature and intensity ---===---
|
|
|
|
|
|
2012-10-20 02:15:48 +00:00
|
|
|
-(void) setAmbientTemperature:(float)t
|
2012-09-21 05:59:24 +00:00
|
|
|
{
|
2012-10-20 02:15:48 +00:00
|
|
|
float i = [self getAmbientIntensity];
|
2012-09-21 05:59:24 +00:00
|
|
|
|
2012-10-04 22:29:01 +00:00
|
|
|
_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;
|
2012-09-21 05:59:24 +00:00
|
|
|
}
|
|
|
|
|
|
2012-10-20 02:15:48 +00:00
|
|
|
-(void) setAmbientIntensity:(float)i
|
2012-09-21 05:59:24 +00:00
|
|
|
{
|
2012-10-20 02:15:48 +00:00
|
|
|
float t = [self getAmbientTemperature];
|
2012-10-04 22:29:01 +00:00
|
|
|
|
|
|
|
|
_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;
|
2012-09-21 05:59:24 +00:00
|
|
|
}
|
|
|
|
|
|
2012-10-20 02:15:48 +00:00
|
|
|
-(float) getAmbientIntensity
|
2012-09-21 05:59:24 +00:00
|
|
|
{
|
2012-10-20 02:15:48 +00:00
|
|
|
float i = _camera->dAmbientR;
|
2012-10-04 22:29:01 +00:00
|
|
|
if(_camera->dAmbientG > i) i = _camera->dAmbientG;
|
|
|
|
|
if(_camera->dAmbientB > i) i = _camera->dAmbientB;
|
|
|
|
|
return i;
|
2012-09-21 05:59:24 +00:00
|
|
|
}
|
|
|
|
|
|
2012-10-20 02:15:48 +00:00
|
|
|
-(float) getAmbientTemperature
|
2012-09-21 05:59:24 +00:00
|
|
|
{
|
2012-10-20 02:15:48 +00:00
|
|
|
float i = [self getAmbientIntensity];
|
2012-10-04 22:29:01 +00:00
|
|
|
if(i == 0.0f) return 0.5f; // Avoid division by zero; assume black has a colour temperature of 0.5
|
|
|
|
|
if(_camera->dAmbientB == i) {
|
|
|
|
|
// Cold side, t < 0.5
|
|
|
|
|
return _camera->dAmbientR / i * 0.5f;
|
|
|
|
|
} else {
|
|
|
|
|
// Warm side, t > 0.5
|
|
|
|
|
return 1.0f - (_camera->dAmbientB / i) * 0.5f;
|
|
|
|
|
}
|
2012-09-21 05:59:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2011-10-25 05:03:10 +00:00
|
|
|
@end
|