Rendering a 2nd camera to a texture does seem to render lighting wrong on imported gltf materials when flipY is set to true on render target. It seems to invert the lighting direction, as turning the light by 180 degrees seems to render the object as it should appear. Here is a basic project showing the issue:
https://playcanvas.com/project/1043895/overview/dark-render-target
The flipY bool is exposed to the editor and clicking the left mouse button inverts lightdirection on x.
I use the following function for doing the rendering:
RenderToMaterial.prototype.createNewRenderTexture = function () {
var device = this.app.graphicsDevice;
// Make sure we clean up the old textures first and remove
// any references
if (this.texture && this.renderTarget) {
var oldRenderTarget = this.renderTarget;
var oldTexture = this.texture;
this.renderTarget = null;
this.texture = null;
oldRenderTarget.destroy();
oldTexture.destroy();
}
// Create a new texture based on the current width and height of
// the screen reduced by the scale
var colorBuffer = new pc.Texture(device, {
width: this.renderResolution.x,
height: this.renderResolution.y,
format: pc.PIXELFORMAT_R8_G8_B8,
autoMipmap: true
});
colorBuffer.minFilter = pc.FILTER_LINEAR;
colorBuffer.magFilter = pc.FILTER_LINEAR;
var renderTarget = new pc.RenderTarget({
colorBuffer: colorBuffer,
depth: true,
flipY: this.flipY,
samples: 2
});
this.entity.camera.renderTarget = renderTarget;
this.texture = colorBuffer;
this.renderTarget = renderTarget;
// Create a new Basic material
var material = new pc.BasicMaterial();
// Set the material to have a texture map that is multiplied by a red color
//material.color.set(10, 10, 10);
material.colorMap = this.texture;
// Notify the material that it has been modified
material.update();
if (this.target.element)
this.target.element.texture = this.texture;
if (this.target.render)
this.target.render.meshInstances[0].material = material;
};