   "Raycasting" in a pixel shader
  Hello,I have an application, with renders a skydome with atmospheric scattering.Now I want to replace the skydome with a cube.To to so I have the following algorithm in mind:The camera is always at the center of the cube. I send the five sides (dont need bottom) of the cube to the pipeline and in the vertex shader I calculate a ray from the camera to the current corner vertex of the cube. I store this ray in a texcoord. The rays get interpolated over the cube faces and so I have a ray for every pixel in the pixelshader.My questions:1) Does this interpolation work? Will the interpolated rays be correct?2) My second idea: Instead of storing the rays from cam to vertex I could also store the vertexPosition of the cube in a texcoord and then use the interpolated positions in the pixelshader, to calculate the ray. Would this work and if yes: is it better?Thanks for any help!   
Quote:Original post by schupf1) Does this interpolation work? Will the interpolated rays be correct?Yes, but they won't be normalized.Quote:Original post by schupf2) My second idea: Instead of storing the rays from cam to vertex I could also store the vertexPosition of the cube in a texcoord and then use the interpolated positions in the pixelshader, to calculate the ray. Would this work and if yes: is it better?Since the cube center is at (0,0,0), this would be exactly the same as method 1.;  Thanks for your answer!So Im gonna try the approach with the interpolated rays and normalize them in the pixel shader.One technical question:I dont only want to render the box, I want to create a cube texture (to use them for rendering AND reflections). Btw: I am using DX10 and SM4.0.I guess I have to do the following:for(i=0; i < 5; i++) {   viewMatrix.setMatrix(viewMatrix);   RenderThisFace(renderTarget);}So I have one technique with one pass which does all the "raycasting" in the pixelshader and the result is written to renderTarget.1) But with this approach I need 6 passes (5 to render to the faces and 1 to draw the cube)! I have seen one sample from the DX Docu (CubeMapGS), where they render to all 6 faces simultanously. Unfortunately they just render a complete scene to the faces, while I create the faces with raycasting on the fly. So is there a more efficient way in DX10 to create my cubemap?2) Im really confused about the new DX10 Resources. What I want: a cube map, that can be used for environment mapping and that can be rendered. Do I need a texture2D Array? Does anyone know some simple code which creates and renders a cubemap in DX10 (I just have found ONE sample "CubeMapGS" and to be honest... its really unclear).;Quote:Original post by schupf1) But with this approach I need 6 passes (5 to render to the faces and 1 to draw the cube)! I have seen one sample from the DX Docu (CubeMapGS), where they render to all 6 faces simultanously. Unfortunately they just render a complete scene to the faces, while I create the faces with raycasting on the fly. So is there a more efficient way in DX10 to create my cubemap?You can use the geometry shader stage to render all 5 (or 6) faces in a single pass. This obviously requires GS capable hardware. However, this is still pretty slow on current hardware, slower than doing it the old style way. Next generation hardware will have (much) more powerful geometry shader processing, and the single pass method will probably become the best alternative.Quote:Original post by schupf2) Im really confused about the new DX10 Resources. What I want: a cube map, that can be used for environment mapping and that can be rendered. Do I need a texture2D Array? Does anyone know some simple code which creates and renders a cubemap in DX10 (I just have found ONE sample "CubeMapGS" and to be honest... its really unclear).I have no idea. I'm an OpenGL guy :);Quote:Original post by schupf1) But with this approach I need 6 passes (5 to render to the faces and 1 to draw the cube)! I have seen one sample from the DX Docu (CubeMapGS), where they render to all 6 faces simultanously.As Yann mentioned, you can render all 6 at a time on DX10 hardware but in my experience it's not actually any faster on current hardware. Simply having a geometry shader - even a trivial/identity one - incurs a performance hit large enough to cover any advantage of avoiding multiple passes/render target changes. Future hardware may change this, but conceptually you're just moving more of your render logic onto the GPU so the code doesn't really change that much in any case.One other option to look at is different parameterizations than cube maps. Dual-paraboloid maps come to mind, although you have to make sure that your scene is tessellated enough to make up for the fact that rendering into a dual-paraboloid map technically requires non-linear rasterization.