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.

I'm trying to produce a shader to replicate a white plastic object with a colored light inside. Either by having a shader that will be translucent and if I put a light inside the object the light will show through or by having a shader that fakes the effect of a light inside.

The effect im going for is kinda like a light going through a lamp shade similar to these pictures:

alt text alt text alt text

Ideally I would be able to control the strength and colour of the light to get it to pulse and rotate through some nice bright fluro colours

Though I'm not sure where to start!

My question is does anyone know the techniques I should be researching to be able to produce such a shader or have an example of the same/similar shader I can use as a starting point? Or even if you want to provide a shader that might do the job

share|improve this question
add comment

3 Answers

up vote 10 down vote accepted

This is an effect known as "Sub Surface Scattering."

There is an example screen space implementation of this in the book "GPU Pro: Advanced Rendering Techniques" that is suitable for real time use.

share|improve this answer
add comment

I don't know HLSL so I can't give an exact answer. What you basicly can to do is set the color of each fragment depending on the distance from the lightsource (ignoring any self shadowing).

In pseudocode it would be something like this:

fragment_color = light_intensity * transparency_color * lightsource_color / (attenuation * distance_to_lightsource^2)

You might also want to use a linear attenuation factor in addition to the squared to get the light to spread out more.

share|improve this answer
add comment

Does the light need to be able to move, and does the object need to be able to deform/animate? If neither of these is the case, a cheap way to do this would be to apply a monochrome texture map on the object that acts as a mask for the light; in the shader you'd sample this texture, multiply it by the current light color/strength and add to the output color.

The obvious follow-up question is how will you generate this texture? You could try painting it, if you have access to an artist or can paint textures yourself. It could also be rendered by an offline tool using raytracing or some such. I'm not familiar enough with raytracing tools to tell you in detail how to set that up, though.

A different approach might be to write a shader that samples the light behind it, using the reversed surface normal in the regular Lambert diffuse shading equation; then you'd multiply it by some mask factor like 0.5 or so and add to the output color. This would allow dynamically moving the light or geometry, and require no textures, but you probably wouldn't get results as good-looking as an offline render.

Regarding subsurface scattering: I don't think that's precisely what's wanted here because all the SSS algorithms for graphics I've seen are designed for light that comes from outside the surface, bounces around a bit and exits again, while here the light is inside.

share|improve this answer
add comment

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.