a year ago I did a little experiment rendering
translucent objects, but I never got around to showing it on the
The technique is based on this article and is actually quite simple:
render a shadow map from a light source, then use it to calculate the
position in view space where the light hits the object. Next,
calculate the position where it leaves the object. You then know how
far the light traveled through the object, so you can adjust the color
or brightness accordingly. You're basically calculating light
absorption. Combine this with regular ambient, diffuse and specular
light components and the result is what you see in the video.
Here's part of the fragment shader that does the light
absorption step (names in italic
are passed as attributes from the vertex shader):
unfortunately I can not share the project files, but for the shadow mapping I simply used the sample code written by Eric Renaud-Houde and used 4x4 PCF (Percentage Closer Filtering) to reduce artifacts.
I should probably also point out that you may need to tweak the values calculated for the light absorption contribution in the shader. They greatly depend on the scale of the model used.
I use a spotlight, as it is the easiest to calculate shadows for. The only other viable light type would be a directional light, but if you want to do that properly you need some partitioning of your viewing frustum, like Cascaded Shadow Maps. I usually don't have shadows on point lights, because it requires you to render at least 2 shadow maps, or even 6 in the case of cube maps, per light.
Leave a comment on Dan Ben's reply
Change topic type
Link this topic
Provide the permalink of a topic that is related to this topic