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 7toni7 · Oct 16, 2014 at 07:03 PM · shadershaderscolorvertices

How to get the real color of the vertices in a mesh modified by a shader? [C#]

Hi all,

First of all, I have a mesh with a material and a diffuse shader attached to it. My aim is to know in each moment what is the color assigned to the vertices of the mesh, once it is illuminated by a directional light (e.g., To know in real time how the color of the vertices changes as the light changes)

How can I access (by C# code) the color values for all the vertices in my mesh once the material is being illuminated by the light.

I think I should access to a struct in the diffuse shader, like this:

  struct v2f {
           float4 pos : SV_POSITION;
           fixed4 color : COLOR;
       };

Is this correct? Thank you!

Comment
Add comment · Show 14
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 Graham-Dunnett ♦♦ · Oct 16, 2014 at 07:58 PM 0
Share

Pretty sure it's not possible to get the vertex colours computed by a shader.

avatar image KayelGee · Oct 17, 2014 at 09:52 AM 0
Share

I'm pretty sure aswell that this isn't possible. What are you trying to achieve? $$anonymous$$aybe if you tell us this we can come up with a solution.

avatar image tanoshimi · Oct 17, 2014 at 10:02 AM 0
Share

Surely by the time they've been modified by a shader, they're not really vertex colours any more? Vertex colours are attributes assigned to the mesh, which can be considered inputs to a shader operation, rather than outputs from it.

If you want to apply game logic based on the colour value of certain elements in a scene after having accounted for lighting etc. then you could write the result to a rendertexture and then read that in again?

avatar image MrSoad · Oct 17, 2014 at 11:31 AM 0
Share

Take a look at this $$anonymous$$ayelGee :

http://answers.unity3d.com/questions/810541/how-to-obtain-the-brightnesscolor-of-a-triangle.html

It should answer your question.

avatar image Bunny83 · Oct 17, 2014 at 01:27 PM 1
Share

So the 4th question on the same topic? You didn't reply to your last question. Are you going to post a new question each day?

The information you're after doesn't exist at any time. The lighting is done in the fragment shader. The fragment shader works on pixels on your screen. At this point there are no vertices anymore, only rasterized fragments of interpolated vertex attributes. At this stage the GPU doesn't even know to which triangle a certain pixel belongs. It just has the interpolated attributes (screen space position, normal vector, vertex color) and out of those it calculates the final color for this pixel. Further more realtime shadows are usually calculated in a seperate pass which just darkens certain areas on the screen.

Again at no point in this pipeline the original vertices are "lit". And once more, This is a render engine to produce an image for you to watch, not to do scientific calculations.

Show more comments

0 Replies

· Add your reply
  • Sort: 

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

6 People are following this question.

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

Related Questions

Change shader color for specific GameObject 1 Answer

Any idea on how to do a FallOff Shader...? 0 Answers

Creating a line between different colors? 0 Answers

Shader help - 2d black and white polygons where black shows one background image and white shows another -1 Answers

Material doesn't have a color property '_Color' 4 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