Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Example Fragment Shader
- * Sets the color and alpha of the pixel by setting gl_FragColor
- */
- // Set the precision for data types used in this shader
- precision highp float;
- precision highp int;
- // Default THREE.js uniforms available to both fragment and vertex shader
- uniform mat4 modelMatrix;
- uniform mat4 modelViewMatrix;
- uniform mat4 projectionMatrix;
- uniform mat4 viewMatrix;
- uniform mat3 normalMatrix;
- // Default uniforms provided by ShaderFrog.
- uniform vec3 cameraPosition;
- uniform float time;
- uniform sampler2D noise;
- // A uniform unique to this shader. You can modify it to the using the form
- // below the shader preview. Any uniform you add is automatically given a form
- uniform vec3 color;
- // Example varyings passed from the vertex shader
- varying vec3 vPosition;
- varying vec3 vNormal;
- varying vec2 vUv;
- varying vec2 vUv2;
- void main() {
- // Fragment shaders set the gl_FragColor, which is a vector4 of
- // ( red, green, lue, alpha ).
- float steps = 24.0;
- float step = 1.0 / steps;
- float scale = 0.3;
- float minv = 0.4;
- float maxv = 0.8;
- vec3 top = vec3(1.0, 0.0, 0.0);
- vec3 side = vec3(0.5, 0.5, 0.5);
- float h;
- vec3 col;
- vec2 base = vUv * scale;
- for (int i = -3; i < 3; i++) {
- vec2 ccoord = ((vUv + vec2(0, float(i) * step)) * steps) / steps * scale;
- vec2 coord = floor((vUv + vec2(0, float(i) * step)) * steps) / steps * scale;
- gl_FragColor = vec4(texture2D(noise, coord));
- //return;
- int th = 6 - (i + 3);
- h = texture2D(noise, ccoord).r;
- h = (h - minv) / (maxv - minv);
- int hi = int(floor(h * 6.0));
- gl_FragColor = vec4(vec3(h), 1.0);
- //return;
- float shadow = 1.0 * float(6 - (i + 3)) / 6.0;
- shadow *= (base.y - ccoord.y)*steps*6.0;
- gl_FragColor = vec4(vec3(shadow), 1.0);
- //return;
- if (hi == th) {
- col = top * shadow;
- break;
- } else if (hi > th) {
- //float shadow = (h - th) * (ccoord.y - coord.y) / scale * steps;
- col = side * shadow;
- break;
- }
- }
- gl_FragColor = vec4(col, 1.0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement