OLD | NEW |
(Empty) | |
| 1 |
| 2 /* |
| 3 ** Copyright (c) 2012 The Khronos Group Inc. |
| 4 ** |
| 5 ** Permission is hereby granted, free of charge, to any person obtaining a |
| 6 ** copy of this software and/or associated documentation files (the |
| 7 ** "Materials"), to deal in the Materials without restriction, including |
| 8 ** without limitation the rights to use, copy, modify, merge, publish, |
| 9 ** distribute, sublicense, and/or sell copies of the Materials, and to |
| 10 ** permit persons to whom the Materials are furnished to do so, subject to |
| 11 ** the following conditions: |
| 12 ** |
| 13 ** The above copyright notice and this permission notice shall be included |
| 14 ** in all copies or substantial portions of the Materials. |
| 15 ** |
| 16 ** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 17 ** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 18 ** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
| 19 ** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY |
| 20 ** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, |
| 21 ** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE |
| 22 ** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. |
| 23 */ |
| 24 |
| 25 |
| 26 #ifdef GL_ES |
| 27 precision mediump float; |
| 28 #endif |
| 29 uniform float GrainSize; |
| 30 uniform vec3 DarkColor; |
| 31 uniform vec3 colorSpread; |
| 32 |
| 33 varying float lightIntensity; |
| 34 varying vec3 Position; |
| 35 |
| 36 void main (void) |
| 37 { |
| 38 // |
| 39 // cheap noise |
| 40 // |
| 41 vec3 location = Position; |
| 42 |
| 43 vec3 floorvec = vec3(floor(Position.x * 10.0), 0.0, floor(Position.z * 10.0)
); |
| 44 vec3 noise = Position * 10.0 - floorvec - 0.5; |
| 45 noise *= noise; |
| 46 location += noise * 0.12; |
| 47 |
| 48 // |
| 49 // distance from axis |
| 50 // |
| 51 float dist = location.x * location.x + location.z * location.z; |
| 52 float grain = dist / GrainSize; |
| 53 |
| 54 // |
| 55 // grain effects as function of distance |
| 56 // |
| 57 float brightness = fract(grain); |
| 58 if (brightness > 0.5) |
| 59 brightness = (1.0 - brightness); |
| 60 vec3 color = DarkColor + 0.5 * brightness * (colorSpread); |
| 61 |
| 62 brightness = fract(grain*7.0); |
| 63 if (brightness > 0.5) |
| 64 brightness = 1.0 - brightness; |
| 65 color -= 0.5 * brightness * colorSpread; |
| 66 |
| 67 // |
| 68 // also as a function of lines parallel to the axis |
| 69 // |
| 70 brightness = fract(grain*47.0); |
| 71 float line = fract(Position.z + Position.x); |
| 72 float snap = floor(line * 30.0) * (1.0/30.0); |
| 73 if (line < snap + 0.004) |
| 74 color -= 0.5 * brightness * colorSpread; |
| 75 |
| 76 // |
| 77 // apply lighting effects from vertex processor |
| 78 // |
| 79 color *= lightIntensity; |
| 80 color = clamp(color, 0.0, 1.0); |
| 81 |
| 82 gl_FragColor = vec4(color, 0.1) |
| 83 } |
OLD | NEW |