Harald JOHNSEN:
Melchior has found another bug, I tried to skip some computation for a few frames but that introduced some bad rendering bug with the aircraft moving parts. I corrected that and reduced a bit the cpu usage for ground objects.
This commit is contained in:
@@ -361,7 +361,8 @@ bool SGShadowVolume::ShadowCaster::isSelected ( ssgBranch * branch ) {
|
|||||||
/
|
/
|
||||||
perso2 *-----
|
perso2 *-----
|
||||||
*/
|
*/
|
||||||
void SGShadowVolume::ShadowCaster::computeShadows(sgMat4 rotation, sgMat4 rotation_translation) {
|
void SGShadowVolume::ShadowCaster::computeShadows(sgMat4 rotation, sgMat4 rotation_translation,
|
||||||
|
OccluderType occluder_type) {
|
||||||
|
|
||||||
// check the select and range ssgSelector node
|
// check the select and range ssgSelector node
|
||||||
// object can't cast shadow if it is not visible
|
// object can't cast shadow if it is not visible
|
||||||
@@ -369,21 +370,19 @@ void SGShadowVolume::ShadowCaster::computeShadows(sgMat4 rotation, sgMat4 rotati
|
|||||||
if( first_select && ! isSelected( first_select) )
|
if( first_select && ! isSelected( first_select) )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
sgMat4 transform ;
|
|
||||||
sgMat4 invTransform;
|
|
||||||
// get the transformations : this comes from animation code for example
|
// get the transformations : this comes from animation code for example
|
||||||
// or static transf
|
// or static transf
|
||||||
|
sgMat4 transf;
|
||||||
|
sgVec3 lightPos;
|
||||||
|
int deltaFrame = occluder_type == SGShadowVolume::occluderTypeAircraft ? 0 : 9;
|
||||||
|
if( states->frameNumber - frameNumber > deltaFrame) {
|
||||||
|
sgMat4 transform ;
|
||||||
|
sgMat4 invTransform;
|
||||||
getNetTransform( (ssgBranch *) geometry_leaf, transform );
|
getNetTransform( (ssgBranch *) geometry_leaf, transform );
|
||||||
sgMat4 transf;
|
sgCopyMat4( last_transform, transform );
|
||||||
sgCopyMat4( transf, transform );
|
|
||||||
sgPostMultMat4( transf, rotation_translation );
|
|
||||||
sgPostMultMat4( transform, rotation );
|
sgPostMultMat4( transform, rotation );
|
||||||
sgTransposeNegateMat4 ( invTransform, transform );
|
sgTransposeNegateMat4 ( invTransform, transform );
|
||||||
|
|
||||||
glLoadMatrixf ( (float *) states->CameraViewM ) ;
|
|
||||||
glMultMatrixf( (float *) transf );
|
|
||||||
|
|
||||||
sgVec3 lightPos;
|
|
||||||
sgCopyVec3( lightPos, states->sunPos );
|
sgCopyVec3( lightPos, states->sunPos );
|
||||||
sgXformPnt3( lightPos, invTransform );
|
sgXformPnt3( lightPos, invTransform );
|
||||||
|
|
||||||
@@ -395,12 +394,17 @@ void SGShadowVolume::ShadowCaster::computeShadows(sgMat4 rotation, sgMat4 rotati
|
|||||||
// if the geometry has rotated/moved enought then
|
// if the geometry has rotated/moved enought then
|
||||||
// we need to recompute the silhouette
|
// we need to recompute the silhouette
|
||||||
// but this computation does not need to be done each frame
|
// but this computation does not need to be done each frame
|
||||||
if( (deltaPos > 0.0) && ( states->frameNumber - frameNumber > 4)) {
|
if( deltaPos > 0.0 ) {
|
||||||
CalculateSilhouetteEdges( lightPos );
|
CalculateSilhouetteEdges( lightPos );
|
||||||
sgCopyVec3( last_lightpos, lightPosNorm );
|
sgCopyVec3( last_lightpos, lightPosNorm );
|
||||||
frameNumber = states->frameNumber ;
|
frameNumber = states->frameNumber ;
|
||||||
statSilhouette ++;
|
statSilhouette ++;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
sgCopyMat4( transf, last_transform );
|
||||||
|
sgPostMultMat4( transf, rotation_translation );
|
||||||
|
glLoadMatrixf ( (float *) states->CameraViewM ) ;
|
||||||
|
glMultMatrixf( (float *) transf );
|
||||||
|
|
||||||
if( states->shadowsDebug_enabled )
|
if( states->shadowsDebug_enabled )
|
||||||
{
|
{
|
||||||
@@ -546,7 +550,7 @@ void SGShadowVolume::SceneryObject::computeShadows(void) {
|
|||||||
|
|
||||||
ShadowCaster_list::iterator iShadowCaster;
|
ShadowCaster_list::iterator iShadowCaster;
|
||||||
for(iShadowCaster = parts.begin() ; iShadowCaster != parts.end() ; iShadowCaster ++ ) {
|
for(iShadowCaster = parts.begin() ; iShadowCaster != parts.end() ; iShadowCaster ++ ) {
|
||||||
(*iShadowCaster)->computeShadows(rotation, rotation_translation);
|
(*iShadowCaster)->computeShadows(rotation, rotation_translation, occluder_type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -77,6 +77,7 @@ private:
|
|||||||
ssgBranch *lib_object;
|
ssgBranch *lib_object;
|
||||||
ssgBranch *first_select;
|
ssgBranch *first_select;
|
||||||
sgVec3 last_lightpos;
|
sgVec3 last_lightpos;
|
||||||
|
sgMat4 last_transform;
|
||||||
int frameNumber;
|
int frameNumber;
|
||||||
|
|
||||||
int *indices;
|
int *indices;
|
||||||
@@ -94,7 +95,7 @@ private:
|
|||||||
void SetConnectivity();
|
void SetConnectivity();
|
||||||
void CalculateSilhouetteEdges(sgVec3 lightPosition);
|
void CalculateSilhouetteEdges(sgVec3 lightPosition);
|
||||||
void DrawInfiniteShadowVolume(sgVec3 lightPosition, bool drawCaps);
|
void DrawInfiniteShadowVolume(sgVec3 lightPosition, bool drawCaps);
|
||||||
void computeShadows(sgMat4 rotation, sgMat4 rotation_translation);
|
void computeShadows(sgMat4 rotation, sgMat4 rotation_translation, OccluderType occluder_type);
|
||||||
void getNetTransform ( ssgBranch * branch, sgMat4 xform );
|
void getNetTransform ( ssgBranch * branch, sgMat4 xform );
|
||||||
bool isSelected ( ssgBranch * branch );
|
bool isSelected ( ssgBranch * branch );
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user