2014-03-18 6 views
2

각기 다른 알파 값을 가진 지오메트리 셰이더 (위치 및 색상 만로드 함)로 만든 여러 큐브를 렌더링합니다. 문제는 알파 블렌딩을 활성화 한 후에 큐브의 가시성이 각도에 따라 변하는 것입니다. 알파가 0.5 이상인 오브젝트는 꽤 견고 해 보이며 실제로 회전 시키면 거의 사라집니다.SharpDX/DirectDX : 투명도, 법선 및 렌더링 순서

빨간색 큐브에는 알파 = 255가 있지만 그 아래에는 무엇이 있는지 볼 수 있습니다. 스텐실 버퍼를 활성화하고 비활성화하려고 시도했지만 아무런 변화가 없으므로 셰이더 또는 잘못된 플래그 값과 같은 간단한 것일 것입니다.

http://tinypic.com/r/10e589v/8

알파 블렌딩

  var depthDisabledStencilDesc = new DepthStencilStateDescription() 
     { 
      IsDepthEnabled = false, 
      DepthWriteMask = DepthWriteMask.All, 
      DepthComparison = Comparison.Less, 
      IsStencilEnabled = true, 
      StencilReadMask = 0xFF, 
      StencilWriteMask = 0xFF, 
      // Stencil operation if pixel front-facing. 
      FrontFace = new DepthStencilOperationDescription() 
      { 
       FailOperation = StencilOperation.Keep, 
       DepthFailOperation = StencilOperation.Increment, 
       PassOperation = StencilOperation.Keep, 
       Comparison = Comparison.Always 
      }, 
      // Stencil operation if pixel is back-facing. 
      BackFace = new DepthStencilOperationDescription() 
      { 
       FailOperation = StencilOperation.Keep, 
       DepthFailOperation = StencilOperation.Decrement, 
       PassOperation = StencilOperation.Keep, 
       Comparison = Comparison.Always 
      } 
     }; 

     // Create the depth stencil state. 
     DepthDisabledStencilState = new DepthStencilState(Device, depthDisabledStencilDesc); 
     //turn z-buffer off 
     Device.ImmediateContext.OutputMerger.SetDepthStencilState(DepthDisabledStencilState, 1); 

     #region Initialize Blending 
     BlendStateDescription blendDesc = new BlendStateDescription(); 

     blendDesc.RenderTarget[0].IsBlendEnabled = true; 
     blendDesc.RenderTarget[0].SourceBlend = BlendOption.SourceAlpha; 
     blendDesc.RenderTarget[0].DestinationBlend = BlendOption.InverseSourceAlpha; 
     blendDesc.RenderTarget[0].BlendOperation = BlendOperation.Add; 
     blendDesc.RenderTarget[0].SourceAlphaBlend = BlendOption.One; 
     blendDesc.RenderTarget[0].DestinationAlphaBlend = BlendOption.InverseSourceAlpha; 
     blendDesc.RenderTarget[0].AlphaBlendOperation = BlendOperation.Add; 
     blendDesc.RenderTarget[0].RenderTargetWriteMask = ColorWriteMaskFlags.All; 

     AlphaEnableBlendingState = new BlendState(Device, blendDesc); 

     // Setup the blend factor. 
     var blendFactor = new Color4(0, 0, 0, 0); 

     Device.ImmediateContext.OutputMerger.SetBlendState(AlphaEnableBlendingState, blendFactor, -1); 

기하 구조 셰이더들은

float4 v1 = input[0].Pos/2 + float4(-scale * cube_size, -scale * cube_size, -scale * cube_size, 0) + offset; 
float4 v2 = input[0].Pos/2 + float4(-scale * cube_size, scale * cube_size, -scale * cube_size, 0) + offset; 
float4 v3 = input[0].Pos/2 + float4(scale * cube_size, scale * cube_size, -scale * cube_size, 0) + offset; 
float4 v4 = input[0].Pos/2 + float4(scale * cube_size, -scale * cube_size, -scale * cube_size, 0) + offset; 

float4 v5 = input[0].Pos/2 + float4(-scale * cube_size, -scale * cube_size, scale * cube_size, 0) + offset; 
float4 v6 = input[0].Pos/2 + float4(-scale * cube_size, scale * cube_size, scale * cube_size, 0) + offset; 
float4 v7 = input[0].Pos/2 + float4(scale * cube_size, scale * cube_size, scale * cube_size, 0) + offset; 
float4 v8 = input[0].Pos/2 + float4(scale * cube_size, -scale * cube_size, scale * cube_size, 0) + offset; 

v1 = mul(v1, World); 
v1 = mul(v1, View); 
v1 = mul(v1, Projection); 

v2 = mul(v2, World); 
v2 = mul(v2, View); 
v2 = mul(v2, Projection); 

v3 = mul(v3, World); 
v3 = mul(v3, View); 
v3 = mul(v3, Projection); 

//front 
float4 edge1 = v3-v2; 
float4 edge2 = v1-v3; 
output.Normal = cross(edge1, edge2); 

output.Pos = v3;  
OutputStream.Append(output);    
output.Pos = v2; 
OutputStream.Append(output);    
output.Pos = v1; 
OutputStream.Append(output); 

output.Pos = v3; 
OutputStream.Append(output);   
output.Pos = v4; 
OutputStream.Append(output);   
output.Pos = v1; 
OutputStream.Append(output); 
OutputStream.RestartStrip(); 

다른면은 동일한 방식으로 생성된다.

+0

큐브의 순서는 무엇입니까? 빨간색 큐브가 먼저 생성됩니까? 마지막? 언제? 래스터 라이저 단계에서 렌더링 순서가 중요하기 때문에이 질문을드립니다. 기본적으로 이전에 렌더링 된 객체 (픽셀)와 만 혼합 할 수 있습니다. – tweellt

+0

그건 ... 당신이 그것에 대해 생각할 때 실제로 꽤 분명했습니다. 내가해야만하는 모든 것은 렌더링 전에 알파로 입력을 정렬하는 것이었고 매력처럼 작동합니다. 고맙습니다. 아, 그리고 정답으로 표시 할 수 있도록 대답 해주세요. – Seldon

답변

2

배경 기본 요소와 혼합하려면 기존 픽셀 색을 사용하여 원하는 혼합 작업을 수행하기 위해 동일한 배경 기본 요소를 먼저 렌더링해야합니다. 주문이 반전되면

Blending Stage

, 두 번째 프리미티브는 처음으로 폐색 될 것입니다 그리고 당신은 마지막 원시 픽셀 색상으로 종료됩니다.

귀하의 목표에 더 가까워지기를 바랍니다.

건배