OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "GrDitherEffect.h" | 8 #include "GrDitherEffect.h" |
9 | 9 |
10 #include "gl/GrGLEffect.h" | 10 #include "gl/GrGLEffect.h" |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 // Generate a random number based on the fragment position. For this | 95 // Generate a random number based on the fragment position. For this |
96 // random number generator, we use the "GLSL rand" function | 96 // random number generator, we use the "GLSL rand" function |
97 // that seems to be floating around on the internet. It works under | 97 // that seems to be floating around on the internet. It works under |
98 // the assumption that sin(<big number>) oscillates with high frequency | 98 // the assumption that sin(<big number>) oscillates with high frequency |
99 // and sampling it will generate "randomness". Since we're using this | 99 // and sampling it will generate "randomness". Since we're using this |
100 // for rendering and not cryptography it should be OK. | 100 // for rendering and not cryptography it should be OK. |
101 | 101 |
102 // For each channel c, add the random offset to the pixel to either bump | 102 // For each channel c, add the random offset to the pixel to either bump |
103 // it up or let it remain constant during quantization. | 103 // it up or let it remain constant during quantization. |
104 builder->fsCodeAppendf("\t\tfloat r = " | 104 builder->fsCodeAppendf("\t\tfloat r = " |
105 "fract(sin(dot(%s.xy ,vec2(12.9898,78.233))) * 43758.
5453);\n", | 105 "fract(sin(dot(%s ,vec2(12.9898,78.233))) * 43758.545
3);\n", |
106 builder->fragmentPosition()); | 106 builder->fragmentPosition()); |
107 builder->fsCodeAppendf("\t\t%s = (1.0/255.0) * vec4(r, r, r, r) + %s;\n", | 107 builder->fsCodeAppendf("\t\t%s = (1.0/255.0) * vec4(r, r, r, r) + %s;\n", |
108 outputColor, GrGLSLExpr4(inputColor).c_str()); | 108 outputColor, GrGLSLExpr4(inputColor).c_str()); |
109 } | 109 } |
110 | 110 |
111 ////////////////////////////////////////////////////////////////////////////// | 111 ////////////////////////////////////////////////////////////////////////////// |
112 | 112 |
113 GrEffectRef* GrDitherEffect::Create() { | 113 GrEffectRef* GrDitherEffect::Create() { |
114 return DitherEffect::Create(); | 114 return DitherEffect::Create(); |
115 } | 115 } |
OLD | NEW |