I’m sure this is just a stupid thing I’m missing, but have spend such a long time trying to figure out what i’m doing wrong.
I’m trying to create a custom material using a custom shader and attaching it to a UI element. I have boiled the code down to the bare minimum in this project
But the UI element just stops rendering, any takers on why this is happening ?
var Test = pc.createScript('test');
Test.prototype.initialize = function(){
let material = new pc.Material();
material.setShader(this.createShader());
material.update();
this.entity.element.material = material;
};
Test.prototype.createShader = function(){
var shaderDefinition = {
attributes: {
aPosition: pc.SEMANTIC_POSITION
},
vshader: [
"attribute vec3 aPosition;",
"",
"void main(void)",
"{",
" gl_Position = vec4(aPosition, 1.0);",
"}"
].join("\n"),
fshader: [
"precision " + this.app.graphicsDevice.precision + " float;",
"",
"void main(void)",
"{",
" gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);",
"}"
].join("\n")
};
var shader = new pc.Shader(this.app.graphicsDevice, shaderDefinition);
return shader;
};
So when using Spector JS I can see that the element where I created a new material is not even a drawcall, this leads me to believe that the vertex shader is wrong and the object is rendered out of view frustum.
Witch makes sense as I’m using a standard mapping that is supposed to work on the 3D objects, and not necessarily the UI objects. Will keep digging.
I have a “befor and after” side by side to ensure things are still rendering.
Cloning the shader code from the old material into the new one still results in the new one not rendering. And still not even getting a draw call trying to render it
If it’s not even a render call that means something on CPU side decided it’s not something that needs to be rendered - so it’s likely not related to the shader.
@Mads_Nielsen did you change the project since last time you posted this? I’ve just opened the linked scene (https://playcanvas.com/editor/scene/1244945) and could not reproduce the issue. Also by inspecting with SpectreJS I did see both left and right image elements as 2 separate draw calls.
Could also be that a recent deployment fixed the issue.
I know this is a few months old, but in case this is still an open issue or someone else finds this: We’ve recently added a new UI Example in our Examples Browser that showcases how to setup a custom shader on a UI Element: PlayCanvas Examples