2d Normal and Specular Lighting with GLSL in Defold

(Continuation of this thread)

I’ve managed to put together an example of this shading and how it could be done with multiple lights.
Thanks to @Pawel for setting the building blocks for this type of stuff in Defold.

The README.md is a walkthrough of how it works and how one would implement this for themselves. Please feel free to expand on this and optimize it.

Disclaimer: There may some sort of compatibility or version issue with HTML5 that causes the fragment program to not compile. This doesn’t work on HTML5 for now.
This issue has been fixed, and this method works with HTML5.

5 Likes

These are the errors if anyone is wondering:
In Defold 1.8.1

dmloader.js:724 ERROR:GRAPHICS: Unable to compile fragment shader.
printErr @ dmloader.js:724
dmloader.js:724 ERROR:GRAPHICS: ERROR: 0:39: '==' : wrong operand types - no operation '==' exists that takes a left-hand operand of type 'mediump float' and a right operand of type 'const int' (or there is no acceptable conversion)
printErr @ dmloader.js:724
dmloader.js:724 ERROR: 0:56: 'pow' : no matching overloaded function found
printErr @ dmloader.js:724
dmloader.js:724 ERROR: 0:59: 'max' : no matching overloaded function found
printErr @ dmloader.js:724
dmloader.js:724 ERROR: 0:64: '==' : wrong operand types - no operation '==' exists that takes a left-hand operand of type 'mediump float' and a right operand of type 'const int' (or there is no acceptable conversion)
printErr @ dmloader.js:724
dmloader.js:724 ERROR: 0:84: 'pow' : no matching overloaded function found
printErr @ dmloader.js:724
dmloader.js:724 ERROR: 0:87: 'max' : no matching overloaded function found
printErr @ dmloader.js:724
dmloader.js:724 ERROR: 0:92: '==' : wrong operand types - no operation '==' exists that takes a left-hand operand of type 'mediump float' and a right operand of type 'const int' (or there is no acceptable conversion)
printErr @ dmloader.js:724
dmloader.js:724 ERROR: 0:114: 'pow' : no matching overloaded function found
printErr @ dmloader.js:724
dmloader.js:724 ERROR: 0:117: 'max' : no matching overloaded function found
1 Like

Alright, these issues have been fixed and there is an up and running example:
https://mchlkpng.github.io/shader-test/

2 Likes