Author Topic: Wormhole lighting fix  (Read 1880 times)

0 Members and 1 Guest are viewing this topic.

Offline Valathil

  • ...And I would have had a custom title if it wasn't for you meddling kids!
  • 29
  • Custom Title? Wizards need no Custom Title!
Wormhole lighting fix
Wormhole lighting intensity is currently fixed this patch fixes this by interpolating intensity based on wormhole radius

Code: [Select]
Index: code/fireball/fireballs.cpp
===================================================================
--- code/fireball/fireballs.cpp (Revision 7324)
+++ code/fireball/fireballs.cpp (Arbeitskopie)
@@ -1044,3 +1044,27 @@
 
  return index;
 }
+
+float fireball_wormhole_intensity( object *obj )
+{
+ int num, objnum;
+ fireball *fb;
+
+ num = obj->instance;
+ objnum = OBJ_INDEX(obj);
+ Assert( Fireballs[num].objnum == objnum, "Basic sanity check. Fireballs[num].objnum (%d) should == objnum (%d)", Fireballs[num].objnum, objnum );
+
+ fb = &Fireballs[num];
+
+ float t = fb->time_elapsed;
+ float rad;
+
+ if ( t < WARPHOLE_GROW_TIME ) {
+ rad = (float)pow(t/WARPHOLE_GROW_TIME,0.4f);
+ } else if ( t < fb->total_time - WARPHOLE_GROW_TIME ) {
+ rad = 1;
+ } else {
+ rad = (float)pow((fb->total_time - t)/WARPHOLE_GROW_TIME,0.4f);
+ }
+ return rad;
+}
Index: code/fireball/fireballs.h
===================================================================
--- code/fireball/fireballs.h (Revision 7324)
+++ code/fireball/fireballs.h (Arbeitskopie)
@@ -107,6 +107,9 @@
 // returns the index of the fireball bitmap for this ship. -1 if there is none.
 int fireball_ship_explosion_type(ship_info *sip);
 
+// returns the intensity of a wormhole
+float fireball_wormhole_intensity( object *obj );
+
 // internal function to draw warp grid.
 extern void warpin_render(object *obj, matrix *orient, vec3d *pos, int texture_bitmap_num, float radius, float life_percent, float max_radius, int warp_3d = 0 );
 
Index: code/object/object.cpp
===================================================================
--- code/object/object.cpp (Revision 7324)
+++ code/object/object.cpp (Arbeitskopie)
@@ -1261,11 +1261,17 @@
  p = 1.0f - p;
 
  p *= 2.0f;
-
+ float rad = p * (1.0f + frand() * 0.05f) * objp->radius;
+
+ float intensity = 1.0f;
+ if(fireball_is_warp(objp))
+ {
+ intensity = fireball_wormhole_intensity(objp); // Valathil: Get wormhole radius for lighting
+ rad = objp->radius;
+ }
  // P goes from 0 to 1 to 0 over the life of the explosion
- float rad = p * (1.0f + frand() * 0.05f) * objp->radius;
-
- light_add_point( &objp->pos, rad * 2.0f, rad * 5.0f, 1.0f, r, g, b, -1 );
+
+ light_add_point( &objp->pos, rad * 2.0f, rad * 5.0f, intensity, r, g, b, -1 );
  }
  }
 
« Last Edit: July 05, 2011, 05:22:28 pm by Valathil »
┏┓╋┏┓╋╋╋╋╋╋╋╋╋┏┓
┃┃╋┃┃╋╋╋╋╋╋╋╋╋┃┃
┃┃┏┫┃┏┳━━┓┏━━┓┃┗━┳━━┳━━┳━━┓
┃┃┣┫┗┛┫┃━┫┃┏┓┃┃┏┓┃┏┓┃━━┫━━┫
┃┗┫┃┏┓┫┃━┫┃┏┓┃┃┗┛┃┗┛┣━━┣━━┃
┗━┻┻┛┗┻━━┛┗┛┗┛┗━━┻━━┻━━┻━━┛

 

Offline Iss Mneur

  • 210
  • TODO:
Re: Wormhole lighting fix
Please use assertions, so that the assert has a reason recorded that will be shown and please include the values involved in the assertion so that we don't need to have a debugger attached to find out what the problem with the values was.  That is something like this:

Code: [Select]
+ Assertion( Fireballs[num].objnum == objnum, "Basic sanity check. Fireballs[num].objnum (%d) should == objnum (%d)", Fireballs[num].objnum, objnum);



Why is there a commented out assertion?
Why is are we committing commented out lines of code that appear to be the old version of the line above.
Why is there a commented out mprintf?  If the information will not be usable in the future, please remove it.  If it may be useful, use nprintf with an appropriate filter (I think we have a "lighting" filter already in use).
If there are valid reasons for the above, please note them in the code.
"I love deadlines. I like the whooshing sound they make as they fly by." -Douglas Adams
wxLauncher 0.9.4 public beta (now with no config file editing for FRED) | wxLauncher 2.0 Request for Comments

 

Offline Valathil

  • ...And I would have had a custom title if it wasn't for you meddling kids!
  • 29
  • Custom Title? Wizards need no Custom Title!
Re: Wormhole lighting fix
Ok great tip i just copied this code from another function in the fireball.cpp but i will update and keep in mind when using assertions in the future.
EDIT: Also fixed your other points of contention (hopefully  :confused:)
« Last Edit: July 05, 2011, 05:23:59 pm by Valathil »
┏┓╋┏┓╋╋╋╋╋╋╋╋╋┏┓
┃┃╋┃┃╋╋╋╋╋╋╋╋╋┃┃
┃┃┏┫┃┏┳━━┓┏━━┓┃┗━┳━━┳━━┳━━┓
┃┃┣┫┗┛┫┃━┫┃┏┓┃┃┏┓┃┏┓┃━━┫━━┫
┃┗┫┃┏┓┫┃━┫┃┏┓┃┃┗┛┃┗┛┣━━┣━━┃
┗━┻┻┛┗┻━━┛┗┛┗┛┗━━┻━━┻━━┻━━┛

 

Offline chief1983

  • Still lacks a custom title
  • Moderator
  • 212
  • ⬇️⬆️⬅️⬅️🅰➡️⬇️
    • Skype
    • Steam
    • Twitter
    • Fate of the Galaxy
Re: Wormhole lighting fix
Would possibly be nice to have mod-level control of this too, as mods with custom effects might have dimmer lighting, or is the intensity of the effect itself already taken into account?  I mean, if I had a black wormhole effect for some reason, it shouldn't be giving off light right?
Fate of the Galaxy - Now Hiring!  Apply within | Diaspora | SCP Home | Collada Importer for PCS2
Karajorma's 'How to report bugs' | Mantis
#freespace | #scp-swc | #diaspora | #SCP | #hard-light on EsperNet

"You may not sell or otherwise commercially exploit the source or things you created based on the source." -- Excerpt from FSO license, for reference

Nuclear1:  Jesus Christ zack you're a little too hamyurger for HLP right now...
iamzack:  i dont have hamynerge i just want ptatoc hips D:
redsniper:  Platonic hips?!
iamzack:  lays

 

Offline Valathil

  • ...And I would have had a custom title if it wasn't for you meddling kids!
  • 29
  • Custom Title? Wizards need no Custom Title!
Re: Wormhole lighting fix
this just sets the intensity of the light in question based on the timeline of the animation so whatever you put in your color for the light is just scaled by that intensity. if you take a close look intensity was 1.0f before
┏┓╋┏┓╋╋╋╋╋╋╋╋╋┏┓
┃┃╋┃┃╋╋╋╋╋╋╋╋╋┃┃
┃┃┏┫┃┏┳━━┓┏━━┓┃┗━┳━━┳━━┳━━┓
┃┃┣┫┗┛┫┃━┫┃┏┓┃┃┏┓┃┏┓┃━━┫━━┫
┃┗┫┃┏┓┫┃━┫┃┏┓┃┃┗┛┃┗┛┣━━┣━━┃
┗━┻┻┛┗┻━━┛┗┛┗┛┗━━┻━━┻━━┻━━┛

  

Offline Iss Mneur

  • 210
  • TODO:
Re: Wormhole lighting fix
Committed to trunk as revision 7325.
"I love deadlines. I like the whooshing sound they make as they fly by." -Douglas Adams
wxLauncher 0.9.4 public beta (now with no config file editing for FRED) | wxLauncher 2.0 Request for Comments