Results 1 to 4 of 4

Thread: counterpart to "float4 uv[8] :TEXCOORD0" in GLSL

  1. #1
    Member Contributor
    Join Date
    Jun 2011

    counterpart to "float4 uv[8] :TEXCOORD0" in GLSL

    I am implementing the Summed-Area Table algorithm. There is a statement
    Code :
    float4 uv[8]:TEXCOORD0;
    in the shader code originally written in HLSL in Slide 9 in the following slides
    Summed-Area Table AMD
    When complied in GLSL, it failed and said "OpenGL does not allow Cg-style semantics".

    Is there any way in GLSL to achieve the same effect?

  2. #2

    Re: counterpart to "float4 uv[8] :TEXCOORD0" in GLSL

    Since that seems to be part of their VSoutput, I would hazard a guess that it is a vertex shader and that uv thing is a texcoordinate input for your vertex shader.

    In GLSL version 1.10
    you use gl_MultiTexCoord0

    This is from AMD's RenderMonkey Earth example
    Code :
    #version 110
    // Earth vertex shader computes lighting coefficients.
    // Note: For optimal light animation set the RenderMonkey cycle time 
    // for predefined variables to 20 seconds.  (Found in the Edit->Preferences).
    // predefined variables used to animate light direction
    uniform float cos_time_0_2PI, sin_time_0_2PI;
    // artist variable to control season
    uniform float season;
    // varying variables passed to fragment shader
    varying float Diffuse;
    varying vec3  Specular;
    varying vec2  TexCoord;
    void main(void)
        // calculate vertex position in eye coordinates
        vec4 ecPosition = gl_ModelViewMatrix * gl_Vertex;
        // compute the transformed normal
        vec3 tnorm      = normalize(gl_NormalMatrix * gl_Normal);
        // compute the light vector pointing toward the sun, in model coordinates
        // x,y compose the longitude and z the (seasonal) lattitude of the nadir point.
        vec3 lightVec = normalize(gl_NormalMatrix * vec3(cos_time_0_2PI, season,sin_time_0_2PI));
        // compute the reflection vector
        vec3 reflectVec = reflect(-lightVec, tnorm);
        // compute a unit vector in direction of viewing position
        vec3 viewVec    = normalize(vec3 (-ecPosition));
        // Calculate specular light intensity, scale down and
        // apply a slightly yellowish tint. 
        float specIntensity = pow(max(dot(reflectVec, viewVec), 0.0), 8.0);
        specIntensity       = 0.3 * specIntensity; 
        Specular            = specIntensity * vec3 (1.0, 0.941, 0.898);
        // Calculate a diffuse light intensity
        Diffuse             = dot(lightVec, tnorm);
        // Pass texture coordinates fragment shader
        TexCoord    = vec2 (gl_MultiTexCoord0);
        TexCoord.x  = TexCoord.x;
        // output final vertex information
        gl_Position     = gl_ModelViewProjectionMatrix * gl_Vertex;

  3. #3
    Member Contributor
    Join Date
    Jun 2011

    Re: counterpart to "float4 uv[8] :TEXCOORD0" in GLSL

    Sorry, but it is a vertex shader output (an input for the fragment shader). See the original code here:
    Code :
    void satHV(
    			float4 position: POSITION,
    			float2 inUV: TEXCOORD0,
    			out float4 oPosition: POSITION,
    			out float4 uv[8]    : TEXCOORD0,
    			uniform float fPassIndex,
    			uniform float4x4 modelViewProjMatrix)
    	oPosition = mul(modelViewProjMatrix, position);
    	float passOffSet = pow(16.0, fPassIndex)/256;
    	uv[0].xy = inUV;
    	uv[0].wz = uv[0].xy - float2(passOffSet, 0);
    	for(int i = 1; i < 8; i++)
    		uv[i].xy = uv[0].xy - float2(2.0 * i * passOffSet, 0);
    		uv[i].wz = uv[0].xy - float2((2.0 * i + 1.0) * passOffSet, 0);
    I rewrote it with GLSL, like the following:
    Code :
    #version 330
    in vec3 pos;
    in vec2 inUV;
    smooth out vec4 uv[8]: TEXCOORD0;
    uniform int fPassIndex;
    void main(void){
    	gl_Position = vec4(pos, 1.0);
    	float passOffSet = pow(16.0, fPassIndex)/256;
    	uv[0].xy = inUV;
    	uv[0].wz = uv[0].xy - vec2(passOffSet, 0);
    	for(int i = 1; i < 8; i++)
    		uv[i].xy = uv[0].xy - vec2(2.0 * i * passOffSet, 0);
    		uv[i].wz = uv[0].xy - vec2((2.0 * i + 1.0) * passOffSet, 0);
    but GLSL cannot recognize that statement.

  4. #4
    Senior Member OpenGL Lord
    Join Date
    Mar 2015

    Re: counterpart to "float4 uv[8] :TEXCOORD0" in GLSL

    That's because the statement has no meaning for OpenGL.

    With the exception of separate shaders, the connection between shader outputs and inputs is done by name. If your vertex shader has a `out vec4 uv[8]`, then your fragment shader needs a corresponding `in vec4 uv[8]` to match.

    Separate shader objects allows the intersection to be made via an index, but that only works when doing dynamic linking between separate programs.

Similar Threads

  1. Switching between "arcball" and "fps-style" camera rotation
    By bsabiston in forum OpenGL: Basic Coding
    Replies: 6
    Last Post: 10-31-2017, 12:37 PM
  2. egl gles2 "function is no-op" "Mesa: User error"
    By unixmania in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 09-17-2013, 05:30 AM
  3. Replies: 1
    Last Post: 10-26-2012, 02:19 AM
  4. "best" linux dist for a "Gelato" render farm?
    By ArtificialArtOfficial in forum OpenGL: Linux
    Replies: 10
    Last Post: 12-23-2007, 01:02 PM
  5. "required extension" and "core addition"
    By wycwang in forum OpenGL ES
    Replies: 2
    Last Post: 09-19-2007, 03:11 PM

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