Add sun glitter

This commit is contained in:
Julian
2020-01-29 21:23:25 +01:00
parent f9408474a2
commit 1f8e050bb5
2 changed files with 20 additions and 15 deletions

View File

@@ -81,7 +81,7 @@
float n = octavedPerlinNoise(vec3(gl_FragCoord.x*0.001,gl_FragCoord.y*0.003+uTime*0.00005,uTime*0.00005),8,2.6); //Should be scaled along arbitary axis float n = octavedPerlinNoise(vec3(gl_FragCoord.x*0.001,gl_FragCoord.y*0.003+uTime*0.00005,uTime*0.00005),8,2.6); //Should be scaled along arbitary axis
//float n = noise(vec3(gl_FragCoord.xy*0.01,uTime)); //float n = noise(vec3(gl_FragCoord.xy*0.01,uTime));
//vec3 cloudEffect = clouds(gl_FragCoord.x*0.005, gl_FragCoord.y*0.005); //vec3 cloudEffect = clouds(gl_FragCoord.x*0.005, gl_FragCoord.y*0.005);
vec3 color = vec3(n) + (vec3(1., 1., 1.)/2.); //Scales the height off the waves (/8.0) vec3 color = vec3(n) * 0.3;
gl_FragColor = vec4(color,1.0); gl_FragColor = vec4(color,1.0);
} }
</script> </script>
@@ -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*(1./10.)); vec3 right = vec3(gridPointDelta,0.0,texture2D(displace_map,vec2(v_uv.x + gridPointDelta,v_uv.y)).x*(1./1.));
vec3 left = 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*(1./1.));
vec3 up = vec3(0.,gridPointDelta,texture2D(displace_map,vec2(v_uv.x ,v_uv.y + gridPointDelta)).x*(1./10.)); vec3 up = vec3(0.,gridPointDelta,texture2D(displace_map,vec2(v_uv.x ,v_uv.y + gridPointDelta)).x*(1./1.));
vec3 down = 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*(1./1.));
//vec3 tangent = normalize(right - currPoint); //vec3 tangent = normalize(right - currPoint);
//vec3 biTangent = normalize(up - currPoint); //vec3 biTangent = normalize(up - currPoint);
@@ -147,19 +147,27 @@
vec3 skyColor = vec3(1.,1.,1.); vec3 skyColor = vec3(1.,1.,1.);
//Subsurface scattering //Subsurface scattering
vec3 sssSun = vec3(0.,-50.,-100.0); vec3 sssSun = vec3(0.,-5.,-7.0);
vec3 tosssSun = normalize(sssSun - v_fragPos); vec3 tosssSunVec = normalize(sssSun - v_fragPos);
float ssDistortion = 0.6; vec3 tosssSun = normalize(vec3(0.0,-100.,1.));
float sssIntensity = 1.; float ssDistortion = 1.;
float sssIntensity = .2;
vec3 halfWay = normalize(tosssSun+norm*ssDistortion); vec3 halfWay = normalize(tosssSun+norm*ssDistortion);
float ssScateringCoef = pow(clamp(dot(toCameraVector,-halfWay),0.0,1.0),5.) * sssIntensity; float ssScateringCoef = pow(clamp(dot(toCameraVector,-halfWay),0.0,1.0),5.) * sssIntensity;
//gl_FragColor=vec4(oceanColor + (oceanColor*ssScateringCoef),1.0); //Display subsurfacecatterting component //Sun glittering
float glitterFactor = max(0.0,dot(tosssSunVec,reflect(-toCameraVector,norm)));
if(!(glitterFactor > 0.98)) {
glitterFactor = 0.0;
}
//gl_FragColor = vec4(oceanColor + lightColor * glitterFactor,1.0);
//gl_FragColor=vec4(clamp(oceanColor + (oceanColor*ssScateringCoef),0.,1.0),1.0); //Display subsurfacecatterting component
//gl_FragColor = vec4((mix(oceanColor,skyColor,fresnel).xyz), 1.); //Just display reflection component //gl_FragColor = vec4((mix(oceanColor,skyColor,fresnel).xyz), 1.); //Just display reflection component
//gl_FragColor = vec4(diffuse * oceanColor,1.0); //Render only diffuse component //gl_FragColor = vec4(diffuse * oceanColor,1.0); //Render only diffuse component
//gl_FragColor = vec4(normal,1.0); //show Normal map //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(clamp(diffuse,0.97,1.0) * (mix(oceanColor + (oceanColor*ssScateringCoef),skyColor*0.8,fresnel).xyz), 1.0); //All combined gl_FragColor = vec4((clamp(diffuse,0.97,1.0) * (mix(oceanColor + (oceanColor*ssScateringCoef),skyColor*0.8,fresnel).xyz))+ lightColor * glitterFactor, 1.0); //All combined
} }
</script> </script>
<script id="default-vs" type="x-shader/x-vertex"> <script id="default-vs" type="x-shader/x-vertex">

View File

@@ -374,16 +374,13 @@ function drawScene() {
mat4.identity(projection); mat4.identity(projection);
mat4.perspective(projection, 1.0, viewportWidth / viewportHeight, 0.1, 1000.); //projection mode should actually be camera specific mat4.perspective(projection, 1.0, viewportWidth / viewportHeight, 0.1, 1000.); //projection mode should actually be camera specific
camera.setOffset(15.0); camera.setOffset(1.2);
camera.setRotationX((curRotX += mouseYVel * 0.001)); camera.setRotationX((curRotX += mouseYVel * 0.001));
camera.setRotationY((curRotY += mouseXVel * 0.001)); camera.setRotationY((curRotY += mouseXVel * 0.001));
var view = camera.getViewMatrix(); var view = camera.getViewMatrix();
var model = mat4.create(); var model = mat4.create();
mat4.identity(model); mat4.identity(model);
let xyScaling = vec3.create();
vec3.set(xyScaling, 10., 10., 1.0);
mat4.scale(model, model, xyScaling); //2. Then scale the surface xy by factor 10
let translationCentering = vec3.create(); let translationCentering = vec3.create();
vec3.set(translationCentering, -0.5, -0.5, 0.0); vec3.set(translationCentering, -0.5, -0.5, 0.0);
mat4.translate(model, model, translationCentering); //1. First Center the Surface in the origin. mat4.translate(model, model, translationCentering); //1. First Center the Surface in the origin.