Jump to content

Stereographic Camera


Recommended Posts

Hi All,


Am looking for some advice.


Am currently working on a project the will display a mesh on a scene. this will them be projected inside a dome with a warped lens.


For this to look correct when projected I need to warp the scene like this.



So I was wondering is I could do this via a custom camera that would inherit from the standard Arc camera but display the scene like the above image.


I have come across this project on GitHub that has a shader that  warps google map images how I would want me scene to warp



So I was wondering is there was any tutorials or examples on how to attach a shader to a camera or scene?


Any help would be great!

Link to comment
Share on other sites

My Chrome says: http://www.babylonjs-playground.com/Babylon/Shaders/customFragmentShader.fragment.fx Failed to load resource: the server responded with a status of 404 (Not Found)


..as the first error. Not sure why it is looking for that file but it seems missing.


Did you already get it working in the CYOS? I tried copying your shader definitions, it seems to compile but the object just turns black: http://www.babylonjs.com/cyos/#1MVZJN


But since it compiles it might just be a problem about how you use the shader in the playground. I know some people have done that before but I couldn't find a working example in the forum yet. Did you already try to use the shader on your local pc or a webspace with separate files? Does that make any difference?


Edit: found one where shader is working in the playground: http://www.babylonjs-playground.com/#1WBBW0#1 Maybe you can compare and check ifthis one does something differently. (I know I am not a big help, sorry about that. I am just providing ideas :P )

Link to comment
Share on other sites

also when i run this locally I get 

If I use my Vector Shader 
BJS - [09:24:22]: Error: ERROR: 0:1: '' : No precision specified for (float) 
ERROR: 0:2: 'attribute' :  supported in vertex shaders only  
ERROR: 0:2: '' : No precision specified for (float) 
ERROR: 0:3: 'attribute' :  supported in vertex shaders only  
ERROR: 0:3: '' : No precision specified for (float) 
ERROR: 0:4: '' : No precision specified for (float) 
ERROR: 0:6: 'assign' :  l-value required "v_texcoord" (can't modify a varying)
ERROR: 0:7: 'gl_Position' : undeclared identifier 
ERROR: 0:7: 'assign' :  cannot convert from '4-component vector of float' to 'float'
And If i use my fragmentShader I get 
Error: Varyings with the same name but different type, or statically used varyings in fragment shader are not declared in vertex shader: v_texcoord
my Vector Shader looks like this
    uniform mat4 worldViewProjection;        attribute vec3 position;        attribute vec2 texcoord;        varying vec2 v_texcoord;        void main(){            v_texcoord = texcoord;            gl_Position = worldViewProjection * vec4(position, 1.);        }

and my fragment shader looks like this 

precision mediump float;uniform sampler2D texture;uniform float scale, aspect, time;uniform mat3 transform;varying vec2 v_texcoord;#define PI 3.141592653589793void main(){	vec2 rads = vec2(PI * 2., PI);	vec2 pnt = (v_texcoord - .5) * vec2(scale, scale * aspect);	// Project to Sphere	float x2y2 = pnt.x * pnt.x + pnt.y * pnt.y;	vec3 sphere_pnt = vec3(2. * pnt, x2y2 - 1.) / (x2y2 + 1.);	sphere_pnt *= transform;	// Convert to Spherical Coordinates	float r = length(sphere_pnt);	float lon = atan(sphere_pnt.y, sphere_pnt.x);	float lat = acos(sphere_pnt.z / r);	gl_FragColor = texture2D(texture, vec2(lon, lat) / rads);}

and am using the BABYLON.PostProcess like this.

 var postProcess = new BABYLON.PostProcess("Down sample", "../shaders/fragmentShader", ["worldViewProjection"], null, 0.25, null, BABYLON.Texture.BILINEAR_SAMPLINGMODE, engine, true);                return scene;
Just don't why this is not working any help would be great
Link to comment
Share on other sites

Ok I am making some progress


My shader not renders in the CYOS http://www.babylonjs.com/CYOS/#2L9YGY#5 doesn't give the result I want but I can work on that but when ever I try and run this as a BABYLON.PostProcess i get the error

Error: Varyings with the same name but different type, or statically used varyings in fragment shader are not declared in vertex shader: v_texcoord

So how do I define what vertex shader is used on a PostProcess?

Link to comment
Share on other sites

Am I just being a complete idot?


Lets take a step back, I am trying to take a 3D view like this http://www.babylonjs-playground.com/#QSMQ0#1 and apply a shader to it so it rather that render in 3D renders like the image in my first post



I have been trying to do this with a fragment shader but as i want to apply this to all Meshes in the scene not there textures.


So would I need to the do this via a vector shader to manipulate the points of each vector?

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...