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 / Normal mapping help

Author
Message
Santman
12
Years of Service
User Offline
Joined: 15th Sep 2011
Location: Inverness
Posted: 13th Feb 2018 20:49
Hey everyone.

I'm trying to get normal mapping working, but getting no where. I have generated the normal map of the texture, and if I use setobjectnormalmap it works fine. I grab that vs and ps, but when I put them seperately it doesn;t work. It seems that for some reason the shader seperately can't pick out the normal texture.

Has anyone had this issue?
george++
AGK Tool Maker
16
Years of Service
User Offline
Joined: 13th May 2007
Location: Thessaloniki, Hellas
Posted: 13th Feb 2018 21:03 Edited at: 13th Feb 2018 21:04
I am not an expert.
Recently I read the guide for shaders in the AppGameKit documentation.(https://www.appgamekit.com/documentation/guides/13_shaders.htm)
Do you apply the lighting?

Quote: "
Note the GetVSLighting function is declared but not defined, AppGameKit will define it at runtime. In this case the lighting information is passed directly to the pixel shader, but you can do anything you like to the value. The GetVSLighting function makes no changes to any global values, it only returns a value. Also note that the call to GetVSLighting must occur after setting the gl_Position value, the lighting function makes use of this value.

The function for pixel lighting looks like this
"
Santman
12
Years of Service
User Offline
Joined: 15th Sep 2011
Location: Inverness
Posted: 13th Feb 2018 21:06
I'm looking at hte guide, but something funny is happening. For some reason, the exact same shader that is built into AppGameKit isn't working.
Santman
12
Years of Service
User Offline
Joined: 15th Sep 2011
Location: Inverness
Posted: 13th Feb 2018 21:19
Ok I think I found it.....amazingly, calling your shader "normal.vs" and "normal.ps" causes it to simply not work! Lol.
Santman
12
Years of Service
User Offline
Joined: 15th Sep 2011
Location: Inverness
Posted: 13th Feb 2018 21:23
So that does seem to stop the shader working, but still no normal map working. :-(
janbo
15
Years of Service
User Offline
Joined: 10th Nov 2008
Location: Germany
Posted: 13th Feb 2018 21:45
How do you setup the normal mapping texture are you using SetObjectImage(objID, imageID, 2) or SetObjectNormalMap( objID, imageID ) ?
Santman
12
Years of Service
User Offline
Joined: 15th Sep 2011
Location: Inverness
Posted: 13th Feb 2018 21:56 Edited at: 13th Feb 2018 21:59
If I'm using the internal normal mapping then I use "SetObjectNormalMap(1,2)", where the normal image is loaded as image 2.

When I grab the shader, I load the image and then use "setobjectimage(1,2,2)", where the normal image is loaded as image 2.

The shader outputs as such:



Now, what I've found (I think) is that in the gl_Fragcolor line at the bottom, there is actually no reference AT ALL to the normal texture. So, I have added in the normal texture, and I get a normal map, but with a deep blue colour.
Santman
12
Years of Service
User Offline
Joined: 15th Sep 2011
Location: Inverness
Posted: 13th Feb 2018 21:58 Edited at: 13th Feb 2018 21:59
You can see, normapmap is set to hold the pixel data from the normal image, which is then normalised. The next reference comes at the line:



However norm is not then referenced again. So form everything I've learned (which may be flawed) this shader would never draw the normals.
GaborD
6
Years of Service
User Offline
Joined: 3rd Dec 2017
Location:
Posted: 13th Feb 2018 23:26
You are using the perturbed norm in GetPSLighting, so that should work.
Have you checked if binormal and tangent are correctly generated? I had some issues with that. Switched to using fbx with saved tangent space, that works for me. If you are generating terrain on the fly, then you'd have to make sure they get calculated after creating the mesh. SetObjectNormalMap would probably trigger it but you said above you use setObjectImage instead with the custom shader, so maybe that's the issue.
janbo
15
Years of Service
User Offline
Joined: 10th Nov 2008
Location: Germany
Posted: 13th Feb 2018 23:50 Edited at: 14th Feb 2018 00:03
After suggesting he grabs the default normal mapping shader I guess its not the problem of the binormal or tangent as he would at least get some results then.
To make sure you have the right normals you can output the norm variable: gl_FragColor = vec4(norm,1.0);
I pass the TBN matrix directly from the vertexshader like so:

Also make sure you use SetObjectNormalMap to trigger AppGameKit to generate the appropriate code into the GetPSLighting function and don't overwrite it again with SetObjectImage(X,X,2).
You are not using vertex lighting right ?!
Santman
12
Years of Service
User Offline
Joined: 15th Sep 2011
Location: Inverness
Posted: 14th Feb 2018 18:41
Thanks for the advice guys, gonna look at it a little tonight. I saw the tutorial on normal mapping that showed both vertex and fragment versions, but this is the direct lift from agk.....so as it doesn't work I can only assume agk adds something at runtime or doesn't capture everything.

If I add norm to the last calc, I get a normal effect, but running through the rgb channel as the face of the plane rotates. Gonna use as a basic and try reverse engineering it from online tutorials.
Santman
12
Years of Service
User Offline
Joined: 15th Sep 2011
Location: Inverness
Posted: 14th Feb 2018 21:13
So one step closer.....found an AWESOME tutorial that had normal mapping and calculated specular shading from the normal map that didn;t take too long to adapt to AGK. Not perfect - needs to link the specular to the viewmatrix (I aim to simulate wetness with it) but it's lookin ok I think. Lets see what it looks like as part of the landscape.

puzzler2018
User Banned
Posted: 14th Feb 2018 21:25
This will be my challenge a little bit later in the year for Shadering.. Well found though and if can duplicate it then its taking AppGameKit to another world and is more than capable of dong such thing

Good luck in having a try
Santman
12
Years of Service
User Offline
Joined: 15th Sep 2011
Location: Inverness
Posted: 14th Feb 2018 21:33
I've been playing with roughness texture and now it;s looking far better, much more like "rock" in my book.

Once it's in the landscape, I'll include it with the uploaded example. FPS hit seems really negligable too.

Attachments

Login to view attachments

Login to post a reply

Server time is: 2024-03-29 11:39:36
Your offset time is: 2024-03-29 11:39:36