CDx11UberEffect::CDx11UberEffect(ID3D11Device* device, ID3D11DeviceContext* deviceContext, const EFFECTCAPS& effectCaps) : CDx11Effect(device, deviceContext) , m_effectCaps(effectCaps) { memset(&m_diffuseTextureMatrixOffset, -1, sizeof(m_diffuseTextureMatrixOffset)); auto vertexShaderText = CDx11UberEffectGenerator::GenerateVertexShader(effectCaps); auto pixelShaderText = CDx11UberEffectGenerator::GeneratePixelShader(effectCaps); CompileVertexShader(vertexShaderText); CompilePixelShader(pixelShaderText); OffsetKeeper constantOffset; m_meshColorOffset = constantOffset.Allocate(0x10); m_worldMatrixOffset = constantOffset.Allocate(0x40); m_viewProjMatrixOffset = constantOffset.Allocate(0x40); if(effectCaps.hasShadowMap) m_shadowViewProjMatrixOffset = constantOffset.Allocate(0x40); if(effectCaps.hasDiffuseMap0) m_diffuseTextureMatrixOffset[0] = constantOffset.Allocate(0x40); if(effectCaps.hasDiffuseMap1) m_diffuseTextureMatrixOffset[1] = constantOffset.Allocate(0x40); if(effectCaps.hasDiffuseMap2) m_diffuseTextureMatrixOffset[2] = constantOffset.Allocate(0x40); if(effectCaps.hasDiffuseMap3) m_diffuseTextureMatrixOffset[3] = constantOffset.Allocate(0x40); if(effectCaps.hasDiffuseMap4) m_diffuseTextureMatrixOffset[4] = constantOffset.Allocate(0x40); CreateVertexConstantBuffer(constantOffset.currentOffset); }
void CDx11UmbralEffect::ParseVertexShaderConstantTable(OffsetKeeper& constantOffset, const CD3DShaderConstantTable& vertexShaderConstantTable, CD3DShaderConstantTable::REGISTER_SET registerSetFilter) { std::map<std::string, uint32&> parameterOffsets = { { "ModelBBoxOffSet", m_modelBBoxOffsetOffset }, { "ModelBBoxScale", m_modelBBoxScaleOffset }, { "vertexOcclusionScale", m_vertexOcclusionScaleOffset }, { "vertexColorBias", m_vertexColorBiasOffset }, { "PointLightColors", m_pointLightColorsOffset }, { "PointLightParams", m_pointLightParamsOffset }, { "PointLightPositions", m_pointLightPositionsOffset }, { "viewITMatrix", m_viewITMatrixOffset }, { "worldITMatrix", m_worldITMatrixOffset }, { "worldMatrix", m_worldMatrixOffset }, { "worldViewMatrix", m_worldViewMatrixOffset }, { "worldViewProjMatrix", m_worldViewProjMatrixOffset }, { "isUseInstancing", m_isUseInstancingOffset }, }; for(const auto& constant : vertexShaderConstantTable.GetConstants()) { if(constant.info.registerSet != registerSetFilter) continue; uint32 size = 0; switch(constant.typeInfo.typeClass) { case CD3DShaderConstantTable::CONSTANT_CLASS_SCALAR: case CD3DShaderConstantTable::CONSTANT_CLASS_VECTOR: size = 0x10 * constant.typeInfo.elements; break; case CD3DShaderConstantTable::CONSTANT_CLASS_MATRIX_COLS: assert(constant.typeInfo.rows == 4 && constant.typeInfo.columns == 4); size = 0x40; break; default: assert(0); break; } auto parameterOffsetIterator = parameterOffsets.find(constant.name); if(parameterOffsetIterator != std::end(parameterOffsets)) { parameterOffsetIterator->second = constantOffset.Allocate(size); } else { constantOffset.Allocate(size); } } }
void CDx11UmbralEffect::ParsePixelShaderConstantTable(OffsetKeeper& constantOffset, const CD3DShaderConstantTable& pixelShaderConstantTable, CD3DShaderConstantTable::REGISTER_SET registerSetFilter) { std::map<std::string, uint32&> parameterOffsets = { { "pixelClippingDistance", m_pixelClippingDistanceOffset }, { "modulateColor", m_modulateColorOffset }, { "diffuseColor", m_diffuseColorOffset }, { "specularColor", m_specularColorOffset }, { "shininess", m_shininessOffset }, { "reflectivity", m_reflectivityOffset }, { "normalPower", m_normalPowerOffset }, { "multiDiffuseColor", m_multiDiffuseColorOffset }, { "multiSpecularColor", m_multiSpecularColorOffset }, { "multiShininess", m_multiShininessOffset }, { "multiReflectivity", m_multiReflectivityOffset }, { "multiNormalPower", m_multiNormalPowerOffset }, { "fresnelExp", m_fresnelExpOffset }, { "fresnelLightDiffBias", m_fresnelLightDiffBiasOffset }, { "lightDiffusePower", m_lightDiffusePowerOffset }, { "specularInfluence", m_specularInfluenceOffset }, { "lightDiffuseInfluence", m_lightDiffuseInfluenceOffset }, { "lightDiffuseMapLod", m_lightDiffuseMapLodOffset }, { "reflectMapInfluence", m_reflectMapInfluenceOffset }, { "reflectMapLod", m_reflectMapLodOffset }, { "glareLdrScale", m_glareLdrScaleOffset }, { "normalVector", m_normalVectorOffset }, { "depthBias", m_depthBiasOffset }, { "refAlphaRestrain", m_refAlphaRestrainOffset }, { "velvetParam", m_velvetParamOffset }, { "ambentOcclusionColor", m_ambientOcclusionColorOffset }, { "specularOcclusionColor", m_specularOcclusionColorOffset }, { "pointLightOcclusionColor", m_pointLightOcclusionColorOffset }, { "mainLightOcclusionColor", m_mainLightOcclusionColorOffset }, { "subLightOcclusionColor", m_subLightOcclusionColorOffset }, { "lightMapOcclusionColor", m_lightMapOcclusionColorOffset }, { "reflectMapOcclusionColor", m_reflectMapOcclusionColorOffset }, { "ambientColor", m_ambientColorOffset }, { "ambientLightColor", m_ambientLightColorOffset }, { "latitudeParam", m_latitudeParamOffset }, { "EnableShadowFlag", m_enableShadowFlagOffset }, { "DirLightDirections", m_dirLightDirectionsOffset }, { "DirLightColors", m_dirLightColorsOffset }, }; for(const auto& constant : pixelShaderConstantTable.GetConstants()) { if(constant.info.registerSet != registerSetFilter) continue; uint32 size = 0; switch(constant.typeInfo.typeClass) { case CD3DShaderConstantTable::CONSTANT_CLASS_SCALAR: case CD3DShaderConstantTable::CONSTANT_CLASS_VECTOR: size = 0x10 * constant.typeInfo.elements; break; case CD3DShaderConstantTable::CONSTANT_CLASS_MATRIX_COLS: assert(constant.typeInfo.rows == 4 && constant.typeInfo.columns == 4); size = 0x40; break; default: assert(0); break; } auto parameterOffsetIterator = parameterOffsets.find(constant.name); if(parameterOffsetIterator != std::end(parameterOffsets)) { parameterOffsetIterator->second = constantOffset.Allocate(size); } else { constantOffset.Allocate(size); } } }