Author Topic: Render targets status  (Read 7303 times)

0 Members and 1 Guest are viewing this topic.

Offline WMCoolmon

  • Purveyor of space crack
  • 213
Render targets status
Code: [Select]
--Check for target_set variable, we only need to do this once
if not target_set then
--Create a texture to draw on
--'tex' will always be nil under OpenGL
tex = gr.createTexture(256, 256, "Dynamic")

--If tex was successful, then go ahead with the drawing
if tex then
--Set that texture as the current drawing/rendering buffer
gr.setTarget(tex)

--Set current color to grey
gr.setColor(64, 64, 64)
--Draw rectangle on entire texture
gr.drawRectangle(0, 0, 255, 255, true)
--Set color to green
gr.setColor(0, 255, 0)
--Write "Hello, world!"
gr.drawString("Hello, world!", 0, 0)

--Switch back to drawing on the screen
gr.setTarget()

--Switch to ship to change textures for
ship = mn.getShip("Alpha 1")

--Assuming this is a Ulysses, set all textures to our new one
ship.Textures['fighter01-01a'] = tex
ship.Textures['fighter01-01b'] = tex
ship.Textures['fighter01-01c'] = tex
end

--Set the variable so we don't re-do this every frame
target_set = true
end

Everything seems to work fine, except for the texture replacement code. The render target works, and I've tested it with the 2D functions by drawing to a texture and then calling drawImage on that texture. The texture replacement stuff seems to be getting set fine as well, so I'm not sure what's going on there, either.

Note that any kind of render targets are only supported under D3D...you should always check the return value of createTexture to make sure that it's not Nil.
-C

 

Offline Nuke

  • Ka-Boom!
  • 212
  • Mutants Worship Me
Re: Render targets status
is this what i think it is?
now get us more links to hud gauge data so i can make some custom animated panel gauges :D

now how would you go about loading a texture so that you can add stuf to it. for example i have a cockpit texture, ano in that texture there are a bunch of blank screens. could i render gauges on top of those screens? also would all the shine and glow maps also be processed?
« Last Edit: January 21, 2006, 02:22:29 pm by Nuke »
I can no longer sit back and allow communist infiltration, communist indoctrination, communist subversion, and the international communist conspiracy to sap and impurify all of our precious bodily fluids.

Nuke's Scripting SVN

 

Offline WMCoolmon

  • Purveyor of space crack
  • 213
Re: Render targets status
I'm not sure about shine maps. Theoretically however texture replacement handles that is how those will be handled.

But yeah, that's exactly what you could do. With this code you can also render something to a texture, and then just render that texture every frame, if you don't need to change anything. This can be faster than actually rendering a bunch of lines or a full model. I think you're supposed to either use a dynamic or static map type for that. According to the code, a dynamic map is one that you use frequently, a static infrequently, so I think data is only stored between frames on static maps.
-C

 

Offline Bobboau

  • Just a MODern kinda guy
    Just MODerately cool
    And MODest too
  • 213
Re: Render targets status
IIRC dynamic textures save data between frames just fine, but they draw slower, static ones draw faster but drawing to them is much slower.

and taylor is going to not like this...
Bobboau, bringing you products that work... in theory
learn to use PCS
creator of the ProXimus Procedural Texture and Effect Generator
My latest build of PCS2, get it while it's hot!
PCS 2.0.3


DEUTERONOMY 22:11
Thou shalt not wear a garment of diverse sorts, [as] of woollen and linen together

 

Offline WMCoolmon

  • Purveyor of space crack
  • 213
Re: Render targets status
Well, at this point, most of the use for this is going to be confined to experimental status as people learn Lua. Plus it means that if/when the OGL code is implemented, there will be instant use for it, rather than just sitting around for months on end.
-C

 

Offline Nuke

  • Ka-Boom!
  • 212
  • Mutants Worship Me
Re: Render targets status
i like this caus i had alway thought id have to assign a different texture to each ship's panels and do it that way. but this way eleminates another texture pass and the need to reaply some uv space by allowing me to simply overlay the gauges over the original texture. i figure you could set up the script to only render gauges on the players fighter to save speed. this is cool :D
I can no longer sit back and allow communist infiltration, communist indoctrination, communist subversion, and the international communist conspiracy to sap and impurify all of our precious bodily fluids.

Nuke's Scripting SVN

 

Offline Nuke

  • Ka-Boom!
  • 212
  • Mutants Worship Me
Re: Render targets status
i was thinking about how to do a bridge simulator with this. i would need to actually model a bridge and its texture would be heavliy scripted. i was thinking about a gunnery control console that would have screens displaying the boresight camera on various turrets. is there a way to render a frame from the perspective of the turret normal or an eyepoint and render it to texture? you would be on the bridge and you can view from various screens wich are linked to important turrets and eyepoints on the ship (actually i think eyepoints are submodel relative anyway and could be used for the cameras). it would require some complicated scripting and maybe some sort of mouse based interface. i remember seeing virtual cameras in other games and im wondering would that be hard to implement.

could probibly use this on other things as well, like the gunners panel in the pb sepuelture :D
« Last Edit: January 26, 2006, 12:49:55 pm by Nuke »
I can no longer sit back and allow communist infiltration, communist indoctrination, communist subversion, and the international communist conspiracy to sap and impurify all of our precious bodily fluids.

Nuke's Scripting SVN

 

Offline Nuke

  • Ka-Boom!
  • 212
  • Mutants Worship Me
Re: Render targets status
sorry to bump this i couldnt find a newer thread on this subject. having completed hud pong :D ii want to play with render to texture the next couple days and i thought id try this example. but im not sure if anythings different or whats changed or if it still works at all.. assuming i can get it to work id be willing to put my code in the wiki for everyone to go over and learn from. i have a few questions, like where this code is meant to be placed? will it work in ogl yet? that kind of stuff. im gonna start using it for panel gauges so i got alot of stuff to work out before writing any rendering to texture script. but if i can get an updated overhead that would be great :D

i tried running it from $Simulation, trying both d3d and ogl. i couldnt get anything out of d3d save on occasion a few crashes,  in ogl all i managed to do is black out the ship texture. so im not sure whats going on with it.
« Last Edit: July 11, 2006, 03:36:15 am by Nuke »
I can no longer sit back and allow communist infiltration, communist indoctrination, communist subversion, and the international communist conspiracy to sap and impurify all of our precious bodily fluids.

Nuke's Scripting SVN

 

Offline taylor

  • Super SCP/Linux Guru
  • Moderator
  • 212
    • http://www.icculus.org/~taylor
Re: Render targets status
RTT is broken in D3D, I had to upgrade the interface a little for OGL and I don't know how to do the same thing for D3D.  You'll either have to wait for Bob to fix it or just have to deal with it not working in D3D.  It will only work in OGL, if it actually works.  Meaning, not having one of those bastard ATI cards that you need to use -disable_fbo with.

RTT should still be considered an optional thing.  Some people can't use it because their hardware/drivers don't support it, some people can't use it because their drivers are somewhat broken.  Using it for gauges is fine, but assume that at least 20% of your audience isn't going to be able to see them because of the missing/broken feature.

 

Offline Bobboau

  • Just a MODern kinda guy
    Just MODerately cool
    And MODest too
  • 213
Re: Render targets status
in otherwords it's now your job to make sure there is a non-RTT alternate.

what did you change?
(I'm away from my computer right now so I can't check myself.)
Bobboau, bringing you products that work... in theory
learn to use PCS
creator of the ProXimus Procedural Texture and Effect Generator
My latest build of PCS2, get it while it's hot!
PCS 2.0.3


DEUTERONOMY 22:11
Thou shalt not wear a garment of diverse sorts, [as] of woollen and linen together

 

Offline Nuke

  • Ka-Boom!
  • 212
  • Mutants Worship Me
Re: Render targets status
well as it stands ogl works a hell of alot better for me than d3d (which doesnt have working env at the moment), so id rather just use ogl. i ether want to draw directly on a ships glowmap, or il create a single panel texture for all ships, which can be kept small and have 2 or 3 different styles of panels. probibly to save speed il put a polygon over each panel with the invisible texture but mapped with the proper uv coords for a panel. that way if you dont have rtt support, the polies are invisible and you can still see the static panels behind them, without requiring another texture pass.  i could probibly save some speed is to only re-render the panels like every 10th frame. 

i have my cockpit panels set up in glass cockpit fason, with everything on screens, in the ship texture and shine map they are completely blank, save a little noise and such in the shine map to make it look like glass. so whats displayed on them is entirely on the glow map. if  i can render directly over a ships glowmap with a reasonable speed i might just do it that way.
I can no longer sit back and allow communist infiltration, communist indoctrination, communist subversion, and the international communist conspiracy to sap and impurify all of our precious bodily fluids.

Nuke's Scripting SVN

 

Offline Bobboau

  • Just a MODern kinda guy
    Just MODerately cool
    And MODest too
  • 213
Re: Render targets status
drawing to textures can be very expensive, be carefull.

and one of the big things we wanted RTT for was the ability to seperate the HUD and update parts of it, and things that weren't updated would be drawen with a single pass, as it is half or drawing passes are probly in 2d elements like the HUD.
Bobboau, bringing you products that work... in theory
learn to use PCS
creator of the ProXimus Procedural Texture and Effect Generator
My latest build of PCS2, get it while it's hot!
PCS 2.0.3


DEUTERONOMY 22:11
Thou shalt not wear a garment of diverse sorts, [as] of woollen and linen together

 

Offline Nuke

  • Ka-Boom!
  • 212
  • Mutants Worship Me
Re: Render targets status
i know, i managed to knock the frame rate down to about 4 fps yesterday trying to get it to work. thats sorta why drawing directly to the glow maps is a bad idea. its probibly better to render to a small (and i mean like 256^2 or less) texture for all panels in the game and to routinely skip frames whenever possible. any way to have a function to get the current fps of the game? then i can script in dynamic panel updates so when the framerate's high to do more updates, maybe an update every 5 frames, and if it gets low do them less frequently, like every 20 or 30 frames, or turn off the panels all together. still it would cause an unwanted jitter in the performance and might just make the game unplayable. still my scripting capabilities are quite limited (hudpong for example took me 6 hours to make and another 2 to update with multires support). still it would be nice to have a point and click mfd on a panel, with an actual mouse, you could do some cool stuff, like do a topdown map of the mission area or select intrasystem jump coords, even put pong up on the panel.
I can no longer sit back and allow communist infiltration, communist indoctrination, communist subversion, and the international communist conspiracy to sap and impurify all of our precious bodily fluids.

Nuke's Scripting SVN

 

Offline Wanderer

  • Wiki Warrior
  • 211
  • Mostly harmless
Re: Render targets status
To get lenght of the frame (as time) and from there the FPS... ba.getFrametime()
Do not meddle in the affairs of coders for they are soggy and hard to light

 

Offline WMCoolmon

  • Purveyor of space crack
  • 213
Re: Render targets status
Scripting can be a genuine pain in the ass right now, because of the poor debugging capabilities. If the debugger just gave the frikkin' line number, it wouldn't be such a problem, but as it is I haven't been able to get it out of the thing so far. I've thought of doing something manually by using the per-line hook option, or at least trying to, but I haven't gotten around to it yet.

What I really like about hudpong, though, is that it shows that a mouse interface is most assuredly possible, all the stuff you'd need for it is proven by that one program.
-C

 

Offline Nuke

  • Ka-Boom!
  • 212
  • Mutants Worship Me
Re: Render targets status
me discovering the mouse functions is why hudpong exists. id never have written the script otherwise. i was messing around with my moving retical targeting concept, trying to work out the animated transitions from the static central, non tracking position, to the coordanate tracking mode where its actually leading the target. i never got the lead to work but in the process of making what i had written stable, plugged in the mouse functions into my crosshair render function. resulting in a reticle which moved as a mouse. i thought it would be a good way to controll a turret or something. but instead i wrote a pong game. :D
I can no longer sit back and allow communist infiltration, communist indoctrination, communist subversion, and the international communist conspiracy to sap and impurify all of our precious bodily fluids.

Nuke's Scripting SVN

 

Offline WMCoolmon

  • Purveyor of space crack
  • 213
Re: Render targets status
Bah, when I said 'mouse interface', I was thinking specifically of 'in-game HUD mouse interface'. :rolleyes: Sloppy typing FTL
-C

 

Offline Wanderer

  • Wiki Warrior
  • 211
  • Mostly harmless
Re: Render targets status
Bit out of topic... but here goes... sort of alternate lead indicator that does the job but requires a bit more work..

Code: [Select]
#Global Hooks

$GameInit:

[

-- building weapon velocity library as the data is inaccessible via Lua atm
weaponvelocity = function(name)
   if name == tb.getWeaponClassByName("Halo") then
      wclassvel = 485
   end
   if name == tb.getWeaponClassByName("Akheton SDG") then
      wclassvel = 500
   end
   if name == tb.getWeaponClassByName("Morning Star") then
      wclassvel = 1000
   end
   if name == tb.getWeaponClassByName("Prometheus S") then
      wclassvel = 750
   end
   if name == tb.getWeaponClassByName("Maxim") then
      wclassvel = 1500
   end
   if name == tb.getWeaponClassByName("UD-8 Kayser") then
      wclassvel = 650
   end
   if name == tb.getWeaponClassByName("Subach HL-7") or name == tb.getWeaponClassByName("Lamprey") or name == tb.getWeaponClassByName("Circe") or name == tb.getWeaponClassByName("Prometheus R") then
      wclassvel = 450
   end
   --its nice to return the value too...
   return wclassvel
end

-- draw ugly lead indicator, perhaps simple bitmap would be better...
drawleadreticle = function(x1,y1)
   gr.drawLine(x1-5,y1-2,x1-5,y1+2)
   gr.drawLine(x1+5,y1-2,x1+5,y1+2)
   gr.drawLine(x1-2,y1-5,x1+2,y1-5)
   gr.drawLine(x1-2,y1+5,x1+2,y1+5)
   gr.drawGradientLine(x1,y1,x1+10,y1)
   gr.drawGradientLine(x1,y1,x1,y1+10)
   gr.drawGradientLine(x1,y1,x1-10,y1)
   gr.drawGradientLine(x1,y1,x1,y1-10)
end

--where the weapon intercepts the target assuming it flies along its current velocity (vector)
leadreticle = function(weaponvel)
   if playertrg ~= nil then
      -- gather required data
      local targetpos = playertrg.Position
      local targetvel = playertrg.Velocity
      local lenghttargetvel = targetvel:getMagnitude()
      local playerpos = plr.Position
      local plrtotrg = playerpos - targetpos
      local lenghtplrtotrg = plrtotrg:getMagnitude()
      --use cosine to get the interception time basicaly derived from c^2 = a^2 + b^2 - 2ab cos(C)
      --use dotproduct to get ab cos(C)
      local trgangle = plrtotrg:getDotProduct(targetvel)
      local a = (( weaponvel * weaponvel ) - ( lenghttargetvel * lenghttargetvel ))
      local b = ( 2 * trgangle )
      local c = -( lenghtplrtotrg * lenghtplrtotrg )
      local discrim = ((b * b) - 4 * a * c)
      --idiot checks, i dont think lua can handle imaginary values...
      if discrim >= 0 and a ~= 0 then
         multipl1 = (( -b + math.sqrt(discrim)) / ( 2 * a))
         multipl2 = (( -b - math.sqrt(discrim)) / ( 2 * a))
         --we dont want negative lead do we?
         if multipl1 >=0 and multipl1 <= multipl2 and multipl2 >= 0 then
            targetmult = multipl1
         elseif multipl1 >=0 and multipl2 < 0 then
            targetmult = multipl1
         elseif multipl2 >=0 then
            targetmult = multipl2
         else targetmult = nil
         end
         --with interception time we get the interception coordinates
         if targetmult ~= nil then
            local leadvel = targetvel/(1/targetmult)
            local leadpos = targetpos + leadvel
            if leadpos:getScreenCoords() ~= false then
               leadx, leady = leadpos:getScreenCoords()
               drawleadreticle(leadx,leady)
            end
         end
      end
   end
end

]

$HUD:

[

if plr ~= nil then
   if plr.PrimaryBanks[1] ~= nil and plr.PrimaryBanks[1] ~= false then
      wepname = plr.PrimaryBanks[1].WeaponClass
      weaponvel1 = weaponvelocity(namewep)
   end

   if plr.PrimaryBanks[2] ~= nil and plr.PrimaryBanks[2] ~= false then
      wepname = plr.PrimaryBanks[2].WeaponClass
      weaponvel2 = weaponvelocity(namewep)
   end

   if plr.PrimaryBanks[3] ~= nil and plr.PrimaryBanks[3] ~= false then
      wepname = plr.PrimaryBanks[3].WeaponClass
      weaponvel3 = weaponvelocity(namewep)
   end

   if plr.Target ~= false then
      playertrg = plr.Target
      if playertrg:getBreed() == "Ship" or playertrg:getBreed() == "Weapon" then
         if playertrg.Team.Name == "Hostile" or playertrg.Team.Name == "Traitor" then
            gr.setColor(255,0,0,200)
         elseif playertrg.Team.Name == "Friendly" then
            gr.setColor(0,255,0,200)
         elseif playertrg.Team.Name == "Unknown" then
            gr.setColor(255,0,0,200)
         elseif playertrg.Team.Name == "Neutral" then
            gr.setColor(255,0,255,200)
         else gr.setColor(0,0,255,200)
         end
      else gr.setColor(255,255,255,0)
      end
      if weaponvel1 ~= nil then
         leadreticle(weaponvel1)
      end
      if weaponvel2 ~= nil then
         leadreticle(weaponvel2)
      end
      if weaponvel3 ~= nil then
         leadreticle(weaponvel3)
      end
   end
end

]

#End

EDIT: Hmmm.. managed to paste the wrong version......
« Last Edit: July 13, 2006, 09:37:52 am by Wanderer »
Do not meddle in the affairs of coders for they are soggy and hard to light

 
Re: Render targets status
me discovering the mouse functions is why hudpong exists. id never have written the script otherwise. i was messing around with my moving retical targeting concept, trying to work out the animated transitions from the static central, non tracking position, to the coordanate tracking mode where its actually leading the target. i never got the lead to work but in the process of making what i had written stable, plugged in the mouse functions into my crosshair render function. resulting in a reticle which moved as a mouse. i thought it would be a good way to controll a turret or something. but instead i wrote a pong game. :D
Tie firing angle and camera angle to it as well, and...Freelancer's Turret View anyone? ;7

 

Offline Nuke

  • Ka-Boom!
  • 212
  • Mutants Worship Me
Re: Render targets status
good i was trying to figure this out. looks like it takes more code than i thought it would. i admit i have a nicer looking reticle draw function with fading transparency which is cool (but thats cause im better with pixels than code). but yours has the luxory of working. my goal is top make my reticle autotargeting, as well as to make it a 1 part thing. instead of ligning up a lead indicator with a reticle, i want to light up a single, moving reticle with the ship. this gives the pilot a higher awareness of what that enemy is doing, rather than focusing your eyes on empty space. you seem to have figured out all the math. once the coordanates are projected to 2d, its then just a matter of adding or suptracting the lead distance from the ship, then add or subtract that from the screen center. no doubt by disecting your code il learn something, again. just keep posting sample scripts :D
I can no longer sit back and allow communist infiltration, communist indoctrination, communist subversion, and the international communist conspiracy to sap and impurify all of our precious bodily fluids.

Nuke's Scripting SVN