Hi, I am working on implementing a subsurface scattering light shader and have it all coded I just need to debug. I have a question I cannot solve though, say I have the attenuated light vector that has come from the light, scattered as it enters the surface of the object, and now goes to the viewers eye. What would I do with this output vector for for a mesh that has a standard Blinn-Phong shader? The image has the vector I am talking about, vector PC

With no normal map or anything, how might I slot PC into this code. I'm thinking it would replace the view direction v that I have. Someone else told me the *= it with the final colour, but that just produces weird rainbow type colours, and my light is white

It is a single scattering approximation, using cg. The paper is called subsurface texture mapping and is located here . It uses a texture to encode depth in the rgba channels, where red is the first layer, alpha is the bottom layer etc. So light enters the mesh, becomes attenuated from this texture and lots of other calculations, then leaves afaik. So I'm not really sure what to do with the light that leaves then. My current guess is that it would replace the l vector in the above code (rather than subtracting the light pos from the pixel position).

My theory now is that I could just multiply the final colour by the result. Anyone know if this is correct? My result may be wrong at the moment, its pretty blue so multiplying by the final colour is really removing most of the diffuse colour for a dark blue though....

R and V are purely directional vectors right? So my attenuated light vector must represent a direction and the intensity of the light that is returned to the viewer I think. In the above code the only thing that strikes me as close to this is the calculation of the diffuse value. Ignoring the bump map (I don't need bumped normals), does anyone know if it would be wrong to have:[source lang="cpp"]float4 diff = DiffuseIntensity * diffuse * p_omega_out;[/source]Where p_omega_out is the attenuated light intensity/direction? I think my vector needs to go from the pixel to the viewer, would this vector do that?!

Specular lighting is light that reflects off the surface, without entering the material at all, so your SSS code definately shouldn't modulate the specular contribution.

Diffuse lighting is light that refracts into the object, bounces around inside, and later re-emerges. In standard lighting models, we use the simplification that the diffuse exit points are all located at the entry point (there is no movement inside the material).

SSS expands this by making the diffuse model more advanced -- instead of just using a constant diffuse colour, you use your chosen technique (a multi-layered texture, in your case) to calculate the colouration of the diffuse light, and to calculate how far inside the material the diffuse light travels before re-emerging (which has a blurring effect on the diffuse light).Regarding attenuation: standard lighting will calculate the attenuation from the light-source to the material (from S to K in your original diagram), which affects the amount of light that reaches the surface in the first place (before it's split into diffuse-refraction/specular-reflection). In standard blinn-phong, internal diffuse attenuation is specified by a constant value: your "diffuse colour".When you extend this with SSS, the "diffuse colour" is instead calculated by the internal attenuation from K to M, and M to P -- the details of that specified by your chosen technique.

In standard blinn-phong, internal diffuse attenuation is specified by a constant value: your "diffuse colour".When you extend this with SSS, the "diffuse colour" is instead calculated by the internal attenuation from K to M, and M to P -- the details of that specified by your chosen technique

Ah okay this is interesting thank you. You see the paper assumes you just know what to do with the output vector that has been attenuated from K-M-P. So theoretically it should be okay to use it in place of a hard coded "diffuse" value I did have, e.g.:[source lang="cpp"]float4 diff = DiffuseIntensity * p_omega_out * saturate(dot(IN.worldLightDir,BumpNormal));[/source]At the moment if I output p_omega_out as a colour, the result is some pretty blurry bands of colour, so hopefully it won't damage the rest of the colour too much. (I'll post a screen cap in a few mins). Thanks

You see the paper assumes you just know what to do with the output vector that has been attenuated from K-M-P.

I'm having a hard time following any of your posts in this thread, because "attenuated light vector" doesn't seems like the right terminology for what you're trying to describe.

Also, I have no idea what p_omega_out is, or where those magic colours come from.i.e. with the information given, I can't possibly help. Note my previous post was just general advice barely connected to your posts because of this.

Perhaps you should just post your full SSS shader code, and the input textures?

Woops sorry, I've gotten so deep into this thing I'm just assuming the whole world knows what I mean by p_omega_out. I appreciate the help and even general advice is very useful. Here is another screen from the paper which should be looked at with the image from the first post.When I say p_omega_out, I mean the vector from the pixel P to the viewer.

Here is the fx composer file I have at the moment, it's rather large and based off of the algorithms in the paper which you would probably need to read in full to make sense of so I won't ask you to do that! I am applying this map as the subsurface texture map.

Yeah should've mentioned that too sorry, I am certain that data is correct. This shader is actually being used in Ogre, and it's easy to generate the texture in Ogre and the output is virtually identical to fx composer. Each rgba component in the floating point texture just holds a preset scattering coefficient value taken from this table:

So I've been working on this a while longer, and the only real conclusion I have come up with is the colour values must be wrong. I thought for a while maybe they were right and I was not doing the correct thing with the result. I was given the good advice that:

The scattered radiance should be added to the phong radiance component becausethe phong model computes the radiance at the surface only, the scattered radiance isjust more radiance coming from under the surface, to the eye.

So hopefully that might help some future googlers, now if if I could just work out the correct values to begin with! I knew the colours were too trippy