Beispiel #1
0
	template <typename R> void call(R *r) {
		const auto &view = r->getViewMatrix();
		const auto &projection = r->getProjectionMatrix();
		for (auto &con : r->getScenario().getWorld().cellCellConnections) {
			auto &cc = *(con.second.get());
			if (cc.adhCoef > 0) {
				shader.bind();
				cube.vao.bind();
				QColor color = QColor::fromHsvF(cc.adhCoef * 0.45, 0.7, 0.7);
				shader.setUniformValue(shader.uniformLocation("color"), color);
				shader.setUniformValue(shader.uniformLocation("projection"), projection);
				shader.setUniformValue(shader.uniformLocation("view"), view);
				QMatrix4x4 model;
				auto ab = toQV3D(cc.cells.second->getPosition() - cc.cells.first->getPosition());
				model.translate(toQV3D(cc.cells.second->getPosition()) - ab * 0.5);
				auto dp = ab.normalized().x();
				if (dp != 1 && dp != -1) {
					model.rotate(acos(dp) * 180.0 / M_PI,
					             QVector3D::crossProduct(QVector3D(1, 0, 0), ab));
					model.scale(ab.length() * 0.5, 1.0, 1.0);
					QMatrix4x4 nmatrix = (model).inverted().transposed();
					shader.setUniformValue(shader.uniformLocation("model"), model);
					shader.setUniformValue(shader.uniformLocation("normalMatrix"), nmatrix);
					GL->glDrawElements(GL_TRIANGLES, cube.indices.size(), GL_UNSIGNED_INT, 0);
				}
				cube.vao.release();
				shader.release();
			}
		}
	}
Beispiel #2
0
	template <typename R> void call(R *r) {
		const auto &view = r->getViewMatrix();
		const auto &projection = r->getProjectionMatrix();
		shader.bind();
		sphere.vao.bind();
		texture->bind(0);
		shader.setUniformValue(shader.uniformLocation("projection"), projection);
		shader.setUniformValue(shader.uniformLocation("view"), view);
		for (auto &n : r->getScenario().nutrientSources) {
			QMatrix4x4 model;
			model.translate(n.pos.x(), n.pos.y(), n.pos.z());
			double c = n.content / n.initialcontent;
			double l = 15.0 + sqrt(n.sqradius * c) * 0.05;
			model.scale(l, l, l);
			QMatrix4x4 nmatrix = (model).inverted().transposed();
			shader.setUniformValue(shader.uniformLocation("model"), model);
			shader.setUniformValue(shader.uniformLocation("normalMatrix"), nmatrix);
			auto hsv = QColor::fromHsvF(c * 0.35, 0.9, 0.9);
			QVector4D col(hsv.redF(), hsv.greenF(), hsv.blueF(), 0.5);
			std::cerr << "c = " << c << ", r = " << col.x() << std::endl;
			shader.setUniformValue(shader.uniformLocation("color"), col);
			GL->glDrawElements(GL_TRIANGLES, sphere.indices.size(), GL_UNSIGNED_INT, 0);
		}
		sphere.vao.release();
		shader.release();
	}
void QQuickShapeConicalGradientShader::initialize()
{
    QOpenGLShaderProgram *prog = program();
    m_opacityLoc = prog->uniformLocation("opacity");
    m_matrixLoc = prog->uniformLocation("matrix");
    m_angleLoc = prog->uniformLocation("angle");
    m_translationPointLoc = prog->uniformLocation("translationPoint");
}
Beispiel #4
0
//! [4]
void TriangleWindow::initialize()
{
    m_program = new QOpenGLShaderProgram(this);
    m_program->addShaderFromSourceCode(QOpenGLShader::Vertex, vertexShaderSource);
    m_program->addShaderFromSourceCode(QOpenGLShader::Fragment, fragmentShaderSource);
    m_program->link();
    m_posAttr = m_program->attributeLocation("posAttr");
    m_colAttr = m_program->attributeLocation("colAttr");
    m_matrixUniform = m_program->uniformLocation("matrix");
}
Beispiel #5
0
void OpenGLWidgetPrivate::initialize()
{
    initializeOpenGLFunctions();
    m_program = new QOpenGLShaderProgram;
    m_program->addShaderFromSourceCode(QOpenGLShader::Vertex, vertexShaderSource);
    m_program->addShaderFromSourceCode(QOpenGLShader::Fragment, fragmentShaderSource);
    m_program->link();
    m_posAttr = m_program->attributeLocation("posAttr");
    m_colAttr = m_program->attributeLocation("colAttr");
    m_matrixUniform = m_program->uniformLocation("matrix");
}
void QQuickShapeRadialGradientShader::initialize()
{
    QOpenGLShaderProgram *prog = program();
    m_opacityLoc = prog->uniformLocation("opacity");
    m_matrixLoc = prog->uniformLocation("matrix");
    m_translationPointLoc = prog->uniformLocation("translationPoint");
    m_focalToCenterLoc = prog->uniformLocation("focalToCenter");
    m_centerRadiusLoc = prog->uniformLocation("centerRadius");
    m_focalRadiusLoc = prog->uniformLocation("focalRadius");
}
void SeaNode::draw(std::stack<QMatrix4x4> &MVStack, QMatrix4x4 cameraMatrix, QMatrix4x4 projectionMatrix, QOpenGLShaderProgram *shader) {
	QOpenGLShaderProgram *sh = Shaders::waterGeometryProgram;
	MVStack.push(MVStack.top());

	MVStack.top().translate(this->translation);

	//Convert the quat to a matrix, may be a performance leak.
	QMatrix4x4 tempRot;
	tempRot.rotate(this->rotation.normalized());
	MVStack.top() *= tempRot;

	//If the node is a leaf, draw its contents
	if(leaf) {
		Shaders::bind(sh);
		glUniformMatrix4fv(sh->uniformLocation("modelViewMatrix"), 1, GL_FALSE, MVStack.top().constData());
		glUniformMatrix4fv(sh->uniformLocation("cameraInverseMatrix"), 1, GL_FALSE, cameraMatrix.inverted().constData());
		glUniformMatrix4fv(sh->uniformLocation("perspectiveMatrix"), 1, GL_FALSE, projectionMatrix.constData());
		glUniformMatrix4fv(sh->uniformLocation("normalMatrix"), 1, GL_FALSE, MVStack.top().inverted().transposed().constData());
		int r = (id & 0x000000FF) >>  0;
		int g = (id & 0x0000FF00) >>  8;
		int b = (id & 0x00FF0000) >> 16;
		glUniform4f(sh->uniformLocation("id"), r/255.0f, g/255.0f, b/255.0f, 1.0f);

		glUniform4fv(sh->uniformLocation("color"), 1, color);

		struct timeval start;
		gettimeofday(&start, NULL);
		float seconds = ((start.tv_sec % (int) periodicity) + start.tv_usec / 1000000.0) / (periodicity / 4);

		glActiveTexture(GL_TEXTURE5);
		glBindTexture(GL_TEXTURE_3D, noiseTexture);
		//glUniform1i(sh->uniformLocation("noiseTexture"), 5);

		glUniform1i(sh->uniformLocation("seaWidth"), seaWidth);
		glUniform1i(sh->uniformLocation("seaHeight"), seaHeight);
		glUniform1f(sh->uniformLocation("time"), seconds);

		this->primitive->draw();
		Shaders::release(sh);
	} else {
SeaNode::SeaNode(Primitive *p, std::string name)
	: SceneGraph(p, name)
{
	seaWidth = 256;
	seaHeight = 256;
	periodicity = 512;
	//Create noise texture
	float frequency = 1.0 / pow(2.0, 5);
	noiseData = new GLfloat[seaWidth * seaHeight * (int) periodicity];
	for(int z = 0; z < (int) periodicity; z++) {
		for(int y = 0; y < seaHeight; y++) {
			for(int x = 0; x < seaWidth; x++) {
				noiseData[z * (seaWidth * seaHeight) + y * seaWidth + x] = scaled_raw_noise_3d(0.0, 1.0, x * frequency, y * frequency, z * frequency);
			}
		}
	}

	glGenTextures(1, &noiseTexture);

	glActiveTexture(GL_TEXTURE0);
	glBindTexture(GL_TEXTURE_3D, noiseTexture);
	glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_S, GL_REPEAT);
	glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_T, GL_REPEAT);
	glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_R, GL_MIRRORED_REPEAT);
	glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
	glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
	glTexImage3D(GL_TEXTURE_3D, 0, GL_R16, seaWidth, seaHeight, periodicity, 0, GL_RED, GL_FLOAT, (void*) noiseData);
	glBindTexture(GL_TEXTURE_3D, 0);

	QOpenGLShaderProgram *sh = Shaders::waterGeometryProgram;
	Shaders::bind(sh);
	glActiveTexture(GL_TEXTURE5);
	glBindTexture(GL_TEXTURE_3D, noiseTexture);
	glUniform1i(sh->uniformLocation("noiseTexture"), 5);
	Shaders::release(sh);
}
Beispiel #9
0
	template <typename R> void call(R *r) {
		const auto &view = r->getViewMatrix();
		const auto &projection = r->getProjectionMatrix();
		const float l = 100000.0f;
		shader.bind();
		quad.vao.bind();
		texture->bind(0);
		GL->glActiveTexture(GL_TEXTURE0);
		GL->glBindTexture(GL_TEXTURE_2D, texture->textureId());
		shader.setUniformValue(shader.uniformLocation("tex"), 0);
		shader.setUniformValue(shader.uniformLocation("projection"), projection);
		shader.setUniformValue(shader.uniformLocation("view"), view);
		shader.setUniformValue(shader.uniformLocation("texrepeat"), 300.0f);
		shader.setUniformValue(shader.uniformLocation("alpha"), 0.8f);
		QMatrix4x4 model;
		model.rotate(90.0f, QVector3D(1, 0, 0));
		model.translate(QVector3D(0, 0, 0));
		model.scale(l, l, l);
		shader.setUniformValue(shader.uniformLocation("model"), model);
		GL->glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
		quad.vao.release();
		shader.release();
	}
Beispiel #10
0
	template <typename R> void call(R *r) {
		using V = decltype(declval<typename R::Cell>().getPosition());
		const auto &view = r->getViewMatrix();
		const auto &projection = r->getProjectionMatrix();
		shader.bind();
		disk.vao.bind();
		QVector4D color(0.9f, 0.9f, 0.05f, 1.0f);
		shader.setUniformValue(shader.uniformLocation("color"), color);
		shader.setUniformValue(shader.uniformLocation("projection"), projection);
		shader.setUniformValue(shader.uniformLocation("view"), view);
		for (auto &con : r->getScenario().getWorld().cellCellConnections) {
			auto &cc = con.second;
			QMatrix4x4 model;
			model.translate(
			    toQV3D(cc.cells.first->getPosition() + cc.normal * cc.midpoint.first));
			auto rot = V::getRotation(V(0, 0, 1), cc.normal);
			model.rotate(rot.teta * 180.0 / M_PI, toQV3D(rot.n));
			float rad = static_cast<float>(sqrt(cc.sqradius));
			model.scale(rad, rad, rad);
			QMatrix4x4 nmatrix = (model).inverted().transposed();
			shader.setUniformValue(shader.uniformLocation("model"), model);
			shader.setUniformValue(shader.uniformLocation("normalMatrix"), nmatrix);
			GL->glDrawElements(GL_TRIANGLES, disk.indices.size(), GL_UNSIGNED_INT, 0);
		}
		color = QVector4D(0.1f, 0.7f, 0.f, 1.0f);
		shader.setUniformValue(shader.uniformLocation("color"), color);
		for (auto &con : r->getScenario().getWorld().cellCellConnections) {
			auto &cc = con.second;
			QMatrix4x4 model;
			model.translate(toQV3D(cc.cells.first->getPosition() +
			                       cc.icb.first.currentBasis.X * cc.midpoint.first));
			auto rot = V::getRotation(V(0, 0, 1), cc.icb.first.currentBasis.X);
			model.rotate(rot.teta * 180.0 / M_PI, toQV3D(rot.n));
			float rad = static_cast<float>(sqrt(cc.sqradius));
			model.scale(rad, rad, rad);
			QMatrix4x4 nmatrix = (model).inverted().transposed();
			shader.setUniformValue(shader.uniformLocation("model"), model);
			shader.setUniformValue(shader.uniformLocation("normalMatrix"), nmatrix);
			GL->glDrawElements(GL_TRIANGLES, disk.indices.size(), GL_UNSIGNED_INT, 0);
		}
		color = QVector4D(0.f, 0.1f, 0.7f, 1.0f);
		shader.setUniformValue(shader.uniformLocation("color"), color);
		for (auto &con : r->getScenario().getWorld().cellCellConnections) {
			auto &cc = con.second;
			QMatrix4x4 model;
			model.translate(toQV3D(cc.cells.second->getPosition() +
			                       cc.icb.second.currentBasis.X * cc.midpoint.second));
			auto rot = V::getRotation(V(0, 0, 1), cc.icb.second.currentBasis.X);
			model.rotate(rot.teta * 180.0 / M_PI, toQV3D(rot.n));
			float rad = static_cast<float>(sqrt(cc.sqradius));
			model.scale(rad, rad, rad);
			QMatrix4x4 nmatrix = (model).inverted().transposed();
			shader.setUniformValue(shader.uniformLocation("model"), model);
			shader.setUniformValue(shader.uniformLocation("normalMatrix"), nmatrix);
			GL->glDrawElements(GL_TRIANGLES, disk.indices.size(), GL_UNSIGNED_INT, 0);
		}
		disk.vao.release();
		shader.release();
	}