From: <kla...@us...> - 2016-08-15 14:55:00
|
Revision: 13723 http://sourceforge.net/p/vegastrike/code/13723 Author: klaussfreire Date: 2016-08-15 14:54:57 +0000 (Mon, 15 Aug 2016) Log Message: ----------- Fix 3D cockpit rendering: - Z-buffer range was off such that the whole cockpit was clipped - Lighting was wrong, since the camera was centered but ligths weren't adjusted for it - Disabling Z culling hasn't been working since shader techniques were introduced, that force their own culling modes, so remove the option - Transform matrix was flipping the X axis and thus flipping face normals, fix it to be consistent with GFXLookAt Modified Paths: -------------- trunk/vegastrike/src/gfx/camera.cpp trunk/vegastrike/src/gfx/cockpit.cpp trunk/vegastrike/src/gfxlib.h trunk/vegastrike/src/gldrv/gl_light_state.cpp Modified: trunk/vegastrike/src/gfx/camera.cpp =================================================================== --- trunk/vegastrike/src/gfx/camera.cpp 2016-08-15 14:52:15 UTC (rev 13722) +++ trunk/vegastrike/src/gfx/camera.cpp 2016-08-15 14:54:57 UTC (rev 13723) @@ -124,7 +124,11 @@ #ifdef PERFRAMESOUND AUDListenerOrientation( P, Q, R ); #endif - + + if (centerCamera) + GFXSetLightOffset(-Coord.Cast()); + else + GFXSetLightOffset(Vector(0,0,0)); } void Camera::UpdateCameraSounds() Modified: trunk/vegastrike/src/gfx/cockpit.cpp =================================================================== --- trunk/vegastrike/src/gfx/cockpit.cpp 2016-08-15 14:52:15 UTC (rev 13722) +++ trunk/vegastrike/src/gfx/cockpit.cpp 2016-08-15 14:54:57 UTC (rev 13723) @@ -2431,7 +2431,7 @@ headtrans.clear(); headtrans.push_back( Matrix() ); - VectorAndPositionToMatrix( headtrans.back(), P, Q, R, QVector( 0, 0, 0 ) ); + VectorAndPositionToMatrix( headtrans.back(), -P, Q, R, QVector( 0, 0, 0 ) ); static float theta = 0, wtheta = 0; static float shake_speed = XMLSupport::parse_float( vs_config->getVariable( "graphics", "shake_speed", "50" ) ); @@ -2468,11 +2468,11 @@ ( (GetParent() != NULL) ? LookupUnitStat( UnitImages< void >::WARPFIELDSTRENGTH, GetParent() ) : 0.0f )/warp_shake_ref ) ); if (shakin > shake_limit) shakin = shake_limit; - headtrans.front().p.i = shake_mag*shakin*cos( theta )*cockpitradial/100; //AccessCamera()->GetPosition().i+shakin*cos(theta); - headtrans.front().p.j = shake_mag*shakin*cos( 1.3731*theta )*cockpitradial/100; //AccessCamera()->GetPosition().j+shakin*cos(theta); - headtrans.front().p.k = 0; //AccessCamera()->GetPosition().k; - headtrans.front().p.i += warp_shake_mag*cos( wtheta )*sqr( warp_strength )*cockpitradial/100; //AccessCamera()->GetPosition().i+shakin*cos(theta); - headtrans.front().p.j += warp_shake_mag*cos( 1.165864*wtheta )*sqr( warp_strength )*cockpitradial/100; //AccessCamera()->GetPosition().j+shakin*cos(theta); + headtrans.back().p.i = shake_mag*shakin*cos( theta )*cockpitradial/100; //AccessCamera()->GetPosition().i+shakin*cos(theta); + headtrans.back().p.j = shake_mag*shakin*cos( 1.3731*theta )*cockpitradial/100; //AccessCamera()->GetPosition().j+shakin*cos(theta); + headtrans.back().p.k = 0; //AccessCamera()->GetPosition().k; + headtrans.back().p.i += warp_shake_mag*cos( wtheta )*sqr( warp_strength )*cockpitradial/100; //AccessCamera()->GetPosition().i+shakin*cos(theta); + headtrans.back().p.j += warp_shake_mag*cos( 1.165864*wtheta )*sqr( warp_strength )*cockpitradial/100; //AccessCamera()->GetPosition().j+shakin*cos(theta); if (shakin > 0) { shakin -= GetElapsedTime()*shake_reduction*(shakin/5); //Fast convergence to 5% shaking, slow stabilization if (shakin <= 0) @@ -2487,7 +2487,7 @@ else caccel = Vector( 0, 0, 0 ); float driftphase = pow( 0.25, GetElapsedTime() ); oaccel = (1-driftphase)*caccel+driftphase*oaccel; - headtrans.front().p += -cockpitradial*oaccel; + headtrans.back().p += -cockpitradial*oaccel; float driftmag = cockpitradial*oaccel.Magnitude(); //if (COCKPITZ_PARTITIONS>1) GFXClear(GFXFALSE,GFXFALSE,GFXTRUE);//only clear stencil buffer @@ -2500,30 +2500,22 @@ GFXTRUE, GFXTRUE, GFXTRUE, - zfloor+zrange*j/COCKPITZ_PARTITIONS, - zfloor+zrange*(j+1)/COCKPITZ_PARTITIONS ); //cockpit-specific frustrum (with clipping, with frustrum update) - GFXClear( GFXFALSE, GFXTRUE, GFXFALSE ); //only clear Z + zfloor+zrange*(j-1)/COCKPITZ_PARTITIONS, + zfloor+zrange*j/COCKPITZ_PARTITIONS ); //cockpit-specific frustrum (with clipping, with frustrum update) /*if (COCKPITZ_PARTITIONS>1) { * //Setup stencil * GFXStencilOp(KEEP,KEEP,REPLACE); * GFXStencilFunc(LEQUAL,COCKPITZ_PARTITIONS-j,~0); * GFXStencilMask(~0); * GFXEnable(STENCIL); - * };*/ - _Universe->activateLightMap(); + * }; + */ for (i = 0; i < mesh.size(); ++i) - //mesh[i]->DrawNow(1,true,headtrans.front()); - mesh[i]->Draw( FLT_MAX, headtrans.front() ); - //Whether cockpits shouldn't cull faces - not sure why, probably because - //modellers always set normals the wrong way for cockpits. - static bool nocockpitcull = - XMLSupport::parse_bool( vs_config->getVariable( "graphics", "cockpit_no_face_cull", "true" ) ); - + mesh[i]->Draw( FLT_MAX, headtrans.back() ); Mesh::ProcessZFarMeshes( true ); - if (nocockpitcull) GFXDisable( CULLFACE ); Mesh::ProcessUndrawnMeshes( false, true ); } - headtrans.pop_front(); + headtrans.pop_back(); //if (COCKPITZ_PARTITIONS>1) GFXDisable(STENCIL); GFXDisable( LIGHTING ); GFXDisable( TEXTURE0 ); Modified: trunk/vegastrike/src/gfxlib.h =================================================================== --- trunk/vegastrike/src/gfxlib.h 2016-08-15 14:52:15 UTC (rev 13722) +++ trunk/vegastrike/src/gfxlib.h 2016-08-15 14:54:57 UTC (rev 13723) @@ -88,6 +88,10 @@ void /*GFXDRVAPI*/ GFXGlobalLights( vector< int > &lights, const Vector ¢er, const float radius ); ///loads "lights" with all enabled global lights void /*GFXDRVAPI*/ GFXGlobalLights( vector< int > &lights ); +///Sets light position offset, use when centering the camera off-origin +void /*GFXDRVAPI*/ GFXSetLightOffset( const QVector &offset ); +///Sets light position offset, use when centering the camera off-origin +QVector /*GFXDRVAPI*/ GFXGetLightOffset(); ///Sets the light model to have separate specular color (if available) GFXBOOL /*GFXDRVAPI*/ GFXSetSeparateSpecularColor( const GFXBOOL spec ); ///Sets the intensity cutoff before picked lights are ignored Modified: trunk/vegastrike/src/gldrv/gl_light_state.cpp =================================================================== --- trunk/vegastrike/src/gldrv/gl_light_state.cpp 2016-08-15 14:52:15 UTC (rev 13722) +++ trunk/vegastrike/src/gldrv/gl_light_state.cpp 2016-08-15 14:54:57 UTC (rev 13723) @@ -11,6 +11,18 @@ #define M_PI 3.14159265358979323846264338328 #endif +QVector _light_offset(0,0,0); + +void GFXSetLightOffset( const QVector &offset ) +{ + _light_offset = offset; +} + +QVector GFXGetLightOffset() +{ + return _light_offset; +} + void GFXUploadLightState( int max_light_location, int active_light_array, int apparent_light_size_array, bool shader, vector<int>::const_iterator begin, vector<int>::const_iterator end ) { // FIXME: (klauss) Very bad thing: static variables initialized with heap-allocated arrays... @@ -47,7 +59,7 @@ // For two, scaling would be nullified when scaling both distance // and light size, so it would only waste time. - QVector lightPos = light.getPosition() - modelview.p; + QVector lightPos = light.getPosition() - modelview.p + _light_offset; double lightDistance = lightPos.Magnitude(); double lightSize = light.getSize() * 0.5; @@ -224,7 +236,7 @@ void gfx_light::SendGLPosition( const GLenum target ) const { - float v[4] = {vect[0], vect[1], vect[2], 1}; + float v[4] = {vect[0] + _light_offset.x, vect[1] + _light_offset.y, vect[2] + _light_offset.z, 1}; glLightfv( target, GL_POSITION, v ); } |