Projected Texture

Blitz3D SDK Forums/Blitz3D SDK Programming/Projected Texture

I'm looking to Project a texture through a world, like for a projected lightmap, or one of those circular drop shadows. Any ideas?

look in the code archives for fredborgs projection code, he did something like this for "volumetric light fake"

thanks!

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.

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.

I think i get it. Thanks. :)

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? :-/

Didn't work! Do you think you could help still?

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.

Import Blitz3D.Blitz3DSDK
Import BRL.Math

'Texture Projection (beta) BlitzMax Blitz3D SDK Addon
'by ninjarat

'Thanks to FredBorg's awesome example.

Const PROJECT_CONE=1
Const PROJECT_LINE=2

Private
	Type TReceiver
		Global mesh
	End Type
	
	Type TTexProjector
		Global entity
		Global texture
		Global mode
		Global scale#
		Global r#,g#,b#
	End Type
Public

Function InitTexProjector(texfile$,blend=1)
	bbClearTextureFilters
	
	TTexProjector.texture=bbLoadTexture(texfile,1+8+16+32)
	bbTextureBlend TTexProjector.texture,blend
End Function

Function FreeTexProjector()
	If TTexProjector.texture Then bbFreeTexture TTexProjector.texture
	TTexProjector.texture=Null
End Function

Function SetTexReceiver(mesh,texlayer=1)
	TReceiver.mesh=mesh
	bbEntityTexture TReceiver.mesh,TTexProjector.texture,0,texlayer
End Function

Function SetTexProjectorParams(entity,scale#=.75,projmode=PROJECT_CONE,r#=255,g#=255,b#=255)
	TTexProjector.entity=entity
	TTexProjector.scale=scale
	TTexProjector.mode=projmode
	
	TTexProjector.r=r
	TTexProjector.g=g
	TTexProjector.b=b
End Function

Function TexProjectorUpdate()
	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.5-y/dist
			Case PROJECT_LINE
				texu#=(x*TTexProjector.scale)+.5
				texv#=1.5-(y*TTexProjector.scale)
			End Select
			
			bbVertexTexCoords surf,vert,texu,texv
		Next
	Next
End Function