It is currently Tue Mar 26, 2019 2:07 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: How does light work ???
PostPosted: Fri Jan 11, 2019 3:13 pm 
Offline
User
User

Joined: Wed Sep 12, 2012 5:09 pm
Posts: 38
Hello, I'm unable to project a light on a mesh created with createmsh()... Can someone tell me what am I doing wrong ? ^^"
Code:
InitEngine3D()
InitSprite()

OpenWindow(0,0,0,500,500,"",#PB_Window_ScreenCentered|#PB_Window_SystemMenu)
OpenWindowedScreen(WindowID(0),0,0,500,500)

CreateLight(0,RGB(255,0,0),0,0,1000,#PB_Light_Point)

CreateCamera(0,0,0,100,100)
MoveCamera(0,0,0,1000)

CreateMesh(0, #PB_Mesh_TriangleList, #PB_Mesh_Dynamic)

MeshVertexPosition(-128,128,0)
MeshVertexTextureCoordinate(0,0)
MeshVertexPosition(128,128,0)
MeshVertexTextureCoordinate(0,1)
MeshVertexPosition(128,-128,0)
MeshVertexTextureCoordinate(1,1)
MeshVertexPosition(-128,-128,0)
MeshVertexTextureCoordinate(1,0)

MeshFace(2,1,0)
MeshFace(0,3,2)

FinishMesh(#True)

CreateCube(1,50)

CreateEntity(0,MeshID(0),#PB_Material_None)

CreateEntity(1,MeshID(1),#PB_Material_None)
MoveEntity(1,-130,0,0)

Repeat
  RenderWorld()
  FlipBuffers()
Until WindowEvent() = #PB_Event_CloseWindow


PB 5.70


Top
 Profile  
Reply with quote  
 Post subject: Re: How does light work ???
PostPosted: Fri Jan 11, 2019 7:21 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Sun Jul 29, 2012 10:33 pm
Posts: 726
Location: United States
Your mesh lacks vertex normals. https://www.purebasic.com/documentation ... ormal.html

This tutorial is for ray tracing, but it might help you understand how vertex normals work. https://www.scratchapixel.com/lessons/3 ... ng-normals


Top
 Profile  
Reply with quote  
 Post subject: Re: How does light work ???
PostPosted: Fri Jan 11, 2019 11:16 pm 
Offline
User
User

Joined: Wed Sep 12, 2012 5:09 pm
Posts: 38
Code:
InitEngine3D()
InitSprite()

OpenWindow(0,0,0,500,500,"",#PB_Window_ScreenCentered|#PB_Window_SystemMenu)
OpenWindowedScreen(WindowID(0),0,0,500,500)

CreateLight(0,RGB(255,0,0),0,0,1000,#PB_Light_Point)

CreateCamera(0,0,0,100,100)
MoveCamera(0,0,0,1000)

CreateMesh(0, #PB_Mesh_TriangleList, #PB_Mesh_Dynamic)

MeshVertexPosition(-128,128,0)
MeshVertexTextureCoordinate(0,0)
MeshVertexNormal(0,0,1)
MeshVertexPosition(128,128,0)
MeshVertexTextureCoordinate(0,1)
MeshVertexPosition(128,-128,0)
MeshVertexTextureCoordinate(1,1)
MeshVertexPosition(-128,-128,0)
MeshVertexTextureCoordinate(1,0)

MeshFace(2,1,0)
MeshFace(0,3,2)

FinishMesh(#True)

CreateCube(1,50)

CreateEntity(0,MeshID(0),#PB_Material_None)

CreateEntity(1,MeshID(1),#PB_Material_None)
MoveEntity(1,-130,0,0)

Repeat
  RenderWorld()
  FlipBuffers()
Until WindowEvent() = #PB_Event_CloseWindow


Hoo so this is what normal use for !! Thx Samuel... I just don't understand anything with 3D ^^"


Top
 Profile  
Reply with quote  
 Post subject: Re: How does light work ???
PostPosted: Sun Jan 13, 2019 1:20 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Tue Sep 22, 2009 10:41 pm
Posts: 369
There is three ways to calculate normal manually :

1) by means of torks of adjacents segments of triangles (to simplify, imagine you are on the top of an umbrella)
Result is graduate (Phong)

2) by just tork calculating. The simplest. The eldest. Tiled result.

3) by... opposite of mean of adjacents segments (c'est pas garanti, no garanty, it is my own idea, do not try if beginning)

All 3 results might be normalized (maximum search cross product) to reduce maximum to 1.

For a Phong sphere, it is simpler : just substract vertices position by(<<-- added) sphere position and normalize.

Added : (3) same problem as Atan2 calculating (several quadrants) : virtual sphere around the vertex is divided by a virtual plane, and this last one is too complex to calculate, using heuristics. So, "North" and "South" should be okay, but "equator" of virtual sphere is unabled to be calculate, due to float precision limit to normalize.
Apologize for the third method which is false.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye