Please Test! render2texture & DDS CopySurface

Blitz3D Forums/Blitz3D Userlibs/Please Test! render2texture & DDS CopySurface

Hi all,

BACKUP IMPORTANT WORK BEFORE USING!

Here's a beta version of my Render 2 Texture and a new CopySurface() that works with .dds textures.

Sample source included, please post feedback/bugs and GFX card specs!!!

It requires you install a userlib. Unpack the DX7DLL_8thAug06 ZIP into Blitz3D\Userlibs\ (there should be dx7test.dll and dx7test.decls in there)

Sorry if you were using a previous version of this DLL and it messes up existing projects, but this version is a lot more refined (read: less hacky! :)

http://www.tomspeed.com/beta/

Notes: Blitting TO a DDS texture is slower than blitting to a normal texture, although blitting FROM DDS textures is quick.

CopySurface() works with regular Blitz3D textures too, though for some strange reason DX says blitting from a regular masked or Alpha B3D texture is unsupported (huh?)

Have fun and see if you can break the new functions!

Cheers
Tom

GeForce 7800 GTX:


1 - Simple Render to Texture.bb
Worked! Fps 450-500+

2 - RT Performance.bb
Bombed! Got "Function 'createrendertexture' not found"

3 - EndGraphics.bb
Worked! Memory usage was constant after pressing "space" - which "reset" the scene perfectly. Mouse button stuff worked too.

4 - Using a quad mesh and RT for screen FX.bb
Worked! Took me a while to "get" what "space" does...


CopySurface DDS.bb
[edit] Worked! Duh... can I be so dum... after installing 1.97 it worked MUCH better :)

hehe yeh, 4 isn't obvious if the quad is perfectly lined up.

2 is my fault, I forgot to change references to CreateRenderTexture to UserRenderTexture in the source, I'll update it now :)

This is a work machine not a 3D graphics monster but thought I'd try anyhow. I'll post a Radeon X1600 PRO report tonight.

1 - Simple Render to Texture.bb
35 FPS

2 - RT Performance.bb
<edit> 34 FPS

3 - EndGraphics.bb
35 FPS

4 - Using a quad mesh and RT for screen FX.bb
28 FPS

GFX: Intel 82865G

Hi Tom,

another great work!

1 - Simple Render to Texture.bb
Worked!

2 - RT Performance.bb
Worked!

3 - EndGraphics.bb
Worked!

4 - Using a quad mesh and RT for screen FX.bb
Worked!

CopySurface DDS.bb
Copy surface 1 brings texture errors
Copy surface 2 works fine!

Thank you for your hard work!

ATI Radeon 9100 64 MB VRAM / Win98se

What's this stuff for? Is it purely for doing what we can already do, but with a DDS?

You cannot currently render to a texture.

Puki: Normaly when you call RenderWorld() everything is drawn to the backbuffer, the backbuffer being a 'render target'.

Now, hardware permitting, you can create a texture that you can set as a render target, then when you call RenderWorld() it draws the scene directly to the texture.

If you had code that done this:

RenderWorld()
CopyRect 0,0,800,600,0,0,BackBuffer(),TextureBuffer(myTexture)

You could replace it with:
SetRenderTarget myTexture
RenderWorld()

It's a lot quicker


And CopySurface() is primarily if you want to copyrect using DDS textures, as Mark hasn't enabled it at this time.

This thing seems to clash with vardx7 decls and dll so I removed them.

Right, looks like I am going to add in mirrors to Oblivion then - Bethesda didn't have mirrors.

Hi Tom,

1 - Simple Render to Texture.bb
796 FPS - runs fine.

2 - RT Performance.bb
270-814 FPS - runs fine too!

3 - EndGraphics.bb
Worked too!

4 - Using a quad mesh and RT for screen FX.bb
525-745 FPS. runs fine too!

CopySurface DDS.bb

Copy surface 1 brings artifact errors
Copy surface 2 works pretty fine.

Tom, i think you should teamup with BRL to kick B3D to its real limits!!


All tests performed on my work/game machine. details see sig.

oops, i found out that the old dx7dll works fine with EnableAnisotropic. The new one doesn't.

Radeon 9800 Pro 128 megs

1 - Simple Render to Texture.bb
280-310 FPS

2 - RT Performance.bb
280 FPS

3 - EndGraphics.bb
270 FPS

4 - Using a quad mesh and RT for screen FX.bb
200 FPS

CopySurface...worked fine on 2 but got some artifacts on 1

Great stuff...Thanks for all your hard work....now all I've got to do is to work out what I'm supposed to do with it!! :)

Pleased that Mustang has finally got what he wanted :)


Pleased that Mustang has finally got what he wanted :)



:)) Last few days have been very good to me, can't deny that!

But there are still tangent space normalmaps and shadows (stencils, whatever) on my wishlist. After those I'm out of ideas... and can't blame the tools anymore for not finishing my game ;P

nvidia 5700 256 mb

1 - Simple Render to Texture.bb
works

2 - RT Performance.bb
works

3 - EndGraphics.bb
works

4 - Using a quad mesh and RT for screen FX.bb
works

CopySurface...
works

mongia

Hi,

All is working on the laptop, very cool!

For the EndGraphics thingie, you can use clearworld as well. Like this:
; Render to Texture Demo #3
;
; How to handle resetting the Graphics3D system (ClearWorld)

Graphics3D 1024,768,32,2


;Jump back to here when user hits SPACE
.NewScene

; Clear all entities and textures and brushes
ClearWorld True,True,True

;If using this DLL, *always* call this function before calling EndGraphics()
;This is needed because the variables returned from SystemProperty$() change
;each time Graphics3D is called!
RemoveSystemProperties()

;Must let the DLL know a few things about Blitz3D!
d3d=SystemProperty$("Direct3D7")
dev7=SystemProperty$("Direct3DDevice7")
draw7=SystemProperty$("DirectDraw7")
hwnd=SystemProperty$("AppHWND")
instance=SystemProperty$("AppHINSTANCE")
If SetSystemProperties(d3d,dev7,draw7,hwnd,instance) RuntimeError "Error setting 1 or more System Propertys!"

;Does hardware support Renderable Textures?
If Not SupportsRenderTexture() RuntimeError "Ho hardware support for Renderable Textures"


; Camera.. Light(s).. Action!
cam=CreateCamera()
PositionEntity cam,0,2,-7
CameraRange cam,.5,100
CameraClsColor cam,100,120,200

light=CreateLight()
TurnEntity light,-50,0,0



;---------------------------
;Create a Renderable Texture
;---------------------------

;Let the DLL know the *NEXT* texture being created should be one
;we can use as a Render Target
UserRenderTexture


;Create a Renderable Texture, MUST HAVE +256 in flags (256 = Local Vid Mem)
;Texture Size must be ^2 (128,256,512 e.t.c), it doesn't *have* to be the same
;size as the Graphics Viewport though!
texSize=512
tex=CreateTexture(texSize,texSize,256+1)


;By default, a Render Texture is created without a Z-Buffer, but you can add one using..
AddZBuffer tex


;This cube will use the Render Texture
cube=CreateCube()
EntityTexture cube,tex
sky=CreateSphere(32)
FlipMesh sky
EntityColor sky,130,180,220
ScaleEntity sky,50,50,50


; Sexeh checkered ground!
ground=CreateCube()
ScaleEntity ground,50,.1,50
EntityFX ground,1
groundTex=CreateTexture(512,512,1+8)
ScaleTexture groundtex,.1,.1
;ScaleTexture groundTex,.025,.025
SetBuffer TextureBuffer(groundtex)
Color 140,25,0
Rect 0,0,255,255,True
Rect 256,256,255,255
Color 200,160,0
Rect 256,0,255,255,True
Rect 0,256,255,255,True
SetBuffer BackBuffer()
EntityTexture ground,groundTex
PositionEntity ground,0,-1.5,0
Color 0,0,0


fps=0
counter=0
timer=MilliSecs()
MoveMouse GraphicsWidth()*.5,GraphicsHeight()*.5
While Not KeyDown(1)
	t=MilliSecs()


	If KeyHit(2)
		texSize=texSize/2
		If texSize<4 Then texSize = 4
		FreeTexture tex
		UserRenderTexture
		tex=CreateTexture(texSize,texSize,256+1)
		AddZBuffer tex
		EntityTexture cube,tex
	Else If KeyHit(3)
		texSize=texSize*2
		If texSize>2048 Then texSize = 2048
		FreeTexture tex
		userRenderTexture
		tex=CreateTexture(texSize,texSize,256+1)
		AddZBuffer tex
		EntityTexture cube,tex
	End If
	
	If MouseDown(2) TurnEntity cube,0,0,.05
	v#=.005
	If KeyDown(42) v=.0005
	If KeyDown(30) MoveEntity cam,-v,0,0
	If KeyDown(32) MoveEntity cam,v,0,0
	
	If KeyDown(17) MoveEntity cam,0,0,v
	If KeyDown(31) MoveEntity cam,0,0,-v
	
	If KeyHit(57) Goto NewSCene
	RotateEntity cam,180+MouseY()*.5, -(MouseX()-500)*.5,0


	If MouseDown(1)=False
	
		;Set the Render Texture as the target surface RenderWorld will render to
		SetRenderTarget tex
	
		;Disable Color Clearing, useful for mirror in mirror effects
		CameraClsMode cam,0,1
	
		;Set the viewport to same size as the render texture
		CameraViewport cam,0,0,TextureWidth(tex),TextureHeight(tex)
	
		;Render scene to Texture
		RenderWorld
	
		;Set the render target back to the old render target (the BackBuffer())
		RestoreRenderTarget
		CameraViewport cam,0,0,GraphicsWidth(),GraphicsHeight()
		CameraClsMode cam,1,1
	End If
	

	;Render the scene normaly
	RenderWorld

	;Update FPS counter
	counter=counter+1
	If MilliSecs() - timer > 999
		fps=counter
		counter=0
		timer=MilliSecs()
	End If


	Text 0,0,"FPS: "+fps
	Text 0,12,"w,s,a,d, mouse to move, Left Shift to move slowly, RMB turns cube, LMB disables Render to Texture"
	Text 0,24,"Texture Size (1,2 adjusts): "+texSize+"x"+texSize
	Text 0,36,"Free Video Memory: "+AvailVidMem() / 1024
	Text 0,50,"Hit SPACE to restart Graphics3D system"

	Flip 0
Wend
End


1 - Simple Render to Texture.bb
310 FPS

2 - RT Performance.bb
286 FPS

3 - EndGraphics.bb
266 FPS

4 - Using a quad mesh and RT for screen FX.bb
206 FPS

Radeon X1600 PRO

nvidia 6600GT 128Mb - Athlon64 3500+

1 - Simple Render to Texture.bb
486 FPS

2 - RT Performance.bb
449 - 565

3 - EndGraphics.bb
Ok

4 - Using a quad mesh and RT for screen FX.bb
Ok

CopySurface...
OK
Pressing 1 - 'real time' copy
Pressing 2 - a little lag - about .5 second

Great Job!

Intel integrated 852/855 (laptop):


1 - Simple Render to Texture.bb
Worked! Fps 20 (debug on)

2 - RT Performance.bb
Worked!

3 - EndGraphics.bb
Worked!

4 - Using a quad mesh and RT for screen FX.bb
Worked!


CopySurface DDS.bb
Worked!

looking good!

Check my thread in Blitz3D programming for a cute bump mapping demo :)

Okey-dokey.

What thread?

I think I can make Blitz3Ds own environment maps renderable too, then you can bypass the copyrect step when doing realtime cubemaps.

Puki: Shhh!

What about those stencil shadows you were working on? I need those too.

All four examples worked OK on GF1 GTS 32 MB / P4 2.4 / 512MB / WIN XP

And... thanks Tom for all your efforts...

Cheers!

All fully working

GeForce FX5200, normally around 90 - 50FPS

Ati 9600 pro 128mb
P4 2.66ghz

everything works great :) nice work!

yes! yes! yes! yes! and yes! :)

ati radeon ve/win98se

ps: texture sizes over 1024 caused a MAV.

R2T Performance:

- 265 FPS windowed
- 430 FPS fullscreen

EndGraphics:

- Works, no problem here

Quad Mesh FX:

- 200-210 FPS windowed
- 295-305 FPS fullscreen

Textures at 2048 no problem (muk: thats no wonder, your card does not support more than 1024x1024)


System: Core Duo T2500, NVidia 7600 Go 256MB settings on max quality


PS: Amazing work ones again Tom :-)

I'd need this, but the link is dead... Can anyone provide a download link for this please?

edit: Just discovered FastExt. :) ...

Thanks and regards - Xaron