1 | // Generating RLE Sequence for RLE compression |
---|
2 | // |
---|
3 | // author : Byungil Jeong |
---|
4 | // |
---|
5 | |
---|
6 | uniform sampler2D colorMap; |
---|
7 | uniform vec2 winSize; |
---|
8 | uniform vec2 blockSize; |
---|
9 | uniform float blockPixels; |
---|
10 | uniform vec2 blockDim; |
---|
11 | |
---|
12 | void main(void) |
---|
13 | { |
---|
14 | const vec2 offset = vec2(1.0 / winSize.x, 1.0/winSize.y); |
---|
15 | const vec4 zeroColor = vec4(0.0); |
---|
16 | |
---|
17 | vec2 texCoord = gl_TexCoord[0].xy; |
---|
18 | vec2 pixelCoord = floor(texCoord*winSize); |
---|
19 | float pixelIdx = pixelCoord.y * winSize.x + pixelCoord.x; |
---|
20 | float blockIdx = floor(pixelIdx/blockPixels); |
---|
21 | vec2 blockPos = vec2(mod(blockIdx,blockDim.x), floor(blockIdx/blockDim.x)); |
---|
22 | float innerIdx = mod(pixelIdx,blockPixels); |
---|
23 | vec2 innerPos = vec2(mod(innerIdx,blockSize.x), floor(innerIdx/blockSize.x)); |
---|
24 | |
---|
25 | vec2 finalPos = blockPos*blockSize + innerPos; |
---|
26 | vec2 myCoord = texCoord + (finalPos - pixelCoord)*offset; |
---|
27 | vec4 myColor = texture2D(colorMap, myCoord); |
---|
28 | |
---|
29 | vec4 uniquePixel = vec4(1.0, 0.0, 0.0, 0.0); |
---|
30 | vec2 neighborCoord = vec2(myCoord.x - offset.x, myCoord.y); |
---|
31 | vec4 neighborColor = texture2D(colorMap, neighborCoord); |
---|
32 | if (myColor.rgb == neighborColor.rgb && innerPos.x > 0.0) |
---|
33 | uniquePixel.r = 0.0; |
---|
34 | |
---|
35 | gl_FragData[0] = myColor; |
---|
36 | gl_FragData[1] = uniquePixel; |
---|
37 | } |
---|