Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / How do you Normal map a plane with Dark basic???

Author
Message
Programmer X
18
Years of Service
User Offline
Joined: 14th Nov 2007
Location:
Posted: 9th Mar 2015 23:06
I just want a shader example of the process of normal mapping a Plane with dark basic code.

XXX
Rudolpho
20
Years of Service
User Offline
Joined: 28th Dec 2005
Location: Sweden
Posted: 10th Mar 2015 00:59
Normal mapping is really just about sampling normal data from a texture instead of using a mesh's own interpolated per-vertex normals in your lighting calculations.
The normal data is used to simulate how incoming light bounces of the rendered surface. Normally ( no pun intended ) you calculate the dot product of the surface normal (which in the case of normal mapping is sampled from a texture, as previously mentioned) and the direction from which the light is hitting the surface and then simply use that as a factor to multiply your final colour with (if you have a more complex calculation for determining your final pixel colour you can just multiply this factor with the attenuation / intensity value, before any specular highlights etc. are added).


One funky thing that I had lots of trouble finding out is that normal maps are usually stored in tangent space rather than object space. You can essentially think of this as them being relative to the surface normal. This is a good thing since the normals will still be correct even if you deform the mesh (such as through animation), however it isn't quite so simple. Basically your mesh will have to have per-vertex tangents and bitangents (commonly, albeit wrongly, referred to as binormals) in addition to (per-vertex) normals. This is needed to build a 3x3 matrix that can be used to transform between mesh and tangent space for using your normal map's values in your lighting calculations.


This code snippet shows how I'm currently doing the normal transformation in my Ziggurat engine:


Programmer X
18
Years of Service
User Offline
Joined: 14th Nov 2007
Location:
Posted: 10th Mar 2015 01:24
I was hoping to move the normal map calculation to the GPU with a shader to reduce the processing hit.

XXX
Programmer X
18
Years of Service
User Offline
Joined: 14th Nov 2007
Location:
Posted: 10th Mar 2015 01:32
I don't want an FX file i think because the normal map is in a compressed seporate data file which is decompressed and converted to cartesian normals.

XXX
Programmer X
18
Years of Service
User Offline
Joined: 14th Nov 2007
Location:
Posted: 10th Mar 2015 01:50
How would the code snippet look like with the 3d math commands in dark basic pro???



XXX
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 11th Mar 2015 13:47
Quote: "I was hoping to move the normal map calculation to the GPU with a shader to reduce the processing hit."


Quote: "I don't want an FX file i think because the normal map is in a compressed seporate data file which is decompressed and converted to cartesian normals."


What?



Powered by Free Banners
Programmer X
18
Years of Service
User Offline
Joined: 14th Nov 2007
Location:
Posted: 11th Mar 2015 18:31
I got it working now i just need someway to draw all sprites behind objects

XXX
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 11th Mar 2015 21:15
Very basic demo:





Powered by Free Banners

Login to post a reply

Server time is: 2026-07-12 15:59:23
Your offset time is: 2026-07-12 15:59:23