Average Colour of Texture in Surface Shader

Hello there,

I have a basic cube object with a RenderTexture assigned to it that acts as a monitor. I would like the monitor to light up the nearby area based on what the screen shows, so my first thought was to simply get the average colour of the RenderTexture via the shader i am using and get that from a script.

I ended up using a public colour property named _AvgColour and at the end of the surf function i called

_AvgColour.rgb+=(_AvgColour.rgb+c.rgb)*0.5f;

where c is the colour of the current texel. Unfortunately that doesn’t seem to modify the _AvgColour property at all. How else would i be able to calculate the average colour of the camera’s RenderTexture each frame?

I don’t think a surface shader will give you enough control in order to loop through every pixel and to get the average, and it’s a task that will take potentially thousands of additions which is probably too much calculation for the shader anyway. if you use vertex and fragment shader, it would be easy.