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
|
|
|
//
|
|
|
|
|
|
2013-01-11 03:21:19 +00:00
|
|
|
#include "KREngine-common.h"
|
2011-10-25 05:03:10 +00:00
|
|
|
|
2013-01-11 03:21:19 +00:00
|
|
|
#include "KREngine.h"
|
|
|
|
|
#include "KRVector3.h"
|
|
|
|
|
#include "KRScene.h"
|
|
|
|
|
#include "KRSceneManager.h"
|
|
|
|
|
#include "KRNode.h"
|
2011-10-25 05:03:10 +00:00
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-12-20 22:08:41 +00:00
|
|
|
@interface KREngine() {
|
|
|
|
|
KRRenderSettings _settings;
|
|
|
|
|
}
|
2011-10-25 05:03:10 +00:00
|
|
|
- (BOOL)loadShaders;
|
|
|
|
|
- (BOOL)loadResource:(NSString *)path;
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
|
|
@implementation KREngine
|
2012-08-15 21:26:06 +00:00
|
|
|
@synthesize debug_text = _debug_text;
|
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
|
|
|
{
|
2013-01-23 12:43:43 -08:00
|
|
|
#if TARGET_OS_IPHONE
|
2012-10-19 23:17:43 +00:00
|
|
|
BOOL isIpad = UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad;
|
|
|
|
|
BOOL isRetina = [[UIScreen mainScreen] scale] >= 2.0;
|
2013-01-23 12:43:43 -08:00
|
|
|
#else
|
|
|
|
|
BOOL isIpad = false;
|
|
|
|
|
BOOL isRetina = false;
|
|
|
|
|
#endif
|
2012-10-19 23:17:43 +00:00
|
|
|
|
|
|
|
|
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;
|
2012-11-17 00:15:52 +00:00
|
|
|
KRContext::KRENGINE_MAX_TEXTURE_THROUGHPUT = 32000000;
|
2012-10-19 23:17:43 +00:00
|
|
|
} 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-11-17 00:15:52 +00:00
|
|
|
KRContext::KRENGINE_MAX_TEXTURE_THROUGHPUT = 32000000;
|
2012-10-19 23:17:43 +00:00
|
|
|
}
|
|
|
|
|
|
2012-08-16 20:44:33 +00:00
|
|
|
_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-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,
|
2012-11-14 21:46:30 +00:00
|
|
|
@"far_clip" : @33,
|
|
|
|
|
@"volumetric_environment_enable" : @34,
|
|
|
|
|
@"volumetric_environment_downsample" : @35,
|
|
|
|
|
@"volumetric_environment_max_distance" : @36,
|
|
|
|
|
@"volumetric_environment_slices" : @37,
|
2012-11-21 22:47:33 +00:00
|
|
|
@"volumetric_environment_intensity" : @38,
|
|
|
|
|
@"fog_type": @39,
|
|
|
|
|
@"fog_near": @40,
|
|
|
|
|
@"fog_far": @41,
|
|
|
|
|
@"fog_density": @42,
|
|
|
|
|
@"fog_color_r": @43,
|
|
|
|
|
@"fog_color_g": @44,
|
2012-11-23 01:13:35 +00:00
|
|
|
@"fog_color_b": @45,
|
|
|
|
|
@"dust_enable" : @46,
|
|
|
|
|
@"dust_intensity" : @47
|
2012-11-14 21:46:30 +00:00
|
|
|
|
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-12-28 03:20:06 +00:00
|
|
|
- (void)renderScene: (KRScene *)pScene WithDeltaTime: (float)deltaTime
|
2011-10-25 05:03:10 +00:00
|
|
|
{
|
2012-12-20 22:08:41 +00:00
|
|
|
KRCamera *camera = pScene->find<KRCamera>();
|
|
|
|
|
if(camera) {
|
|
|
|
|
camera->settings = _settings;
|
|
|
|
|
}
|
|
|
|
|
pScene->renderFrame(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(_context) {
|
|
|
|
|
delete _context; _context = NULL;
|
|
|
|
|
}
|
2011-10-25 05:03:10 +00:00
|
|
|
[super dealloc];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
-(int)getParameterCount
|
|
|
|
|
{
|
2012-11-23 01:13:35 +00:00
|
|
|
return 48;
|
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-11-23 01:13:35 +00:00
|
|
|
NSString *parameter_labels[48] = {
|
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",
|
2012-11-14 21:46:30 +00:00
|
|
|
@"Clip Plane - Near",
|
|
|
|
|
@"Clip Plane - Far",
|
|
|
|
|
@"Volumetric Env. - Enabled",
|
|
|
|
|
@"Volumetric Env. - Resolution",
|
|
|
|
|
@"Volumetric Env. - Maximum Distance",
|
|
|
|
|
@"Volumetric Env. - Quality",
|
2012-11-21 22:47:33 +00:00
|
|
|
@"Volumetric Env. - Intensity",
|
|
|
|
|
@"Fog - Type",
|
|
|
|
|
@"Fog - Near",
|
|
|
|
|
@"Fog - Far",
|
|
|
|
|
@"Fog - Density",
|
|
|
|
|
@"Fog - Color R",
|
|
|
|
|
@"Fog - Color G",
|
2012-11-23 01:13:35 +00:00
|
|
|
@"Fog - Color B",
|
|
|
|
|
@"Dust - Enable",
|
|
|
|
|
@"Dust - Intensity"
|
2011-10-25 05:03:10 +00:00
|
|
|
};
|
|
|
|
|
return parameter_labels[i];
|
|
|
|
|
}
|
|
|
|
|
-(KREngineParameterType)getParameterTypeWithIndex: (int)i
|
|
|
|
|
{
|
2012-11-23 01:13:35 +00:00
|
|
|
KREngineParameterType types[48] = {
|
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,
|
2012-11-14 21:46:30 +00:00
|
|
|
KRENGINE_PARAMETER_FLOAT,
|
|
|
|
|
KRENGINE_PARAMETER_BOOL,
|
|
|
|
|
KRENGINE_PARAMETER_INT,
|
|
|
|
|
KRENGINE_PARAMETER_FLOAT,
|
|
|
|
|
KRENGINE_PARAMETER_FLOAT,
|
2012-11-21 22:47:33 +00:00
|
|
|
KRENGINE_PARAMETER_FLOAT,
|
|
|
|
|
KRENGINE_PARAMETER_INT,
|
|
|
|
|
KRENGINE_PARAMETER_FLOAT,
|
|
|
|
|
KRENGINE_PARAMETER_FLOAT,
|
|
|
|
|
KRENGINE_PARAMETER_FLOAT,
|
|
|
|
|
KRENGINE_PARAMETER_FLOAT,
|
|
|
|
|
KRENGINE_PARAMETER_FLOAT,
|
2012-11-23 01:13:35 +00:00
|
|
|
KRENGINE_PARAMETER_FLOAT,
|
|
|
|
|
KRENGINE_PARAMETER_BOOL,
|
2012-10-27 00:50:17 +00:00
|
|
|
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-11-23 01:13:35 +00:00
|
|
|
float values[48] = {
|
2012-12-20 22:08:41 +00:00
|
|
|
_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,
|
2012-09-21 05:59:24 +00:00
|
|
|
[self getAmbientTemperature],
|
|
|
|
|
[self getAmbientIntensity],
|
|
|
|
|
[self getSunTemperature],
|
|
|
|
|
[self getSunIntensity],
|
2012-12-20 22:08:41 +00:00
|
|
|
_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
|
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;
|
2012-11-14 21:46:30 +00:00
|
|
|
// NSLog(@"Set Parameter: (%s, %f)", [[self getParameterNameWithIndex: i] UTF8String], v);
|
2011-10-25 05:03:10 +00:00
|
|
|
switch(i) {
|
|
|
|
|
case 0: // FOV
|
2012-12-20 22:08:41 +00:00
|
|
|
_settings.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-12-20 22:08:41 +00:00
|
|
|
_settings.m_cShadowBuffers = (int)v;
|
2011-10-25 05:03:10 +00:00
|
|
|
break;
|
2012-08-15 21:26:06 +00:00
|
|
|
case 2:
|
2012-12-20 22:08:41 +00:00
|
|
|
_settings.bEnablePerPixel = bNewBoolVal;
|
2011-10-25 05:03:10 +00:00
|
|
|
break;
|
2012-08-15 21:26:06 +00:00
|
|
|
case 3:
|
2012-12-20 22:08:41 +00:00
|
|
|
_settings.bEnableDiffuseMap = bNewBoolVal;
|
2011-10-25 05:03:10 +00:00
|
|
|
break;
|
2012-08-15 21:26:06 +00:00
|
|
|
case 4:
|
2012-12-20 22:08:41 +00:00
|
|
|
_settings.bEnableNormalMap = bNewBoolVal;
|
2011-10-25 05:03:10 +00:00
|
|
|
break;
|
2012-08-15 21:26:06 +00:00
|
|
|
case 5:
|
2012-12-20 22:08:41 +00:00
|
|
|
_settings.bEnableSpecMap = bNewBoolVal;
|
2011-10-25 05:03:10 +00:00
|
|
|
break;
|
2012-08-15 21:26:06 +00:00
|
|
|
case 6:
|
2012-12-20 22:08:41 +00:00
|
|
|
_settings.bEnableReflectionMap = bNewBoolVal;
|
2011-10-25 05:03:10 +00:00
|
|
|
break;
|
2012-08-15 21:26:06 +00:00
|
|
|
case 7:
|
2012-12-20 22:08:41 +00:00
|
|
|
_settings.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-12-20 22:08:41 +00:00
|
|
|
if(_settings.dof_quality != (int)v) {
|
|
|
|
|
_settings.dof_quality = (int)v;
|
2011-10-25 05:03:10 +00:00
|
|
|
}
|
|
|
|
|
break;
|
2012-09-21 05:59:24 +00:00
|
|
|
case 13:
|
2012-12-20 22:08:41 +00:00
|
|
|
if(_settings.dof_depth != v) {
|
|
|
|
|
_settings.dof_depth = v;
|
2011-10-25 05:03:10 +00:00
|
|
|
}
|
|
|
|
|
break;
|
2012-09-21 05:59:24 +00:00
|
|
|
case 14:
|
2012-12-20 22:08:41 +00:00
|
|
|
if(_settings.dof_falloff != v) {
|
|
|
|
|
_settings.dof_falloff = v;
|
2011-10-25 05:03:10 +00:00
|
|
|
}
|
|
|
|
|
break;
|
2012-09-21 05:59:24 +00:00
|
|
|
case 15:
|
2012-12-20 22:08:41 +00:00
|
|
|
if(_settings.bEnableFlash != bNewBoolVal) {
|
|
|
|
|
_settings.bEnableFlash = bNewBoolVal;
|
2011-10-25 05:03:10 +00:00
|
|
|
}
|
|
|
|
|
break;
|
2012-09-21 05:59:24 +00:00
|
|
|
case 16:
|
2012-12-20 22:08:41 +00:00
|
|
|
if(_settings.flash_intensity != v) {
|
|
|
|
|
_settings.flash_intensity = v;
|
2011-10-25 05:03:10 +00:00
|
|
|
}
|
|
|
|
|
break;
|
2012-09-21 05:59:24 +00:00
|
|
|
case 17:
|
2012-12-20 22:08:41 +00:00
|
|
|
if(_settings.flash_depth != v) {
|
|
|
|
|
_settings.flash_depth = v;
|
2011-10-25 05:03:10 +00:00
|
|
|
}
|
|
|
|
|
break;
|
2012-09-21 05:59:24 +00:00
|
|
|
case 18:
|
2012-12-20 22:08:41 +00:00
|
|
|
if(_settings.flash_falloff != v) {
|
|
|
|
|
_settings.flash_falloff = v;
|
2011-10-25 05:03:10 +00:00
|
|
|
}
|
|
|
|
|
break;
|
2012-09-21 05:59:24 +00:00
|
|
|
case 19:
|
2012-12-20 22:08:41 +00:00
|
|
|
if(_settings.bEnableVignette != bNewBoolVal) {
|
|
|
|
|
_settings.bEnableVignette = bNewBoolVal;
|
2011-10-25 05:03:10 +00:00
|
|
|
}
|
|
|
|
|
break;
|
2012-09-21 05:59:24 +00:00
|
|
|
case 20:
|
2012-12-20 22:08:41 +00:00
|
|
|
if(_settings.vignette_radius != v) {
|
|
|
|
|
_settings.vignette_radius = v;
|
2011-10-25 05:03:10 +00:00
|
|
|
}
|
|
|
|
|
break;
|
2012-09-21 05:59:24 +00:00
|
|
|
case 21:
|
2012-12-20 22:08:41 +00:00
|
|
|
if(_settings.vignette_falloff != v) {
|
|
|
|
|
_settings.vignette_falloff = v;
|
2011-10-25 05:03:10 +00:00
|
|
|
}
|
|
|
|
|
break;
|
2012-09-21 05:59:24 +00:00
|
|
|
case 22:
|
2012-12-20 22:08:41 +00:00
|
|
|
if(_settings.bShowShadowBuffer != bNewBoolVal) {
|
|
|
|
|
_settings.bShowShadowBuffer = bNewBoolVal;
|
2011-10-25 05:03:10 +00:00
|
|
|
}
|
|
|
|
|
break;
|
2012-09-21 05:59:24 +00:00
|
|
|
case 23:
|
2012-12-20 22:08:41 +00:00
|
|
|
if(_settings.bDebugPSSM != bNewBoolVal) {
|
|
|
|
|
_settings.bDebugPSSM = bNewBoolVal;
|
2011-10-25 05:03:10 +00:00
|
|
|
}
|
|
|
|
|
break;
|
2012-09-21 05:59:24 +00:00
|
|
|
case 24:
|
2012-12-20 22:08:41 +00:00
|
|
|
if(_settings.bEnableAmbient != bNewBoolVal) {
|
|
|
|
|
_settings.bEnableAmbient = bNewBoolVal;
|
2011-10-25 05:03:10 +00:00
|
|
|
}
|
|
|
|
|
break;
|
2012-09-21 05:59:24 +00:00
|
|
|
case 25:
|
2012-12-20 22:08:41 +00:00
|
|
|
if(_settings.bEnableDiffuse != bNewBoolVal) {
|
|
|
|
|
_settings.bEnableDiffuse = bNewBoolVal;
|
2011-10-25 05:03:10 +00:00
|
|
|
}
|
|
|
|
|
break;
|
2012-09-21 05:59:24 +00:00
|
|
|
case 26:
|
2012-12-20 22:08:41 +00:00
|
|
|
if(_settings.bEnableSpecular != bNewBoolVal) {
|
|
|
|
|
_settings.bEnableSpecular = bNewBoolVal;
|
2011-10-25 05:03:10 +00:00
|
|
|
}
|
|
|
|
|
break;
|
2012-09-21 05:59:24 +00:00
|
|
|
case 27:
|
2012-12-20 22:08:41 +00:00
|
|
|
if(_settings.bEnableReflection != bNewBoolVal) {
|
|
|
|
|
_settings.bEnableReflection = bNewBoolVal;
|
2012-10-12 00:02:24 +00:00
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case 28:
|
2012-12-20 22:08:41 +00:00
|
|
|
if(_settings.bDebugSuperShiny != bNewBoolVal) {
|
|
|
|
|
_settings.bDebugSuperShiny = bNewBoolVal;
|
2011-10-25 05:03:10 +00:00
|
|
|
}
|
|
|
|
|
break;
|
2012-10-12 00:02:24 +00:00
|
|
|
case 29:
|
2012-12-20 22:08:41 +00:00
|
|
|
if(_settings.bShowOctree != bNewBoolVal) {
|
|
|
|
|
_settings.bShowOctree = bNewBoolVal;
|
2012-09-11 03:06:35 +00:00
|
|
|
}
|
|
|
|
|
break;
|
2012-10-12 00:02:24 +00:00
|
|
|
case 30:
|
2012-12-20 22:08:41 +00:00
|
|
|
if(_settings.bShowDeferred != bNewBoolVal) {
|
|
|
|
|
_settings.bShowDeferred = bNewBoolVal;
|
2012-09-11 07:23:54 +00:00
|
|
|
}
|
|
|
|
|
break;
|
2012-10-12 00:02:24 +00:00
|
|
|
case 31:
|
2012-12-20 22:08:41 +00:00
|
|
|
if(_settings.bEnableDeferredLighting != bNewBoolVal) {
|
|
|
|
|
_settings.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:
|
2012-12-20 22:08:41 +00:00
|
|
|
_settings.setPerspectiveNear(v);
|
2012-10-27 00:50:17 +00:00
|
|
|
break;
|
|
|
|
|
case 33:
|
2012-12-20 22:08:41 +00:00
|
|
|
_settings.setPerpsectiveFarZ(v);
|
2012-10-27 00:50:17 +00:00
|
|
|
break;
|
2012-11-14 21:46:30 +00:00
|
|
|
case 34:
|
2012-12-20 22:08:41 +00:00
|
|
|
_settings.volumetric_environment_enable = bNewBoolVal;
|
2012-11-14 21:46:30 +00:00
|
|
|
break;
|
|
|
|
|
case 35:
|
2012-12-20 22:08:41 +00:00
|
|
|
_settings.volumetric_environment_downsample = 5 - (int)v;
|
2012-11-14 21:46:30 +00:00
|
|
|
break;
|
|
|
|
|
case 36:
|
2012-12-20 22:08:41 +00:00
|
|
|
_settings.volumetric_environment_max_distance = v;
|
2012-11-14 21:46:30 +00:00
|
|
|
break;
|
|
|
|
|
case 37:
|
2012-12-20 22:08:41 +00:00
|
|
|
_settings.volumetric_environment_quality = v;
|
2012-11-14 21:46:30 +00:00
|
|
|
break;
|
|
|
|
|
case 38:
|
2012-12-20 22:08:41 +00:00
|
|
|
_settings.volumetric_environment_intensity = v;
|
2012-11-14 21:46:30 +00:00
|
|
|
break;
|
2012-11-21 22:47:33 +00:00
|
|
|
case 39:
|
2012-12-20 22:08:41 +00:00
|
|
|
_settings.fog_type = v;
|
2012-11-21 22:47:33 +00:00
|
|
|
break;
|
|
|
|
|
case 40:
|
2012-12-20 22:08:41 +00:00
|
|
|
_settings.fog_near = v;
|
2012-11-21 22:47:33 +00:00
|
|
|
break;
|
|
|
|
|
case 41:
|
2012-12-20 22:08:41 +00:00
|
|
|
_settings.fog_far = v;
|
2012-11-21 22:47:33 +00:00
|
|
|
break;
|
|
|
|
|
case 42:
|
2012-12-20 22:08:41 +00:00
|
|
|
_settings.fog_density = v;
|
2012-11-21 22:47:33 +00:00
|
|
|
break;
|
|
|
|
|
case 43:
|
2012-12-20 22:08:41 +00:00
|
|
|
_settings.fog_color.x = v;
|
2012-11-21 22:47:33 +00:00
|
|
|
break;
|
|
|
|
|
case 44:
|
2012-12-20 22:08:41 +00:00
|
|
|
_settings.fog_color.y = v;
|
2012-11-21 22:47:33 +00:00
|
|
|
break;
|
|
|
|
|
case 45:
|
2012-12-20 22:08:41 +00:00
|
|
|
_settings.fog_color.z = v;
|
2012-11-21 22:47:33 +00:00
|
|
|
break;
|
2012-11-23 01:13:35 +00:00
|
|
|
case 46:
|
2012-12-20 22:08:41 +00:00
|
|
|
_settings.dust_particle_enable = bNewBoolVal;
|
2012-11-23 01:13:35 +00:00
|
|
|
break;
|
|
|
|
|
case 47:
|
2012-12-20 22:08:41 +00:00
|
|
|
_settings.dust_particle_intensity = v;
|
2012-11-23 01:13:35 +00:00
|
|
|
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-11-23 01:13:35 +00:00
|
|
|
float minValues[48] = {
|
2013-01-24 21:56:40 -08:00
|
|
|
0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f,
|
|
|
|
|
0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f,
|
|
|
|
|
0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f,
|
|
|
|
|
0.0f, 0.0f, 0.01f, 50.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f,
|
|
|
|
|
0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.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-11-23 01:13:35 +00:00
|
|
|
float maxValues[48] = {
|
2013-01-24 21:56:40 -08:00
|
|
|
PI, 3.0f, 1.0f, 1.0, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 10.0f,
|
|
|
|
|
1.0f, 10.0f, 2.0f, 1.0f, 1.0f, 1.0f, 5.0f, 1.0f, 0.5f, 1.0f,
|
|
|
|
|
2.0f, 2.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f,
|
|
|
|
|
1.0f, 1.0f, 10.0f, 1000.0f, 1.0f, 5.0f, 1000.0f, 1.0f, 5.0f, 3.0f,
|
|
|
|
|
1000.0f, 1000.0f, 0.01f, 1.0f, 1.0f, 1.0f, 1.0f, 1.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-12-20 22:08:41 +00:00
|
|
|
_settings.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-12-20 22:08:41 +00:00
|
|
|
_settings.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-12-20 22:08:41 +00:00
|
|
|
_settings.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-12-20 22:08:41 +00:00
|
|
|
_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
|
|
|
|
|
);
|
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-12-20 22:08:41 +00:00
|
|
|
_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
|
|
|
|
|
);
|
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-12-20 22:08:41 +00:00
|
|
|
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];
|
2012-10-04 22:29:01 +00:00
|
|
|
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
|
2012-12-20 22:08:41 +00:00
|
|
|
if(_settings.light_intensity[2] == i) {
|
2012-10-04 22:29:01 +00:00
|
|
|
// Cold side, t < 0.5
|
2012-12-20 22:08:41 +00:00
|
|
|
return _settings.light_intensity[0] / i * 0.5f;
|
2012-10-04 22:29:01 +00:00
|
|
|
} else {
|
|
|
|
|
// Warm side, t > 0.5
|
2012-12-20 22:08:41 +00:00
|
|
|
return 1.0f - (_settings.light_intensity[2] / i) * 0.5f;
|
2012-10-04 22:29:01 +00:00
|
|
|
}
|
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-12-20 22:08:41 +00:00
|
|
|
_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
|
|
|
|
|
);
|
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-12-20 22:08:41 +00:00
|
|
|
_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
|
|
|
|
|
);
|
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-12-20 22:08:41 +00:00
|
|
|
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];
|
2012-10-04 22:29:01 +00:00
|
|
|
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
|
2012-12-20 22:08:41 +00:00
|
|
|
if(_settings.ambient_intensity[2] == i) {
|
2012-10-04 22:29:01 +00:00
|
|
|
// Cold side, t < 0.5
|
2012-12-20 22:08:41 +00:00
|
|
|
return _settings.ambient_intensity[0] / i * 0.5f;
|
2012-10-04 22:29:01 +00:00
|
|
|
} else {
|
|
|
|
|
// Warm side, t > 0.5
|
2012-12-20 22:08:41 +00:00
|
|
|
return 1.0f - (_settings.ambient_intensity[2] / i) * 0.5f;
|
2012-10-04 22:29:01 +00:00
|
|
|
}
|
2012-09-21 05:59:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2011-10-25 05:03:10 +00:00
|
|
|
@end
|