Alright i’ve been trying to understand how shaders work in Defold, I know CG and have used GLSL before in another engine but I don’t see how to apply it here. I’ve read all three pages which are involved in the shader process (material, shader, and rendering) but I don’t think they do a good job in combining those into an actual use case. You only see bits and pieces of code and a few images from the material window but nothing about connecting your shader to the rendering process?
From what I understand I need to connect my material to the rendering pipeline. Does this imply that I add my material in the builtins-> default.render_script or do I make a new render script?
Atm. I’m trying to replicate the builtin sprite mat.
I have initialised the constants in the material and set a tag.
vertex shader:
uniform mediump mat4 view_proj;
// positions are in world space
attribute mediump vec4 position;
attribute mediump vec2 texcoord0;
varying mediump vec2 var_texcoord0;
void main()
{
gl_Position = view_proj * vec4(position.xyz, 1.0);
var_texcoord0 = texcoord0;
}
fragment shader
// The texture coordinate for the fragment
varying mediump vec2 var_texcoord0;
// Texture sampler input
uniform lowp sampler2D DIFFUSE_TEXTURE;
uniform lowp vec4 tint;
void main()
{
// Pre-multiply alpha since all runtime textures already are
lowp vec4 tint_pm = vec4(tint.xyz * tint.w, tint.w);
gl_FragColor = texture2D(DIFFUSE_TEXTURE, var_texcoord0.xy) * tint_pm;
}
In the builtin render script i’ve then added my new predicate in init()
self.tex_pred = render.predicate({"test"})
and draw it in the update function
render.draw(self.tex_pred)
The material is attached to a sprite but all i’m getting is black object when I run the game.
what am I missing?
btw. my material and shader files are located in main/level