Forum

2 Pass Shader in DX11 (CookTorranceMultiTexFresnel)

Hello together,

inspired by the Blog-Snapshoot cooktorrence-(ex9.effect)-help-renderer last Week, I am currently porting @dottore two Pass CookTorranceMultiTexFresnel-Shader from DX9 to DX11. At the moment the Shader is rendering only the Fresnel–Pass or the CookTorrance-Pass depending on direction.

I have implemented the Depth, Blend and Rasterizer States for the Passes so I know the fundamental techniques I am using is working.

Is it possible to do two or more Passes in DX11? I see in DX9 we have a Technique Pass Pin, but he exists not in the DX11 Layout.

DX9 Technique

technique CookTorranceMultiTextureFresnel <string Script = "Pass=p0; Pass=p1;";>
{
    // shared lighting: ambient, environment, and Z
    pass p0 <string Script = "Draw=geometry;";>
       {
           VertexShader = compile vs_1_1 fresVS(); 
           ZEnable = true;
           ZWriteEnable = true;
           CullMode = None;
           PixelShader = compile ps_1_1 fresPS_t();
       }
     // pass for each lamp (repeat for multiple lamps)
     pass p1 <string Script = "Draw=geometry;";> 
       {
          VertexShader = compile vs_1_1 cookTorrMultVS(); 
          ZEnable = true;
          ZWriteEnable = false;
          ZFunc = LessEqual;
          CullMode = None;
          AlphaBlendEnable = true;
          SrcBlend = One;
          DestBlend = One;
          PixelShader = compile ps_1_1 cookTorrMultPS_t()
        }
}

DX11 Technique

// Depth-Stencil State /////////////////////////////////////////////////////////////////////////// /////
DepthStencilState Depth_Fresnel 
{
      DepthEnable = TRUE; 
      DepthWriteMask = ALL; 
      DepthFunc = LESS_EQUAL; 
      StencilEnable = TRUE;
};
DepthStencilState Depth_CookTorrance 
{
      DepthEnable = TRUE; 
};
// Blend State /////////////////////////////////////////////////////////////////////////// /////
BlendState Blend_Fresnel 
{
};
BlendState Blend_CookTorrance 
{
      AlphaToCoverageEnable = TRUE; 
      BlendEnable[0](0) = TRUE; 
      SrcBlend = ONE;
      DestBlend = ONE;
      BlendOp = ADD;
      BlendOpAlpha = ADD; 
      RenderTargetWriteMask[0](0) = 0x0F;
};
// Rasterizer State /////////////////////////////////////////////////////////////////////////// /////
RasterizerState Rasterizer_Fresnel 
{
      CullMode = NONE;
};
RasterizerState Rasterizer_CookTorrance 
{
      CullMode = NONE;
};
/////////////////////////////////////////////////////////////////////////// /////
technique10 CookTorranceFresnel <string Script = "Pass=p0;Pass=p1";>
{
    pass p0 <string Script = "Draw=geometry;"; >
       {
           SetVertexShader( CompileShader( vs_4_0, Fresnel_VS() ) );
           SetRasterizerState(Rasterizer_Fresnel);
           SetBlendState(Blend_Fresnel, float4( 0.0f, 0.0f, 0.0f, 0.0f ), 0xFFFFFFFF );
           SetDepthStencilState(Depth_Fresnel, 0); SetGeometryShader( NULL );
           SetPixelShader( CompileShader( ps_4_0, Fresnel_PS() ) );
       }
    pass p1 <string Script = "Draw=geometry;";>
       {
           SetVertexShader( CompileShader( vs_4_0, CookTorrance_VS() ) );         SetRasterizerState(Rasterizer_CookTorrance);
           SetBlendState(Blend_CookTorrance, float4( 0.0f, 0.0f, 0.0f, 0.0f ), 0xFFFFFFFF );
           SetDepthStencilState(Depth_CookTorrance, 0); 
           SetGeometryShader( NULL );
           SetPixelShader( CompileShader( ps_4_0, CookTorrance_PS() ) );
        }
}

For the Test I write a single Fresnel and a CookTorrance-Shader and combine these Layers in a Extra Patch.

Thanks for tips!

CookTorranceMultiTextureFresnel (EffectShader).zip (1.3 MB)

Hmm, I was under the impression you could simple put 2 passes in line as you have and it would work…Interesting!

try this, looks ok to me, I just added the fresnel to the other pass and added extra targets in the vs

Single Shader Version (1.2 MB)

Cheers! @Catweasel, the tip to add the Vertex and Pixelpasses to unify in one Pass is great. I discovered that the NoMipMap-Pin must be ON at the FileTextureIn-Node in DX11 for the CubeMap Texture. Otherwise the Texture is not sharp!?!

I have cleaning the Shader a little bit and updated the contribution. cooktorrancemultitexfresnel

That Thing with the Effect Module mixing by the LayerIn-Pin is an even more complex manner BlendAdvence-Nodes in DX11 is crazy. Is that an @Vux Special?