Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var createScene = function () {
- var scene = new BABYLON.Scene(engine);
- scene.defaultMaterial.dispose()
- scene.defaultMaterial = new BABYLON.CellMaterial("cell", scene)
- scene.defaultMaterial.specularColor = new BABYLON.Color3.Black()
- scene.defaultMaterial.computeHighLevel = true
- scene.ambientColor = BABYLON.Color3.Black()
- scene.fogEnabled = true;
- scene.fogMode = BABYLON.Scene.FOGMODE_EXP;
- scene.fogColor = scene.clearColor
- scene.fogDensity = 0.07
- var camera = new BABYLON.FreeCamera("camera1", new BABYLON.Vector3(0, 5, -10), scene);
- camera.setTarget(BABYLON.Vector3.Zero());
- camera.attachControl(canvas, true);
- var defaultpipeline = new BABYLON.DefaultRenderingPipeline("Default", false, scene, [camera])
- var tonemappingpipeline = new BABYLON.TonemapPostProcess("Tonemapping", BABYLON.TonemappingOperator.HejiDawson, devicePixelRatio, camera)
- var imageprocesspipeline = new BABYLON.ImageProcessingPostProcess("ImageProcessing", devicePixelRatio, camera)
- imageprocesspipeline.exposure = 1.4
- BABYLON.Effect.ShadersStore["customVertexShader"]=
- "precision highp float;\r\n"+
- "// Attributes\r\n"+
- "attribute vec3 position;\r\n"+
- "attribute vec2 uv;\r\n"+
- "// Uniforms\r\n"+
- "uniform mat4 worldViewProjection;\r\n"+
- "// Varying\r\n"+
- "varying vec2 vUV;\r\n"+
- "void main(void) {\r\n"+
- " vec3 f = position;\r\n"+
- " //f.y = 0.0;\r\n"+
- " gl_Position = worldViewProjection * vec4(f, 1.0);\r\n"+
- " vUV = uv;\r\n"+
- "}\r\n";
- BABYLON.Effect.ShadersStore["customFragmentShader"]=
- "precision highp float;\r\n"+
- "varying vec2 vUV;\r\n"+
- "uniform sampler2D textureSampler;\r\n"+
- "uniform float time;\r\n"+
- "uniform vec4 sky1;\r\n"+
- "uniform vec4 sky2;\r\n"+
- "uniform float a;\r\n"+
- "// Sky Gradient by Hazel Quantock\r\n"+
- "#define sphere false\r\n"+
- "#define ground true\r\n"+
- "// quick and pretty sky colour\r\n"+
- "vec3 SkyColour( vec3 ray )\r\n"+
- "{\r\n"+
- " return exp2(-ray.y/vec3(.1,.3,.6)); // blue\r\n"+
- "// return exp2(-ray.y/vec3(.18,.2,.28))*vec3(1,.95,.8); // overcast\r\n"+
- "// return exp2(-ray.y/vec3(.1,.2,.8))*vec3(1,.75,.5); // dusk\r\n"+
- "// return exp2(-ray.y/vec3(.03,.2,.9)); // tropical blue\r\n"+
- "// return exp2(-ray.y/vec3(.4,.06,.01)); // orange-red\r\n"+
- "// return exp2(-ray.y/vec3(.1,.2,.01)); // green\r\n"+
- "}\r\n"+
- "vec4 finalImage(vec2 fragCoord, vec2 resolution )\r\n"+
- "{\r\n"+
- " vec3 ray;\r\n"+
- " ray.xy = (fragCoord - resolution.xy*.5)/resolution.y;\r\n"+
- " ray.y -= 0.59;\r\n"+
- " ray.z = .7;\r\n"+
- " //ray.z -= dot(ray.xy,ray.xy)*.5; // fisheye lens\r\n"+
- " ray = normalize(ray);\r\n"+
- " \r\n"+
- " // tilt upwards\r\n"+
- " vec3 k = normalize(vec3(0,sphere?-.5:.8,1));\r\n"+
- " vec3 i = normalize(cross(vec3(0,1,0),k));\r\n"+
- " vec3 j = cross(k,i);\r\n"+
- " ray = ray.x*i+ray.y*j+ray.z*k;\r\n"+
- " \r\n"+
- " if ( sphere )\r\n"+
- " {\r\n"+
- " // reflect ray off sphere\r\n"+
- " vec3 c = k*1.8;\r\n"+
- " float t = dot(c,ray);\r\n"+
- " float t2 = sqrt(dot(c,c)-t*t);\r\n"+
- " if ( t2 < 1. )\r\n"+
- " {\r\n"+
- " t -= sqrt(1.-t2*t2);\r\n"+
- " vec3 n = ray*t-c;\r\n"+
- " ray = reflect(ray,n);\r\n"+
- " }\r\n"+
- " }\r\n"+
- " \r\n"+
- " vec3 tint = vec3(1);\r\n"+
- " if ( ground && ray.y < .0 )\r\n"+
- " {\r\n"+
- " ray.y = -ray.y;\r\n"+
- " tint = mix( vec3(.2), tint, pow(1.-ray.y,10.) );\r\n"+
- " }\r\n"+
- " \r\n"+
- " vec4 fragColor;\r\n"+
- " \r\n"+
- " vec4 mixS = mix(exp2(-ray.y/sky1), exp2(-ray.y/sky2), a);\r\n"+
- " fragColor.xyzw = mixS*vec4(tint, 1.0);//SkyColour( ray )*tint;\r\n"+
- " \r\n"+
- " // signature\r\n"+
- " #define L(m,n,u,v,l,f) min(f,max(abs(dot(fragCoord-vec2(m,n),vec2(u,v)))-l,abs(dot(fragCoord-vec2(m,n),vec2(-v,u)))-1.))\r\n"+
- " float sig=L(3,7,0,1,3.5,L(7,7,0,1,3.5,L(5,7,1,0,2.,L(14.5,5,.7071,-.7071,2.5,abs(length(fragCoord-vec2(12.7,7))-3.)-1.))));\r\n"+
- " fragColor = .6+(clamp(fragColor,0.,1.)-.6)*sig/(.1+abs(sig));\r\n"+
- " \r\n"+
- " fragColor.xyz = pow(fragColor.xyz,vec3(1./2.2));\r\n"+
- " //fragColor.w = 0.5;\r\n"+
- " \r\n"+
- " return fragColor;\r\n"+
- "}\r\n"+
- "void main(void) {\r\n"+
- " //gl_FragColor = texture2D(textureSampler, vUV);\r\n"+
- " \r\n"+
- " /*vec3 col;\r\n"+
- " \r\n"+
- " vec3 _SkyTint = vec3(1.9,0.55,0);//vec3(1.0, 0.4, 0.1);\r\n"+
- " vec3 _GroundColor = vec3(0.226,0.000,0.615);//vec3(0.0, 0.0, 0.0);\r\n"+
- " \r\n"+
- " float p = vUV.y+cos(time);\r\n"+
- " float p1 = pow(min(1.0, 1.0 - p), 2.0);\r\n"+
- " col.x = smoothstep(_GroundColor.x, _SkyTint.x, p1);\r\n"+
- " col.y = smoothstep(_GroundColor.y, _SkyTint.y, p1);\r\n"+
- " col.z = smoothstep(_GroundColor.z, _SkyTint.z, p1);\r\n"+
- " \r\n"+
- " gl_FragColor = vec4(1.0-col, 1.0);*/\r\n"+
- " \r\n"+
- " gl_FragColor = finalImage(vUV, vec2(1.0, 1.0));\r\n"+
- " \r\n"+
- "}\r\n";
- var light = new BABYLON.DirectionalLight("Light1", new BABYLON.Vector3(0, -1, 1), scene);
- light.intensity = 1
- light.position = new BABYLON.Vector3(0, 5, -5)
- light.shadowEnabled = true;
- var shadowGenerator = new BABYLON.ShadowGenerator(1024, light);
- shadowGenerator.useBlurExponentialShadowMap = true;
- var sphere = BABYLON.MeshBuilder.CreateSphere("sphere", { diameter: 2, segments: 32 }, scene);
- sphere.position.y = 1;
- shadowGenerator.addShadowCaster(sphere);
- var ground = BABYLON.MeshBuilder.CreateGround("ground", { width: 50, height: 50, segments: 30 }, scene);
- ground.receiveShadows = true
- return scene;
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement