Double RenderWorld

Blitz3D Forums/Blitz3D Programming/Double RenderWorld

Yue(Posted 2014) [#1]
Where I can discover an example of double render.

Anyway, I need to implement the DOF effect, but entities do not look good transparency (GUI Menu), and have told me that with a double RenderWorld can solve the problem.

A greeting.


RemiD(Posted 2014) [#2]
Take a look at Copyrect() and DrawImage().

What i do :
I hide all meshes
I show some meshes
Renderworld()
Copyrect(0,0,GraphicsWidth(),GraphicsHeight(),0,0,BackBuffer(),ImageBuffer(Image))

i do others render and others copyrect to others images if necessary (it can be useful for a glow effect, or to render the scene in several passes so that you can see far without zorder problems, or to display a GUI above a 3d scene, or to have several views of the 3d scene).

then for each Image
DrawImage(Image,0,0)


Yue(Posted 2014) [#3]
Hello I'm trying and not working.


Text3D ("Text"); Lib Draw3D2
RenderWorld
; DOF Here
clear3D()
Flip



Any tips?


RemiD(Posted 2014) [#4]
I am not sure what you are trying to do so i don't know if what i have explained can help you.

The idea is to have several images with the same width and height of the screen resolution.

Then you hide all meshes.

You show some meshes that you want to render.

Then renderworld

Then copyrect what has been drawn on the backbuffer in one image with copyrect

Then do others renders and others copyrects to others images as much as you need.

Then you draw one image on top of another with drawimage, the black pixels will not be displayed and so this will allow to have several layers.

Also if you want transparency for the GUI you need to to use several textures instead of images, and several textured quads, one on top of the other (position or entityorder), one for each layer.


RGR(Posted 2014) [#5]
; QuadRenderCams.bp
Function QuadRenderCams(PlayerCam, CountTrianglesRendered=0)
	UpdateWorld()
	HideEntity QuadCamera
	ShowEntity PlayerCam
	RenderWorld()
	If CountTrianglesRendered=1
		QuadRenderedTris=TrisRendered()
	EndIf
	HideEntity PlayerCam
	ShowEntity QuadCamera
	RenderWorld()
	If CountTrianglesRendered=1
		QuadRenderedTris=QuadRenderedTris+TrisRendered()
	EndIf
	ShowEntity PlayerCam
End Function
;!
;* Quad\QuadGlobals.bbg


The QuadCam is positioned at 100000,0,0 ... QuadCamera, QuadRenderedTris are Globals ... make sure the CameraRanges do not overlap
This is one Function of a 140 Functions Set of postioning, scaling and displaying pixelperfect Images, Text, Animations on different layers in front of the QuadCamera ...
So you have 2 virtual worlds. A main 3DWorld and a second 3DWorld (100000 meters away) displaying HUD, and Effects in front of your main world.

Don't know if it's what you where looking for.


Yue(Posted 2014) [#6]
I appreciate the patience in the matter, for now I'm trying to grasp the concept of double-render. Where the idea is to maintain proper transparency in the GUI when the DOF enabled, but still do not understand this very well, I could give an example CopyRect please would be the most reliable way to learn.

On the other hand I do not understand that the RGR our friend code, if so I always have something new to learn.

Graphics3D 800,600,32,2
SetBuffer BackBuffer()

Local PlayerCam% = CreateCamera()
CameraRange PlayerCam%, 1,10000

Cubo% = CreateCube()
Luz%  = CreateLight()

Global  QuadCamera = CreateSphere()

PositionEntity QuadCamera%,-3,0,0
PositionEntity PlayerCam%,0,0,-10


Repeat 
	
	
	
	
	
;	RenderWorld 
;	Flip 
	QuadRenderCams(PlayerCam%,10000)
	
	
	
Until KeyHit(1)












Function QuadRenderCams(PlayerCam, CountTrianglesRendered=0)
	UpdateWorld()
	HideEntity QuadCamera
	ShowEntity PlayerCam
	RenderWorld()
	If CountTrianglesRendered=1
		QuadRenderedTris=TrisRendered()
	EndIf
	HideEntity PlayerCam
	ShowEntity QuadCamera
	RenderWorld()
	If CountTrianglesRendered=1
		QuadRenderedTris=QuadRenderedTris+TrisRendered()
	EndIf
	ShowEntity PlayerCam
End Function


The sphere disappears ...


RGR(Posted 2014) [#7]
No ... QuadCamera is no sphere ... it is a second Camera which is positioned x=100000 y=0 z=0
You can create a sphere and position it at x=100000 y=0 z=30 and see what happens

After QuadRenderCam(PlayerCam%) ; only one parameter because you do not need to know the rendered triangles
you must Flip()

The PlayerCam shows a Terrain or plane with some qubes or whatever your scene includes ...
The QuadCam in your (fixed) example will show the sphere or Sprite with text or so ...

In case you need it, I'll put a small example together ... busy at present


Yue(Posted 2014) [#8]
I could use one example, is the most intuitive way to learn.

The problem I have is that when you turn the DOF effect, the transparency of the GUI objects are affected by the DOF, so they are above other objects, such as sky and models of the scene.

Ok Corrigo and what the camera and put a sphere, I am slowly understanding the concept of double render.

One question is, this affects performance?


Yue(Posted 2014) [#9]
Graphics3D 800,600,32,2
SetBuffer BackBuffer()

Local PlayerCam% = CreateCamera()
CameraRange PlayerCam%, 1,10000


Cubo% = CreateCube()
Luz%  = CreateLight()

Global  QuadCamera = CreateCamera()
PositionEntity QuadCamera,-1000,0,0
CameraRange QuadCamera,1,10000

PositionEntity QuadCamera%,-1000,0,-10
PositionEntity PlayerCam%,0,0,-10



Esfera% = CreateSphere()
PositionEntity Esfera%,-1000,0,10

Global QuadRenderedTris 


Repeat 
	
	
	
	
	QuadRenderCams(PlayerCam%,100)
	
	Flip 
	
Until KeyHit(1)




Function QuadRenderCams(PlayerCam, CountTrianglesRendered=0)
	UpdateWorld()
	HideEntity QuadCamera
	ShowEntity PlayerCam
	RenderWorld()
	If CountTrianglesRendered=1
		QuadRenderedTris=TrisRendered()
	EndIf
	HideEntity PlayerCam
	ShowEntity QuadCamera
	RenderWorld()
	If CountTrianglesRendered=1
		QuadRenderedTris=QuadRenderedTris+TrisRendered()
	EndIf
	ShowEntity PlayerCam
End Function


I put a cube and a sphere, and just visualize the cube, not endiendo what happens.


Guy Fawkes(Posted 2014) [#10]
nice :)


Yue(Posted 2014) [#11]
@RedimD, This is correct?, At least I think, but I need the rotating cube does not affect the command to put everything in gray scale.

Graphics3D 800, 600, 0, 2



Include "include\FastExt.bb"
initExt()

CreateLight()

pivot = CreatePivot()

For i = 0 To 10
	
	cube = CreateCube(pivot)
	PositionEntity cube, Rnd(-5, 5), 0, Rnd(-5, 5)
	EntityColor cube, Rand(255), Rand(255), Rand(255)
	
Next

camera = CreateCamera()
CameraRange camera,0.1,50000

MoveEntity camera, 0, 0, -15

keystone = CreateCube()
FlipMesh keystone
PositionEntity keystone, 0, 2, -15
EntityParent keystone, camera
ScaleEntity keystone, 10, 10, 10
EntityFX keystone, 1

Cubo% = CreateCube()
PositionEntity Cubo%,0,0,-10
EntityColor cubo%,128,0,0

tex = CreateTexture(512, 512)
Repeat
	
	TurnEntity Cubo%,1,1,1
	
	HideEntity keystone
	HideEntity Cubo%
	ShowEntity pivot
	RenderWorld()
	
	CopyRect 144, 44, 512, 512, 0, 0, BackBuffer(), TextureBuffer(tex)
	EntityTexture keystone, tex
	ShowEntity Cubo%
	ShowEntity keystone
	
	HideEntity pivot
	RenderWorld()
	
	If KeyDown(200) Then TurnEntity keystone,  1, 0, 0
	If KeyDown(208) Then TurnEntity keystone, -1, 0, 0
	If KeyDown(203) Then TurnEntity keystone,  0, -1, 0
	If KeyDown(205) Then TurnEntity keystone,  0, +1, 0
	
	Text 0, 0, "use cursor keys to turn cube"
	
	
	RenderPostprocess Fe_grayscale
	Flip
	
	
	
Until KeyHit(1)

End



RemiD(Posted 2014) [#12]

The problem I have is that when you turn the DOF effect, the transparency of the GUI objects are affected by the DOF, so they are above other objects, such as sky and models of the scene.


Ok, if i understand correctly, in this case i would :
Have 2 quads, 2 textures,
one quad with one texture to copyrect the render of the 3d world with all the effects
one quad with one texture to copyrect the render of the GUI
Do 3 renders
One render for the 3d world
One render for the GUI
One render of the textured quads, one on top of the other with specific alpha value (depending on the transparency you want)
Remember that you can position the quads at the same position and use EntityOrder to display one on top of the other (for the last render)

Do some tests, search the forum for some code examples, reread this, i am sure that you will understand.


Yue(Posted 2014) [#13]
you're turning me into a crazy XD. Ok, here I will continue doing my brain a little bigger. :).

all have something to learn, the problem is not when it stops.


Yue(Posted 2014) [#14]
Yesss!, Powerful.
Problem!


Fix!


Jo jo jo XD.


RGR(Posted 2014) [#15]
Graphics3D 0,0,32,1

Camera = CreateCamera()
CameraRange Camera, 1,10000
PositionEntity Camera, 0,0,-100,True


Cube% = CreateCube()
Luz%  = CreateLight()


Global QuadCamera = CreateCamera()
PositionEntity QuadCamera,100000,0,0
CameraRange QuadCamera,1,10000
HideEntity Quadcamera
CameraClsMode(QuadCamera,0,1)

; Load texture
tex=LoadTexture( "b3dlogo.jpg" )

ScaleEntity Cube, 50,5,50, True
PositionEntity Cube, 0, 0, 30, True
; Texture cube
EntityTexture cube,tex

; Set initial uv scale values
u_scale#=1
v_scale#=1




Cube2 = CreateCube()
PositionEntity Cube2,100000,0,10
EntityColor Cube2, 100,200,10

Global QuadRenderedTris 


Repeat 
	
	TurnEntity cube,0.1,0.1,0.1
	TurnEntity cube2,-0.1,-0.1,-0.1
	
	If KeyDown( 208 )
		MoveEntity Camera, 0,0,0.5
	EndIf
	If KeyDown( 200 )
		MoveEntity Camera, 0,0,-0.5
	EndIf
	If KeyDown( 203 )
		MoveEntity Camera, 0.5,0,0
	EndIf
	If KeyDown( 205 )
		MoveEntity Camera, -0.5,0,0
	EndIf
	

	QuadRenderCams(Camera)
	
	Flip(True)
	
Until KeyHit(1)

End


Function QuadRenderCams(PlayerCam, CountTrianglesRendered=0)
	UpdateWorld()
	HideEntity QuadCamera
	ShowEntity PlayerCam
	RenderWorld()
	If CountTrianglesRendered=1
		QuadRenderedTris=TrisRendered()
	EndIf
	HideEntity PlayerCam
	ShowEntity QuadCamera
	RenderWorld()
	If CountTrianglesRendered=1
		QuadRenderedTris=QuadRenderedTris+TrisRendered()
	EndIf
	ShowEntity PlayerCam
End Function


The Image is in your local Blitz3D Folder (Blitz3D\help\commands\3d_examples\media\)

What I had not mentioned before: Most important is CameraClsMode(QuadCamera,0,1)
Then the first render is kept and the Screen is not cleaned!


Yue(Posted 2014) [#16]
RGR, I appreciate your help, I have to always learn something from someone else, but I commented that I could not properly configure the DOF you have any suggestions?.

This is with CopyRect.




RGR(Posted 2014) [#17]
You needed an example for double render and I think you got it.
How this can be used for DOF effects as you suggested in your first post I'm sorry, I don't know.
RemiD gave an instruction for triple render above. You would need to add a third Camera. Easy to be done.
Actually you can use one camera and move it where you need it before each render. I personally prefere to use multiple cameras.
Anyway, when you use CopyRect on the screen, the multiple Renders of 3D-Scenes may not be needed.


RemiD(Posted 2014) [#18]
2 others important things :
The quad mesh size, the UV coords of each vertex of the quad mesh, the texture size must tweaked so that the image is not stretched.
If i remember correctly, you can disable mipmapping so that the textures on the quad meshes do not look blurred.


Yue(Posted 2014) [#19]
Well, the new problem is that when changing resolution texture within the quad is bigger and only a portion is displayed.

Screen resolution 800 x 600
CopyRect 144.44 ...

I put values a screen resolution of 1024 x 768 and 1280 x 800, can not understand those values.

A greeting.


Yue(Posted 2014) [#20]
@RGR

RGB, between the two methods apparently have already gained a better understanding that you have raised and loved me as I have no problems with changing the resolution, just as it was very good to learn both RemiD as you, but yours is the that is more comfortable for my needs.

Thanks for the help of the two. :)