LODGroup threshold units are now converted correctly when importing FBX files.
Implemented LOD bias setting
This commit is contained in:
@@ -92,6 +92,7 @@ void KRCamera::renderFrame(float deltaTime, GLint renderBufferWidth, GLint rende
|
|||||||
KRMat4 projectionMatrix;
|
KRMat4 projectionMatrix;
|
||||||
projectionMatrix.perspective(settings.perspective_fov, settings.m_viewportSize.x / settings.m_viewportSize.y, settings.perspective_nearz, settings.perspective_farz);
|
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);
|
m_viewport = KRViewport(settings.getViewportSize(), viewMatrix, projectionMatrix);
|
||||||
|
m_viewport.setLODBias(settings.getLODBias());
|
||||||
|
|
||||||
KRVector3 vecCameraDirection = m_viewport.getCameraDirection();
|
KRVector3 vecCameraDirection = m_viewport.getCameraDirection();
|
||||||
|
|
||||||
|
|||||||
@@ -160,7 +160,8 @@ void kraken::set_parameter(const std::string ¶meter_name, float parameter_va
|
|||||||
@"fog_color_b": @45,
|
@"fog_color_b": @45,
|
||||||
@"dust_enable" : @46,
|
@"dust_enable" : @46,
|
||||||
@"dust_intensity" : @47,
|
@"dust_intensity" : @47,
|
||||||
@"debug_display" : @48
|
@"lod_bias" : @48,
|
||||||
|
@"debug_display" : @49
|
||||||
|
|
||||||
} copy];
|
} copy];
|
||||||
[self loadShaders];
|
[self loadShaders];
|
||||||
@@ -233,7 +234,7 @@ void kraken::set_parameter(const std::string ¶meter_name, float parameter_va
|
|||||||
|
|
||||||
-(int)getParameterCount
|
-(int)getParameterCount
|
||||||
{
|
{
|
||||||
return 49;
|
return 50;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -249,7 +250,7 @@ void kraken::set_parameter(const std::string ¶meter_name, float parameter_va
|
|||||||
|
|
||||||
-(NSString *)getParameterLabelWithIndex: (int)i
|
-(NSString *)getParameterLabelWithIndex: (int)i
|
||||||
{
|
{
|
||||||
NSString *parameter_labels[49] = {
|
NSString *parameter_labels[50] = {
|
||||||
@"Camera FOV",
|
@"Camera FOV",
|
||||||
@"Shadow Quality (0 - 2)",
|
@"Shadow Quality (0 - 2)",
|
||||||
@"Enable per-pixel lighting",
|
@"Enable per-pixel lighting",
|
||||||
@@ -298,13 +299,14 @@ void kraken::set_parameter(const std::string ¶meter_name, float parameter_va
|
|||||||
@"Fog - Color B",
|
@"Fog - Color B",
|
||||||
@"Dust - Enable",
|
@"Dust - Enable",
|
||||||
@"Dust - Intensity",
|
@"Dust - Intensity",
|
||||||
|
@"LOD Bias",
|
||||||
@"Debug - Display"
|
@"Debug - Display"
|
||||||
};
|
};
|
||||||
return parameter_labels[i];
|
return parameter_labels[i];
|
||||||
}
|
}
|
||||||
-(KREngineParameterType)getParameterTypeWithIndex: (int)i
|
-(KREngineParameterType)getParameterTypeWithIndex: (int)i
|
||||||
{
|
{
|
||||||
KREngineParameterType types[49] = {
|
KREngineParameterType types[50] = {
|
||||||
|
|
||||||
KRENGINE_PARAMETER_FLOAT,
|
KRENGINE_PARAMETER_FLOAT,
|
||||||
KRENGINE_PARAMETER_INT,
|
KRENGINE_PARAMETER_INT,
|
||||||
@@ -354,13 +356,14 @@ void kraken::set_parameter(const std::string ¶meter_name, float parameter_va
|
|||||||
KRENGINE_PARAMETER_FLOAT,
|
KRENGINE_PARAMETER_FLOAT,
|
||||||
KRENGINE_PARAMETER_BOOL,
|
KRENGINE_PARAMETER_BOOL,
|
||||||
KRENGINE_PARAMETER_FLOAT,
|
KRENGINE_PARAMETER_FLOAT,
|
||||||
|
KRENGINE_PARAMETER_FLOAT,
|
||||||
KRENGINE_PARAMETER_INT
|
KRENGINE_PARAMETER_INT
|
||||||
};
|
};
|
||||||
return types[i];
|
return types[i];
|
||||||
}
|
}
|
||||||
-(float)getParameterValueWithIndex: (int)i
|
-(float)getParameterValueWithIndex: (int)i
|
||||||
{
|
{
|
||||||
float values[49] = {
|
float values[50] = {
|
||||||
_settings.perspective_fov,
|
_settings.perspective_fov,
|
||||||
(float)_settings.m_cShadowBuffers,
|
(float)_settings.m_cShadowBuffers,
|
||||||
_settings.bEnablePerPixel ? 1.0f : 0.0f,
|
_settings.bEnablePerPixel ? 1.0f : 0.0f,
|
||||||
@@ -409,6 +412,7 @@ void kraken::set_parameter(const std::string ¶meter_name, float parameter_va
|
|||||||
_settings.fog_color.z,
|
_settings.fog_color.z,
|
||||||
_settings.dust_particle_enable,
|
_settings.dust_particle_enable,
|
||||||
_settings.dust_particle_intensity,
|
_settings.dust_particle_intensity,
|
||||||
|
_settings.getLODBias(),
|
||||||
_settings.debug_display
|
_settings.debug_display
|
||||||
};
|
};
|
||||||
return values[i];
|
return values[i];
|
||||||
@@ -603,6 +607,9 @@ void kraken::set_parameter(const std::string ¶meter_name, float parameter_va
|
|||||||
_settings.dust_particle_intensity = v;
|
_settings.dust_particle_intensity = v;
|
||||||
break;
|
break;
|
||||||
case 48:
|
case 48:
|
||||||
|
_settings.setLODBias(v);
|
||||||
|
break;
|
||||||
|
case 49:
|
||||||
_settings.debug_display = (KRRenderSettings::debug_display_type)v;
|
_settings.debug_display = (KRRenderSettings::debug_display_type)v;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -610,12 +617,12 @@ void kraken::set_parameter(const std::string ¶meter_name, float parameter_va
|
|||||||
|
|
||||||
-(float)getParameterMinWithIndex: (int)i
|
-(float)getParameterMinWithIndex: (int)i
|
||||||
{
|
{
|
||||||
float minValues[49] = {
|
float minValues[50] = {
|
||||||
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, 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.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, 0.0f
|
0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, -10.0f, 0.0f
|
||||||
};
|
};
|
||||||
|
|
||||||
return minValues[i];
|
return minValues[i];
|
||||||
@@ -623,12 +630,12 @@ void kraken::set_parameter(const std::string ¶meter_name, float parameter_va
|
|||||||
|
|
||||||
-(float)getParameterMaxWithIndex: (int)i
|
-(float)getParameterMaxWithIndex: (int)i
|
||||||
{
|
{
|
||||||
float maxValues[49] = {
|
float maxValues[50] = {
|
||||||
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, 0.5f, 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, 1.0f, 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,
|
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, (float)(KRRenderSettings::KRENGINE_DEBUG_DISPLAY_NUMBER - 1)
|
1000.0f, 1000.0f, 0.01f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 10.0f, (float)(KRRenderSettings::KRENGINE_DEBUG_DISPLAY_NUMBER - 1)
|
||||||
};
|
};
|
||||||
|
|
||||||
return maxValues[i];
|
return maxValues[i];
|
||||||
|
|||||||
@@ -86,11 +86,13 @@ bool KRLODGroup::getLODVisibility(const KRViewport &viewport)
|
|||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
// return (m_max_distance == 0); // FINDME, HACK - Test code to enable only the lowest LOD group
|
// return (m_max_distance == 0); // FINDME, HACK - Test code to enable only the lowest LOD group
|
||||||
float lod_bias = 1.0f;
|
float lod_bias = viewport.getLODBias();
|
||||||
|
lod_bias = pow(2.0f, lod_bias);
|
||||||
// Compare square distances as sqrt is expensive
|
// Compare square distances as sqrt is expensive
|
||||||
float sqr_distance = (viewport.getCameraPosition() - getWorldReferencePoint()).sqrMagnitude() * (lod_bias * lod_bias);
|
float sqr_distance = (viewport.getCameraPosition() - getWorldReferencePoint()).sqrMagnitude() * (lod_bias * lod_bias);
|
||||||
return ((sqr_distance >= m_min_distance * m_min_distance || m_min_distance == 0) && (sqr_distance < m_max_distance * m_max_distance || m_max_distance == 0));
|
float sqr_min_distance = m_min_distance * m_min_distance;
|
||||||
|
float sqr_max_distance = m_max_distance * m_max_distance;
|
||||||
|
return ((sqr_distance >= sqr_min_distance || m_min_distance == 0) && (sqr_distance < sqr_max_distance || m_max_distance == 0));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -73,6 +73,8 @@ KRRenderSettings::KRRenderSettings()
|
|||||||
dust_particle_intensity = 0.25f;
|
dust_particle_intensity = 0.25f;
|
||||||
dust_particle_enable = false;
|
dust_particle_enable = false;
|
||||||
|
|
||||||
|
m_lodBias = 1.0f;
|
||||||
|
|
||||||
debug_display = KRENGINE_DEBUG_DISPLAY_NONE;
|
debug_display = KRENGINE_DEBUG_DISPLAY_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -141,6 +143,8 @@ KRRenderSettings& KRRenderSettings::operator=(const KRRenderSettings &s)
|
|||||||
m_skyBoxName=s.m_skyBoxName;
|
m_skyBoxName=s.m_skyBoxName;
|
||||||
debug_display = s.debug_display;
|
debug_display = s.debug_display;
|
||||||
|
|
||||||
|
m_lodBias = s.m_lodBias;
|
||||||
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -178,3 +182,13 @@ void KRRenderSettings::setPerpsectiveFarZ(float v)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
float KRRenderSettings::getLODBias()
|
||||||
|
{
|
||||||
|
return m_lodBias;
|
||||||
|
}
|
||||||
|
|
||||||
|
void KRRenderSettings::setLODBias(float v)
|
||||||
|
{
|
||||||
|
m_lodBias = v;
|
||||||
|
}
|
||||||
@@ -28,6 +28,9 @@ public:
|
|||||||
void setPerspectiveNear(float v);
|
void setPerspectiveNear(float v);
|
||||||
void setPerpsectiveFarZ(float v);
|
void setPerpsectiveFarZ(float v);
|
||||||
|
|
||||||
|
float getLODBias();
|
||||||
|
void setLODBias(float v);
|
||||||
|
|
||||||
bool bEnablePerPixel;
|
bool bEnablePerPixel;
|
||||||
bool bEnableDiffuseMap;
|
bool bEnableDiffuseMap;
|
||||||
bool bEnableNormalMap;
|
bool bEnableNormalMap;
|
||||||
@@ -95,6 +98,7 @@ public:
|
|||||||
} debug_display;
|
} debug_display;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
float m_lodBias;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -594,6 +594,9 @@ void LoadNode(KFbxScene* pFbxScene, KRNode *parent_node, std::vector<KRResource
|
|||||||
KFbxVector4 lTmpVector;
|
KFbxVector4 lTmpVector;
|
||||||
pNode->UpdatePropertiesFromPivotsAndLimits();
|
pNode->UpdatePropertiesFromPivotsAndLimits();
|
||||||
|
|
||||||
|
|
||||||
|
FbxSystemUnit system_unit = pFbxScene->GetGlobalSettings().GetSystemUnit();
|
||||||
|
|
||||||
// Transform = T * Roff * Rp * Rpre * R * Rpost * inverse(Rp) * Soff * Sp * S * inverse(Sp)
|
// Transform = T * Roff * Rp * Rpre * R * Rpost * inverse(Rp) * Soff * Sp * S * inverse(Sp)
|
||||||
|
|
||||||
// Import animated properties
|
// Import animated properties
|
||||||
@@ -759,12 +762,12 @@ void LoadNode(KFbxScene* pFbxScene, KRNode *parent_node, std::vector<KRResource
|
|||||||
if(i > 0 ) {
|
if(i > 0 ) {
|
||||||
FbxDistance d;
|
FbxDistance d;
|
||||||
fbx_lod_group->GetThreshold(i - 1, d);
|
fbx_lod_group->GetThreshold(i - 1, d);
|
||||||
min_distance = d.value();
|
min_distance = d.valueAs(system_unit);
|
||||||
}
|
}
|
||||||
if(i < child_count - 1) {
|
if(i < child_count - 1) {
|
||||||
FbxDistance d;
|
FbxDistance d;
|
||||||
fbx_lod_group->GetThreshold(i, d);
|
fbx_lod_group->GetThreshold(i, d);
|
||||||
max_distance = d.value();
|
max_distance = d.valueAs(system_unit);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case FbxLODGroup::eShow:
|
case FbxLODGroup::eShow:
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ KRViewport::KRViewport()
|
|||||||
m_size = KRVector2::One();
|
m_size = KRVector2::One();
|
||||||
m_matProjection = KRMat4();
|
m_matProjection = KRMat4();
|
||||||
m_matView = KRMat4();
|
m_matView = KRMat4();
|
||||||
|
m_lodBias = 1.0f;
|
||||||
calculateDerivedValues();
|
calculateDerivedValues();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -36,6 +37,7 @@ KRViewport& KRViewport::operator=(const KRViewport &v) {
|
|||||||
m_size = v.m_size;
|
m_size = v.m_size;
|
||||||
m_matProjection = v.m_matProjection;
|
m_matProjection = v.m_matProjection;
|
||||||
m_matView = v.m_matView;
|
m_matView = v.m_matView;
|
||||||
|
m_lodBias = v.m_lodBias;
|
||||||
|
|
||||||
calculateDerivedValues();
|
calculateDerivedValues();
|
||||||
}
|
}
|
||||||
@@ -158,3 +160,14 @@ std::map<KRAABB, int> &KRViewport::getVisibleBounds()
|
|||||||
{
|
{
|
||||||
return m_visibleBounds;
|
return m_visibleBounds;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
float KRViewport::getLODBias() const
|
||||||
|
{
|
||||||
|
return m_lodBias;
|
||||||
|
}
|
||||||
|
|
||||||
|
void KRViewport::setLODBias(float lod_bias)
|
||||||
|
{
|
||||||
|
m_lodBias = lod_bias;
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -35,6 +35,8 @@ public:
|
|||||||
void setSize(const KRVector2 &size);
|
void setSize(const KRVector2 &size);
|
||||||
void setViewMatrix(const KRMat4 &matView);
|
void setViewMatrix(const KRMat4 &matView);
|
||||||
void setProjectionMatrix(const KRMat4 &matProjection);
|
void setProjectionMatrix(const KRMat4 &matProjection);
|
||||||
|
float getLODBias() const;
|
||||||
|
void setLODBias(float lod_bias);
|
||||||
|
|
||||||
// Overload assignment operator
|
// Overload assignment operator
|
||||||
KRViewport& operator=(const KRViewport &v);
|
KRViewport& operator=(const KRViewport &v);
|
||||||
@@ -49,6 +51,7 @@ private:
|
|||||||
KRMat4 m_matView;
|
KRMat4 m_matView;
|
||||||
KRMat4 m_matProjection;
|
KRMat4 m_matProjection;
|
||||||
|
|
||||||
|
float m_lodBias;
|
||||||
|
|
||||||
// Derived values
|
// Derived values
|
||||||
KRMat4 m_matViewProjection;
|
KRMat4 m_matViewProjection;
|
||||||
|
|||||||
Reference in New Issue
Block a user