Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 2 of 2

Thread: Weird texturing behaviour

  1. #1
    Newbie Newbie
    Join Date
    Feb 2014
    Posts
    1

    Weird texturing behaviour

    hi,

    I have a shader that computes a displacement map to be applied to a VBO.

    In the main() function you can see I use a texture (heightmap), and add some sine waves for effect.

    Here is the problem :

    Code :
    void main()
    {
    	float d = amplitude * displace( gl_TexCoord[0].xy );
    	float c = texture2D(tex, gl_TexCoord[0]).r;
    	gl_FragColor = vec4(d , 0.0, 0.0, 1.0 );
    }

    The above works. The wave texture (d) is generated, c (the heightmap) is not used.

    Code :
    void main()
    {
    	float d = amplitude * displace( gl_TexCoord[0].xy );
    	float c = texture2D(tex, gl_TexCoord[0]).r;
    	gl_FragColor = vec4(c, 0.0, 0.0, 1.0 );
    }

    The above works. c (the heightmap) is successfully used to the texture.

    Code :
    void main()
    {
    	float d = amplitude * displace( gl_TexCoord[0].xy );
    	float c = texture2D(tex, gl_TexCoord[0]).r;
    	gl_FragColor = vec4( c + d, 0.0, 0.0, 1.0 );
    }

    The above does not work. Only d (the sine waves) is taken into account, somehow c (the heightmap) is completely ignored.

    Here is the full code :

    Code :
    #version 120
     
    uniform float		time;
    uniform float		amplitude;
    uniform sampler2D	tex;
     
    float wave( float period )
    {
    	return sin( period * 6.283185 );
    }
     
    // calculate displacement based on uv coordinate
    float displace( vec2 uv )
    {
    	// large up and down movement
    	float d = wave( (uv.x * 0.5) - time * 0.01 );
    	// add a large wave from left to right
    	d -= 0.9 * wave( (uv.x * 0.9) - time * 0.04 );
    	// add diagonal waves from back to front
    	d -= 0.25 * wave( ((uv.x + uv.y) * 2.2) - time * 0.05 );
    	// add additional waves for increased complexity
    	d += 0.25 * wave( (uv.y * 1.2) - time * 0.01 );
    	d -= 0.15 * wave( ((uv.y + uv.x) * 2.8) - time * 0.09 );
    	d += 0.15 * wave( ((uv.y - uv.x) * 1.9) - time * 0.08 );
    	d += 0.20 * wave( (uv.y * 2.5) - time * 0.04);
    	d += 0.35 * wave( (uv.y * 1.2) - time * 0.03 );
    	d -= 0.40 * wave( ((uv.y + uv.x) * 2.8) - time * 0.1 );
    	d += 0.60 * wave( ((uv.y - uv.x) * 1.9) - time * 0.2 );
    	d += 0.50 * wave( (uv.y * 2.5) - time * 0.06);
     
    	return d;
    }
     
    void main()
    {
    	float d = amplitude * displace( gl_TexCoord[0].xy );
    	float c = texture2D(tex, gl_TexCoord[0]).r;
    	gl_FragColor = vec4( c + d, 0.0, 0.0, 1.0 );
    }
    Last edited by Kevinnn; 02-10-2014 at 01:59 AM.

  2. #2
    Senior Member OpenGL Pro
    Join Date
    Jan 2012
    Location
    Australia
    Posts
    1,105
    If the combine value still in the range 0-1?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •