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 / GLSL shader

Author
Message
Zapa
6
Years of Service
User Offline
Joined: 20th Apr 2018
Location:
Posted: 3rd May 2018 15:27
Hi,

I'm wondering is there a way to convert a GLSL shader to AppGameKit? From what I've read in the documentation the AppGameKit shader language is based on GLSL. However all examples of GLSL shaders that I used do not work in agk. Here's an example:

.ps


.vs


The shader loads fine but when I apply it to a cube (CreateObjectBox) that cube 's color becomes black.

Shader example from here
GaborD
6
Years of Service
User Offline
Joined: 3rd Dec 2017
Location:
Posted: 3rd May 2018 17:40 Edited at: 3rd May 2018 17:57
Seems to be set up as a post shader (is looking into a prerendered sceneTex for the color info), are you providing it with a rendertex of the scene?
Also, are the threshold values and offsets set with SetShaderConstantByName?

If you want to skip all the post shenanigans and just use it as a simple object shader that takes the diffuse texture, applies stock lighting and then quickly crosshatches it, you can try something like this: (just a few changes needed)
I hardcoded the thresholds for simplicity, so that it works with any AppGameKit project, you can ofcourse put those back into uniforms and then set them from your AppGameKit code.

vs


ps


Works fine on loaded models, just need to add a stock AppGameKit light. Test-screenshot attached.
You can prolly get more performance out of it if you convert it to not use so many conditionals, but then again, it runs pretty fast as it is.

Attachments

Login to view attachments
Zapa
6
Years of Service
User Offline
Joined: 20th Apr 2018
Location:
Posted: 4th May 2018 08:09 Edited at: 4th May 2018 09:12
Hey,

Thanks for the quick reply! I applied the shader to the scene and setup some custom colors. All objects have normal maps on them. It looks good except that the back of the models/objects have no texture. It applies to all the objects loaded or created. Without the shader, their texture and normal map is applied correctly. This is how it looks like:



I also created a point light and set it's position to the camera's position. Switched it's PointLightMode between Vertex and Pixel. Lighting seems to not influence the scene and I'm wondering if GetPSLighting actually does anything.

This can be recreated using your code with just the TC vallues being changed a bit to give the mathpaper outline colors.
Can you point me in the right direction?

Edit: It seems that by modifying the amb value get's all faces to shade properly. Now only the light problems remains.
fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 8th May 2018 18:52 Edited at: 8th May 2018 19:13
For light to have an effect when a shader is used you have to add "varying mediump vec3 lightVarying;"
it has to be in the vs shader and ps shader you then multiply by lightvaring when you are setting the pixels
an example of a color being set for a pixel is something like this
the above is only a snippet and part of what I think needs to be added but should give you an idea
on whats needed to be added because you need light varying and possibly may want to add fog later
the thread Useful Community shaders has allot of example shaders and altho is quite large should
help explain allot of these conceptshttps://forum.thegamecreators.com/thread/214598 and
when you get it sorted the way you like it would be great to share there for others to see and use

The AppGameKit Documentation also tries to clarify this and has a list down the bottom Shader Variables
and explains allot about using shaders in AppGameKit https://www.appgamekit.com/documentation/guides/13_shaders.htm
Which should help with converting shaders
fubar

Login to post a reply

Server time is: 2024-11-23 20:12:45
Your offset time is: 2024-11-23 20:12:45