/***************************************************************************
 keyboard
 ****************************************************************************/
void keyboard(unsigned char key, int x, int y)
{
    if(key == 'm'){
        drawmode++;
        drawmode = drawmode % MAX_DRAW_MODES;
    }
    else if(key == 's'){
        shademode++;
        shademode = shademode % MAX_SHADE_MODES;
        setShader();
    }
    callback_display();
    return;
}
Exemplo n.º 2
0
    void STDRenderer::preDrawBatch()
    {
        ShaderProgram* prog = _uberShader->getShaderProgram(_shaderFlags)->program;
        setShader(prog);


        _uberShader->apply(_driver, _base, _alpha);

        UberShaderProgramBase::ShaderUniformsCallback cb = _uberShader->getShaderUniformsCallback();
        if (cb)
        {
            cb(_driver, prog);
        }
    }
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;
}
Exemplo n.º 4
0
StereoMultipass::StereoMultipass(osg::TextureRectangle *left_tex,
								 osg::TextureRectangle *right_tex,
								 int width, int height,
								 int min_disparity, int max_disparity, int window_size) :
    _TextureWidth(width),
    _TextureHeight(height)
{
    _RootGroup = new osg::Group;

    createOutputTextures();

    _Camera = new osg::Camera;
    setupCamera();
    _Camera->addChild(createTexturedQuad().get());

    _RootGroup->addChild(_Camera.get());

    setShader("shaders/stereomatch_clear.frag");

    flip=1;
    flop=0;
	// we can do 16 differences in one pass,
	// but we must ping-pong the aggregate textures between passes
	// add passes until we cover the disparity range
	for (int i=min_disparity; i<=max_disparity; i+=16) {
		SubtractPass *subp = new SubtractPass(left_tex, right_tex,
											  width, height,
											  i);
		AggregatePass *aggp = new AggregatePass(subp->getOutputTexture(0).get(),
												subp->getOutputTexture(1).get(),
												subp->getOutputTexture(2).get(),
												subp->getOutputTexture(3).get(),
												_OutTexture[flip].get(),
												_OutTexture[flop].get(),
												width, height,
												i, window_size);

		_RootGroup->addChild(subp->getRoot().get());
		_RootGroup->addChild(aggp->getRoot().get());
		flip = flip ? 0 : 1;
		flop = flop ? 0 : 1;
    }
    // add select pass
    _SelectPass = new SelectPass(_OutTexture[flip].get(),
								 width, height,
								 min_disparity, max_disparity);
    _RootGroup->addChild(_SelectPass->getRoot().get());
}
Exemplo n.º 5
0
    void STDRenderer::preDrawBatch()
    {
        ShaderProgram* prog = _uberShader->getShaderProgram(_shaderFlags)->program;
        setShader(prog);

        _driver->setTexture(UberShaderProgram::SAMPLER_BASE, _base);

        if (_alpha)
            _driver->setTexture(UberShaderProgram::SAMPLER_ALPHA, _alpha);

        UberShaderProgramBase::ShaderUniformsCallback cb = _uberShader->getShaderUniformsCallback();
        if (cb)
        {
            cb(_driver, prog);
        }
    }
Exemplo n.º 6
0
void Material::unload(void)
{
	clearUniforms();
	setShader(nullptr);

	ResourceManagerBase* texture_manager = m_resource_manager.get(ResourceManager::TEXTURE);
	for (int i = 0; i < m_texture_count; i++)
	{
		if (m_textures[i])
		{
			removeDependency(*m_textures[i]);
			texture_manager->unload(*m_textures[i]);
		}
	}
	m_texture_count = 0;
}
Exemplo n.º 7
0
 void
 Material::initShader() {
     AC_DEBUG << "Material initShader "<<(void*)this;
     if (vertexShader_.empty() || fragmentShader_.empty()) {
         setShader();
     }
     shaderProgram_ = createProgram(vertexShader_, fragmentShader_);
     if (!shaderProgram_) {
         AC_ERROR << "Could not create program.";
         throw ShaderCreationException("problems during shader program creation of " + vertexShader_ + " or/and " + fragmentShader_, PLUS_FILE_LINE);
     }
     bindAttributes();
     setHandles();
     glLinkProgram(shaderProgram_);
     ASSERT_GL("glLinkProgram", PLUS_FILE_LINE);
 }
Exemplo n.º 8
0
 void MaskImageWidget::setPropertyOverride(const std::string& _key, const std::string& _value) {
     if (_key == "Shader") {
         size_t delim_pos = _value.find(';');
         if (delim_pos!=_value.npos) {
             sb::string vert = _value.substr(0,delim_pos);
             sb::string frag = _value.substr(delim_pos+1);
             setShader(RenderManager::getInstance().resources()->GetShader(vert.c_str(), frag.c_str()));
         }
     }
     else
     {
         Base::setPropertyOverride(_key, _value);
         return;
     }
     
     eventChangeProperty(this, _key, _value);
 }
Exemplo n.º 9
0
	void display()
	{
		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
		glMatrixMode(GL_MODELVIEW);
		glLoadIdentity();
		gluLookAt(0.0, 0.0, 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
		setShader();
		setShaderVariables(bubbleShaderProg);
		switch (mode) {
			case BUBBLE_MODE:
				glClearColor(0.0f, 0.15f, 0.25f, 0.0f);
				for(int i = 0; i < NUM_BUBBLES; i++) {
					bubbles[i].draw();
				}
				break;
		}
		glFlush();
	}
Exemplo n.º 10
0
void Renderer::drawHud()
{
	if(!setShader(SHADER_ALLEGRO))
		NBT_Debug("failed to set allegro shader");

	//al_use_shader(nullptr);
	//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
	//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);

	//int dw = al_get_display_width(dpy_);
   //int dh = al_get_display_height(dpy_);

	/*ALLEGRO_TRANSFORM trans;
	al_identity_transform(&trans);
	al_orthographic_transform(&trans, 0, 0, -1, dw, dh, 1);
	al_set_projection_transform(dpy_, &trans);
	al_identity_transform(&trans);
	al_use_transform(&trans);
	*/

	if(!resManager_->getAtlas()->getSheet(0)->alBitmap())
		NBT_Debug("no sheet bitmap????");

	//al_use_shader(nullptr);section_y
	ALLEGRO_BITMAP *tex = resManager_->getAtlas()->getSheet(0)->alBitmap();
	//glActiveTexture(GL_TEXTURE0);
	//glBindTexture(GL_TEXTURE_2D, al_get_opengl_texture(tex));
	//al_set_shader_sampler("al_tex", tex, 0);
	al_draw_bitmap(tex, 0, 0, 0);

	float x = 0.0, y = 0.0;
	al_transform_coordinates(&camera_transform_, &x, &y);

	Vector3D world_pos;


	al_draw_textf(fnt_, al_map_rgb(0,0,0), 4, al_get_display_height(dpy_)-12, 0, "Pos: x:%.0f, y:%.0f, z:%.0f", camera_pos_.x, camera_pos_.y, camera_pos_.z);

//	al_draw_textf(fnt_, al_map_rgb(0,0,0), 4, al_get_display_height(dpy_)-24, 0, "WP: %.0f %.0f %.0f", world_pos.x, world_pos.y, world_pos.z);
	//al_draw_textf(fnt_, al_map_rgb(0,0,0), 4, al_get_display_height(dpy_)-24, 0, "Mat: x0:%.0f x1:%.0f x2:%.0f x3:%.0f z0:%.0f z1:%.0f z2:%.0f z3:%.0f",
	//				  world.m[0][0], world.m[1][0], world.m[2][0], world.m[3][0],
	//				  world.m[2][2], world.m[2][2], world.m[2][2], world.m[3][2]);
	//al_draw_textf(fnt_, al_map_rgb(0,0,0), 4, al_get_display_height(dpy_)-12, 0, "Pos: x:%.0f y:%.0f z:%.0f", camera_pos_.getX(), camera_pos_.getY(), camera_pos_.getZ());
}
Exemplo n.º 11
0
void shader_object::init_from_file(const char* vsfile, const char* fsfile)
{
    //fprintf(stderr, "**** %s:%s() ****\n", __FILE__, __func__);

    char *vs = textFileRead(vsfile);
    char *fs = textFileRead(fsfile);
	
    if(vs==0 || fs==0){
        fprintf(stderr, "no shader source available\n");
        exit(0);
    }

    const char * vv = vs;
    const char * ff = fs;
	
    setShader(vv, ff);
	
    free(vs);
    free(fs);
}
Exemplo n.º 12
0
SelectPass::SelectPass(osg::TextureRectangle *in_tex,
					   int width, int height,
					   int min_disparity, int max_disparity) :
    _TextureWidth(width),
    _TextureHeight(height),
    _MinDisparity(min_disparity),
    _MaxDisparity(max_disparity)
{
    _RootGroup = new osg::Group;
    _InTexture = in_tex;

    createOutputTextures();

    _Camera = new osg::Camera;
    setupCamera();
    _Camera->addChild(createTexturedQuad().get());

    _RootGroup->addChild(_Camera.get());

    setShader("shaders/stereomatch_select.frag");
}
Exemplo n.º 13
0
SubtractPass::SubtractPass(osg::TextureRectangle *left_tex,
						   osg::TextureRectangle *right_tex,
						   int width, int height,
						   int start_disparity) :
    _TextureWidth(width),
    _TextureHeight(height),
    _StartDisparity(start_disparity)
{
    _RootGroup = new osg::Group;
    _InTextureLeft = left_tex;
    _InTextureRight = right_tex;

    createOutputTextures();

    _Camera = new osg::Camera;
    setupCamera();
    _Camera->addChild(createTexturedQuad().get());

    _RootGroup->addChild(_Camera.get());

    setShader("shaders/stereomatch_subtract.frag");
}
Exemplo n.º 14
0
void Material::setShader( MaterialShaderVariant::Type variant )
{
	switch( variant )
	{
		case MaterialShaderVariant::BLOBBING:
			setShader( MaterialQuality::LOW, data()->shaderName(MaterialQuality::LOW)+".blobbing" );
			setShader( MaterialQuality::MEDIUM, data()->shaderName(MaterialQuality::MEDIUM)+".blobbing" );
			setShader( MaterialQuality::HIGH, data()->shaderName(MaterialQuality::HIGH)+".blobbing" );
			break;
		default:
		case MaterialShaderVariant::DEFAULT:
			setShader( MaterialQuality::LOW, data()->shaderName(MaterialQuality::LOW)+".default" );
			setShader( MaterialQuality::MEDIUM, data()->shaderName(MaterialQuality::MEDIUM)+".default" );
			setShader( MaterialQuality::HIGH, data()->shaderName(MaterialQuality::HIGH)+".default" );
			break;
	}
}
Exemplo n.º 15
0
  Cube::Cube()
  {
    for (GLuint i = 0; i < sizeof(vertices) / sizeof(GLfloat); i += 6) {
      Vertex vert;
      glm::vec3 v;
      v.x = vertices[i];
      v.y = vertices[i + 1];
      v.z = vertices[i + 2];
      vert.Position = v;

      v.x = vertices[i + 3];
      v.y = vertices[i + 4];
      v.z = vertices[i + 5];
      vert.Normal = v;

      glm::vec2 t(0.0f, 0.0f);
      vert.TexCoords = t;
      vertices_.push_back(vert);
    }

    setShader(Shader("Shaders/phong.vert", "Shaders/phong.frag"));
    setPosition(glm::vec3(0.0f, 0.0f, 0.0f));
  }
Exemplo n.º 16
0
void shader_object::init_from_file(const char* vsfile, const char* fsfile, 
                                   const char* gsfile, GLuint itype, GLuint otype,
                                   GLint osize)
{
    char *vs = textFileRead(vsfile);
    char *fs = textFileRead(fsfile);
    char *gs = textFileRead(gsfile);
	
    if(vs==0 || fs==0 || gs==0){
        fprintf(stderr, "no shader source available\n");
        exit(0);
    }

    const char * vv = vs;
    const char * ff = fs;
    const char * gg = gs;
	
    setShader(vv, ff, gg, itype, otype, osize);
	
    free(vs);
    free(fs);
    free(gs);
}
Exemplo n.º 17
0
Material::Material( GLWidget * glWidget, QString name, MaterialShaderVariant::Type variant ) : AResource()
{
	mGLWidget = glWidget;
	mName = name;
	mDefaultQuality = MaterialQuality::HIGH;
	mShaderSet[MaterialQuality::LOW].textureUnits.clear();
	mShaderSet[MaterialQuality::LOW].shader = 0;
	mShaderSet[MaterialQuality::LOW].blobMapUniform = -1;
	mShaderSet[MaterialQuality::LOW].cubeMapUniform = -1;
	mShaderSet[MaterialQuality::MEDIUM].textureUnits.clear();
	mShaderSet[MaterialQuality::MEDIUM].shader = 0;
	mShaderSet[MaterialQuality::MEDIUM].blobMapUniform = -1;
	mShaderSet[MaterialQuality::MEDIUM].cubeMapUniform = -1;
	mShaderSet[MaterialQuality::HIGH].textureUnits.clear();
	mShaderSet[MaterialQuality::HIGH].shader = 0;
	mShaderSet[MaterialQuality::HIGH].blobMapUniform = -1;
	mShaderSet[MaterialQuality::HIGH].cubeMapUniform = -1;
	mBlobMap = mCubeMap = -1;

	QSharedPointer<MaterialData> n( new MaterialData( glWidget, name ) );
	cache( n );

	setShader( variant );
}
Exemplo n.º 18
0
  Cube::Cube()
  {
    GLfloat vertices[] = {
    -0.5f, -0.5f, -0.5f,  0.0f, 0.0f,
     0.5f, -0.5f, -0.5f,  1.0f, 0.0f,
     0.5f,  0.5f, -0.5f,  1.0f, 1.0f,
     0.5f,  0.5f, -0.5f,  1.0f, 1.0f,
    -0.5f,  0.5f, -0.5f,  0.0f, 1.0f,
    -0.5f, -0.5f, -0.5f,  0.0f, 0.0f,

    -0.5f, -0.5f,  0.5f,  0.0f, 0.0f,
     0.5f, -0.5f,  0.5f,  1.0f, 0.0f,
     0.5f,  0.5f,  0.5f,  1.0f, 1.0f,
     0.5f,  0.5f,  0.5f,  1.0f, 1.0f,
    -0.5f,  0.5f,  0.5f,  0.0f, 1.0f,
    -0.5f, -0.5f,  0.5f,  0.0f, 0.0f,

    -0.5f,  0.5f,  0.5f,  1.0f, 0.0f,
    -0.5f,  0.5f, -0.5f,  1.0f, 1.0f,
    -0.5f, -0.5f, -0.5f,  0.0f, 1.0f,
    -0.5f, -0.5f, -0.5f,  0.0f, 1.0f,
    -0.5f, -0.5f,  0.5f,  0.0f, 0.0f,
    -0.5f,  0.5f,  0.5f,  1.0f, 0.0f,

     0.5f,  0.5f,  0.5f,  1.0f, 0.0f,
     0.5f,  0.5f, -0.5f,  1.0f, 1.0f,
     0.5f, -0.5f, -0.5f,  0.0f, 1.0f,
     0.5f, -0.5f, -0.5f,  0.0f, 1.0f,
     0.5f, -0.5f,  0.5f,  0.0f, 0.0f,
     0.5f,  0.5f,  0.5f,  1.0f, 0.0f,

    -0.5f, -0.5f, -0.5f,  0.0f, 1.0f,
     0.5f, -0.5f, -0.5f,  1.0f, 1.0f,
     0.5f, -0.5f,  0.5f,  1.0f, 0.0f,
     0.5f, -0.5f,  0.5f,  1.0f, 0.0f,
    -0.5f, -0.5f,  0.5f,  0.0f, 0.0f,
    -0.5f, -0.5f, -0.5f,  0.0f, 1.0f,

    -0.5f,  0.5f, -0.5f,  0.0f, 1.0f,
     0.5f,  0.5f, -0.5f,  1.0f, 1.0f,
     0.5f,  0.5f,  0.5f,  1.0f, 0.0f,
     0.5f,  0.5f,  0.5f,  1.0f, 0.0f,
    -0.5f,  0.5f,  0.5f,  0.0f, 0.0f,
    -0.5f,  0.5f, -0.5f,  0.0f, 1.0f
    };



    SetPosition(glm::vec3(0.0f, 0.0f, 0.0f));
    setShader( Shader("shaders/default.vs", "shaders/default.fs") );

    glGenVertexArrays(1, &VAO);
    glGenBuffers(1, &VBO);

    glBindVertexArray(VAO);

    glBindBuffer(GL_ARRAY_BUFFER, VBO);
        glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);

        glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE,
                              5 * sizeof(GLfloat), (GLvoid*)0);
        glEnableVertexAttribArray(0);

    glBindBuffer(GL_ARRAY_BUFFER, 0);

    glBindVertexArray(0);

  }
Exemplo n.º 19
0
void GFXD3D9Device::disableShaders()
{
   setShader( NULL );
   setShaderConstBuffer( NULL );
}
Exemplo n.º 20
0
 Element::Element(VertexData vertex_data, std::shared_ptr<Skin> skin, const unsigned int layer) : Renderable(vertex_data.generateVertexArrayObject(), vertex_data), skin(skin), anchor_point(glm::vec2(0.0, 0.0)), width(0), height(0), text_padding(0), cursor_within(false), color(glm::vec4(1.0)), layer(layer) {
   setShader(skin->getShader());
   addTexture(0, "skin0", skin->getTexture());
   getTransform()->translate(glm::vec3(0.0, 0.0, -(float)layer));
 }
Exemplo n.º 21
0
chaos::GameObject::GameObject(chaos::Renderer* ren, std::string vaoId, std::string shaderId)
:renderer(ren), material(glm::vec4(1, 0.1, 0.4, 1.0), glm::vec4(0,1,0,1), 32)
{
    setVertexArray(vaoId);
    setShader(shaderId);
}
Exemplo n.º 22
0
	void TextArea::updateModels()
	{
		if (!font.isValid())
		{
			return;
		}

		for (auto && model : models)
		{
			getScene()->destroyModel(model);
		}
		models.clear();
		meshes.clear();

		// A text area may use multiple textures for different code point areas. A separate model is created for each texture.
		std::map<Ptr<render::Image>, std::vector<float>> meshVertices;
		std::map<Ptr<render::Image>, std::vector<unsigned int>> meshIndices;
		Vector2i cursor {0, font->getLineHeight()};
		for (size_t i = 0; i < text.size();)
		{
			// Get the next character, move i forward.
			unsigned int c = getChar(text, i);

			if (c == '\n')
			{
				cursor[1] += font->getLineHeight();
				cursor[0] = 0;
				continue;
			}
			else if (c == '\r')
			{
				continue;
			}
			else if (c == '\t')
			{
				cursor[0] += font->getLineHeight();
				continue;
			}

			// Get the font information for the next character.
			render::Font::GlyphCoords const & glyphCoords = font->getGlyphCoordsFromChar(c);
			Ptr<render::Image> glyphImage = font->getImageFromChar(c);

			// Setup the vertice and indices for this glyph.
			Rectf glyphBounds;
			glyphBounds.min = Vector2f(cursor + glyphCoords.offset);
			glyphBounds.setSize(Vector2f(glyphCoords.uvBounds.getSize()));
			Rectf glyphUVBounds = Rectf(glyphCoords.uvBounds);
			glyphUVBounds.max += Vector2f {1, 1};
			std::vector<float> & vertices = meshVertices[glyphImage];
			int startingIndex = (int)vertices.size() / 4;
			vertices.push_back(glyphBounds.min[0]);
			vertices.push_back(glyphBounds.min[1]);
			vertices.push_back(glyphUVBounds.min[0]);
			vertices.push_back(glyphUVBounds.min[1]);
			vertices.push_back(glyphBounds.max[0]);
			vertices.push_back(glyphBounds.min[1]);
			vertices.push_back(glyphUVBounds.max[0]);
			vertices.push_back(glyphUVBounds.min[1]);
			vertices.push_back(glyphBounds.max[0]);
			vertices.push_back(glyphBounds.max[1]);
			vertices.push_back(glyphUVBounds.max[0]);
			vertices.push_back(glyphUVBounds.max[1]);
			vertices.push_back(glyphBounds.min[0]);
			vertices.push_back(glyphBounds.max[1]);
			vertices.push_back(glyphUVBounds.min[0]);
			vertices.push_back(glyphUVBounds.max[1]);
			std::vector<unsigned int> & indices = meshIndices[glyphImage];
			indices.push_back(startingIndex + 0);
			indices.push_back(startingIndex + 2);
			indices.push_back(startingIndex + 1);
			indices.push_back(startingIndex + 0);
			indices.push_back(startingIndex + 3);
			indices.push_back(startingIndex + 2);
			cursor[0] += glyphCoords.advance;
		}

		// Construct the models form the text.
		for (auto const & pair : meshVertices)
		{
			auto image = pair.first;
			auto model = getScene()->createModel();
			meshes.push_back(std::move(OwnPtr<render::Mesh>::returnNew()));
			auto & mesh = meshes.back();
			meshes.back()->setVertices(0, meshVertices[image], sizeof(float) * 4, false);
			meshes.back()->setVertexComponent(0, 2, 0, 0);
			meshes.back()->setVertexComponent(1, 2, sizeof(float) * 2, 0);
			mesh->setIndices(meshIndices[image]);
			model->setMesh(mesh);
			model->setShader(getShader());
			model->setImageAtSlot(image, 0);
			model->setUniformsFunction([this, image](Ptr<render::Shader> const & shader)
			{
				shader->setUniformValue<Vector2f>(originUniformLocation, (Vector2f)bounds.min);
				shader->setUniformValue<Vector2f>(imageSizeUniformLocation, (Vector2f)image->getSize());
				shader->setUniformValue<int>(imageUniformLocation, 0);
				shader->setUniformValue<Vector4f>(colorUniformLocation, color);
			});
			model->setDepth(depth);
			models.push_back(model);
		}
	}
Exemplo n.º 23
0
void PlatformDemoState::buildTerrain()
{
    m_shaderResource.preload(PlatformShaderId::SpecularSmooth2D, xy::Shader::NormalMapped::vertex, NORMAL_FRAGMENT_TEXTURED);
    m_textureResource.setFallbackColour({ 127, 127, 255 });
    const auto& normalTexture = m_textureResource.get("normalFallback");

    auto background = xy::Component::create<Plat::Background>(m_messageBus, m_textureResource);
    background->setAmbientColour(m_scene.getAmbientColour());
    auto entity = xy::Entity::create(m_messageBus);
    entity->addComponent(background);
    m_scene.addEntity(entity, xy::Scene::Layer::BackRear);

    auto drawable = xy::Component::create<xy::AnimatedDrawable>(m_messageBus);
    drawable->setTexture(m_textureResource.get("assets/images/platform/left_edge.png"));
    drawable->setNormalMap(normalTexture);
    drawable->setShader(m_shaderResource.get(PlatformShaderId::SpecularSmooth2D));

    entity = xy::Entity::create(m_messageBus);
    entity->addComponent(drawable);

    m_scene.addEntity(entity, xy::Scene::Layer::BackFront);
    //-------------------------
    drawable = xy::Component::create<xy::AnimatedDrawable>(m_messageBus);
    drawable->setTexture(m_textureResource.get("assets/images/platform/ground_section.png"));
    drawable->setNormalMap(normalTexture);
    drawable->setShader(m_shaderResource.get(PlatformShaderId::SpecularSmooth2D));

    entity = xy::Entity::create(m_messageBus);
    entity->setPosition(256.f, 1080.f - 128.f);
    entity->addComponent(drawable);

    m_scene.addEntity(entity, xy::Scene::Layer::BackFront);
    //-------------------------
    drawable = xy::Component::create<xy::AnimatedDrawable>(m_messageBus);
    drawable->setTexture(m_textureResource.get("assets/images/platform/ground_section.png"));
    drawable->setNormalMap(normalTexture);
    drawable->setShader(m_shaderResource.get(PlatformShaderId::SpecularSmooth2D));

    entity = xy::Entity::create(m_messageBus);
    entity->setPosition(1024.f, 1080.f - 128.f);
    entity->addComponent(drawable);

    m_scene.addEntity(entity, xy::Scene::Layer::BackFront);
    //-------------------------
    drawable = xy::Component::create<xy::AnimatedDrawable>(m_messageBus);
    drawable->setTexture(m_textureResource.get("assets/images/platform/ground_section.png"));
    drawable->setNormalMap(normalTexture);
    drawable->setShader(m_shaderResource.get(PlatformShaderId::SpecularSmooth2D));

    entity = xy::Entity::create(m_messageBus);
    entity->setPosition(1792.f, 1080.f - 128.f);
    entity->addComponent(drawable);

    m_scene.addEntity(entity, xy::Scene::Layer::BackFront);
    //-------------------------
    drawable = xy::Component::create<xy::AnimatedDrawable>(m_messageBus);
    drawable->setTexture(m_textureResource.get("assets/images/platform/right_edge.png"));
    drawable->setNormalMap(normalTexture);
    drawable->setShader(m_shaderResource.get(PlatformShaderId::SpecularSmooth2D));

    entity = xy::Entity::create(m_messageBus);
    entity->setPosition(2560.f, 0.f);
    entity->addComponent(drawable);

    m_scene.addEntity(entity, xy::Scene::Layer::BackFront);
    //-------------------------
    auto model = m_meshRenderer.createModel(MeshID::Platform, m_messageBus);
    model->rotate(xy::Model::Axis::X, 90.f);
    model->rotate(xy::Model::Axis::Z, 180.f);
    model->setPosition({ 384.f, 158.f, 0.f });
    model->setBaseMaterial(m_meshRenderer.getMaterial(MatId::Platform01));

    entity = xy::Entity::create(m_messageBus);
    entity->setPosition(400.f, 700.f);
    entity->addComponent(model);

    m_scene.addEntity(entity, xy::Scene::Layer::BackFront);
    //-------------------------
    drawable = xy::Component::create<xy::AnimatedDrawable>(m_messageBus);
    drawable->setTexture(m_textureResource.get("assets/images/platform/plat_03.png"));
    drawable->setNormalMap(normalTexture);
    drawable->setShader(m_shaderResource.get(PlatformShaderId::SpecularSmooth2D));

    entity = xy::Entity::create(m_messageBus);
    entity->setPosition(2000.f, 550.f);
    entity->addComponent(drawable);

    m_scene.addEntity(entity, xy::Scene::Layer::BackFront);
    //-------------------------
    drawable = xy::Component::create<xy::AnimatedDrawable>(m_messageBus);
    drawable->setTexture(m_textureResource.get("assets/images/platform/plat_02.png"));
    drawable->setNormalMap(normalTexture);
    drawable->setShader(m_shaderResource.get(PlatformShaderId::SpecularSmooth2D));

    entity = xy::Entity::create(m_messageBus);
    entity->setPosition(1670.f, 450.f);
    entity->addComponent(drawable);

    m_scene.addEntity(entity, xy::Scene::Layer::BackFront);
    //-------------------------

    model = m_meshRenderer.createModel(MeshID::Platform, m_messageBus);
    model->rotate(xy::Model::Axis::X, 90.f);
    model->rotate(xy::Model::Axis::Z, 180.f);
    model->setPosition({ 384.f, 158.f, 0.f });
    model->setBaseMaterial(m_meshRenderer.getMaterial(MatId::Platform04));

    entity = xy::Entity::create(m_messageBus);
    entity->setPosition(1210.f, 600.f);
    entity->addComponent(model);

    m_scene.addEntity(entity, xy::Scene::Layer::BackFront);

    //------some shadow receivers-------//
    model = m_meshRenderer.createModel(MeshID::Quad, m_messageBus);
    model->setPosition({ 0.f, 0.f, -250.f });

    entity = xy::Entity::create(m_messageBus);
    entity->setPosition(1000.f, 702.f);
    entity->addComponent(model);
    m_scene.addEntity(entity, xy::Scene::Layer::BackFront);

    model = m_meshRenderer.createModel(MeshID::Quad, m_messageBus);
    model->rotate(xy::Model::Axis::X, 90.f);

    entity = xy::Entity::create(m_messageBus);
    entity->setPosition(1000.f, 952.f);
    entity->addComponent(model);
    m_scene.addEntity(entity, xy::Scene::Layer::BackFront);
}
void Shader::setupGrayscale(){
	setShader("shaders_texture/standard.vert", "shaders_texture/grayscale.frag");
}
void Shader::setupThreshold(){
	setShader("shaders_texture/standard.vert", "shaders_texture/threshold.frag");
    addParameter("threshold", 0, 1);
}
void Shader::setupBits(){
    setShader("shaders_color/standard.vert", "shaders_color/bits.frag");
    addParameter("mult", ofVec2f(0, 0), ofVec2f(100, 10));
    addParameter("grid", ofVec2f(0, 0), ofVec2f(1, 1));
}
Exemplo n.º 27
0
FullscreenQuad::FullscreenQuad()
{
	drawMode = GL_TRIANGLE_STRIP;
	generateGeometry();
	setShader("postProcessing");
}
Exemplo n.º 28
0
void CitySceneGenerator::generate(Scene* scene) {
	auto renderer = scene->renderer();
	auto material = std::make_shared<PhongMaterial>(renderer);
	material->setShader(renderer->shaderManager()->getGlslProgram("phong"));

	PhongMaterialData materialData = { glm::vec4(0.0f, 0.1f, 0.0f, 1.0f), 
		glm::vec4(0.8f, 0.3f, 0.1f, 1.0f), glm::vec4(0.3f, 0.3f, 0.3f, 1.0f), 5.0f };

	material->properties()->setData(materialData);
	material->properties()->flushData();

	auto mesh = std::make_shared<Mesh>();
	mesh->setPrimitiveType(PrimitiveType::TriangleList);

	size_t buildingVerticesCount = sizeof(buildingVertices) / sizeof(*buildingVertices);
	std::vector<char> vertices(reinterpret_cast<const char*>(buildingVertices), 
		reinterpret_cast<const char*>(buildingVertices) + sizeof(buildingVertices));
	std::vector<VertexElement> layout = {
		VertexElement(3, VertexElementType::Float),
		VertexElement(3, VertexElementType::Float)
	};
	mesh->loadVertices(vertices, buildingVerticesCount, layout);

	size_t buildingIndicesCount = sizeof(buildingIndices) / sizeof(*buildingIndices);
	std::vector<uint32_t> indices(reinterpret_cast<const unsigned*>(buildingIndices), 
		reinterpret_cast<const unsigned*>(buildingIndices) + buildingIndicesCount);
	mesh->loadIndices(indices);

	size_t numBuildings = 1000;
	float citySize = 500.0f;
	float minBuildingSize = 10.0f;
	float maxBuildingSize = 60.0f;
	float minHeightToWidthRatio = 8.0f;
	float maxHeightToWidthRatio = 16.0f;

	std::uniform_real_distribution<float> angleDist(0.0f, 360.0f);
	std::uniform_real_distribution<float> positionDist(-citySize, citySize);
	std::uniform_real_distribution<float> canonicalDist;

	std::vector<std::shared_ptr<BaseSceneObject>> buildings;
	for (size_t i = 0; i < numBuildings; i++) {
		auto building = std::make_shared<Building>(mesh, material);

		// set random position
		glm::mat4 model = glm::translate(glm::mat4(1.0f),
			glm::vec3(positionDist(m_rng), positionDist(m_rng), 0.0f)
		);

		// rotate around z with random angle
		model = glm::rotate(model, angleDist(m_rng), glm::vec3(0.0f, 0.0f, 1.0f));

		glm::vec3 scale;
		// multiplying uniform distribution will generate beta distribution
		scale.x = canonicalDist(m_rng) * canonicalDist(m_rng) * canonicalDist(m_rng) * canonicalDist(m_rng)
			* (maxBuildingSize - minBuildingSize) + minBuildingSize;
		scale.y = scale.x;
		scale.z = canonicalDist(m_rng) * canonicalDist(m_rng) * canonicalDist(m_rng) * scale.x
			* (maxHeightToWidthRatio - minHeightToWidthRatio) + minHeightToWidthRatio;
		model = glm::scale(model, scale);

		building->setModelMatrix(model);
		building->calculateBBox();

		buildings.push_back(building);
	}

	scene->setStaticGeometry(std::move(buildings));
}
Exemplo n.º 29
0
FullscreenQuad::FullscreenQuad(const char* name)
{
	drawMode = GL_TRIANGLE_STRIP;
	generateGeometry();
	setShader(name);
}
HardwareSkinningDemo::HardwareSkinningDemo( hkDemoEnvironment* env )
:	hkDefaultAnimationDemo(env)
{
	// Disable warnings: if no renderer									
	if( hkString::strCmp( m_env->m_options->m_renderer, "n" ) == 0 )
	{
		hkError::getInstance().setEnabled(0xf0d1e423, false); //'Could not realize an inplace texture of type PNG.'
	}

	//
	// Setup the camera
	//
	{
		hkVector4 from(  -0.92f, -1.2f, 0.63f );
		hkVector4 to  ( 0.35f,-0.35f, 0.30f );
		hkVector4 up  ( 0.0f,  0.0f, 1.0f);
		setupDefaultCameras( env, from, to, up, 0.01f, 10000.0f );
	}

	m_loader = new hkLoader();

	// We want to use this demo to do the skinning, so we don't let our graphics engine do it.

	m_canSkin = (hkgSystem::g_RendererType != hkgSystem::HKG_RENDERER_NULL); 
	if (hkgSystem::g_RendererType != hkgSystem::HKG_RENDERER_CONSOLE)
	{
		m_canSkin = m_env->m_window->shaderSupportGreaterOrEqualTo(1); // has shaders..
	}
	env->m_sceneConverter->setAllowHardwareSkinning(m_canSkin);

	// Convert the scene
	{
		hkString assetFile = hkAssetManagementUtil::getFilePath("Resources/Animation/Scene/hkScene.hkx");
		hkRootLevelContainer* container = m_loader->load( assetFile.cString() );
		HK_ASSERT2(0x27343437, container != HK_NULL , "Could not load asset");
		hkxScene* scene = reinterpret_cast<hkxScene*>( container->findObjectByType( hkxSceneClass.getName() ));

		HK_ASSERT2(0x27343635, scene, "No scene loaded");
		removeLights(m_env); // assume we have some in the file
		env->m_sceneConverter->convert( scene );
	}

	// Get the rig
	{
		hkString assetFile = hkAssetManagementUtil::getFilePath("Resources/Animation/HavokGirl/hkRig.hkx");
		hkRootLevelContainer* container = m_loader->load( assetFile.cString() );
		HK_ASSERT2(0x27343437, container != HK_NULL , "Could not load asset");
		hkaAnimationContainer* ac = reinterpret_cast<hkaAnimationContainer*>( container->findObjectByType( hkaAnimationContainerClass.getName() ));

		HK_ASSERT2(0x27343435, ac && (ac->m_numSkeletons > 0), "No skeleton loaded");
		m_skeleton = ac->m_skeletons[0];
	}

	// Get the animation and the binding
	{
		hkString assetFile = hkAssetManagementUtil::getFilePath("Resources/Animation/HavokGirl/hkIdle.hkx");
		hkRootLevelContainer* container = m_loader->load( assetFile.cString() );
		HK_ASSERT2(0x27343437, container != HK_NULL , "Could not load asset");
		hkaAnimationContainer* ac = reinterpret_cast<hkaAnimationContainer*>( container->findObjectByType( hkaAnimationContainerClass.getName() ));

		HK_ASSERT2(0x27343435, ac && (ac->m_numAnimations > 0), "No animation loaded");
		m_animation = ac->m_animations[0];

		HK_ASSERT2(0x27343435, ac && (ac->m_numBindings > 0), "No binding loaded");
		m_binding = ac->m_bindings[0];
	}

	// Convert the skin
	{

		const char* skinFile = "Resources/Animation/HavokGirl/hkLowResSkin18Bones.hkx";

		hkString assetFile = hkAssetManagementUtil::getFilePath( skinFile );
		hkRootLevelContainer* container = m_loader->load( assetFile.cString() );
		HK_ASSERT2(0x27343437, container != HK_NULL , "Could not load asset");

		hkxScene* scene = reinterpret_cast<hkxScene*>( container->findObjectByType( hkxSceneClass.getName() ));
		HK_ASSERT2(0x27343435, scene , "No scene loaded");

		hkaAnimationContainer* ac = reinterpret_cast<hkaAnimationContainer*>( container->findObjectByType( hkaAnimationContainerClass.getName() ));
		HK_ASSERT2(0x27343435, ac && (ac->m_numSkins > 0), "No skins loaded");

		m_numSkinBindings = ac->m_numSkins;
		m_skinBindings = ac->m_skins;

		// Make graphics output buffers for the skins
		env->m_sceneConverter->convert( scene );

		// If we are hardware skinning, we need to inform the graphics of the
		// mappings between the skeleton bones and the primitive subsets with
		// possibly limited palettes. Looks worse than it is as our scene converter
		// has no dependancy on the animation system, so we need to cast a bit.
		if (m_canSkin)
		{

			
			hkgShaderCollection* platformShader; 
			if (m_env->m_window->supportsShaderCompilation())
			{
				platformShader = compileShader();
			}
			else
			{
				platformShader = loadPrecompiledShader();
			}	

			for (int ms=0; ms < m_numSkinBindings; ++ms)
			{
				hkaMeshBinding* skinBinding = m_skinBindings[ms];
				if ( m_env->m_sceneConverter->setupHardwareSkin( m_env->m_window->getContext(), skinBinding->m_mesh,
						reinterpret_cast<hkgAssetConverter::IndexMapping*>( skinBinding->m_mappings ),
						skinBinding->m_numMappings, (hkInt16)skinBinding->m_skeleton->m_numBones ) )
				{
					// based on the hkxMesh will find the hkg object and set the shader in the material(s)
					setShader( skinBinding->m_mesh, platformShader );
				}
			}
			platformShader->release();


		}
	}

	// Create the skeleton
	m_skeletonInstance = new hkaAnimatedSkeleton( m_skeleton );
	{
		hkaDefaultAnimationControl* ac = new hkaDefaultAnimationControl( m_binding );

		ac->setPlaybackSpeed(1.0f);
		m_skeletonInstance->addAnimationControl( ac );
		ac->removeReference();
	}

	// set up the vdb
	setupGraphics();

}