void HdStreamTaskController::_CreateLightingTasks() { // Simple lighting task uses lighting state from Sprims. _simpleLightTaskId = GetControllerId().AppendChild( _tokens->simpleLightTask); HdxSimpleLightTaskParams simpleLightParams; simpleLightParams.cameraPath = _cameraId; GetRenderIndex()->InsertTask<HdxSimpleLightTask>(&_delegate, _simpleLightTaskId); _delegate.SetParameter(_simpleLightTaskId, HdTokens->params, simpleLightParams); _delegate.SetParameter(_simpleLightTaskId, HdTokens->children, SdfPathVector()); _simpleLightBypassTaskId = GetControllerId().AppendChild( _tokens->simpleLightBypassTask); // Simple lighting bypass task uses lighting state from a lighting // context. HdxSimpleLightBypassTaskParams simpleLightBypassParams; simpleLightBypassParams.cameraPath = _cameraId; GetRenderIndex()->InsertTask<HdxSimpleLightBypassTask>(&_delegate, _simpleLightBypassTaskId); _delegate.SetParameter(_simpleLightBypassTaskId, HdTokens->params, simpleLightBypassParams); _delegate.SetParameter(_simpleLightBypassTaskId, HdTokens->children, SdfPathVector()); }
/* virtual */ HdStreamTaskController::~HdStreamTaskController() { GetRenderIndex()->RemoveSprim(HdPrimTypeTokens->camera, _cameraId); SdfPath const tasks[] = { _renderTaskId, _idRenderTaskId, _selectionTaskId, _simpleLightTaskId, _simpleLightBypassTaskId, }; for (size_t i = 0; i < sizeof(tasks)/sizeof(tasks[0]); ++i) { GetRenderIndex()->RemoveTask(tasks[i]); } TF_FOR_ALL (id, _lightIds) { GetRenderIndex()->RemoveSprim(HdPrimTypeTokens->light, *id); }
void HdStreamTaskController::_CreateRenderTasks() { // Create two render tasks, one to create a color render, the other // to create an id render (so we don't need to thrash params). _renderTaskId = GetControllerId().AppendChild(_tokens->renderTask); _idRenderTaskId = GetControllerId().AppendChild(_tokens->idRenderTask); HdxRenderTaskParams renderParams; renderParams.camera = _cameraId; renderParams.viewport = GfVec4d(0,0,1,1); HdRprimCollection collection(HdTokens->geometry, HdTokens->smoothHull); collection.SetRootPath(SdfPath::AbsoluteRootPath()); SdfPath const renderTasks[] = { _renderTaskId, _idRenderTaskId, }; for (size_t i = 0; i < sizeof(renderTasks)/sizeof(renderTasks[0]); ++i) { GetRenderIndex()->InsertTask<HdxRenderTask>(&_delegate, renderTasks[i]); _delegate.SetParameter(renderTasks[i], HdTokens->params, renderParams); _delegate.SetParameter(renderTasks[i], HdTokens->children, SdfPathVector()); _delegate.SetParameter(renderTasks[i], HdTokens->collection, collection); } }
void HdSt_UnitTestDelegate::AddTexture(SdfPath const& id, GlfTextureRefPtr const& texture) { HdRenderIndex& index = GetRenderIndex(); index.InsertBprim(HdPrimTypeTokens->texture, this, id); _textures[id] = _Texture(texture); }
HdTaskSharedPtrVector UsdMayaGLBatchRenderer::TaskDelegate::GetSetupTasks() { HdTaskSharedPtrVector tasks; // lighting tasks.push_back(GetRenderIndex().GetTask(_simpleLightTaskId)); return tasks; }
void UsdMayaGLBatchRenderer::TaskDelegate::SetCameraState( const GfMatrix4d& viewMatrix, const GfMatrix4d& projectionMatrix, const GfVec4d& viewport) { // cache the camera matrices _ValueCache &cache = _valueCacheMap[_cameraId]; cache[HdStCameraTokens->worldToViewMatrix] = VtValue(viewMatrix); cache[HdStCameraTokens->projectionMatrix] = VtValue(projectionMatrix); cache[HdStCameraTokens->windowPolicy] = VtValue(); // no window policy. // invalidate the camera to be synced GetRenderIndex().GetChangeTracker().MarkSprimDirty(_cameraId, HdStCamera::AllDirty); if( _viewport != viewport ) { // viewport is also read by HdxRenderTaskParam. invalidate it. _viewport = viewport; // update all render tasks for( const auto &it : _renderTaskIdMap ) { SdfPath const &taskId = it.second; HdxRenderTaskParams taskParams = _GetValue<HdxRenderTaskParams>(taskId, HdTokens->params); // update viewport in HdxRenderTaskParams taskParams.viewport = viewport; _SetValue(taskId, HdTokens->params, taskParams); // invalidate GetRenderIndex().GetChangeTracker().MarkTaskDirty( taskId, HdChangeTracker::DirtyParams); } } }
UsdImaging_DefaultTaskDelegate::~UsdImaging_DefaultTaskDelegate() { // remove the render graph entities from the renderIndex HdRenderIndex &renderIndex = GetRenderIndex(); renderIndex.RemoveCamera(_cameraId); renderIndex.RemoveTask(_selectionTaskId); renderIndex.RemoveTask(_simpleLightTaskId); renderIndex.RemoveTask(_simpleLightBypassTaskId); renderIndex.RemoveTask(_renderTaskId); renderIndex.RemoveTask(_idRenderTaskId); TF_FOR_ALL (id, _lightIds) { renderIndex.RemoveLight(*id); }
void UsdMayaGLBatchRenderer::TaskDelegate::_InsertRenderTask(SdfPath const &id) { GetRenderIndex().InsertTask<HdxRenderTask>(this, id); _ValueCache &cache = _valueCacheMap[id]; HdxRenderTaskParams taskParams; taskParams.camera = _cameraId; // Initialize viewport to the latest value since render tasks can be lazily // instantiated, potentially even after SetCameraState. All other // parameters will be updated by _UpdateRenderParams. taskParams.viewport = _viewport; cache[HdTokens->params] = VtValue(taskParams); cache[HdTokens->children] = VtValue(SdfPathVector()); cache[HdTokens->collection] = VtValue(); }
void HdStreamTaskController::_CreateCamera() { // Create a default camera, driven by SetCameraMatrices. _cameraId = GetControllerId().AppendChild(_tokens->camera); GetRenderIndex()->InsertSprim(HdPrimTypeTokens->camera, &_delegate, _cameraId); _delegate.SetParameter(_cameraId, HdStCameraTokens->windowPolicy, VtValue()); _delegate.SetParameter(_cameraId, HdStCameraTokens->matrices, HdStCameraMatrices()); _delegate.SetParameter(_cameraId, HdStCameraTokens->clipPlanes, VtValue(std::vector<GfVec4d>())); }
void HdStreamTaskController::_CreateSelectionTask() { // Create a selection highlighting task. _selectionTaskId = GetControllerId().AppendChild(_tokens->selectionTask); HdxSelectionTaskParams selectionParams; selectionParams.enableSelection = true; selectionParams.selectionColor = GfVec4f(1,1,0,1); selectionParams.locateColor = GfVec4f(0,0,1,1); GetRenderIndex()->InsertTask<HdxSelectionTask>(&_delegate, _selectionTaskId); _delegate.SetParameter(_selectionTaskId, HdTokens->params, selectionParams); _delegate.SetParameter(_selectionTaskId, HdTokens->children, SdfPathVector()); }
UsdImaging_DefaultTaskDelegate::UsdImaging_DefaultTaskDelegate( HdRenderIndexSharedPtr const& parentIndex, SdfPath const& delegateID) : UsdImagingTaskDelegate(parentIndex, delegateID) , _viewport(0,0,1,1) , _selectionColor(1,1,0,1) { // create an unique namespace _rootId = delegateID.AppendChild( TfToken(TfStringPrintf("_UsdImaging_%p", this))); _renderTaskId = _rootId.AppendChild(_tokens->renderTask); _idRenderTaskId = _rootId.AppendChild(_tokens->idRenderTask); _selectionTaskId = _rootId.AppendChild(_tokens->selectionTask); _simpleLightTaskId = _rootId.AppendChild(_tokens->simpleLightTask); _simpleLightBypassTaskId = _rootId.AppendChild(_tokens->simpleLightBypassTask); _cameraId = _rootId.AppendChild(_tokens->camera); _activeSimpleLightTaskId = SdfPath(); // TODO: tasks of shadow map generation, accumulation etc will be // prepared here. HdRenderIndex &renderIndex = GetRenderIndex(); // camera { renderIndex.InsertCamera<HdCamera>(this, _cameraId); _ValueCache &cache = _valueCacheMap[_cameraId]; cache[HdShaderTokens->worldToViewMatrix] = VtValue(GfMatrix4d(1)); cache[HdShaderTokens->projectionMatrix] = VtValue(GfMatrix4d(1)); cache[HdTokens->cameraFrustum] = VtValue(); // we don't use GfFrustum. cache[HdTokens->windowPolicy] = VtValue(); // we don't use window policy. } // selection task { renderIndex.InsertTask<HdxSelectionTask>(this, _selectionTaskId); _ValueCache &cache = _valueCacheMap[_selectionTaskId]; HdxSelectionTaskParams params; params.enableSelection = true; params.selectionColor = _selectionColor; params.locateColor = GfVec4f(0,0,1,1); cache[HdTokens->params] = VtValue(params); cache[HdTokens->children] = VtValue(SdfPathVector()); } // simple lighting task (for Hydra native) { renderIndex.InsertTask<HdxSimpleLightTask>(this, _simpleLightTaskId); _ValueCache &cache = _valueCacheMap[_simpleLightTaskId]; HdxSimpleLightTaskParams params; params.cameraPath = _cameraId; cache[HdTokens->params] = VtValue(params); cache[HdTokens->children] = VtValue(SdfPathVector()); } // simple lighting task (for Presto UsdBaseIc compatible) { renderIndex.InsertTask<HdxSimpleLightBypassTask>(this, _simpleLightBypassTaskId); _ValueCache &cache = _valueCacheMap[_simpleLightBypassTaskId]; HdxSimpleLightBypassTaskParams params; params.cameraPath = _cameraId; cache[HdTokens->params] = VtValue(params); cache[HdTokens->children] = VtValue(SdfPathVector()); } // render task _InsertRenderTask(_renderTaskId); _InsertRenderTask(_idRenderTaskId); // initialize HdxRenderTaskParams for render tasks _UpdateCollection(&_rprims, HdTokens->geometry, HdTokens->smoothHull, SdfPathVector(1, SdfPath::AbsoluteRootPath()), _renderTaskId, _idRenderTaskId); _UpdateRenderParams(_renderParams, _renderParams, _renderTaskId); _UpdateRenderParams(_idRenderParams, _idRenderParams, _idRenderTaskId); }
HdTaskSharedPtr UsdMayaGLBatchRenderer::TaskDelegate::GetRenderTask( size_t hash, RenderParams const &renderParams, SdfPathVector const &roots) { // select bucket SdfPath renderTaskId; if( !TfMapLookup(_renderTaskIdMap, hash, &renderTaskId) ) { // create new render task if not exists renderTaskId = _rootId.AppendChild( TfToken(TfStringPrintf("renderTask%zx", hash))); _InsertRenderTask(renderTaskId); _renderTaskIdMap[hash] = renderTaskId; } // // XXX: The Maya-Hydra plugin needs refactoring such that the plugin is // creating a different collection name for each collection it is trying to // manage. (i.e. Each collection within a frame that has different content // should have a different collection name) // // With Hydra, changing the contents of a collection can be // an expensive operation as it causes draw batches to be rebuilt. // // The Maya-Hydra Plugin is currently reusing the same collection // name for all collections within a frame. // (This stems from a time when collection name had a significant meaning // rather than id'ing a collection). // // The plugin should also track deltas to the contents of a collection // and set Hydra's dirty state when prims get added and removed from // the collection. // // Another possible change that can be made to this code is HdxRenderTask // now takes an array of collections, so it is possible to support different // reprs using the same task. Therefore, this code should be modified to // only add one task that is provided with the active set of collections. // // However, a further improvement to the code could be made using // UsdDelegate's fallback repr feature instead of using multiple // collections as it would avoid modifying the collection as a Maya shape // object display state changes. This would result in a much cheaper state // transition within Hydra itself. // TfToken colName = renderParams.geometryCol; HdRprimCollection rprims(colName, renderParams.drawRepr); rprims.SetRootPaths(roots); rprims.SetRenderTags(renderParams.renderTags); GetRenderIndex().GetChangeTracker().MarkCollectionDirty(colName); // update value cache _SetValue(renderTaskId, HdTokens->collection, rprims); // invalidate GetRenderIndex().GetChangeTracker().MarkTaskDirty( renderTaskId, HdChangeTracker::DirtyCollection); // update render params in the value cache HdxRenderTaskParams taskParams = _GetValue<HdxRenderTaskParams>(renderTaskId, HdTokens->params); // update params taskParams.overrideColor = renderParams.overrideColor; taskParams.wireframeColor = renderParams.wireframeColor; taskParams.enableLighting = renderParams.enableLighting; taskParams.enableIdRender = false; taskParams.alphaThreshold = 0.1; taskParams.tessLevel = 32.0; const float tinyThreshold = 0.9f; taskParams.drawingRange = GfVec2f(tinyThreshold, -1.0f); taskParams.depthBiasUseDefault = true; taskParams.depthFunc = HdCmpFuncLess; taskParams.cullStyle = renderParams.cullStyle; taskParams.geomStyle = HdGeomStylePolygons; taskParams.enableHardwareShading = true; // note that taskParams.rprims and taskParams.viewport are not updated // in this function, and needed to be preserved. // store into cache _SetValue(renderTaskId, HdTokens->params, taskParams); // invalidate GetRenderIndex().GetChangeTracker().MarkTaskDirty( renderTaskId, HdChangeTracker::DirtyParams); return GetRenderIndex().GetTask(renderTaskId); }
void UsdMayaGLBatchRenderer::TaskDelegate::_SetLightingStateFromLightingContext() { const GlfSimpleLightVector& lights = _lightingContext->GetLights(); bool hasNumLightsChanged = false; // Insert light Ids into the render index for those that do not yet exist. while (_lightIds.size() < lights.size()) { SdfPath lightId( TfStringPrintf("%s/light%d", _rootId.GetText(), (int)_lightIds.size())); _lightIds.push_back(lightId); // Since we're hardcoded to use HdStRenderDelegate, we expect to have // light Sprims. TF_VERIFY(GetRenderIndex().IsSprimTypeSupported(HdPrimTypeTokens->light)); GetRenderIndex().InsertSprim(HdPrimTypeTokens->light, this, lightId); hasNumLightsChanged = true; } // Remove unused light Ids from HdRenderIndex while (_lightIds.size() > lights.size()) { GetRenderIndex().RemoveSprim(HdPrimTypeTokens->light, _lightIds.back()); _lightIds.pop_back(); hasNumLightsChanged = true; } // invalidate HdLights for (size_t i = 0; i < lights.size(); ++i) { _ValueCache &cache = _valueCacheMap[_lightIds[i]]; // store GlfSimpleLight directly. cache[HdStLightTokens->params] = VtValue(lights[i]); cache[HdStLightTokens->transform] = VtValue(); cache[HdStLightTokens->shadowParams] = VtValue(HdxShadowParams()); cache[HdStLightTokens->shadowCollection] = VtValue(); // Only mark as dirty the parameters to avoid unnecessary invalidation // specially marking as dirty lightShadowCollection will trigger // a collection dirty on geometry and we don't want that to happen // always GetRenderIndex().GetChangeTracker().MarkSprimDirty( _lightIds[i], HdStLight::AllDirty); } // sadly the material also comes from lighting context right now... HdxSimpleLightTaskParams taskParams = _GetValue<HdxSimpleLightTaskParams>(_simpleLightTaskId, HdTokens->params); taskParams.sceneAmbient = _lightingContext->GetSceneAmbient(); taskParams.material = _lightingContext->GetMaterial(); // invalidate HdxSimpleLightTask too if (hasNumLightsChanged) { _SetValue(_simpleLightTaskId, HdTokens->params, taskParams); GetRenderIndex().GetChangeTracker().MarkTaskDirty( _simpleLightTaskId, HdChangeTracker::DirtyParams); } }