Notifications
Clear all

[Closed] Accessing Lighting and Shadow Data??

Hi All,

I trying to write a script which is able to colour the faces of a mesh object based upon their exposure to a light source whilst taking into account shadows.
Is there any way of looping through all the faces within the object and assigning colours in such a way? I have looked at “BakeElement” but this does not seem the right way to go?!

If anyone could point me in a direction that might be useful I would be very appreciative! I am struggling to see how this can be done at the moment.

[color=white]Thanks. [/color]

14 Replies

see MAX Help VertexPaint Modifier -> Assign Vertex Color rollout
and MXS Help VertexPaint : Modifier and Interface: AssignVertexColors

it seems like what are you looking for.

A while ago I posted snippets how to Assign Vertex Colors , set and control parameters. Please search in this forum for AssignVertexColors

Thanks for the quick reply, I have had a look at your recent post and will try and figure it out.

I think I am almost there, I have applied the VertexPaint modifier (manually at the moment) and assigned an object’s faces with colours. I now just need to find a way of accessing this data so that I can get each face and its colour as an rgb value.

Thanks again.

Hi again,

Im still having no luck with this, I thought I had it but I am still struggling. Let me explain what I need to do:
I have a scene with an object in it and a light source. I need a script that tests the surface colour of each face of the object (using VertexPaint perhaps) with respect to shadows and then allows me to access information from each face about how much light it is receiving (using an rgb value perhaps).
The colours that each face get changed too do not really matter, the purpose of the script is to analyse the objects form and which parts are capturing the light.

To do this am I still needing VertexPaint? Im sorry to ask again, I have just been getting no-where with this and it seems like it should be an easy task!

Any help would be great.

Thanks.

when you talk about shadow do you mean self-shadow or shadow received from other objects?

I would hope to incorporate both self-shadow and shadows from other object if possible.

1 Reply
(@denist)
Joined: 10 months ago

Posts: 0

if you want to get shadow info from other objects you have to use render to texture and baked element (Lighting Map with .shadowsOn). VertexPaint doesn’t take into account shadows from the scene.

I’m not sure the ‘lightingmap’ is what I am looking for? I don’t need to unwrap the objects material and/or save a map of the objects material with shadows applied.

What I need to do is be able to select all of the faces of the object that are in shade, partial shade or not shaded. I think the script needs to be structured something like this:

1 – Create object

2 – Apply lighting

3 – Assign colour to each face of object a ‘flat’ colour that relates to its light intensity, this could be done using an threshold analysis separating all faces into three categories: compete shade, partial shade and lit.

4 – Be able to access the colour of each face by looping through all faces later.

The part I am struggling with is being able to convert the scene’s lighting and shadow calculations of the object into variables that I can assign to individual faces and then access at a later point.

Thanks for the help so far!

1 Reply
(@denist)
Joined: 10 months ago

Posts: 0

Assign colour to each face of object a ‘flat’ colour that relates to its light intensity

That’s the KEY operation. It’s exactly what render does during calculation of lighting model. To get this information you have to render the object taking into account all light parameters (direction, intensity, falloff, attenuation, etc.). So you have to calculate the lighting model (and shadow if necessary) and bake it somewhere. The texture is the only one way to bake this data. After that using color of all three face’s vertices and probably center of the face (in bary coordinates) you will be able to calculate average irradiance for this face.

if you have some a simple light (or lights), or you know all formulas for falloff and attenuation you can calculate intensity of light for every corner of the face. All that you have to know is vertex normal, vertex position (in case of falloff or attenuation), light ray direction, and light intensity in the vertex point. So the vertex brightness will depends on angle between vertex normal and light direction, distance from light source, and initial light intensity. Any vertex that blocked from the light by other geometry doesn’t receive any light amount.

But I don’t see a reason to do it yourself if MAX render can do it for you.

[font=Arial]I agree, if I can get MAX render to do the calculations that would be ideal. I am still looking into ‘baking’ but there does not seem to be much references for me to get a handle on how it works.[/font]

[font=Arial]If I do bake the information to a texture, which still seems a unusual way to do it, how would I then collect the data from this texture?[/font]

[font=Arial]Would it be possible to generate this information from the centre point of each face by some sort of sampling process? or directly from vertices?? [/font]

you can start with something very simple. Lets say:

  1. Apply Face UVW mapping to the object
  2. Flatten UVW coordinates
  3. Render Lighting to Texture using default scanline renderer
  4. Find color of the texture pixel in center of Map face and use its value as brightness of Geo Face.

That’s it.
After that if it will be necessary you can try another more accurate method (using three corner colors).

Page 1 / 2