Hello,
I have written a custom shader and am trying to apply a it to a material, but when I try to run the app, the scene partially loads and there is a Javascript error in the browser console, specifically:
playcanvas-stable.js:4782 Uncaught TypeError: Cannot read property 'ready' of undefined playcanvas-stable.js:4539 Uncaught TypeError: Cannot read property 'samplers' of undefined'
this is my shader code
pc.script.attribute('vs', 'asset'); pc.script.attribute('fs', 'asset'); pc.script.attribute('diffuseMap', 'asset');
pc.script.attribute('tint', 'rgba', [1,1,1,1]); pc.script.create('customShader', function (app) { // Creates a new CustomShader instance var CustomShader = function (entity) { this.entity = entity; };
CustomShader.prototype = {
// Called once after all resources are loaded and before the first update
initialize: function () {
this.initializeShader();
},
initializeShader: function() {
//var app = this.app;
var model = this.entity.model.model;
var gd = app.graphicsDevice;
var diffuseTexture = this.diffuseMap;
var vertexShader = this.vs;
var fragmentShader = this.fs;
var shaderDefinition = {
attributes: {
aPositon: pc.SEMANTIC_POSTION,
aUv0: pc.SEMANTIC_TEXCOORD0
},
vshader: vertexShader,
fshader: fragmentShader
};
this.shader = new pc.Shader(gd, shaderDefinition);
this.material = new pc.Material();
this.material.setShader(this.Shader);
this.material.setParameter('uDiffuseMap', diffuseTexture);
model.meshInstances[0].material = this.material;
},
update: function (dt) {
}
};
return CustomShader;
});