How can i pass shadow color variable to shader on a box GUI

I want to pass a variable as a secondary color to GUI box shader, i’m trying to use set_shadow or set_outline but the shadow or outline variable is not passed to the vertex shader.

Is there anyway to make the GUI box pass the shadow color variable? just like the GUI Font

You can do this using gui node properties.

gui.set_outline() and gui.set_shadow()

I’ve tried it but it is not passed to box type gui shader, it only passed if I’m using font type gui

Yup, The box node does not have properties for shadows or an outline. Only the text node does. You can create a shader for it yourself or a more straight forward approach would be to layer your nodes into a single node then you can edit colors , move it around together etc. in runtime. Here’s an example.

dmengine_QA8E6pXeWB
GUI_shadowandoutline_test.zip (4.0 KB)

1 Like

But I do not want to use it as shadow, I want use the shadow color as a extra variable for the shader

hhm I think I might understand what you are asking for now. So you want to pass a vec4 to the vertex or fragment program and use it in the shader? These are called vertex and fragment constants and also you can use vertex attributes. You can read about them here: Defold materials manual .

To use them in gui you first need to add your material to the gui outline and then assign it to a node in its properties. You must use the constant in the shader or you may get warnings. Then to change the constant you can use for example: gui.set(node, "myconst", vmath.vec4(1,1,0,1))API reference (GUI)

Here I have copied the gui material in my project, named it mygui and customized it by adding a vertex constant named “myconst” its type user and is a vec4.

I then need to use the constant in the shader or it will throw errors/warnings.

#version 140

in mediump vec3 position;
in mediump vec2 texcoord0;
in mediump vec4 color;

out mediump vec2 var_texcoord0;
out mediump vec4 var_color;

uniform vs_uniforms
{
    mediump mat4 view_proj;
    mediump vec4 myconst;
};

void main()
{
    //Use my constant or it will be removed and cause a warning. Note this is just an example
    var_dosomething = myconst;
    ////////////////////////////
    var_texcoord0 = texcoord0;
    var_color = vec4(color.rgb * color.a, color.a);
    gl_Position = view_proj * vec4(position.xyz, 1.0);
}

I add my material to the gui outline.

Then I can assign the material to a node.

and now I can use the constant in the gui script
gui.set(node, "myconst", vmath.vec4(1,1,0,1))

3 Likes

Thank you for the help

My mistake is tought only go object can define a shader variable, turns out it works on gui node to

Thank you.