HDR control on an entity?

Blitz3D Forums/Blitz3D Programming/HDR control on an entity?

Guy Fawkes(Posted 2013) [#1]
Hi all. How can I make it so that I can make a glowing 3D, alpha-textured green grid from a plane like in Tron while controlling the intensity of the HDR for the grid?

Thank You!


Guy Fawkes(Posted 2013) [#2]
Gah, I can't find anything remotely close to "The Grid" from Tron... :(


Rob the Great(Posted 2013) [#3]
I honestly have no idea what you're looking for, but I remember a Tron sample that came with Blitz3d.

For your convenience, I have included it. Note that it has been modified so it doesn't need the start.bb file.:

smooth=True

Global info1$="Tron demo"
Global info2$="Features dynamic mesh creation"
Global info3$="Use arrow keys to steer, A/Z to zoom"

;Include "../start.bb"
Graphics3D 1024,768,0,2

grid_tex=CreateTexture( 32,32,8 )
ScaleTexture grid_tex,10,10
SetBuffer TextureBuffer( grid_tex )
Color 0,0,64:Rect 0,0,32,32
Color 0,0,255:Rect 0,0,32,32,False
SetBuffer BackBuffer()

grid_plane=CreatePlane()
EntityTexture grid_plane,grid_tex
EntityBlend grid_plane,1
EntityAlpha grid_plane,.6
EntityFX grid_plane,1

mirror=CreateMirror()

pivot=CreatePivot()

p=CreatePivot( p )
cube=CreateCube( p )
ScaleEntity cube,1,1,5
SetAnimKey cube,0
RotateEntity cube,0,120,0
SetAnimKey cube,60
RotateEntity cube,0,240,0
SetAnimKey cube,120
RotateEntity cube,0,0,0
SetAnimKey cube,180
AddAnimSeq p,180

For x=-100 To 100 Step 25
For z=-100 To 100 Step 25
e=CopyEntity( p,pivot )
PositionEntity e,x,5,z
Animate e
Next
Next
FreeEntity cube

trail_mesh=CreateMesh()
trail_brush=CreateBrush()
BrushColor trail_brush,255,0,0
BrushBlend trail_brush,3
BrushFX trail_brush,1
trail_surf=CreateSurface( trail_mesh,trail_brush )
AddVertex trail_surf,0,2,0,0,0
AddVertex trail_surf,0,0,0,0,1
AddVertex trail_surf,0,2,0,0,0
AddVertex trail_surf,0,0,0,0,1
AddTriangle trail_surf,0,2,3
AddTriangle trail_surf,0,3,1
AddTriangle trail_surf,0,3,2
AddTriangle trail_surf,0,1,3
trail_vert=2

bike=CreateSphere()
ScaleMesh bike,.75,1,2
PositionEntity bike,0,1,0
EntityShininess bike,1
EntityColor bike,192,0,255

camera=CreateCamera()
TurnEntity camera,45,0,0
cam_d#=30

light=CreateLight()
TurnEntity light,45,45,0

add_flag=False

While Not KeyHit(1)

	If KeyHit(17)
		wire=Not wire
		WireFrame wire
	EndIf
	
	If KeyDown(30) cam_d=cam_d-1
	If KeyDown(44) cam_d=cam_d+1
	
	turn=0
	If smooth
		If KeyDown(203) turn=5
		If KeyDown(205) turn=-5
		If turn
			add_cnt=add_cnt+1
			If add_cnt=3
				add_cnt=0
				add_flag=True
			Else
				add_flag=False
			EndIf
		Else If add_cnt
			add_cnt=0
			add_flag=True
		Else
			add_flag=False
		EndIf
	Else
		If KeyHit(203) turn=90
		If KeyHit(205) turn=-90
		If turn Then add_flag=True Else add_flag=False
	EndIf
	
	If turn
		TurnEntity bike,0,turn,0
	EndIf
	
	MoveEntity bike,0,0,1
	
	If add_flag
		AddVertex trail_surf,EntityX(bike),2,EntityZ(bike),0,0
		AddVertex trail_surf,EntityX(bike),0,EntityZ(bike),0,1
		AddTriangle trail_surf,trail_vert,trail_vert+2,trail_vert+3
		AddTriangle trail_surf,trail_vert,trail_vert+3,trail_vert+1
		AddTriangle trail_surf,trail_vert,trail_vert+3,trail_vert+2
		AddTriangle trail_surf,trail_vert,trail_vert+1,trail_vert+3
		trail_vert=trail_vert+2
	Else
		VertexCoords trail_surf,trail_vert,EntityX(bike),2,EntityZ(bike)
		VertexCoords trail_surf,trail_vert+1,EntityX(bike),0,EntityZ(bike)
	EndIf
	
	UpdateWorld
	
	PositionEntity camera,EntityX(bike)-5,0,EntityZ(bike)
	MoveEntity camera,0,0,-cam_d

;	PositionEntity camera,0,20,0
;	PointEntity camera,bike
	
	RenderWorld
	Flip

Wend
End



Guy Fawkes(Posted 2013) [#4]
Thanks, but I'm actually looking to make a "glowing grid". :)


Guy Fawkes(Posted 2013) [#5]
Here's my grid:



Now I simply want to make the grid glow with HDR. (High Definition Rendering).

This will require an object-by-object based HDR. In other words, an effect that you can apply to only 1 mesh at a time.


RemiD(Posted 2013) [#6]
I don't think HDR is the correct term for what you want, i think glow effect is the correct term.
See : http://www.gamasutra.com/view/feature/2107/realtime_glow.php

Here is one way to achieve a glow effect of some meshes :

before the mainloop :
create one quad mesh of the size of the screen for the "TextureScene", set it as child of the camera
create one texture "TextureScene" of the resolution of the screen or less.
create one quad mesh of the size of the screen for the "TextureGlow", set it as a child of the camera
create one texture "TextureGlow" of the resolution of the screen or less.
the quad mesh of the TextureGlow must be the nearest to the camera, on top of the quad mesh of the TextureScene

during the mainloop, instead of renderworld :
hide the 2 screen meshes
show all meshes/surfaces which must glow, set them to fullbright.
show all others meshes/surfaces, set their color to 000,000,000
render the scene
copyrect the screen to a temporary texture
apply a fast blur routine on the texture so that the colors "bleed"
copyrect the screen to the texture "TextureGlow"
show all meshes/surfaces which must glow, set them to normal
show all others meshes/surfaces, set their color to 255,255,255
render the scene
copyrect the screen to the texture TextureScene
show the 2 screen meshes

Now play with the blendmodes and see the magic happens :)

Note : a way to avoid to have to use a fast blur routine, is to choose a width and height for the TextureGlow inferior to those of the TextureScene.

there is fast blur routine somewhere on the forum but i don't know where it is, by sswift i think...
Also there is a fast blur routine with FastExt but it is not precise enough so it is ugly, see :
http://blitzbasic.com/gallery/view_pic.php?id=2347&gallery=&page=7


Guy Fawkes(Posted 2013) [#7]
Hi, RemiD. I don't want the whole screen to glow, just the object.

Thank You!


RemiD(Posted 2013) [#8]
That's exactly what i have explained...
That's why 2 renders are required, one render for the glowing meshes/surfaces, one render for the "normal" meshes/surfaces.


Guy Fawkes(Posted 2013) [#9]
Hi, RemiD. Ok.

Now, I'm gonna go through a checklist with you as I create the code, to make sure I'm doing it right.

Here's my checklist so far & the code:



See where the "???" is?

How do I do this line in code?

Thank You!


RemiD(Posted 2013) [#10]
About the quad, it is not as simple as that to do...
I suggest that you try to make the effect with images instead of textures and quads, so that you understand the concepts, but it will be too slow for games...
or
easier solution : find the example by sswift, it is somewhere on the forum, i have read it a few years ago.



;the quad mesh of the TextureGlow must be the nearest To the camera, on top of the quad mesh of the TextureScene


By this i mean that the quad with the TextureGlow must be the nearest from the Camera and the quad with the TextureScene must be the farest (if that's a word) from the camera.
example
quad TS is at 0,0,1.0
quad TG must be at 0,0,0.999 or something like that.


I don't have time to help you to code this, read the article here :
http://www.gamasutra.com/view/feature/2107/realtime_glow.php
and do it by yourself.


Also i think that it is possible to achieve this effect with shaders, but Blitz3d can't help you with this, maybe the nuclear 3d engine ?


RemiD(Posted 2013) [#11]
To do a fast blur effect on the texture : http://blitzbasic.com/codearcs/codearcs.php?code=754