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 / learning about shaders and having some success but also problems

Author
Message
29 games
18
Years of Service
User Offline
Joined: 23rd Nov 2005
Location: not entirely sure
Posted: 16th Jan 2014 21:52 Edited at: 20th Feb 2014 15:21
update 20 feb 2014

After much faffing about I've managed to get my light shader to work on my android tablet and phone (but may not work on all devices such as the Galaxy S3). I've updated the code snippet and the download.

update:

Thanks to lilpissywilly I managed to get my shaders working and have combined them into a single shader which allows: 1 texture, 1 directional light, 2 point lights, ambient light and allows the object to be affected by the setObjectColor command:

vertex shader:


updated 20 feb 2014
Pixel shader:


AGK tier 1 code:


positions, radius and directions are floats
red, green, blue and integers with a range of 0 thru 255
ambient level is a float with a range of 0 thru 1

In the download of this post is a simple project that uses this shader.


+++++++
Original post:

As the title suggest, I've been having a go at learning shaders. With people posting some simple examples and explanations, namely Cliff Mellangard, lilpissywilly and Paul, which has been really helpful so thanks guys, it seemed like a good time to learn.

What I've managed to do is create a shader for a texture and two point lights:

vertex shader:


pixel shader:


AGK Tier 1 code to set position, range and colour:


I'm sure there's a better way to code the pixel shader but I've never done this before so I'm just pleased it works.

I then tried to do a shader for 1 texture and a directional light but it doesn't work as intended. I simply tried to make it work in the same way as the default shader but the colours come out wrong.

vertex shader:


pixel shader:


AGK Tier 1 code to set direction and colour:


edit: this project has been replaced
I've attached a project as an example of how it all works, or doesn't as the case may be, so if someone could help me out I'd really appreciate it.

Attachments

Login to view attachments
lilpissywilly
AGK Developer
13
Years of Service
User Offline
Joined: 10th Sep 2010
Location: Office Chair
Posted: 17th Jan 2014 20:38
I've only had a quick glance, but shouldn't it be:



in the last line in your pixelshader for the directional lighting.

I haven't checked the example to see what's wrong yet. I'll try to make some time and see if I can help out.

My hovercraft is full of eels
lilpissywilly
AGK Developer
13
Years of Service
User Offline
Joined: 10th Sep 2010
Location: Office Chair
Posted: 17th Jan 2014 21:02 Edited at: 17th Jan 2014 21:03
Guess I had time right away, who knew..

pixel shader:


Change in code:


I think you'll find the changes pretty obvious. I found that when clamping the color values I had to go lower than 1.0 because it was much brighter than the default shader, shown below:
vec3 color = clamp(dot(-DLightDir.xyz,norm)*DLightCol.rgb,0.2,0.7)

That 0.7 is supposed to be 1.0, but to make it look like the default 0.7 seems sufficient. Could instead clamp the values inside the code for same effect and use 1.0 in the shader.

My hovercraft is full of eels
29 games
18
Years of Service
User Offline
Joined: 23rd Nov 2005
Location: not entirely sure
Posted: 30th Jan 2014 21:06
Thanks for the help and sorry for the late reply.

The bit where I went wrong was not dividing the colour value by 255. Instead of doing that with AppGameKit code, I added a line to in the shader itself and it worked after that.

When it comes to the agk_ObjColor, it seems you only need to add that if you want the object to be affect by the setObjectColor command.

So what I've managed to do today is to combine the two shaders together and have come up with a single shader that allows for : one texture, 1 directional light, 2 point lights, setting the ambient light level and use the agk_ObColor.

I've updated the original post with the new shader.

Once again, thanks for your help.

lilpissywilly
AGK Developer
13
Years of Service
User Offline
Joined: 10th Sep 2010
Location: Office Chair
Posted: 30th Jan 2014 22:49
Nicely done

My hovercraft is full of eels
lilpissywilly
AGK Developer
13
Years of Service
User Offline
Joined: 10th Sep 2010
Location: Office Chair
Posted: 31st Jan 2014 15:11
There is a problem, android doesn't seem to like the shader. I think it's something to do with the directional light part of the shader.

I'll see if I have time to troubleshoot it.

Nice ideas tho. I feel like maybe I should read about glsl instead of using guesswork heh

My hovercraft is full of eels
29 games
18
Years of Service
User Offline
Joined: 23rd Nov 2005
Location: not entirely sure
Posted: 1st Feb 2014 00:51 Edited at: 1st Feb 2014 00:52
That's a bit annoying. I didn't try this on my android device at first but I just tried it and it doesn't work on my tablet either. Didn't someone mention that there was a problem with certain chips? I'll have a look around the forums.

[a few minutes later]

Here we are, maybe what Cliff put at the top of this thread has something to do with it. http://forum.thegamecreators.com/?m=forum_view&t=201508&b=41 Basically, I think I have to pass the values from AppGameKit to the vertex shader first and then pass them to the pixel shader. I'll have a go at that later and get back to you.

I've been guessing at this myself, I only have a vague idea of what it's all about. I did a small amount of reading on it and then just copied and expanded on what people had already done. However, I think with this as a start, i.e. not a complete failure, I feel more motivated to look at this in more depth.

29 games
18
Years of Service
User Offline
Joined: 23rd Nov 2005
Location: not entirely sure
Posted: 20th Feb 2014 15:26
I was playing around with this last night and it is the directional light that android doesn't like. More specifically the line:

vec3 fDLightCol = DLightCol/255;

And even more specifically it's the use of an integer in the division. Replacing the above line with:

vec3 fDLightCol = DLightCol/255.0;

and it works fine on my android tablet.

There are still some issues that I haven't addressed, as detailed in Cliff's post I linked to, but I don't have a suitable device to test it in so I'd be shooting in the dark. I might do it at some point but I'm only really working on this sporadically.

I've updated the pixel shader code snippet and the download in my original post anyway so people can have a play.

Login to post a reply

Server time is: 2024-03-29 09:29:13
Your offset time is: 2024-03-29 09:29:13