- Performance optimization - Eliminating extra matrix calculations for shaders that do not use the results
--HG-- extra : convert_revision : svn%3A7752d6cf-9f14-4ad2-affc-04f1e67b81a5/trunk%40137
This commit is contained in:
@@ -47,8 +47,8 @@ KRCamera::KRCamera(KRContext &context) : KRContextObject(context) {
|
|||||||
backingHeight = 0;
|
backingHeight = 0;
|
||||||
|
|
||||||
|
|
||||||
double const PI = 3.141592653589793f;
|
float const PI = 3.141592653589793f;
|
||||||
double const D2R = PI * 2 / 360;
|
float const D2R = PI * 2 / 360;
|
||||||
|
|
||||||
bShowShadowBuffer = false;
|
bShowShadowBuffer = false;
|
||||||
bShowOctree = false;
|
bShowOctree = false;
|
||||||
@@ -791,8 +791,8 @@ void KRCamera::renderPost()
|
|||||||
|
|
||||||
const char *pChar = szText;
|
const char *pChar = szText;
|
||||||
int iPos=0;
|
int iPos=0;
|
||||||
double dScale = 1.0 / 24.0;
|
float dScale = 1.0 / 24.0;
|
||||||
double dTexScale = 1.0 / 16.0;
|
float dTexScale = 1.0 / 16.0;
|
||||||
while(*pChar) {
|
while(*pChar) {
|
||||||
int iChar = *pChar++ - '\0';
|
int iChar = *pChar++ - '\0';
|
||||||
int iCol = iChar % 16;
|
int iCol = iChar % 16;
|
||||||
|
|||||||
@@ -81,28 +81,28 @@ public:
|
|||||||
bool bEnableDiffuse;
|
bool bEnableDiffuse;
|
||||||
bool bEnableSpecular;
|
bool bEnableSpecular;
|
||||||
bool bEnableDeferredLighting;
|
bool bEnableDeferredLighting;
|
||||||
double dSunR;
|
float dSunR;
|
||||||
double dSunG;
|
float dSunG;
|
||||||
double dSunB;
|
float dSunB;
|
||||||
double dAmbientR;
|
float dAmbientR;
|
||||||
double dAmbientG;
|
float dAmbientG;
|
||||||
double dAmbientB;
|
float dAmbientB;
|
||||||
double perspective_fov;
|
float perspective_fov;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int dof_quality;
|
int dof_quality;
|
||||||
double dof_depth;
|
float dof_depth;
|
||||||
double dof_falloff;
|
float dof_falloff;
|
||||||
bool bEnableFlash;
|
bool bEnableFlash;
|
||||||
double flash_intensity;
|
float flash_intensity;
|
||||||
double flash_depth;
|
float flash_depth;
|
||||||
double flash_falloff;
|
float flash_falloff;
|
||||||
|
|
||||||
bool bEnableVignette;
|
bool bEnableVignette;
|
||||||
double vignette_radius;
|
float vignette_radius;
|
||||||
double vignette_falloff;
|
float vignette_falloff;
|
||||||
|
|
||||||
KRVector2 m_viewportSize;
|
KRVector2 m_viewportSize;
|
||||||
|
|
||||||
|
|||||||
@@ -60,17 +60,17 @@ typedef enum KREngineParameterType {KRENGINE_PARAMETER_INT, KRENGINE_PARAMETER_F
|
|||||||
-(NSString *)getParameterNameWithIndex: (int)i;
|
-(NSString *)getParameterNameWithIndex: (int)i;
|
||||||
-(NSString *)getParameterLabelWithIndex: (int)i;
|
-(NSString *)getParameterLabelWithIndex: (int)i;
|
||||||
-(KREngineParameterType)getParameterTypeWithIndex: (int)i;
|
-(KREngineParameterType)getParameterTypeWithIndex: (int)i;
|
||||||
-(double)getParameterMinWithIndex: (int)i;
|
-(float)getParameterMinWithIndex: (int)i;
|
||||||
-(double)getParameterMaxWithIndex: (int)i;
|
-(float)getParameterMaxWithIndex: (int)i;
|
||||||
-(double)getParameterValueWithIndex: (int)i;
|
-(float)getParameterValueWithIndex: (int)i;
|
||||||
-(void)setParameterValueWithIndex: (int)i Value: (double)v;
|
-(void)setParameterValueWithIndex: (int)i Value: (float)v;
|
||||||
-(void)setParameterValueWithName: (NSString *)name Value: (double)v;
|
-(void)setParameterValueWithName: (NSString *)name Value: (float)v;
|
||||||
-(int)getParameterIndexWithName: (NSString *)name;
|
-(int)getParameterIndexWithName: (NSString *)name;
|
||||||
|
|
||||||
- (void)renderScene: (KRScene *)pScene WithViewMatrix: (KRMat4)viewMatrix;
|
- (void)renderScene: (KRScene *)pScene WithViewMatrix: (KRMat4)viewMatrix;
|
||||||
- (void)renderScene: (KRScene *)pScene WithPosition: (KRVector3)position Yaw: (GLfloat)yaw Pitch: (GLfloat)pitch Roll: (GLfloat)roll;
|
- (void)renderScene: (KRScene *)pScene WithPosition: (KRVector3)position Yaw: (GLfloat)yaw Pitch: (GLfloat)pitch Roll: (GLfloat)roll;
|
||||||
- (void)setNearZ: (double)dNearZ;
|
- (void)setNearZ: (float)dNearZ;
|
||||||
- (void)setFarZ: (double)dFarZ;
|
- (void)setFarZ: (float)dFarZ;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ using namespace std;
|
|||||||
|
|
||||||
@implementation KREngine
|
@implementation KREngine
|
||||||
@synthesize debug_text = _debug_text;
|
@synthesize debug_text = _debug_text;
|
||||||
double const PI = 3.141592653589793f;
|
float const PI = 3.141592653589793f;
|
||||||
|
|
||||||
|
|
||||||
+ (KREngine *)sharedInstance
|
+ (KREngine *)sharedInstance
|
||||||
@@ -273,11 +273,11 @@ double const PI = 3.141592653589793f;
|
|||||||
};
|
};
|
||||||
return types[i];
|
return types[i];
|
||||||
}
|
}
|
||||||
-(double)getParameterValueWithIndex: (int)i
|
-(float)getParameterValueWithIndex: (int)i
|
||||||
{
|
{
|
||||||
double values[32] = {
|
float values[32] = {
|
||||||
_camera->perspective_fov,
|
_camera->perspective_fov,
|
||||||
(double)_camera->m_cShadowBuffers,
|
(float)_camera->m_cShadowBuffers,
|
||||||
_camera->bEnablePerPixel ? 1.0f : 0.0f,
|
_camera->bEnablePerPixel ? 1.0f : 0.0f,
|
||||||
_camera->bEnableDiffuseMap ? 1.0f : 0.0f,
|
_camera->bEnableDiffuseMap ? 1.0f : 0.0f,
|
||||||
_camera->bEnableNormalMap ? 1.0f : 0.0f,
|
_camera->bEnableNormalMap ? 1.0f : 0.0f,
|
||||||
@@ -311,7 +311,7 @@ double const PI = 3.141592653589793f;
|
|||||||
};
|
};
|
||||||
return values[i];
|
return values[i];
|
||||||
}
|
}
|
||||||
-(void)setParameterValueWithIndex: (int)i Value: (double)v
|
-(void)setParameterValueWithIndex: (int)i Value: (float)v
|
||||||
{
|
{
|
||||||
bool bNewBoolVal = v > 0.5;
|
bool bNewBoolVal = v > 0.5;
|
||||||
NSLog(@"Set Parameter: (%s, %f)", [[self getParameterNameWithIndex: i] UTF8String], v);
|
NSLog(@"Set Parameter: (%s, %f)", [[self getParameterNameWithIndex: i] UTF8String], v);
|
||||||
@@ -455,9 +455,9 @@ double const PI = 3.141592653589793f;
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
-(double)getParameterMinWithIndex: (int)i
|
-(float)getParameterMinWithIndex: (int)i
|
||||||
{
|
{
|
||||||
double minValues[32] = {
|
float minValues[32] = {
|
||||||
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.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,
|
||||||
@@ -467,9 +467,9 @@ double const PI = 3.141592653589793f;
|
|||||||
return minValues[i];
|
return minValues[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
-(double)getParameterMaxWithIndex: (int)i
|
-(float)getParameterMaxWithIndex: (int)i
|
||||||
{
|
{
|
||||||
double maxValues[32] = {
|
float maxValues[32] = {
|
||||||
PI, 3.0f, 1.0f, 1.0, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 10.0f,
|
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,
|
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,
|
0.5f, 1.0f, 2.0f, 2.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f,
|
||||||
@@ -479,7 +479,7 @@ double const PI = 3.141592653589793f;
|
|||||||
return maxValues[i];
|
return maxValues[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
-(void)setParameterValueWithName: (NSString *)name Value: (double)v
|
-(void)setParameterValueWithName: (NSString *)name Value: (float)v
|
||||||
{
|
{
|
||||||
int cParameters = [self getParameterCount];
|
int cParameters = [self getParameterCount];
|
||||||
for(int i=0; i < cParameters; i++) {
|
for(int i=0; i < cParameters; i++) {
|
||||||
@@ -501,11 +501,11 @@ double const PI = 3.141592653589793f;
|
|||||||
return -1; // not found
|
return -1; // not found
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setNearZ: (double)dNearZ
|
- (void)setNearZ: (float)dNearZ
|
||||||
{
|
{
|
||||||
_camera->setPerspectiveNear(dNearZ);
|
_camera->setPerspectiveNear(dNearZ);
|
||||||
}
|
}
|
||||||
- (void)setFarZ: (double)dFarZ
|
- (void)setFarZ: (float)dFarZ
|
||||||
{
|
{
|
||||||
_camera->setPerpsectiveFarZ(dFarZ);
|
_camera->setPerpsectiveFarZ(dFarZ);
|
||||||
}
|
}
|
||||||
@@ -521,35 +521,35 @@ double const PI = 3.141592653589793f;
|
|||||||
|
|
||||||
// ---===--- Sun Temperature and intensity ---===---
|
// ---===--- Sun Temperature and intensity ---===---
|
||||||
|
|
||||||
-(void) setSunTemperature:(double)t
|
-(void) setSunTemperature:(float)t
|
||||||
{
|
{
|
||||||
double i = [self getSunIntensity];
|
float i = [self getSunIntensity];
|
||||||
|
|
||||||
_camera->dSunR = (t < 0.5f ? t * 2.0f : 1.0f) * i;
|
_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->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;
|
_camera->dSunB = (t < 0.5f ? 1.0f : (1.0f - t) * 2.0f) * i;
|
||||||
}
|
}
|
||||||
|
|
||||||
-(void) setSunIntensity:(double)i
|
-(void) setSunIntensity:(float)i
|
||||||
{
|
{
|
||||||
double t = [self getSunTemperature];
|
float t = [self getSunTemperature];
|
||||||
|
|
||||||
_camera->dSunR = (t < 0.5f ? t * 2.0f : 1.0f) * i;
|
_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->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;
|
_camera->dSunB = (t < 0.5f ? 1.0f : (1.0f - t) * 2.0f) * i;
|
||||||
}
|
}
|
||||||
|
|
||||||
-(double) getSunIntensity
|
-(float) getSunIntensity
|
||||||
{
|
{
|
||||||
double i = _camera->dSunR;
|
float i = _camera->dSunR;
|
||||||
if(_camera->dSunG > i) i = _camera->dSunG;
|
if(_camera->dSunG > i) i = _camera->dSunG;
|
||||||
if(_camera->dSunB > i) i = _camera->dSunB;
|
if(_camera->dSunB > i) i = _camera->dSunB;
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
-(double) getSunTemperature
|
-(float) getSunTemperature
|
||||||
{
|
{
|
||||||
double i = [self getSunIntensity];
|
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(i == 0.0f) return 0.5f; // Avoid division by zero; assume black has a colour temperature of 0.5
|
||||||
if(_camera->dSunB == i) {
|
if(_camera->dSunB == i) {
|
||||||
// Cold side, t < 0.5
|
// Cold side, t < 0.5
|
||||||
@@ -562,35 +562,35 @@ double const PI = 3.141592653589793f;
|
|||||||
|
|
||||||
// ---===--- Ambient Temperature and intensity ---===---
|
// ---===--- Ambient Temperature and intensity ---===---
|
||||||
|
|
||||||
-(void) setAmbientTemperature:(double)t
|
-(void) setAmbientTemperature:(float)t
|
||||||
{
|
{
|
||||||
double i = [self getAmbientIntensity];
|
float i = [self getAmbientIntensity];
|
||||||
|
|
||||||
_camera->dAmbientR = (t < 0.5f ? t * 2.0f : 1.0f) * i;
|
_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->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;
|
_camera->dAmbientB = (t < 0.5f ? 1.0f : (1.0f - t) * 2.0f) * i;
|
||||||
}
|
}
|
||||||
|
|
||||||
-(void) setAmbientIntensity:(double)i
|
-(void) setAmbientIntensity:(float)i
|
||||||
{
|
{
|
||||||
double t = [self getAmbientTemperature];
|
float t = [self getAmbientTemperature];
|
||||||
|
|
||||||
_camera->dAmbientR = (t < 0.5f ? t * 2.0f : 1.0f) * i;
|
_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->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;
|
_camera->dAmbientB = (t < 0.5f ? 1.0f : (1.0f - t) * 2.0f) * i;
|
||||||
}
|
}
|
||||||
|
|
||||||
-(double) getAmbientIntensity
|
-(float) getAmbientIntensity
|
||||||
{
|
{
|
||||||
double i = _camera->dAmbientR;
|
float i = _camera->dAmbientR;
|
||||||
if(_camera->dAmbientG > i) i = _camera->dAmbientG;
|
if(_camera->dAmbientG > i) i = _camera->dAmbientG;
|
||||||
if(_camera->dAmbientB > i) i = _camera->dAmbientB;
|
if(_camera->dAmbientB > i) i = _camera->dAmbientB;
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
-(double) getAmbientTemperature
|
-(float) getAmbientTemperature
|
||||||
{
|
{
|
||||||
double i = [self getAmbientIntensity];
|
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(i == 0.0f) return 0.5f; // Avoid division by zero; assume black has a colour temperature of 0.5
|
||||||
if(_camera->dAmbientB == i) {
|
if(_camera->dAmbientB == i) {
|
||||||
// Cold side, t < 0.5
|
// Cold side, t < 0.5
|
||||||
|
|||||||
@@ -223,7 +223,7 @@ void KRMat4::ortho(GLfloat left, GLfloat right, GLfloat top, GLfloat bottom, GLf
|
|||||||
bool KRMat4::invert() {
|
bool KRMat4::invert() {
|
||||||
// Based on gluInvertMatrix implementation
|
// Based on gluInvertMatrix implementation
|
||||||
|
|
||||||
double inv[16], det;
|
float inv[16], det;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
inv[0] = m_mat[5]*m_mat[10]*m_mat[15] - m_mat[5]*m_mat[11]*m_mat[14] - m_mat[9]*m_mat[6]*m_mat[15]
|
inv[0] = m_mat[5]*m_mat[10]*m_mat[15] - m_mat[5]*m_mat[11]*m_mat[14] - m_mat[9]*m_mat[6]*m_mat[15]
|
||||||
|
|||||||
@@ -128,59 +128,59 @@ bool KRMaterialManager::load(const char *szName, KRDataBlock *data) {
|
|||||||
}
|
}
|
||||||
} else if(strcmp(szSymbol[0], "ka") == 0) {
|
} else if(strcmp(szSymbol[0], "ka") == 0) {
|
||||||
char *pScan2 = szSymbol[1];
|
char *pScan2 = szSymbol[1];
|
||||||
double r = strtof(pScan2, &pScan2);
|
float r = strtof(pScan2, &pScan2);
|
||||||
if(cSymbols == 2) {
|
if(cSymbols == 2) {
|
||||||
pMaterial->setAmbient(KRVector3(r, r, r));
|
pMaterial->setAmbient(KRVector3(r, r, r));
|
||||||
} else if(cSymbols == 4) {
|
} else if(cSymbols == 4) {
|
||||||
pScan2 = szSymbol[2];
|
pScan2 = szSymbol[2];
|
||||||
double g = strtof(pScan2, &pScan2);
|
float g = strtof(pScan2, &pScan2);
|
||||||
pScan2 = szSymbol[3];
|
pScan2 = szSymbol[3];
|
||||||
double b = strtof(pScan2, &pScan2);
|
float b = strtof(pScan2, &pScan2);
|
||||||
pMaterial->setAmbient(KRVector3(r, g, b));
|
pMaterial->setAmbient(KRVector3(r, g, b));
|
||||||
}
|
}
|
||||||
} else if(strcmp(szSymbol[0], "kd") == 0) {
|
} else if(strcmp(szSymbol[0], "kd") == 0) {
|
||||||
char *pScan2 = szSymbol[1];
|
char *pScan2 = szSymbol[1];
|
||||||
double r = strtof(pScan2, &pScan2);
|
float r = strtof(pScan2, &pScan2);
|
||||||
if(cSymbols == 2) {
|
if(cSymbols == 2) {
|
||||||
pMaterial->setDiffuse(KRVector3(r, r, r));
|
pMaterial->setDiffuse(KRVector3(r, r, r));
|
||||||
} else if(cSymbols == 4) {
|
} else if(cSymbols == 4) {
|
||||||
pScan2 = szSymbol[2];
|
pScan2 = szSymbol[2];
|
||||||
double g = strtof(pScan2, &pScan2);
|
float g = strtof(pScan2, &pScan2);
|
||||||
pScan2 = szSymbol[3];
|
pScan2 = szSymbol[3];
|
||||||
double b = strtof(pScan2, &pScan2);
|
float b = strtof(pScan2, &pScan2);
|
||||||
pMaterial->setDiffuse(KRVector3(r, g, b));
|
pMaterial->setDiffuse(KRVector3(r, g, b));
|
||||||
}
|
}
|
||||||
} else if(strcmp(szSymbol[0], "ks") == 0) {
|
} else if(strcmp(szSymbol[0], "ks") == 0) {
|
||||||
char *pScan2 = szSymbol[1];
|
char *pScan2 = szSymbol[1];
|
||||||
double r = strtof(pScan2, &pScan2);
|
float r = strtof(pScan2, &pScan2);
|
||||||
if(cSymbols == 2) {
|
if(cSymbols == 2) {
|
||||||
pMaterial->setSpecular(KRVector3(r, r, r));
|
pMaterial->setSpecular(KRVector3(r, r, r));
|
||||||
} else if(cSymbols == 4) {
|
} else if(cSymbols == 4) {
|
||||||
pScan2 = szSymbol[2];
|
pScan2 = szSymbol[2];
|
||||||
double g = strtof(pScan2, &pScan2);
|
float g = strtof(pScan2, &pScan2);
|
||||||
pScan2 = szSymbol[3];
|
pScan2 = szSymbol[3];
|
||||||
double b = strtof(pScan2, &pScan2);
|
float b = strtof(pScan2, &pScan2);
|
||||||
pMaterial->setSpecular(KRVector3(r, g, b));
|
pMaterial->setSpecular(KRVector3(r, g, b));
|
||||||
}
|
}
|
||||||
} else if(strcmp(szSymbol[0], "kr") == 0) {
|
} else if(strcmp(szSymbol[0], "kr") == 0) {
|
||||||
char *pScan2 = szSymbol[1];
|
char *pScan2 = szSymbol[1];
|
||||||
double r = strtof(pScan2, &pScan2);
|
float r = strtof(pScan2, &pScan2);
|
||||||
if(cSymbols == 2) {
|
if(cSymbols == 2) {
|
||||||
pMaterial->setReflection(KRVector3(r, r, r));
|
pMaterial->setReflection(KRVector3(r, r, r));
|
||||||
} else if(cSymbols == 4) {
|
} else if(cSymbols == 4) {
|
||||||
pScan2 = szSymbol[2];
|
pScan2 = szSymbol[2];
|
||||||
double g = strtof(pScan2, &pScan2);
|
float g = strtof(pScan2, &pScan2);
|
||||||
pScan2 = szSymbol[3];
|
pScan2 = szSymbol[3];
|
||||||
double b = strtof(pScan2, &pScan2);
|
float b = strtof(pScan2, &pScan2);
|
||||||
pMaterial->setReflection(KRVector3(r, g, b));
|
pMaterial->setReflection(KRVector3(r, g, b));
|
||||||
}
|
}
|
||||||
} else if(strcmp(szSymbol[0], "tr") == 0) {
|
} else if(strcmp(szSymbol[0], "tr") == 0) {
|
||||||
char *pScan2 = szSymbol[1];
|
char *pScan2 = szSymbol[1];
|
||||||
double a = strtof(pScan2, &pScan2);
|
float a = strtof(pScan2, &pScan2);
|
||||||
pMaterial->setTransparency(a);
|
pMaterial->setTransparency(a);
|
||||||
} else if(strcmp(szSymbol[0], "ns") == 0) {
|
} else if(strcmp(szSymbol[0], "ns") == 0) {
|
||||||
char *pScan2 = szSymbol[1];
|
char *pScan2 = szSymbol[1];
|
||||||
double a = strtof(pScan2, &pScan2);
|
float a = strtof(pScan2, &pScan2);
|
||||||
pMaterial->setShininess(a);
|
pMaterial->setShininess(a);
|
||||||
} else if(strncmp(szSymbol[0], "map", 3) == 0) {
|
} else if(strncmp(szSymbol[0], "map", 3) == 0) {
|
||||||
// Truncate file extension
|
// Truncate file extension
|
||||||
@@ -213,7 +213,7 @@ bool KRMaterialManager::load(const char *szName, KRDataBlock *data) {
|
|||||||
iScaleParam = -1;
|
iScaleParam = -1;
|
||||||
} else {
|
} else {
|
||||||
char *pScan3 = szSymbol[iScanSymbol];
|
char *pScan3 = szSymbol[iScanSymbol];
|
||||||
double v = strtof(pScan3, &pScan3);
|
float v = strtof(pScan3, &pScan3);
|
||||||
if(iScaleParam == 0) {
|
if(iScaleParam == 0) {
|
||||||
texture_scale.x = v;
|
texture_scale.x = v;
|
||||||
iScaleParam++;
|
iScaleParam++;
|
||||||
|
|||||||
@@ -168,7 +168,7 @@ void KRPointLight::generateMesh() {
|
|||||||
std::vector<Facet3> f = std::vector<Facet3>(facet_count);
|
std::vector<Facet3> f = std::vector<Facet3>(facet_count);
|
||||||
|
|
||||||
int i,it;
|
int i,it;
|
||||||
double a;
|
float a;
|
||||||
KRVector3 p[6] = {
|
KRVector3 p[6] = {
|
||||||
KRVector3(0,0,1),
|
KRVector3(0,0,1),
|
||||||
KRVector3(0,0,-1),
|
KRVector3(0,0,-1),
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ public:
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
double sun_pitch, sun_yaw;
|
float sun_pitch, sun_yaw;
|
||||||
|
|
||||||
|
|
||||||
void notify_sceneGraphCreate(KRNode *pNode);
|
void notify_sceneGraphCreate(KRNode *pNode);
|
||||||
|
|||||||
@@ -134,11 +134,9 @@ KRShader::KRShader(char *szKey, std::string options, std::string vertShaderSourc
|
|||||||
GLDEBUG(m_uniforms[KRENGINE_UNIFORM_INVMVP_NO_TRANSLATE] = glGetUniformLocation(m_iProgram, "inv_mvp_matrix_no_translate"));
|
GLDEBUG(m_uniforms[KRENGINE_UNIFORM_INVMVP_NO_TRANSLATE] = glGetUniformLocation(m_iProgram, "inv_mvp_matrix_no_translate"));
|
||||||
GLDEBUG(m_uniforms[KRENGINE_UNIFORM_MODEL_VIEW_INVERSE_TRANSPOSE] = glGetUniformLocation(m_iProgram, "model_view_inverse_transpose_matrix"));
|
GLDEBUG(m_uniforms[KRENGINE_UNIFORM_MODEL_VIEW_INVERSE_TRANSPOSE] = glGetUniformLocation(m_iProgram, "model_view_inverse_transpose_matrix"));
|
||||||
GLDEBUG(m_uniforms[KRENGINE_UNIFORM_MODEL_INVERSE_TRANSPOSE] = glGetUniformLocation(m_iProgram, "model_inverse_transpose_matrix"));
|
GLDEBUG(m_uniforms[KRENGINE_UNIFORM_MODEL_INVERSE_TRANSPOSE] = glGetUniformLocation(m_iProgram, "model_inverse_transpose_matrix"));
|
||||||
GLDEBUG(m_uniforms[KRENGINE_UNIFORM_M2V] = glGetUniformLocation(m_iProgram, "model_view_matrix"));
|
GLDEBUG(m_uniforms[KRENGINE_UNIFORM_MODEL_VIEW] = glGetUniformLocation(m_iProgram, "model_view_matrix"));
|
||||||
GLDEBUG(m_uniforms[KRENGINE_UNIFORM_MODEL_MATRIX] = glGetUniformLocation(m_iProgram, "model_matrix"));
|
GLDEBUG(m_uniforms[KRENGINE_UNIFORM_MODEL_MATRIX] = glGetUniformLocation(m_iProgram, "model_matrix"));
|
||||||
|
|
||||||
GLDEBUG(m_uniforms[KRENGINE_UNIFORM_V2M] = glGetUniformLocation(m_iProgram, "inv_model_view_matrix"));
|
|
||||||
|
|
||||||
GLDEBUG(m_uniforms[KRENGINE_UNIFORM_SHADOWMVP1] = glGetUniformLocation(m_iProgram, "shadow_mvp1"));
|
GLDEBUG(m_uniforms[KRENGINE_UNIFORM_SHADOWMVP1] = glGetUniformLocation(m_iProgram, "shadow_mvp1"));
|
||||||
GLDEBUG(m_uniforms[KRENGINE_UNIFORM_SHADOWMVP2] = glGetUniformLocation(m_iProgram, "shadow_mvp2"));
|
GLDEBUG(m_uniforms[KRENGINE_UNIFORM_SHADOWMVP2] = glGetUniformLocation(m_iProgram, "shadow_mvp2"));
|
||||||
GLDEBUG(m_uniforms[KRENGINE_UNIFORM_SHADOWMVP3] = glGetUniformLocation(m_iProgram, "shadow_mvp3"));
|
GLDEBUG(m_uniforms[KRENGINE_UNIFORM_SHADOWMVP3] = glGetUniformLocation(m_iProgram, "shadow_mvp3"));
|
||||||
@@ -206,47 +204,70 @@ bool KRShader::bind(KRCamera *pCamera, KRMat4 &matModel, KRMat4 &matView, KRMat4
|
|||||||
if(m_iProgram == 0) {
|
if(m_iProgram == 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
GLDEBUG(glUseProgram(m_iProgram));
|
||||||
|
|
||||||
|
if(m_uniforms[KRENGINE_UNIFORM_LIGHT_DIRECTION_MODEL_SPACE] != -1 || m_uniforms[KRENGINE_UNIFORM_CAMERAPOS_MODEL_SPACE] != -1) {
|
||||||
|
KRMat4 inverseModelMatrix = matModel;
|
||||||
|
inverseModelMatrix.invert();
|
||||||
|
|
||||||
|
if(m_uniforms[KRENGINE_UNIFORM_LIGHT_DIRECTION_MODEL_SPACE] != -1) {
|
||||||
|
// Bind the light direction vector
|
||||||
|
KRVector3 lightDirObject = KRMat4::Dot(inverseModelMatrix, lightDirection);
|
||||||
|
lightDirObject.normalize();
|
||||||
|
lightDirObject.setUniform(m_uniforms[KRENGINE_UNIFORM_LIGHT_DIRECTION_MODEL_SPACE]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(m_uniforms[KRENGINE_UNIFORM_CAMERAPOS_MODEL_SPACE] != -1) {
|
||||||
|
// Transform location of camera to object space for calculation of specular halfVec
|
||||||
KRMat4 inverseViewMatrix = matView;
|
KRMat4 inverseViewMatrix = matView;
|
||||||
inverseViewMatrix.invert();
|
inverseViewMatrix.invert();
|
||||||
KRVector3 cameraPosition = KRMat4::Dot(inverseViewMatrix, KRVector3::Zero());
|
KRVector3 cameraPosition = KRMat4::Dot(inverseViewMatrix, KRVector3::Zero());
|
||||||
|
|
||||||
// Transform location of camera to object space for calculation of specular halfVec
|
|
||||||
KRMat4 inverseModelMatrix = matModel;
|
|
||||||
inverseModelMatrix.invert();
|
|
||||||
KRVector3 cameraPosObject = KRMat4::Dot(inverseModelMatrix, cameraPosition);
|
KRVector3 cameraPosObject = KRMat4::Dot(inverseModelMatrix, cameraPosition);
|
||||||
KRVector3 lightDirObject = KRMat4::Dot(inverseModelMatrix, lightDirection);
|
cameraPosObject.setUniform(m_uniforms[KRENGINE_UNIFORM_CAMERAPOS_MODEL_SPACE]);
|
||||||
lightDirObject.normalize();
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
GLDEBUG(glUseProgram(m_iProgram));
|
|
||||||
|
|
||||||
// Bind our modelmatrix variable to be a uniform called mvpmatrix in our shaderprogram
|
// Bind our modelmatrix variable to be a uniform called mvpmatrix in our shaderprogram
|
||||||
mvpMatrix.setUniform(m_uniforms[KRENGINE_UNIFORM_MVP]);
|
mvpMatrix.setUniform(m_uniforms[KRENGINE_UNIFORM_MVP]);
|
||||||
|
|
||||||
|
if(m_uniforms[KRShader::KRENGINE_UNIFORM_LIGHT_POSITION_VIEW_SPACE] != -1 || m_uniforms[KRENGINE_UNIFORM_MODEL_VIEW_INVERSE_TRANSPOSE] != -1) {
|
||||||
|
KRMat4 matModelView = matModel * matView;
|
||||||
|
matModelView.setUniform(m_uniforms[KRShader::KRENGINE_UNIFORM_MODEL_VIEW]);
|
||||||
|
|
||||||
KRMat4 matModelViewInverseTranspose = matView * matModel;
|
|
||||||
|
if(m_uniforms[KRShader::KRENGINE_UNIFORM_LIGHT_POSITION_VIEW_SPACE] != -1) {
|
||||||
|
KRVector3 view_space_model_origin = KRMat4::Dot(matModelView, KRVector3::Zero()); // Origin point of model space is the light source position. No perspective, so no w divide required
|
||||||
|
view_space_model_origin.setUniform(m_uniforms[KRShader::KRENGINE_UNIFORM_LIGHT_POSITION_VIEW_SPACE]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(m_uniforms[KRENGINE_UNIFORM_MODEL_VIEW_INVERSE_TRANSPOSE] != -1) {
|
||||||
|
KRMat4 matModelViewInverseTranspose = matModelView;
|
||||||
matModelViewInverseTranspose.transpose();
|
matModelViewInverseTranspose.transpose();
|
||||||
matModelViewInverseTranspose.invert();
|
matModelViewInverseTranspose.invert();
|
||||||
|
|
||||||
matModelViewInverseTranspose.setUniform(m_uniforms[KRENGINE_UNIFORM_MODEL_VIEW_INVERSE_TRANSPOSE]);
|
matModelViewInverseTranspose.setUniform(m_uniforms[KRENGINE_UNIFORM_MODEL_VIEW_INVERSE_TRANSPOSE]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(m_uniforms[KRENGINE_UNIFORM_MODEL_INVERSE_TRANSPOSE] != -1) {
|
||||||
KRMat4 matModelInverseTranspose = matModel;
|
KRMat4 matModelInverseTranspose = matModel;
|
||||||
matModelInverseTranspose.transpose();
|
matModelInverseTranspose.transpose();
|
||||||
matModelInverseTranspose.invert();
|
matModelInverseTranspose.invert();
|
||||||
|
|
||||||
matModelInverseTranspose.setUniform(m_uniforms[KRENGINE_UNIFORM_MODEL_INVERSE_TRANSPOSE]);
|
matModelInverseTranspose.setUniform(m_uniforms[KRENGINE_UNIFORM_MODEL_INVERSE_TRANSPOSE]);
|
||||||
|
}
|
||||||
|
|
||||||
KRMat4 matInvProjection;
|
if(m_uniforms[KRShader::KRENGINE_UNIFORM_INVP] != -1) {
|
||||||
matInvProjection = pCamera->getProjectionMatrix();
|
KRMat4 matInvProjection = pCamera->getProjectionMatrix();
|
||||||
matInvProjection.invert();
|
matInvProjection.invert();
|
||||||
matInvProjection.setUniform(m_uniforms[KRShader::KRENGINE_UNIFORM_INVP]);
|
matInvProjection.setUniform(m_uniforms[KRShader::KRENGINE_UNIFORM_INVP]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(m_uniforms[KRShader::KRENGINE_UNIFORM_INVMVP] != -1) {
|
||||||
KRMat4 matInvMVP = mvpMatrix;
|
KRMat4 matInvMVP = mvpMatrix;
|
||||||
matInvMVP.invert();
|
matInvMVP.invert();
|
||||||
matInvMVP.setUniform(m_uniforms[KRShader::KRENGINE_UNIFORM_INVMVP]);
|
matInvMVP.setUniform(m_uniforms[KRShader::KRENGINE_UNIFORM_INVMVP]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(m_uniforms[KRShader::KRENGINE_UNIFORM_INVMVP_NO_TRANSLATE] != -1) {
|
||||||
KRMat4 matInvMVPNoTranslate = matModel * matView;
|
KRMat4 matInvMVPNoTranslate = matModel * matView;
|
||||||
// Remove the translation
|
// Remove the translation
|
||||||
matInvMVPNoTranslate.getPointer()[3] = 0;
|
matInvMVPNoTranslate.getPointer()[3] = 0;
|
||||||
@@ -259,28 +280,11 @@ bool KRShader::bind(KRCamera *pCamera, KRMat4 &matModel, KRMat4 &matView, KRMat4
|
|||||||
matInvMVPNoTranslate = matInvMVPNoTranslate * pCamera->getProjectionMatrix();
|
matInvMVPNoTranslate = matInvMVPNoTranslate * pCamera->getProjectionMatrix();
|
||||||
matInvMVPNoTranslate.invert();
|
matInvMVPNoTranslate.invert();
|
||||||
matInvMVPNoTranslate.setUniform(m_uniforms[KRShader::KRENGINE_UNIFORM_INVMVP_NO_TRANSLATE]);
|
matInvMVPNoTranslate.setUniform(m_uniforms[KRShader::KRENGINE_UNIFORM_INVMVP_NO_TRANSLATE]);
|
||||||
|
}
|
||||||
|
|
||||||
matModel.setUniform(m_uniforms[KRShader::KRENGINE_UNIFORM_MODEL_MATRIX]);
|
matModel.setUniform(m_uniforms[KRShader::KRENGINE_UNIFORM_MODEL_MATRIX]);
|
||||||
|
|
||||||
|
if(m_uniforms[KRENGINE_UNIFORM_VIEWPORT] != -1) {
|
||||||
{
|
|
||||||
KRMat4 matModelToView2 = KRMat4() * matModel * matView;
|
|
||||||
matModelToView2.setUniform(m_uniforms[KRShader::KRENGINE_UNIFORM_M2V]);
|
|
||||||
|
|
||||||
KRVector3 view_space_model_origin = KRMat4::Dot(matModelToView2, KRVector3::Zero()); // Origin point of model space is the light source position. No perspective, so no w divide required
|
|
||||||
view_space_model_origin.setUniform(m_uniforms[KRShader::KRENGINE_UNIFORM_LIGHT_POSITION_VIEW_SPACE]);
|
|
||||||
|
|
||||||
KRMat4 matViewToModel = matModelToView2;
|
|
||||||
matViewToModel.invert();
|
|
||||||
matViewToModel.setUniform(m_uniforms[KRShader::KRENGINE_UNIFORM_V2M]);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Bind the light direction vector
|
|
||||||
lightDirObject.setUniform(m_uniforms[KRENGINE_UNIFORM_LIGHT_DIRECTION_MODEL_SPACE]);
|
|
||||||
|
|
||||||
// Bind the camera position, in model space
|
|
||||||
cameraPosObject.setUniform(m_uniforms[KRENGINE_UNIFORM_CAMERAPOS_MODEL_SPACE]);
|
|
||||||
|
|
||||||
GLDEBUG(glUniform4f(
|
GLDEBUG(glUniform4f(
|
||||||
m_uniforms[KRENGINE_UNIFORM_VIEWPORT],
|
m_uniforms[KRENGINE_UNIFORM_VIEWPORT],
|
||||||
(GLfloat)0.0,
|
(GLfloat)0.0,
|
||||||
@@ -288,6 +292,7 @@ bool KRShader::bind(KRCamera *pCamera, KRMat4 &matModel, KRMat4 &matView, KRMat4
|
|||||||
(GLfloat)pCamera->getViewportSize().x,
|
(GLfloat)pCamera->getViewportSize().x,
|
||||||
(GLfloat)pCamera->getViewportSize().y
|
(GLfloat)pCamera->getViewportSize().y
|
||||||
));
|
));
|
||||||
|
}
|
||||||
|
|
||||||
// Bind the shadowmap space matrices
|
// Bind the shadowmap space matrices
|
||||||
for(int iShadow=0; iShadow < cShadowBuffers; iShadow++) {
|
for(int iShadow=0; iShadow < cShadowBuffers; iShadow++) {
|
||||||
|
|||||||
@@ -92,8 +92,7 @@ public:
|
|||||||
KRENGINE_UNIFORM_INVMVP_NO_TRANSLATE,
|
KRENGINE_UNIFORM_INVMVP_NO_TRANSLATE,
|
||||||
KRENGINE_UNIFORM_MODEL_VIEW_INVERSE_TRANSPOSE,
|
KRENGINE_UNIFORM_MODEL_VIEW_INVERSE_TRANSPOSE,
|
||||||
KRENGINE_UNIFORM_MODEL_INVERSE_TRANSPOSE,
|
KRENGINE_UNIFORM_MODEL_INVERSE_TRANSPOSE,
|
||||||
KRENGINE_UNIFORM_M2V,
|
KRENGINE_UNIFORM_MODEL_VIEW,
|
||||||
KRENGINE_UNIFORM_V2M,
|
|
||||||
KRENGINE_UNIFORM_MODEL_MATRIX,
|
KRENGINE_UNIFORM_MODEL_MATRIX,
|
||||||
|
|
||||||
KRENGINE_UNIFORM_CAMERAPOS_MODEL_SPACE,
|
KRENGINE_UNIFORM_CAMERAPOS_MODEL_SPACE,
|
||||||
|
|||||||
Reference in New Issue
Block a user