Per pixel lighting (with normal map)

Just starting out? Need help? Post your questions and find answers here.
User avatar
[blendman]
Enthusiast
Enthusiast
Posts: 297
Joined: Thu Apr 07, 2011 1:14 pm
Location: 3 arks
Contact:

Per pixel lighting (with normal map)

Post by [blendman] »

Hi

I would like to know if it's possible to create a sort of per pixel lighting with Purebasic ? Or use the normal map in 2D (with sprite3D), to create the light of a scene (on object), like that :
http://www.youtube.com/watch?v=ut0SqBeAy1Q&NR=1

Thank you.
applePi
Addict
Addict
Posts: 1404
Joined: Sun Jun 25, 2006 7:28 pm

Re: Per pixel lighting (with normal map)

Post by applePi »

i saw this kind of lighting in the example LightLookAt.pb in the Examples\3D folder .purebasic v4.60. move the mouse and the dark places will light more.
User avatar
[blendman]
Enthusiast
Enthusiast
Posts: 297
Joined: Thu Apr 07, 2011 1:14 pm
Location: 3 arks
Contact:

Re: Per pixel lighting (with normal map)

Post by [blendman] »

Hi, thanks for answer.

But there are some differences between the video and the LightLootAt example :
- the video use only sprite3D (2D image), not 3D engine, so the light and shadows are made on sprite/sprite3D.
- it's easy to add a light on the sprites (with spriteblendingmode() for example), but the video is more complicated : the light illuminate the "volume" of the image of the sprite, thanks to the normal map image
- the light create some shadows : with the help of a Code I have find on a Russian Site of purebasic (thanks to Aptem), I have create the shadows with sprite3D : http://vimeo.com/32071358

So the difficulty is to find a way to illuminate the "volume" (fake) of a sprite3D thanks to a normal map, like in 3D : the normal map is usefull to simulate a volume which isn't made with the polygon of the object.

So i'm looking about the same technic with sprite3D ;).

Thank you again.
User avatar
Kuron
Addict
Addict
Posts: 1626
Joined: Sat Oct 17, 2009 10:51 pm
Location: Pacific Northwest

Re: Per pixel lighting (with normal map)

Post by Kuron »

[blendman] wrote:- the video use only sprite3D (2D image), not 3D engine, so the light and shadows are made on sprite/sprite3D.
The video you linked to is using 3D and openly admits it. It is only "emulating" 2D by using 3D methods.
Best wishes to the PB community. Thank you for the memories. ♥️
User avatar
[blendman]
Enthusiast
Enthusiast
Posts: 297
Joined: Thu Apr 07, 2011 1:14 pm
Location: 3 arks
Contact:

Re: Per pixel lighting (with normal map)

Post by [blendman] »

Kuron wrote:The video you linked to is using 3D and openly admits it. It is only "emulating" 2D by using 3D methods.
ok, but the video is using 3D like sprite3D or like Ogre (3D engine) ?

Is it possible to do that sort of things with purebasic, with sprite3D ?
Becasue, for The shadows, i have found a code and change it to create the shadows, but I don't find any code for normal map and sprite3D, so I don't know how to do that.

Thanks
User avatar
Kuron
Addict
Addict
Posts: 1626
Joined: Sat Oct 17, 2009 10:51 pm
Location: Pacific Northwest

Re: Per pixel lighting (with normal map)

Post by Kuron »

[blendman] wrote:
Kuron wrote:The video you linked to is using 3D and openly admits it. It is only "emulating" 2D by using 3D methods.
ok, but the video is using 3D like sprite3D or like Ogre (3D engine) ?

It is using a 3D engine based on Direct3D and shaders which are based on NVIDIA's Cg. I don't use Sprite3D, so I can't say for certain whether there is a method to do this. I also do not actively use PB's OGRE implementation, so I can't speak to whether that would work or your needs.
Best wishes to the PB community. Thank you for the memories. ♥️
marc_256
Enthusiast
Enthusiast
Posts: 745
Joined: Thu May 06, 2010 10:16 am
Location: Belgium
Contact:

Re: Per pixel lighting (with normal map)

Post by marc_256 »

Hi Blendman,

First at all, I like your work,

Here I did some things with canvas gadget and a lamp torch.

The background image 'Logo_PVG.bmp'
Image

The torch 'LoopLamp.png'
Image

The inversed 'dark' torch 'LoopLampDark.png'
Image

The program:
http://www.marc-systems.be/PureBasic/LoopLampTest.pb

Code: Select all

;---------------------------------------------------------------------------------------------------
;- 
;---------------------------------------------------------------------------------------------------
	EnableExplicit


;---------------------------------------------------------------------------------------------------
Define Window.l
Define CanvasGadget3.l

Define Event.l

Define PVG_Mouse_PosX.w
Define PVG_Mouse_PosY.w

	UsePNGImageDecoder()

;	LoadImage(11, "LoopLamp.png")
	LoadImage(11, "LoopLampDark.png")
	LoadImage(12, "Logo_PVG.bmp")

	CreateImage(13, 160, 160, 32)

;---------------------------------------------------------------------------------------------------
	Window = OpenWindow(#PB_Any, 0, 0, 200, 200, "CanvasGadget", #PB_Window_SystemMenu|#PB_Window_ScreenCentered)

	If Window
		CanvasGadget3 = CanvasGadget(#PB_Any, 20, 20, 160, 160, #PB_Canvas_Keyboard|#PB_Canvas_DrawFocus|#PB_Canvas_Border)

;---------------------------------------------------------------------------------------------------
;- DO LOOP
;---------------------------------------------------------------------------------------------------
Repeat
	Event = WaitWindowEvent(1)
	If Event = #PB_Event_Gadget
		Select EventGadget()

;---------------------------------------------------------------------------------------------------
;- 
;---------------------------------------------------------------------------------------------------
				Case CanvasGadget3
					Select EventType()

						Case #PB_EventType_MouseMove

							SetGadgetAttribute(CanvasGadget3, #PB_Canvas_Cursor, #PB_Cursor_Invisible)

							PVG_Mouse_PosX = GetGadgetAttribute(CanvasGadget3, #PB_Canvas_MouseX)
							PVG_Mouse_PosY = GetGadgetAttribute(CanvasGadget3, #PB_Canvas_MouseY)
;Debug PVG_Mouse_PosX
;Debug PVG_Mouse_PosY

							StartDrawing(ImageOutput(13))
								DrawImage(ImageID(12), 0, 0)			; 160, 160)
								DrawingMode(#PB_2DDrawing_AlphaBlend)				; Clip)
								DrawImage(ImageID(11), PVG_Mouse_PosX-160, PVG_Mouse_PosY-160)			; 160, 160)
							StopDrawing()

							StartDrawing(CanvasOutput(CanvasGadget3))
								DrawImage(ImageID(13), 0, 0)			; 160, 160)
							StopDrawing()

					EndSelect

;---------------------------------------------------------------------------------------------------
		EndSelect
	EndIf

Until Event = #PB_Event_CloseWindow

EndIf

;---------------------------------------------------------------------------------------------------

Marc,
- every professional was once an amateur - greetings from Pajottenland - Belgium -
PS: sorry for my english I speak flemish ...
applePi
Addict
Addict
Posts: 1404
Joined: Sun Jun 25, 2006 7:28 pm

Re: Per pixel lighting (with normal map)

Post by applePi »

thank you marc_256, this is a great demonstration of the CanvasGadget, and also a great toy, also i can imagine its possible usage for playing with secret writing; at first we see a white blackboard, and moving a mouse illuminate parts of it and show a treasure.
thank you
User avatar
Andre
PureBasic Team
PureBasic Team
Posts: 2058
Joined: Fri Apr 25, 2003 6:14 pm
Location: Germany (Saxony, Deutscheinsiedel)
Contact:

Re: Per pixel lighting (with normal map)

Post by Andre »

I tried it with PB4.60 on MacOS, but there it doesn't seem to work like it should. There is no lighting visible in the PVG image, just when moving the mouse cursor from top into the CanvasGadget, there is shown the LoopLamp image instead of the PVG image...

A restriction on MacOS or a bug in the CanvasGadget features on PB4.60 for MacOS?
Bye,
...André
(PureBasicTeam::Docs & Support - PureArea.net | Order:: PureBasic | PureVisionXP)
marc_256
Enthusiast
Enthusiast
Posts: 745
Joined: Thu May 06, 2010 10:16 am
Location: Belgium
Contact:

Re: Per pixel lighting (with normal map)

Post by marc_256 »

@ applePi,
You are welcome.

@ Andre,
I use Win XP SP2 Home, and it works well.
With PB4.60 RC2.
I do not have apple computer to test ?
I do not know what applePi is using ?
Try this program, I added a imagegadget...

Code: Select all

;---------------------------------------------------------------------------------------------------
;- L O O P L A M P
;---------------------------------------------------------------------------------------------------
	EnableExplicit


;---------------------------------------------------------------------------------------------------
Define Window.l
Define CanvasGadget3.l
Define ImageGadget3.l

Define Event.l

Define PVG_Mouse_PosX.w
Define PVG_Mouse_PosY.w

	UsePNGImageDecoder()

	LoadImage(11, "LoopLamp.png")
;	LoadImage(11, "LoopLampDark.png")
	LoadImage(12, "Logo_PVG.bmp")

	CreateImage(13, 160, 160, 32)

;---------------------------------------------------------------------------------------------------
	Window = OpenWindow(#PB_Any, 0, 0, 400, 200, "CanvasGadget", #PB_Window_SystemMenu|#PB_Window_ScreenCentered)

	If Window
		CanvasGadget3 = CanvasGadget(#PB_Any, 20, 20, 160, 160, #PB_Canvas_Keyboard|#PB_Canvas_DrawFocus|#PB_Canvas_Border)
		ImageGadget3 = ImageGadget(#PB_Any, 200, 20, 160, 160, ImageID(13))

;---------------------------------------------------------------------------------------------------
;- DO LOOP
;---------------------------------------------------------------------------------------------------
Repeat
	Event = WaitWindowEvent(1)
	If Event = #PB_Event_Gadget
		Select EventGadget()

;---------------------------------------------------------------------------------------------------
;- 
;---------------------------------------------------------------------------------------------------
				Case CanvasGadget3
					Select EventType()

						Case #PB_EventType_MouseMove

							SetGadgetAttribute(CanvasGadget3, #PB_Canvas_Cursor, #PB_Cursor_Invisible)

							PVG_Mouse_PosX = GetGadgetAttribute(CanvasGadget3, #PB_Canvas_MouseX)
							PVG_Mouse_PosY = GetGadgetAttribute(CanvasGadget3, #PB_Canvas_MouseY)
;Debug PVG_Mouse_PosX
;Debug PVG_Mouse_PosY

							StartDrawing(ImageOutput(13))
								DrawImage(ImageID(12), 0, 0)			; 160, 160)
								DrawingMode(#PB_2DDrawing_AlphaBlend)				; Clip)
								DrawImage(ImageID(11), PVG_Mouse_PosX-160, PVG_Mouse_PosY-160)			; 160, 160)
							StopDrawing()

							SetGadgetState(ImageGadget3, ImageID(13))

							StartDrawing(CanvasOutput(CanvasGadget3))
								DrawImage(ImageID(13), 0, 0)			; 160, 160)
							StopDrawing()

					EndSelect

;---------------------------------------------------------------------------------------------------
		EndSelect
	EndIf

Until Event = #PB_Event_CloseWindow

EndIf

;---------------------------------------------------------------------------------------------------

Marc,
- every professional was once an amateur - greetings from Pajottenland - Belgium -
PS: sorry for my english I speak flemish ...
User avatar
[blendman]
Enthusiast
Enthusiast
Posts: 297
Joined: Thu Apr 07, 2011 1:14 pm
Location: 3 arks
Contact:

Re: Per pixel lighting (with normal map)

Post by [blendman] »

Hi Marc

Thank you for your answer ;)
Your exemple is interesting, I probably use this technic, if I can reproduce it with a Screen and DirectX.

It's not the feature I'm looking for, because the feature is more a "bump" effect or "normal map effect". But thanks again for your interesting exemple ;).
User avatar
Andre
PureBasic Team
PureBasic Team
Posts: 2058
Joined: Fri Apr 25, 2003 6:14 pm
Location: Germany (Saxony, Deutscheinsiedel)
Contact:

Re: Per pixel lighting (with normal map)

Post by Andre »

Sorry Marc, the changed code still doesn't work on MacOS.
No reaction when moving the mouse over the ImageGadget and same effect like described above over CanvasGadget (only something to see when moving the mouse cursor from top-side into the CanvasGadget and out again...).
Bye,
...André
(PureBasicTeam::Docs & Support - PureArea.net | Order:: PureBasic | PureVisionXP)
marc_256
Enthusiast
Enthusiast
Posts: 745
Joined: Thu May 06, 2010 10:16 am
Location: Belgium
Contact:

Re: Per pixel lighting (with normal map)

Post by marc_256 »

@ [blendman]
You are welcome

@Andre
It is strange, but I'm not a apple specialist... :(
So, I look around and I have a question.
Can Apple handle .bmp images ?
I converted the .bmp logo to .png logo image.

The .png background image 'Logo_PVG.png'
Image

And replace line
LoadImage(12, "Logo_PVG.bmp")
with
LoadImage(12, "Logo_PVG.png")


Works also good with windows XP SP2 Home

Marc,
- every professional was once an amateur - greetings from Pajottenland - Belgium -
PS: sorry for my english I speak flemish ...
remi_meier
Enthusiast
Enthusiast
Posts: 468
Joined: Sat Dec 20, 2003 6:19 pm
Location: Switzerland

Re: Per pixel lighting (with normal map)

Post by remi_meier »

Seriously, am I the only one which remembers the examples
from LarsG and Dennis from the year 2003? Didn't know I'm
getting old, too. :mrgreen:

Look for Bump(Map) on http://www.purearea.net/pb/english/projects_app.htm

It's not Sprite3D, but it was real-time in 2003 (yes, I remember :lol: ).
So maybe it gives you an idea. Of course there certainly is a way
to apply any kind of shader to a Sprite3D if you know the internals,
but you might need to manually render everything later. I think
DarkDragon might be so kind to give you an example of how to
do it with OpenGL (not sure if I'm allowed to give you the sources
or if they were posted somewhere anyway).
For DirectX you'll have to find some other gurus.

Cheers,
Remi
Athlon64 3700+, 1024MB Ram, Radeon X1600
User avatar
Kuron
Addict
Addict
Posts: 1626
Joined: Sat Oct 17, 2009 10:51 pm
Location: Pacific Northwest

Re: Per pixel lighting (with normal map)

Post by Kuron »

marc_256 wrote:@ Andre,
I use Win XP SP2 Home, and it works well.
With PB4.60 RC2.

Just curious. Why are you using such an old version?
Best wishes to the PB community. Thank you for the memories. ♥️
Post Reply