0 Members and 1 Guest are viewing this topic.

#### 3rik

• LV3 Member (Next: 100)
• Posts: 92
• Rating: +8/-0
• My TI-84+ SE
« on: August 26, 2011, 04:52:03 pm »
I am working on a Lua function that creates a TI Image of a 3D object made of triangles but I don't know how to determine what shade the pixel should be.
I have looked at some websites but they either didn't get into detail or they used notation or syntax I'm not familiar with.

This is the relevant information I have:
camera position
light source position
the points that make up the triangle
the equation of the plane the triangle lies in
point where the camera view intersects the plane
the original color of the triangle

If anyone understands how Phong shading (or something similar) works, explaining it at a precalculus level would be much appreciated.

Something like this is what I am thinking of but I don't know how it works.

I know about vectors but I don't understand what R is.

Thank you
Userbars

#### Eiyeron

• Urist McEiyolobster
• LV10 31337 u53r (Next: 2000)
• Posts: 1430
• Rating: +130/-10
• (-_(//));
« Reply #1 on: August 26, 2011, 04:53:55 pm »
Ray. Of light of course
« Last Edit: August 26, 2011, 04:54:28 pm by Eiyeron »

#### 3rik

• LV3 Member (Next: 100)
• Posts: 92
• Rating: +8/-0
• My TI-84+ SE
« Reply #2 on: August 26, 2011, 04:56:54 pm »
But how do I find it and what should I do with it once I have it and why? This is beyond what we covered in math class.
Userbars

#### ben_g

• Hey cool I can set a custom title now :)
• LV9 Veteran (Next: 1337)
• Posts: 1002
• Rating: +125/-4
• Asm noob
« Reply #3 on: August 26, 2011, 04:57:53 pm »
The amount of light that hits the surface is the cosine of the angle between the normal vector (N) and the direction of the light (L). Or ta least it had something to do with the cosine between two vectors.
My projects
- The Lost Survivors (Unreal Engine) ACTIVE [GameCommandoSquad main project]
- Oxo, with single-calc multiplayer and AI (axe) RELEASED (screenshot) (topic)
- An android version of oxo (java)  ACTIVE
- A 3D collision detection library (axe) RELEASED! (topic)(screenshot)(more recent screenshot)(screenshot of it being used in a tilemapper)
Spoiler For inactive:
- A first person shooter with a polygon-based 3d engine. (z80, will probably be recoded in axe using GLib) ON HOLD (screenshot)
- A java MORPG. (pc) DEEP COMA(read more)(screenshot)
- a minecraft game in axe DEAD (source code available)
- a 3D racing game (axe) ON HOLD (outdated screenshot of asm version)

This signature was last updated on 20/04/2015 and may be outdated

#### 3rik

• LV3 Member (Next: 100)
• Posts: 92
• Rating: +8/-0
• My TI-84+ SE
« Reply #4 on: August 26, 2011, 05:01:10 pm »
I think I want the angle between -R and V but I'm not sure how to get R.
Userbars

#### ben_g

• Hey cool I can set a custom title now :)
• LV9 Veteran (Next: 1337)
• Posts: 1002
• Rating: +125/-4
• Asm noob
« Reply #5 on: August 26, 2011, 05:04:36 pm »
If you only need to do simple lighting, then you only need to find out the angle between the direction the light hits the surface and the normal vector.

EDIT: I checked it: it's the cosine of the angle between the normal and the light direction. That's all you need if you just want the most simple concept of lighting.
« Last Edit: August 26, 2011, 05:11:02 pm by ben_g »
My projects
- The Lost Survivors (Unreal Engine) ACTIVE [GameCommandoSquad main project]
- Oxo, with single-calc multiplayer and AI (axe) RELEASED (screenshot) (topic)
- An android version of oxo (java)  ACTIVE
- A 3D collision detection library (axe) RELEASED! (topic)(screenshot)(more recent screenshot)(screenshot of it being used in a tilemapper)
Spoiler For inactive:
- A first person shooter with a polygon-based 3d engine. (z80, will probably be recoded in axe using GLib) ON HOLD (screenshot)
- A java MORPG. (pc) DEEP COMA(read more)(screenshot)
- a minecraft game in axe DEAD (source code available)
- a 3D racing game (axe) ON HOLD (outdated screenshot of asm version)

This signature was last updated on 20/04/2015 and may be outdated

#### 3rik

• LV3 Member (Next: 100)
• Posts: 92
• Rating: +8/-0
• My TI-84+ SE
« Reply #6 on: August 26, 2011, 05:12:04 pm »
In my function the Light isn't necessarily in the same position as the camera so the Light might be directly over the object but the camera is at a low angle above the object. It would be a big difference.

If I can't come up with what I'm looking for then that sounds like a good method. Thanks.
Userbars

#### ben_g

• Hey cool I can set a custom title now :)
• LV9 Veteran (Next: 1337)
• Posts: 1002
• Rating: +125/-4
• Asm noob
« Reply #7 on: August 26, 2011, 05:15:45 pm »
If you want to know more abouth how lighting is calculated in 3D computer programs, you can take a look at this: http://www.lighthouse3d.com/tutorials/glsl-tutorial/directional-lights-i/
I know the code in it will be useless to you, but you can use the formula's. They are all explained. And if you don't understand something related to 3D programming, feel free to ask.
« Last Edit: August 26, 2011, 05:16:06 pm by ben_g »
My projects
- The Lost Survivors (Unreal Engine) ACTIVE [GameCommandoSquad main project]
- Oxo, with single-calc multiplayer and AI (axe) RELEASED (screenshot) (topic)
- An android version of oxo (java)  ACTIVE
- A 3D collision detection library (axe) RELEASED! (topic)(screenshot)(more recent screenshot)(screenshot of it being used in a tilemapper)
Spoiler For inactive:
- A first person shooter with a polygon-based 3d engine. (z80, will probably be recoded in axe using GLib) ON HOLD (screenshot)
- A java MORPG. (pc) DEEP COMA(read more)(screenshot)
- a minecraft game in axe DEAD (source code available)
- a 3D racing game (axe) ON HOLD (outdated screenshot of asm version)

This signature was last updated on 20/04/2015 and may be outdated

#### 3rik

• LV3 Member (Next: 100)
• Posts: 92
• Rating: +8/-0
• My TI-84+ SE
« Reply #8 on: August 26, 2011, 05:52:40 pm »
Thanks! I think I will use this. It seems realistic enough. Hopefully I'll have it finished later today.

Edit: The very next page had what I was looking for! Thank you.
« Last Edit: August 26, 2011, 05:59:18 pm by 3rik »
Userbars

#### ben_g

• Hey cool I can set a custom title now :)
• LV9 Veteran (Next: 1337)
• Posts: 1002
• Rating: +125/-4
• Asm noob
« Reply #9 on: August 26, 2011, 06:25:40 pm »
Thanks! I think I will use this. It seems realistic enough. Hopefully I'll have it finished later today.

Edit: The very next page had what I was looking for! Thank you.
You're welcome. And keep in mind that while this is for directional lights (like the sun), you can also let the light come from one point, and then calculate the direction the rays of light hit he surface.

Also: You get the best graphical results when you doo all of the calculations per pixel, instaed of per triangle. This would be slower, but as you said it will be used for creating images of that, I don't think that would be a problem.

good luck
« Last Edit: August 26, 2011, 06:30:35 pm by ben_g »
My projects
- The Lost Survivors (Unreal Engine) ACTIVE [GameCommandoSquad main project]
- Oxo, with single-calc multiplayer and AI (axe) RELEASED (screenshot) (topic)
- An android version of oxo (java)  ACTIVE
- A 3D collision detection library (axe) RELEASED! (topic)(screenshot)(more recent screenshot)(screenshot of it being used in a tilemapper)
Spoiler For inactive:
- A first person shooter with a polygon-based 3d engine. (z80, will probably be recoded in axe using GLib) ON HOLD (screenshot)
- A java MORPG. (pc) DEEP COMA(read more)(screenshot)
- a minecraft game in axe DEAD (source code available)
- a 3D racing game (axe) ON HOLD (outdated screenshot of asm version)

This signature was last updated on 20/04/2015 and may be outdated

#### 3rik

• LV3 Member (Next: 100)
• Posts: 92
• Rating: +8/-0
• My TI-84+ SE