Add sss (subsurfacescattering)
This commit is contained in:
33
index.html
33
index.html
@@ -101,7 +101,7 @@
|
|||||||
uniform vec3 eyePos;
|
uniform vec3 eyePos;
|
||||||
uniform sampler2D displace_map;
|
uniform sampler2D displace_map;
|
||||||
|
|
||||||
vec3 lightPos = vec3(0.,0.,10.); //should be an directional light
|
vec3 lightPos = vec3(0.,0.,10.); //not used in diffuse. diffuse uses a directional light. It is only used for specular glittering.
|
||||||
vec3 lightColor = vec3(1.0,1.0,1.0);
|
vec3 lightColor = vec3(1.0,1.0,1.0);
|
||||||
|
|
||||||
//using forward difference
|
//using forward difference
|
||||||
@@ -112,10 +112,10 @@
|
|||||||
//calculate normal
|
//calculate normal
|
||||||
float gridPointDelta = (1. / 256.);
|
float gridPointDelta = (1. / 256.);
|
||||||
vec3 currPoint = vec3(0.0,0.0,displace.x);
|
vec3 currPoint = vec3(0.0,0.0,displace.x);
|
||||||
vec3 right = vec3(gridPointDelta,0.0,texture2D(displace_map,vec2(v_uv.x + gridPointDelta,v_uv.y)).x*0.1);
|
vec3 right = vec3(gridPointDelta,0.0,texture2D(displace_map,vec2(v_uv.x + gridPointDelta,v_uv.y)).x*(1./10.));
|
||||||
vec3 left = vec3(-gridPointDelta,0.0,texture2D(displace_map,vec2(v_uv.x - gridPointDelta,v_uv.y)).x*0.1);
|
vec3 left = vec3(-gridPointDelta,0.0,texture2D(displace_map,vec2(v_uv.x - gridPointDelta,v_uv.y)).x*(1./10.));
|
||||||
vec3 up = vec3(0.,gridPointDelta,texture2D(displace_map,vec2(v_uv.x ,v_uv.y + gridPointDelta)).x*0.1);
|
vec3 up = vec3(0.,gridPointDelta,texture2D(displace_map,vec2(v_uv.x ,v_uv.y + gridPointDelta)).x*(1./10.));
|
||||||
vec3 down = vec3(0.,-gridPointDelta,texture2D(displace_map,vec2(v_uv.x ,v_uv.y - gridPointDelta)).x*0.1);
|
vec3 down = vec3(0.,-gridPointDelta,texture2D(displace_map,vec2(v_uv.x ,v_uv.y - gridPointDelta)).x*(1./10.));
|
||||||
|
|
||||||
//vec3 tangent = normalize(right - currPoint);
|
//vec3 tangent = normalize(right - currPoint);
|
||||||
//vec3 biTangent = normalize(up - currPoint);
|
//vec3 biTangent = normalize(up - currPoint);
|
||||||
@@ -126,7 +126,8 @@
|
|||||||
|
|
||||||
vec3 norm = normalize(normal);
|
vec3 norm = normalize(normal);
|
||||||
norm.y *= -1.; //Normal y direction is somehow inverted
|
norm.y *= -1.; //Normal y direction is somehow inverted
|
||||||
vec3 lightDir = normalize(lightPos - v_fragPos);
|
//vec3 lightDir = normalize(lightPos - v_fragPos);
|
||||||
|
vec3 lightDir = normalize(-vec3(0.0,.0,-1.)); //sun shines in drection of -z
|
||||||
|
|
||||||
float diff = max(dot(norm,lightDir),0.0);
|
float diff = max(dot(norm,lightDir),0.0);
|
||||||
vec3 diffuse = diff * lightColor;
|
vec3 diffuse = diff * lightColor;
|
||||||
@@ -142,13 +143,23 @@
|
|||||||
float fresnel = R0 + (1. - R0)*pow((1.-dot(norm,reflec)),5.) ;
|
float fresnel = R0 + (1. - R0)*pow((1.-dot(norm,reflec)),5.) ;
|
||||||
|
|
||||||
//vec3 waterColor = vec3(34./255.,154./255.,211./255.);
|
//vec3 waterColor = vec3(34./255.,154./255.,211./255.);
|
||||||
vec3 oceanColor = vec3(0,.04,.04) * 10.; // under-sea colour
|
vec3 oceanColor = vec3(0,.4,.4); // under-sea colour
|
||||||
vec3 skyColor = vec3(1.,1.,1.);
|
vec3 skyColor = vec3(1.,1.,1.);
|
||||||
|
|
||||||
|
//Subsurface scattering
|
||||||
|
vec3 sssSun = vec3(0.,-50.,-100.0);
|
||||||
|
vec3 tosssSun = normalize(sssSun - v_fragPos);
|
||||||
|
float ssDistortion = 0.6;
|
||||||
|
float sssIntensity = 1.;
|
||||||
|
vec3 halfWay = normalize(tosssSun+norm*ssDistortion);
|
||||||
|
float ssScateringCoef = pow(clamp(dot(toCameraVector,-halfWay),0.0,1.0),5.) * sssIntensity;
|
||||||
|
|
||||||
gl_FragColor = vec4(mix(oceanColor,skyColor,fresnel).xyz, 1.);
|
//gl_FragColor=vec4(oceanColor + (oceanColor*ssScateringCoef),1.0); //Display subsurfacecatterting component
|
||||||
//gl_FragColor = vec4(result,1.0);
|
//gl_FragColor = vec4((mix(oceanColor,skyColor,fresnel).xyz), 1.); //Just display reflection component
|
||||||
//gl_FragColor = vec4(normal,1.0);
|
//gl_FragColor = vec4(diffuse * oceanColor,1.0); //Render only diffuse component
|
||||||
|
//gl_FragColor = vec4(normal,1.0); //show Normal map
|
||||||
//gl_FragColor = vec4(displace.x,displace.x,displace.x,1.0); //Show Perlin Noise texture deactivate vertex distrotion before
|
//gl_FragColor = vec4(displace.x,displace.x,displace.x,1.0); //Show Perlin Noise texture deactivate vertex distrotion before
|
||||||
|
gl_FragColor = vec4((mix(oceanColor + (oceanColor*ssScateringCoef),skyColor,fresnel).xyz), 1.0); //All combined
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
<script id="default-vs" type="x-shader/x-vertex">
|
<script id="default-vs" type="x-shader/x-vertex">
|
||||||
|
|||||||
Reference in New Issue
Block a user