Re: Groverburger's 3D Engine (g3d) v1.4 Release
Posted: Tue Nov 09, 2021 1:54 am
Löve adds an abstraction layer on top of GLSL shaders; it adds main() itself, and that main() calls effect(). Take into account that Löve is designed for 2D, not 3D; otherwise the design (at least the parameters of effect()) would have been different for sure.
With version 11.3, you can look at what exact shader code it generates for your system, with this program:
(better save the output to a file because it's long). The first `false` parameter means no GLES; if you want the GLES version change it to `true` For me, at the end of the code there's this snippet:
After `#line 0` the user code (the actual code that you passed to the shader) is inserted verbatim.
love_PixelCoord love_PixelColor is a version-dependent definition that is the variable where the fragment shader returns its result (defined to be gl_FragColor or gl_FragData in some GLSL versions, and an `out` variable in others), and is set to whatever the effect() function returns.
So, basically you have to modify the shader in such a way that instead of using main() and writing to gl_FragColor or to the out variable, it uses effect() and returns the value.
In fact, by monkey-patching that function and making it return the vertex and fragment shaders that you want, you can use a raw shader, but you better know what you're doing with respect to cross-system compatibility.
With version 11.3, you can look at what exact shader code it generates for your system, with this program:
Code: Select all
local vshader, fshader = love.graphics._shaderCodeToGLSL(false, nil,
-- add some shader here
[[vec4 effect(vec4 colour, Image tex, vec2 texpos, vec2 scrpos) {
return Texel(tex, texpos) * colour; } ]])
print(fshader)
Code: Select all
vec4 effect(vec4 vcolor, Image tex, vec2 texcoord, vec2 pixcoord);
void main() {
love_PixelColor = effect(VaryingColor, MainTex, VaryingTexCoord.st, love_PixelCoord);
}
#line 0
vec4 effect(vec4 colour, Image tex, vec2 texpos, vec2 scrpos) {
return Texel(tex, texpos) * colour; }
So, basically you have to modify the shader in such a way that instead of using main() and writing to gl_FragColor or to the out variable, it uses effect() and returns the value.
In fact, by monkey-patching that function and making it return the vertex and fragment shaders that you want, you can use a raw shader, but you better know what you're doing with respect to cross-system compatibility.