Ejemplo n.º 1
0
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());
}
Ejemplo n.º 2
0
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);
    }
}
Ejemplo n.º 3
0
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();
}
Ejemplo n.º 4
0
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());
}
Ejemplo n.º 5
0
UsdMayaGLBatchRenderer::TaskDelegate::TaskDelegate(
    HdRenderIndex *renderIndex, SdfPath const& delegateID)
    : HdSceneDelegate(renderIndex, delegateID)
{
    _lightingContext = GlfSimpleLightingContext::New();

    // populate tasks in renderindex

    // create an unique namespace
    _rootId = delegateID.AppendChild(
        TfToken(TfStringPrintf("_UsdImaging_%p", this)));

    _simpleLightTaskId          = _rootId.AppendChild(_tokens->simpleLightTask);
    _cameraId                   = _rootId.AppendChild(_tokens->camera);

    // camera
    {
        // Since we're hardcoded to use HdStRenderDelegate, we expect to
        // have camera Sprims.
        TF_VERIFY(renderIndex->IsSprimTypeSupported(HdPrimTypeTokens->camera));

        renderIndex->InsertSprim(HdPrimTypeTokens->camera, this, _cameraId);
        _ValueCache &cache = _valueCacheMap[_cameraId];
        cache[HdStCameraTokens->worldToViewMatrix] = VtValue(GfMatrix4d(1.0));
        cache[HdStCameraTokens->projectionMatrix] = VtValue(GfMatrix4d(1.0));
        cache[HdStCameraTokens->windowPolicy] = VtValue();  // no window policy.
    }

    // simple lighting task (for Hydra native)
    {
        renderIndex->InsertTask<HdxSimpleLightTask>(this, _simpleLightTaskId);
        _ValueCache &cache = _valueCacheMap[_simpleLightTaskId];
        HdxSimpleLightTaskParams taskParams;
        taskParams.cameraPath = _cameraId;
        cache[HdTokens->params] = VtValue(taskParams);
        cache[HdTokens->children] = VtValue(SdfPathVector());
    }
}
Ejemplo n.º 6
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);
}
Ejemplo n.º 7
0
void
UsdMayaGLBatchRenderer::_RenderBatches( 
    const MHWRender::MDrawContext* vp2Context,
    const MMatrix& viewMat,
    const MMatrix& projectionMat,
    const GfVec4d& viewport )
{
    if( _renderQueue.empty() )
        return;
    
    if( !_populateQueue.empty() )
    {
        TF_DEBUG(PXRUSDMAYAGL_QUEUE_INFO).Msg(
            "____________ POPULATE STAGE START ______________ (%zu)\n",_populateQueue.size());

        std::vector<UsdImagingDelegate*> delegates;
        UsdPrimVector rootPrims;
        std::vector<SdfPathVector> excludedPrimPaths;
        std::vector<SdfPathVector> invisedPrimPaths;
        
        for( ShapeRenderer *shapeRenderer : _populateQueue )
        {
            delegates.push_back(shapeRenderer->_delegate.get());
            rootPrims.push_back(shapeRenderer->_rootPrim);
            excludedPrimPaths.push_back(shapeRenderer->_excludedPaths);
            invisedPrimPaths.push_back(SdfPathVector());
            
            shapeRenderer->_isPopulated = true;
        }
        
        UsdImagingDelegate::Populate( delegates,
                                      rootPrims,
                                      excludedPrimPaths,
                                      invisedPrimPaths );
        
        _populateQueue.clear();

        TF_DEBUG(PXRUSDMAYAGL_QUEUE_INFO).Msg(
            "^^^^^^^^^^^^ POPULATE STAGE FINISH ^^^^^^^^^^^^^ (%zu)\n",_populateQueue.size());
    }
    
    TF_DEBUG(PXRUSDMAYAGL_QUEUE_INFO).Msg(
        "____________ RENDER STAGE START ______________ (%zu)\n",_renderQueue.size());

    // A new display refresh signifies that the cached selection data is no
    // longer valid.
    _selectQueue.clear();
    _selectResults.clear();

    // We've already populated with all the selection info we need.  We Reset
    // and the first call to GetSoftSelectHelper in the next render pass will
    // re-populate it.
    _softSelectHelper.Reset();
    
    GfMatrix4d modelViewMatrix(viewMat.matrix);
    GfMatrix4d projectionMatrix(projectionMat.matrix);

    _taskDelegate->SetCameraState(modelViewMatrix, projectionMatrix, viewport);

    // save the current GL states which hydra may reset to default
    glPushAttrib(GL_LIGHTING_BIT |
                 GL_ENABLE_BIT |
                 GL_POLYGON_BIT |
                 GL_DEPTH_BUFFER_BIT |
                 GL_VIEWPORT_BIT);
    
    // hydra orients all geometry during topological processing so that
    // front faces have ccw winding. We disable culling because culling
    // is handled by fragment shader discard.
    glFrontFace(GL_CCW); // < State is pushed via GL_POLYGON_BIT
    glDisable(GL_CULL_FACE);

    // note: to get benefit of alpha-to-coverage, the target framebuffer
    // has to be a MSAA buffer.
    glDisable(GL_BLEND);
    glEnable(GL_SAMPLE_ALPHA_TO_COVERAGE);

    if (vp2Context) {
        _taskDelegate->SetLightingStateFromMayaDrawContext(*vp2Context);
    } else {
        _taskDelegate->SetLightingStateFromVP1(viewMat);
    }
    
    // The legacy viewport does not support color management,
    // so we roll our own gamma correction by GL means (only in
    // non-highlight mode)
    bool gammaCorrect = !vp2Context;

    if( gammaCorrect )
        glEnable(GL_FRAMEBUFFER_SRGB_EXT);

    glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);

    // render task setup
    HdTaskSharedPtrVector tasks = _taskDelegate->GetSetupTasks(); // lighting etc

    for( const auto &renderSetIter : _renderQueue )
    {
        size_t hash = renderSetIter.first;
        const RenderParams &params = renderSetIter.second.first;
        const _SdfPathSet &renderPaths = renderSetIter.second.second;

        TF_DEBUG(PXRUSDMAYAGL_QUEUE_INFO).Msg(
                "*** renderQueue, batch %zx, size %zu\n",
                renderSetIter.first, renderPaths.size() );

        SdfPathVector roots(renderPaths.begin(), renderPaths.end());
        tasks.push_back(_taskDelegate->GetRenderTask(hash, params, roots));
    }

    _hdEngine.Execute(*_renderIndex, tasks);
    
    if( gammaCorrect )
        glDisable(GL_FRAMEBUFFER_SRGB_EXT);

    glPopAttrib(); // GL_LIGHTING_BIT | GL_ENABLE_BIT | GL_POLYGON_BIT
    
    // Selection is based on what we have last rendered to the display. The
    // selection queue is cleared above, so this has the effect of resetting
    // the render queue and prepping the selection queue without any
    // significant memory hit.
    _renderQueue.swap( _selectQueue );
    
    TF_DEBUG(PXRUSDMAYAGL_QUEUE_INFO).Msg(
        "^^^^^^^^^^^^ RENDER STAGE FINISH ^^^^^^^^^^^^^ (%zu)\n",_renderQueue.size());
}
Ejemplo n.º 8
0
/*virtual*/
SdfPathVector
HdSceneDelegate::GetSurfaceShaderTextures(SdfPath const &shaderId)
{
    return SdfPathVector();
}