veMaterial* veDeferredRenderPipeline::createSpotLightMaterial(veLight *light)
{
    auto material = new veMaterial;
    auto technique = new veTechnique;
    auto pass0 = new vePass;
    auto pass1 = new vePass;
    material->addTechnique(technique);
    technique->addPass(pass0);
    technique->addPass(pass1);
    
    pass0->setRenderPass(vePass::FORWARD_PASS);
    pass0->depthTest() = true;
    pass0->depthWrite() = false;
    pass0->stencilTest() = true;
    pass0->cullFace() = false;
    pass0->stencilFunc() = { GL_ALWAYS, 0, 0, GL_ALWAYS, 0, 0 };
    pass0->stencilOp() = { GL_KEEP, GL_DECR_WRAP, GL_KEEP, GL_KEEP, GL_INCR_WRAP, GL_KEEP };
    pass0->blendFunc() = veBlendFunc::DISABLE;
    pass0->setShader(new veShader(veShader::VERTEX_SHADER, WORLD_BASED_LIGHT_VERTEX_SHADER));
    pass0->setShader(new veShader(veShader::FRAGMENT_SHADER, "layout(location=0) out vec4 fragColor;void main(){}"));
    pass0->addUniform(new veUniform("u_ModelViewProjectMat", MVP_MATRIX));
    pass0->setApplyFunctionCallback([]() {
        glClear(GL_STENCIL_BUFFER_BIT);
        glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
    });
    
    initLightCommomParams(light, pass1);
    pass1->setRenderPass(vePass::FORWARD_PASS);
    pass1->depthTest() = false;
    pass1->depthWrite() = false;
    pass1->stencilTest() = true;
    pass1->cullFace() = true;
    pass1->cullFaceMode() = GL_FRONT;
    pass1->blendFunc().src = GL_ONE;
    pass1->blendFunc().dst = GL_ONE;
    pass1->blendEquation() = GL_FUNC_ADD;
    pass1->stencilFunc() = { GL_NOTEQUAL, 0, 0xFF, GL_NOTEQUAL, 0, 0xFF };
    pass1->setShader(new veShader(veShader::VERTEX_SHADER, WORLD_BASED_LIGHT_VERTEX_SHADER));
    pass1->setShader(new veShader(veShader::FRAGMENT_SHADER, SPOT_LIGHT_FRAGMENT_SHADER));
    pass1->addUniform(new veUniform("u_ModelViewProjectMat", MVP_MATRIX));
    pass1->addUniform(new veUniform("u_lightDirection", veVec3(0.0f)));
    pass1->addUniform(new veUniform("u_lightPosition", veVec3(0.0f)));
    pass1->addUniform(new veUniform("u_lightMatrix", veMat4::IDENTITY));
    pass1->addUniform(new veUniform("u_lightARI", 0.0f));
    pass1->addUniform(new veUniform("u_lightInnerAngleCos", 0.0f));
    pass1->addUniform(new veUniform("u_lightOuterAngleCos", 0.0f));
    pass1->addUniform(new veUniform("u_shadowTex", 4));
    pass1->setApplyFunctionCallback([]() {
        glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
    });
    
    return material;
}
Esempio n. 2
0
void Label::update()
{
    updateText();
    blendFunc(GL_ONE,GL_ONE_MINUS_SRC_ALPHA);
    
    if (getObject()) {
        m_transform->copy(getObject()->getTransInWorld());
    }
    else {
        m_transform->copy(GLCanvas::GetInstance()->getGlobalTrans());
    }
    float lastX=0;
    for (TextFrame* frame : m_allTextFrames) {
        Transform orgin;
        orgin.copy(m_transform);
        Transform offst;
        offst.setX(lastX);
        offst.setY(m_fontSize-frame->getBearingY());
        offst.flush();
        orgin.setWidth(frame->getWidth());
        orgin.setHeight(frame->getHeight());
        orgin.transform(&offst);
        
        GLCanvas::GetInstance()->paint(frame, &orgin, &m_color, m_program);
        lastX += frame->getAdvance();
    }
}
Esempio n. 3
0
void LLRender::blendFunc(eBlendFactor color_sfactor, eBlendFactor color_dfactor,
			 eBlendFactor alpha_sfactor, eBlendFactor alpha_dfactor)
{
	llassert(color_sfactor < BF_UNDEF);
	llassert(color_dfactor < BF_UNDEF);
	llassert(alpha_sfactor < BF_UNDEF);
	llassert(alpha_dfactor < BF_UNDEF);
	if (!gGLManager.mHasBlendFuncSeparate)
	{
		LL_WARNS_ONCE("render") << "no glBlendFuncSeparateEXT(), using color-only blend func" << llendl;
		blendFunc(color_sfactor, color_dfactor);
		return;
	}
	if (mCurrBlendColorSFactor != color_sfactor || mCurrBlendColorDFactor != color_dfactor ||
	    mCurrBlendAlphaSFactor != alpha_sfactor || mCurrBlendAlphaDFactor != alpha_dfactor)
	{
		mCurrBlendColorSFactor = color_sfactor;
		mCurrBlendAlphaSFactor = alpha_sfactor;
		mCurrBlendColorDFactor = color_dfactor;
		mCurrBlendAlphaDFactor = alpha_dfactor;
		flush();
		glBlendFuncSeparateEXT(sGLBlendFactor[color_sfactor], sGLBlendFactor[color_dfactor],
				       sGLBlendFactor[alpha_sfactor], sGLBlendFactor[alpha_dfactor]);
	}
}
void veSphereRenderer::render(veNode *node, veRenderableObject *renderableObj, veCamera *camera, unsigned int contextID)
{
	updateBuffer(contextID);

	veRenderCommand rc;
	rc.mask = node->getMask();
	rc.worldMatrix = new veMat4Ptr(node->getNodeToWorldMatrix());
	//rc.attachedNode = node;
	rc.camera = camera;
	rc.sceneManager = camera->getSceneManager();
	rc.depthInCamera = (camera->viewMatrix() * rc.worldMatrix->value())[2][3];
	rc.renderer = this;
    rc.contextID = contextID;

    auto material = renderableObj->getMaterial();
    for (unsigned int i = 0; i < material->activeTechnique()->getPassNum(); ++i) {
        auto pass = material->activeTechnique()->getPass(i);
        if (camera->getMask() & pass->drawMask()) {
            bool isTransparent = pass->blendFunc() != veBlendFunc::DISABLE ? true : false;
            rc.pass = pass;
            pass->visit(rc);
            if (isTransparent)
                camera->getRenderQueue()->pushCommand(i, veRenderQueue::RENDER_QUEUE_TRANSPARENT, rc);
            else
                camera->getRenderQueue()->pushCommand(i, veRenderQueue::RENDER_QUEUE_ENTITY, rc);
        }
    }
}
static FilterOperations applyFilterAnimation(const FilterOperations& from, const FilterOperations& to, double progress, const FloatSize& boxSize)
{
    // First frame of an animation.
    if (!progress)
        return from;

    // Last frame of an animation.
    if (progress == 1)
        return to;

    if (!from.isEmpty() && !to.isEmpty() && !from.operationsMatch(to))
        return to;

    FilterOperations result;

    size_t fromSize = from.operations().size();
    size_t toSize = to.operations().size();
    size_t size = std::max(fromSize, toSize);
    for (size_t i = 0; i < size; i++) {
        RefPtr<FilterOperation> fromOp = (i < fromSize) ? from.operations()[i].get() : nullptr;
        RefPtr<FilterOperation> toOp = (i < toSize) ? to.operations()[i].get() : nullptr;
        RefPtr<FilterOperation> blendedOp = toOp ? blendFunc(fromOp.get(), *toOp, progress, boxSize) : (fromOp ? blendFunc(nullptr, *fromOp, progress, boxSize, true) : nullptr);
        if (blendedOp)
            result.operations().append(blendedOp);
        else {
            RefPtr<FilterOperation> identityOp = PassthroughFilterOperation::create();
            if (progress > 0.5)
                result.operations().append(toOp ? toOp : identityOp);
            else
                result.operations().append(fromOp ? fromOp : identityOp);
        }
    }

    return result;
}
veMaterial* veDeferredRenderPipeline::createIBLightMaterial(veLight *light)
{
    auto material = new veMaterial;
    auto technique = new veTechnique;
    auto pass = new vePass;
    material->addTechnique(technique);
    technique->addPass(pass);
    
    initLightCommomParams(light, pass);
    pass->setRenderPass(vePass::FORWARD_PASS);
    pass->depthTest() = false;
    pass->depthWrite() = false;
    pass->stencilTest() = false;
    pass->cullFace() = true;
    pass->cullFaceMode() = GL_BACK;
    pass->blendFunc().src = GL_ONE;
    pass->blendFunc().dst = GL_ONE;
    pass->blendEquation() = GL_FUNC_ADD;
    pass->setShader(new veShader(veShader::VERTEX_SHADER, SCREEN_BASED_LIGHT_VERTEX_SHADER));
    pass->setShader(new veShader(veShader::FRAGMENT_SHADER, IB_LIGHT_FRAGMENT_SHADER));
    pass->addUniform(new veUniform("u_lightDirection", veVec3::ZERO));
    pass->addUniform(new veUniform("u_specularMipMapCount", 1.0f));
    pass->addUniform(new veUniform("u_diffuseLighting", 4));
    pass->addUniform(new veUniform("u_specularLighting", 5));
    
    
    return material;
}
veMaterial* veDeferredRenderPipeline::createDirectionalLightMaterial(veLight *light)
{
    auto material = new veMaterial;
    auto technique = new veTechnique;
    auto pass = new vePass;
    material->addTechnique(technique);
    technique->addPass(pass);
    
    initLightCommomParams(light, pass);
    pass->setRenderPass(vePass::FORWARD_PASS);
    pass->depthTest() = false;
    pass->depthWrite() = false;
    pass->stencilTest() = false;
    pass->cullFace() = true;
    pass->cullFaceMode() = GL_BACK;
    pass->blendFunc().src = GL_ONE;
    pass->blendFunc().dst = GL_ONE;
    pass->blendEquation() = GL_FUNC_ADD;
    pass->setShader(new veShader(veShader::VERTEX_SHADER, SCREEN_BASED_LIGHT_VERTEX_SHADER));
    pass->setShader(new veShader(veShader::FRAGMENT_SHADER, DIRECTIONAL_LIGHT_FRAGMENT_SHADER));
    pass->addUniform(new veUniform("u_lightDirection", veVec3::ZERO));
    pass->addUniform(new veUniform("u_lightMatrixs", &veMat4::IDENTITY, 1));
    pass->addUniform(new veUniform("u_shadowCascadedLevels", 0.f));
    pass->addUniform(new veUniform("u_shadowCascadedCount", 0.f));
    pass->addUniform(new veUniform("u_shadowTex", 4));
    
    return material;
}
Esempio n. 8
0
po::BlendState::BlendState() {
	enabled = false;
	
	blendEquation(GL_FUNC_ADD);
	blendFunc(GL_ONE, GL_ZERO);
	
	color = poColor::transparent;
}
Esempio n. 9
0
void LLRender::setSceneBlendType(eBlendType type)
{
	switch (type) 
	{
		case BT_ALPHA:
			blendFunc(BF_SOURCE_ALPHA, BF_ONE_MINUS_SOURCE_ALPHA);
			break;
		case BT_ADD:
			blendFunc(BF_ONE, BF_ONE);
			break;
		case BT_ADD_WITH_ALPHA:
			blendFunc(BF_SOURCE_ALPHA, BF_ONE);
			break;
		case BT_MULT:
			blendFunc(BF_DEST_COLOR, BF_ZERO);
			break;
		case BT_MULT_ALPHA:
			blendFunc(BF_DEST_ALPHA, BF_ZERO);
			break;
		case BT_MULT_X2:
			blendFunc(BF_DEST_COLOR, BF_SOURCE_COLOR);
			break;
		case BT_REPLACE:
			blendFunc(BF_ONE, BF_ZERO);
			break;
		default:
			llerrs << "Unknown Scene Blend Type: " << type << llendl;
			break;
	}
}
Esempio n. 10
0
RefPtr<CSSCrossfadeValue> CSSCrossfadeValue::blend(const CSSCrossfadeValue& from, double progress) const
{
    ASSERT(equalInputImages(from));
    if (!m_cachedToImage || !m_cachedFromImage)
        return nullptr;
    auto fromImageValue = CSSImageValue::create(*m_cachedFromImage);
    auto toImageValue = CSSImageValue::create(*m_cachedToImage);

    double fromPercentage = from.m_percentageValue->getDoubleValue();
    if (from.m_percentageValue->isPercentage())
        fromPercentage /= 100.0;
    double toPercentage = m_percentageValue->getDoubleValue();
    if (m_percentageValue->isPercentage())
        toPercentage /= 100.0;
    auto percentageValue = CSSPrimitiveValue::create(blendFunc(fromPercentage, toPercentage, progress), CSSPrimitiveValue::CSS_NUMBER);

    return CSSCrossfadeValue::create(WTFMove(fromImageValue), WTFMove(toImageValue), WTFMove(percentageValue), from.isPrefixed() && isPrefixed());
}
Esempio n. 11
0
bool ofPixels_<PixelType>::blendInto(ofPixels_<PixelType> &dst, int xTo, int yTo) const{
	if (!(isAllocated()) || !(dst.isAllocated()) || getBytesPerPixel() != dst.getBytesPerPixel() || xTo + getWidth()>dst.getWidth() || yTo + getHeight()>dst.getHeight() || getNumChannels()==0) return false;

	std::function<void(const ConstPixel&,Pixel&)> blendFunc;
	switch(getNumChannels()){
	case 1:
		blendFunc = [](const ConstPixel&src, Pixel&dst){
			dst[0] = clampedAdd(src[0], dst[0]);
		};
		break;
	case 2:
		blendFunc = [](const ConstPixel&src, Pixel&dst){
			dst[0] = clampedAdd(src[0], dst[0] / ofColor_<PixelType>::limit() * (ofColor_<PixelType>::limit() - src[1]));
			dst[1] = clampedAdd(src[1], dst[1] / ofColor_<PixelType>::limit() * (ofColor_<PixelType>::limit() - src[1]));
		};
		break;
	case 3:
		blendFunc = [](const ConstPixel&src, Pixel&dst){
			dst[0] = clampedAdd(src[0], dst[0]);
			dst[1] = clampedAdd(src[1], dst[1]);
			dst[2] = clampedAdd(src[2], dst[2]);
		};
		break;
	case 4:
		blendFunc = [](const ConstPixel&src, Pixel&dst){
			dst[0] = clampedAdd(src[0], dst[0] / ofColor_<PixelType>::limit() * (ofColor_<PixelType>::limit() - src[3]));
			dst[1] = clampedAdd(src[1], dst[1] / ofColor_<PixelType>::limit() * (ofColor_<PixelType>::limit() - src[3]));
			dst[2] = clampedAdd(src[2], dst[2] / ofColor_<PixelType>::limit() * (ofColor_<PixelType>::limit() - src[3]));
			dst[3] = clampedAdd(src[3], dst[3] / ofColor_<PixelType>::limit() * (ofColor_<PixelType>::limit() - src[3]));
		};
		break;
	}
	auto dstLine = dst.getLine(yTo);
	for(auto line: getConstLines()){
		auto dstPixel = dstLine.getPixels().begin() + xTo;
		for(auto p: line.getPixels()){
			blendFunc(p,dstPixel);
			dstPixel++;
		}
		dstLine++;
	}

	return true;
}
Esempio n. 12
0
PassRefPtr<CSSCrossfadeValue> CSSCrossfadeValue::blend(const CSSCrossfadeValue& from, double progress) const
{
    ASSERT(equalInputImages(from));
    RefPtr<StyleCachedImage> toStyledImage = StyleCachedImage::create(m_cachedToImage.get());
    RefPtr<StyleCachedImage> fromStyledImage = StyleCachedImage::create(m_cachedFromImage.get());

    auto fromImageValue = CSSImageValue::create(m_cachedFromImage->url(), fromStyledImage.get());
    auto toImageValue = CSSImageValue::create(m_cachedToImage->url(), toStyledImage.get());

    RefPtr<CSSCrossfadeValue> crossfadeValue = CSSCrossfadeValue::create(WTF::move(fromImageValue), WTF::move(toImageValue));

    double fromPercentage = from.m_percentageValue->getDoubleValue();
    if (from.m_percentageValue->isPercentage())
        fromPercentage /= 100.0;
    double toPercentage = m_percentageValue->getDoubleValue();
    if (m_percentageValue->isPercentage())
        toPercentage /= 100.0;
    crossfadeValue->setPercentage(CSSPrimitiveValue::create(blendFunc(fromPercentage, toPercentage, progress), CSSPrimitiveValue::CSS_NUMBER));
    return crossfadeValue.release();
}
Esempio n. 13
0
void LLDrawPoolWLSky::renderSkyClouds(F32 camHeightLocal) const
{
	if (gPipeline.canUseWindLightShaders() && gPipeline.hasRenderType(LLPipeline::RENDER_TYPE_WL_CLOUDS))
	{
		LLGLSLShader* shader =
			LLPipeline::sUnderWaterRender ?
				&gObjectSimpleWaterProgram :
				&gWLCloudProgram;

		LLGLEnable blend(GL_BLEND);
		LLGLSBlendFunc blendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
		gGL.setAlphaRejectSettings(LLRender::CF_DEFAULT);

		gGL.getTexUnit(0)->bind(sCloudNoiseTexture);

		shader->bind();

		/// Render the skydome
		renderDome(camHeightLocal, shader);

		shader->unbind();
	}
}
veMaterial* veDeferredRenderPipeline::createAmbientLightMaterial()
{
    auto material = new veMaterial;
    auto technique = new veTechnique;
    auto pass = new vePass;
    material->addTechnique(technique);
    technique->addPass(pass);
    
    pass->setRenderPass(vePass::FORWARD_PASS);
    pass->depthTest() = false;
    pass->depthWrite() = false;
    pass->stencilTest() = false;
    pass->cullFace() = true;
    pass->cullFaceMode() = GL_BACK;
    pass->blendFunc().src = GL_ONE;
    pass->blendFunc().dst = GL_ONE;
    pass->blendEquation() = GL_FUNC_ADD;
    pass->setShader(new veShader(veShader::VERTEX_SHADER, SCREEN_BASED_LIGHT_VERTEX_SHADER));
    pass->setShader(new veShader(veShader::FRAGMENT_SHADER, AMBIENT_LIGHT_FRAGMENT_SHADER));
    pass->addUniform(new veUniform("u_ambient", veVec3::ZERO));
    pass->addUniform(new veUniform("u_RT1", 0));
    
    return material;
}
void veTerrainRenderer::render(veNode *node, veRenderableObject *renderableObj, veCamera *camera, unsigned int contextID)
{
    
    auto vao = _vaoBuffer->getData(contextID);
    if (!vao) {
        vao = _vaoBuffer->createData(contextID);
        _needRefresh = true;
    }
    
    auto terrainGrid = static_cast<veTerrainGrid *>(renderableObj);
    if (_needRefresh) {
        glBindVertexArray(vao);
        
        auto vbo = _vboBuffer->getData(contextID);
        if (!vbo){
            vbo = _vboBuffer->createData(contextID);
        }
        glBindBuffer(GL_ARRAY_BUFFER, vbo);
        
        if (!terrainGrid->getVertexArray()->empty())
            glBufferData(GL_ARRAY_BUFFER, terrainGrid->getVertexArray()->size() * sizeof((*terrainGrid->getVertexArray())[0]), terrainGrid->getVertexArray()->buffer(), GL_DYNAMIC_DRAW);
        
        unsigned int stride = terrainGrid->getVertexStride();
        
        unsigned int offsets = 0;
        for (unsigned int i = 0; i < terrainGrid->getVertexAtrributeNum(); ++i) {
            glVertexAttribPointer(i, terrainGrid->getVertexAtrributeSize(i), GL_FLOAT, GL_FALSE, stride, (GLvoid *)(sizeof(GLfloat) * offsets));
            glEnableVertexAttribArray(i);
            offsets += terrainGrid->getVertexAtrributeSize(i);
        }
        
        auto ibo = _iboBuffer->getData(contextID);
        if (!ibo){
            ibo = _iboBuffer->createData(contextID);
        }
        
        glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ibo);
        if (!terrainGrid->getIndexArray()->empty())
            glBufferData(GL_ELEMENT_ARRAY_BUFFER, terrainGrid->getIndexArray()->size() * sizeof((*terrainGrid->getIndexArray())[0]), terrainGrid->getIndexArray()->buffer(), GL_STATIC_DRAW);
        _indicesCount = (GLsizei)terrainGrid->getIndexArray()->size();
        
        _needRefresh = false;
    }

	veRenderCommand rc;
	rc.mask = node->getMask();
	rc.worldMatrix = new veMat4Ptr(node->getNodeToWorldMatrix());
	rc.camera = camera;
	rc.sceneManager = camera->getSceneManager();
	rc.depthInCamera = (camera->viewMatrix() * rc.worldMatrix->value())[2][3];
	rc.renderer = this;
    rc.contextID = contextID;

    auto material = renderableObj->getMaterial();
    for (unsigned int i = 0; i < material->activeTechnique()->getPassNum(); ++i) {
        auto pass = material->activeTechnique()->getPass(i);
        if (camera->getMask() & pass->drawMask()) {
            bool isTransparent = pass->blendFunc() != veBlendFunc::DISABLE ? true : false;
            rc.pass = pass;
            pass->visit(rc);
            if (isTransparent)
                camera->getRenderQueue()->pushCommand(i, veRenderQueue::RENDER_QUEUE_TRANSPARENT, rc);
            else
                camera->getRenderQueue()->pushCommand(i, veRenderQueue::RENDER_QUEUE_ENTITY, rc);
        }
    }

}