/* Draws a line connecting two Poin2F structures. */ static int galDrawLine(IDevice *pContext, Point2F a, Point2F b) { GIDevice *icontext = NULL; if ((icontext = (GIDevice*)pContext) == NULL) { return GI_ERROR; } struct pipe_context *context; if ((context = icontext->context) == NULL) { return GI_ERROR; } GIEdge edge[2]; edge[0].x = a.x; edge[0].y = a.y; edge[0].r = 1.0f; edge[0].g = 1.0f; edge[0].b = 1.0f; edge[0].a = 1.0f; edge[1].x = b.x; edge[1].y = b.y; edge[1].r = 1.0f; edge[1].g = 1.0f; edge[1].b = 1.0f; edge[1].a = 0.4f; pipe_buffer_write(context, icontext->buffer, 0, sizeof(edge), edge); struct pipe_draw_info info; memset(&info, 0, sizeof(info)); info.instance_count = 1; info.max_index = 0xffffffff; info.mode = PIPE_PRIM_LINES; info.start = 0; info.count = 2; info.min_index = 0; info.max_index = 0 + 2 - 1; SetPixelShader(context, icontext->fs_color); context->draw_vbo(context, &info); SetPixelShader(context, NULL); return GI_SUCCESS; }
void OvRenderer::RenderUnitRect( OvVertexShaderSPtr v_shader , OvPixelShaderSPtr p_shader ) { struct SScreenRect { OvPoint3 pos; OvPoint2 tex; }; static D3DVERTEXELEMENT9 rect_elem[] = { { 0, 0 , D3DDECLTYPE_FLOAT3 , D3DDECLMETHOD_DEFAULT , D3DDECLUSAGE_POSITION, 0 }, { 0, 12 , D3DDECLTYPE_FLOAT2 , D3DDECLMETHOD_DEFAULT , D3DDECLUSAGE_TEXCOORD, 0 }, D3DDECL_END() }; static SScreenRect rect[] = { {OvPoint3(-1,-1,0),OvPoint2(0,1)} , {OvPoint3(-1,+1,0),OvPoint2(0,0)} , {OvPoint3(+1,+1,0),OvPoint2(1,0)} , {OvPoint3(+1,-1,0),OvPoint2(1,1)}}; static LPDIRECT3DVERTEXBUFFER9 rectVertBuffer = CreateVertexStream( (void*)&rect[0], sizeof( SScreenRect ), 4 ); static LPDIRECT3DVERTEXDECLARATION9 rectDecl = CreateVertexDeclaration( rect_elem ); if ( v_shader ) SetVertexShader( v_shader ); if ( p_shader ) SetPixelShader( p_shader ); SetVertexStream( 0, SVertexStreamInfo( rectVertBuffer, sizeof( SScreenRect ), 0) ); SetVertexDeclaration( rectDecl ); DrawPrimitive( D3DPT_TRIANGLEFAN, 2); }
//============================================================================================================================== bool DebugGBufferDeferredShader::RenderDepth11(ID3D11ShaderResourceView* texture, Camera* camera) { cbInvMatrixBuffer cMB; cMB.g_InvViewProj = camera->InvViewProj4x4(); // Map the matrix buffer { D3D11_MAPPED_SUBRESOURCE mapped_res2; m_pD3DSystem->GetDeviceContext()->Map(m_pMatrixCB, 0, D3D11_MAP_WRITE_DISCARD, 0, &mapped_res2); { assert(mapped_res2.pData); *(cbInvMatrixBuffer*)mapped_res2.pData = cMB; } m_pD3DSystem->GetDeviceContext()->Unmap(m_pMatrixCB, 0); } ID3D11Buffer* ps_cbs[1] = { m_pMatrixCB }; m_pD3DSystem->GetDeviceContext()->PSSetConstantBuffers(0, 1, ps_cbs); // Assign Texture ID3D11ShaderResourceView* ps_srvs[1] = { texture }; ID3D11SamplerState* ps_samp[1] = { m_pD3DSystem->Point() }; if (!m_Wireframe) { m_pD3DSystem->GetDeviceContext()->PSSetShaderResources(0, 1, ps_srvs); m_pD3DSystem->GetDeviceContext()->PSSetSamplers(0, 1, ps_samp); SwitchTo("DebugGBufferDepthDeferredPS", ZShadeSandboxShader::EShaderTypes::ST_PIXEL); } else { SwitchTo("DebugGBufferDeferredWireframePS", ZShadeSandboxShader::EShaderTypes::ST_PIXEL); } m_pD3DSystem->TurnOnAdditiveBlending(); SetVertexShader(); SetPixelShader(); //Perform Drawing onto a fullscreen quad with a NULL Input Layout RenderDraw11(4); m_pD3DSystem->TurnOffAdditiveBlending(); // Unbind if (!m_Wireframe) { ps_samp[0] = NULL; m_pD3DSystem->GetDeviceContext()->PSSetSamplers(0, 1, ps_samp); ps_srvs[0] = NULL; m_pD3DSystem->GetDeviceContext()->PSSetShaderResources(0, 1, ps_srvs); } return true; }
/*virtual*/ void D3D9Renderer::SetShaderProgram( IShaderProgram* const pShaderProgram) { DEBUGASSERT(pShaderProgram); if (pShaderProgram == m_ShaderProgram) { return; } m_ShaderProgram = pShaderProgram; SetVertexShader(pShaderProgram->GetVertexShader()); SetPixelShader(pShaderProgram->GetPixelShader()); }
//----------------------------------------------------------------------------- // CreateDefaultObjects // Creates the default objects //----------------------------------------------------------------------------- void CRenderer::CreateDefaultObjects( void ) { // Texture m_nDefaultTexture = LoadTexture2D( "Assets/Textures/DefaultTexture.png" ); // Default mesh m_nDefaultMesh = CreateMesh(); // debug sphere m_nSphereMesh = LoadMesh( "Assets/meshes/sphere.mesh" ); // debug box m_nDebugBox = CreateDynamicBox(); ////////////////////////////////////////// // Load Shaders LoadShaders(); // a vertex shader for drawing lines VPosColor pLineVertices[] = { { RVector3( 0.0f, 0.0f, 0.0f ), RVector4( 1.0f, 1.0f, 1.0f, 1.0f ) }, { RVector3( 1.0f, 1.0f, 1.0f ), RVector4( 1.0f, 1.0f, 1.0f, 1.0f ) }, }; m_pLineBuffer = m_pDevice->CreateVertexBuffer( sizeof( pLineVertices ), pLineVertices ); // Set the defaults SetVertexShader( eVS3DPosNorTexStd ); SetPixelShader( ePS3DStd ); SetSamplerState( eSamplerLinear ); m_pDevice->SetPrimitiveType( GFX_PRIMITIVE_TRIANGLELIST ); static float Vtx[] = { -1.0f, -1.0f, -1.0f, 1.0f, 1.0f, 1.0f, 1.0f, -1.0f, }; static uint16 Idx[] = { 0, 1, 2, 0, 2, 3, }; m_pFSRectVB = m_pDevice->CreateVertexBuffer( sizeof( Vtx ), Vtx ); m_pFSRectIB = m_pDevice->CreateIndexBuffer ( sizeof( Idx ), Idx ); }
Air::U1 System::SetShader( Render::enumShaderType type,IShader* pShader ){ IDirect3DVertexShader9* pVS = NULL; IDirect3DPixelShader9* pPS = NULL; if(type == enVS){ if(pShader!=NULL){ pVS = (DxVertexShader*)pShader->GetShader(); } SetVertexShader(pVS); }else{ if(pShader!=NULL){ pPS = (DxPixelShader*)pShader->GetShader(); } SetPixelShader(pPS); } return true; }
//============================================================================== // Shader //------------------------------------------------------------------------------ void Shader::setPixShader(const char* fileName) { auto pDevice = App::instance().getRenderer()->getDevice(); if(fileName == nullptr) { pDevice->SetPixelShader(nullptr); _nowPixShader = nullptr; return; } if(_nowPixShader != nullptr && _nowPixShader->filename == fileName) { return; } auto it = _pixShaderMap.find(fileName); if(it == _pixShaderMap.end()) { return; } setPixShader(it->second); }
//============================================================================================================================== bool DebugGBufferDeferredShader::Render11(ID3D11ShaderResourceView* texture) { // Assign Texture ID3D11ShaderResourceView* ps_srvs[1] = { texture }; ID3D11SamplerState* ps_samp[1] = { m_pD3DSystem->Point() }; if (!m_Wireframe) { m_pD3DSystem->GetDeviceContext()->PSSetShaderResources(0, 1, ps_srvs); m_pD3DSystem->GetDeviceContext()->PSSetSamplers(0, 1, ps_samp); SwitchTo("DebugGBufferDeferredPS", ZShadeSandboxShader::EShaderTypes::ST_PIXEL); } else { SwitchTo("DebugGBufferDeferredWireframePS", ZShadeSandboxShader::EShaderTypes::ST_PIXEL); } m_pD3DSystem->TurnOnAdditiveBlending(); SetVertexShader(); SetPixelShader(); //Perform Drawing onto a fullscreen quad with a NULL Input Layout RenderDraw11(4); m_pD3DSystem->TurnOffAdditiveBlending(); // Unbind if (!m_Wireframe) { ps_samp[0] = NULL; m_pD3DSystem->GetDeviceContext()->PSSetSamplers(0, 1, ps_samp); ps_srvs[0] = NULL; m_pD3DSystem->GetDeviceContext()->PSSetShaderResources(0, 1, ps_srvs); } return true; }
void plLayer::CloneNoTexture( plLayerInterface *original ) { SetBlendFlags( original->GetBlendFlags() ); SetClampFlags( original->GetClampFlags() ); SetShadeFlags( original->GetShadeFlags() ); SetZFlags( original->GetZFlags() ); SetMiscFlags( original->GetMiscFlags() ); SetState( original->GetState() ); SetPreshadeColor( original->GetPreshadeColor() ); SetRuntimeColor( original->GetRuntimeColor() ); SetAmbientColor( original->GetAmbientColor() ); SetSpecularColor( original->GetSpecularColor() ); SetOpacity( original->GetOpacity() ); SetTransform( original->GetTransform() ); SetUVWSrc( original->GetUVWSrc() ); SetLODBias( original->GetLODBias() ); SetSpecularPower( original->GetSpecularPower() ); SetVertexShader( original->GetVertexShader() ); SetPixelShader( original->GetPixelShader() ); SetBumpEnvMatrix( original->GetBumpEnvMatrix() ); }
//============================================================================================================================== bool TerrainTessellationQuadShadowShader::Render(int indexCount, LightCamera* lightcamera, ZShadeSandboxTerrain::TerrainShadingConst terrainShadingConst, ID3D11ShaderResourceView* heightMapSRV) { cTessellationBuffer cTB; cMatrixBuffer cMB; cDomainConstBuffer cDCB; m_pD3DSystem->SetRasterizerState(m_pD3DSystem->RSDepth()); //if (m_UseCustomWorld) // cMB.g_WorldMatrix = ZShadeSandboxMath::ZMath::GMathMF(XMMatrixTranspose(mWorld.Get())); //else // cMB.g_WorldMatrix = ZShadeSandboxMath::ZMath::GMathMF(XMMatrixTranspose(XMMatrixIdentity())); cMB.g_ViewMatrix = lightcamera->LightView4x4(); cMB.g_ProjMatrix = lightcamera->LightProj4x4(); cMB.g_ShadowMatrix = lightcamera->ShadowTransform4x4(); XMMATRIX toTexSpace = XMMatrixScaling(0.5f, -0.5f, 1.0f) * XMMatrixTranslation(0.5f, 0.5f, 0); cMB.g_TexSpaceMatrix = ZShadeSandboxMath::ZMath::GMathMF(XMMatrixTranspose(toTexSpace)); cTB.g_EyePosW = terrainShadingConst.g_EyePosW; cTB.g_MinDist = terrainShadingConst.g_MinDist; cTB.g_MaxDist = terrainShadingConst.g_MaxDist; cTB.g_MinTess = terrainShadingConst.g_MinTess; cTB.g_MaxTess = terrainShadingConst.g_MaxTess; cTB.g_FrustumCull = terrainShadingConst.g_FrustumCull; cTB.padding = XMFLOAT2(0, 0); cTB.g_TerrSize = terrainShadingConst.g_MapSize; cTB.g_TerrScale = terrainShadingConst.g_TerrSize; cDCB.g_TexScale = XMFLOAT2(66.0f, 66.0f); cDCB.g_HeightScale = terrainShadingConst.g_HeightScale; cDCB.g_TerrainZScale = terrainShadingConst.g_TerrSize; cDCB.g_ClipPlane = terrainShadingConst.g_ClipPlane; cDCB.g_tpadding = XMFLOAT3(0, 0, 0); cDCB.g_FarPlane = terrainShadingConst.g_FarPlane; // Map tessellation constants { D3D11_MAPPED_SUBRESOURCE mapped_res; m_pD3DSystem->GetDeviceContext()->Map(m_pTessellationCB, 0, D3D11_MAP_WRITE_DISCARD, 0, &mapped_res); { assert(mapped_res.pData); *(cTessellationBuffer*)mapped_res.pData = cTB; } m_pD3DSystem->GetDeviceContext()->Unmap(m_pTessellationCB, 0); } // Map domain shader constants { D3D11_MAPPED_SUBRESOURCE mapped_res; m_pD3DSystem->GetDeviceContext()->Map(m_pDomainCB, 0, D3D11_MAP_WRITE_DISCARD, 0, &mapped_res); { assert(mapped_res.pData); *(cDomainConstBuffer*)mapped_res.pData = cDCB; } m_pD3DSystem->GetDeviceContext()->Unmap(m_pDomainCB, 0); } // Map matrix constants { D3D11_MAPPED_SUBRESOURCE mapped_res; m_pD3DSystem->GetDeviceContext()->Map(m_pMatrixBufferCB, 0, D3D11_MAP_WRITE_DISCARD, 0, &mapped_res); { assert(mapped_res.pData); *(cMatrixBuffer*)mapped_res.pData = cMB; } m_pD3DSystem->GetDeviceContext()->Unmap(m_pMatrixBufferCB, 0); } // Set the tessellation constant buffer into the Hull Shader ID3D11Buffer* hs_cbs[1] = { m_pTessellationCB }; m_pD3DSystem->GetDeviceContext()->HSSetConstantBuffers(0, 1, hs_cbs); // Set the domain and matrix constant buffer into the Domain Shader ID3D11Buffer* ds_cbs[2] = { m_pDomainCB, m_pMatrixBufferCB }; m_pD3DSystem->GetDeviceContext()->DSSetConstantBuffers(0, 2, ds_cbs); // Set the heightmap texture into the vertex shader ID3D11ShaderResourceView* vs_srvs[1] = { heightMapSRV }; m_pD3DSystem->GetDeviceContext()->VSSetShaderResources(0, 1, vs_srvs); // Set the heightmap texture into the domain shader ID3D11ShaderResourceView* ds_srvs[1] = { heightMapSRV }; m_pD3DSystem->GetDeviceContext()->DSSetShaderResources(0, 1, ds_srvs); // Tell the shader what input layout to use SetInputLayout("TerrainTessellationQuadShadowShader"); // Assign the shaders to render the mesh SetVertexShader(); SetHullShader(); SetDomainShader(); SetPixelShader(); //m_pD3DSystem->GetDeviceContext()->PSSetShader(NULL, NULL, 0); //Perform Drawing RenderIndex11(indexCount); return true; }
static int galDrawImage(IDevice *pContext, ISurface *pSurface, unsigned x, unsigned y, unsigned sx, unsigned sy, unsigned width, unsigned height) { GIDevice *icontext = NULL; if ((icontext = (GIDevice*)pContext) == NULL) { return GI_ERROR; } GISurface *isurface = NULL; if ((isurface = (GISurface*)pSurface) == NULL) { return GI_ERROR; } struct pipe_context *context; if ((context = icontext->context) == NULL) { return GI_ERROR; } struct pipe_sampler_view *view; if ((view = isurface->view) == NULL) { return GI_ERROR; } GIEdge edge[4]; edge[0].x = x; edge[0].y = y; edge[0].r = 0.0f; edge[0].g = 0.0f; edge[0].b = 0.0f; edge[0].a = 0.0f; edge[1].x = (x + width); edge[1].y = (y); edge[1].r = 0.0f; edge[1].g = 0.0f; edge[1].b = 0.0f; edge[1].a = 0.0f; edge[2].x = (x + width); edge[2].y = (y + height); edge[2].r = 0.0f; edge[2].g = 0.0f; edge[2].b = 0.0f; edge[2].a = 0.0f; edge[3].x = (x); edge[3].y = (y + height); edge[3].r = 0.0f; edge[3].g = 0.0f; edge[3].b = 0.0f; edge[3].a = 0.0f; pipe_buffer_write(context, icontext->buffer, 0, sizeof(edge), edge); struct pipe_draw_info info; memset(&info, 0, sizeof(info)); info.instance_count = 1; info.max_index = 0xffffffff; info.mode = PIPE_PRIM_QUADS; info.start = 0; info.count = 4; info.min_index = 0; info.max_index = 0 + 2 - 1; SetPixelShader(context, icontext->fs_image); context->set_fragment_sampler_views(context, 1, &view); context->draw_vbo(context, &info); SetPixelShader(context, NULL); return GI_SUCCESS; }
//============================================================================== // Shader //------------------------------------------------------------------------------ void Shader::setPixShader(unsigned int id) { auto pDevice = App::instance().getRenderer()->getDevice(); _nowPixShader = _pixShaderList[id]; pDevice->SetPixelShader(_nowPixShader->_shader); }
bool GLVideo::DrawRectangle( const math::Vector2 &v2Pos, const math::Vector2 &v2Size, const Color& color0, const Color& color1, const Color& color2, const Color& color3, const float angle, const Sprite::ENTITY_ORIGIN origin) { if (v2Size == math::Vector2(0,0)) { return true; } // TODO/TO-DO this is diplicated code: fix it math::Vector2 v2Center; switch (origin) { case Sprite::EO_CENTER: case Sprite::EO_RECT_CENTER: v2Center.x = v2Size.x / 2.0f; v2Center.y = v2Size.y / 2.0f; break; case Sprite::EO_RECT_CENTER_BOTTOM: case Sprite::EO_CENTER_BOTTOM: v2Center.x = v2Size.x / 2.0f; v2Center.y = v2Size.y; break; case Sprite::EO_RECT_CENTER_TOP: case Sprite::EO_CENTER_TOP: v2Center.x = v2Size.x / 2.0f; v2Center.y = 0.0f; break; case Sprite::EO_DEFAULT: default: v2Center.x = 0.0f; v2Center.y = 0.0f; break; }; math::Matrix4x4 mRot; if (angle != 0.0f) mRot = math::RotateZ(math::DegreeToRadian(angle)); m_rectVS->SetMatrixConstant("rotationMatrix", mRot); m_rectVS->SetConstant("size", v2Size); m_rectVS->SetConstant("entityPos", v2Pos); m_rectVS->SetConstant("center", v2Center); m_rectVS->SetConstant("color0", color0); m_rectVS->SetConstant("color1", color1); m_rectVS->SetConstant("color2", color2); m_rectVS->SetConstant("color3", color3); ShaderPtr prevVertexShader = GetVertexShader(), prevPixelShader = GetPixelShader(); SetVertexShader(m_rectVS); SetPixelShader(ShaderPtr()); UnsetTexture(0); UnsetTexture(1); GetVertexShader()->SetShader(); m_rectRenderer.Draw(Sprite::RM_TWO_TRIANGLES); SetPixelShader(prevPixelShader); SetVertexShader(prevVertexShader); return true; }
//============================================================================================================================== bool MaterialTessellationShader::Render11 ( int indexCount , int instanceCount , ZShadeSandboxMesh::MeshRenderParameters mrp , ZShadeSandboxLighting::ShaderMaterial* material ) { ID3D11ShaderResourceView* diffuseArrayTexture = 0; ID3D11ShaderResourceView* diffuseTexture = 0; ID3D11ShaderResourceView* ambientTexture = 0; ID3D11ShaderResourceView* specularTexture = 0; ID3D11ShaderResourceView* emissiveTexture = 0; ID3D11ShaderResourceView* normalMapTexture = 0; ID3D11ShaderResourceView* blendMapTexture = 0; ID3D11ShaderResourceView* detailMapTexture = 0; ID3D11ShaderResourceView* alphaMapTexture = 0; ID3D11ShaderResourceView* shadowMapTexture = 0; ID3D11ShaderResourceView* ssaoTexture = 0; ID3D11ShaderResourceView* displacementMapTexture = 0; material->GetTextures( diffuseArrayTexture, diffuseTexture, ambientTexture, specularTexture, emissiveTexture, normalMapTexture, blendMapTexture, detailMapTexture, alphaMapTexture, shadowMapTexture, ssaoTexture, displacementMapTexture ); material->BuildMaterialTessellationBuffer(m_pTessellationCB, mrp.camera->Position()); material->BuildMaterialDomainBuffer(m_pDomainCB, mrp.world, mrp.camera, mrp.clipplane, mrp.reflection); material->BuildMaterialConstantBuffer(m_pShadingCB, mrp.camera->Position(), mrp.clipplane); ZShadeSandboxLighting::LightManager::Instance()->BuildFinalLightBuffers(m_pLightCB, m_pSunCB); ID3D11Buffer* vs_cbs[1] = { m_pShadingCB }; m_pD3DSystem->GetDeviceContext()->VSSetConstantBuffers(4, 1, vs_cbs); // Set the tessellation constant buffer into the Hull Shader ID3D11Buffer* hs_cbs[1] = { m_pTessellationCB }; m_pD3DSystem->GetDeviceContext()->HSSetConstantBuffers(2, 1, hs_cbs); // Set the matrix constant buffer into the Domain Shader ID3D11Buffer* ds_cbs[2] = { m_pDomainCB, m_pShadingCB }; m_pD3DSystem->GetDeviceContext()->DSSetConstantBuffers(3, 2, ds_cbs); ID3D11Buffer* ps_cbs[5] = { m_pLightCB, m_pSunCB, m_pTessellationCB, m_pDomainCB, m_pShadingCB }; m_pD3DSystem->GetDeviceContext()->PSSetConstantBuffers(0, 5, ps_cbs); ID3D11ShaderResourceView* ps_srvs[11] = { diffuseArrayTexture, diffuseTexture, ambientTexture, specularTexture, emissiveTexture, normalMapTexture, blendMapTexture, detailMapTexture, alphaMapTexture, shadowMapTexture, ssaoTexture }; ID3D11SamplerState* ps_samp[2] = { m_pD3DSystem->Point(), m_pD3DSystem->Linear() }; ID3D11ShaderResourceView* disp_srvs[1] = { displacementMapTexture }; if (!m_Wireframe) { // Assign Texture m_pD3DSystem->GetDeviceContext()->VSSetSamplers(0, 2, ps_samp); m_pD3DSystem->GetDeviceContext()->DSSetSamplers(0, 2, ps_samp); m_pD3DSystem->GetDeviceContext()->PSSetSamplers(0, 2, ps_samp); m_pD3DSystem->GetDeviceContext()->VSSetShaderResources(11, 1, disp_srvs); m_pD3DSystem->GetDeviceContext()->DSSetShaderResources(11, 1, disp_srvs); m_pD3DSystem->GetDeviceContext()->PSSetShaderResources(0, 11, ps_srvs); switch (mType) { case ZShadeSandboxLighting::EMaterialTessellationType::Type::eQuad: SwitchTo("QuadMaterialTessellationPS", ZShadeSandboxShader::EShaderTypes::ST_PIXEL); break; case ZShadeSandboxLighting::EMaterialTessellationType::Type::eTri: SwitchTo("TriMaterialTessellationPS", ZShadeSandboxShader::EShaderTypes::ST_PIXEL); break; } } else { switch (mType) { case ZShadeSandboxLighting::EMaterialTessellationType::Type::eQuad: SwitchTo("QuadMaterialTessellationWireframePS", ZShadeSandboxShader::EShaderTypes::ST_PIXEL); break; case ZShadeSandboxLighting::EMaterialTessellationType::Type::eTri: SwitchTo("TriMaterialTessellationWireframePS", ZShadeSandboxShader::EShaderTypes::ST_PIXEL); break; } } if (mrp.useInstancing) { SetInputLayout("MaterialTessellationShaderInstance"); switch (mType) { case ZShadeSandboxLighting::EMaterialTessellationType::Type::eQuad: SwitchTo("QuadMaterialTessellationInstanceVS", ZShadeSandboxShader::EShaderTypes::ST_VERTEX); break; case ZShadeSandboxLighting::EMaterialTessellationType::Type::eTri: SwitchTo("TriMaterialTessellationInstanceVS", ZShadeSandboxShader::EShaderTypes::ST_VERTEX); break; } } else { SetInputLayout("MaterialTessellationShader"); switch (mType) { case ZShadeSandboxLighting::EMaterialTessellationType::Type::eQuad: SwitchTo("QuadMaterialTessellationVS", ZShadeSandboxShader::EShaderTypes::ST_VERTEX); break; case ZShadeSandboxLighting::EMaterialTessellationType::Type::eTri: SwitchTo("TriMaterialTessellationVS", ZShadeSandboxShader::EShaderTypes::ST_VERTEX); break; } } SetVertexShader(); SetHullShader(); SetDomainShader(); SetPixelShader(); //Perform Drawing if (mrp.useInstancing) { RenderIndexInstanced11(indexCount, instanceCount); } else { RenderIndex11(indexCount); } // Unbind if (!m_Wireframe) { ps_samp[0] = NULL; m_pD3DSystem->GetDeviceContext()->VSSetSamplers(0, 2, ps_samp); m_pD3DSystem->GetDeviceContext()->DSSetSamplers(0, 2, ps_samp); m_pD3DSystem->GetDeviceContext()->PSSetSamplers(0, 2, ps_samp); disp_srvs[0] = NULL; m_pD3DSystem->GetDeviceContext()->VSSetShaderResources(11, 1, disp_srvs); m_pD3DSystem->GetDeviceContext()->DSSetShaderResources(11, 1, disp_srvs); for (int i = 0; i < 11; i++) ps_srvs[i] = NULL; m_pD3DSystem->GetDeviceContext()->PSSetShaderResources(0, 11, ps_srvs); } // Set Hull, Domain and Geometry Shaders to null in case they are not needed m_pD3DSystem->GetDeviceContext()->HSSetShader(NULL, NULL, 0); m_pD3DSystem->GetDeviceContext()->DSSetShader(NULL, NULL, 0); m_pD3DSystem->GetDeviceContext()->GSSetShader(NULL, NULL, 0); return true; }
//============================================================================================================================== bool MaterialShader::Render11 ( int indexCount , int instanceCount , ZShadeSandboxMesh::MeshRenderParameters mrp , ZShadeSandboxLighting::ShaderMaterial* material ) { ID3D11ShaderResourceView* diffuseArrayTexture = 0; ID3D11ShaderResourceView* diffuseTexture = 0; ID3D11ShaderResourceView* ambientTexture = 0; ID3D11ShaderResourceView* specularTexture = 0; ID3D11ShaderResourceView* emissiveTexture = 0; ID3D11ShaderResourceView* normalMapTexture = 0; ID3D11ShaderResourceView* blendMapTexture = 0; ID3D11ShaderResourceView* detailMapTexture = 0; ID3D11ShaderResourceView* alphaMapTexture = 0; ID3D11ShaderResourceView* shadowMapTexture = 0; ID3D11ShaderResourceView* ssaoTexture = 0; ID3D11ShaderResourceView* displacementMapTexture = 0; if (material == 0) return false; material->GetTextures( diffuseArrayTexture, diffuseTexture, ambientTexture, specularTexture, emissiveTexture, normalMapTexture, blendMapTexture, detailMapTexture, alphaMapTexture, shadowMapTexture, ssaoTexture, displacementMapTexture ); material->fBlendAmount = mrp.blendAmount; material->BuildMaterialConstantBuffer(m_pShadingCB, mrp.camera->Position(), mrp.clipplane); // Use the default light if there is no light if (mrp.light == 0) { MaterialShader::mDefaultLight->Update(); mrp.light = MaterialShader::mDefaultLight; } mrp.camera->BuildCameraConstantBuffer(m_pD3DSystem, m_pMatrixCB, mrp.light, mrp.world, mrp.reflection); if (m_pD3DSystem->GetEngineOptions()->m_DimType == DimType::ZSHADE_3D) ZShadeSandboxLighting::LightManager::Instance()->BuildFinalLightBuffers(m_pLightCB, m_pSunCB); else { material->bEnableLighting = false; material->bHasDetailMapTexture = false; } ID3D11Buffer* vs_cbs[2] = { m_pShadingCB, m_pMatrixCB }; m_pD3DSystem->GetDeviceContext()->VSSetConstantBuffers(2, 2, vs_cbs); ID3D11Buffer* ps_cbs[3] = { m_pLightCB, m_pSunCB, m_pShadingCB }; m_pD3DSystem->GetDeviceContext()->PSSetConstantBuffers(0, 3, ps_cbs); ID3D11ShaderResourceView* ps_srvs[11] = { diffuseArrayTexture, diffuseTexture, ambientTexture, specularTexture, emissiveTexture, normalMapTexture, blendMapTexture, detailMapTexture, alphaMapTexture, shadowMapTexture, ssaoTexture }; ID3D11SamplerState* ps_samp[2] = { m_pD3DSystem->Point(), m_pD3DSystem->Linear() }; ID3D11ShaderResourceView* vs_srvs[1] = { displacementMapTexture }; if (!m_Wireframe) { // Assign Texture m_pD3DSystem->GetDeviceContext()->VSSetSamplers(0, 2, ps_samp); m_pD3DSystem->GetDeviceContext()->PSSetSamplers(0, 2, ps_samp); m_pD3DSystem->GetDeviceContext()->VSSetShaderResources(11, 1, vs_srvs); m_pD3DSystem->GetDeviceContext()->PSSetShaderResources(0, 11, ps_srvs); SwitchTo("MaterialShaderPS", ZShadeSandboxShader::EShaderTypes::ST_PIXEL); } else { SwitchTo("MaterialShaderWireframePS", ZShadeSandboxShader::EShaderTypes::ST_PIXEL); } if (mrp.useInstancing) { SetInputLayout("MaterialShaderInstance"); SwitchTo("MaterialShaderInstanceVS", ZShadeSandboxShader::EShaderTypes::ST_VERTEX); } else { SetInputLayout("MaterialShader"); SwitchTo("MaterialShaderVS", ZShadeSandboxShader::EShaderTypes::ST_VERTEX); } SetVertexShader(); SetPixelShader(); //Perform Drawing if (mrp.useInstancing) { RenderIndexInstanced11(indexCount, instanceCount); } else { RenderIndex11(indexCount); } // Unbind if (!m_Wireframe) { ps_samp[0] = NULL; ps_samp[1] = NULL; m_pD3DSystem->GetDeviceContext()->VSSetSamplers(0, 2, ps_samp); m_pD3DSystem->GetDeviceContext()->PSSetSamplers(0, 2, ps_samp); vs_srvs[0] = NULL; m_pD3DSystem->GetDeviceContext()->VSSetShaderResources(11, 1, vs_srvs); for (int i = 0; i < 11; i++) ps_srvs[i] = NULL; m_pD3DSystem->GetDeviceContext()->PSSetShaderResources(0, 11, ps_srvs); } return true; }
//============================================================================================================================== bool AmbientLightDeferredShader::Render11 ( Camera* camera , ZShadeSandboxLighting::AmbientLight* light , XMFLOAT3 ambientUp , XMFLOAT3 ambientDown , ID3D11ShaderResourceView* colorTexture , ID3D11ShaderResourceView* normalTexture , ID3D11ShaderResourceView* depthTexture ) { cbDeferredLightBuffer cLB; cLB.g_AmbientLightColor = light->DiffuseColor(); cLB.g_AmbientDown = ambientDown; cLB.padding1 = 0; cLB.g_AmbientUp = ambientUp; cLB.padding2 = 0; cLB.g_InvViewProj = camera->InvViewProj4x4(); // Map the light buffer { D3D11_MAPPED_SUBRESOURCE mapped_res2; m_pD3DSystem->GetDeviceContext()->Map(m_pLightCB, 0, D3D11_MAP_WRITE_DISCARD, 0, &mapped_res2); { assert(mapped_res2.pData); *(cbDeferredLightBuffer*)mapped_res2.pData = cLB; } m_pD3DSystem->GetDeviceContext()->Unmap(m_pLightCB, 0); } ID3D11Buffer* ps_cbs[1] = { m_pLightCB }; m_pD3DSystem->GetDeviceContext()->PSSetConstantBuffers(0, 1, ps_cbs); // Assign Texture ID3D11ShaderResourceView* ps_srvs[3] = { colorTexture, normalTexture, depthTexture }; ID3D11SamplerState* ps_samp[2] = { m_pD3DSystem->Point(), m_pD3DSystem->Linear() }; if (!m_Wireframe) { m_pD3DSystem->GetDeviceContext()->PSSetShaderResources(0, 3, ps_srvs); m_pD3DSystem->GetDeviceContext()->PSSetSamplers(0, 2, ps_samp); SwitchTo("AmbientLightDeferredPS", ZShadeSandboxShader::EShaderTypes::ST_PIXEL); } else { SwitchTo("AmbientLightDeferredWireframePS", ZShadeSandboxShader::EShaderTypes::ST_PIXEL); } m_pD3DSystem->TurnOnAdditiveBlending(); //m_pD3DSystem->TurnOnAlphaBlending(); SetVertexShader(); SetPixelShader(); //Perform Drawing onto a fullscreen quad with a NULL Input Layout RenderDraw11(4); //m_pD3DSystem->TurnOffAlphaBlending(); m_pD3DSystem->TurnOffAdditiveBlending(); // Unbind if (!m_Wireframe) { ps_samp[0] = NULL; ps_samp[1] = NULL; m_pD3DSystem->GetDeviceContext()->PSSetSamplers(0, 2, ps_samp); ps_srvs[0] = NULL; ps_srvs[1] = NULL; ps_srvs[2] = NULL; m_pD3DSystem->GetDeviceContext()->PSSetShaderResources(0, 3, ps_srvs); } return true; }
//============================================================================================================================== bool TerrainTessellationQuadSSAOShader::Render(int indexCount, Camera* camera, LightCamera* lightcamera, ZShadeSandboxTerrain::TerrainShadingConst terrainShadingConst, ID3D11ShaderResourceView* heightMapSRV) { cTessellationBuffer cTB; cMatrixBuffer cMB; cDomainConstBuffer cDCB; cShadingConstBuffer cSCB; //if (m_UseCustomWorld) // cMB.g_WorldMatrix = ZShadeSandboxMath::ZMath::GMathMF(XMMatrixTranspose(mWorld.Get())); //else // cMB.g_WorldMatrix = camera->World4x4(); cMB.g_ViewMatrix = camera->View4x4(); cMB.g_ProjMatrix = camera->Proj4x4(); XMMATRIX toTexSpace = XMMatrixScaling(0.5f, -0.5f, 1.0f) * XMMatrixTranslation(0.5f, 0.5f, 0); cMB.g_TexSpaceMatrix = ZShadeSandboxMath::ZMath::GMathMF(XMMatrixTranspose(toTexSpace)); // Need to create the shadow matrix cMB.g_ShadowMatrix = lightcamera->ShadowTransform4x4(); cTB.g_EyePosW = terrainShadingConst.g_EyePosW; cTB.g_MinDist = terrainShadingConst.g_MinDist; cTB.g_MaxDist = terrainShadingConst.g_MaxDist; cTB.g_MinTess = terrainShadingConst.g_MinTess; cTB.g_MaxTess = terrainShadingConst.g_MaxTess; cTB.g_FrustumCull = terrainShadingConst.g_FrustumCull; cTB.padding = XMFLOAT2(0, 0); cTB.g_TerrSize = terrainShadingConst.g_MapSize; cTB.g_TerrScale = terrainShadingConst.g_TerrSize; cDCB.g_TexScale = XMFLOAT2(66.0f, 66.0f); cDCB.g_HeightScale = terrainShadingConst.g_HeightScale; cDCB.g_TerrainZScale = terrainShadingConst.g_TerrSize; cDCB.g_ClipPlane = terrainShadingConst.g_ClipPlane; cDCB.g_tpadding = XMFLOAT3(0, 0, 0); cDCB.g_FarPlane = terrainShadingConst.g_FarPlane; cSCB.g_EyePosW = terrainShadingConst.g_EyePosW; cSCB.g_DetailBrightness = terrainShadingConst.g_DetailBrightness; cSCB.g_fogThinning = terrainShadingConst.g_fogThinning; cSCB.g_fogAltitude = terrainShadingConst.g_fogAltitude; cSCB.g_fogNear = terrainShadingConst.g_fogNear; cSCB.g_fogFar = terrainShadingConst.g_fogFar; cSCB.g_fogColor = terrainShadingConst.g_fogColor; cSCB.g_TextureAmount = terrainShadingConst.g_TextureAmount; cSCB.g_TextureWidth = terrainShadingConst.g_TextureWidth; cSCB.g_TextureHeight = terrainShadingConst.g_TextureHeight; cSCB.g_seaLevel = terrainShadingConst.g_seaLevel; cSCB.g_waterBodyColor = terrainShadingConst.g_waterBodyColor; //cSCB.g_SunDir = terrainShadingConst.g_SunDir; //cSCB.g_EnableSun = terrainShadingConst.g_EnableSun; //cSCB.g_SunDiffuseColor = terrainShadingConst.g_SunDiffuseColor; cSCB.g_MaterialDiffuseColor = terrainShadingConst.g_MaterialDiffuseColor; cSCB.g_MaterialAmbientColor = terrainShadingConst.g_MaterialAmbientColor; cSCB.g_TexelCellSpaceU = terrainShadingConst.g_TexelCellSpaceU; cSCB.g_TexelCellSpaceV = terrainShadingConst.g_TexelCellSpaceV; cSCB.g_MaterialSpecularPower = terrainShadingConst.g_MaterialSpecularPower; cSCB.g_MaterialSpecularIntensity = terrainShadingConst.g_MaterialSpecularIntensity; cSCB.g_useClippingPlane = terrainShadingConst.g_useClippingPlane; cSCB.g_useNormalMap = terrainShadingConst.g_useNormalMap; cSCB.g_UseSobelFilter = terrainShadingConst.g_UseSobelFilter; cSCB.g_useShadowMap = terrainShadingConst.g_useShadowMap; cSCB.tpadding = XMFLOAT3(0, 0, 0); cSCB.g_useSSAO = terrainShadingConst.g_useSSAO; cSCB.g_ViewMatrix = cMB.g_ViewMatrix; ZShadeSandboxLighting::LightManager::Instance()->BuildFinalLightBuffers(m_pLightCB, m_pSunCB); // Map tessellation constants { D3D11_MAPPED_SUBRESOURCE mapped_res; m_pD3DSystem->GetDeviceContext()->Map(m_pTessellationCB, 0, D3D11_MAP_WRITE_DISCARD, 0, &mapped_res); { assert(mapped_res.pData); *(cTessellationBuffer*)mapped_res.pData = cTB; } m_pD3DSystem->GetDeviceContext()->Unmap(m_pTessellationCB, 0); } // Map domain shader constants { D3D11_MAPPED_SUBRESOURCE mapped_res; m_pD3DSystem->GetDeviceContext()->Map(m_pDomainCB, 0, D3D11_MAP_WRITE_DISCARD, 0, &mapped_res); { assert(mapped_res.pData); *(cDomainConstBuffer*)mapped_res.pData = cDCB; } m_pD3DSystem->GetDeviceContext()->Unmap(m_pDomainCB, 0); } // Map matrix constants { D3D11_MAPPED_SUBRESOURCE mapped_res; m_pD3DSystem->GetDeviceContext()->Map(m_pMatrixBufferCB, 0, D3D11_MAP_WRITE_DISCARD, 0, &mapped_res); { assert(mapped_res.pData); *(cMatrixBuffer*)mapped_res.pData = cMB; } m_pD3DSystem->GetDeviceContext()->Unmap(m_pMatrixBufferCB, 0); } // Map pixel shading constants { D3D11_MAPPED_SUBRESOURCE mapped_res; m_pD3DSystem->GetDeviceContext()->Map(m_pShadingCB, 0, D3D11_MAP_WRITE_DISCARD, 0, &mapped_res); { assert(mapped_res.pData); *(cShadingConstBuffer*)mapped_res.pData = cSCB; } m_pD3DSystem->GetDeviceContext()->Unmap(m_pShadingCB, 0); } // Set the tessellation constant buffer into the Hull ZShadeSandboxShader::Shader ID3D11Buffer* hs_cbs[1] = { m_pTessellationCB }; m_pD3DSystem->GetDeviceContext()->HSSetConstantBuffers(0, 1, hs_cbs); // Set the domain constant buffer into the Domain ZShadeSandboxShader::Shader // Set the matrix constant buffer into the Domain ZShadeSandboxShader::Shader ID3D11Buffer* ds_cbs[2] = { m_pDomainCB, m_pMatrixBufferCB }; m_pD3DSystem->GetDeviceContext()->DSSetConstantBuffers(0, 2, ds_cbs); // Set the shading constant buffer into the Pixel ZShadeSandboxShader::Shader ID3D11Buffer* ps_cbs[3] = { m_pShadingCB, m_pLightCB, m_pSunCB }; m_pD3DSystem->GetDeviceContext()->PSSetConstantBuffers(0, 3, ps_cbs); // Set the heightmap texture into the vertex shader ID3D11ShaderResourceView* vs_srvs[1] = { heightMapSRV }; m_pD3DSystem->GetDeviceContext()->VSSetShaderResources(0, 1, vs_srvs); // Set the heightmap texture into the domain shader ID3D11ShaderResourceView* ds_srvs[1] = { heightMapSRV }; m_pD3DSystem->GetDeviceContext()->DSSetShaderResources(0, 1, ds_srvs); // Set the textures into the Pixel Shader ID3D11ShaderResourceView* ps_srvs[1] = { heightMapSRV }; m_pD3DSystem->GetDeviceContext()->PSSetShaderResources(0, 1, ps_srvs); // Tell the shader what input layout to use SetInputLayout("TerrainTessellationQuadSSAOShader"); // Assign the shaders to render the mesh SetVertexShader(); SetHullShader(); SetDomainShader(); SetPixelShader(); //Perform Drawing RenderIndex11(indexCount); return true; }
//============================================================================================================================== bool TriMaterialTessellationShader::Render11(int indexCount, ZShadeSandboxMath::XMMath4 clipplane, Camera* camera, float tessFactor, ZShadeSandboxLighting::ShaderMaterial* material) { int useDiffuseArrayTexture = 0; int useDiffuseTexture = 0; int useNormalMapTexture = 0; int useBlendMapTexture = 0; int useDetailMapTexture = 0; int useAlphaMapTexture = 0; ID3D11ShaderResourceView* diffuseArrayTexture = 0; ID3D11ShaderResourceView* diffuseTexture = 0; ID3D11ShaderResourceView* normalMapTexture = 0; ID3D11ShaderResourceView* blendMapTexture = 0; ID3D11ShaderResourceView* detailMapTexture = 0; ID3D11ShaderResourceView* alphaMapTexture = 0; for (int i = 0; i < material->TextureCount(); i++) { switch (material->GetMaterialTextureType(i)) { case ZShadeSandboxLighting::EMaterialTextureType::eDiffuseArray: useDiffuseArrayTexture = 1; diffuseArrayTexture = material->GetTexture(i)->getTexture11(); break; case ZShadeSandboxLighting::EMaterialTextureType::eDiffuse: useDiffuseTexture = 1; diffuseTexture = material->GetTexture(i)->getTexture11(); break; case ZShadeSandboxLighting::EMaterialTextureType::eNormal: useNormalMapTexture = 1; normalMapTexture = material->GetTexture(i)->getTexture11(); break; case ZShadeSandboxLighting::EMaterialTextureType::eBlend: useBlendMapTexture = 1; blendMapTexture = material->GetTexture(i)->getTexture11(); break; case ZShadeSandboxLighting::EMaterialTextureType::eDetail: useDetailMapTexture = 1; detailMapTexture = material->GetTexture(i)->getTexture11(); break; case ZShadeSandboxLighting::EMaterialTextureType::eAlpha: useAlphaMapTexture = 1; alphaMapTexture = material->GetTexture(i)->getTexture11(); break; } } Const_Per_Frame per_frame; per_frame.g_EyePosW = camera->Position(); per_frame.g_ClipPlane = XMFLOAT4(clipplane.x, clipplane.y, clipplane.z, clipplane.w); per_frame.g_MaterialDiffuseColor = material->DiffuseColor(); per_frame.g_MaterialAmbientColor = material->AmbientColor(); per_frame.g_MaterialSpecularPower = material->SpecularPower(); per_frame.g_MaterialSpecularIntensity = material->SpecularIntensity(); per_frame.g_UsingDiffuseArrayTexture = useDiffuseArrayTexture; per_frame.g_UsingDiffuseTexture = useDiffuseArrayTexture; per_frame.g_UsingNormalMapTexture = useNormalMapTexture; per_frame.g_UsingBlendMapTexture = useBlendMapTexture; per_frame.g_UsingDetailMapTexture = useDetailMapTexture; per_frame.g_UseAlphaMapTexture = useAlphaMapTexture; per_frame.g_EnableTransparency = material->EnableTransparency(); per_frame.g_EnableLighting = material->EnableLighting(); per_frame.g_DetailBrightness = material->DetailBrightness(); per_frame.g_AlphaToCoverageValue = material->AlphaToCoverageValue(); // Value that clips pixel during alpha blending per_frame.g_FlipTextureH = (bFlipHorizontally == true) ? 1 : 0; per_frame.g_FlipTextureV = (bFlipVertically == true) ? 1 : 0; per_frame.padding = 0; Const_Per_Object per_object; if (m_UseCustomWorld) { XMFLOAT4X4 world = ZShadeSandboxMath::ZMath::GMathMF(XMMatrixTranspose(mWorld.Get())); per_object.g_matWorld = world; } else per_object.g_matWorld = camera->World4x4(); if (m_UseCustomView) { per_object.g_matView = mView; } else per_object.g_matView = camera->View4x4(); if (m_pD3DSystem->GetEngineOptions()->m_DimType == DimType::ZSHADE_2D) per_object.g_matProj = camera->Ortho4x4(); else if (m_pD3DSystem->GetEngineOptions()->m_DimType == DimType::ZSHADE_3D) per_object.g_matProj = camera->Proj4x4(); if (m_UseOrtho) { per_object.g_matProj = camera->Ortho4x4(); } ZShadeSandboxLighting::cbLightBuffer cLB; ZShadeSandboxLighting::cbAmbientLightBuffer alb; ZShadeSandboxLighting::cbDirectionalLightBuffer dlb; ZShadeSandboxLighting::cbSpotLightBuffer slb; ZShadeSandboxLighting::cbPointLightBuffer plb; ZShadeSandboxLighting::cbCapsuleLightBuffer clb; for (int i = 0; i < material->GetLightBuffer()->g_AmbientLightCount; i++) { alb.g_AmbientColor = material->GetLightBuffer()->g_AmbientLight[i].g_AmbientColor; cLB.g_AmbientLight[i] = alb; } for (int i = 0; i < material->GetLightBuffer()->g_DirectionalLightCount; i++) { dlb.g_Direction = material->GetLightBuffer()->g_DirectionalLight[i].g_LightDirection; dlb.padding = 0; dlb.g_Ambient = material->GetLightBuffer()->g_DirectionalLight[i].g_AmbientColor; dlb.g_Diffuse = material->GetLightBuffer()->g_DirectionalLight[i].g_DiffuseColor; cLB.g_DirectionalLight[i] = dlb; } for (int i = 0; i < material->GetLightBuffer()->g_SpotLightCount; i++) { slb.g_AmbientColor = material->GetLightBuffer()->g_SpotLight[i].g_AmbientColor; slb.g_DiffuseColor = material->GetLightBuffer()->g_SpotLight[i].g_DiffuseColor; slb.g_LightPosition = material->GetLightBuffer()->g_SpotLight[i].g_LightPosition; slb.padding = 0; slb.g_LightRange = material->GetLightBuffer()->g_SpotLight[i].g_LightRange; slb.g_SpotCosOuterCone = material->GetLightBuffer()->g_SpotLight[i].g_SpotCosOuterCone; slb.g_SpotInnerConeReciprocal = material->GetLightBuffer()->g_SpotLight[i].g_SpotInnerConeReciprocal; slb.g_CosineAngle = material->GetLightBuffer()->g_SpotLight[i].g_CosineAngle; cLB.g_SpotLight[i] = slb; } for (int i = 0; i < material->GetLightBuffer()->g_PointLightCount; i++) { plb.g_LightPosition = material->GetLightBuffer()->g_PointLight[i].g_LightPosition; plb.g_LightRange = material->GetLightBuffer()->g_PointLight[i].g_LightRange; plb.g_Attenuation = material->GetLightBuffer()->g_PointLight[i].g_Attenuation; plb.padding = 0; plb.g_AmbientColor = material->GetLightBuffer()->g_PointLight[i].g_AmbientColor; plb.g_DiffuseColor = material->GetLightBuffer()->g_PointLight[i].g_DiffuseColor; cLB.g_PointLight[i] = plb; } for (int i = 0; i < material->GetLightBuffer()->g_CapsuleLightCount; i++) { clb.g_LightPosition = material->GetLightBuffer()->g_CapsuleLight[i].g_LightPosition; clb.g_LightRange = material->GetLightBuffer()->g_CapsuleLight[i].g_LightRange; clb.g_LightDirection = material->GetLightBuffer()->g_CapsuleLight[i].g_LightDirection; clb.g_DiffuseColor = material->GetLightBuffer()->g_CapsuleLight[i].g_DiffuseColor; clb.g_LightLength = material->GetLightBuffer()->g_CapsuleLight[i].g_LightLength; clb.g_CapsuleDirectionLength = material->GetLightBuffer()->g_CapsuleLight[i].g_CapsuleDirectionLength; clb.g_CapsuleIntensity = material->GetLightBuffer()->g_CapsuleLight[i].g_CapsuleIntensity; cLB.g_CapsuleLight[i] = clb; } cLB.g_AmbientLightCount = material->GetLightBuffer()->g_AmbientLightCount; cLB.g_DirectionalLightCount = material->GetLightBuffer()->g_DirectionalLightCount; cLB.g_SpotLightCount = material->GetLightBuffer()->g_SpotLightCount; cLB.g_PointLightCount = material->GetLightBuffer()->g_PointLightCount; cLB.g_CapsuleLightCount = material->GetLightBuffer()->g_CapsuleLightCount; cLB.g_AmbientDown = material->GetLightBuffer()->g_AmbientDown; cLB.g_AmbientUp = material->GetLightBuffer()->g_AmbientUp; cLB.padding = 0; ZShadeSandboxLighting::cbSunLightBuffer cSLB; cSLB.g_SunDir = material->GetSunLightBuffer()->g_SunDir; cSLB.g_EnableSun = material->GetSunLightBuffer()->g_EnableSun; cSLB.g_SunDiffuseColor = material->GetSunLightBuffer()->g_SunDiffuseColor; cSLB.padding = XMFLOAT3(0, 0, 0); cSLB.g_SunShineness = material->GetSunLightBuffer()->g_SunShineness; cTessellationBuffer cTB; cTB.g_TessellationFactor = tessFactor; cTB.padding = XMFLOAT3(0, 0, 0); // Map tessellation constants { D3D11_MAPPED_SUBRESOURCE mapped_res; m_pD3DSystem->GetDeviceContext()->Map(m_pTessellationCB, 0, D3D11_MAP_WRITE_DISCARD, 0, &mapped_res); { assert(mapped_res.pData); *(cTessellationBuffer*)mapped_res.pData = cTB; } m_pD3DSystem->GetDeviceContext()->Unmap(m_pTessellationCB, 0); } // Map the per frame constants { D3D11_MAPPED_SUBRESOURCE mapped_res; m_pD3DSystem->GetDeviceContext()->Map(m_pPerFrameCB, 0, D3D11_MAP_WRITE_DISCARD, 0, &mapped_res); { assert(mapped_res.pData); *(Const_Per_Frame*)mapped_res.pData = per_frame; } m_pD3DSystem->GetDeviceContext()->Unmap(m_pPerFrameCB, 0); } // Map the matrix constants { D3D11_MAPPED_SUBRESOURCE mapped_res2; m_pD3DSystem->GetDeviceContext()->Map(m_pPerObjectCB, 0, D3D11_MAP_WRITE_DISCARD, 0, &mapped_res2); { assert(mapped_res2.pData); *(Const_Per_Object*)mapped_res2.pData = per_object; } m_pD3DSystem->GetDeviceContext()->Unmap(m_pPerObjectCB, 0); } // Map light shading constants { D3D11_MAPPED_SUBRESOURCE mapped_res; m_pD3DSystem->GetDeviceContext()->Map(m_pLightCB, 0, D3D11_MAP_WRITE_DISCARD, 0, &mapped_res); { assert(mapped_res.pData); *(ZShadeSandboxLighting::cbLightBuffer*)mapped_res.pData = cLB; } m_pD3DSystem->GetDeviceContext()->Unmap(m_pLightCB, 0); } // Map sun light shading constants { D3D11_MAPPED_SUBRESOURCE mapped_res; m_pD3DSystem->GetDeviceContext()->Map(m_pSunCB, 0, D3D11_MAP_WRITE_DISCARD, 0, &mapped_res); { assert(mapped_res.pData); *(ZShadeSandboxLighting::cbSunLightBuffer*)mapped_res.pData = cSLB; } m_pD3DSystem->GetDeviceContext()->Unmap(m_pSunCB, 0); } // Set the tessellation constant buffer into the Hull Shader ID3D11Buffer* hs_cbs[1] = { m_pTessellationCB }; m_pD3DSystem->GetDeviceContext()->HSSetConstantBuffers(0, 1, hs_cbs); // Set the matrix constant buffer into the Domain Shader ID3D11Buffer* ds_cbs[2] = { m_pPerFrameCB, m_pPerObjectCB }; m_pD3DSystem->GetDeviceContext()->DSSetConstantBuffers(0, 2, ds_cbs); //ID3D11Buffer* vs_cbs[2] = { m_pPerFrameCB, m_pPerObjectCB }; //m_pD3DSystem->GetDeviceContext()->VSSetConstantBuffers(0, 2, vs_cbs); ID3D11Buffer* ps_cbs[3] = { m_pPerFrameCB, m_pLightCB, m_pSunCB }; m_pD3DSystem->GetDeviceContext()->PSSetConstantBuffers(0, 3, ps_cbs); ID3D11ShaderResourceView* ps_srvs[6] = { diffuseArrayTexture, diffuseTexture, normalMapTexture, blendMapTexture, detailMapTexture, alphaMapTexture }; if (!m_Wireframe) { // Assign Texture m_pD3DSystem->GetDeviceContext()->PSSetShaderResources(0, 6, ps_srvs); SwitchTo("MaterialTessellationShaderPS", ZShadeSandboxShader::EShaderTypes::ST_PIXEL); } else { SwitchTo("MaterialTessellationShaderWireframePS", ZShadeSandboxShader::EShaderTypes::ST_PIXEL); } SetVertexShader(); SetHullShader(); SetDomainShader(); SetPixelShader(); SetInputLayout("TriMaterialTessellationShader"); //Perform Drawing RenderIndex11(indexCount); // Unbind if (!m_Wireframe) { for (int i = 0; i < 6; i++) ps_srvs[i] = NULL; m_pD3DSystem->GetDeviceContext()->PSSetShaderResources(0, 6, ps_srvs); } // Set Hull, Domain and Geometry Shaders to null in case they are not needed m_pD3DSystem->GetDeviceContext()->HSSetShader(NULL, NULL, 0); m_pD3DSystem->GetDeviceContext()->DSSetShader(NULL, NULL, 0); m_pD3DSystem->GetDeviceContext()->GSSetShader(NULL, NULL, 0); return true; }
/* Draws a rectangle specified by a Rect4F structure. */ static int galDrawRectangle(IDevice *pContext, Rect4F bounds) { GIDevice *icontext = NULL; if ((icontext = (GIDevice*)pContext) == NULL) { return GI_ERROR; } struct pipe_context *context; if ((context = icontext->context) == NULL) { return GI_ERROR; } GIEdge edge[4]; edge[0].x = (bounds.x); edge[0].y = (bounds.y); edge[0].r = 1.0f; edge[0].g = 0.0f; edge[0].b = 0.0f; edge[0].a = 1.0f; edge[1].x = (bounds.x + bounds.width); edge[1].y = (bounds.y); edge[1].r = 0.0f; edge[1].g = 1.0f; edge[1].b = 0.0f; edge[1].a = 0.6f; edge[2].x = (bounds.x + bounds.width); edge[2].y = (bounds.y + bounds.height); edge[2].r = 0.0f; edge[2].g = 0.0f; edge[2].b = 1.0f; edge[2].a = 0.6f; edge[3].x = (bounds.x); edge[3].y = (bounds.y + bounds.height); edge[3].r = 1.0f; edge[3].g = 0.0f; edge[3].b = 0.0f; edge[3].a = 0.6f; pipe_buffer_write(context, icontext->buffer, 0, sizeof(edge), edge); struct pipe_draw_info info; memset(&info, 0, sizeof(info)); info.instance_count = 1; info.max_index = 0xffffffff; info.mode = PIPE_PRIM_QUADS; info.start = 0; info.count = 4; info.min_index = 0; info.max_index = 0 + 2 - 1; SetPixelShader(context, icontext->fs_color); context->draw_vbo(context, &info); SetPixelShader(context, NULL); return GI_SUCCESS; }
//============================================================================= // draw //============================================================================= void Title::Draw() { auto graphic_device = GET_GRAPHIC_DEVICE(); auto gb_vs = graphic_device->LoadVertexShader("resources/shader/graphics_buffer.vsc"); auto gb_ps = graphic_device->LoadPixelShader("resources/shader/graphics_buffer.psc"); auto d_vs = graphic_device->LoadVertexShader("resources/shader/deferred.vsc"); auto d_ps = graphic_device->LoadPixelShader("resources/shader/deferred.psc"); auto basic_vs = graphic_device->LoadVertexShader("resources/shader/basic.vsc"); auto basic_ps = graphic_device->LoadPixelShader("resources/shader/basic.psc"); //画面クリア graphic_device->Clear(float4(1.0f, 1.0f, 1.0f, 1.0f), 1.0f); //デバッグワイヤーフレーム // graphic_device->GetDevice()->SetRenderState(D3DRS_FILLMODE, D3DFILL_WIREFRAME); float4 color(1.0f, 1.0f, 1.0f, 1.0f); //シェーダ設定 graphic_device->SetVertexShader(basic_vs); graphic_device->SetPixelShader(basic_ps); basic_vs->SetValue("_view_matrix", (f32*)&observer_2d_->GetViewMatrix(), 16); basic_vs->SetValue("_projection_matrix", (f32*)&observer_2d_->GetProjectionMatrix(), 16); basic_vs->SetValue("_world_matrix", (f32*)&background_->GetMatrix(), 16); basic_vs->SetValue("_color", (f32*)&color,4); basic_ps->SetTexture("_texture_sampler", background_->GetTexture(0)->GetTexture()); //背景 background_->Draw(); //パーティクル for (u32 i = 0; i < PARTICUL_MAX; ++i) { basic_vs->SetValue("_world_matrix", (f32*)&particul_[i].particul_->GetMatrix(), 16); basic_vs->SetValue("_color", (f32*)&color, 4); basic_ps->SetTexture("_texture_sampler", particul_[i].particul_->GetTexture(0)->GetTexture()); //ロゴ particul_[i].particul_->Draw(); } basic_vs->SetValue("_world_matrix", (f32*)&logo_->GetMatrix(), 16); basic_vs->SetValue("_color", (f32*)&color, 4); basic_ps->SetTexture("_texture_sampler", logo_->GetTexture(0)->GetTexture()); //ロゴ logo_->Draw(); draw_cnt_++; if (draw_cnt_ > 100) { use_flag_ = true; } if (draw_cnt_ > 200) { draw_cnt_ = 0; use_flag_ = false; } if (use_flag_) { //ボタン背景 basic_vs->SetValue("_world_matrix", (f32*)&button_interface_->GetMatrix(), 16); basic_vs->SetValue("_color", (f32*)&color, 4); basic_ps->SetTexture("_texture_sampler", button_interface_->GetTexture(0)->GetTexture()); //ボタン背景 button_interface_->Draw(); basic_vs->SetValue("_world_matrix", (f32*)&button_->GetMatrix(), 16); basic_vs->SetValue("_color", (f32*)&color, 4); basic_ps->SetTexture("_texture_sampler", button_->GetTexture(0)->GetTexture()); //ボタン button_->Draw(); } }
//----------------------------------------------------------------------------- // Render // Performs rendering //----------------------------------------------------------------------------- void CRenderer::Render( CTerrain* pTerrain ) { ////////////////////////////////////////// // Just render the text if( !gnRenderOn ) { // Don't render if we shouldn't m_nPrevNumCommands = 0; m_nPrevNumBoxes = 0; m_pDevice->Clear(); UI::Draw( m_pDevice ); m_pDevice->Present(); return; } ////////////////////////////////////////// // Sort the list Sort(); ////////////////////////////////////////// // Restore solid fill mode if( gnRenderWireframe ) m_pDevice->SetFillMode( GFX_FILL_WIREFRAME ); else m_pDevice->SetFillMode( GFX_FILL_SOLID ); ////////////////////////////////////////// // Update lighting m_pDevice->UpdateBuffer( m_pLightCB, m_pPrevLights ); m_pDevice->SetPSConstantBuffer( 0, m_pLightCB ); ////////////////////////////////////////// // Clear m_pDevice->Clear(); m_pDevice->SetDepthTest( true, true ); ////////////////////////////////////////// // Render ASSERT( m_pCurrentView ); SetViewProj( m_pCurrentView->GetViewMatrix(), m_pCurrentView->GetProjMatrix() ); // if( m_pTestRT ) // { // m_pDevice->ClearRenderTarget( m_pTestRT ); // m_pDevice->SetRenderTarget( m_pTestRT ); // } // ////////////////////////////////////////// // // Z pre-pass // { // m_pDevice->SetColorWrite( true ); // m_pDevice->SetDepthTest( true, true ); // // ////////////////////////////////////////// // // Render the terrain // SetVertexShader( eVS3DPosNorTexNoTransform ); // SetPixelShader( ePS3DStd ); // pTerrain->Render(); // SetVertexShader( eVS3DPosNorTexStd ); // // ////////////////////////////////////////// // // Perform basic object rendering // for( sint i = 0; i < m_nPrevNumCommands; ++i ) // { // ProcessCommand( m_pPrevCommands[i], m_pPrevTransforms[i] ); // } // } ////////////////////////////////////////// // Actual rendering { m_pDevice->SetColorWrite( true ); // m_pDevice->SetDepthTest( true, false ); // TEMP! m_pDevice->SetDepthTest( true, true ); ////////////////////////////////////////// // Render the terrain SetVertexShader( eVS3DPosNorTexNoTransform ); SetPixelShader( ePS3DStd ); pTerrain->Render(); SetVertexShader( eVS3DPosNorTexStd ); /* ////////////////////////////////////////// // Perform basic object rendering for( sint i = 0; i < m_nPrevNumCommands; ++i ) { ProcessCommand( m_pPrevCommands[i], m_pPrevTransforms[i] ); } */ } // ////////////////////////////////////////// // // Draw the debug volumes // if( gnShowBoundingVolumes ) // { // m_pDevice->SetFillMode( GFX_FILL_WIREFRAME ); // SetVertexShader( eVS3DPosColStd ); // SetPixelShader( ePS3DColor ); // // // Draw the debug boxes // for( sint i = 0; i < m_nPrevNumBoxes; ++i ) // { // RVector3 vMin = m_pPrevDebugBoxes[i].box.min; // RVector3 vMax = m_pPrevDebugBoxes[i].box.max; // RVector3 vColor = m_pPrevDebugBoxes[i].color; // // RMatrix4 mWorld = RMatrix4Identity(); // SetWorldMatrix( mWorld ); // // VPosColor vertices[] = // { // { RVector3( vMin.x, vMax.y, vMin.z ), Homogonize( vColor ) }, // { RVector3( vMax.x, vMax.y, vMin.z ), Homogonize( vColor ) }, // { RVector3( vMax.x, vMax.y, vMax.z ), Homogonize( vColor ) }, // { RVector3( vMin.x, vMax.y, vMax.z ), Homogonize( vColor ) }, // // { RVector3( vMin.x, vMin.y, vMin.z ), Homogonize( vColor ) }, // { RVector3( vMax.x, vMin.y, vMin.z ), Homogonize( vColor ) }, // { RVector3( vMax.x, vMin.y, vMax.z ), Homogonize( vColor ) }, // { RVector3( vMin.x, vMin.y, vMax.z ), Homogonize( vColor ) }, // // { RVector3( vMin.x, vMin.y, vMax.z ), Homogonize( vColor ) }, // { RVector3( vMin.x, vMin.y, vMin.z ), Homogonize( vColor ) }, // { RVector3( vMin.x, vMax.y, vMin.z ), Homogonize( vColor ) }, // { RVector3( vMin.x, vMax.y, vMax.z ), Homogonize( vColor ) }, // // { RVector3( vMax.x, vMin.y, vMax.z ), Homogonize( vColor ) }, // { RVector3( vMax.x, vMin.y, vMin.z ), Homogonize( vColor ) }, // { RVector3( vMax.x, vMax.y, vMin.z ), Homogonize( vColor ) }, // { RVector3( vMax.x, vMax.y, vMax.z ), Homogonize( vColor ) }, // // { RVector3( vMin.x, vMin.y, vMin.z ), Homogonize( vColor ) }, // { RVector3( vMax.x, vMin.y, vMin.z ), Homogonize( vColor ) }, // { RVector3( vMax.x, vMax.y, vMin.z ), Homogonize( vColor ) }, // { RVector3( vMin.x, vMax.y, vMin.z ), Homogonize( vColor ) }, // // { RVector3( vMin.x, vMin.y, vMax.z ), Homogonize( vColor ) }, // { RVector3( vMax.x, vMin.y, vMax.z ), Homogonize( vColor ) }, // { RVector3( vMax.x, vMax.y, vMax.z ), Homogonize( vColor ) }, // { RVector3( vMin.x, vMax.y, vMax.z ), Homogonize( vColor ) }, // }; // // m_pDevice->UpdateBuffer( m_ppMeshes[m_nDebugBox]->m_pVertexBuffer, vertices ); // // m_ppMeshes[m_nDebugBox]->DrawMesh(); // } // // // Draw the rays // m_pDevice->SetPrimitiveType( GFX_PRIMITIVE_LINELIST ); // for( sint i = 0; i < m_nPrevNumRays; ++i ) // { // RVector3 vStart = m_pPrevDebugRays[i].start; // RVector3 vEnd = m_pPrevDebugRays[i].end; // // RVector4 vWhite( 1.0f, 1.0f, 1.0f, 1.0f ); // RVector4 vBlack( 0.0f, 0.0f, 0.0f, 0.0f ); // VPosColor vertices[] = // { // { vStart, vBlack }, // { vEnd, vWhite }, // }; // // m_pDevice->UpdateBuffer( m_pLineBuffer, vertices ); // // m_pDevice->SetVertexBuffer( 0, m_pLineBuffer, VPosColor::VertexStride ); // m_pDevice->DrawPrimitive( 2 ); // } // // m_pDevice->SetFillMode( GFX_FILL_SOLID ); // m_pDevice->SetPrimitiveType( GFX_PRIMITIVE_TRIANGLELIST ); // SetVertexShader( eVS3DPosNorTexStd ); // SetPixelShader( ePS3DStd ); // } // m_pDevice->SetDefaultRenderDepthTarget(); // m_pDevice->SetDepthTest( false, false ); // // SetVertexShader( eVS2DPos ); // SetPixelShader( ePS2DFS ); // SetSamplerState( eSamplerNearest ); // // if( m_pTestRT ) // m_pDevice->SetPSRenderTarget( 0, m_pTestRT ); // // m_pDevice->SetVertexBuffer( 0, m_pFSRectVB, VPos::VertexStride ); // m_pDevice->SetIndexBuffer( m_pFSRectIB, 2 ); // // m_pDevice->DrawIndexedPrimitive( 6 ); ////////////////////////////////////////// // Draw the UI // UI::Draw( m_pDevice ); // Present m_pDevice->Present(); }
//============================================================================================================================== bool DeferredShader::Render11 ( int indexCount , Camera* camera , XMMATRIX world , XMFLOAT2 specularPowerRange , float specularIntensity , float specularPower , ID3D11ShaderResourceView* texture ) { cbPackBuffer cPB; cPB.g_SpecularPowerRange = specularPowerRange; cPB.g_SpecularIntensity = specularIntensity; cPB.g_SpecularPower = specularPower; // Map the pack buffer { D3D11_MAPPED_SUBRESOURCE mapped_res2; m_pD3DSystem->GetDeviceContext()->Map(m_pPackCB, 0, D3D11_MAP_WRITE_DISCARD, 0, &mapped_res2); { assert(mapped_res2.pData); *(cbPackBuffer*)mapped_res2.pData = cPB; } m_pD3DSystem->GetDeviceContext()->Unmap(m_pPackCB, 0); } cbMatrixBuffer cMB; cMB.g_matWorld = ZShadeSandboxMath::ZMath::GMathMF(XMMatrixTranspose(world)); cMB.g_matView = camera->View4x4(); cMB.g_matProj = camera->Proj4x4(); // Map the matrix buffer { D3D11_MAPPED_SUBRESOURCE mapped_res2; m_pD3DSystem->GetDeviceContext()->Map(m_pMatrixCB, 0, D3D11_MAP_WRITE_DISCARD, 0, &mapped_res2); { assert(mapped_res2.pData); *(cbMatrixBuffer*)mapped_res2.pData = cMB; } m_pD3DSystem->GetDeviceContext()->Unmap(m_pMatrixCB, 0); } ID3D11Buffer* vs_cbs[1] = { m_pMatrixCB }; m_pD3DSystem->GetDeviceContext()->VSSetConstantBuffers(1, 1, vs_cbs); ID3D11Buffer* ps_cbs[1] = { m_pPackCB }; m_pD3DSystem->GetDeviceContext()->PSSetConstantBuffers(0, 1, ps_cbs); // Assign Texture ID3D11ShaderResourceView* ps_srvs[1] = { texture }; ID3D11SamplerState* ps_samp[1] = { m_pD3DSystem->Linear() }; if (!m_Wireframe) { m_pD3DSystem->GetDeviceContext()->PSSetShaderResources(0, 1, ps_srvs); m_pD3DSystem->GetDeviceContext()->PSSetSamplers(0, 1, ps_samp); SwitchTo("DeferredShaderPS", ZShadeSandboxShader::EShaderTypes::ST_PIXEL); } else { SwitchTo("DeferredShaderWireframePS", ZShadeSandboxShader::EShaderTypes::ST_PIXEL); } SetInputLayout("DeferredShader"); SetVertexShader(); SetPixelShader(); //Perform Drawing RenderIndex11(indexCount); // Unbind if (!m_Wireframe) { m_pD3DSystem->TurnOnCulling(); ps_samp[0] = NULL; m_pD3DSystem->GetDeviceContext()->PSSetSamplers(0, 1, ps_samp); ps_srvs[0] = NULL; m_pD3DSystem->GetDeviceContext()->PSSetShaderResources(0, 1, ps_srvs); } return true; }
//============================================================================================================================== bool OBJMeshShader::Render ( int startIndex , int indexCount , ZShadeSandboxMesh::MeshRenderParameters mrp , ZShadeSandboxLighting::ShaderMaterial* material ) { ID3D11ShaderResourceView* diffuseArrayTexture = 0; ID3D11ShaderResourceView* diffuseTexture = 0; ID3D11ShaderResourceView* ambientTexture = 0; ID3D11ShaderResourceView* specularTexture = 0; ID3D11ShaderResourceView* emissiveTexture = 0; ID3D11ShaderResourceView* normalMapTexture = 0; ID3D11ShaderResourceView* blendMapTexture = 0; ID3D11ShaderResourceView* detailMapTexture = 0; ID3D11ShaderResourceView* alphaMapTexture = 0; ID3D11ShaderResourceView* shadowMapTexture = 0; ID3D11ShaderResourceView* ssaoTexture = 0; ID3D11ShaderResourceView* displacementMapTexture = 0; material->GetTextures( diffuseArrayTexture, diffuseTexture, ambientTexture, specularTexture, emissiveTexture, normalMapTexture, blendMapTexture, detailMapTexture, alphaMapTexture, shadowMapTexture, ssaoTexture, displacementMapTexture ); material->BuildMaterialConstantBuffer(m_pShadingCB, mrp.camera->Position(), mrp.clipplane); mrp.camera->BuildCameraConstantBuffer(m_pD3DSystem, m_pMatrixCB, mrp.world, mrp.reflection); ZShadeSandboxLighting::LightManager::Instance()->BuildFinalLightBuffers(m_pLightCB, m_pSunCB); // Set the shading constant buffer and matrix constant buffer into the Vertex Shader ID3D11Buffer* vs_cbs[2] = { m_pShadingCB, m_pMatrixCB }; m_pD3DSystem->GetDeviceContext()->VSSetConstantBuffers(2, 2, vs_cbs); // Set the shading constant buffer into the Pixel Shader ID3D11Buffer* ps_cbs[3] = { m_pLightCB, m_pSunCB, m_pShadingCB }; m_pD3DSystem->GetDeviceContext()->PSSetConstantBuffers(0, 3, ps_cbs); ID3D11ShaderResourceView* ps_srvs[11] = { diffuseArrayTexture, diffuseTexture, ambientTexture, specularTexture, emissiveTexture, normalMapTexture, blendMapTexture, detailMapTexture, alphaMapTexture, shadowMapTexture, ssaoTexture }; ID3D11SamplerState* ps_samp[1] = { m_pD3DSystem->Linear() }; if (!m_Wireframe) { m_pD3DSystem->TurnOffCulling(); // Set the texture into the Pixel Shader m_pD3DSystem->GetDeviceContext()->PSSetShaderResources(0, 11, ps_srvs); m_pD3DSystem->GetDeviceContext()->PSSetSamplers(0, 1, ps_samp); SwitchTo("OBJMeshPS", ZShadeSandboxShader::EShaderTypes::ST_PIXEL); } else { SwitchTo("OBJMeshWireframePS", ZShadeSandboxShader::EShaderTypes::ST_PIXEL); } // Tell the shader what input layout to use SetInputLayout("OBJMeshShader"); // Assign the shaders to render the mesh SetVertexShader(); SetPixelShader(); //Perform Drawing RenderIndex11(startIndex, indexCount); // Unbind if (!m_Wireframe) { m_pD3DSystem->TurnOnCulling(); ps_samp[0] = NULL; m_pD3DSystem->GetDeviceContext()->PSSetSamplers(0, 1, ps_samp); for (int i = 0; i < 11; i++) ps_srvs[i] = NULL; m_pD3DSystem->GetDeviceContext()->PSSetShaderResources(0, 11, ps_srvs); } return true; }
//============================================================================================================================== bool OBJMeshShader::Render(int startIndex, int indexCount, Camera* camera, XMMATRIX wvp, XMFLOAT4 clipplane, XMFLOAT4 difColor, bool hasTexture, ID3D11ShaderResourceView* texture) { cbOBJShadingConst cSC; cbMatrixBuffer cMB; cMB.g_WVPMatrix = ZShadeSandboxMath::ZMath::GMathMF(XMMatrixTranspose(wvp)); //if (m_UseCustomWorld) // cMB.g_WorldMatrix = ZShadeSandboxMath::ZMath::GMathMF(XMMatrixTranspose(mWorld.Get())); //else // cMB.g_WorldMatrix = camera->World4x4(); cSC.g_ClipPlane = clipplane; cSC.g_DifColor = difColor; cSC.padding = XMFLOAT2(0, 0); cSC.g_FarPlane = fFarPlane; cSC.g_hasTexture = (hasTexture == true) ? 1 : 0; // Map shading constants { D3D11_MAPPED_SUBRESOURCE mapped_res; m_pD3DSystem->GetDeviceContext()->Map(m_pOBJShadingCB, 0, D3D11_MAP_WRITE_DISCARD, 0, &mapped_res); { assert(mapped_res.pData); *(cbOBJShadingConst*)mapped_res.pData = cSC; } m_pD3DSystem->GetDeviceContext()->Unmap(m_pOBJShadingCB, 0); } // Map matrix constants { D3D11_MAPPED_SUBRESOURCE mapped_res; m_pD3DSystem->GetDeviceContext()->Map(m_pMatrixBufferCB, 0, D3D11_MAP_WRITE_DISCARD, 0, &mapped_res); { assert(mapped_res.pData); *(cbMatrixBuffer*)mapped_res.pData = cMB; } m_pD3DSystem->GetDeviceContext()->Unmap(m_pMatrixBufferCB, 0); } // Set the shading constant buffer and matrix constant buffer into the Vertex ZShadeSandboxShader::Shader ID3D11Buffer* vs_cbs[2] = { m_pOBJShadingCB, m_pMatrixBufferCB }; m_pD3DSystem->GetDeviceContext()->VSSetConstantBuffers(0, 2, vs_cbs); // Set the shading constant buffer into the Pixel Shader ID3D11Buffer* ps_cbs[1] = { m_pOBJShadingCB }; m_pD3DSystem->GetDeviceContext()->PSSetConstantBuffers(0, 1, ps_cbs); ID3D11ShaderResourceView* ps_srvs[1] = { texture }; ID3D11SamplerState* ps_samp[1] = { m_pD3DSystem->Linear() }; if (!m_Wireframe) { m_pD3DSystem->TurnOffCulling(); // Set the texture into the Pixel Shader if (hasTexture) { m_pD3DSystem->GetDeviceContext()->PSSetShaderResources(0, 1, ps_srvs); m_pD3DSystem->GetDeviceContext()->PSSetSamplers(0, 1, ps_samp); } SwitchTo("OBJMeshPS", ZShadeSandboxShader::EShaderTypes::ST_PIXEL); } else { SwitchTo("OBJMeshWireframePS", ZShadeSandboxShader::EShaderTypes::ST_PIXEL); } // Tell the shader what input layout to use SetInputLayout("OBJMeshShader"); // Assign the shaders to render the mesh SetVertexShader(); SetPixelShader(); //Perform Drawing RenderIndex11(startIndex, indexCount); if (!m_Wireframe) { m_pD3DSystem->TurnOnCulling(); } // Unbind if (!m_Wireframe && hasTexture) { ps_samp[0] = NULL; m_pD3DSystem->GetDeviceContext()->PSSetSamplers(0, 1, ps_samp); ps_srvs[0] = NULL; m_pD3DSystem->GetDeviceContext()->PSSetShaderResources(0, 1, ps_srvs); } return true; }