Part of the Khronos Group

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 2 of 2

Thread: TinyPlanet shader problem

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Junior Member Newbie
    Join Date
    Jun 2012

    TinyPlanet shader problem

    Hello, I'm using the next shader to create tiny planet images.
    The problem I'm facing is that though it renders perfectly in Desktop machines, when it comes to Android mobile devices it renders also a small square-artifact right at the center of the final image. Can anyone spot the problem? Thank you

    Code :
    varying vec2 v_texcoord;
    uniform sampler2D u_texture;
    void main()
    	float PI = 3.14159265358979323846264;
    	float HALF_PI = PI * 0.5;
    	float TWO_PI = PI * 2.0;
    	float SCALE = 0.45;
    	float PLANET_FACTOR = 4.7;
    	float cosphi0 = cos(PLANET_FACTOR);
    	float sinphi0 = sin(PLANET_FACTOR);
    	float x = (v_texcoord.x - 0.5) / SCALE;
    	float y = (0.5 - v_texcoord.y) / SCALE;
    	float rho = sqrt(x * x + y * y);
    	float c = 2.0 * atan(rho);
    	float sinc = sin(c);
    	float cosc = cos(c);
    	float lambda = atan(x * sinc, rho * cosc);
    	float phi = asin(y * sinc / rho);
    	float cosphi = cos(phi);
    	float x1 = cos(lambda) * cosphi;
    	float y1 = sin(lambda) * cosphi;
    	float z1 = sin(phi);
    	lambda = atan(y1, x1 * cosphi0 + z1 * sinphi0);
    	phi = asin(z1 * cosphi0 - x1 * sinphi0);
    	vec2 coord = vec2((lambda + PI) / TWO_PI, (phi + HALF_PI) / PI);
    	gl_FragColor = texture2D(u_texture, coord);
    Last edited by sanchiski; 02-20-2015 at 08:17 AM.

  2. #2
    Senior Member OpenGL Guru
    Join Date
    Jun 2013
    My first guess would be issues related to the precision of the trigonometric functions.

    You could try reformulating your equations to avoid some of these. A brief look at your code shows that most of the trigonometric functions can be eliminated using trigonometric identities. Primarily, the identity tan(x)=sin(x)/cos(x), the Pythagorean identity sinē(x)+cosē(x)=1, and the double-angle formulae (for sin(2x) and cos(2x) in terms of sin(x), cos(x) and/or tan(x)).

    Calculating sin/cos/tan of an angle obtained from asin/acos/atan can be done using only the four arithmetic operators and square roots, without using any trigonometric functions. Likewise for half the angle or an integer multiple of it.

Tags for this Thread

Posting Permissions

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