// Create MOD function that acts like glsl mod, rather than HLSL's fmod. // Necessary to have consistent pattern tiling in both OGL systems (mac/linux) // and DirectX systems (windows) #define MOD(x, y) (x - y * floor(x / y)) uniform float4x4 ViewProj; uniform texture2d image; uniform float2 uv_size; uniform float pixel_size; uniform float2 tess_origin; uniform float sin_theta; uniform float cos_theta; uniform float sin_rtheta; uniform float cos_rtheta; sampler_state textureSampler{ Filter = Linear; AddressU = Clamp; AddressV = Clamp; MinLOD = 0; MaxLOD = 0; }; struct VertData { float4 pos : POSITION; float2 uv : TEXCOORD0; }; VertData mainTransform(VertData v_in) { v_in.pos = mul(float4(v_in.pos.xyz, 1.0), ViewProj); return v_in; } float4 mainImage(VertData v_in) : TARGET { // 1. Sample incoming pixel float2 coord = v_in.uv * uv_size; float2 coord_p = coord - tess_origin; // Shifted box coordinate coord_p = float2(coord_p.x * cos_theta - coord_p.y * sin_theta, coord_p.x * sin_theta + coord_p.y * cos_theta); float2 coord_grid = (coord_p - MOD(coord_p, pixel_size) + float2(pixel_size, pixel_size) / 2.0f); float2 uv_prime = (float2(coord_grid.x * cos_rtheta - coord_grid.y * sin_rtheta, coord_grid.x * sin_rtheta + coord_grid.y * cos_rtheta) + tess_origin)/uv_size; return distance(coord_grid, coord_p) <= pixel_size/2.0f ? image.Sample(textureSampler, uv_prime) : float4(0.0f, 0.0f, 0.0f, 0.0f); } technique Draw { pass { vertex_shader = mainTransform(v_in); pixel_shader = mainImage(v_in); } }