Exemplo n.º 1
0
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);
}
Exemplo n.º 2
0
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);
}