Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

Later Edit

Since there seemed to be a bit of confusion: I am asking this for purely didactic reasons, I'm not searching for the most efficient solution. Reformulated question: I'm working under Unity, and I'd like to know if it would be possible to somehow query the material + shader of each GameObject that has a Mesh Renderer attached to itself, in order to find out how much light has fallen on the 3D model. I'm not very experienced in computer graphics, so this may seem like a stupid question. I'm thinking of something along the line of pixel by pixel comparison of a texture's brightness at any given point in time.

share|improve this question
    
It depends on how you've implementing lighting in your game. Frequently those calculations are done in the shader, so it'll be difficult to get the result. But it sounds like you're talking like the material somehow does all these calculations without a performance cost. It'll cost just as much to do it outside the context of the model. –  Byte56 Jan 21 '13 at 23:20
    
Right, so it's the shader that calculates the thing. Good to know! @costs: maybe my question was ambiguous. I was thinking that instead of taking into consideration the distance between each model and the light source + the light's brightness I could somehow do... pixel by pixel comparisons on the model's texture (to see how bright they are). Not sure how to put it differently. –  Alex M. Jan 21 '13 at 23:27
add comment

2 Answers

up vote 2 down vote accepted

I'm working under Unity, and I'd like to know if it would be possible to somehow query the material + shader of each GameObject that has a Mesh Renderer attached to itself, in order to find out how much light has fallen on the 3D model.

As per Unity's documentation, Unity does not provide such functionality, so it's not possible to achieve what you want.

share|improve this answer
1  
Can you provide a link to this documentation? It would probably help later viewers. –  Josh Petrie 2 days ago
add comment

A quick and dirty solution might be to get the position and intensity of nearby light sources and calculate intensity/distance for each, taking the greatest value to be the light level (if you're just after relative levels rather than pure accuracy, such as you might want when making a minecraft clone and deciding whether creatures spawn or not depending on darkness).

share|improve this answer
3  
+1. Trying to read back lighting from the graphics system is likely to be fraught with difficulty. It's almost certainly easier and better to just use the logical position of light sources without considering the rendering side at all. –  Kylotan Jan 22 '13 at 13:18
1  
That's what I said too. I was just asking for didactic reasons, as I was curious if it would be possible to somehow decide how much light falls upon a character based on how bright the rendered materials are. –  Alex M. Jan 22 '13 at 17:58
    
If you could mark the answer as correct that'd be great (need the points!) thank you very much :) –  nospamthanks Jan 23 '13 at 13:42
1  
Well damn, I would, but your answer is basically the same as the 2nd and third paragraphs in my question. –  Alex M. Jan 23 '13 at 15:19
2  
You did not answer my question, it's that simple. –  Alex M. Jan 23 '13 at 16:20
show 2 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.