Heightfield::Heightfield(ID3D11DeviceContext *mDevcon, ID3D11Device *mDev, GeometryGenerator *geoGen) : mDevcon(mDevcon), mDev(mDev) { CreateGeometry(geoGen); SetupBuffer(); SetupPipeline(); }
void BlBox::CreateParts() { CreateGeometry(); BlRigidBody::CreateItem(); Box::CreateParts(); }
void UserInterface::ResizeGeometry() { if (!isGeometryCreated) CreateGeometry(); assert(isGeometryCreated); root->ResizeGeometry(); }
bool SMDImporter::Import ( char *in_szFilename ) { FILE *f = fopen ( in_szFilename, "rb" ); if ( !f ) { LPWSTR l_wszModelName; DSA2W(&l_wszModelName,in_szFilename); XSI::CString cstr = L"SMDImport: Cannot open the file "; cstr += l_wszModelName; XSILogMessage ( (unsigned short*)cstr.GetWideString(), XSI::siErrorMsg ); return false; } memset ( m_szActionName, 0, 1024 ); _splitpath ( in_szFilename, NULL, NULL, m_szActionName, NULL ); char drive[1024]; char dirc[1024]; memset ( m_szDirectory, 0, 1024 ); if ( strlen(___gTexturePathOverride)) { sprintf ( ___gTexturePathOverride, "%s\\", ___gTexturePathOverride ); _splitpath ( ___gTexturePathOverride, drive, dirc, NULL, NULL ); sprintf ( m_szDirectory, "%s\\%s\\", drive, dirc ); } else { _splitpath ( in_szFilename, drive, dirc, NULL, NULL ); sprintf ( m_szDirectory, "%s\\%s\\", drive, dirc ); } bool Success = Parse ( f ); fclose (f); if ( !Success ) { return Success; } DetectModel(); CreateHierarchy(); CreateGeometry(); WeightGeometry(); CreateShapeClips(); CreateAnimationSource(); return true; }
Geometry* FeatureShp::GetGeometry() { if(m_pGeometry==NULL) { m_pGeometry = CreateGeometry(m_fid, m_pFeatureClass->m_pshpHandle); } return m_pGeometry; }
void VsEllipsoid::CreateParts() { CreateGeometry(); VsRigidBody::CreateItem(); Ellipsoid::CreateParts(); VsRigidBody::SetBody(); }
void VsCone::CreateParts() { CreateGeometry(); VsRigidBody::CreateItem(); Cone::CreateParts(); VsRigidBody::SetBody(); }
Thruster::Thruster(const Thruster &thruster, NodeCopyCache *cache) : Node(thruster, cache) , m_tMat(thruster.m_tMat) , linearOnly(thruster.linearOnly) , dir(thruster.dir) , pos(thruster.pos) { m_tVerts.Reset(CreateGeometry()); }
void VsFluidPlane::CreateParts() { CreateGeometry(); //Create the geometry and osg drawable nodes. m_eControlType = VxEntity::kControlNode; //This is not a dynamic part. VsRigidBody::CreateItem(); FluidPlane::CreateParts(); VsRigidBody::SetBody(); }
void OM_DomeScreen::Display() { if(needsrecompile) { CreateGeometry(); renderer->ResetGeometry(vertexBuffer, ScreenGeometryBase::VBT_SIMPLE_VERTEX_FLT, ScreenGeometryBase::VBT_TRIANGLES, &vertexCount, 1); needsrecompile = false; } renderer->Display(NULL); }
GroundPlane::GroundPlane(ID3D11DeviceContext *mDevcon, ID3D11Device *mDev, GeometryGenerator *geoGen, int planeSize, int increment) : mDevcon(mDevcon), mDev(mDev), size(planeSize), inc(increment) { cb = new PostPBuff(); cb->viewInvProj; cb->viewPrevProj; CreateGeometry(geoGen); SetupBuffer(); SetupPipeline(); SetupRenderTarget(); }
void rPrimitive::RecreateGeometry(){ if (m_geometry) m_engine->content->RemoveGeometryAsset(m_geometry->Name()); rTexCoordGeometryData geometryData; CreateGeometry(geometryData); rString assetName = Id() + "_geometry"; m_geometry = m_engine->content->LoadGeometry(geometryData, assetName); m_geometryInvalid = false; }
/*! \brief Get feature (private) \return pointer to OGRFeature \return NULL not found */ OGRFeature *OGRVFKLayer::GetFeature(VFKFeature *poVFKFeature) { OGRGeometry *poGeom; /* skip feature with unknown geometry type */ if (poVFKFeature->GetGeometryType() == wkbUnknown) return NULL; /* get features geometry */ poGeom = CreateGeometry(poVFKFeature); if (poGeom != NULL) poGeom->assignSpatialReference(poSRS); /* does it satisfy the spatial query, if there is one? */ if (m_poFilterGeom != NULL && poGeom && !FilterGeometry(poGeom)) { return NULL; } /* convert the whole feature into an OGRFeature */ OGRFeature *poOGRFeature = new OGRFeature(GetLayerDefn()); poOGRFeature->SetFID(poVFKFeature->GetFID()); // poOGRFeature->SetFID(++m_iNextFeature); for (int iField = 0; iField < poDataBlock->GetPropertyCount(); iField++) { if (poVFKFeature->GetProperty(iField)->IsNull()) continue; OGRFieldType fType = poOGRFeature->GetDefnRef()->GetFieldDefn(iField)->GetType(); if (fType == OFTInteger) poOGRFeature->SetField(iField, poVFKFeature->GetProperty(iField)->GetValueI()); else if (fType == OFTReal) poOGRFeature->SetField(iField, poVFKFeature->GetProperty(iField)->GetValueD()); else poOGRFeature->SetField(iField, poVFKFeature->GetProperty(iField)->GetValueS()); } /* test against the attribute query */ if (m_poAttrQuery != NULL && !m_poAttrQuery->Evaluate(poOGRFeature)) { delete poOGRFeature; return NULL; } if (poGeom) poOGRFeature->SetGeometryDirectly(poGeom->clone()); return poOGRFeature; }
void *OM_DomeScreen::GetVertexBuffer(int **numVertices, ScreenGeometryBase::VertexType &vertType, ScreenGeometryBase::ShapeType &shapeType, int &aNumShapes) { if (needsrecompile) { CreateGeometry(); renderer->ResetGeometry(vertexBuffer, ScreenGeometryBase::VBT_SIMPLE_VERTEX_FLT, ScreenGeometryBase::VBT_TRIANGLES, &vertexCount, 1); needsrecompile = false; } *numVertices = &vertexCount; vertType = vertexType; aNumShapes = 1; shapeType = ScreenGeometryBase::VBT_TRIANGLES; return vertexBuffer; }
Thruster::Thruster(Graphics::Renderer *r, bool _linear, const vector3f &_pos, const vector3f &_dir) : Node(r, NODE_TRANSPARENT) , linearOnly(_linear) , dir(_dir) , pos(_pos) { m_tVerts.Reset(CreateGeometry()); //set up materials Graphics::MaterialDescriptor desc; desc.textures = 1; desc.twoSided = true; m_tMat.Reset(r->CreateMaterial(desc)); m_tMat->texture0 = Graphics::TextureBuilder::Billboard(thrusterTextureFilename).GetOrCreateTexture(r, "model"); m_tMat->diffuse = baseColor; }
int main(int argc, char **argv) { Initialize(argc, argv); InitializeUI(); glutReshapeFunc(ResizeFunction); glutDisplayFunc(RenderFunction); glutIdleFunc(RenderFunction); glewInit(); programID = LoadShaders("shader.vert", "shader.frag"); LoadTriangle(); CreateGeometry(); glutMainLoop(); TwTerminate(); }
bool DemoApp::Init() { if (!DemoBase::Init()) return false; m_pShadowMap = new ShadowMap(md3dDevice, mShadowMapSize, mShadowMapSize); m_pSkybox = new SkyBox( md3dDevice, 1000, 50, 50, "test"); CreateLights(); CreateShaders(); CreateGeometry(); CreateContantBuffers(); CreateSamplerStates(); CreateRenderStates(); SetUpSceneConsts(); return true; }
void BubbleEmitter::SetBubbleDensity( unsigned int density ) { DALI_ASSERT_ALWAYS( density>0 && density<=9 && " Only densities between 1 to 9 are valid " ); if( density == mDensity ) { return; } else { mDensity = density; mMeshGeometry = CreateGeometry( mNumBubblePerActor*mDensity ); for(unsigned int i=0; i < mNumActor; i++ ) { (mBubbleActors[i])->SetGeometry( mMeshGeometry ); } } }
Mesh* MDLMeshImporter::CreateMesh( NWN::GeometryNode* pNode, Mesh* pParent, Bool pMetallic ) { Mesh* mesh = NULL; switch( pNode->GetType() ) { // Trimesh (& danglymesh) have geometry, so create it. case NWN::DANGLY_MESH_ID: case NWN::TRIMESH_ID: mesh = GD_NEW(Mesh, this, "Mesh"); if( ((NWN::TrimeshGeometryNode*)pNode)->mRender && !((NWN::TrimeshGeometryNode*)pNode)->mTransparencyHint ) { CreateGeometry( (NWN::TrimeshGeometryNode*)pNode, mesh ); CreateShader( (NWN::TrimeshGeometryNode*)pNode, mesh, pMetallic ); } break; case NWN::EMITTER_ID: case NWN::DUMMY_ID: case NWN::AABB_ID: mesh = GD_NEW(Mesh, this, "Mesh"); break; default: return NULL; } // Create all childs recursivly. for( std::map<String,NWN::Node*>::iterator itMap = pNode->mChilds.begin(); itMap != pNode->mChilds.end(); ++itMap ) CreateMesh( (NWN::GeometryNode*)(itMap->second), mesh, pMetallic ); // Add the new mesh to it's parent (and store his relative position and orientation). if( pParent ) { mesh->SetName(pNode->mName); //mesh->SetPosition(((NWN::DummyGeometryNode*)pNode)->mPosition); //mesh->SetOrientation(Quaternionf( ((NWN::DummyGeometryNode*)pNode)->mRotationVector, ((NWN::DummyGeometryNode*)pNode)->mRotationAngle)); pParent->AddChild(mesh); } return mesh; }
// main program - initialize, then send to proper function int main (int argc, char **argv) { CubitStatus s = InitCGMA::initialize_cgma( ENGINE ); if (CUBIT_SUCCESS != s) return 1; //Do tests. int rsl = CreateGeometry(); if (rsl == 1) PRINT_INFO("Operation Failed"); int ret_val = ( CubitMessage::instance()->error_count() ); if ( ret_val != 0 ) { PRINT_ERROR("Errors found during Mergechk session.\n"); } else ret_val = 0; return ret_val; }
bool TextureOverlay::Initialize(RenderManagerPtr pRenderManager, const std::string& name, const math::RectI& rect, TexturePtr pTex) { m_pRenderManager = pRenderManager; m_name = name; m_rect = rect; m_pMaterial = m_pRenderManager->CreateMaterialFromFile("./assets/standard/material/texture_overlay.material"); if(m_pMaterial == nullptr) { return false; } m_pParamImage = m_pMaterial->GetParameterByName("overlay_image");; m_pParamTrans = m_pMaterial->GetParameterByName("trans");; m_pParamScreenSize = m_pMaterial->GetParameterByName("screen_size");; if(CreateGeometry() == false) { return false; } m_pRenderData = alloc_object<RenderData>(); m_pRenderData->geometry = m_pGeometry; m_pRenderData->material = m_pMaterial; m_pRenderData->world_matrix.MakeIdentity(); m_pRenderData->base_vertex = 0; m_pRenderData->index_count = 0; m_pRenderData->start_index = 0; m_pRenderData->vertex_count = 6; AttachTexture(pTex); return true; }
void BlMeshBase::Physics_Resize() { //First lets get rid of the current current geometry and then put new geometry in place. if(m_osgNode.valid() && m_osgMeshNode.valid()) { osg::Group *osgGroup = dynamic_cast<osg::Group *>(m_osgNode.get()); if(osgGroup && osgGroup->containsNode(m_osgMeshNode.get())) osgGroup->removeChild(m_osgMeshNode.get()); m_osgGeometry.release(); m_osgMeshNode.release(); m_osgBaseMeshNode.release(); CreateGeometry(); //Now lets re-adjust the gripper size. if(m_osgDragger.valid()) m_osgDragger->SetupMatrix(); //Reset the user data for the new parts. if(m_osgNodeGroup.valid()) { osg::ref_ptr<OsgUserDataVisitor> osgVisitor = new OsgUserDataVisitor(this); osgVisitor->traverse(*m_osgNodeGroup); } if(Physics_IsDefined()) { ResizePhysicsGeometry(); //Now get base values, including mass and volume GetBaseValues(); } if(m_lpThisRB->Callback()) m_lpThisRB->Callback()->SizeChanged(); } }
void BubbleEmitter::OnInitialize() { // Create the root actor, all the meshActor should be its children mBubbleRoot = Actor::New(); mBubbleRoot.SetSize(mMovementArea); // Prepare the frame buffer to store the color adjusted background image mEffectImage = FrameBufferImage::New( mMovementArea.width/4.f, mMovementArea.height/4.f, Pixel::RGBA8888, Dali::Image::UNUSED ); // Generate the geometry, which is used by all bubbleActors mMeshGeometry = CreateGeometry( mNumBubblePerActor*mDensity ); Shader bubbleShader = CreateBubbleShader (mNumBubblePerActor ); mMaterial = Material::New( bubbleShader ); mMaterial.AddTexture( mEffectImage, "sBackground" ); mMaterial.AddTexture( mShapeImage, "sBubbleShape" ); mBubbleActors.resize( mNumActor ); // Create the meshActor group and bubbleEffect group to emit bubbles following the given track, such as finger touch track. for(unsigned int i=0; i < mNumActor; i++ ) { mBubbleActors[i] = new BubbleActor( mNumBubblePerActor, mMovementArea ); (mBubbleActors[i])->MakeRenderable( mMeshGeometry, mMaterial ); mBubbleRoot.Add( (mBubbleActors[i])->GetMeshActor() ); } // Create a cameraActor for the off screen render task. mCameraActor = CameraActor::New(mMovementArea); mCameraActor.SetParentOrigin(ParentOrigin::CENTER); Stage stage = Stage::GetCurrent(); stage.Add(mCameraActor); stage.ContextRegainedSignal().Connect(this, &BubbleEmitter::OnContextRegained); }
/*! \brief Get feature (private) \return pointer to OGRFeature or NULL not found */ OGRFeature *OGRVFKLayer::GetFeature(IVFKFeature *poVFKFeature) { OGRGeometry *poGeom; /* skip feature with unknown geometry type */ if (poVFKFeature->GetGeometryType() == wkbUnknown) return NULL; /* get features geometry */ poGeom = CreateGeometry(poVFKFeature); if (poGeom != NULL) poGeom->assignSpatialReference(poSRS); /* does it satisfy the spatial query, if there is one? */ if (m_poFilterGeom != NULL && poGeom && !FilterGeometry(poGeom)) { return NULL; } /* convert the whole feature into an OGRFeature */ OGRFeature *poOGRFeature = new OGRFeature(GetLayerDefn()); poOGRFeature->SetFID(poVFKFeature->GetFID()); // poOGRFeature->SetFID(++m_iNextFeature); poVFKFeature->LoadProperties(poOGRFeature); /* test against the attribute query */ if (m_poAttrQuery != NULL && !m_poAttrQuery->Evaluate(poOGRFeature)) { delete poOGRFeature; return NULL; } if (poGeom) poOGRFeature->SetGeometryDirectly(poGeom->clone()); return poOGRFeature; }
//******************************************************************************* void CBCGPChartInterLineColoringEffect::OnDraw(CBCGPGraphicsManager* pGM) { ASSERT_VALID(this); if (m_pSeries1 == NULL || m_arPointsSeries1.GetSize() < 2 || !IsVisible()) { return; } BOOL bWasTransparency = CBCGPGraphicsManagerGDI::IsTransparencyEnabled(); CBCGPGraphicsManagerGDI::EnableTransparency(); BCGPChartFormatSeries::ChartCurveType curveType = m_pSeries1->GetCurveType(); if (curveType == BCGPChartFormatSeries::CCT_STEP || curveType == BCGPChartFormatSeries::CCT_REVERSED_STEP || m_pSeries2 != NULL && (m_pSeries2->GetCurveType() == BCGPChartFormatSeries::CCT_STEP || m_pSeries2->GetCurveType() == BCGPChartFormatSeries::CCT_REVERSED_STEP)) { return; } CBCGPChartAxis* pXAxis = m_pSeries1->GetRelatedAxis(CBCGPChartSeries::AI_X); CBCGPRect rectBounds = pXAxis->GetBoundingRect(); CBCGPChartAxis* pYAxis = m_pSeries1->GetRelatedAxis(CBCGPChartSeries::AI_Y); if (pYAxis->m_bReverseOrder) { pYAxis->IsVertical() ? rectBounds.SwapTopBottom() : rectBounds.SwapLeftRight(); } if (pXAxis->m_bReverseOrder) { pXAxis->IsVertical() ? rectBounds.SwapTopBottom() : rectBounds.SwapLeftRight(); } BCGPSeriesColorsPtr colors; m_pSeries1->GetColors(colors, -1); CBCGPBrush& brFill = m_brTopBrush.IsEmpty() ? *colors.m_pBrElementFillColor : m_brTopBrush; CBCGPGeometry* pDrawGeometry = CreateGeometry(m_arPointsSeries1, rectBounds, curveType, FALSE); CBCGPGeometry* pClipGeometry = m_pSeries2 != NULL ? CreateGeometry(m_arPointsSeries2, rectBounds, m_pSeries2->GetCurveType(), TRUE) : CreateClipGeometry(m_dblOrigin); ASSERT_VALID(pDrawGeometry); ASSERT_VALID(pClipGeometry); DrawEffect(pGM, pDrawGeometry, pClipGeometry, rectBounds, brFill); delete pClipGeometry; delete pDrawGeometry; if (m_pSeries2 != NULL && m_arPointsSeries2.GetSize() > 2 && !m_bTopOnly) { BCGPSeriesColorsPtr colors; m_pSeries2->GetColors(colors, -1); pDrawGeometry = CreateGeometry(m_arPointsSeries2, rectBounds, m_pSeries2->GetCurveType(), FALSE); pClipGeometry = CreateGeometry(m_arPointsSeries1, rectBounds, curveType, TRUE); CBCGPBrush& brFill = m_brBottomBrush.IsEmpty() ? *colors.m_pBrElementFillColor : m_brBottomBrush; DrawEffect(pGM, pDrawGeometry, pClipGeometry, rectBounds, brFill); delete pClipGeometry; delete pDrawGeometry; } CBCGPGraphicsManagerGDI::EnableTransparency(bWasTransparency); }
void Character3D::Create( char character, SDFont &font, sf::Shader &shader ) { m_font = &font; m_shader = &shader; m_character = character; CreateGeometry(); }
bool GltfPbr::OnCreate( ID3D12Device* pDevice, UploadHeapDX12* pUploadHeap, ResourceViewHeapsDX12 *pHeaps, DynamicBufferRingDX12 *pDynamicBufferRing, StaticBufferPoolDX12 *pStaticBufferPool, GLTFCommon *pGLTFData, SkyDome *pSkyDome, #ifdef USE_SHADOWMAPS Texture *pShadowMap, #endif void *pluginManager, void *msghandler) { m_pGLTFData = pGLTFData; m_pDynamicBufferRing = pDynamicBufferRing; m_pResourceViewHeaps = pHeaps; m_pStaticBufferPool = pStaticBufferPool; // Load cubemaps maps for IBL m_pCubeDiffuseTexture = pSkyDome->GetDiffuseCubeMap(); m_pCubeSpecularTexture = pSkyDome->GetSpecularCubeMap(); if (m_BrdfTexture.InitFromFile(pDevice, pUploadHeap, L"./plugins/media/envmap/brdf.dds", pluginManager, msghandler) != 0) { return false; } pUploadHeap->FlushAndFinish(); json &j3 = pGLTFData->j3; // Load Textures for gltf file if (!pGLTFData->isBinFile) { auto images = j3["images"]; m_textures.resize(images.size()); for (unsigned int i = 0; i < images.size(); i++) { std::string filename = images[i]["uri"]; WCHAR wcstrPath[MAX_PATH]; MultiByteToWideChar(CP_UTF8, 0, (pGLTFData->m_path + filename).c_str(), -1, wcstrPath, MAX_PATH); INT32 result = m_textures[i].InitFromFile(pDevice, pUploadHeap, wcstrPath, pluginManager, msghandler); } pUploadHeap->FlushAndFinish(); } // Load PBR 2.0 Materials // if (DX12_CMips) { DX12_CMips->Print("Load PBR 2.0 Materials"); } std::vector<PBRMaterial *> materialsData; auto materials = j3["materials"]; auto textures = j3["textures"]; for (unsigned int i = 0; i < materials.size(); i++) { json::object_t material = materials[i]; PBRMaterial *tfmat = new PBRMaterial(); materialsData.push_back(tfmat); // Load material constants // json::array_t ones = { 1.0, 1.0, 1.0, 1.0 }; json::array_t zeroes = { 0.0, 0.0, 0.0, 0.0 }; tfmat->emissiveFactor = (XMVECTOR) GetVector(GetElementJsonArray(material, "emissiveFactor", zeroes)); tfmat->baseColorFactor = (XMVECTOR) GetVector(GetElementJsonArray(material, "pbrMetallicRoughness/baseColorFactor", ones)); try { tfmat->metallicFactor = GetElementFloat(material, "pbrMetallicRoughness/metallicFactor", 1.0); } catch (json::exception& e) { tfmat->metallicFactor = (GetElementJsonArray(material, "pbrMetallicRoughness/metallicFactor", ones))[0]; } try { tfmat->roughnessFactor = GetElementFloat(material, "pbrMetallicRoughness/roughnessFactor", 1.0); } catch (json::exception& e) { tfmat->roughnessFactor = (GetElementJsonArray(material, "pbrMetallicRoughness/roughnessFactor", ones))[0]; } tfmat->m_defines["DEF_alphaMode_" + GetElementString(material, "alphaMode", "OPAQUE")] = 1; float alphaCutOff = 0.0f; try { alphaCutOff = GetElementFloat(material, "alphaCutoff", 1.0); } catch (json::exception& e) { alphaCutOff = (GetElementJsonArray(material, "alphaCutoff", ones))[0]; } tfmat->m_defines["DEF_alphaCutoff"] = std::to_string(alphaCutOff); // load glTF 2.0 material's textures (if present) and create descriptor set // std::map<std::string, TextureDX12 *> texturesBase; if (textures.size() > 0) { AddTextureIfExists(material, textures, texturesBase, "pbrMetallicRoughness/baseColorTexture/index", "baseColorTexture"); AddTextureIfExists(material, textures, texturesBase, "pbrMetallicRoughness/metallicRoughnessTexture/index", "metallicRoughnessTexture"); AddTextureIfExists(material, textures, texturesBase, "emissiveTexture/index", "emissiveTexture"); AddTextureIfExists(material, textures, texturesBase, "normalTexture/index", "normalTexture"); AddTextureIfExists(material, textures, texturesBase, "occlusionTexture/index", "occlusionTexture"); } tfmat->m_textureCount = (int)texturesBase.size(); if (m_pCubeDiffuseTexture) tfmat->m_textureCount += 1; if (m_pCubeSpecularTexture) tfmat->m_textureCount += 1; //+ 1 brdf lookup texture, add that to the total count of textures used tfmat->m_textureCount += 1; #ifdef USE_SHADOWMAPS // plus shadows if (pShadowMap != NULL) tfmat->m_textureCount += 1; #endif if (tfmat->m_textureCount >= 0) { //allocate descriptor table for the textures tfmat->m_pTexturesTable = new CBV_SRV_UAV[tfmat->m_textureCount]; pHeaps->AllocCBV_SRV_UAVDescriptor(tfmat->m_textureCount, tfmat->m_pTexturesTable); int cnt = 0; //create SRVs and #defines so the shader compiler knows what the index of each texture is for (auto it = texturesBase.begin(); it != texturesBase.end(); it++) { tfmat->m_defines[std::string("ID_") + it->first] = std::to_string(cnt); it->second->CreateSRV(cnt++, tfmat->m_pTexturesTable); } //create SRVs and #defines for the IBL resources if (m_pCubeDiffuseTexture) { tfmat->m_defines["ID_diffuseCube"] = std::to_string(cnt); m_pCubeDiffuseTexture->CreateCubeSRV(cnt++, tfmat->m_pTexturesTable); tfmat->m_defines["USE_IBL"] = "1"; } if (m_pCubeSpecularTexture) { tfmat->m_defines["ID_specularCube"] = std::to_string(cnt); m_pCubeSpecularTexture->CreateCubeSRV(cnt++, tfmat->m_pTexturesTable); tfmat->m_defines["USE_IBL"] = "1"; } tfmat->m_defines["ID_brdfTexture"] = std::to_string(cnt); m_BrdfTexture.CreateSRV(cnt++, tfmat->m_pTexturesTable); #ifdef USE_SHADOWMAPS // add SRV for the shadowmap if (pShadowMap!=NULL) { tfmat->m_defines["ID_shadowMap"] = std::to_string(cnt); pShadowMap->CreateSRV(cnt++, tfmat->m_pTexturesTable); } #endif } } // Load Meshes // if (DX12_CMips) { DX12_CMips->Print("Load Meshes"); } auto accessors = j3["accessors"]; auto bufferViews = j3["bufferViews"]; auto meshes = j3["meshes"]; m_meshes.resize(meshes.size()); for (unsigned int i = 0; i < meshes.size(); i++) { PBRMesh *tfmesh = &m_meshes[i]; auto primitives = meshes[i]["primitives"]; tfmesh->m_pPrimitives.resize(primitives.size()); for (unsigned int p = 0; p < primitives.size(); p++) { PBRPrimitives *pPrimitive = &tfmesh->m_pPrimitives[p]; // Set Material // pPrimitive->m_pMaterial = materialsData[primitives[p]["material"]]; // Set Index buffer // tfAccessor indexBuffer; { int indicesID = primitives[p]["indices"].get<int>(); json::object_t indicesAccessor = accessors[indicesID]; GetBufferDetails(indicesAccessor, bufferViews, pGLTFData->buffersData, &indexBuffer); } // Get input layout // std::vector<tfAccessor> vertexBuffers; std::vector<std::string> semanticNames; std::vector<D3D12_INPUT_ELEMENT_DESC> layout; auto attribute = primitives[p]["attributes"]; layout.reserve(attribute.size()); semanticNames.reserve(attribute.size()); vertexBuffers.resize(attribute.size()); for (auto it = attribute.begin(); it != attribute.end(); it++) { // glTF attributes may end in a number, DX12 doest like this and if this is the case we need to split the attribute name from the number // CMP_DWORD semanticIndex = 0; std::string semanticName; SplitGltfAttribute(it.key(), &semanticName, &semanticIndex); semanticNames.push_back(semanticName); auto accessor = accessors[it.value().get<int>()]; // Get VB accessors // GetBufferDetails(accessor, bufferViews, pGLTFData->buffersData, &vertexBuffers[layout.size()]); // Create Input Layout // D3D12_INPUT_ELEMENT_DESC l; l.SemanticName = NULL; // we need to set it in the pipeline function (because of multithreading) l.SemanticIndex = semanticIndex; l.Format = GetFormatDX12(accessor["type"], accessor["componentType"]); l.InputSlot = (UINT)layout.size(); l.InputSlotClass = D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA; l.InstanceDataStepRate = 0; l.AlignedByteOffset = D3D12_APPEND_ALIGNED_ELEMENT; layout.push_back(l); } if (!CreateGeometry(indexBuffer, vertexBuffers, pPrimitive)) return false; GetThreadPool()->Add_Job([=]() { CreatePipeline(pDevice, pUploadHeap->GetNodeMask(), semanticNames, layout, pPrimitive); }); } } return true; }
TDataSet *CreateTable() {return CreateGeometry("y2003");}
void VoxelChunk::CreateMesh( UINT8* m_pBlocks, bool* _acted, unsigned int dimm )//lower corner { if (!_vao) _vao = new VAO(); _dirty = false; Color clr; clr.comp[0] = 255; clr.comp[1] = 255; clr.comp[2] = 255; clr.comp[3] = 255; int h_dimm = dimm>>1; const int _local_to_global_i = h_dimm + _lbl[0]; const int _local_to_global_j = h_dimm + _lbl[1]; const int _local_to_global_k = h_dimm + _lbl[2]; unsigned int num_created = 0; unsigned int global_index = 0; UINT8 tmp_res = 0; unsigned int x, y; for (unsigned int i = 0; i < size; i++) { x = (_local_to_global_i+i)*dimm*dimm; for (unsigned int j = 0; j < size; j++) { y = (_local_to_global_j+j)*dimm; for (unsigned int k = 0; k < size; k++) { tmp_res = EvaluateCell( m_pBlocks, _local_to_global_i+i, _local_to_global_j+j, _local_to_global_k+k, dimm ); if (tmp_res) { if ( _points == NULL ) { CreateGeometry(); } if (!_vbo) _vbo = new VBO(_points, NULL, 0, _vertex_len ); global_index = ( x+ y + _local_to_global_k+k );; //MapColor( &clr, m_pBlocks[global_index], false); MapColor( &clr, m_pBlocks[global_index], _acted[global_index]); _acted[global_index] = false; clr.comp[3] = tmp_res; SetColorForVoxel(i, j, k, &clr); _renderable_indexes[num_created] = i*size*size + j*size + k; ++num_created; } } } } _renderable_indexes_count = num_created; if ( num_created ) { _vbo->UpdateColorArray( _colors, _vertex_len ); _vbo->UpdateIndexArray( _renderable_indexes, _renderable_indexes_count ); _vao->bind( *_vbo ); } else { if ( _points != NULL ) { ClearGeometry(); } ClearMesh(); } }
void ImposterNode::UpdateImposter() { Camera * camera = scene->GetCurrentCamera(); Camera * imposterCamera = new Camera(); Vector3 cameraPos = camera->GetPosition(); Entity * child = GetChild(0); AABBox3 bbox = child->GetWTMaximumBoundingBoxSlow(); Vector3 bboxCenter = bbox.GetCenter(); imposterCamera->Setup(camera->GetFOV(), camera->GetAspect(), camera->GetZNear(), camera->GetZFar()); imposterCamera->SetTarget(bbox.GetCenter()); imposterCamera->SetPosition(cameraPos); imposterCamera->SetUp(camera->GetUp()); imposterCamera->SetLeft(camera->GetLeft()); Rect viewport = RenderManager::Instance()->GetViewport(); const Matrix4 & mvp = imposterCamera->GetUniformProjModelMatrix(); AABBox3 screenBounds; GetOOBBoxScreenCoords(child, mvp, screenBounds); Vector4 pv(bboxCenter); pv = pv*mvp; pv.z = (pv.z/pv.w + 1.f) * 0.5f; float32 bboxCenterZ = pv.z; Vector2 screenSize = Vector2(screenBounds.max.x-screenBounds.min.x, screenBounds.max.y-screenBounds.min.y); Vector3 screenBillboardVertices[4]; screenBillboardVertices[0] = Vector3(screenBounds.min.x, screenBounds.min.y, screenBounds.min.z); screenBillboardVertices[1] = Vector3(screenBounds.max.x, screenBounds.min.y, screenBounds.min.z); screenBillboardVertices[2] = Vector3(screenBounds.min.x, screenBounds.max.y, screenBounds.min.z); screenBillboardVertices[3] = Vector3(screenBounds.max.x, screenBounds.max.y, screenBounds.min.z); center = Vector3(); Matrix4 invMvp = mvp; invMvp.Inverse(); for(int32 i = 0; i < 4; ++i) { //unproject Vector4 out; out.x = 2.f*(screenBillboardVertices[i].x-viewport.x)/viewport.dx-1.f; out.y = 2.f*(screenBillboardVertices[i].y-viewport.y)/viewport.dy-1.f; out.z = 2.f*screenBillboardVertices[i].z-1.f; out.w = 1.f; out = out*invMvp; DVASSERT(out.w != 0.f); out.x /= out.w; out.y /= out.w; out.z /= out.w; imposterVertices[i] = Vector3(out.x, out.y, out.z); center += imposterVertices[i]; } center /= 4.f; //draw RecreateFbo(screenSize); //Logger::Info("%f, %f", screenSize.x, screenSize.y); if(!block) { return; } direction = camera->GetPosition()-center; direction.Normalize(); distanceSquaredToCamera = (center-cameraPos).SquareLength(); float32 nearPlane = sqrtf(distanceSquaredToCamera); //float32 farPlane = nearPlane + (bbox.max.z-bbox.min.z); float32 w = (imposterVertices[1]-imposterVertices[0]).Length(); float32 h = (imposterVertices[2]-imposterVertices[0]).Length(); //TODO: calculate instead of +50 imposterCamera->Setup(-w/2.f, w/2.f, -h/2.f, h/2.f, nearPlane, nearPlane+50.f); Rect oldViewport = RenderManager::Instance()->GetViewport(); //Texture * target = fbo->GetTexture(); RenderManager::Instance()->AppendState(RenderState::STATE_SCISSOR_TEST); RenderManager::Instance()->State()->SetScissorRect(Rect(block->offset.x, block->offset.y, block->size.dx, block->size.dy)); RenderManager::Instance()->FlushState(); //TODO: use one "clear" function instead of two //if(block->size.x == 512.f) //{ // RenderManager::Instance()->ClearWithColor(0.f, .8f, 0.f, 1.f); //} //else if(block->size.x == 256.f) //{ // RenderManager::Instance()->ClearWithColor(0.f, .3f, 0.f, 1.f); //} //else if(block->size.x == 128.f) //{ // RenderManager::Instance()->ClearWithColor(.3f, .3f, 0.f, 1.f); //} //else //{ // RenderManager::Instance()->ClearWithColor(.3f, 0.f, 0.f, 1.f); //} RenderManager::Instance()->ClearWithColor(.0f, .0f, 0.f, .0f); RenderManager::Instance()->ClearDepthBuffer(); RenderManager::Instance()->RemoveState(RenderState::STATE_SCISSOR_TEST); RenderManager::Instance()->SetViewport(Rect(block->offset.x, block->offset.y, block->size.dx, block->size.dy), true); imposterCamera->SetTarget(center); imposterCamera->Set(); //TODO: remove this call HierarchicalRemoveCull(child); RenderManager::Instance()->FlushState(); child->Draw(); RenderManager::Instance()->SetViewport(oldViewport, true); isReady = true; state = STATE_IMPOSTER; //unproject screenBillboardVertices[0] = Vector3(screenBounds.min.x, screenBounds.min.y, bboxCenterZ); screenBillboardVertices[1] = Vector3(screenBounds.max.x, screenBounds.min.y, bboxCenterZ); screenBillboardVertices[2] = Vector3(screenBounds.min.x, screenBounds.max.y, bboxCenterZ); screenBillboardVertices[3] = Vector3(screenBounds.max.x, screenBounds.max.y, bboxCenterZ); for(int32 i = 0; i < 4; ++i) { //unproject Vector4 out; out.x = 2.f*(screenBillboardVertices[i].x-viewport.x)/viewport.dx-1.f; out.y = 2.f*(screenBillboardVertices[i].y-viewport.y)/viewport.dy-1.f; out.z = 2.f*screenBillboardVertices[i].z-1.f; out.w = 1.f; out = out*invMvp; DVASSERT(out.w != 0.f); out.x /= out.w; out.y /= out.w; out.z /= out.w; imposterVertices[i] = Vector3(out.x, out.y, out.z); } SafeRelease(imposterCamera); ClearGeometry(); CreateGeometry(); }