コード例 #1
0
void MirrorRenderLoop_cl::CreateSimpleShaders()
{
  // create a dummy diffuse-only surface
  m_dummySurface.SetEffect(NULL); // make sure all lighting shaders are set properly
  VCompiledEffect *pFX = m_dummySurface.m_spCurrentEffect;
  VVERIFY_MSG(pFX != NULL,"failed to initialize mirror shaders");

  VTechniqueConfig *pGlobalConfig = Vision::Shaders.GetGlobalTechniqueConfig();
  VTechniqueConfig usageConfig;

  // default technique to render lightmapped geometry
  usageConfig.SetInclusionTags("MIRROR;LIGHTMAP");
  m_spDefaultLightMapping = pFX->FindCompatibleTechnique(&usageConfig, pGlobalConfig);
  if (!m_spDefaultLightMapping)
    m_spDefaultLightMapping = pFX->GetDefaultTechnique();

  // technique to render geometry with light grid
  usageConfig.SetInclusionTags("MIRROR;LIGHTGRID");
  m_spDefaultLightGrid = pFX->FindCompatibleTechnique(&usageConfig, pGlobalConfig);
  if (!m_spDefaultLightGrid)
    m_spDefaultLightGrid = pFX->GetDefaultTechnique();

  // depth stencil state
  m_dynLightDefaultState = *VisRenderStates_cl::GetDepthStencilDefaultState();
  m_dynLightDefaultState.m_cDepthComparisonFunc = COMPARISON_EQUAL;
  m_dynLightDefaultState.m_iStencilReadMask = 0;
  m_dynLightDefaultState.m_bDepthWriteEnabled = false;
  m_dynLightDefaultState.ComputeHash();

  VASSERT(m_spDefaultLightMapping && m_spDefaultLightGrid);
}
コード例 #2
0
void VTerrainDecorationEntityModel::ReapplyShaders()
{
  m_spVegetationShaders = NULL;

  // set default material to vegetation (when AUTO mode is used):
  if (m_spMesh!=NULL)
  {

#if defined( HK_ANARCHY )
    const BOOL bUseDeferred = FALSE;
#else
    const BOOL bUseDeferred =  Vision::Renderer.IsRendererNodeOfType(V_RUNTIME_CLASS(VDeferredRenderingSystem));
#endif
    
    int iSubmeshCount = m_spMesh->GetSubmeshCount();
    for (int i=0;i<iSubmeshCount;i++)
    {
      VCompiledEffect *pVegetationFX = NULL;
      VBaseSubmesh *pSubmesh = m_spMesh->GetSubmesh(i);
      VisSurface_cl *pSurf = pSubmesh->GetSurface();
      if (m_spVegetationShaders==NULL)
        m_spVegetationShaders = new VisShaderSet_cl();

      if (pSurf->GetShaderMode()==VisSurface_cl::VSM_Auto)
      {
        char szParamStr[1024];
      
        const hkvAlignedBBox &bbox = m_spMesh->GetBoundingBox();
        float fBaseZ = bbox.isValid() ? -bbox.m_vMin.z : 0.f;
        sprintf(szParamStr,"MaterialParams=%.4f,%.4f,%.4f,%.4f;AlphaThreshold=%.3f;fBaseZ=%.2f", 
          pSurf->GetSpecularMultiplier(),
          pSurf->GetSpecularExponent(),
          pSurf->GetParallaxScale (), pSurf->GetParallaxBias (),
          pSurf->GetAlphaTestThreshold(),fBaseZ
          );

        if (bUseDeferred)
        {
          if (Vision::RenderLoopHelper.GetLightGrid()!=NULL)
          {
            VShaderEffectLib *pLib = Vision::Shaders.LoadShaderLibrary("\\Shaders\\DeferredShadingVegetationLG.ShaderLib", SHADERLIBFLAG_HIDDEN);
            pVegetationFX = Vision::Shaders.CreateEffect("DeferredVegetation_Wind_LG",szParamStr,EFFECTCREATEFLAG_NONE,pLib);
          } else
          {
            VShaderEffectLib *pLib = Vision::Shaders.LoadShaderLibrary("\\Shaders\\DeferredShadingVegetation.ShaderLib", SHADERLIBFLAG_HIDDEN);
            pVegetationFX = Vision::Shaders.CreateEffect("DeferredVegetation_Wind",szParamStr,EFFECTCREATEFLAG_NONE,pLib);
          }
        } else
        {
          BOOL bRes = Vision::Shaders.LoadShaderLibrary("\\Shaders\\TerrainVegetation.ShaderLib", SHADERLIBFLAG_HIDDEN) != NULL;
          if (pSurf->m_spNormalMap!=NULL)
          {
            if (pSurf->m_spSpecularMap!=NULL)
              pVegetationFX = Vision::Shaders.CreateEffect("VegetationNrmlSpec_Wind",szParamStr);
            else
              pVegetationFX = Vision::Shaders.CreateEffect("VegetationNrml_Wind",szParamStr);
          } 
          else
            pVegetationFX = Vision::Shaders.CreateEffect("Vegetation_Wind",szParamStr);
        }
      }
      
      if (pVegetationFX==NULL)
        pVegetationFX = pSurf->GetEffect();
      else
      {
        pSurf->SetEffect(pVegetationFX); // sets up depth technique etc.
        pSurf->SetShaderMode(VisSurface_cl::VSM_Auto);
      }
      if (pSurf->GetTechnique())
        m_spVegetationShaders->Add(pSubmesh, pSurf, pSurf->GetTechnique());
    }
  }

  if (m_spVegetationShaders==NULL)
    m_spVegetationShaders = m_spMesh->GetShaderSet();  // no clone


  // supports instancing at all?
#if defined (WIN32)
  m_spInstancingTech = NULL;
  m_spInstancingTechShadow = NULL;
  m_spInstancingTechIRPrePass = NULL;
  m_spInstancingTechIRMainPass = NULL;
  if (Vision::Renderer.SupportsInstancing() && m_bValidState && m_spVegetationShaders->Count()==1)
  {
    const VisDrawCallInfo_t &drawCall(m_spVegetationShaders->GetDrawCallList()[0]);
    VisSurface_cl *pMat = drawCall.GetSurface();
    bool bAnyInstancingShader = false;
    VCompiledEffect *pFX = pMat->m_spCurrentEffect;
    if (pFX) // checks whether the assigned shader effect holds an instancing version
    {
      VTechniqueConfig cfg;

#ifdef _VR_DX10
      if ((Vision::Renderer.GetRendererNode ()) && (Vision::Renderer.GetRendererNode ()->GetMultisampleMode() != VVIDEO_MULTISAMPLE_OFF))
        cfg.SetInclusionTags("Instancing;MSAA");
      else
#endif
      cfg.SetInclusionTags("Instancing");
      m_spInstancingTech = pFX->FindCompatibleTechnique(&cfg, Vision::Shaders.GetGlobalTechniqueConfig());
      if (m_spInstancingTech!=NULL && m_spInstancingTech->GetShaderCount()==1)
        bAnyInstancingShader = true;

      // shadowmap instancing?
      VTechniqueConfig cfg_shadow("Instancing;SpecificShadowmapFill",NULL);
      m_spInstancingTechShadow = pFX->FindCompatibleTechnique(&cfg_shadow, Vision::Shaders.GetGlobalTechniqueConfig());
      if (m_spInstancingTechShadow!=NULL && m_spInstancingTechShadow->GetShaderCount()==1)
        bAnyInstancingShader = true;
    }


    if (bAnyInstancingShader)
    {
      VisMBVertexDescriptor_t desc;
      int iIndexCount = m_spMesh->GetMeshBuffer()->GetIndexCount();
      VVertexBuffer* pVB = m_spMesh->GetMeshBuffer()->GetVertexBuffer();
      m_spMesh->GetMeshBuffer()->GetVertexDescriptor(desc);

      VIndexBuffer* pIB = m_spMesh->GetMeshBuffer()->GetIndexBuffer();

      m_spModelMesh = new VisMeshBuffer_cl();
      m_spModelMesh->SetVertexBuffer(pVB,desc,m_spMesh->GetNumOfVertices(),VIS_MEMUSAGE_STATIC, 0);
      m_spModelMesh->SetIndexBuffer(pIB,iIndexCount,pIB->GetUsageFlags(), 0);
      m_spModelMesh->SetPrimitiveCount(iIndexCount/3);
      m_spModelMesh->SetPrimitiveType(VisMeshBuffer_cl::MB_PRIMTYPE_INDEXED_TRILIST);
      #ifdef HK_DEBUG
      m_spModelMesh->SetFilename("<TerrainDecorationEntity>");
      #endif
      m_iModelStreams = m_spModelMesh->GetStreamMask() & (m_spInstancingTech->GetShader(0)->GetStreamMask () | VERTEX_STREAM_INDEXBUFFER);
    }
  }
#endif
}
コード例 #3
0
ファイル: FXAA.cpp プロジェクト: Arpit007/projectanarchy
void VPostProcessFXAA::InitializePostProcessor()
{
  if (m_bIsInitialized || !m_bActive)
    return;

  SetupContext();

  // Load glow shader library
  BOOL bResult = Vision::Shaders.LoadShaderLibrary("\\Shaders\\FXAA.ShaderLib", SHADERLIBFLAG_HIDDEN) != NULL;
  VASSERT(bResult); // file not found?

  GetTargetContext()->GetSize(m_iWidth, m_iHeight);

  m_spMask = new VisScreenMask_cl();
  m_spMask->SetPos(0,0);
  m_spMask->SetTargetSize((float)m_iWidth,(float)m_iHeight);
  m_spMask->SetTextureRange(0.0f, 0.0f, (float)m_iWidth, (float)m_iHeight);
#ifdef _VR_DX9
  m_spMask->SetUseOpenGLTexelShift(TRUE);
#else
  m_spMask->SetUseOpenGLTexelShift(FALSE);
#endif
  //m_spMask->SetUseOpenGLTexelShift(FALSE);

  m_spMask->SetTransparency(VIS_TRANSP_NONE);
  m_spMask->SetVisible(FALSE);
  m_spMask->SetDepthWrite(FALSE);
  m_spMask->SetWrapping(FALSE, FALSE);
  m_spMask->SetVisibleBitmask(0); // this mask is rendered manually via a collection

  // no wireframe for this mask
  VSimpleRenderState_t s = m_spMask->GetRenderState();
  s.SetFlag(RENDERSTATEFLAG_NOWIREFRAME);
  m_spMask->SetRenderState(s);

  VTechniqueConfig vc;

  VString tags;
  tags.Format("FXAA_PRESET=%d", (int)Quality);
  vc.SetInclusionTags(tags);

  VCompiledTechnique *pTech = Vision::Shaders.CreateTechnique("FXAA", NULL, &vc, EFFECTFLAGS_FORCEUNIQUE);
  VASSERT(pTech!=NULL && "Could not create technique for FXAA postprocessor!");
  m_spMask->SetTechnique(pTech);
  m_spMask->SetTransparency(VIS_TRANSP_NONE);

  VShaderConstantBuffer *pPS = pTech->GetShader(0)->GetConstantBuffer(VSS_PixelShader);
  m_iRegScreenSize = pPS->GetRegisterByName("rcpFrame");
  
  // make frame copy only if this is not the last PP
  bool bFrameCopy = !IsLastComponent();
  if (bFrameCopy && GetTargetContext()->GetRenderTarget() == m_spSourceTextures[0])
  {
    m_spFrameCopyTexture = ScratchTexturePool_cl::GlobalManager().GetScratchTexture(m_iWidth, m_iHeight, m_spSourceTextures[0]->GetTextureFormat(), 0);
    m_spMask->SetTextureObject(m_spFrameCopyTexture);
  }
  else
  {
    m_spFrameCopyTexture = NULL;
    m_spMask->SetTextureObject(m_spSourceTextures[0]);
  }

  m_bIsInitialized = true;
}