Results 1 to 3 of 3

Thread: How can I test GL_HALF_FLOAT in shader?

  1. #1
    Junior Member Newbie
    Join Date
    Jan 2013
    Posts
    13

    How can I test GL_HALF_FLOAT in shader?

    Searched a lot but not getting now

    I am passing GLushort half_float values to shader as :

    Code :
    const GLushort	iValueSize[4] = {0x3C00, 0x7BFF, 0x0400, 0x8000};
    glEnableVertexAttribArray(0);
    glVertexAttribPointer(0, 1, GL_HALF_FLOAT, GL_FALSE, 0, iValueSize)

    Vertex Shader as follows:

    Code :
    precision mediump float;
     
    in	mediump	vec4	TestVector; // have bound loaction 0 
    out		vec4	FragColor;
     
    void main(void)
    {
    	vec4	RefValue;
    	bool	bCorrect = true;
     
            RefValue.x = uintBitsToFloat(uint(0x3C00));
    	RefValue.y = uintBitsToFloat(uint(0x7BFF));
    	RefValue.z = uintBitsToFloat(uint(0x0400));
    	RefValue.w = uintBitsToFloat(uint(0x8000));
     
    //     if(TestVector.x==1.0) //passes  
            if(TestVector == RefValue) // failes
                     bCorrect = true;
     
            if (bCorrect)
    		FragColor = vec4(0.0, 1.0, 0.0, 1.0); // Green (correct)
    	else
    		FragColor = vec4(1.0, 0.0, 0.0, 1.0); // Red (incorrect)
    }

    The rendered color is always RED.
    Did lot of debugging but no getting why it is failing.

    Is it valid to get float value from uint using uintBitsToFloat(uint(0x3C00)) ?

    Thanks.

  2. #2
    Senior Member OpenGL Guru
    Join Date
    Jun 2013
    Posts
    3,104
    Quote Originally Posted by harsha View Post
    I am passing GLushort half_float values to shader as :
    Code :
    glVertexAttribPointer(0, 1, GL_HALF_FLOAT, GL_FALSE, 0, iValueSize)
    The second argument (size) has a value of 1, which says that each array element has a single component. So TestVector.x will have a value from the iValueSize array, while the y, z and w components will be 0.0, 0.0, and 1.0 respectively.

    If you have a single vertex with a vec4 attribute (rather than 4 vertices with a float attribute), set size to 4.

  3. #3
    Senior Member OpenGL Lord
    Join Date
    Mar 2015
    Posts
    6,674
    Also:

    Code :
    precision mediump float;
     
    in	mediump	vec4	TestVector; // have bound loaction 0

    This does absolutely nothing. At least, in terms of the precision. In desktop GLSL, all of the precision qualifiers are completely ignored. They're only there for OpenGL ES 2.0 compatibility; they mean nothing at all.

    All values passed to an attribute via glVertexAttribPointer will be converted to 32-bit floats when they reach the vertex shader. This is just as true if you pass integer values via glVertexAttribPointer as if you pass half-floats (if you want to feed an `ivec4`, you use glVertexAttribIPointer). All of these are just smaller ways of packing floating-point data. Your shader does not have to know or care how the data was packed.

Similar Threads

  1. Perform stencil test only if depth test fails
    By Ray1184 in forum OpenGL: Basic Coding
    Replies: 6
    Last Post: 09-23-2015, 01:21 AM
  2. Online hardware shader test system?
    By imported_JoshKlint in forum OpenGL: GLSL
    Replies: 2
    Last Post: 08-05-2015, 06:54 PM
  3. help: copy default depthbuffer to texture; test in vertex shader
    By bootstrap in forum OpenGL: Advanced Coding
    Replies: 0
    Last Post: 09-17-2013, 06:32 PM
  4. GL_HALF_FLOAT slowdow
    By Bombata in forum OpenGL: macOS
    Replies: 5
    Last Post: 03-18-2011, 07:13 AM
  5. Hello. I have this shader test, originally in HLSL
    By giugio in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 08-23-2010, 08:56 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean