I made a tool in maxscript in coorperation with one of my teachers to try out a new lightcaculation approach in his game-engine.
He wanted a tool that could give him information about which points were lighted by which light (splotlight). In this way he could input that information into his engine and skip light-calculations for vertices of objects he knew would not be lit, hence be able to put more lights in his scene without a significat frame-dropping.
This would also avoid light-leaking through walls ( a common problem). This happens when you have two rooms are split by a wall or ceiling and light from one room is shining trough on a wall from the other room. See figure 1.Figure 1
Also, when you would do a specular hightlight calculation based on a reflection vector of your lightsource, there exists a scenario pictured in figure 2 where you get specular light generated by the backface of a surface. This is because in HLSL the reflect function doesn't care wether the angle between your light- and normalvector is small than 90 degress. My script would just avoid the calculation of the specularity.Figure 2
How it works
You place some objects (walls, boxes etc..) in a maxscene. Then you add some spotlights. For now the script only works with spotlights since those are the only onces who really have a range. But it could be expanded to handle omnilights as well (in theory you could be a omnilight out of several spotlights).
Now max looks at all the vertices in the whole scene, for every light. Based on the position of the light, the position of the vertex and cone angle of the spotlight one can calculate (triangle-calculation) if a vertex is lit. Next it is added to the list.
The lightinformation (light-id, position, intensity, cone angle, nearattenuation, farattenuation) is written to a file as well. This could come in handy to easily load the light in the engine.
Notice that this is just a starting point. Right now the script acts a bit rough on the edges of the spotlight. The next step would be to check wether an unlit point is just next to a lit point and add it to a different list containing the edge vertices. In this way you could let the shader interpolate the lighting at the edges.
What I Did
This was a one man project.
What I've learned
- General syntax and object-properties
- Create custom meshes, rendering, texture baking.
- Writing to and from files.