Changeset View
Changeset View
Standalone View
Standalone View
source/blender/gpu/shaders/gpu_shader_image_stipple_frag.glsl
- This file was added.
| /* Keep these in sync with GPU_basic_shader.h */ | |||||
| #define STIPPLE_HALFTONE 0 | |||||
| #define STIPPLE_QUARTTONE 1 | |||||
| #define STIPPLE_CHECKER_8PX 2 | |||||
| #define STIPPLE_HEXAGON 3 | |||||
| #define STIPPLE_DIAG_STRIPES 4 | |||||
| #define STIPPLE_DIAG_STRIPES_SWAP 5 | |||||
| #define STIPPLE_S3D_INTERLACE_ROW 6 | |||||
| #define STIPPLE_S3D_INTERLACE_ROW_SWAP 7 | |||||
| #define STIPPLE_S3D_INTERLACE_COLUMN 8 | |||||
| #define STIPPLE_S3D_INTERLACE_COLUMN_SWAP 9 | |||||
| #define STIPPLE_S3D_INTERLACE_CHECKERBOARD 10 | |||||
| #define STIPPLE_S3D_INTERLACE_CHECKERBOARD_SWAP 11 | |||||
| #if __VERSION__ == 120 | |||||
| varying vec2 texCoord_interp; | |||||
| #define fragColor gl_FragColor | |||||
| #else | |||||
| in vec2 texCoord_interp; | |||||
| out vec4 fragColor; | |||||
| #define texture2D texture | |||||
| #endif | |||||
| uniform sampler2D image; | |||||
| uniform int stipple_id; | |||||
| void stipple(in int stipple_mode) | |||||
| { | |||||
| /* We have to use mod function and integer casting. | |||||
| * This can be optimized further with the bitwise operations | |||||
| * when GLSL 1.3 is supported. */ | |||||
| if (stipple_mode == STIPPLE_HALFTONE || | |||||
| stipple_mode == STIPPLE_S3D_INTERLACE_CHECKERBOARD || | |||||
| stipple_mode == STIPPLE_S3D_INTERLACE_CHECKERBOARD_SWAP) | |||||
| { | |||||
| int result = int(mod(gl_FragCoord.x + gl_FragCoord.y, 2)); | |||||
| bool dis = result == 0; | |||||
| if (stipple_mode == STIPPLE_S3D_INTERLACE_CHECKERBOARD_SWAP) | |||||
| dis = !dis; | |||||
| if (dis) | |||||
| discard; | |||||
| } | |||||
| else if (stipple_mode == STIPPLE_QUARTTONE) { | |||||
| int mody = int(mod(gl_FragCoord.y, 4)); | |||||
| int modx = int(mod(gl_FragCoord.x, 4)); | |||||
| if (mody == 0) { | |||||
| if (modx != 2) | |||||
| discard; | |||||
| } | |||||
| else if (mody == 2) { | |||||
| if (modx != 0) | |||||
| discard; | |||||
| } | |||||
| else | |||||
| discard; | |||||
| } | |||||
| else if (stipple_mode == STIPPLE_CHECKER_8PX) { | |||||
| int result = int(mod(int(gl_FragCoord.x) / 8 + int(gl_FragCoord.y) / 8, 2)); | |||||
| if (result != 0) | |||||
| discard; | |||||
| } | |||||
| else if (stipple_mode == STIPPLE_DIAG_STRIPES) { | |||||
| int mody = int(mod(gl_FragCoord.y, 16)); | |||||
| int modx = int(mod(gl_FragCoord.x, 16)); | |||||
| if ((16 - modx > mody && mody > 8 - modx) || mody > 24 - modx) | |||||
| discard; | |||||
| } | |||||
| else if (stipple_mode == STIPPLE_DIAG_STRIPES_SWAP) { | |||||
| int mody = int(mod(gl_FragCoord.y, 16)); | |||||
| int modx = int(mod(gl_FragCoord.x, 16)); | |||||
| if (!((16 - modx > mody && mody > 8 - modx) || mody > 24 - modx)) | |||||
| discard; | |||||
| } | |||||
| else if (stipple_mode == STIPPLE_S3D_INTERLACE_ROW || stipple_mode == STIPPLE_S3D_INTERLACE_ROW_SWAP) { | |||||
| int result = int(mod(gl_FragCoord.y, 2)); | |||||
| bool dis = result == 0; | |||||
| if (stipple_mode == STIPPLE_S3D_INTERLACE_ROW_SWAP) | |||||
| dis = !dis; | |||||
| if (dis) | |||||
| discard; | |||||
| } | |||||
| else if (stipple_mode == STIPPLE_S3D_INTERLACE_COLUMN || stipple_mode == STIPPLE_S3D_INTERLACE_COLUMN_SWAP) { | |||||
| int result = int(mod(gl_FragCoord.x, 2)); | |||||
| bool dis = result != 0; | |||||
| if (stipple_mode == STIPPLE_S3D_INTERLACE_COLUMN_SWAP) | |||||
| dis = !dis; | |||||
| if (dis) | |||||
| discard; | |||||
| } | |||||
| else if (stipple_mode == STIPPLE_HEXAGON) { | |||||
| int mody = int(mod(gl_FragCoord.y, 2)); | |||||
| int modx = int(mod(gl_FragCoord.x, 4)); | |||||
| if (mody != 0) { | |||||
| if (modx != 1) | |||||
| discard; | |||||
| } | |||||
| else { | |||||
| if (modx != 3) | |||||
| discard; | |||||
| } | |||||
| } | |||||
| } | |||||
| void main() | |||||
| { | |||||
| stipple(stipple_id); | |||||
| fragColor = texture2D(image, texCoord_interp); | |||||
| fragColor.r = 0.0f; | |||||
| } | |||||