Working with shaders using lookup data IOS

Discussion in 'iOS Programming' started by niralipandey, May 15, 2015.

  1. niralipandey, May 15, 2015
    Last edited by a moderator: May 15, 2015

    niralipandey macrumors newbie

    May 15, 2015
    I have lookup data(256 values) provided by one software and I want to use this data with shader as written below:


    Fragment Shader code:

    precision highp float;
     uniform sampler2D inputImageTexture;
     uniform sampler2D inputImageTexture2;
     varying vec2 textureCoordinate;
     uniform float uAmount;
     void main() {
         vec4 color = texture2D(inputImageTexture, textureCoordinate);
         vec2 pos = vec2((color.r + color.g + color.b)/ 3.0, 0.0);
         vec4 dstColor = texture2D(inputImageTexture2, pos);
         gl_FragColor = mix(
    Help me to pass this data to sampler2D inputimageTexture2.
    I am thinking that these should converted to rgb(image texture) somehow, so I can pass this to sampler2D.
  2. teagls macrumors regular

    May 16, 2013
    First you will need to convert those large numbers to rgb. I would do this by normalizing from 0.0 to 1.0. Then save the max value to restore them to their original in the shader. You can pass in the max float value in as a uniform. There might be some precision lose.

    Then for each vertex of whatever geometry you are passing you have to encode a 2D lookup into your texture. Be aware that GLSL will do interpolating for that version. You can't use flat keyword. What this means is that between vertices GLSL will do interpolation between values. So in the fragment shader when you do your lookup you will not get the exact values unless you set all the vertices of say your triangle to the same value.
  3. niralipandey thread starter macrumors newbie

    May 15, 2015
    Can you please give me brief idea how can I convert these lookup data to rgb data.
    Thank you.
  4. teagls macrumors regular

    May 16, 2013
    I would create a 16x16 texture to get your 256 values. Shift your data to unsigned chars. To do this find the max value and normalize the data from 0 to 255. Then put all the values in an array you can use the same value for rgb channel
  5. niralipandey thread starter macrumors newbie

    May 15, 2015
    Thank you.

    Thank you.
    I got it that these values are 32 bit integer. I convert 32-bit integer value to RGB value.

Share This Page