void ElectrodeRenderer2D::initializeShaders()
{
    ElectrodeRenderer::initializeShaders();

    auto vertexShader = us::ShaderObject::create();
    vertexShader->loadFile("shaders/electrodesOrtho.vert");

    auto geometryShader = us::ShaderObject::create();
    geometryShader->loadFile("shaders/electrodesOrtho.geom");

    auto fragmentShader = us::ShaderObject::create();
    fragmentShader->loadFile("shaders/electrodesOrtho.frag");

    auto program = us::ShaderProgram::create();
    program->addShaderObject(vertexShader);
    program->addShaderObject(geometryShader);
    program->addShaderObject(fragmentShader);
    program->ensureLink();

    auto input = program->getInput();
    _electrodePosAttr = input->addAttribute("position");
    _electrodeColorAttr = input->addAttribute("vColor");
    _radiusUnif = input->addUniform("radius");
    _mvpMatrixUnif = input->addUniform("mvpMatrix");

    _electrodePosAttr->connectBuffer(_electrodePosAttrBuf);
    _electrodePosAttr->setReadingMode(us::Attribute::ReadingMode::FLOAT);

    _electrodeColorAttr->connectBuffer(_electrodeColorAttrBuf);
    _electrodeColorAttr->setReadingMode(us::Attribute::ReadingMode::FLOAT);

    _renderEngine->connectProgram(program);
}
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;
}
示例#3
0
// Method to link the shader program and display the link status
void ShaderProgram::link()
{
    // If we have at least two shaders (like a vertex shader and a fragment shader)...
    if (shaderCount >= 2)
    {
        // Perform the linking process
        glLinkProgram(programId);

        // Check the status
        GLint linkStatus;
        glGetProgramiv(programId, GL_LINK_STATUS, &linkStatus);
        if (linkStatus == GL_FALSE)
        {
            std::cout << "Shader program linking failed." << std::endl;
            // glfwTerminate();
        }
        else
        {
            addUniform( "model" );
            addUniform( "view" );
            addUniform( "projection" );

            std::cout << "Shader program linking OK." << std::endl;
        }
    }
    else
    {
        std::cout << "Can't link shaders - you need at least 2, but attached shader count is only: " << shaderCount << std::endl;
        // glfwTerminate();
    }

}
示例#4
0
SkyboxShader::SkyboxShader() : Shader("skybox_vert.glsl", "skybox_frag.glsl") {
	addUniform("worldToViewMatrix");
	addUniform("viewToProjectionMatrix");
	addUniform("modColour");
	addUniform("ambientLight");
	setTextureUnit("theTexture");
}
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;
}
ForwardAmbientLightShader::ForwardAmbientLightShader() : Shader("forward_ambient_vert.glsl",
																"forward_ambient_frag.glsl") {
	addUniform("ambientLight");
	addUniform("worldToProjectionMatrix");
	addUniform("modelToWorldMatrix");
	addUniform("modColour");

	setTextureUnit("theTexture");
}
示例#7
0
BasicShader::BasicShader()
{
	addVertexShaderFromFile("basicVertex.txt");
	addFragmentShaderFromFile("basicFragment.txt");
	compileShader();

	addUniform("transform");
	addUniform("color");
	addUniform("sampler");
}
示例#8
0
SkyBox::SkyBox()
{
	addVertexShaderFromFile("SkyBox.vs");
	addFragmentShaderFromFile("SkyBox.fs");
	compileShader();

	addUniform("view");
	addUniform("projection");
	addUniform("cameraPos");
}
示例#9
0
int main() {
  circe::SceneApp<> app(800, 800, "", false);
  app.init();
  app.addViewport(0, 0, 800, 800);
  ponos::RawMeshSPtr mesh(new ponos::RawMesh());
  // circe::loadOBJ("/mnt/windows/Users/fuiri/Desktop/dragon.obj", &mesh);
  circe::loadOBJ(
      "/mnt/windows/Projects/ponos/circe/examples/assets/torusknot.obj",
      mesh.get());
  mesh->apply(ponos::scale(0.1, 0.1, 0.1));
  mesh->computeBBox();
  mesh->splitIndexData();
  mesh->buildInterleavedData();
  auto texture = circe::ImageTexture::checkBoard(64, 64);
  ponos::RawMeshSPtr m(
      ponos::create_icosphere_mesh(ponos::Point3(), 1.f, 3, true, false));
  // create a vertex buffer for base mesh
  // circe::SceneMesh sm(*m.get());
  circe::SceneMesh smesh(mesh);
  auto s = circe::ShaderProgram(
      circe::ShaderManager::instance().loadFromTexts(vs, nullptr, fs));
  s.addVertexAttribute("position", 0);
  s.addVertexAttribute("normal", 1);
  s.addVertexAttribute("texcoord", 2);
  s.addUniform("proj", 3);
  s.addUniform("model", 4);
  s.addUniform("tex", 5);
  // create a buffer for particles positions + sizes
  app.viewports[0].renderCallback = [&](const circe::CameraInterface *camera) {
    smesh.bind();
    smesh.vertexBuffer()->locateAttributes(s);
    texture.bind(GL_TEXTURE0);
    s.begin();
    s.setUniform("proj",
                 ponos::transpose(camera->getProjectionTransform().matrix()));
    s.setUniform("model",
                 ponos::transpose(camera->getViewTransform().matrix()));
    circe::CHECK_GL_ERRORS;
    s.setUniform("tex", 0);
    //    s.setUniform("ldir", ponos::vec3(1,0,0));
    circe::CHECK_GL_ERRORS;
    auto ib = smesh.indexBuffer();
    glDrawElements(ib->bufferDescriptor.elementType,
                   ib->bufferDescriptor.elementCount *
                       ib->bufferDescriptor.elementSize,
                   ib->bufferDescriptor.dataType, 0);
    circe::CHECK_GL_ERRORS;
    s.end();
  };
  circe::SceneObjectSPtr grid(new circe::CartesianGrid(5));
  app.scene.add(grid.get());
  app.run();
  return 0;
}
示例#10
0
BasicShader::BasicShader()
{
	addVertexShaderFromFile("blinnPhong.vs");
	addFragmentShaderFromFile("blinnPhong.fs");
	compileShader();

	addUniform("transform");
	addUniform("color");
	addUniform("time");
	//addUniform("sampler2D");
}
示例#11
0
void Scene::createVertexNode()
{
    _vgeode = new osg::Geode;
    _vgeode->setDataVariance(osg::Object::DYNAMIC);

    osg::Vec3f lightDir(1.0f, 1.0f, 1.0f);
    lightDir.normalize();

    auto offsets = new osg::Uniform(osg::Uniform::FLOAT_VEC3, "offsets", Scene::VertexInstances);
    offsets->setDataVariance(osg::Object::DYNAMIC);

    auto stateSet = _vgeode->getOrCreateStateSet();
    stateSet->setAttributeAndModes(_instancedProgram, osg::StateAttribute::ON);
    stateSet->addUniform(new osg::Uniform("ecLightDirection", lightDir));
    stateSet->addUniform(new osg::Uniform("lightColor", osg::Vec3(1.0f, 1.0f, 1.0f)));
    stateSet->addUniform(offsets);

    osg::Vec3 scale(1.0f, 1.0f, 1.0f);
    osg::Vec4 color(0.25f, 0.25f, 0.25f, 1.0f);

    auto vertexMatrix = osg::Matrixf::scale(scale * 0.125f * 0.25f);
    auto normalMatrix = inverseTranspose(vertexMatrix);

    _vgeometry = new osgKaleido::PolyhedronGeometry("#27");
    _vgeometry->setUseDisplayList(false);
    _vgeometry->setUseVertexBufferObjects(true);

    _vgeometry->update(nullptr); // Force geometry generation

    auto vertices = dynamic_cast<osg::Vec3Array*>(_vgeometry->getVertexArray());
    if (vertices != nullptr) {
        transform(*vertices, vertexMatrix);
    }

    auto normals = dynamic_cast<osg::Vec3Array*>(_vgeometry->getNormalArray());
    if (normals != nullptr) {
        transform(*normals, normalMatrix);
    }

    auto colors = dynamic_cast<osg::Vec4Array*>(_vgeometry->getColorArray());
    if (colors != nullptr) {
        fill(*colors, color);
    }

    makeInstanced(_vgeometry, Scene::VertexInstances);

    auto size = 1.0f;
    osg::BoundingBox bb(-size, -size, -size, +size, +size, +size);
    _vgeometry->setInitialBound(bb);

    _vgeode->addDrawable(_vgeometry);

    addChild(_vgeode);
}
示例#12
0
BasicShader::BasicShader()
{
    addVertexShaderFromFile("basicVertex.vs");
    addFragmentShaderFromFile("basicFragment.fs");

    //setAttribLocation("position", 0);
    //setAttribLocation("texCoord", 1);
    compileShader();

    addUniform("transform");
    addUniform("color");
}
Program::Program(const ProgramDescription& description, const char* vertex, const char* fragment) {
    mInitialized = false;
    mHasColorUniform = false;
    mHasSampler = false;
    mUse = false;

    // No need to cache compiled shaders, rely instead on Android's
    // persistent shaders cache
    mVertexShader = buildShader(vertex, GL_VERTEX_SHADER);
    if (mVertexShader) {
        mFragmentShader = buildShader(fragment, GL_FRAGMENT_SHADER);
        if (mFragmentShader) {
            mProgramId = glCreateProgram();

            glAttachShader(mProgramId, mVertexShader);
            glAttachShader(mProgramId, mFragmentShader);

            bindAttrib("position", kBindingPosition);
            if (description.hasTexture || description.hasExternalTexture) {
                texCoords = bindAttrib("texCoords", kBindingTexCoords);
            } else {
                texCoords = -1;
            }

            ATRACE_BEGIN("linkProgram");
            glLinkProgram(mProgramId);
            ATRACE_END();

            GLint status;
            glGetProgramiv(mProgramId, GL_LINK_STATUS, &status);
            if (status != GL_TRUE) {
                GLint infoLen = 0;
                glGetProgramiv(mProgramId, GL_INFO_LOG_LENGTH, &infoLen);
                if (infoLen > 1) {
                    GLchar log[infoLen];
                    glGetProgramInfoLog(mProgramId, infoLen, nullptr, &log[0]);
                    ALOGE("%s", log);
                }
                LOG_ALWAYS_FATAL("Error while linking shaders");
            } else {
                mInitialized = true;
            }
        } else {
            glDeleteShader(mVertexShader);
        }
    }

    if (mInitialized) {
        transform = addUniform("transform");
        projection = addUniform("projection");
    }
}
示例#14
0
void UIShader::extractUniforms(string _shaderCode){
    //  Prepear the uniform to be checked
    //
    for (int i = 0; i < uniforms.size(); i++) {
        uniforms[i]->bUpdated = false;
    }
    
    //  Read the shader and check what needs to be added;
    //
    vector<string> lines = ofSplitString(_shaderCode, "\n");
    for(int i = 0; i<lines.size(); i++){
        vector<string> words = ofSplitString( lines[i], " ");
        
        for(int j = 0; j < words.size(); j++){
            if (words[j] == "uniform"){
                jumpNextWord(j,words);
                
                if (words[j] == "vec3"){
                    jumpNextWord(j,words);
                    eraseSemiColon(words[j]);
                    addUniform(UNIFORM_VEC3,words[j]);
                } else if (words[j] == "vec2"){
                    jumpNextWord(j,words);
                    eraseSemiColon(words[j]);
                    addUniform(UNIFORM_VEC2,words[j]);
                } else if (words[j] == "float"){
                    jumpNextWord(j,words);
                    eraseSemiColon(words[j]);
                    addUniform(UNIFORM_FLOAT,words[j]);
                }
                
            } else {
                break;
            }
        }
    }
    
//    //  Get rid of extra uniforms
//    //
//    for (int i = uniforms.size()-1; i >= 0; i--) {
//        if (!uniforms[i]->bUpdated){
//            
//            gui->removeWidget( uniforms[i]->name );
//            delete uniforms[i];
//            uniforms.erase(uniforms.begin()+i);
//        }
//    }
}
void ShapeRenderer2D::initializeShaders()
{
    auto vertexShader = us::ShaderObject::create();
    vertexShader->loadFile("shaders/shapes2D.vert");

    auto fragmentShader = us::ShaderObject::create();
    fragmentShader->loadFile("shaders/shapes2D.frag");

    auto program = us::ShaderProgram::create();
    program->addShaderObject(vertexShader);
    program->addShaderObject(fragmentShader);
    program->ensureLink();

    auto input = program->getInput();
    _posAttr = input->addAttribute("position");
    _colorAttr = input->addAttribute("vColor");
    _mvpMatrixUnif = input->addUniform("mvpMatrix");

    _posAttrBuf = us::Buffer<float>::create();
    _posAttr->setReadingMode(us::Attribute::ReadingMode::FLOAT);
    _posAttr->connectBuffer(_posAttrBuf);

    _colorAttrBuf = us::Buffer<float>::create();
    _colorAttr->setReadingMode(us::Attribute::ReadingMode::FLOAT);
    _colorAttr->connectBuffer(_colorAttrBuf);

    _renderEngine->connectProgram(program);
}
示例#16
0
void Shader::ShaderCode::addUniform(string & name)
{
	string uniName = "";
	if (name[name.size() - 1] == ';')
		uniName = name.substr(0, name.size() - 2);
	else
		uniName = name;
	unsigned int nameSep1 = uniName.find_first_of(' ');
	string varName = uniName.substr(nameSep1 + 1, uniName.size() - nameSep1 - 1);
	unsigned int size = Uniform::getUniformSize(name);
	if (size > 0)
		uniforms.push_back(Uniform(varName, size));
	else
	{
		vector<string> variableNames = resolveStructVariable(uniName);
		for (unsigned int i = 1; i < variableNames.size(); i++) //recursivly add all Structure Variables
		{
			string variable = "";
			unsigned int nameSep = variableNames[i].find_first_of(' ');
			variable += variableNames[i].substr(0, nameSep); //type
			variable += " " + varName;
			variable += "." + variableNames[i].substr(nameSep + 1, variableNames[i].size() - nameSep - 1);
			addUniform(variable);
		}
	}
}
int Program::getUniform(const char* name) {
    ssize_t index = mUniforms.indexOfKey(name);
    if (index >= 0) {
        return mUniforms.valueAt(index);
    }
    return addUniform(name);
}
示例#18
0
void
VSShaderLib::addUniforms() {

	int count;
	GLsizei actualLen;
	GLint size;
	GLint uniArrayStride;
	GLenum type;
	char *name;

	int maxUniLength;
	glGetProgramiv(pProgram, GL_ACTIVE_UNIFORMS, &count);

	glGetProgramiv(pProgram, GL_ACTIVE_UNIFORM_MAX_LENGTH, &maxUniLength);

	name = (char *)malloc(sizeof(char) * maxUniLength);

	unsigned int loc;
	for (int i = 0; i < count; ++i) {

		glGetActiveUniform(pProgram, i, maxUniLength, &actualLen, &size, &type, name);
		// -1 indicates that is not an active uniform, although it may be present in a
		// uniform block
		loc = glGetUniformLocation(pProgram, name);
		if (loc != -1) {
			glGetActiveUniformsiv(pProgram, 1, (GLuint*)&i, GL_UNIFORM_ARRAY_STRIDE, &uniArrayStride);
			addUniform(name, type, size);
		}
	}
	free(name);
}
示例#19
0
int main() {
  circe::SceneApp<> app(800, 800, "");
  app.scene.add(new circe::CartesianGrid(5));
  auto objPath = std::string(ASSETS_PATH) + "/suzanne.obj";
  //   objPath = "C:/Users/fuiri/Desktop/dragon.obj";
  auto vs = std::string(SHADERS_PATH) + "/basic.vert";
  auto fs = std::string(SHADERS_PATH) + "/basic.frag";
  auto shader = circe::createShaderProgramPtr(
      circe::ShaderManager::instance().loadFromFiles({vs.c_str(), fs.c_str()}));
  shader->addVertexAttribute("position", 0);
  shader->addVertexAttribute("normal", 1);
  shader->addUniform("Light.position", 2);
  shader->addUniform("Light.ambient", 3);
  shader->addUniform("Light.diffuse", 4);
  shader->addUniform("Light.specular", 5);
  shader->addUniform("Material.kAmbient", 6);
  shader->addUniform("Material.kDiffuse", 7);
  shader->addUniform("Material.kSpecular", 8);
  shader->addUniform("Material.shininess", 9);
  shader->addUniform("cameraPosition", 10);
  shader->addUniform("model", 11);
  shader->addUniform("view", 12);
  shader->addUniform("projection", 13);
  auto obj = circe::createSceneMeshObjectSPtr(objPath, shader);
  std::cerr << *obj->mesh()->rawMesh() << std::endl;
  obj->transform = ponos::scale(0.5, 0.5, 0.5);
  obj->drawCallback = [](circe::ShaderProgram *s,
                         const circe::CameraInterface *camera,
                         ponos::Transform t) {
    glEnable(GL_DEPTH_TEST);
    s->begin();
    s->setUniform("Light.position", ponos::vec3(0, 0, 5));
    s->setUniform("Light.ambient", ponos::vec3(1, 1, 1));
    s->setUniform("Light.diffuse", ponos::vec3(1, 1, 1));
    s->setUniform("Light.specular", ponos::vec3(1, 1, 1));
    s->setUniform("Material.kAmbient", ponos::vec3(0.01, 0.01, 0.1));
    s->setUniform("Material.kDiffuse", ponos::vec3(0.5, 0.5, 0.5));
    s->setUniform("Material.kSpecular", ponos::vec3(0.8, 1, 1));
    s->setUniform("Material.shininess", 200.f);
    s->setUniform("model", ponos::transpose(t.matrix()));
    s->setUniform("view",
                  ponos::transpose(camera->getViewTransform().matrix()));
    s->setUniform("projection",
                  ponos::transpose(camera->getProjectionTransform().matrix()));
    s->setUniform("cameraPosition", camera->getPosition());
  };
  app.scene.add(obj.get());
  app.run();
  return 0;
}
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;
}
示例#21
0
void Scene::createPolyhedronNode()
{
    _pgeode = new osg::Geode;
    _pgeode->setDataVariance(osg::Object::DYNAMIC);

    osg::Vec3f lightDir(0.0f, 0.0f, 1.0f);
    lightDir.normalize();

    auto stateSet = _pgeode->getOrCreateStateSet();
    stateSet->setAttributeAndModes(_twoSidedProgram, osg::StateAttribute::ON);
    stateSet->addUniform(new osg::Uniform("ecLightDirection", lightDir));
    stateSet->addUniform(new osg::Uniform("lightColor", osg::Vec3(1.0f, 1.0f, 1.0f)));

    _pgeometry = new osgKaleido::PolyhedronGeometry("#27");
    _pgeometry->setUseDisplayList(false);
    _pgeometry->setUseVertexBufferObjects(true);

    _pgeode->addDrawable(_pgeometry);

    addChild(_pgeode);
}
示例#22
0
    void initShader(Vec3 &pos, Mat4 &perspective, Mat4 &cameraTranslation, Mat4 &cameraRotation)
    {

      BasicShader::initShader();

      addVertexShader("../../shaders/simple_v.glsl");
      addFragmentShader("../../shaders/simple_f.glsl");

      linkShader();

      addUniform(std::string("transform"));
      addUniform(std::string("perspective"));
      addUniform(std::string("camera"));
      addUniform(std::string("cameraRotation"));

      //addUniform(std::string("model_col"));

      perspective_ = &perspective;
      cameraTranslation_ = &cameraTranslation;
      cameraRotation_ = &cameraRotation;
      eyePos_ = pos;

    }
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;
}
// FOR NOW THIS HAS THE FOLLOWING LIMITATIONS:
//		- Blocks can only be lighting related (easily fixable) << Quickly
//		- There's no explicit support to arrays.
// FIX ASAP
void ShaderProgram::fillUniformTable(){
	for(unsigned int i=0; i<m_shaders.size(); i++){
		std::string currSource = m_shaders.at(i).getSource();
		std::string line,s, type;
		std::istringstream sourceStream(currSource);
		while(std::getline(sourceStream,line)){
			std::istringstream iss(line);
			iss >> s;
			if(s=="layout(std140)"){
				iss >> s;	// skip keyword "uniform"
				iss >> s;
				m_lightUBO = glGetUniformBlockIndex(m_ID, s.c_str());
				glUniformBlockBinding(m_ID, m_lightUBO, LIGHT_UBO_BINDING_POINT);
			} else if(s=="uniform"){
				iss >> type; // skip type
				iss >> s;
				s = s.substr(0, s.size()-1); // Remove ;
				addUniform(s);	
			}
示例#25
0
Program::Program(const char* vertex, const char* fragment) {
    mInitialized = false;

    vertexShader = buildShader(vertex, GL_VERTEX_SHADER);
    if (vertexShader) {

        fragmentShader = buildShader(fragment, GL_FRAGMENT_SHADER);
        if (fragmentShader) {

            id = glCreateProgram();
            glAttachShader(id, vertexShader);
            glAttachShader(id, fragmentShader);
            glLinkProgram(id);

            GLint status;
            glGetProgramiv(id, GL_LINK_STATUS, &status);
            if (status != GL_TRUE) {
                LOGE("Error while linking shaders:");
                GLint infoLen = 0;
                glGetProgramiv(id, GL_INFO_LOG_LENGTH, &infoLen);
                if (infoLen > 1) {
                    GLchar log[infoLen];
                    glGetProgramInfoLog(id, infoLen, 0, &log[0]);
                    LOGE("%s", log);
                }
                glDeleteShader(vertexShader);
                glDeleteShader(fragmentShader);
                glDeleteProgram(id);
            } else {
                mInitialized = true;
            }
        }
    }

    mUse = false;

    if (mInitialized) {
        position = addAttrib("position");
        transform = addUniform("transform");
    }
}
示例#26
0
void CGLSLProgram::loadUniformVariables(){

	GLenum uniformVariableType;
	GLint uniformMaxLength, numberOfUniforms, uniformVariableSize;

	glGetProgramiv(mProgram, GL_ACTIVE_UNIFORMS, &numberOfUniforms);
	glGetProgramiv(mProgram, GL_ACTIVE_UNIFORM_MAX_LENGTH, &uniformMaxLength);

	GLchar *uniformName = new GLchar[uniformMaxLength];

	printf("\nActive Uniforms\n---------------------------------------------\nID  -  Name  -  Type\n\n");

	for (int k = 0; k < numberOfUniforms; ++k){

		glGetActiveUniform(mProgram, k, uniformMaxLength + 1, NULL, &uniformVariableSize, &uniformVariableType, uniformName);
		addUniform(uniformName);
		printf("%d | %s (%s)\n", mUniformsList[uniformName], uniformName, getTypeString(uniformVariableType).c_str());

	}

	printf("\n---------------------------------------------\n");

}
示例#27
0
TEST(OsgMaterialTests, AccessibleUniformTest)
{
	auto material = std::make_shared<OsgMaterial>("material");

	std::string uniform1Name = "ossFloatUniform";
	auto uniform1 = std::make_shared<OsgUniform<float>>(uniform1Name);


	std::string uniform2Name = "ossVector2fUniform";
	auto uniform2 = std::make_shared<OsgUniform<Vector2f>>(uniform2Name);

	material->addUniform(uniform1);
	material->addUniform(uniform2);

	material->setValue(uniform1Name, 2.0f);

	EXPECT_FLOAT_EQ(2.0, uniform1->get());

	uniform1->set(4.0f);
	EXPECT_FLOAT_EQ(4.0f, material->getValue<float>(uniform1Name));

	Vector2f vector1(1.0f, 2.0f);
	Vector2f vector2(3.0f, 4.0f);

	material->setValue(uniform2Name, vector1);

	EXPECT_TRUE(vector1.isApprox(uniform2->get()));

	uniform2->set(vector2);
	EXPECT_TRUE(vector2.isApprox(material->getValue<Vector2f>(uniform2Name)));

	material->removeUniform(uniform1);

	EXPECT_ANY_THROW(material->setValue(uniform1Name, 1.0f));

}
示例#28
0
ShadowDepthShader::ShadowDepthShader() : Shader("shadow_depth_vert.glsl", "shadow_depth_frag.glsl") {
	addUniform("worldToProjectionMatrix");
	addUniform("modelToWorldMatrix");
}
Material::Material( Program *program, Texture *texture ) : program( program ), texture( texture )
{
    uniforms = program->uniforms;

    addUniform( new GLUniform( "tex", TEXTURE, texture ) );
}
示例#30
0
void Shader::ShaderCode::load(ifstream &ShaderStream)
{
	string Line = "";
	if (ShaderStream.is_open())
	{
		while (getline(ShaderStream, Line))
		{
			if (ShaderStream.eof() || ShaderStream.bad())
				break;
			_code += Line + "\n";
		}
	}
	else
	{
		LOG << string(_path) + " wasn't open :/\n";
		return;
	}

	//Analyze Code
	try {
		//get Structures
		smatch _structs, _vars;

		regex structRegex = regex("struct .*?\\n?\\{\\n(.*?;\\n)*\\};");
		auto StructBegin = std::sregex_iterator(_code.begin(), _code.end(), structRegex);

		unsigned int _counter(0);
		for (auto i = StructBegin; i != std::sregex_iterator(); i++) {
			std::string temp = (*i).str();
			vector<string> structVar = vector<string>();
			regex_search(temp, _vars, regex("struct .*?\\n\\{\\n"));
			temp = _vars[0].str();
			structVar.push_back(temp.substr(7, temp.size() - 10));//adds name
			temp = (*i).str();

			regex structVarRegex = regex("\\t.*? .*?;\\n");
			auto StructVarBegin = std::sregex_iterator(temp.begin(), temp.end(), structVarRegex);

			for (std::sregex_iterator i = StructVarBegin; i != std::sregex_iterator(); ++i) {
				std::string match_str = (*i).str();
				structVar.push_back(match_str.substr(1, match_str.size() - 3)); //write the variables
			}
			structVariables.push_back(structVar);
			_counter++;
		}
		LOG << string(_path) + " contains " + to_string(_counter) + " Structures\n";

		//read uniforms
		_counter = 0;
		regex structVarRegex = regex("uniform .*? .*?;\\n");
		auto UniformsBegin = std::sregex_iterator(_code.begin(), _code.end(), structVarRegex);
		for (auto i = UniformsBegin; i != std::sregex_iterator(); i++) {
			std::string match_str = (*i).str();
			addUniform(match_str.substr(match_str.find_first_of(' ') + 1, match_str.size() - 3 - match_str.find_first_of(' ')));
			_counter++;
		}
		LOG << string(_path) + " contains " + to_string(_counter) + " Uniforms\n";
	}
	catch (regex_error &e)
	{
		LOG << string(e.what()) + "\n";
		LOG << "Could not Resolve Uniforms in Shader \n";
	}

}