Render to Texture demo

Blitz3D Forums/Blitz3D Programming/Render to Texture demo

Tom(Posted 2004) [#1]
Hi,

This is just a test, there's no checking at all yet so it 'may' cause a MAV, also that ATI 'thing' may stop the clearing working.

I take no responsibility if it goes pear shaped, try at your own discretion!

http://www.tomspeed.com/r2t.zip

The checking will come soon, I'm still slowly wading through this DX SDK, I liken it to swimming in honey :P

Anyways, it's possible, it does work (for me at least), and it's fast.

I had to cheat, I created a renderable texture, then hijack a BB texture and replaced it's surface pointer to the render texture pointer. Blending modes still work too.

More later!
Tom


fredborg(Posted 2004) [#2]
dude this sucks!


Tom(Posted 2004) [#3]
Bleedin hecklers :P


fredborg(Posted 2004) [#4]
Yeah, and don't get me started on US politics either!

Seriously it rocks!


Hujiklo(Posted 2004) [#5]
Is this for a mirror Tom? It looks great and is very realistic!


Tom(Posted 2004) [#6]
This version uses BB clear instead of the DLL one, should avoid ATI problems (if any)

http://www.tomspeed.com/r2t-bbclear.zip

After setting the render texture, the render loop is pretty simple:

While Not Keyhit(1)
; Set the renderTexture
SetRenderTarget(renderTex)
CameraClsMode cam,False,True ; don't clear color
ScaleEntity cam,1.33,1,1 ; scale render to fit 512x512 texture
RenderWorld

; Set the render target back to BackBuffer()
SetRenderTarget(rtbb)
CameraClsMode cam,True,True
ScaleEntity cam,1,1,1
RenderWorld
Flip
Wend



John Pickford(Posted 2004) [#7]
Any chance of speed comparision between this and the usual render-to-backbuffer->copyrect technique?

My game uses a lot of render to textures so I'm intrigued by this.


Dock(Posted 2004) [#8]
Works great for me, and much like John Pickford a working implementation of this code would make a huge difference to the speed of my game (it involves a lot of cubemaps and some shadows).


mrtricks(Posted 2004) [#9]
Can't wait to try this out (at work atm) as my game demo involves a lot of render to texture too...


Bouncer(Posted 2004) [#10]
Absolutely wonderfull stuff Tom!!


TartanTangerine (was Indiepath)(Posted 2004) [#11]
This is very nice.


John Pickford(Posted 2004) [#12]
Hmm... I'm doing up to 8 render to textures in my game. I just tried making the copyrect() part of the process only happen if you aren't pressing CTRL. It makes no noticable difference to the framerate either way. Perhaps the results will be different on other cards.

This system will still be useful if you want to render into a texture which is bigger than the screen.


Software Horizons(Posted 2004) [#13]
Just want to say you're doing awesome work. The clipping plane from your stencil mirror AND this render to texture code was exactly what I needed for my project, and spookily both have just abour arrived as I've needed them. Don't stop and could you please put up latest decl's and source?


Bouncer(Posted 2004) [#14]
Yeah Tom... If you'll release the decls for this I'll be forever grateful... with this it would be possible to make a decent speed Bloom effect.

please... please... please :)


Tom(Posted 2004) [#15]
Will do soon :)

Trying my best to implement caps checking for all this stuff, otherwise it'll be useless if you implement it in a project only to find it doesn't work on someone's PC.

I managed to convert a loaded texture to DXT compression last night too :) AvailVidMem() Immediately showed a saving of a few meg on 1 1024 * 1024 res texture! Though there's an odd pause while I Blit the existing texture over from the existing texture surface to the compressed surface.

If I knew how B3D stored textures/images I could probably do all this properly and return a pointer to Blitz.


See if I can get this DLL out over the weekend.

Tom


Dreamora(Posted 2004) [#16]
Sounds great :)

The second version of the render to surface works superb on my mobility radeon 9700 :)


Software Horizons(Posted 2004) [#17]
This might be dumb but doesn't Blitz use the FreeImage library to store its textures\images in memory? Perhaps that's a clue to how to get them?


slenkar(Posted 2004) [#18]
works on my PC which means it will work on most pc'S


Tom(Posted 2004) [#19]
Pilot: I can access texture/image 'buffers' as normal DX7 surfaces, the problem is returning a pointer back to Blitz.

i.e

myTex=LoadTexture("pic.jpg")

'myTex' is a pointer to a Struct in memory that Blitz uses to store information on the loaded texture, somewhere within that struct would be a pointer to the IDirectDrawSurface7, as well as information on its flags/blending modes e.t.c.

I found by trial & error that INT (TextureBuffer()+12) = a valid IDirectDrawSurface7 pointer. So what I've been doing is creating surfaces with other properties and placing the pointer back at TextureBuffer()+12

Hacky, but it works.

Dreamora & Slenkar, good to know it's working on more PCs :))

Keep you posted!
Tom


Bouncer(Posted 2004) [#20]
Any new developments on this Tom?? I just can't wait... :)


BlitzSupport(Posted 2004) [#21]
The first version fails for me (I get corrupted graphics), but the bbclear one works well.


Tom(Posted 2004) [#22]
Yup, I was going the long way about creating a compliant renderable surface. Now I'm cpying Blitzes current backbuffer & Zbuffer, so if it fails, it's ONLY because the GFX hardware just plain doesn't support renderable textures.

I'll throw up a DLL and some source to try in a few minutes.

Tom


Tom(Posted 2004) [#23]
Ok give this a try:

http://www.tomspeed.com/r2t.zip

Copy contents of userlibs over to your blitz3d\userlibs folder

As with using any experimental software, please BACKUP your important data before using! Read the 'reade me.txt' before using, thanks.

Lemme know how you get on.

Cheers
Tom


Dreamora(Posted 2004) [#24]
works without probs :) ( beside the fact that LMB does not do anything on my radeon 9700 )

just had to kick the texturefilters.decl from another DX7 userlibs floating around here ( for those that are having probs )


Mikele(Posted 2004) [#25]
Wow!!! DXTC!!!
:o)
Works well..


GW(Posted 2004) [#26]
There is no 'readme' file or decls file, The zip looks the same as the previous one.

Edit:
Ops never mind Its wss Firefox being dumb ;(


Tom(Posted 2004) [#27]
Dreamorama: oops! :) That texture filters was mine too sorry. I'll eventualy add all the 'useful' DX stuff into the 1 DLL.

To see the ripple effect you need to show the screen mesh, it defaults to hidden, so press space, then try LMB!

Tom


Dreamora(Posted 2004) [#28]
ah ok thanks :)

yeah I saw that it was yours ;)
I deleted it, didn't use the functions so far, just the ones from the old dx7test.dll which had a changed interface decl ;) ( old were device, ... )

one thing I miss now in the DLL is the maxtexturewidth height function ;)

( I hope it is ok to use it in own projects? )

but great stuff :)

1mb for a 1024x1024 instead of 4mb is just cool :)

Still ask myself why BR did never implement it ( a simple "this mode prevents you from doing any further operations on the texture" note would have been enough :) )

PS: My name is Dreamora ;)


Bouncer(Posted 2004) [#29]
Works but I get jerky update... about once a sec the frame freezes... then a few good frames... then small freeze again. Just trying now to pinpoint the problem...

Hope I get this working correctly...


Bouncer(Posted 2004) [#30]
[EDIT]

the problem seems to only exist in windowed mode... weird..


Tom(Posted 2004) [#31]
Reasons BR may not have implemented DXT...

Could be there's more work involved when manipulating DXT compressed textures, something I've not looked at yet.

You guys get the short delay on converting to DXT? Like, 1-2 seconds? According to most people I've asked there shouldn't be a delay. It's actualy the blit from old surface to new DXT surface that it slows down.

They are cool though, save loads of vidmem!

Dreamora :) I wouldn't rely on it for any projects yet, too early. But give it some testing for sure.


Bouncer(Posted 2004) [#32]
Delay here while converting... maybe 1-2 secs as you said.
I have Radeon9600 if that helps any..


Beaker(Posted 2004) [#33]
Works fine here.


Tom(Posted 2004) [#34]
There are some delays when previewing DDS images before export in Photoshop, but mainly when you're previewing many different formats.

Having said that, the DDS file format looks easy to read/write.

LoadDDSTexture()
SaveDDSTexture()

Now to go learn how to read/write files in C++ :) (yes I'm serious LOL)


Dreamora(Posted 2004) [#35]
previewing DDS has another reason for delay: try on your own to create several mipmaps ;) [edit] up to 16 depending on the settings [/edit]

-> a reason loading of textures in Blitz3D is not really possible in realtime ;)


Dreamora(Posted 2004) [#36]
ding ding
how are things evolving? :)

really strange ... you can write surface stuff and compress textures but no idea of IO things? ;)


Tom(Posted 2004) [#37]
Yeh, figured out the IO stuff :) ... but once again things aint working on ATIs but they do on NVidia. I'm talking, an almost exact copy of loadDDS DX7 SDK code. What's with those cards? :)

Been a slow week, but added some blitting functions, DX Blt, BltFast, stretched blit, GDI blit, works with image or texture to image or texture.

Been messing with 'texGen' or 'automatic UV generation', kinda what spherical maps use to generate the UVs based on camera > vertex normals. However, using vertex position instead of normals, you can do a flat projection of a texture (think spotlight). So far I can only do it from the camera position, need to work out how to add in a transform matrix so you can project from elsewhere (a light position).

'Could' be useful in projecting a shadowmap onto geometry without the need to set all the UVs (transform them into light space), all done in hardware, so no slowdown.

Spoke to Mark on Irc and along with a few of the guys there, persueded him to reconsider releasing more information on Blitzs internals, he said he'd think about it again, so fingers crossed! :)


It's good fun, and I'm still learning! :)
Tom


Software Horizons(Posted 2004) [#38]
Excellent news! Can't wait to see what you cook up.


Dreamora(Posted 2004) [#39]
hmm ... "higherlevel ATIs" are not as old as the Blitz3D core. Perhaps this has some influence.

can't wait to see what is coming up :)


Bouncer(Posted 2004) [#40]
Sounds like great stuff Tom. There seems to be lot's of stuff you can do even with dx7...


Mustang(Posted 2006) [#41]
*BUMP* ...And how is this r-2-t progressing, Tom? :)