I am trying to implement a simple Shader that demonstrates Bayer dithering in a 2D context. When I try to run the following code…
class DitherShader extends hxsl.Shader {
static var SRC = {
@:import h3d.shader.Base2d;
@param var texture : Sampler2D;
@param var scale = 1.0;
function findClosest(x : Int, y : Int, c0 : Float, dither : Int) : Float{
var limit = 0.0;
if(x < 8){limit = dither/64.0;}
if(c0 < limit){return 0.0;}
else{return 1.0;}
}
function fragment() {
var dither = [[0, 32, 8, 40, 2, 34, 10, 42],
[48, 16, 56, 24, 50, 18, 58, 26],
[12, 44, 4, 36, 14, 46, 6, 38],
[60, 28, 52, 20, 62, 30, 54, 22],
[3, 35, 11, 43, 1, 33, 9, 41],
[51, 19, 59, 27, 49, 17, 57, 25],
[15, 47, 7, 39, 13, 45, 5, 37],
[63, 31, 55, 23, 61, 29, 53, 21]];
var rgb = texture.get(calculatedUV);
var xy = calculatedUV.xy * scale;
var x = int(mod((xy.x/240),8)); ///240
var y = int(mod((xy.y)/135,8)); ///135
var finalRGB : Vec3;
finalRGB.r = findClosest(x,y,rgb.r,dither[x][y+1]);
finalRGB.g = findClosest(x,y,rgb.g,dither[x][y+1]);
finalRGB.b = findClosest(x,y,rgb.b,dither[x][y+1]);
pixelColor = vec4(finalRGB, 1.0);
}
};
}
Heaps returns with an error saying “Int[8] should be Int[8] at [16,13]”
I am new to HXSL and shaders in general. Could someone point me in the right direction here? I’m not sure if HXSL supports Arrays or maybe the syntax/declaration is different, but I feel as though I’ve tried everything to get it working.
Any feedback would be appreciated. Thanks!