[SOLVED] Invert colors on render texture

Is it possible to invert the colors on a render texture?

I was thinking in the direction of:

ApplyTexture.prototype.postInitialize = function() {
var layer = this.app.scene.layers.getLayerByName(this.layerName);

// get the material on the first mesh instance this script is attached to
// and apply the rendertarget from the layer to it's diffuse map
var material = this.entity.model.model.meshInstances[0].material;

{meta-code start}
material.diffuseMap = layer.renderTarget.colorBuffer.RGBA16BIT_INVERT; … or whatever that exists in that direction :-/
{meta-code end}



You could use the getSource and setSource available in any pc.Texture to get the pixels array. From there you can do your math operation to invert the colors and then upload the pixels back. But that is going to be awfully slow, especially if you are doing per frame.


It would be way faster and easier to do this on a pixel shader using the shader chunks to bind this invert function to your material. Here is a simple example on how shadder chunks work:


Ok, the last suggestion will get me to my goal … thx
For those interested in ‘alternative’ shadow generation:

1 Like