calculation error

This topic contains 0 replies, has 1 voice, and was last updated by  jinwoo Yoo 6 years, 11 months ago.

Viewing 1 post (of 1 total)
  • Author
    Posts
  • #30340

    jinwoo Yoo
    Member

    Hi,

    I want to calculate

    (C.r+C.g*255.0+C.b*255.0^2+C.a*255.0^3)-(C’.r+C’.g*255.0+C’.b*255.0^2+C’.a*255.0^3)

    in fragment shader, where C, C’ are pixel values.

    If input C is (38, 144, 0, 0) and C’ is (242, 143, 0, 0), result is expected (51, 0, 0, 0).

    but, actually result is (82, 0, 0, 0).

    What is the problem?

    This is part of my source code

    uniform sampler2D sTexture;

    varying mediump vec2 TexCoord;

    void main()

    {

        mediump float s = TexCoord.s;

        mediump float t = TexCoord.t;

        mediump float offsetX = 1.0/width; // width = texture width

        highp vec4 C = texture2D(sTexture, vec2(s,t));

        highp vec4 L = texture2D(sTexture, vec2(s-offsetX,t));

        highp float CC = (((((C.a*255.0)+C.b)*255.0)+C.g)*255.0)+C.r;

        highp float LL = (((((L.a*255.0)+L.b)*255.0)+L.g)*255.0)+L.r;

        highp float value = float(CC-LL)/255.0;

        gl_FragColor = vec4(value, 0.0, 0.0, 0.0);

    }

    Thanks

Viewing 1 post (of 1 total)
You must be logged in to reply to this topic.