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.

AppGameKit Classic Chat / 3D Normal Shader using 5 lights and a texture atlas - working I think

Author
Message
AJCodes
9
Years of Service
User Offline
Joined: 6th Jan 2015
Location:
Posted: 13th Jan 2015 05:13
OK...I'm really new to shaders and I've been working on this for about a week.

The goal: a shader that will handle up to 5 lights, normal mapping, passing the object texture offset (numbers across and down, not the actual offsets) in R and G of the object color, passing the ambient light level in the B parameter, and the object's alpha in A.

I think I've got it, but I'd love someone who knows this stuff to take a look.

Here's the vertex shader:



and here's the pixel shader:



Cobbled together and modified from about 1,000 examples here and on the internet. I also use a few "undocumented" things from agk...I just assumed that there'd be a tangent and binormal vector available...and my example seems to indicate that they do exist but I haven't seen any documentation.

I know the attenuation is cheap, but I've been focused hard on correct normal mapping and the 5 light problem.

Here's some agk code to set the shader up:



Oh...and the hsv to rgb code is there as, after I get some validation that this really is normal mapping correctly, I'll be using the object R channel for the texture number and deriving the offsets from that while converting the G to the H part of HSV so I can do some really basic object coloring.

Would appreciate it if anyone that really knows this stuff could check it out to validate that it's really doing normal mapping. And...any comment from the AppGameKit devs as to parameters available to shaders would be great too!

Born. Currently living.
AJCodes
9
Years of Service
User Offline
Joined: 6th Jan 2015
Location:
Posted: 13th Jan 2015 07:06
More tests...normal mapping is not working. Apparently I'm not getting those vectors and I just happened onto a perspective that worked during development. Bleh.

Born. Currently living.
CJB
Valued Member
20
Years of Service
User Offline
Joined: 10th Feb 2004
Location: Essex, UK
Posted: 13th Jan 2015 10:10
Did you see Janbo's normal mapping thread over in the Showcase board?

http://forum.thegamecreators.com/?m=forum_view&t=212611&b=48

Some fantastic results there. Getting it to work with atlas textures would be sweet! I'll be keeping an eye on this thread!

V2 T1 (Mostly)
Uzmadesign
AJCodes
9
Years of Service
User Offline
Joined: 6th Jan 2015
Location:
Posted: 13th Jan 2015 15:41
Yep...that's for a sprite shader - 2D. Sprite shaders can do normal (bump) mapping with a fixed normal vector(one, facing out to the viewer) which simplifies the handling of the normal texture.

I'm working now on approximating the tangent and binormal needed to do this in 3D using concepts from http://www.geeks3d.com/20130122/normal-mapping-without-precomputed-tangent-space-vectors/.

Now...the method I use to do the texture atlas can be used in either...it's pretty straightforward.

Born. Currently living.
AJCodes
9
Years of Service
User Offline
Joined: 6th Jan 2015
Location:
Posted: 18th Jan 2015 05:03
OK...an update. Normal mapping WITHOUT vertex tangents or binormals (bitangents).

One point light. Texture atlas. Normal (bump) mapping.

The base texture goes into texture 0, the normal texture into texture 1. I wrote some code to construct the atlases from individual textures I made in Substance Designer. Remember to set GL normals!

The shader assumes that your atlas (base and normal map) is 16x16. The agk code snippet shows the setup and use of the shader.

Vertex shader:



Pixel shader:


And some sample setup code:


There's plenty of room to improve attenuation, etc., but compared to getting normal mapping working that's pretty simple.

Enjoy.

Born. Currently living.
janbo
16
Years of Service
User Offline
Joined: 10th Nov 2008
Location: Germany
Posted: 19th Jan 2015 18:38 Edited at: 19th Jan 2015 18:44
Hi,

Good job!

I think you had inverted normals (Depends on the normal map u used) but I fixed it for me... aaand added specular highlights.

Fragment Shader






Using AppGameKit V2 Tier1

Attachments

Login to view attachments

Login to post a reply

Server time is: 2024-11-25 15:22:04
Your offset time is: 2024-11-25 15:22:04