Faux SSS translucency shader setup - WIP

Post Reply
User avatar
Draise
Captain
Posts: 3198
Joined: 21 Sep 2009, 19:33
Type the number ten into the box: 0
Location: Bogota, Colombia
Contact:

Faux SSS translucency shader setup - WIP

Post by Draise »

Realtime SSS translucency in GLSL - experimenting.

Hi guys, as mentioned in the Blender Forum, I have embarked on an obsessive frenzy to try implement a realtime fake SSS shader for the BGE - as I can't download anything to help me with that, nor find any good tutorials. Why am I doing this? As I am a fan of trueSpace 7.61 beta 8's (eol'd) DirectX shaders - including realtime fake SSS which are surprisingly really good - considering it's DirectX9 now 5 years old. So I tried to reproduce it, scoured the internet for hours on end, and finally attempted to make my own version.

So this is a shader node tree for GLSL- as I am still new to learning GLSL logic or Python logic - and unfortunately doesn't work with the BGE just yet..... but does work for Blenders OpenGl preview engine. Renders like 2 or 3 frames per second to file - but it's realtime in the viewport.


The basic concept was using the Local Normals on an inverted colour for an Fresnel (diffuse ramp of a material) mask to create two different biased fresnel translucence on surface only. One for the blood layer, and the other for the fat layer - sub-dermis and dermis.

I then combined them with a epidermis, and viola!

I also used a Dirty Vertex colour input to help blend in exaggerated SSS effects (could be hand painted) on the ears and some parts of the character, black being more translucent (which works from all angles, does not consider object occlusion.. yet). This is very useful for things like ears or fingers of flaps of skin, or even the tip of the nose.

Images!

Image

Image

Image

Image


Here is the shadertree I used.

Image


Here is an example video:




Please feel free to request then play with it, post your examples, or advise as to how I can improve, do it better, or share your techniques - or how you used mine. Feel free! I really want to know how you guys do realtime fake SSS translucency - be it for sculpting, fast animations rendering for webseries, or anything.



-This shader does not require a list of lights (well not yet, I will have to see how "accurate" it is).

-This does not work in the BGE as of yet......

-I have yet to test it on objects that deform, as sculpted, or a number of other things - with many lights - multi layered textures on a model with UV's, etc etc.

-I also need to learn how to use this whole thing as a node group to apply to other objects and scenes - create a mega realtime translucent node.

-I have yet to try color ramping the RGB values, which has a nice solid faux translucency to it, also to test a little more with the Multiply multi Multiply method.


And if anyone knows how to pull or nodify the faux SSS from the BG Candy version to Blender 2.70, that would be mint!


I was trying to replicate the following HLSL node shader code below. If someone could help me out with GLSL scripts or how to implement it into Blender Shader Nodes - and how to script it and use it.. I would.. love you till the end of days. If I could understand this, or get some hints as to how I can get Dot, Smoothstep and Lerp, Pow, Normalize and so forth within GLSL methods would be wonderful.

Code: Select all

void NewFunction(in RtFloat3 LV, in RtFloat3 N, in RtFloat TransRampOff, in RtFloat4 TransSampler,
in RtFloat4 TransColBack, in RtFloat4 TransColOut,
in RtFloat TransMultiplier, in RtFloat4 TransColIn, in RtFloat shine,
in RtFloat4 specular, in RtFloat4 lightcolor, in RtFloat3 eye, out RtFloat4 result,
in RtFloat4 diffuse, in RtFloat amplifier, in RtFloat4 dif, in RtFloat bias,
in RtFloat power, in RtFloat scale, in RtFloat4 edgecolor)
{
//Translucent Lighting Model from Joel Styles
RtFloat DotLN = dot(LV,N);
RtFloat Translucence = smoothstep(-TransRampOff * (TransSampler),1.0,DotLN) - smoothstep(1,1,DotLN);
RtFloat4 Colorize = lerp(TransColBack, lerp(TransColOut * TransMultiplier,TransColIn,DotLN),Translucence);

//Schlick model
RtFloat DiffuseCoef = max(0,0.75f*DotLN+amplifier);
RtFloat3 Reflection = normalize(2 * N * DotLN - LV);
RtFloat RdotV = max(dot(Reflection,eye),0);
RtFloat SchlickTerm = RdotV / (shine - (shine * RdotV) + RdotV);

// Fresnel
RtFloat NdotV_fresnel = saturate(dot(eye,N));
RtFloat Fresnel = pow(NdotV_fresnel,power) * scale + bias;
RtFloat Saturate = saturate(Fresnel);
RtFloat4 ofresnel = lerp(edgecolor, dif, Saturate);

result = (dif * Colorize * DiffuseCoef + specular * SchlickTerm) * lightcolor;
result *= ofresnel;
result.a = diffuse.a;
}

All in all, hope you like it.
froo
Captain
Posts: 2554
Joined: 22 May 2009, 12:13

Re: Faux SSS translucency shader setup - WIP

Post by froo »

That's very cool Draise! Good to see you working on shader nodes for blender. I will be getting to that eventually.
User avatar
Draise
Captain
Posts: 3198
Joined: 21 Sep 2009, 19:33
Type the number ten into the box: 0
Location: Bogota, Colombia
Contact:

Re: Faux SSS translucency shader setup - WIP

Post by Draise »

Great Froo! It's fun, simple enough. I must say, warning.. they are more limiting that trueSpaces realtime shaders, potentially. TS has a lot more nodes to work with! But.. they aren't as intuitive to use.

You can squeeze a lot more out of the material attributes that aren't immediately exposed in the node tree, let me tell you that. ;)
Post Reply