I threw together some quick code and it all seems to work very nicely, other than this repeating error I have that fills up my console log.
“Trying to bind current color buffer as a texture”
Link to Scene: https://playcanvas.com/editor/scene/551936
any way to get rid of this error? Or any work around for getting dynamic cubemaps working properly would be greatly appreciated!
Code:
var DynamicCubeMap = pc.createScript("dynamicCubeMap");
DynamicCubeMap.prototype.initialize = function() {
// Create a 512x512x24-bit render target with a depth buffer
var colorBuffer = new pc.Texture(this.app.graphicsDevice, {
width: 512,
height: 512,
format: pc.PIXELFORMAT_R8_G8_B8,
cubemap: true,
fixCubemapSeams: true,
autoMipmap: true
});
colorBuffer.minFilter = pc.FILTER_LINEAR;
colorBuffer.magFilter = pc.FILTER_LINEAR;
colorBuffer.addressU = pc.ADDRESS_CLAMP_TO_EDGE;
colorBuffer.addressV = pc.ADDRESS_CLAMP_TO_EDGE;
var angles = [
[ 0, 90, 180 ],
[ 0, -90, 180 ],
[ 90, 0, 0 ],
[ -90, 0, 0 ],
[ 0, 180, 180 ],
[ 0, 0, 180 ]
];
for (var i = 0; i < 6; i++) {
var renderTarget = new pc.RenderTarget(this.app.graphicsDevice, colorBuffer, {
depth: true,
face: i
});
var e = new pc.Entity();
e.addComponent('camera', {
clearColor: new pc.Color(1, 1, 1),
//aspectRatio: 1,
fov: 90
});
e.camera.aspectRatio = 1;
e.camera.renderTarget = renderTarget;
this.entity.addChild(e);
e.setLocalEulerAngles(angles[i][0], angles[i][1], angles[i][2]);
}
var sphere = this.app.root.findByName('Sphere');
sphere.model.meshInstances[0].mask = 0;
var m = sphere.model.material;
m.cubeMap = colorBuffer;
m.reflectivity = 1;
m.update();
};