Textured Spot light ??

Everything related to 3D programming
applePi
Addict
Addict
Posts: 1404
Joined: Sun Jun 25, 2006 7:28 pm

Textured Spot light ??

Post by applePi »

just a subject for contemplation and ideas how to achieve this, a textured batman spotlight like this one
if you want to see how it looks like download Blitz3DDemo183.exe and run the code. it seems to me too complex code in blitz3d. you need the following picture for the code
Image

if you want to do experiments in purebasic i suggest as a framework to use RotateLight.pb from the 3D folder
Last edited by applePi on Thu Jun 26, 2014 1:50 pm, edited 1 time in total.
PMV
Enthusiast
Enthusiast
Posts: 727
Joined: Sat Feb 24, 2007 3:15 pm
Location: Germany

Re: Textured Spot light ??

Post by PMV »

Without reading the blitz3d topic ... one easy solution could be:
create a big cylinder that is transparent white
locate that cylinder at the ground, going up into the air where it gets bigger and bigger
at the ground of the cylinder, the texture alpha is low, making it less transparent at it should be full transparent at the end
create a flat plane and use the badman texture
the plane has to be located in the air at the end of the cylinder facing to the ground

If you have already used material-scripts before, it could be done in an hour or less. :D


Edit: can't find a download-link for the finished example, just for the code?

MFG PMV
applePi
Addict
Addict
Posts: 1404
Joined: Sun Jun 25, 2006 7:28 pm

Re: Textured Spot light ??

Post by applePi »

Thanks PMV i will try your suggestion
the download link for the finished example is here, i have tried it
http://www.blitzbasic.com/codearcs/codearcs_bb/1000.bb
it needs the above picture
PMV
Enthusiast
Enthusiast
Posts: 727
Joined: Sat Feb 24, 2007 3:15 pm
Location: Germany

Re: Textured Spot light ??

Post by PMV »

That is still the link to the code ... so if you have to compile it yourself, maybe a picture or video would be great.
applePi
Addict
Addict
Posts: 1404
Joined: Sun Jun 25, 2006 7:28 pm

Re: Textured Spot light ??

Post by applePi »

the following is the link, i have tested the program on winxp, but can't test it on windows 7 since it is corrupted 2 days ago while trying to install LinuxMint.
the best scene is to press back arrow so to have distant scene then use the mouse to move the spotlight over the room walls
http://www.mediafire.com/?sp7o6ukbhdrkk3p
applePi
Addict
Addict
Posts: 1404
Joined: Sun Jun 25, 2006 7:28 pm

Re: Textured Spot light ??

Post by applePi »

it seems Samuel have solved this problem before here: http://www.purebasic.fr/english/viewtop ... 44#p421777
i can't now prepare a suitable batman sign but i have a previously made transparent texture so save this texture:
Image
http://s13.postimg.org/wezihh3l3/batman.png
and replace its name in the AlphaToShadow.MATERIAL samuel have posted at line 24 write texture batman.png -1
and run the code there you will see the shadow of the picture on the ground (the picture in a transparent texture are textured over a cube, and the light cast its shadow on the ground) it is amazing to look at the shadow of a texture.
Image
in the future i will use samuel code and material to make more decorative effect and presentation with a suitable texture and on a plane so it will look like a textured spotlight.
i hope Samuel will agree to repost his code again changed very slightly to show the effect more so the users can run it easily.
put all code and the batman.png picture in the same folder.
AlphaToShadow.MATERIAL ---> by Samuel

Code: Select all

material Transparent
{
   receive_shadows off
   transparency_casts_shadows off
   technique Default
   {
      pass Main
      {
         ambient 0.8 0.8 0.8 0.8
         specular 0 0 0 0 0
         emissive  0.8 0.8 0.8 0.8

         cull_hardware none
         cull_software none
         scene_blend alpha_blend 
         
         alpha_rejection greater 128 
         depth_write on 

         
         texture_unit
         {
             //CHANGE Spark1.png To a texture that has some alpha.
            texture batman.png -1
         }         
      }
   }
}
the code ___ by Samuel changed a liitle

Code: Select all

;PRESS Escape to exit

#CameraSpeed = 1

Define.f KeyX, KeyY, MouseX, MouseY

If InitEngine3D()

  InitSprite()
  InitKeyboard()
  InitMouse()
  ExamineDesktops()
  
DeskWid=DesktopWidth(0)
DeskHei=DesktopHeight(0)

Add3DArchive(".", #PB_3DArchive_FileSystem);####SET THE PATH TO YOUR MATERIAL SCRIPT.
Add3DArchive(".", #PB_3DArchive_FileSystem);####SET THE PATH TO YOUR TEXTURE THAT THE MATERIAL SCRIPT USES.

 If OpenWindow(0, 0, 0, DeskWid, DeskHei, "Alpha to Shadow", #PB_Window_ScreenCentered)
  If OpenWindowedScreen(WindowID(0), 0, 0, DeskWid, DeskHei, 0, 0, 0)
    
    Parse3DScripts()
    
    GetScriptMaterial(BoxMaterial, "Transparent")
    ;LoadTexture(5,"SpotLight2.png")
    ;AddMaterialLayer(BoxMaterial, TextureID(5) ,#PB_Material_Replace     )
    ;DisableMaterialLighting(BoxMaterial, 0)

    
    BoxMesh=CreateCube(#PB_Any,40)
    BoxEntity=CreateEntity(#PB_Any,MeshID(BoxMesh),MaterialID(BoxMaterial),0,0,0)
    
    
    PlaneTexture=CreateTexture(#PB_Any,32,32)
    StartDrawing(TextureOutput(PlaneTexture))
      Box(0,0,32,32,RGB(255,255,255))
    StopDrawing()
    
    PlaneMaterial=CreateMaterial(#PB_Any, TextureID(PlaneTexture))
    
    PlaneMesh=CreatePlane(#PB_Any,10000,10000,10,10,10,10)
    PlaneEntity=CreateEntity(#PB_Any,MeshID(PlaneMesh),MaterialID(PlaneMaterial),0,-40,0)
    EntityRenderMode(PlaneEntity,0)
    
    CreateCamera(0, 0, 0, 100, 100)
    MoveCamera(0, -50, 0, 120, #PB_Absolute)
    CameraBackColor(0, RGB(255,255,0))

    CameraLookAt(0,0,-10,0)

    CreateLight(0,RGB(100,100,100),0,100,0)
    
    WorldShadows(#PB_Shadow_TextureAdditive, 0, RGB(127, 127, 127), 4096)
    
    Repeat
            
      If ExamineMouse()
        MouseX = -MouseDeltaX() * #CameraSpeed * 0.05
        MouseY = -MouseDeltaY() * #CameraSpeed * 0.05
      EndIf  
      
      If ExamineKeyboard()
        
        If KeyboardPushed(#PB_Key_Left)
          KeyX = -#CameraSpeed 
        ElseIf KeyboardPushed(#PB_Key_Right)
          KeyX = #CameraSpeed 
        Else
          KeyX = 0
        EndIf
                  
        If KeyboardPushed(#PB_Key_Up)
          KeyY = -#CameraSpeed 
        ElseIf KeyboardPushed(#PB_Key_Down)
          KeyY = #CameraSpeed 
        Else
          KeyY = 0
        EndIf

      EndIf
            
      RotateEntity(BoxEntity,0,0.5,0,#PB_Relative)
      RotateCamera(0, MouseY, MouseX, 0, #PB_Relative)
      MoveCamera(0, KeyX, 0, KeyY)

    
      RenderWorld()

      FlipBuffers()
    Until KeyboardPushed(#PB_Key_Escape) 
  EndIf
 EndIf
Else
  MessageRequester("Error", "The 3D Engine can't be initialized", 0)
EndIf
  
End
PMV
Enthusiast
Enthusiast
Posts: 727
Joined: Sat Feb 24, 2007 3:15 pm
Location: Germany

Re: Textured Spot light ??

Post by PMV »

Now, i have seen what the Blitz3D example does ...
it maps the texture on the complete scene ... i
really don't know, if something like that is possible
with OGRE alone, maybe with shaders but i'm not
helpful there. The ogre3d-forum could help you more.

The code from Samuel is, what i have suggested :)
If you displays that entity on a flat wall or in the
air, you will have your wanted effect. If the ground/
wall is not flat ... it will still look good as long
as you are far away. :wink:

MFG PMV
Post Reply