Skip to main content
shader corrected and visual result image changed
Source Link
philB
  • 333
  • 2
  • 11

I'm trying to render a cone at the gpu for some effects. I'm using the parametric equation provided here. I ended up with the shader below intended to work with an unorderedaccessview target (DX11). I'm blocked in the rotating effect I want to have, the cone seems to rotate but it remains flat on the rendered result is not correct asscreen shown in the above picture. screen shot of the result.screen shot o fthe rotating cone

In thisthe shader the rotation is applied to the direction D and to the two vectors U and V defining the plane of the circle. Maybe these U and V vectors are not correct or it is my calculs for the rotation. The rotation is in the matrix world (rotation in the y axis only). What does totally not work is when I apply the full transformation to the calculated cone point in the "a" loop. The calcul I use is set as comment.

[numthreads(32,32,1)]
void CS_PostDeferred( uint3 nGid : SV_GroupID, uint3 nDTid : SV_DispatchThreadID, uint3 nGTid : SV_GroupThreadID )
{
    float2 Tex = float2(nDTid.x/SM_SCREENX, nDTid.y/SM_SCREENY);
    //this is a brut force shader for test. The cone is displayed only at point screen(0.25,0.25) 
    if ((Tex.x>0.249)&&(Tex.x<0.25)) 
    if ((Tex.y>0.2475)&&(Tex.y<0.25)) 
    {
           matrix M = World*ViewProjection;//can't work with yet. see below
           float3 O = float3(0,0,0);//top of cone
           float R = 200;//radius of cone at the base
           float H = 255;//height of cone
           float3 D = float3(0,0,1);//direction of the cone
           float3 U = float3(0,1,0);//vector in the plane of the cone circle if cone oriented in z axis
           float3 V = float3(1,0,0);//vector in the plane of the cone circle if cone oriented in z axis
           //some rotation at the start whitout rotating the pixel position 
           //gives some effective rotation but the cone is not correctly rotating
           D =  normalize(mul( D, (float3x3)World ));
           U =  normalize(mul( U, (float3x3)World ));
           V =  normalize(mul( V, (float3x3)World ));
           float3 P;
           uint h;//current position along the total height H
           for ( h = 0; h< H; h++)
           {
               float hH = h/H;
               float RhH = R * hH;
               uint a;//angle used to draw the circle at height h
               for ( a = 0; a < 72; a++ )//make a circle at height h
               {
                   float T = a2*3.1415f*a/72.0f;
                   float S = sin(T);  
                   float C = cos(T);  
                   P.x = O.x*hH*D.x + RhH * (C * U.x + S * V.x);
                   P.y = O.y*hH*D.y + RhH * (C * U.y + S * V.y);
                   P.z = O.x*hH*D.z + RhH * (C * U.z + S * V.z);
                   //this should rotate the cone point but the cone disappears
                   //P.xy = mul( float4(P,1), M ).xy*2-1;
                   //P.xy*=float2(SM_SCREENX,SM_SCREENY);
                   uint2int2 XY = uint2int2(P.xy);
                   //colorize the pixel based on P.xy value (should have z as blue also)
                   UAVDiffuse0[nDTid.xy+XY]= XY.x | (XY.y<<8)|0x000000FF;
               }
           }
       }
   }

I'm trying to render a cone at the gpu for some effects. I'm using the parametric equation provided here. I ended up with the shader below intended to work with an unorderedaccessview target (DX11). I'm blocked in the rotating effect I want to have, the cone seems to rotate but the rendered result is not correct as shown in the above picture. screen shot of the result.

In this shader the rotation is applied to the direction D and to the two vectors U and V defining the plane of the circle. Maybe these U and V vectors are not correct or it is my calculs for the rotation. The rotation is in the matrix world (rotation in the y axis only). What does totally not work is when I apply the full transformation to the calculated cone point in the "a" loop. The calcul I use is set as comment.

[numthreads(32,32,1)]
void CS_PostDeferred( uint3 nGid : SV_GroupID, uint3 nDTid : SV_DispatchThreadID, uint3 nGTid : SV_GroupThreadID )
{
    float2 Tex = float2(nDTid.x/SM_SCREENX, nDTid.y/SM_SCREENY);
    //this is a brut force shader for test. The cone is displayed only at point screen(0.25,0.25) 
    if ((Tex.x>0.249)&&(Tex.x<0.25)) 
    if ((Tex.y>0.2475)&&(Tex.y<0.25)) 
    {
           matrix M = World*ViewProjection;//can't work with yet. see below
           float3 O = float3(0,0,0);//top of cone
           float R = 200;//radius of cone at the base
           float H = 255;//height of cone
           float3 D = float3(0,0,1);//direction of the cone
           float3 U = float3(0,1,0);//vector in the plane of the cone circle if cone oriented in z axis
           float3 V = float3(1,0,0);//vector in the plane of the cone circle if cone oriented in z axis
           //some rotation at the start whitout rotating the pixel position 
           //gives some effective rotation but the cone is not correctly rotating
           D =  normalize(mul( D, (float3x3)World ));
           U =  normalize(mul( U, (float3x3)World ));
           V =  normalize(mul( V, (float3x3)World ));
           float3 P;
           uint h;//current position along the total height H
           for ( h = 0; h< H; h++)
           {
               float hH = h/H;
               float RhH = R * hH;
               uint a;//angle used to draw the circle at height h
               for ( a = 0; a < 72; a++ )//make a circle at height h
               {
                   float T = a/72.0f;
                   float S = sin(T);  
                   float C = cos(T);  
                   P.x = O.x*hH*D.x + RhH * (C * U.x + S * V.x);
                   P.y = O.y*hH*D.y + RhH * (C * U.y + S * V.y);
                   P.z = O.x*hH*D.z + RhH * (C * U.z + S * V.z);
                   //this should rotate the cone point but the cone disappears
                   //P.xy = mul( float4(P,1), M ).xy*2-1;
                   //P.xy*=float2(SM_SCREENX,SM_SCREENY);
                   uint2 XY = uint2(P.xy);
                   //colorize the pixel based on P.xy value (should have z as blue also)
                   UAVDiffuse0[nDTid.xy+XY]= XY.x | (XY.y<<8)|0x000000FF;
               }
           }
       }
   }

I'm trying to render a cone at the gpu for some effects. I'm using the parametric equation provided here. I ended up with the shader below intended to work with an unorderedaccessview target (DX11). I'm blocked in the rotating effect I want to have, the cone seems to rotate but it remains flat on the screen shown in the above picture. screen shot o fthe rotating cone

In the shader the rotation is applied to the direction D and to the two vectors U and V defining the plane of the circle. Maybe these U and V vectors are not correct or it is my calculs for the rotation. The rotation is in the matrix world (rotation in the y axis only). What does totally not work is when I apply the full transformation to the calculated cone point in the "a" loop. The calcul I use is set as comment.

[numthreads(32,32,1)]
void CS_PostDeferred( uint3 nGid : SV_GroupID, uint3 nDTid : SV_DispatchThreadID, uint3 nGTid : SV_GroupThreadID )
{
    float2 Tex = float2(nDTid.x/SM_SCREENX, nDTid.y/SM_SCREENY);
    //this is a brut force shader for test. The cone is displayed only at point screen(0.25,0.25) 
    if ((Tex.x>0.249)&&(Tex.x<0.25)) 
    if ((Tex.y>0.2475)&&(Tex.y<0.25)) 
    {
           matrix M = World*ViewProjection;//can't work with yet. see below
           float3 O = float3(0,0,0);//top of cone
           float R = 200;//radius of cone at the base
           float H = 255;//height of cone
           float3 D = float3(0,0,1);//direction of the cone
           float3 U = float3(0,1,0);//vector in the plane of the cone circle if cone oriented in z axis
           float3 V = float3(1,0,0);//vector in the plane of the cone circle if cone oriented in z axis
           //some rotation at the start whitout rotating the pixel position 
           //gives some effective rotation but the cone is not correctly rotating
           D =  normalize(mul( D, (float3x3)World ));
           U =  normalize(mul( U, (float3x3)World ));
           V =  normalize(mul( V, (float3x3)World ));
           float3 P;
           uint h;//current position along the total height H
           for ( h = 0; h< H; h++)
           {
               float hH = h/H;
               float RhH = R * hH;
               uint a;//angle used to draw the circle at height h
               for ( a = 0; a < 72; a++ )//make a circle at height h
               {
                   float T = 2*3.1415f*a/72.0f;
                   float S = sin(T);  
                   float C = cos(T);  
                   P.x = O.x*hH*D.x + RhH * (C * U.x + S * V.x);
                   P.y = O.y*hH*D.y + RhH * (C * U.y + S * V.y);
                   P.z = O.x*hH*D.z + RhH * (C * U.z + S * V.z);
                   //this should rotate the cone point but the cone disappears
                   //P.xy = mul( float4(P,1), M ).xy*2-1;
                   //P.xy*=float2(SM_SCREENX,SM_SCREENY);
                   int2 XY = int2(P.xy);
                   //colorize the pixel based on P.xy value (should have z as blue also)
                   UAVDiffuse0[nDTid.xy+XY]= XY.x | (XY.y<<8)|0x000000FF;
               }
           }
       }
   }
Source Link
philB
  • 333
  • 2
  • 11

Difficulties for GPU rendering of a cone using parametric equation

I'm trying to render a cone at the gpu for some effects. I'm using the parametric equation provided here. I ended up with the shader below intended to work with an unorderedaccessview target (DX11). I'm blocked in the rotating effect I want to have, the cone seems to rotate but the rendered result is not correct as shown in the above picture. screen shot of the result.

In this shader the rotation is applied to the direction D and to the two vectors U and V defining the plane of the circle. Maybe these U and V vectors are not correct or it is my calculs for the rotation. The rotation is in the matrix world (rotation in the y axis only). What does totally not work is when I apply the full transformation to the calculated cone point in the "a" loop. The calcul I use is set as comment.

[numthreads(32,32,1)]
void CS_PostDeferred( uint3 nGid : SV_GroupID, uint3 nDTid : SV_DispatchThreadID, uint3 nGTid : SV_GroupThreadID )
{
    float2 Tex = float2(nDTid.x/SM_SCREENX, nDTid.y/SM_SCREENY);
    //this is a brut force shader for test. The cone is displayed only at point screen(0.25,0.25) 
    if ((Tex.x>0.249)&&(Tex.x<0.25)) 
    if ((Tex.y>0.2475)&&(Tex.y<0.25)) 
    {
           matrix M = World*ViewProjection;//can't work with yet. see below
           float3 O = float3(0,0,0);//top of cone
           float R = 200;//radius of cone at the base
           float H = 255;//height of cone
           float3 D = float3(0,0,1);//direction of the cone
           float3 U = float3(0,1,0);//vector in the plane of the cone circle if cone oriented in z axis
           float3 V = float3(1,0,0);//vector in the plane of the cone circle if cone oriented in z axis
           //some rotation at the start whitout rotating the pixel position 
           //gives some effective rotation but the cone is not correctly rotating
           D =  normalize(mul( D, (float3x3)World ));
           U =  normalize(mul( U, (float3x3)World ));
           V =  normalize(mul( V, (float3x3)World ));
           float3 P;
           uint h;//current position along the total height H
           for ( h = 0; h< H; h++)
           {
               float hH = h/H;
               float RhH = R * hH;
               uint a;//angle used to draw the circle at height h
               for ( a = 0; a < 72; a++ )//make a circle at height h
               {
                   float T = a/72.0f;
                   float S = sin(T);  
                   float C = cos(T);  
                   P.x = O.x*hH*D.x + RhH * (C * U.x + S * V.x);
                   P.y = O.y*hH*D.y + RhH * (C * U.y + S * V.y);
                   P.z = O.x*hH*D.z + RhH * (C * U.z + S * V.z);
                   //this should rotate the cone point but the cone disappears
                   //P.xy = mul( float4(P,1), M ).xy*2-1;
                   //P.xy*=float2(SM_SCREENX,SM_SCREENY);
                   uint2 XY = uint2(P.xy);
                   //colorize the pixel based on P.xy value (should have z as blue also)
                   UAVDiffuse0[nDTid.xy+XY]= XY.x | (XY.y<<8)|0x000000FF;
               }
           }
       }
   }