Hi all,
I’m trying to port my HLSL shader that makes a simple RGB shift and ended up with shifting the entire texture left or right instead of only shifting red, green, blue pixels.
If the pixels aren’t being separated by color, then your offset is evaluating to 0. Following your variables back, it must mean your ‘height’ and ‘width’ don’t have the correct values.
Unity has built-in shader variables for width and height in _ScreenParams.x and _ScreenParams.y.
Though you shouldn’t be using those at all. You should calculate the offsets in script, and set Property values in the shader that you can simply reference. Right now you are re-doing the pixel offset calculations for each pixel for no reason (at least 5 multiplies per pixel). You may want to calculate a different offset for each pixel, but even then you should pre-calculate hPixel and vPixel. The screen size certainly isn’t going to change between pixels in the middle of a shader pass.
Also, you texture is shifting because you are sampling from the texture coordiantes with an offset. For changing just the colour of the texture, you will want to sample the whole texture and then change specific colours by values probably passed in via a script that TheShane mentioned:
fixed4 color = tex2D(TextureSampler, input.TexCoord);
color.r *= [Some value to change colour]
color.g*= [Some value to change colour]
color.b *= [Some value to change colour]