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 / Bumpmapping requires Tangent.

Author
Message
OminusPrime
9
Years of Service
User Offline
Joined: 30th Jun 2015
Location:
Posted: 3rd Apr 2016 19:55
Hi Everyone ive been converting over some useful Shaders to work with AppGameKit
Proper bump mapping is one thing i think we all need but it requires a Tangent reference to be passed in from AGK. Ive found ways to fake it like getting the Dot Product between the normal vector and the light vector or use some other reference point. But this only works for floors or walls not all objects.
also if you start flying around a cube with bump map applied it works on one or two sizes then messes up as the Dot Product Tangent misalignment with the UV Coordinates.
in the community shader project thread there are examples of bump mapping but they all have this misalignment problem.

Does AppGameKit have any way of passing a Vertex Attribute Tangent or alternatively is there any way to quickly Calculate it. note that the tangent needs to be aligned with U of the UV or Misalignment occurs.

I have researched and there are several ways of calculating it from Normals and UVs but this will be at the expense of further computation .
I Would rather not precompute Tangents. does anyone have any ideas ??

Thks

Preben
AGK Studio Developer
20
Years of Service
User Offline
Joined: 30th Jun 2004
Location:
Posted: 5th Apr 2016 14:19
Hi,

Until tangent is available , perhaps you could use bump ( heightmap ) mapping instead of normal mapping.



Not mush difference , normal is better but not mush. heightmap ( bump ) is grayscale only so you can pack it inside your textures in the Alpha channel ( if your objects are not transparent ) , this way you only have one texture that also include the heightmap.

The calculation for a heightmap is mush faster , i use something like this:

color = rocktex.rgb * (clamp( dot( (rocktex.aaa-0.50)*(1.50), LightDir), 0.30, 0.85)+0.50);

( this assumes that the heightmap is baked into the texture "rocktex.aaa" , you could also just use a separate texture for the bump map and use bumptex.rgb instead of rocktex.aaa. )

light direction is set in vertex like this:

LightDir = dot(-ldir,norm)*vec3(1.0) ;

Its a really fast way of doing bump mapping ( height mapping ).


best regards Preben Eriksen,
janbo
15
Years of Service
User Offline
Joined: 10th Nov 2008
Location: Germany
Posted: 5th Apr 2016 15:59 Edited at: 5th Apr 2016 20:58
You will need Tangents for both techniques to work properly.
I think your example does only work on flat surfaces not?

Using AGKv2 Tier1
Preben
AGK Studio Developer
20
Years of Service
User Offline
Joined: 30th Jun 2004
Location:
Posted: 6th Apr 2016 08:49
No it use the objects normals to do the mapping , so it will work from any angle.

mediump vec3 norm = normalize(agk_WorldNormal * normal);
LightDir = dot(-ldir,norm)*vec3(1.0) ;

Sure you need light to make it work just like normal mapping , so if you look at a side that has no light, bump will look flat, normally you add just a little light to the player position so even when you see a object with no light , it will display small bumps.

But its just like calculating light, you just take the textures height map into account, thats it.

BTW: on objects where you do bump map you do not need any light calculation, the bump map calculation will do that for you ( its the same ). The sample above is just for directional light you need to add any other types of light you need to the calculation.

I use it and it works , no tangents needed.


best regards Preben Eriksen,
OminusPrime
9
Years of Service
User Offline
Joined: 30th Jun 2015
Location:
Posted: 7th Apr 2016 23:08
Hi Preben
That's an interesting idea
Ive tried your code from your first entry, I get a texture but unfortunately i think Im missing something because it isnt showing a shadowing effect. I
have a texture with a baked height map that iv'e been using in my experiments.

Do you have a vertex/pixel shader code sample. even if they are not AppGameKit compatible it will give us an idea of your method.

i see how it looks very similar to the process ive been using to calculate lighting or specular spots.

Thks

ive just spent the last two hours picking apart a directX shader converting it to GLSL for AppGameKit but now i see the UVs are all upsidedown AHHHHHHHH

Van B
Moderator
21
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 8th Apr 2016 02:20
Perhaps the normal from the vertex shader could be passed to the pixel shader, and then add the normal multiplied by the height to the normal again... (normal + mul( normal , height) ) before calculating the diffuse level.

My bet is that it'll do something - but it might not be enough to provide a decent effect.
Preben
AGK Studio Developer
20
Years of Service
User Offline
Joined: 30th Jun 2004
Location:
Posted: 12th Apr 2016 15:23
Here is another code example:

https://forum.thegamecreators.com/thread/215857#msg2574121

You can see the difference in the texture here:

https://forum.thegamecreators.com/thread/215889

So it do make a huge difference , but you need to adjust the calculation to get the result you like
best regards Preben Eriksen,

Login to post a reply

Server time is: 2024-09-29 13:33:15
Your offset time is: 2024-09-29 13:33:15