# calculation error

**URL:** https://forums.imgtec.com/t/calculation-error/893
**Category:** PowerVR Insider
**Created:** [November 5, 2010, 3:33am UTC](https://forums.imgtec.com/t/calculation-error/893 "2010-11-05T03:33:37Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![jinwoo-yoo](https://avatars.discourse-cdn.com/v4/letter/j/b4bc9f/32.png) [@jinwoo-yoo](https://forums.imgtec.com/u/jinwoo-yoo)
#### Post date: [November 5, 2010, 3:33am UTC](https://forums.imgtec.com/t/calculation-error/893/1 "2010-11-05T03:33:37Z")

</div>

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()  
  
  
{  
  
  
&nbsp;&nbsp;&nbsp;&nbsp;mediump float s = TexCoord.s;  
  
  
&nbsp;&nbsp;&nbsp;&nbsp;mediump float t = TexCoord.t;  
  
  
&nbsp;&nbsp;&nbsp;&nbsp;mediump float offsetX = 1.0/width; // width = texture width  
  
  
&nbsp;&nbsp;&nbsp;&nbsp;highp vec4 C = texture2D(sTexture, vec2(s,t));  
  
  
&nbsp;&nbsp;&nbsp;&nbsp;highp vec4 L = texture2D(sTexture, vec2(s-offsetX,t));  
  
  
&nbsp;&nbsp;&nbsp;&nbsp;highp float CC = (((((C.a\*255.0)+C.b)\*255.0)+C.g)_255.0)+C.r;_  
  
   
_&nbsp;&nbsp;&nbsp;&nbsp;highp float LL = (((((L.a_255.0)+L.b)\*255.0)+L.g)\*255.0)+L.r;  
  
  
&nbsp;&nbsp;&nbsp;&nbsp;highp float value = float(CC-LL)/255.0;  
  
  
&nbsp;&nbsp;&nbsp;&nbsp;gl\_FragColor = vec4(value, 0.0, 0.0, 0.0);  
  
  
}  
  
  
  
  
  
Thanks
