# Normalizing var\_texcoord0 in a sprite fragment shader

**URL:** <https://forum.defold.com/t/normalizing-var-texcoord0-in-a-sprite-fragment-shader/75877>\
**Category:** Questions\
**Created:** [February 1, 2024, 3:41pm UTC](https://forum.defold.com/t/normalizing-var-texcoord0-in-a-sprite-fragment-shader/75877 "2024-02-01T15:41:23Z")\
**Posts on this page:** 1\
**Showing post:** 14

<div class="post-metadata">

**Author:** ![aikelb](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/aikelb/32/34293_2.png) [@aikelb](https://forum.defold.com/u/aikelb)\
**Post date:** [February 2, 2024, 9:30am UTC](https://forum.defold.com/t/normalizing-var-texcoord0-in-a-sprite-fragment-shader/75877/14 "2024-02-02T09:30:33Z")

</div>

A dither shader:

```hlsl
varying mediump vec4 position;
varying mediump vec2 var_texcoord0;

uniform lowp sampler2D texture_sampler;
uniform lowp vec4 tint;
uniform mediump vec4 nomalized_sprite_ps;
uniform mediump vec4 alpha;

float DitherPlastic(vec2 pos)
{
    return 2.0 * abs(fract(dot(pos, vec2(0.75487767, 0.56984029))) - 0.5);
}

void main()
{
	// Pre-multiply alpha since all runtime textures already are
	lowp vec4 tint_pm = vec4(tint.xyz * tint.w, tint.w);
	

    // Normalize var_texcoord0 using offset and scale
	vec2 invertedTexCoords = vec2(var_texcoord0.x, 1 - var_texcoord0.y);
    vec2 normalizedTexCoords = (invertedTexCoords - nomalized_sprite_ps.xy) / nomalized_sprite_ps.zw;
	vec2 normalizedPixel = floor(normalizedTexCoords * vec2(640,320));

	gl_FragColor = vec4(step(alpha.x, DitherPlastic(normalizedPixel)), 0,0,1);
}

```

I tried using the floor when normalizing the coords, but still have the same issue. Not sure if it can be fixed. I want to use that value as alpha.

---

_[View the full topic](https://forum.defold.com/t/normalizing-var-texcoord0-in-a-sprite-fragment-shader/75877)._
