How High

Blitz3D Forums/Blitz3D Programming/How High

JBR(Posted 2004) [#1]
Hello, I have a square tiled landscape with each square 2 tris. I have many particles above and many shadows on the landscape. To get the height of the shadow I decide which tris the particle is above and then treat that tris as a plane and get the height. This works very well for smooth undulating landscapes but is not perfect.

It has to be fast so the shadow is just a quad placed at the height found.

I was wondering if there are better ways to create shadows?

Thanks
Marg


Abomination(Posted 2004) [#2]
are Your shadows directly under the particles, or is the light cast at an angle?


Stevie G(Posted 2004) [#3]
Marg,

The way I created full black shadows for virus remake was by overlaying a texture on the landscape and adjusting u,v for each vertice.

Pseudo Code

Create a texture, multiply blend
Create a shadowcamera using ortho view mode
Set cameraclscolor to 255,255,255.
Use a cameraviewport the same size as the texture
Point shadowcamera at the landscape from high above
{you'll need to fiddle with the height}
Hide all light
Hide the landscape.
Renderworld()
Copyrect the cameraviewport to the texture

I've been working on the game for the last few days but can send you some working code if you want?

Stevie


JBR(Posted 2004) [#4]
Abomination, yes shadows are just directly below.(no lights)

Stevie G, sounds a bit beyond me at the moment, I'll investigate but if you have the time a bit of code would be nice.

Thanks
Marg


Abomination(Posted 2004) [#5]
Unless I misunderstand what You are trying to do:
You don't need to bother with height.
The x- and z-positions of the objects will be the x- and z-positions of their shadows on the landscape. So the y-vector of that position is the height of the shadow. Or You could just shade its tile.


JBR(Posted 2004) [#6]
Abomination, what would be the best way to get the y-vector. I'm fairly new to 3d; is there a built in way to calculate this?

Marg


Abomination(Posted 2004) [#7]
I'm asuming the shadows are shadows cast on to the landscape, and not in mid-air.
So any object will have a shadow on its own x-z-coordinates.
The y-coordinate wil be the y coordinate of the tile that occupies that x-y-position.

Or perhaps You are doing something quite different?


JBR(Posted 2004) [#8]
Thanks Abomination that's pretty much what I'm doing.
Marg


JBR(Posted 2004) [#9]
Stevie, If I understand you right is this what you are doing?

Take a plan view of anything which will cast a shadow.
Copy this to a texture.
When drawing the landscape draw the alpha'd texture aswell as the 'normal' colours.

To do this, do you use AddVertex with u,v or maybe VertexTexCoords with u,v?
Do you need an EntityFX to force the use of the blending the texture?

Your method, if I understand it seems a lot simpler than doing a lot of clipping. What size of texture did you use for Zarch and was there a performance hit?

Basically, I'd like to know how you set up the texture and how you combine it with your landscape?

Thanks
Marg


Stevie G(Posted 2004) [#10]
Here are some snippets which will hopefully help.

This sets up the shadow camera. You'll have to play with the camerazoom to get the view to completly fill the viewport.

shadow_cam=CreateCamera()
shadow=CreateTexture(256,256,48)
TextureBlend shadow,2
CameraViewport shadow_cam,0,0,256,256
PositionEntity shadow_cam,0,2000,0
CameraRange shadow_cam,1,2000
RotateEntity shadow_cam,90,0,0
CameraProjMode shadow_cam,2
CameraClsColor shadow_cam,255,255,255
camerazoom shadow_cam,.0105


This updates the shadow each frame where grid is the landscape. Note I'm not using any lights other than ambient. If you have any others you will have to hide them before renderworld().

Function update_shadow()

	ShowEntity shadow_cam
	HideEntity player_cam
	HideEntity grid
	AmbientLight 0,0,0
	RenderWorld()
	CopyRect 0,0,256,256,0,0,BackBuffer(),TextureBuffer(shadow) 
	HideEntity shadow_cam
	ShowEntity player_cam
	ShowEntity grid
	AmbientLight 255,255,255
		
End Function


This is the terrain update function - note how 'tu' and 'tv' are constantly adjusted.

Function update_terrain()

	FreeEntity pivot:pivot=CreatePivot()
			
	ax#=Floor(player(cam)\x):az#=Floor(player(cam)\z)
	fx#=(player(cam)\x) - ax:fz#=(player(cam)\z) - az  
		
	For z=-divs To divs+1 
		For x=-divs To divs+1
		
			;grid positions
			nx#=qwrap(ax+x,size) 
			nz#=qwrap(az+z,size) 
			
			;vertex positions
			vy#=terrain(nx,nz)\height
			vx#=qlimit( x-fx,-divs,divs)
			vz#=qlimit( z-fz,-divs,divs)
											
			;shadow texture coords
			tu#=.5+(vx/divs)*.5 + (.5/512.0)
			tv#=.5+(vz/divs)*.5 + (.5/512.0)
					
			;If point on edge of grid smooth height	
			If divs < 18
				If Abs(vx)=divs Or Abs(vz)=divs Then vy#=get_height( player(cam)\x+vx , player(cam)\z+vz)
			EndIf
			
			;vertex positions	
			x1 = ( x + divs ) * 2 - ( x > -divs )
			z1 = ( z + divs ) * 2 - ( z > -divs )
			
			For iz = 0 To ( z > -divs And z < divs+1 )
				For ix = 0 To ( x > -divs And x < divs+1 )
					x2 = x1 + ix:z2 = z1 + iz    
					v=x2+z2*(divg+1)
					VertexCoords surf,v, vx * scale , vy , -vz * scale
					VertexTexCoords surf,v,tu,tv
				Next
			Next
					
			;vertex colours
			If x < divs+1 And z < divs+1
				x1 = ( x + divs ) * 2 
				z1 = ( z + divs ) * 2 	
				For iz = 0 To 1 
					For ix = 0 To 1
						x2 = x1 + ix:z2 = z1 + iz
						v=x2+z2*(divg+1)
						VertexColor surf,v,terrain(nx,nz)\r,terrain(nx,nz)\g,terrain(nx,nz)\b 
					Next
				Next
			EndIf
								
		Next	
	Next
	
End Function


Hope this helps you. Give me a shout if your unsure of anything. Oh.. and using the textureflag + 256 should speed up the copyrect process for you - it doesn't do anything for me and a lowly gf2.

Stevie


JBR(Posted 2004) [#11]
Thanks Stevie, I have a 1024 by 1024 shadow 'map' on my landscape and it looks pretty good.

Marg


Stevie G(Posted 2004) [#12]
I think it's kind of slow on mine. You must be running it in a pretty high resolution and have a cameraviewport 1024x1024?


JBR(Posted 2004) [#13]
I had it at 1280 by 1024 screen, but I've cut it down to 512 by 512 shadow so I can use smaller screens. 800 by 600 upwards.

Marg


Rook Zimbabwe(Posted 2004) [#14]
Just to be obtuse:

Hao Hi is a mountain in China

I would just bake them in to the colormap.