Ejemplo n.º 1
0
StarsGeode::StarsGeode(const char* brightStarsFilePath)
:   osg::Geode()

,   m_program(new osg::Program)
,   m_vShader(new osg::Shader(osg::Shader::VERTEX))
,   m_gShader(new osg::Shader(osg::Shader::GEOMETRY))
,   m_fShader(new osg::Shader(osg::Shader::FRAGMENT))

,   u_R(NULL)
,   u_q(NULL)
,   u_noise1(NULL)

,   u_color(NULL)
,   u_glareIntensity(NULL)
,   u_glareScale(NULL)
,   u_apparentMagnitude(NULL)
,   u_scattering(NULL)
,   u_scintillations(NULL)
,   u_scale(NULL)
{
    setName("Stars");

    osg::StateSet* stateSet = getOrCreateStateSet();

    setupNode(stateSet, brightStarsFilePath);
    setupUniforms(stateSet);
    setupShader(stateSet);
    setupTextures(stateSet);
};
Ejemplo n.º 2
0
void Material::loadShader(const string& vsFilename, const string& fsFilename)
{
  GLuint vertexShaderProgram = 0;
  vertexShaderProgram = loadShaderFromFile(vsFilename, VERTEX_SHADER);
  checkForCompilerErrors(vertexShaderProgram);
  
  GLuint fragmentShaderProgram = 0;
  fragmentShaderProgram = loadShaderFromFile(fsFilename, FRAGMENT_SHADER);
  checkForCompilerErrors(fragmentShaderProgram);
  
  m_ShaderProgram = glCreateProgram();
  glAttachShader(m_ShaderProgram, vertexShaderProgram);
  glAttachShader(m_ShaderProgram, fragmentShaderProgram);
  
  //Link attributes
  glBindAttribLocation(m_ShaderProgram, 0, "vertexPosition");
  glBindAttribLocation(m_ShaderProgram, 1, "vertexColour");
  glBindAttribLocation(m_ShaderProgram, 2, "vertexTexCoords");
  glBindAttribLocation(m_ShaderProgram, 3, "vertexNormal");
  glBindAttribLocation(m_ShaderProgram, 7, "instancePosition");
  
  glLinkProgram(m_ShaderProgram);
  checkForLinkErrors(m_ShaderProgram);
  //now we can delete the VS & FS Programs
  glDeleteShader(vertexShaderProgram);
  glDeleteShader(fragmentShaderProgram);
  setupUniforms();
}
Ejemplo n.º 3
0
//==============================================================================
void RenderableDrawer::render(SceneNode& frsn, VisibleNode& visibleNode)
{
	RenderingBuildData build;

	// Get components
	FrustumComponent& fr = frsn.getComponent<FrustumComponent>();
	RenderComponent& renderable = 
		visibleNode.m_node->getComponent<RenderComponent>();
	const Material& mtl = renderable.getMaterial();

	// Calculate the key
	RenderingKey key;

	Vec4 camPos = fr.getFrustumOrigin();

	F32 dist = (visibleNode.m_node->getComponent<SpatialComponent>().
		getSpatialOrigin() - camPos).getLength();
	F32 flod = m_r->calculateLod(dist);
	build.m_key.m_lod = flod;
	build.m_key.m_pass = m_pass;
	build.m_key.m_tessellation = 
		m_r->usesTessellation() 
		&& mtl.getTessellation()
		&& build.m_key.m_lod == 0;

	// Blending
	Bool blending = mtl.isBlendingEnabled();
	if(!blending)
	{
		if(m_stage == RenderingStage::BLEND)
		{
			return;
		}
	}
	else
	{
		if(m_stage != RenderingStage::BLEND)
		{
			return;
		}

		m_jobs.setBlendFunctions(
			mtl.getBlendingSfactor(), mtl.getBlendingDfactor());
	}

#if ANKI_GL == ANKI_GL_DESKTOP
	// TODO Set wireframe
#endif

	// Enqueue uniform state updates
	setupUniforms(visibleNode, renderable, fr, flod);

	// Enqueue vertex, program and drawcall
	build.m_subMeshIndicesArray = &visibleNode.m_spatialIndices[0];
	build.m_subMeshIndicesCount = visibleNode.m_spatialsCount;
	build.m_jobs = m_jobs;

	renderable.buildRendering(build);
}
Ejemplo n.º 4
0
void Shader::setupCommonUniforms()
{
	std::set<std::string> commonUniformNames
	{
		"u_eyePositionW",
		"u_elapsedTime",
		"u_techniqueMax",
		"u_M_Mat",
		"u_MV_Mat",
		"u_MVP_Mat",
		"u_N_Mat",
		"s_colorTex",
		"s_normalHeightTex",
		"s_cubeTex",
		"s_lightMapTex",
		"s_tex1",
		"s_tex2",
		"s_tex3",
		"u_technique",
		"u_scale",
		"u_bias",
		"enabledLights",
		"u_enableShadows",
		"u_numLightSources",
		"u_shadowMapPixelOffsetX",
		"u_shadowMapPixelOffsetY",
		"u_shadowMapArray",
	};

	char tmp[256];
	const char* lightAttributes[7] = { "type", "pos", "ambient", "diffuse", "specular", "attenuation", "shadowMatrix" };
	for (uint lightId = 0; lightId < 6; lightId++)
	{
		for (uint attribId = 0; attribId < 7; attribId++)
		{
			sprintf(tmp, "u_lights[%d].%s", lightId, lightAttributes[attribId]);
			commonUniformNames.insert(tmp);
		}
	}

	setupUniforms(commonUniformNames);

	// common uniform parameters
	setUniform1i("s_colorTex", 0);
	setUniform1i("s_normalHeightTex", 1);
	setUniform1i("s_cubeTex", 2);

	//additional textures
	setUniform1i("s_tex1", 3);
	setUniform1i("s_tex2", 4);
	setUniform1i("s_tex3", 5);


	setUniform1i("u_technique", 0);
	setUniform1f("u_scale", 0.04f);
	setUniform1f("u_bias", -0.02f);
}
Ejemplo n.º 5
0
bool PainterShaderProgram::link()
{
    m_startTime = g_clock.seconds();
    bindAttributeLocation(VERTEX_ATTR, "a_Vertex");
    bindAttributeLocation(TEXCOORD_ATTR, "a_TexCoord");
    if(ShaderProgram::link()) {
        bind();
        setupUniforms();
        release();
        return true;
    }
    return false;
}
Ejemplo n.º 6
0
bool DX11RenderEventHandler::onInitRenderPasses( const EventData *eventData ) {
    OSRE_ASSERT(nullptr != m_dx11Renderer);

    InitPassesEventData *frameToCommitData = (InitPassesEventData*)eventData;
    if (nullptr == frameToCommitData) {
        return false;
    }

    CPPCore::TArray<ui32> primGroups;
    Frame *frame = frameToCommitData->m_frame;
    for (ui32 passIdx = 0; passIdx < frame->m_newPasses.size(); ++passIdx) {
        PassData *currentPass = frame->m_newPasses[passIdx];
        OSRE_ASSERT(nullptr != currentPass);

        if (!currentPass->m_isDirty) {
            continue;
        }

        // ToDo: create pipeline pass for the name.
        for (ui32 batchIdx = 0; batchIdx < currentPass->m_geoBatches.size(); ++batchIdx) {
            GeoBatchData *currentBatchData = currentPass->m_geoBatches[batchIdx];
            OSRE_ASSERT(nullptr != currentBatchData);

            // set the matrix
            MatrixBuffer &matrixBuffer = currentBatchData->m_matrixBuffer;
            setConstantBuffers(matrixBuffer.m_model, matrixBuffer.m_view, matrixBuffer.m_proj, m_dx11Renderer );

            // set uniforms
            for (ui32 uniformIdx = 0; uniformIdx < currentBatchData->m_uniforms.size(); ++uniformIdx) {
                setupUniforms(nullptr, m_dx11Renderer);
                //setupConstantBuffer(currentBatchData->m_uniforms[uniformIdx], m_oglBackend, this);
            }

            // set meshes
            for (ui32 meshEntryIdx = 0; meshEntryIdx < currentBatchData->m_meshArray.size(); ++meshEntryIdx) {
                MeshEntry *currentMeshEntry = currentBatchData->m_meshArray[meshEntryIdx];
                OSRE_ASSERT(nullptr != currentMeshEntry);
                if (!currentMeshEntry->m_isDirty) {
                    continue;
                }

                for (ui32 meshIdx = 0; meshIdx < currentMeshEntry->m_geo.size(); ++meshIdx) {
                    Mesh *currentMesh = currentMeshEntry->m_geo[meshIdx];
                    OSRE_ASSERT(nullptr != currentMesh);

                    // register primitive groups to render
                    for (ui32 i = 0; i < currentMesh->m_numPrimGroups; ++i) {
                        //const ui32 primIdx(m_oglBackend->addPrimitiveGroup(&currentMesh->m_primGroups[i]));
                      //  primGroups.add(primIdx);
                    }

                    // create the default material
                    //SetMaterialStageCmdData *data = setupMaterial(currentMesh->m_material, m_oglBackend, this);

                    // setup vertex array, vertex and index buffers
                    //m_vertexArray = setupBuffers(currentMesh, m_oglBackend, m_renderCmdBuffer->getActiveShader());
                    //if (nullptr == m_vertexArray) {
                        osre_debug(Tag, "Vertex-Array-pointer is a nullptr.");
                        return false;
                    //}
                    //data->m_vertexArray = m_vertexArray;

                    // setup the draw calls
                    if (0 == currentMeshEntry->numInstances) {
                     /*   setupPrimDrawCmd(currentBatchData->m_id, currentMesh->m_localMatrix, currentMesh->m_model,
                            primGroups, m_oglBackend, this, m_vertexArray);*/
                    }
                    else {
                        /*setupInstancedDrawCmd(currentBatchData->m_id, primGroups, m_oglBackend, this, m_vertexArray,
                            currentMeshEntry->numInstances);*/
                    }

                    primGroups.resize(0);
                }
                currentMeshEntry->m_isDirty = false;
            }
        }
    }

    frame->m_newPasses.clear();

    //m_oglBackend->useShader(nullptr);

    return true;
}
Ejemplo n.º 7
0
void OcclusionSlicer::process() {

    // compile program if needed
    if (getInvalidationLevel() >= Processor::INVALID_PROGRAM)
        compile();
    LGL_ERROR;

    occlusionbuffer0_.activateTarget();
    glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    occlusionbuffer1_.activateTarget();
    glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    outport_.activateTarget();
    glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    LGL_ERROR;

    // bind transfer function
    TextureUnit transferUnit;
    transferUnit.activate();
    if (transferFunc_.get())
        transferFunc_.get()->bind();

    transferFunc_.setVolumeHandle(volumeInport_.getData());

    // vector containing the volumes to bind; is passed to bindVolumes()
    std::vector<VolumeStruct> volumeTextures;

    // add main volume
    TextureUnit volUnit;
    volumeTextures.push_back(VolumeStruct(
        volumeInport_.getData(),
        &volUnit,
        "volume_","volumeStruct_")
    );

    // initialize slicing shader
    tgt::Shader* slicingPrg = shaderProp_.getShader();
    slicingPrg->activate();

    // fragment shader uniforms
    TextureUnit occlusionUnit;
    transferFunc_.get()->setUniform(slicingPrg, "transferFunc_", "transferFuncTex_", transferUnit.getUnitNumber());
    slicingPrg->setUniform("occlusion_", occlusionUnit.getUnitNumber());
    occlusionbuffer1_.setTextureParameters(slicingPrg, "occlusionParams_");

    //clipping uniforms
    setupUniforms(slicingPrg);

    // set common uniforms used by all shaders
    tgt::Camera cam = camera_.get();
    setGlobalShaderParameters(slicingPrg, &cam);

    slicingPrg->setUniform("sigma_", sigma_.get());
    slicingPrg->setUniform("radius_", radius_.get());
    slicingPrg->setUniform("lightPos_", lightPosition_.get().xyz());

    // bind the volumes and pass the necessary information to the shader
    bindVolumes(slicingPrg, volumeTextures, &cam, lightPosition_.get());

    glDisable(GL_DEPTH_TEST);

    glMatrixMode(GL_PROJECTION);
    glPushMatrix();
    tgt::loadMatrix(camera_.get().getProjectionMatrix(outport_.getSize()));

    glMatrixMode(GL_MODELVIEW);
    glPushMatrix();
    tgt::loadMatrix(camera_.get().getViewMatrix());

    unsigned int numSlices = static_cast<unsigned int>(maxLength_ / sliceDistance_);

    slicingPrg->activate();

    for (unsigned int curSlice=0; curSlice<numSlices; curSlice++) {
        // first pass
        slicingPrg->setUniform("secondPass_", false);
        outport_.activateTarget();
        glEnable(GL_BLEND);
        glBlendFunc(GL_ONE_MINUS_DST_ALPHA, GL_ONE);

        occlusionbuffer0_.bindColorTexture(occlusionUnit.getEnum());

        glBegin(GL_POLYGON);
        for (unsigned int curPoint=0; curPoint<6; curPoint++)
            glVertex2i(curPoint, curSlice);
        glEnd();
        glDisable(GL_BLEND);

        outport_.deactivateTarget();

        // second pass
        slicingPrg->setUniform("secondPass_", true);

        occlusionbuffer1_.activateTarget();

        slicingPrg->setUniform("blurDirection_", tgt::vec2(1.f, 0.f));
        glBegin(GL_POLYGON);
        for (unsigned int curPoint=0; curPoint<6; curPoint++)
            glVertex2i(curPoint, curSlice);
        glEnd();

        occlusionbuffer1_.deactivateTarget();
        occlusionbuffer0_.activateTarget();
        occlusionbuffer1_.bindColorTexture(occlusionUnit.getEnum());

        slicingPrg->setUniform("blurDirection_", tgt::vec2(0.f, 1.f));
        glBegin(GL_POLYGON);
        for (unsigned int curPoint=0; curPoint<6; curPoint++)
            glVertex2i(curPoint, curSlice);
        glEnd();

        occlusionbuffer0_.deactivateTarget();
    }

    slicingPrg->deactivate();

    glEnable(GL_DEPTH_TEST);

    glPopMatrix();
    glMatrixMode(GL_PROJECTION);
    glPopMatrix();
    glMatrixMode(GL_MODELVIEW);

    glBlendFunc(GL_ONE, GL_ZERO);
    TextureUnit::setZeroUnit();
    LGL_ERROR;
}
Ejemplo n.º 8
0
void SingleVolumeSlicer::process() {

    // compile program if needed
    if (getInvalidationLevel() >= Processor::INVALID_PROGRAM)
        compile();
    LGL_ERROR;

    // bind transfer function
    TextureUnit transferUnit;
    transferUnit.activate();
    if (transferFunc_.get())
        transferFunc_.get()->bind();

    transferFunc_.setVolumeHandle(volumeInport_.getData());

    // vector containing the volumes to bind; is passed to bindVolumes()
    std::vector<VolumeStruct> volumeTextures;

    // add main volume
    TextureUnit volUnit;
    volumeTextures.push_back(VolumeStruct(
        volumeInport_.getData(),
        &volUnit,
        "volume_","volumeStruct_")
    );

    // initialize slicing shader
    tgt::Shader* slicingPrg = shaderProp_.getShader();
    slicingPrg->activate();
    // fragment shader uniforms
    transferFunc_.get()->setUniform(slicingPrg, "transferFunc_", "transferFuncTex_", transferUnit.getUnitNumber());

    setupUniforms(slicingPrg);

    // set common uniforms used by all shaders
    tgt::Camera cam = camera_.get();
    setGlobalShaderParameters(slicingPrg, &cam);
    // bind the volumes and pass the necessary information to the shader
    bindVolumes(slicingPrg, volumeTextures, &cam, lightPosition_.get());

    glDisable(GL_DEPTH_TEST);

    MatStack.matrixMode(tgt::MatrixStack::PROJECTION);
    MatStack.pushMatrix();
    MatStack.loadMatrix(camera_.get().getProjectionMatrix(outport_.getSize()));

    MatStack.matrixMode(tgt::MatrixStack::MODELVIEW);
    MatStack.pushMatrix();
    MatStack.loadMatrix(camera_.get().getViewMatrix());

    unsigned int numSlices = static_cast<unsigned int>(maxLength_ / sliceDistance_);

    slicingPrg->activate();
    outport_.activateTarget();
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    glEnable(GL_BLEND);
    glBlendFunc(GL_ONE_MINUS_DST_ALPHA, GL_ONE);

    for (unsigned int curSlice=0; curSlice<numSlices; curSlice++) {
        glBegin(GL_POLYGON);
            for (unsigned int curPoint=0; curPoint<6; curPoint++)
                glVertex2i(curPoint, curSlice);
        glEnd();
    }

    glBlendFunc(GL_ONE, GL_ZERO);
    glDisable(GL_BLEND);
    glEnable(GL_DEPTH_TEST);

    MatStack.popMatrix();
    MatStack.matrixMode(tgt::MatrixStack::PROJECTION);
    MatStack.popMatrix();
    MatStack.matrixMode(tgt::MatrixStack::MODELVIEW);

    slicingPrg->deactivate();
    outport_.deactivateTarget();
    TextureUnit::setZeroUnit();

    LGL_ERROR;
}
Ejemplo n.º 9
0
void HalfAngleSlicer::process() {

    // compile program if needed
    if (getInvalidationLevel() >= Processor::INVALID_PROGRAM)
        compile();
    LGL_ERROR;

    lightport_.activateTarget();
    glClearColor(1.0, 1.0, 1.0, 1.0);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    lightport_.deactivateTarget();
    outport_.activateTarget();
    glClearColor(0.0, 0.0, 0.0, 0.0);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    outport_.deactivateTarget();

    // bind transfer function
    TextureUnit transferUnit;
    transferUnit.activate();
    if (transferFunc_.get())
        transferFunc_.get()->bind();

    transferFunc_.setVolumeHandle(volumeInport_.getData());

    // vector containing the volumes to bind; is passed to bindVolumes()
    std::vector<VolumeStruct> volumeTextures;

    // add main volume
    TextureUnit volUnit;
    volumeTextures.push_back(VolumeStruct(
        volumeInport_.getData(),
        &volUnit,
        "volume_","volumeStruct_")
    );

    // initialize slicing shader
    tgt::Shader* slicingPrg = shaderProp_.getShader();
    slicingPrg->activate();

    // fragment shader uniforms
    transferFunc_.get()->setUniform(slicingPrg, "transferFunc_", "transferFuncTex_", transferUnit.getUnitNumber());

    // set common uniforms used by all shaders
    tgt::Camera cam = eyeCamera_.get();
    // bind the volumes and pass the necessary information to the shader
    bindVolumes(slicingPrg, volumeTextures, &cam, lightPosition_.get());

    setupUniforms(slicingPrg);

    // correct slice distance for this technique
    sliceDistance_ *= 0.5f*std::sqrt(1.f + dot(eyeCamera_.get().getLook(), lightCamera_.getLook()));
    slicingPrg->setUniform("dPlaneIncr_", sliceDistance_);

    glDisable(GL_DEPTH_TEST);

    glMatrixMode(GL_PROJECTION);
    glPushMatrix();
    tgt::loadMatrix(eyeCamera_.get().getProjectionMatrix(outport_.getSize()));

    glMatrixMode(GL_MODELVIEW);
    glPushMatrix();
    tgt::loadMatrix(eyeCamera_.get().getViewMatrix());

    slicingPrg->activate();
    glEnable(GL_BLEND);

    unsigned int numSlices = static_cast<unsigned int>(maxLength_ / sliceDistance_);

    TextureUnit lightBufferUnit;

    slicingPrg->setUniform("lightBuf_", lightBufferUnit.getUnitNumber());
    slicingPrg->setUniform("lightMat_", lightCamera_.getViewMatrix());
    lightport_.setTextureParameters(slicingPrg, "lightBufParameters_");

    for (unsigned int curSlice = 0; curSlice < numSlices; curSlice++) {
        outport_.activateTarget();

        // FIRST PASS
        if(invert_)
            glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
        else
            glBlendFunc(GL_ONE_MINUS_DST_ALPHA, GL_ONE);

        lightBufferUnit.activate();
        glEnable(GL_TEXTURE_2D);
        lightport_.bindColorTexture();

        tgt::Camera cam = eyeCamera_.get();
        setGlobalShaderParameters(slicingPrg, &cam);
        slicingPrg->setUniform("secondPass_", false);

        glBegin(GL_POLYGON);
            for (unsigned int curPoint=0; curPoint<6; curPoint++)
                glVertex2i(curPoint, curSlice);
        glEnd();

        outport_.deactivateTarget();

        // SECOND PASS
        lightport_.activateTarget();

        glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
        glPushMatrix();
        tgt::loadMatrix(lightCamera_.getViewMatrix());
        setGlobalShaderParameters(slicingPrg, &lightCamera_);
        slicingPrg->setUniform("secondPass_", true);

        glBegin(GL_POLYGON);
            for (unsigned int curPoint=0; curPoint<6; curPoint++)
                glVertex2i(curPoint, curSlice);
        glEnd();
        glPopMatrix();

        lightport_.deactivateTarget();
    }

    glBlendFunc(GL_ONE, GL_ZERO);
    glDisable(GL_BLEND);
    glEnable(GL_DEPTH_TEST);

    glPopMatrix();
    glMatrixMode(GL_PROJECTION);
    glPopMatrix();
    glMatrixMode(GL_MODELVIEW);

    slicingPrg->deactivate();

    glClearColor(0.0, 0.0, 0.0, 0.0);
    TextureUnit::setZeroUnit();
    LGL_ERROR;
}