Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Gravitational lensing shader  (Read 3112 times)

0 Members and 1 Guest are viewing this topic.

korczurekk

  • Full Member
  • ***
  • Posts: 150
    • View Profile
    • Email
Gravitational lensing shader
« on: November 24, 2015, 07:53:05 pm »
Hi, i've tried to use gravitational lensing shader from shadertoy.com (https://www.shadertoy.com/view/Md2XWc#), but i have no idea, how to change shader on website so it can be used in my app. :/ It's that code:
// reference: http://www.photon.at/~werner/bh/gvsim.html

vec3 bh=vec3(0.0);
float bh_M=1.;

vec3 eye=vec3(0.,0.,10.);
vec3 up=vec3(0.,1.,0.);
mat3 cam_mat;// camera -> world
float tan_half_vfov=1.0;
vec2 iplane_size=2.*tan_half_vfov*vec2(iResolution.x/iResolution.y,1.);

void setupCamera()
{
        vec3 n=normalize(eye-bh);
        vec3 s=normalize(cross(up,n));
        vec3 t=cross(n,s);
        cam_mat[0]=s;
    cam_mat[1]=t;
    cam_mat[2]=n;
}

vec3 rot_y(vec3 v,float theta)
{
    float s=sin(theta),c=cos(theta);
    return vec3(c*v.x+s*v.z,v.y,c*v.z-s*v.x);    
}

void mainImage( out vec4 fragColor, in vec2 fragCoord )
{
    setupCamera();
   
    vec2 ixy=(fragCoord.xy/iResolution.xy - 0.5)*iplane_size;
    vec3 ray_dir=cam_mat*normalize(vec3(ixy.x,ixy.y,-1.));  
   
        vec3 h2e=eye-bh; float l2_h2e=dot(h2e,h2e);
    float d=length(cross(ray_dir,h2e));
        if(d>3.*bh_M)
    {
        // closest point
        vec3 cp= eye+ray_dir*sqrt(l2_h2e-d*d);
                // bend
                float alpha=4.*bh_M/d;
        ray_dir=normalize(ray_dir+tan(alpha)*normalize(bh-cp));
       
        fragColor=textureCube(iChannel0,rot_y(ray_dir,-0.2*iGlobalTime));
    }
    else
        fragColor=vec4(0.);
}
 
Thanks!

GraphicsWhale

  • Full Member
  • ***
  • Posts: 131
    • View Profile
Re: Gravitational lensing shader
« Reply #1 on: November 24, 2015, 11:55:26 pm »
It does not appear to be the same shading language as what SFML uses (which is whatever versions of GLSL OpenGL 2.0 and 2.1 use). You're going to have to re-write it in GLSL.

Hapax

  • Hero Member
  • *****
  • Posts: 3346
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Gravitational lensing shader
« Reply #2 on: November 25, 2015, 03:34:05 am »
You seem to have ignored the Shader Inputs on that link.
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

korczurekk

  • Full Member
  • ***
  • Posts: 150
    • View Profile
    • Email
Re: Gravitational lensing shader
« Reply #3 on: November 25, 2015, 02:59:57 pm »
It does not appear to be the same shading language as what SFML uses (which is whatever versions of GLSL OpenGL 2.0 and 2.1 use). You're going to have to re-write it in GLSL.
Thanks, i'll do it later and share results.

You seem to have ignored the Shader Inputs on that link.
I haven't, but i didn't know what "iChanel" etc. are. :/

Hapax

  • Hero Member
  • *****
  • Posts: 3346
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Gravitational lensing shader
« Reply #4 on: November 27, 2015, 02:55:11 am »
You seem to have ignored the Shader Inputs on that link.
I haven't, but i didn't know what "iChanel" etc. are. :/
On that link, click on "Shader Inputs". There is a list of uniforms that I would expect should be added to the shader.
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*