Forum Discussion

🚨 This forum is archived and read-only. To submit a forum post, please visit our new Developer Forum. 🚨
vivekviga's avatar
vivekviga
Honored Guest
12 years ago

Oculus SDK - Spherical projection using DirectX

Hi,
I am trying to create a basic sphere with a texture map on it using the Oculus SDK 0.4.2 along with the direct to rift functionality for DK2. I am using the OculusTinyRoom example as the starter code. I have no prior experience in Direct3D and I am finding it hard to figure out how to get this done.
Currently, this is what I was able to do.
When I went through the OculusTinyRoom code, they were using slabs as a basic primitive to construct other geometry, hence I created a sphere using Slabs with this code :
Slab SphereSlabs [2628] ;
void createSphereSlabs ()
{
//Slab SphereSlabs[200];//*b = new Slab[100];
float val = 3.14285/ 180;
int i = 0;
float rad = 3.0;
for(float p= 0; p <= 360; p=p +5)
{
for(float t= 0;t < 180; t=t +5)
{
Slab a ;

a.x1 = rad * sin(t *val) * cos(p *val);
a.y1 = rad * sin(t *val) * sin(p *val);
a.z1 = rad * cos(t *val);

a.x2 = rad * sin((t +5)* val) * cos ((p+ 5)*val );
a.y2 = rad * sin((t +5)* val) * sin ((p+ 5)*val ) ;
a.z2 = rad * cos((t +5)* val);

a.c = Color( 0,0 ,0) ;
SphereSlabs[i ] = a;
i++;

}
}
int totali = i;


But unfortunately the sphere is not smooth as expected because my slabs are are quite small enough. I also came across the createdirect3dSphere() function that can create a sphere. But I have no idea where to call it. Also once I get the sphere, how do I texture it using a spherical projection. Does direct3d have any built in function calls that can do this ?

I was trying to see if VRPlayer has any source code that can help, but did not find any. I would exactly like to simulate the VR video player (only the spherical projection of over/under input image part) but with DK2 direct to rift support.

Any information on this would be very helpful.
Thank you very much !

3 Replies

  • If you are using DirectX11 then everything is done with shaders and there is very little "built-in" (fixed-function) functionality.

    Spherical projection would be done by creating a sphere and using a pixel shader to warp a texture inside of it. You can probably find code for cube mapping easily as this is more common for skyboxes or reflections. Using other formats may be less common, but you should be able to find code if you look around.

    You could probably get something working by UV mapping in a 3D modelling package, which will get you something on screen but then you will not have real-time control over it like if you did it manually with a pixel shader.

    Hope that helps.
  • Oh okay ! Cool, I will look around if I can find any code reference. Thank you very much !
  • Assume I have 2 spheres in a scene and that I need each camera to see only one of the spheres, how do I tell Directx11 to render only one of the spheres for a camera , when I have 2 different spheres in the scene ?
    I am searching online about culling, but I am finding it hard to get resources for multiple cameras inside directx.
    It would be great if someone could help me understand this .

    Thank you