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 / LoadShader From Single *.glsl File

Author
Message
Nieb
8
Years of Service
User Offline
Joined: 13th May 2014
Location: Lurking
Posted: 4th May 2021 10:59 Edited at: 11th Jun 2022 02:18
Here's a robust function for loading a shader from a single text file, enjoy.

The Function:


Example usage:


Example shader file:



Edit 2022-06-10

A function to quickly dump object shaders:


You can set these before using it if you don't care to go digging around to find the file:
janbo
Tower Defence Competition 2nd Place
13
Years of Service
User Offline
Joined: 10th Nov 2008
Location: Germany
Posted: 10th May 2021 15:06 Edited at: 10th May 2021 15:06
Can I suggest you try to fallback to the default shader given by AppGameKit when no Vertex or fragment shader is found ?
And why do you want to put it all into one single file ?
Nieb
8
Years of Service
User Offline
Joined: 13th May 2014
Location: Lurking
Posted: 11th May 2021 00:20 Edited at: 11th May 2021 00:29
Quote: "Can I suggest you try to fallback to the default shader given by AppGameKit when no Vertex or fragment shader is found ?"

The default shader in AppGameKit is dynamically generated based on properties of the 3D-object and other 3D-settings, probably best not to assume what the user will need.
Also, the function will return 0 in any error case. If you do SetObjectShader( objID, 0 ) it will give you a default shader.

Quote: "And why do you want to put it all into one single file ?"

I don't like switching between files while working on shaders.
janbo
Tower Defence Competition 2nd Place
13
Years of Service
User Offline
Joined: 10th Nov 2008
Location: Germany
Posted: 13th May 2021 18:11
For example you set the object up with SetObjectMeshNormalMap which generates a vertex shader with tangent bitangent and normal varyings and you don't want to type it yourself.
But you might not want to do that neccesarily when it fails I see..
Just thought if it doesnt have one you try your best to make it run by using the default shader ^^


Quote: "I don't like switching between files while working on shaders."

Okay
Nieb
8
Years of Service
User Offline
Joined: 13th May 2014
Location: Lurking
Posted: 14th May 2021 01:09
Hmm, I think I follow what you are looking for. However, this would require the shader-loader-function be aware of what object(s) it's being applied to. Something that behaves similar to how AppGameKit auto generates an objects shader is certainly possible, but implementation & usage would be quite a bit more complex.
An interesting idea. However, this is not a feature I need, so I can't justify spending time to implement it.
Nieb
8
Years of Service
User Offline
Joined: 13th May 2014
Location: Lurking
Posted: 11th Jun 2022 01:58
Updated main post to include a function to quickly dump object shaders.

Login to post a reply

Server time is: 2022-08-18 11:32:31
Your offset time is: 2022-08-18 11:32:31