Projected Texture

Archives Forums/Blitz3D SDK Programming/Projected Texture

ninjarat(Posted 2007) [#1]
I'm looking to Project a texture through a world, like for a projected lightmap, or one of those circular drop shadows. Any ideas?


Dreamora(Posted 2007) [#2]
look in the code archives for fredborgs projection code, he did something like this for "volumetric light fake"


ninjarat(Posted 2007) [#3]
thanks!


ninjarat(Posted 2007) [#4]
Also, I would like to know... how do you do a line projection instead of a cone projection? Sorry, my 3D math knowledge isn't too developed.


Dreamora(Posted 2007) [#5]
you would just use one direction (projection point to "texture mid point") to project instead of calculate direction from the projection point to the current texture point in space.


ninjarat(Posted 2007) [#6]
I think i get it. Thanks. :)


ninjarat(Posted 2007) [#7]
So change this...

mesh=TReceiver.mesh
numsurfs=bbCountSurfaces(mesh)
For s=1 To numsurfs
	surf=bbGetSurface(mesh,s)
	numverts=bbCountVertices(surf)-1
	For vert=0 To numverts
		Select TTexProjector.mode
		Case PROJECT_CONE
			bbTFormPoint bbVertexX(surf,vert),bbVertexY(surf,vert),bbVertexZ(surf,vert),mesh,TTexProjector.entity
			
			x#=bbTFormedX()
			y#=bbTFormedY()
			z#=bbTFormedZ()
			
			dist#=Sqr(x*x+y*y+z*z)*TTexProjector.scale
			texu#=x/dist+.5
			texv#=1#-(y/dist+.5)
		Case PROJECT_LINE
			'currently not available
		End Select
		
		bbVertexTexCoords surf,vert,texu,texv
	Next
Next


to this...

mesh=TReceiver.mesh
numsurfs=bbCountSurfaces(mesh)
For s=1 To numsurfs
	surf=bbGetSurface(mesh,s)
	numverts=bbCountVertices(surf)-1
	For vert=0 To numverts
		bbTFormPoint bbVertexX(surf,vert),bbVertexY(surf,vert),..
		 bbVertexZ(surf,vert),mesh,TTexProjector.entity
		
		x#=bbTFormedX()
		y#=bbTFormedY()
		z#=bbTFormedZ()
		
		Select TTexProjector.mode
		Case PROJECT_CONE
			dist#=Sqr(x*x+y*y+z*z)*TTexProjector.scale
			texu#=x/dist+.5
			texv#=1#-(y/dist+.5)
		Case PROJECT_LINE
			texu#=x+.5
			texv#=1#-(y+.5)
		End Select
		
		bbVertexTexCoords surf,vert,texu,texv
	Next
Next


and it should work, right? :-/


ninjarat(Posted 2007) [#8]
Didn't work! Do you think you could help still?


ninjarat(Posted 2007) [#9]
I've tried everything I can think of. Is there some elusive B3D command I have to use for the math that I'm missing? The problem is, the light makes this weird plus effect, and some of the activity I just don't understand at all...

Here's the full code...
should be able to figure it out.