Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Professor Snake · Jul 23, 2013 at 08:33 PM · shadercoloraverage

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?

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image reefwirrax · Sep 30, 2013 at 07:48 AM 0
Share

this is a good question for the shader forum. I think that the colour in the surface shader is called albedo. you can probably do it in a fragment shader, and if performance is not an issue you can send the texture to the CPU, I believe it might be possible with a render texture.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by reefwirrax · Sep 30, 2013 at 08:24 AM

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.

Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Professor Snake · Sep 30, 2013 at 08:13 AM 0
Share

It should be an additional 4-ish(?) math operations per pixel, doesn't sound all that unrealistic.

avatar image Hoeloe · Sep 30, 2013 at 08:45 AM 0
Share

It's because you can't do it the way you're intending to. You would need at least two passes to do it this way, and even then, I'm pretty sure you can't save values between pixels like this. What you really need to do is calculate the colour and then use it directly, which is much more calculation.

avatar image Professor Snake · Sep 30, 2013 at 01:07 PM 0
Share

This was more or less the kind of answer i was looking for. If values can't be saved across pixels, i may as well do it on the CPU.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

17 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Material doesn't have a color property '_Color' 4 Answers

Changing Eye Colour (Colour only non-white parts of a texture?) 2 Answers

Color white does nothing consider mobile... really? 1 Answer

Transparency cube shader? 1 Answer

Shader: get nearest point light's color, direction and general custom lighting questions 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges