コード例 #1
0
void Box::initTopBottomBack(){

	GLuint VBO;
	GLuint CBO;
	GLuint IBO;

	glGenVertexArrays (1, &vertexArrayObjectFBTB);
	glBindVertexArray(vertexArrayObjectFBTB);

	vec3 v0 = vec3(-width/2, width/2, width/2);
	vec3 v1 = vec3(width/2, width/2, width/2);
	vec3 v2 = vec3(-width/2, -width/2, width/2);
	vec3 v3 = vec3(width/2, -width/2, width/2);
	
	vec3 v4 = vec3(-width/2, width/2, -width/2);
	vec3 v5 = vec3(width/2, width/2, -width/2);
	vec3 v6 = vec3(-width/2, -width/2, -width/2);
	vec3 v7 = vec3(width/2, -width/2, -width/2);

	vector<pntVertexData> v;

	vec2 t0 = vec2(0,1);
	vec2 t1 = vec2(1,1);
	vec2 t2 = vec2(0,0);
	vec2 t3 = vec2(1,0);

	vec2 t6 = vec2(0,1);
	vec2 t7 = vec2(1,1);
	vec2 t4 = vec2(0,0);
	vec2 t5 = vec2(1,0);

	v.push_back(pntVertexData(v0, normalize(vec3(-1,1,1)), t0));
	v.push_back(pntVertexData(v1, normalize(vec3(1,1,1)), t1));
	v.push_back(pntVertexData(v2, normalize(vec3(-1,-1,1)), t2));
	v.push_back(pntVertexData(v3, normalize(vec3(1,-1,1)), t3));
	
	v.push_back(pntVertexData(v4, normalize(vec3(-1,1,-1)), t4));
	v.push_back(pntVertexData(v5, normalize(vec3(1,1,-1)), t5));
	v.push_back(pntVertexData(v6, normalize(vec3(-1,-1,-1)), t6));
	v.push_back(pntVertexData(v7, normalize(vec3(1,-1,-1)), t7));

	/*
	glGenBuffers(1, &VBO);
	glBindBuffer(GL_ARRAY_BUFFER, VBO);
	glBufferData(GL_ARRAY_BUFFER, v.size() * sizeof(vec3), &v[0], GL_STATIC_DRAW);
	glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0);
	glEnableVertexAttribArray(0);
	*/
	vector<vec4> c;

	vec4 c1 = vec4(1.0f, 0.0f, 0.0f, 1.0f);
	vec4 c2 = vec4(0.0f, 1.0f, 0.0f, 1.0f);
	vec4 c3 = vec4(0.0f, 0.0f, 1.0f, 1.0f);
	vec4 c4 = vec4(1.0f, 1.0f, 0.0f, 1.0f);
	vec4 c5 = vec4(1.0f, 0.0f, 1.0f, 1.0f);

	c.push_back(c1);
	c.push_back(c2);
	c.push_back(c3);
	c.push_back(c4);
	c.push_back(c5);
	c.push_back(c1);
	c.push_back(c2);
	c.push_back(c3);
	/*
	glGenBuffers(1, &CBO);
	glBindBuffer(GL_ARRAY_BUFFER, CBO);
	glBufferData(GL_ARRAY_BUFFER, c.size() * sizeof(vec4), &c[0], GL_STATIC_DRAW);
	glVertexAttribPointer(2, 4, GL_FLOAT, GL_FALSE, 0, 0);
	glEnableVertexAttribArray(2);
	*/
	vector<GLuint> indices;

	// front
	indices.push_back(0);
	indices.push_back(2);
	indices.push_back(1);

	indices.push_back(1);
	indices.push_back(2);
	indices.push_back(3);

	// back
	indices.push_back(6);
	indices.push_back(4);
	indices.push_back(5);

	indices.push_back(5);
	indices.push_back(7);
	indices.push_back(6);

	// top
	indices.push_back(1);
	indices.push_back(5);
	indices.push_back(0);

	indices.push_back(0);
	indices.push_back(5);
	indices.push_back(4);

	// bottom
	indices.push_back(7);
	indices.push_back(3);
	indices.push_back(6);

	indices.push_back(6);
	indices.push_back(3);
	indices.push_back(2);

	numberOfIndices = indices.size();

	/*
	glGenBuffers(1, &IBO);
	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, IBO);
	glBufferData( GL_ELEMENT_ARRAY_BUFFER, indices.size() * sizeof(GLuint), &indices[0], GL_STATIC_DRAW);
	*/

	glGenVertexArrays (1, &vertexArrayObjectFBTB);
	glBindVertexArray( vertexArrayObjectFBTB );

	// finally, create the buffer to hold interleaved  and bind the data to them
	glGenBuffers(1, &VBO);
	glBindBuffer(GL_ARRAY_BUFFER, VBO); // Buffer for vertex data
	glBufferData(GL_ARRAY_BUFFER, v.size() * sizeof(pntVertexData), &v[0], GL_STATIC_DRAW); //Buffering vertex data

	glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(pntVertexData), 0);
	glEnableVertexAttribArray(0);

	glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, sizeof(pntVertexData), (const GLvoid*)sizeof(vec3) );
	glEnableVertexAttribArray(1);

	glVertexAttribPointer(3, 2, GL_FLOAT, GL_FALSE,  sizeof(pntVertexData),  (const GLvoid*)(2 * sizeof(vec3)) );
	glEnableVertexAttribArray(3);

	// Generate a buffer for the indices
	glGenBuffers(1, &IBO);
	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, IBO);
	glBufferData(GL_ELEMENT_ARRAY_BUFFER, indices.size() * sizeof(unsigned int), &indices[0] , GL_STATIC_DRAW);
} // end initialize
コード例 #2
0
ファイル: Matrix44.cpp プロジェクト: tangziwen/Cube-Engine
vec3 Matrix44::transformVec3(vec3 v)
{
    auto result = *this * vec4(v, 1.0f);
    return vec3(result.x, result.y, result.z);
}
コード例 #3
0
ファイル: ShaderGen2D.cpp プロジェクト: WilliamFeely/dxgl
// Variables
static const char var_dest[] = "ivec4 dest;\n";
static const char var_pattern[] = "ivec4 pattern;\n";
static const char var_pixel[] = "ivec4 pixel;\n";
static const char var_src[] = "ivec4 src;\n";
static const char var_patternst[] = "vec2 patternst;\n";

// Operations
static const char op_src[] = "src = ivec4(texture2D(srctex,gl_TexCoord[0].st)*vec4(colorsizesrc)+.5);\n";
static const char op_pixel[] = "pixel = ivec4(texture2D(srctex,gl_TexCoord[0].st)*vec4(colorsizedest)+.5);\n";
static const char op_color[] = "pixel = fillcolor;\n";
static const char op_dest[] = "dest = ivec4(texture2D(desttex,gl_TexCoord[1].st)*vec4(colorsizedest)+.5);\n";
static const char op_pattern[] = "patternst = vec2(mod(gl_FragCoord.x,float(patternsize.x))/float(patternsize.x),\n\
mod(gl_FragCoord.y, float(patternsize.y)) / float(patternsize.y));\n\
pattern = ivec4(texture2D(patterntex,patternst)*vec4(colorsizedest)+.5);\n";
static const char op_destout[] = "gl_FragColor = vec4(pixel)/vec4(colorsizedest);\n";
static const char op_vertex[] = "vec4 xyzw = vec4(xy[0],xy[1],0,1);\n\
mat4 proj = mat4(\n\
vec4(2.0 / (view[1] - view[0]), 0, 0, 0),\n\
vec4(0, 2.0 / (view[2] - view[3]), 0, 0),\n\
vec4(0, 0, -2.0, 0),\n\
vec4(-(view[1] + view[0]) / (view[1] - view[0]),\n\
-(view[2] + view[3]) / (view[2] - view[3]), -1 , 1));\n\
gl_Position    = proj * xyzw;\n";
static const char op_vertcolorrgb[] = "gl_FrontColor = vec4(rgb,1.0);\n";
static const char op_texcoord0[] = "gl_TexCoord[0] = vec4(srcst,0.0,1.0);\n";
static const char op_texcoord1[] = "gl_TexCoord[1] = vec4(destst,0.0,1.0);\n";
static const char op_texcoord3[] = "gl_TexCoord[3] = vec4(stencilst,0.0,1.0);\n";
static const char op_ckeysrc[] = "if(src.rgb == ckeysrc) discard;\n";
static const char op_ckeydest[] = "if(dest.rgb != ckeydest) discard;\n";
コード例 #4
0
ファイル: Ocean.cpp プロジェクト: segfault11/GerstnerWaves
 void main()
 {
     gl_Position = vec4(Position, 1.0f);// P*V*vec4(x, y, z, 1.0f);
 }
コード例 #5
0
ファイル: layerParam.cpp プロジェクト: nystep/Scream
 layerParam::layerParam() : 
     position(vec2(0.f)), scale(vec2(1.f)), hsb_bias(vec3(0.f)),
     hsb_mod(vec3(1.f)), color_bias(vec4(0.f)), color_mod(vec4(1.f)), 
     blend(BLEND_REPLACE)
 {
 }
コード例 #6
0
void OpenglBufferData::loadBufferData() {
	if (!theModelView)
		return;
	SimMesh *theMesh = theModelView->theMesh;
	MeshColor *theColor = theModelView->theColor;
	MeshTexture *theTexture = theModelView->theTexture;
	MeshNormal *theNormals = theModelView->theNormals;
	vertex *data = NULL;
	glGenVertexArrays(1, &vao);
	glBindVertexArray(vao);
	glGenBuffers(1, &vbo);
	glBindBuffer(GL_ARRAY_BUFFER, vbo);
	if (!theTexture) {
		data = new vertex[theMesh->numVertices()];
		for (size_t i = 0; i < theMesh->numVertices(); i++) {
			data[i].position = vec4(theMesh->indVertex(i)->p[0], theMesh->indVertex(i)->p[1], theMesh->indVertex(i)->p[2], 1.0f);
			if (theModelView->theColor) {
				GLfloat a = 1.0f;
				if (i < theColor->a.size()) a = theColor->a[i] / 255.0f;
				data[i].color = vec4(theColor->r[i] / 255.0f, theColor->g[i] / 255.0f, theColor->b[i] / 255.0f, a);
			}
			else
				data[i].color = vec4(theModelView->color[0], theModelView->color[1], theModelView->color[2], 1.0f);
		}
		if (theNormals) {
			for (size_t i = 0; i < theNormals->vNormals.size(); i++) {
				data[i].normal = vec3(theNormals->vNormals[i][0], theNormals->vNormals[i][1], theNormals->vNormals[i][2]);
			}
		}
		glBufferData(GL_ARRAY_BUFFER, theMesh->numVertices() * sizeof(vertex), data, GL_STATIC_DRAW);
	}
	else {
		// if texture exists, we need to duplicate the vertex on each triangle
		data = new vertex[theMesh->numFaces() * 3];
		for (size_t i = 0; i < theMesh->numFaces(); i++) {
			SimFace *f = theMesh->indFace(i);
			for (int j = 0; j < 3; j++) {
				SimVertex *v = f->ver[j];
				data[i * 3 + j].position = vec4(theMesh->indVertex(v->idx)->p[0], theMesh->indVertex(v->idx)->p[1], theMesh->indVertex(v->idx)->p[2], 1.0);
				if (theNormals) {
					data[i * 3 + j].normal = vec3(theNormals->vNormals[v->idx][0], theNormals->vNormals[v->idx][1], theNormals->vNormals[v->idx][2]);
					data[i * 3 + j].tangent = vec3(theModelView->tangents[i * 3 + j][0], theModelView->tangents[i * 3 + j][1], theModelView->tangents[i * 3 + j][2]);
				}
				data[i * 3 + j].texCoord = vec2(theTexture->getU(v, f), theTexture->getV(v, f));
			}
		}
		glBufferData(GL_ARRAY_BUFFER, 3 * theMesh->numFaces() * sizeof(vertex), data, GL_STATIC_DRAW);
	}

	glEnableVertexAttribArray(0);
	glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, sizeof(vertex), BUFFER_OFFSET(0));
	if (theTexture) {
		glEnableVertexAttribArray(3);
		glVertexAttribPointer(3, 2, GL_FLOAT, GL_FALSE, sizeof(vertex), BUFFER_OFFSET(2 * sizeof(vec4) + sizeof(vec3)));
		if (theNormals) {
			glEnableVertexAttribArray(4);
			glVertexAttribPointer(4, 3, GL_FLOAT, GL_FALSE, sizeof(vertex), BUFFER_OFFSET(2 * sizeof(vec4) + sizeof(vec3) + sizeof(vec2)));
		}
	}
	else {
		glEnableVertexAttribArray(1);
		glVertexAttribPointer(1, 4, GL_FLOAT, GL_FALSE, sizeof(vertex), BUFFER_OFFSET(sizeof(vec4)));
	}
	if (theNormals) {
		glEnableVertexAttribArray(2);
		glVertexAttribPointer(2, 3, GL_FLOAT, GL_FALSE, sizeof(vertex), BUFFER_OFFSET(2 * sizeof(vec4)));
	}
	unsigned int *face_indices = new unsigned int[3 * theMesh->numFaces()];
	for (size_t i = 0; i < theMesh->numFaces(); i++) {
		SimFace *f = theMesh->indFace(i);
		for (int j = 0; j < 3; j++) {
			if (!theTexture) 
				face_indices[3 * i + j] = f->ver[j]->idx;
			else 
				face_indices[3 * i + j] = 3 * i + j;
		}
	}
	glGenBuffers(1, &vbo_face_indices);
	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vbo_face_indices);
	glBufferData(GL_ELEMENT_ARRAY_BUFFER, 3 * theMesh->numFaces() * sizeof(unsigned int), face_indices, GL_STATIC_DRAW);
	glGenVertexArrays(1, &vao_wireFrame);
	glBindVertexArray(vao_wireFrame);
	glBindBuffer(GL_ARRAY_BUFFER, vbo);
	glEnableVertexAttribArray(0);
	glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, sizeof(vertex), BUFFER_OFFSET(0));
	unsigned int *edge_indices = new unsigned int[2 * theMesh->numEdges()];
	if (theTexture) {
		for (size_t i = 0; i < theMesh->numFaces(); i++) {
			SimFace *f = theMesh->indFace(i);
			for (int j = 0; j < 3; j++) {
				SimEdge * e = theMesh->idEdge(f->ver[j]->idx, f->ver[(j + 1) % 3]->idx);
				edge_indices[2 * e->idx + 0] = i * 3 + j;
				edge_indices[2 * e->idx + 1] = i * 3 + (j + 1) % 3;
			}
		}
	}
	else {
		for (size_t i = 0; i < theMesh->numEdges(); i++) {
			SimEdge * e = theMesh->indEdge(i);
			edge_indices[2 * i + 0] = e->v0->idx;
			edge_indices[2 * i + 1] = e->v1->idx;
		}
	}
	
	glGenBuffers(1, &vbo_edge_indices);
	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vbo_edge_indices);
	glBufferData(GL_ELEMENT_ARRAY_BUFFER, 2 * theMesh->numEdges() * sizeof(unsigned int), edge_indices, GL_STATIC_DRAW);
	if (theTexture) {
		glGenTextures(1, &texture);
		glBindTexture(GL_TEXTURE_2D, texture);
			//get the OpenGL-friendly image
		QImage GL_formatted_image = QGLWidget::convertToGLFormat(QImage(theModelView->theTexture->texture_filename.c_str()));
		glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
		glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
		glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
		glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
					//generate the texture
		glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, GL_formatted_image.width(),
		GL_formatted_image.height(),
		0, GL_RGBA, GL_UNSIGNED_BYTE, GL_formatted_image.bits() );
		glBindTexture(GL_TEXTURE_2D, 0);
		//QImage GL_formatted_image2 = QGLWidget::convertToGLFormat(QImage("normal.bmp"));
		//glGenTextures(1, &normalTexture);
		//glBindTexture(GL_TEXTURE_2D, normalTexture);
		////get the OpenGL-friendly image
		//glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
		//glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
		//glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
		//glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
		////generate the texture
		//glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, GL_formatted_image2.width(),
		//	GL_formatted_image2.height(),
		//	0, GL_RGBA, GL_UNSIGNED_BYTE, GL_formatted_image2.bits() );
		//glBindTexture(GL_TEXTURE_2D, 0);
		
	}

	delete []data;
	delete []edge_indices;
	delete []face_indices;
}
コード例 #7
0
ファイル: surfaceextraction.cpp プロジェクト: sunwj/inviwo
void SurfaceExtraction::updateColors() {
    const static vec4 defaultColor[11] = {vec4(1.0f),
                                          vec4(0x1f, 0x77, 0xb4, 255) / vec4(255, 255, 255, 255),
                                          vec4(0xff, 0x7f, 0x0e, 255) / vec4(255, 255, 255, 255),
                                          vec4(0x2c, 0xa0, 0x2c, 255) / vec4(255, 255, 255, 255),
                                          vec4(0xd6, 0x27, 0x28, 255) / vec4(255, 255, 255, 255),
                                          vec4(0x94, 0x67, 0xbd, 255) / vec4(255, 255, 255, 255),
                                          vec4(0x8c, 0x56, 0x4b, 255) / vec4(255, 255, 255, 255),
                                          vec4(0xe3, 0x77, 0xc2, 255) / vec4(255, 255, 255, 255),
                                          vec4(0x7f, 0x7f, 0x7f, 255) / vec4(255, 255, 255, 255),
                                          vec4(0xbc, 0xbd, 0x22, 255) / vec4(255, 255, 255, 255),
                                          vec4(0x17, 0xbe, 0xcf, 255) / vec4(255, 255, 255, 255)};

    size_t count = 0;
    for (const auto& data : volume_) {
        count++;
        if (colors_.size() < count) {
            const static std::string color = "color";
            const static std::string dispName = "Color for Volume ";
            FloatVec4Property* colorProp =
                new FloatVec4Property(color + toString(count - 1), dispName + toString(count),
                                      defaultColor[(count - 1) % 11]);
            colorProp->setCurrentStateAsDefault();
            colorProp->setSemantics(PropertySemantics::Color);
            colorProp->setSerializationMode(PropertySerializationMode::ALL);
            colors_.addProperty(colorProp);
        }
        colors_[count - 1]->setVisible(true);
    }

    for (size_t i = count; i < colors_.size(); i++) {
        colors_[i]->setVisible(false);
    }
}
コード例 #8
0
ファイル: Main.cpp プロジェクト: AMiller90/Homework
int main()
{

	Vector2<int> vec2(12,25);
	Vector2<int> vec3(13,24);
	Vector2<int> storage;

	std::cout << "Vector2: \n\n";

	storage = vec3 + vec2;
	
	std::cout << "Add:" << "(" << storage.x << "," << storage.y << ")" << std::endl;

	storage = vec3 - vec2;

	std::cout << "Subtract:" << "(" << storage.x << "," << storage.y << ")" << std::endl;

	storage = vec3 / vec2;

	std::cout << "Divide:" << "(" << storage.x << "," << storage.y  << ")" << std::endl; 

	storage = vec3 * vec2;

	std::cout << "Multiply:" << "(" << storage.x << "," << storage.y << ")" << std::endl;

	storage = vec3 % vec2;

	std::cout << "Modulus:" << "(" << storage.x << "," << storage.y << "," << ")" << std::endl;

	int sto = storage.Dot(vec2, vec3);
	std::cout << "Dot product: " << sto << std::endl;

	int mg = storage.Mag(vec2);
	std::cout << "Magnitude: " << mg << std::endl;

	Vector2<int> norm = storage.Normalise(vec2);
	std::cout << "Normalize:" << "(" << norm.x << "," << norm.y << "," << ")\n\n" << std::endl;


	Vector3<int> vec1(12, 12, 12);
	Vector3<int> vec4(12, 12, 12);
	Vector3<int> storage2;
	
	std::cout << "Vector3: \n\n";

	storage2 = vec1 + vec4;

	std::cout << "Add:" << "(" << storage2.x << "," << storage2.y << "," << storage2.z << ")" << std::endl;

	storage2 = vec1 - vec4;

	std::cout << "Subtract:" << "(" << storage2.x << "," << storage2.y << "," << storage2.z << ")" << std::endl;

	storage2 = vec1 / vec4;

	std::cout << "Divide:" << "(" << storage2.x << "," << storage2.y << "," << storage2.z << ")" << std::endl; 

	storage2 = vec1 * vec4;

	std::cout << "Multiply:" << "(" << storage2.x << "," << storage2.y << "," << storage2.z << ")" << std::endl;

	storage2 = vec1 % vec4;

	std::cout << "Modulus:" << "(" << storage2.x << "," << storage2.y << "," << storage2.z << ")" << std::endl;

	int Dot = storage2.Dot(vec1, vec4);

	std::cout << "Dot Product is: " << Dot << std::endl;

	Vector3<int> cross = storage2.Cross(vec1, vec4);

	std::cout << "Cross Product is: " << cross.x << "," << cross.y << cross.z << std::endl;

	int Mag = storage2.Mag(vec1);

	std::cout << "Magnitude Product is: " << Mag  << std::endl;

	Vector3<int> Norm = storage2.Normalise(vec1);

	std::cout << "Normalised:" << "(" << Norm.x << "," << Norm.y << "," << Norm.z << ")\n" << std::endl;


	std::cout << "Color: \n\n";
	Color<int> color;

	Color<int> boo1(12, 12, 12, 12);
	Color<int> boo2(13, 13, 13, 13);
	Color<int> test;

	test = boo1 + boo2;

	std::cout << "Add:" << "(" << test.r << "," << test.g << "," << test.b << "," << test.a << ")" << std::endl;

	test = boo1 - boo2;

	std::cout << "Subtract:" << "(" << test.r << "," << test.g << "," << test.b << "," << test.a << ")" << std::endl;

	test = boo1 * boo2;

	std::cout << "Multiply:" << "(" << test.r << "," << test.g << "," << test.b << "," << test.a << ")" << std::endl;

	test = boo1 / boo2;

	std::cout << "Quotient:" << "(" << test.r << "," << test.g << "," << test.b << "," << test.a << ")" << std::endl;

	test = boo1 % boo2;

	std::cout << "Modulus:" << "(" << test.r << "," << test.g << "," << test.b << "," << test.a << ")" << std::endl;

	test = test.Normalise(boo1);
	
	std::cout << "Normalize:" << "(" << test.r << "," << test.g << "," << test.b << "," << test.a << ")" << std::endl;

	float mag = test.Mag(boo1);

	std::cout << "Magnitude: " << mag;

	Color<int> rgba = color.HexConv("#FFFFFF");

	std::cout << "\nRGBA Values Are : (" << rgba.r << "," << rgba.g << "," << rgba.b << "," << rgba.a << ")\n";


	system("PAUSE");
	return 0;

}
コード例 #9
0
 void main()
 {
     gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
     gl_TexCoord[0] = gl_MultiTexCoord0; //poop
     cameraPosition = (gl_ModelViewMatrixInverse * vec4(0.,0.,0.,1.)).xyz;
 }); // END VERTEX SHADER STRINGIFY
コード例 #10
0
ファイル: SSProjectiles.cpp プロジェクト: Robograde/Robograde
void SSProjectiles::SetSpecificProjectileProperties( Projectile* projectile, const glm::vec3& distance )
{
    // TODODP: TEMP
    //auto GetEffect = [] ( ) -> gfx::ParticleSystem
    //{
    //	ScriptArg args[17];
    //	g_Script.Run( "../../../script/Test.lua" );
    //	g_Script.GetArray( "ParticleTest", args, 17 );
    //	gfx::ParticleSystem ps	= g_SSParticle.GetDefaultParticleSystem( PARTICLE_TYPE_CONE );
    //	ps.EmitterPosition		= glm::vec3( args[0].asDouble, args[1].asDouble, args[2].asDouble );
    //	ps.TimeToLive			= args[3].asDouble;
    //	ps.Colour				= glm::vec4( args[4].asDouble, args[5].asDouble, args[6].asDouble, args[7].asDouble );
    //	ps.Direction			= glm::vec3( args[8].asDouble, args[9].asDouble, args[10].asDouble );
    //	ps.ParticlesSpeed		= args[11].asDouble;
    //	ps.Size					= glm::vec2( args[12].asDouble, args[13].asDouble );
    //	ps.ParticlesTimeToLive	= args[14].asDouble;
    //	ps.TransparencyPolynome	= glm::vec2( args[15].asDouble, args[16].asDouble );
    //	return ps;
    //};

    switch ( projectile->Type )
    {
    case PROJECTILE_TYPE_BULLET:
        projectile->Orientation = RotationAlignment( MODEL_PROJECTILE_UP, glm::normalize( projectile->Destination - projectile->Origin ) );

        //projectile->Scale.z = 1; // TODODP: Move hardcoded length
        projectile->Orientation = RotationAlignment(MODEL_BEAM_UP, glm::normalize(projectile->Destination - projectile->Origin));
        {


            if (projectile->Tracer)
            {
                gfx::ParticleSystem effect = g_SSParticle.GetDefaultParticleSystem(PARTICLE_TYPE_BULLET);
                effect.ParticlesSpeed = projectile->Speed;
                effect.TimeToLive = glm::length(distance) / projectile->Speed;
                effect.ParticlesTimeToLive = glm::length(distance) / projectile->Speed;
                effect.EmitterPosition = projectile->Origin + glm::vec3(0.0f, 0.5f, 0.0f);
                effect.Direction = glm::normalize(projectile->Destination - projectile->Origin) * projectile->Scale.z;
                effect.EmitterPosition = effect.EmitterPosition;

                if (projectile->Weapon == WEAPON_TANK_CANNON)
                    effect.Size = glm::vec2(0.25f, 0.25f);
                else if (projectile->Weapon == WEAPON_MACHINE_GUN)
                    effect.Size = glm::vec2(0.15f, 0.15f);

                g_SSParticle.SpawnParticleSystem(PARTICLE_TYPE_BULLET, effect);

                projectile->Light.Position = projectile->Position;
                projectile->Light.Range = 4;
                projectile->Light.Intensity = 15;
                projectile->Light.Color = vec4(1.0f, 0.2f, 0.2f, 1.0f);
            }
            else
            {
                projectile->Light.Position = projectile->Position;
                projectile->Light.Range = 7;
                projectile->Light.Intensity = 2;
                projectile->Light.Color = vec4(0.2f);
            }
        }

        break;

    case PROJECTILE_TYPE_GRENADE:
        projectile->Velocity.y	= -((projectile->Position.y - projectile->Destination.y) / projectile->TimeLeft - GRAVITY_CONSTANT * projectile->TimeLeft / 2.0f);
        {
            gfx::ParticleSystem effect	= g_SSParticle.GetDefaultParticleSystem( PARTICLE_TYPE_SMOKE_TRAIL );
            effect.EmitterPosition		= glm::vec3( FLT_MIN );
            projectile->Effect			= g_SSParticle.SpawnParticleSystem( PARTICLE_TYPE_SMOKE_TRAIL, effect );
        }
        {
            projectile->Light.Position		= projectile->Position;
            projectile->Light.Color		= glm::vec4( 1.0f );
            projectile->Light.Intensity	= 5.0f;
            projectile->Light.Range		= 100.0f;
        }
        break;

    case PROJECTILE_TYPE_BEAM:
        projectile->TimeLeft	= 0.1f;
        projectile->Scale.z		= projectile->Weapon == WEAPON_PIERCING_LASER ? 25.0f : glm::length( distance ); // TODODP: Move hardcoded length
        projectile->Orientation = RotationAlignment( MODEL_BEAM_UP, glm::normalize( projectile->Destination - projectile->Origin ) );
        projectile->Destination = projectile->Destination + glm::vec3( 0.0f, 0.5f, 0.0f );
        {
            gfx::ParticleSystem effect	= g_SSParticle.GetDefaultParticleSystem( PARTICLE_TYPE_LASER );
            effect.EmitterPosition = projectile->Origin;// +glm::vec3(0.0f, 0.5f, 0.0f);
            effect.Direction			= glm::normalize( projectile->Destination - projectile->Origin ) * projectile->Scale.z;

            if (projectile->Weapon == WEAPON_CUTTER)
            {
                effect.Colour = vec4(0.1f, 0.1f, 0.9f, 1);
                effect.Size = glm::vec2(0.1f, 0.1f);
            }

            g_SSParticle				.SpawnParticleSystem( PARTICLE_TYPE_LASER, effect );
            effect.EmitterPosition		= effect.EmitterPosition + glm::normalize( projectile->Destination - projectile->Origin ) * effect.Size.x / 2.0f;
            g_SSParticle				.SpawnParticleSystem( PARTICLE_TYPE_LASER, effect );

            if(projectile->Weapon == WEAPON_PIERCING_LASER)
            {
                projectile->Light = gfx::Light();
                projectile->Light.Position = projectile->Origin;
                projectile->Light.Direction = projectile->Destination - projectile->Origin;
                projectile->Light.Length = 25.0f; //glm::length( m_LineLight->Direction );
                projectile->Light.Range = 5;
                projectile->Light.Intensity = 3;
                projectile->Light.Color = vec4(0.9f,0.1f,0.1f,1);
            }

// 				if (projectile->Weapon == WEAPON_CUTTER)
// 				{
// 					projectile->Light.Direction = projectile->Destination - projectile->Origin;
// 					projectile->Light.Position = projectile->Destination;
// 					projectile->Light.Color = vec4(0.9f, 0.1f, 0.1f, 1);
// 					projectile->Light.Intensity = 500.0f;
// 					projectile->Light.Range = 100.0f;
// 					projectile->Light.Length = 25.0f;
// 				}
        }
        break;

    case PROJECTILE_TYPE_CONE:
        projectile->TimeLeft	= 0.2f;
        projectile->Scale.z		= g_SSUpgrades.GetUpgrade( WEAPON_PLASMA_SPEWER ).Data.Weapon.AreaOfEffect;
        projectile->Destination = projectile->Destination + glm::vec3( 0.0f, 0.5f, 0.0f );
        {
            gfx::ParticleSystem effect	= g_SSParticle.GetDefaultParticleSystem( PARTICLE_TYPE_CONE );
            effect.EmitterPosition		= projectile->Origin + glm::vec3( 0.0f, 0.5f, 0.0f );
            effect.Direction			= glm::normalize( projectile->Destination - projectile->Origin ) * projectile->Scale.z;
            effect.ParticlesSpeed		= projectile->AoE;
            g_SSParticle.SpawnParticleSystem( PARTICLE_TYPE_CONE, effect );
        }
        break;

    case PROJECTILE_TYPE_NONE:
    default:
        projectile->TimeLeft	= 0.0f;
        break;
    }
}
コード例 #11
0
ファイル: gameclient.cpp プロジェクト: Amor/Clientmod
void GAMECLIENT::on_snapshot()
{
	new_tick = true;
	
	// clear out the invalid pointers
	mem_zero(&gameclient.snap, sizeof(gameclient.snap));
	snap.local_cid = -1;

	// secure snapshot
	{
		int num = snap_num_items(SNAP_CURRENT);
		for(int index = 0; index < num; index++)
		{
			SNAP_ITEM item;
			void *data = snap_get_item(SNAP_CURRENT, index, &item);
			if(netobj_validate(item.type, data, item.datasize) != 0)
			{
				if(config.debug)
					dbg_msg("game", "invalidated index=%d type=%d (%s) size=%d id=%d", index, item.type, netobj_get_name(item.type), item.datasize, item.id);
				snap_invalidate_item(SNAP_CURRENT, index);
			}
		}
	}
		
	process_events();

	if(config.dbg_stress)
	{
		if((client_tick()%100) == 0)
		{
			char message[64];
			int msglen = rand()%(sizeof(message)-1);
			for(int i = 0; i < msglen; i++)
				message[i] = 'a'+(rand()%('z'-'a'));
			message[msglen] = 0;
				
			NETMSG_CL_SAY msg;
			msg.team = rand()&1;
			msg.message = message;
			msg.pack(MSGFLAG_VITAL);
			client_send_msg();
		}
	}

	// go trough all the items in the snapshot and gather the info we want
	{
		snap.team_size[0] = snap.team_size[1] = 0;
		
		// TeeComp.
		for(int i=0; i<MAX_CLIENTS; i++)
			stats[i].active = false;

		int num = snap_num_items(SNAP_CURRENT);
		for(int i = 0; i < num; i++)
		{
			SNAP_ITEM item;
			const void *data = snap_get_item(SNAP_CURRENT, i, &item);

			if(item.type == NETOBJTYPE_CLIENT_INFO)
			{
				const NETOBJ_CLIENT_INFO *info = (const NETOBJ_CLIENT_INFO *)data;
				int cid = item.id;
				ints_to_str(&info->name0, 6, clients[cid].name);
				ints_to_str(&info->skin0, 6, clients[cid].skin_name);
				
				clients[cid].use_custom_color = info->use_custom_color;
				clients[cid].color_body = info->color_body;
				clients[cid].color_feet = info->color_feet;
				
				// prepare the info
				if(clients[cid].skin_name[0] == 'x' || clients[cid].skin_name[1] == '_')
					str_copy(clients[cid].skin_name, "default", 64);
					
				clients[cid].skin_info.color_body = skins->get_color(clients[cid].color_body);
				clients[cid].skin_info.color_feet = skins->get_color(clients[cid].color_feet);
				clients[cid].skin_info.size = 64;
				
				// find new skin
				clients[cid].skin_id = gameclient.skins->find(clients[cid].skin_name);
				if(clients[cid].skin_id < 0)
				{
					clients[cid].skin_id = gameclient.skins->find("default");
					if(clients[cid].skin_id < 0)
						clients[cid].skin_id = 0;
				}
				
				if(clients[cid].use_custom_color)
					clients[cid].skin_info.texture = gameclient.skins->get(clients[cid].skin_id)->color_texture;
				else
				{
					clients[cid].skin_info.texture = gameclient.skins->get(clients[cid].skin_id)->org_texture;
					clients[cid].skin_info.color_body = vec4(1,1,1,1);
					clients[cid].skin_info.color_feet = vec4(1,1,1,1);
				}

				clients[cid].update_render_info(cid);
				gameclient.snap.num_players++;
			}
			else if(item.type == NETOBJTYPE_PLAYER_INFO)
			{
				const NETOBJ_PLAYER_INFO *info = (const NETOBJ_PLAYER_INFO *)data;
				
				clients[info->cid].team = info->team;
				snap.player_infos[info->cid] = info;
				
				if(info->local)
				{
					snap.local_cid = item.id;
					snap.local_info = info;
					
					if (info->team == -1)
						snap.spectate = true;
				}
				
				// calculate team-balance
				if(info->team != -1)
				{
					snap.team_size[info->team]++;
					stats[info->cid].active = true;
				}
				
			}
			else if(item.type == NETOBJTYPE_CHARACTER)
			{
				const void *old = snap_find_item(SNAP_PREV, NETOBJTYPE_CHARACTER, item.id);
				if(old)
				{
					snap.characters[item.id].active = true;
					snap.characters[item.id].prev = *((const NETOBJ_CHARACTER *)old);
					snap.characters[item.id].cur = *((const NETOBJ_CHARACTER *)data);

					if(snap.characters[item.id].prev.tick)
						evolve(&snap.characters[item.id].prev, client_prevtick());
					if(snap.characters[item.id].cur.tick)
						evolve(&snap.characters[item.id].cur, client_tick());
				}
			}
			else if(item.type == NETOBJTYPE_GAME)
			{
				snap.gameobj = (NETOBJ_GAME *)data;
				if(snap.gameobj->game_over != last_game_over)
				{
					if(!last_game_over)
						on_game_over();
					else
						on_game_restart();
					last_game_over = snap.gameobj->game_over;
				}
				if((snap.gameobj->warmup > 0) != last_warmup)
				{
					if(last_warmup)
						on_warmup_end();
					last_warmup = snap.gameobj->warmup > 0;
				}
			}
			else if(item.type == NETOBJTYPE_FLAG)
			{
				int fid = item.id%2;
				snap.flags[fid] = (const NETOBJ_FLAG *)data;
				if(snap.flags[fid]->carried_by != last_flag_carrier[fid])
				{
					if(snap.flags[fid]->carried_by >= 0)
						on_flag_grab(fid);
					last_flag_carrier[fid] = snap.flags[fid]->carried_by;
				}
			}
		}

		// TeeComp
		for(int i=0; i<MAX_CLIENTS; i++)
		{
			if(stats[i].active && !stats[i].was_active)
			{
				stats[i].reset(); // Client connected, reset stats.
				stats[i].active = true;
				stats[i].join_date = client_tick();
			}
			stats[i].was_active = stats[i].active;
		}
	}
	
	// setup local pointers
	if(snap.local_cid >= 0)
	{
		SNAPSTATE::CHARACTERINFO *c = &snap.characters[snap.local_cid];
		if(c->active)
		{
			snap.local_character = &c->cur;
			snap.local_prev_character = &c->prev;
			local_character_pos = vec2(snap.local_character->x, snap.local_character->y);
		}
	}
	else
		snap.spectate = true;
	
	TUNING_PARAMS standard_tuning;
	SERVER_INFO current_server_info;
	client_serverinfo(&current_server_info);
	if(current_server_info.gametype[0] != '0')
	{
		if(strcmp(current_server_info.gametype, "DM") != 0 && strcmp(current_server_info.gametype, "TDM") != 0 && strcmp(current_server_info.gametype, "CTF") != 0)
			servermode = SERVERMODE_MOD;
		else if(memcmp(&standard_tuning, &tuning, sizeof(TUNING_PARAMS)) == 0)
			servermode = SERVERMODE_PURE;
		else
			servermode = SERVERMODE_PUREMOD;
	}
	

	// update render info
	for(int i = 0; i < MAX_CLIENTS; i++)
		clients[i].update_render_info(i);
}
コード例 #12
0
 BoundingSphere(vec3 center, vec3 radius)
 {
     this->center = vec4(center, 1.0f);
     this->radius = vec_length(radius);
 }
コード例 #13
0
AxisAlignedCutPlane::AxisAlignedCutPlane()
    : Processor()
    , volume_("volume")
    , imageInport_("imageInport_")
    , outport_("outport")
    , xSlide_("x", "X Slide")
    , ySlide_("y", "Y Slide")
    , zSlide_("z", "Z Slide")
    , disableTF_("disableTF", "Disable transfer function", false,
                 InvalidationLevel::InvalidResources)
    , tf_("transferfunction", "Transfer function", TransferFunction(), &volume_)
    , sliceShader_("geometryrendering.vert", "axisalignedcutplaneslice.frag", false)
    , boundingBoxShader_("geometryrendering.vert", "axisalignedcutplaneboundingbox.frag")
    , showBoundingBox_("boundingBox", "Show Bounding Box", true)
    , boundingBoxColor_("boundingBoxColor", "Bounding Box Color", vec4(0.0f, 0.0f, 0.0f, 1.0f))
	, renderPointSize_("renderPointSize", "Point Size", 1.0f, 0.001f, 15.0f, 0.001f)
	, renderLineWidth_("renderLineWidth", "Line Width", 1.0f, 0.001f, 15.0f, 0.001f)
    , nearestInterpolation_("nearestInterpolation", "Use nearest neighbor interpolation", false)
    , camera_("camera", "Camera")
    , trackball_(&camera_) {
    addPort(volume_);
    addPort(imageInport_);
    addPort(outport_);

    addProperty(xSlide_);
    addProperty(ySlide_);
    addProperty(zSlide_);
    addProperty(disableTF_);
    addProperty(tf_);
    addProperty(showBoundingBox_);
	addProperty(boundingBoxColor_);
	addProperty(renderPointSize_);
	addProperty(renderLineWidth_);

    addProperty(camera_);
    addProperty(trackball_);

    imageInport_.setOptional(true);

    tf_.get().clearPoints();
    tf_.get().addPoint(vec2(0.0f, 1.0f), vec4(0.0f, 0.0f, 0.0f, 1.0f));
    tf_.get().addPoint(vec2(1.0f, 1.0f), vec4(1.0f, 1.0f, 1.0f, 1.0f));

    tf_.setCurrentStateAsDefault();

    xSlide_.onChange([&]() {
        if (volume_.hasData()) xSlide_.createDrawer(volume_.getData());
    });
    ySlide_.onChange([&]() {
        if (volume_.hasData()) ySlide_.createDrawer(volume_.getData());
    });
    zSlide_.onChange([&]() {
        if (volume_.hasData()) zSlide_.createDrawer(volume_.getData());
    });

    volume_.onChange([&]() {
        if (!volume_.hasData()) return;
        auto vol = volume_.getData();
        xSlide_.onVolumeChange(vol);
        ySlide_.onVolumeChange(vol);
        zSlide_.onVolumeChange(vol);
        if (!boundingBoxMesh_) {
            createBoundingBox();
        }
        boundingBoxMesh_->setModelMatrix(vol->getModelMatrix());
        boundingBoxMesh_->setWorldMatrix(vol->getWorldMatrix());
    });

    boundingBoxColor_.setSemantics(PropertySemantics::Color);

    setAllPropertiesCurrentStateAsDefault();

    createBoundingBox();

}
コード例 #14
0
MeshRenderProcessorGL::MeshRenderProcessorGL()
    : Processor()
    , inport_("geometry.inport")
    , imageInport_("imageInport")
    , outport_("image.outport")
    , camera_("camera", "Camera")
    , centerViewOnGeometry_("centerView", "Center view on geometry")
    , setNearFarPlane_("setNearFarPlane", "Calculate Near and Far Plane")
    , resetViewParams_("resetView", "Reset Camera")
    , trackball_(&camera_)
    , overrideColorBuffer_("overrideColorBuffer", "Override Color Buffer", false , INVALID_RESOURCES)
    , overrideColor_("overrideColor", "Override Color", vec4(0.75f, 0.75f, 0.75f, 1.0f), vec4(0.0f), vec4(1.0f))
    , geomProperties_("geometry", "Geometry Rendering Properties")
    , cullFace_("cullFace", "Cull Face")
    , polygonMode_("polygonMode", "Polygon Mode")
    , renderPointSize_("renderPointSize", "Point Size", 1.0f, 0.001f, 15.0f, 0.001f)
    , renderLineWidth_("renderLineWidth", "Line Width", 1.0f, 0.001f, 15.0f, 0.001f)
    , lightingProperty_("lighting", "Lighting", &camera_)
    , layers_("layers", "Layers")
    , colorLayer_("colorLayer", "Color", true, INVALID_RESOURCES)
    , texCoordLayer_("texCoordLayer", "Texture Coordinates", false, INVALID_RESOURCES)
    , normalsLayer_("normalsLayer", "Normals (World Space)", false, INVALID_RESOURCES)
    , viewNormalsLayer_("viewNormalsLayer", "Normals (View space)", false, INVALID_RESOURCES)
    , shader_("geometryrendering.vert", "geometryrendering.frag", false) {

    addPort(inport_);
    addPort(imageInport_);
    addPort(outport_);
    addProperty(camera_);
    centerViewOnGeometry_.onChange(this, &MeshRenderProcessorGL::centerViewOnGeometry);
    addProperty(centerViewOnGeometry_);
    setNearFarPlane_.onChange(this, &MeshRenderProcessorGL::setNearFarPlane);
    addProperty(setNearFarPlane_);
    resetViewParams_.onChange([this]() { camera_.resetCamera(); });    addProperty(resetViewParams_);
    outport_.addResizeEventListener(&camera_);
    inport_.onChange(this, &MeshRenderProcessorGL::updateDrawers);

    cullFace_.addOption("culldisable", "Disable", GL_NONE);
    cullFace_.addOption("cullfront", "Front", GL_FRONT);
    cullFace_.addOption("cullback", "Back", GL_BACK);
    cullFace_.addOption("cullfrontback", "Front & Back", GL_FRONT_AND_BACK);
    cullFace_.set(GL_NONE);

    polygonMode_.addOption("polypoint", "Points", GL_POINT);
    polygonMode_.addOption("polyline", "Lines", GL_LINE);
    polygonMode_.addOption("polyfill", "Fill", GL_FILL);
    polygonMode_.set(GL_FILL);
    polygonMode_.onChange(this, &MeshRenderProcessorGL::changeRenderMode);

    geomProperties_.addProperty(cullFace_);
    geomProperties_.addProperty(polygonMode_);
    geomProperties_.addProperty(renderPointSize_);
    geomProperties_.addProperty(renderLineWidth_);

    geomProperties_.addProperty(overrideColorBuffer_);
    geomProperties_.addProperty(overrideColor_);
    overrideColor_.setSemantics(PropertySemantics::Color);
    overrideColor_.setVisible(false);
    overrideColorBuffer_.onChange([&](){overrideColor_.setVisible(overrideColorBuffer_.get()); });

    float lineWidthRange[2];
    float increment;
    glGetFloatv(GL_LINE_WIDTH_RANGE, lineWidthRange);
    glGetFloatv(GL_LINE_WIDTH_GRANULARITY, &increment);
    renderLineWidth_.setMinValue(lineWidthRange[0]);
    renderLineWidth_.setMaxValue(lineWidthRange[1]);
    renderLineWidth_.setIncrement(increment);

    renderLineWidth_.setVisible(false);
    renderPointSize_.setVisible(false);

    addProperty(geomProperties_);
    addProperty(lightingProperty_);
    addProperty(trackball_);

    addProperty(layers_);
    layers_.addProperty(colorLayer_);
    layers_.addProperty(texCoordLayer_);
    layers_.addProperty(normalsLayer_);
    layers_.addProperty(viewNormalsLayer_);

    setAllPropertiesCurrentStateAsDefault();
}
コード例 #15
0
void main() {
    vUv = vec2(uv.x, 1.0 - uv.y);
    gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
}
コード例 #16
0
ファイル: backgroundFragment.c プロジェクト: Kitware/cinema
void main() {
    vec4 color = texture2D(backgroundSampler, v_texCoord);
    gl_FragColor = vec4(backgroundColor.rgb, color.a);
}
コード例 #17
0
bool LayerFilterRenderer::initializeSharedGLObjects()
{
    // See also TextureMapperShaderManager.cpp

    char standardVertexShaderString[] =
        "attribute vec4 a_position;   \n"
        "attribute vec2 a_texCoord;   \n"
        "varying vec2 v_texCoord;     \n"
        "void main()                  \n"
        "{                            \n"
        "  gl_Position = a_position;  \n"
        "  v_texCoord = a_texCoord;   \n"
        "}                            \n";

    char offsetVertexShaderString[] =
        "attribute vec4 a_position;              \n"
        "attribute vec2 a_texCoord;              \n"
        "uniform mediump vec2 u_offset;          \n"
        "varying vec2 v_texCoord;                \n"
        "void main()                             \n"
        "{                                       \n"
        "  gl_Position = a_position;             \n"
        "  v_texCoord = a_texCoord - u_offset;   \n"
        "}                                       \n";

#define STANDARD_FILTER(x...) \
        "precision mediump float; \n"\
        "\n"\
        "varying mediump vec2 v_texCoord;\n"\
        "uniform lowp sampler2D s_texture;\n"\
        "uniform highp float u_amount;\n"\
        #x\
        "void main(void)\n { gl_FragColor = shade(texture2D(s_texture, v_texCoord)); }"

#define BLUR_FILTER(x...) \
        "precision highp float; \n"\
        "\n"\
        "varying mediump vec2 v_texCoord;\n"\
        "uniform lowp sampler2D s_texture;\n"\
        "uniform highp float u_amount;\n"\
        "uniform highp float u_blurSize;\n"\
        "const float pi = 3.1415927;\n"\
        #x\
        "void main(void)\n"\
        "{\n"\
        "vec3 incr;\n"\
        "incr.x = 1.0 / (sqrt(2.0 * pi) * u_amount);\n"\
        "incr.y = exp(-0.5 / (u_amount * u_amount));\n"\
        "incr.z = incr.y * incr.y;\n"\
        "\n"\
        "vec4 avg = vec4(0.0, 0.0, 0.0, 0.0);\n"\
        "float coefficientSum = 0.0;\n"\
        "\n"\
        "avg += texture2D(s_texture, v_texCoord.xy) * incr.x;\n"\
        "coefficientSum += incr.x;\n"\
        "incr.xy *= incr.yz;\n"\
        "\n"\
        "for (float i = 1.0; i <= u_amount; i++) {\n"\
        "    avg += texture2D(s_texture, v_texCoord.xy - i * u_blurSize * blurMultiplyVec) * incr.x;\n"\
        "    avg += texture2D(s_texture, v_texCoord.xy + i * u_blurSize * blurMultiplyVec) * incr.x;\n"\
        "    coefficientSum += 2.0 * incr.x;\n"\
        "    incr.xy *= incr.yz;\n"\
        "}\n"\
        "\n"\
        "gl_FragColor = avg / coefficientSum;\n"\
        "}"

    const char* shaderStrs[LayerData::NumberOfCSSFilterShaders];

    shaderStrs[LayerData::CSSFilterShaderGrayscale] = STANDARD_FILTER(
        lowp vec4 shade(lowp vec4 color)
        {
            lowp float amount = 1.0 - u_amount;
            return vec4((0.2126 + 0.7874 * amount) * color.r + (0.7152 - 0.7152 * amount) * color.g + (0.0722 - 0.0722 * amount) * color.b,
                        (0.2126 - 0.2126 * amount) * color.r + (0.7152 + 0.2848 * amount) * color.g + (0.0722 - 0.0722 * amount) * color.b,
                        (0.2126 - 0.2126 * amount) * color.r + (0.7152 - 0.7152 * amount) * color.g + (0.0722 + 0.9278 * amount) * color.b,
                        color.a);
        }
コード例 #18
0
ファイル: colored-image-canvas.cpp プロジェクト: Zoxc/scaled
		void main(void)\
		{\
			gl_Position = vec4(point.x / scene.x - 1.0, 1.0 - point.y / scene.y, 0.0, 1.0);\
			v_tex_coord = tex_coord;\
			v_color = color;\
		}";
コード例 #19
0
ファイル: Menu_Win.cpp プロジェクト: BraXi/FartyBear
void Init_Menu_Win()
{
	ItemDef    *item;
	
	Menu_Win = new MenuDef( "win" );
	Engine->UI->PushMenu( Menu_Win );

	Menu_Win->OnOpen = OnOpen;


	item = new ItemDef( ITYPE_DEFAULT, ITEMFLAG_IMAGE, "background" );
	Menu_Win->PushItem( item );
	{
		item->rect = vec4( 0,0,640,480 );
		item->mat = NULL;
		item->color = vec4( 0,0,0,0.4 );
	}
	

	item = new ItemDef( ITYPE_DEFAULT, ITEMFLAG_TEXT, "as" );
	Menu_Win->PushItem( item );
	{
		item->rect = vec4( 320,170,0,0 );
		item->textColor = vec4( 0.0,0.8,0,1.0 );
		item->textAlign = vec2(1,0);
		item->fontSize = 2.6f;

		item->font = 0;
		item->string = "YOU WIN";
	}

	item = new ItemDef( ITYPE_DEFAULT, ITEMFLAG_TEXT, "as" );
	Menu_Win->PushItem( item );
	{
		item->rect = vec4( 320,190,0,0 );
		item->textColor = vec4( 0.96,0.96,0.96,1 );
		item->textAlign = vec2(1,0);
		item->fontSize = 1.3f;

		item->font = 0;
		//item->string = info;//"WANT TO FART AGAIN?";

		score = item;
	}

	item = new ItemDef( ITYPE_BUTTON, (ITEMFLAG_IMAGE|ITEMFLAG_TEXT), "button-yes" );
	Menu_Win->PushItem( item );
	{
		item->rect = vec4( 225,230,90,40 );
		item->mat = NULL;
		
		item->color = vec4(0.1,0.1,0.1,0.4);
		item->textColor = vec4( 0.92,0.92,0.92,1.0 );
		item->textOffset = vec2( 45,25 );
		item->fontSize = 1.3f;
		item->textAlign = vec2(1,0);
		item->font = 0;
		item->string = "NEXT LEVEL";

		item->OnFocus = ButtonFocus;
		item->OnAction = ButtonYesAction;

		item->visible = true;
	}
	
	item = new ItemDef( ITYPE_BUTTON, (ITEMFLAG_IMAGE|ITEMFLAG_TEXT), "button-no" );
	Menu_Win->PushItem( item );
	{
		item->rect = vec4( 325,230,90,40 );
		item->mat = NULL;
		
		item->color = vec4(0.1,0.1,0.1,0.4);
		item->textColor = vec4( 0.92,0.92,0.92,1.0 );
		item->textOffset = vec2( 45,25 );
		item->fontSize = 1.3f;
		item->textAlign = vec2(1,0);
		item->font = 0;
		item->string = "BACK TO MENU";

		item->OnFocus = ButtonFocus;
		item->OnAction = ButtonNoAction;

		item->visible = true;
	}
}
コード例 #20
0
ファイル: fontVertex.c プロジェクト: calceusHD/cqtTest
void main(void)
{
	gl_Position = charMat * vec4(pos.xy, 0.0, 1.0);
	charDataOut = charDataIn;
	texCoords = pos.zw;
}
コード例 #21
0
void Trans_Mesh::Draw(const Base_Camera* camera, float dt){

	Graphics::SetTopology(PRIM_TRIANGLELIST);
	Graphics::DepthStates::NoDepthTest.Bind();
	Graphics::RasterizerStates::CullNone.Bind();
	Graphics::BlendStates::No_Blend.Bind();

	VB[0].BindAsVertexBuffer();
	IB.BindAsIndexBuffer();

	// first axis
	Batch* cone_batch = Batches[0];
	Batch* rod_batch = Batches[1];

	struct tempstruct{
		mat4 vp;
		vec4 color;
	};
	tempstruct t;
	mat4 bvtrans, bvaxis, rodscale, rodtrans;

	const float offaxis =10.0f;
	rodscale.setupScale(offaxis/3.0f, .1f, .1f);
	const float distaway = 120.0f;
	LastCamPosition = camera->Position;

	vec3 transpost =  GetPosition()-LastCamPosition;
	transpost.normalize();

	//FIRST AXIS.. RED AND X
	bvtrans.setupTranslation((transpost*distaway) + LastCamPosition+vec3(offaxis, 0.0f, 0.0f));
	bvaxis.setupTranslation(vec3(-1.0f, 0, 0));
	t.vp = bvaxis*bvtrans*camera->VP;// we have to move the BV that was pregenerated into the correct position and scale it 
	t.vp.Transpose();
	t.color = vec4(XAxis_Color, 1);//red  ==x
	CBuffer0.Update(&t);

	cone_batch->GetVS()->Bind();
	cone_batch->GetVS()->SetConstantBuffer(CBuffer0, 0);
	cone_batch->GetPS()->Bind();

	Graphics::DrawIndexed(cone_batch->StartIndex, cone_batch->NumIndices);
	//now draw the rod
	bvtrans.setupTranslation((transpost*distaway) + LastCamPosition);
	rodtrans.setupTranslation(vec3(1.3f, 0, 0));
	t.vp = rodtrans*rodscale*bvtrans*camera->VP;// we have to move the BV that was pregenerated into the correct position and scale it 
	t.vp.Transpose();
	CBuffer0.Update(&t);

	cone_batch->GetVS()->SetConstantBuffer(CBuffer0, 0);
	Graphics::DrawIndexed(rod_batch->StartIndex, rod_batch->NumIndices);


	//SECOND AXIS. .. BLUE AND Z
	mat4 rot;
	rot.setupRotateY(-Pi/2.0f);
	bvaxis.setupTranslation( 0.0f,  0.0f, -1.0f);
	bvtrans.setupTranslation((transpost*distaway) + LastCamPosition+ vec3(0.0f, 0.0f, offaxis));

	t.vp = bvaxis*rot*bvtrans*camera->VP;
	t.vp.Transpose();
	t.color = vec4(ZAxis_Color, 1);
	CBuffer0.Update(&t);
	cone_batch->GetVS()->SetConstantBuffer(CBuffer0, 0);

	Graphics::DrawIndexed(cone_batch->StartIndex, cone_batch->NumIndices);

	//now draw the rod
	bvtrans.setupTranslation((transpost*distaway) + LastCamPosition+ vec3(1.0f, 0, offaxis/2.0f));
	t.vp = rodscale*rot*bvtrans*camera->VP;// we have to move the BV that was pregenerated into the correct position and scale it 
	t.vp.Transpose();
	CBuffer0.Update(&t);

	cone_batch->GetVS()->SetConstantBuffer(CBuffer0, 0);
	Graphics::DrawIndexed(rod_batch->StartIndex, rod_batch->NumIndices);

	//THIRD AXIS . . . . GREEN AND Y
	rot.setupRotateZ(Pi/2.0f);
	bvtrans.setupTranslation((transpost*distaway) + LastCamPosition + vec3(0.0f, offaxis, 0.0f));
	bvaxis.setupTranslation(0.0f, -1.0f, 0.0f);

	t.vp = bvaxis*rot*bvtrans*camera->VP;
	t.vp.Transpose();
	t.color = vec4(YAxis_Color, 1);
	CBuffer0.Update(&t);
	cone_batch->GetVS()->SetConstantBuffer(CBuffer0, 0);

	Graphics::DrawIndexed(cone_batch->StartIndex, cone_batch->NumIndices);

	//now draw the rod
	bvtrans.setupTranslation((transpost*distaway) + LastCamPosition+ vec3(1.0f, offaxis/2.0f, 0.0f));
	rodtrans.setupTranslation(vec3(0,  1.3f, 0));
	t.vp = rodtrans*rodscale*rot*bvtrans*camera->VP;// we have to move the BV that was pregenerated into the correct position and scale it 
	t.vp.Transpose();
	CBuffer0.Update(&t);

	cone_batch->GetVS()->SetConstantBuffer(CBuffer0, 0);
	Graphics::DrawIndexed(rod_batch->StartIndex, rod_batch->NumIndices);
}
コード例 #22
0
/* Use mesa's clipping algorithms, translated to GEN4 assembly.
 */
void brw_clip_tri( struct brw_clip_compile *c )
{
   struct brw_compile *p = &c->func;
   struct brw_indirect vtx = brw_indirect(0, 0);
   struct brw_indirect vtxPrev = brw_indirect(1, 0);
   struct brw_indirect vtxOut = brw_indirect(2, 0);
   struct brw_indirect plane_ptr = brw_indirect(3, 0);
   struct brw_indirect inlist_ptr = brw_indirect(4, 0);
   struct brw_indirect outlist_ptr = brw_indirect(5, 0);
   struct brw_indirect freelist_ptr = brw_indirect(6, 0);
   struct brw_instruction *plane_loop;
   struct brw_instruction *plane_active;
   struct brw_instruction *vertex_loop;
   struct brw_instruction *next_test;
   struct brw_instruction *prev_test;
   
   brw_MOV(p, get_addr_reg(vtxPrev),     brw_address(c->reg.vertex[2]) );
   brw_MOV(p, get_addr_reg(plane_ptr),   brw_clip_plane0_address(c));
   brw_MOV(p, get_addr_reg(inlist_ptr),  brw_address(c->reg.inlist));
   brw_MOV(p, get_addr_reg(outlist_ptr), brw_address(c->reg.outlist));

   brw_MOV(p, get_addr_reg(freelist_ptr), brw_address(c->reg.vertex[3]) );

   plane_loop = brw_DO(p, BRW_EXECUTE_1);
   {
      /* if (planemask & 1)
       */
      brw_set_conditionalmod(p, BRW_CONDITIONAL_NZ);
      brw_AND(p, vec1(brw_null_reg()), c->reg.planemask, brw_imm_ud(1));
      
      plane_active = brw_IF(p, BRW_EXECUTE_1);
      {
	 /* vtxOut = freelist_ptr++ 
	  */
	 brw_MOV(p, get_addr_reg(vtxOut),       get_addr_reg(freelist_ptr) );
	 brw_ADD(p, get_addr_reg(freelist_ptr), get_addr_reg(freelist_ptr), brw_imm_uw(c->nr_regs * REG_SIZE));

	 if (c->key.nr_userclip)
	    brw_MOV(p, c->reg.plane_equation, deref_4f(plane_ptr, 0));
	 else
	    brw_MOV(p, c->reg.plane_equation, deref_4b(plane_ptr, 0));
	    
	 brw_MOV(p, c->reg.loopcount, c->reg.nr_verts);
	 brw_MOV(p, c->reg.nr_verts, brw_imm_ud(0));

	 vertex_loop = brw_DO(p, BRW_EXECUTE_1);
	 {
	    /* vtx = *input_ptr;
	     */
	    brw_MOV(p, get_addr_reg(vtx), deref_1uw(inlist_ptr, 0));

	    /* IS_NEGATIVE(prev) */
	    brw_set_conditionalmod(p, BRW_CONDITIONAL_L);
	    brw_DP4(p, vec4(c->reg.dpPrev), deref_4f(vtxPrev, c->offset[VERT_RESULT_HPOS]), c->reg.plane_equation);
	    prev_test = brw_IF(p, BRW_EXECUTE_1);
	    {
	       /* IS_POSITIVE(next)
		*/
	       brw_set_conditionalmod(p, BRW_CONDITIONAL_GE);
	       brw_DP4(p, vec4(c->reg.dp), deref_4f(vtx, c->offset[VERT_RESULT_HPOS]), c->reg.plane_equation);
	       next_test = brw_IF(p, BRW_EXECUTE_1);
	       {

		  /* Coming back in.
		   */
		  brw_ADD(p, c->reg.t, c->reg.dpPrev, negate(c->reg.dp));
		  brw_math_invert(p, c->reg.t, c->reg.t);
		  brw_MUL(p, c->reg.t, c->reg.t, c->reg.dpPrev);

		  /* If (vtxOut == 0) vtxOut = vtxPrev
		   */
		  brw_CMP(p, vec1(brw_null_reg()), BRW_CONDITIONAL_EQ, get_addr_reg(vtxOut), brw_imm_uw(0) );
		  brw_MOV(p, get_addr_reg(vtxOut), get_addr_reg(vtxPrev) );
		  brw_set_predicate_control(p, BRW_PREDICATE_NONE);

		  brw_clip_interp_vertex(c, vtxOut, vtxPrev, vtx, c->reg.t, GL_FALSE);

		  /* *outlist_ptr++ = vtxOut;
		   * nr_verts++; 
		   * vtxOut = 0;
		   */
		  brw_MOV(p, deref_1uw(outlist_ptr, 0), get_addr_reg(vtxOut));
		  brw_ADD(p, get_addr_reg(outlist_ptr), get_addr_reg(outlist_ptr), brw_imm_uw(sizeof(short)));
		  brw_ADD(p, c->reg.nr_verts, c->reg.nr_verts, brw_imm_ud(1));
		  brw_MOV(p, get_addr_reg(vtxOut), brw_imm_uw(0) );
	       }
	       brw_ENDIF(p, next_test);
	       
	    }
	    prev_test = brw_ELSE(p, prev_test);
	    {
	       /* *outlist_ptr++ = vtxPrev;
		* nr_verts++;
		*/
	       brw_MOV(p, deref_1uw(outlist_ptr, 0), get_addr_reg(vtxPrev));
	       brw_ADD(p, get_addr_reg(outlist_ptr), get_addr_reg(outlist_ptr), brw_imm_uw(sizeof(short)));
	       brw_ADD(p, c->reg.nr_verts, c->reg.nr_verts, brw_imm_ud(1));

	       /* IS_NEGATIVE(next)
		*/
	       brw_set_conditionalmod(p, BRW_CONDITIONAL_L);
	       brw_DP4(p, vec4(c->reg.dp), deref_4f(vtx, c->offset[VERT_RESULT_HPOS]), c->reg.plane_equation);
	       next_test = brw_IF(p, BRW_EXECUTE_1);
	       {
		  /* Going out of bounds.  Avoid division by zero as we
		   * know dp != dpPrev from DIFFERENT_SIGNS, above.
		   */
		  brw_ADD(p, c->reg.t, c->reg.dp, negate(c->reg.dpPrev));
		  brw_math_invert(p, c->reg.t, c->reg.t);
		  brw_MUL(p, c->reg.t, c->reg.t, c->reg.dp);

		  /* If (vtxOut == 0) vtxOut = vtx
		   */
		  brw_CMP(p, vec1(brw_null_reg()), BRW_CONDITIONAL_EQ, get_addr_reg(vtxOut), brw_imm_uw(0) );
		  brw_MOV(p, get_addr_reg(vtxOut), get_addr_reg(vtx) );
		  brw_set_predicate_control(p, BRW_PREDICATE_NONE);

		  brw_clip_interp_vertex(c, vtxOut, vtx, vtxPrev, c->reg.t, GL_TRUE);		  

		  /* *outlist_ptr++ = vtxOut;
		   * nr_verts++; 
		   * vtxOut = 0;
		   */
		  brw_MOV(p, deref_1uw(outlist_ptr, 0), get_addr_reg(vtxOut));
		  brw_ADD(p, get_addr_reg(outlist_ptr), get_addr_reg(outlist_ptr), brw_imm_uw(sizeof(short)));
		  brw_ADD(p, c->reg.nr_verts, c->reg.nr_verts, brw_imm_ud(1));
		  brw_MOV(p, get_addr_reg(vtxOut), brw_imm_uw(0) );
	       } 	       
	       brw_ENDIF(p, next_test);
	    }
	    brw_ENDIF(p, prev_test);
	    
	    /* vtxPrev = vtx;
	     * inlist_ptr++;
	     */
	    brw_MOV(p, get_addr_reg(vtxPrev), get_addr_reg(vtx));
	    brw_ADD(p, get_addr_reg(inlist_ptr), get_addr_reg(inlist_ptr), brw_imm_uw(sizeof(short)));

	    /* while (--loopcount != 0)
	     */
	    brw_set_conditionalmod(p, BRW_CONDITIONAL_NZ);
	    brw_ADD(p, c->reg.loopcount, c->reg.loopcount, brw_imm_d(-1));
	 } 
	 brw_WHILE(p, vertex_loop);

	 /* vtxPrev = *(outlist_ptr-1)  OR: outlist[nr_verts-1]
	  * inlist = outlist
	  * inlist_ptr = &inlist[0]
	  * outlist_ptr = &outlist[0]
	  */
	 brw_ADD(p, get_addr_reg(outlist_ptr), get_addr_reg(outlist_ptr), brw_imm_w(-2));
	 brw_MOV(p, get_addr_reg(vtxPrev), deref_1uw(outlist_ptr, 0));
	 brw_MOV(p, brw_vec8_grf(c->reg.inlist.nr, 0), brw_vec8_grf(c->reg.outlist.nr, 0));
	 brw_MOV(p, get_addr_reg(inlist_ptr), brw_address(c->reg.inlist));
	 brw_MOV(p, get_addr_reg(outlist_ptr), brw_address(c->reg.outlist));
      }
      brw_ENDIF(p, plane_active);
      
      /* plane_ptr++;
       */
      brw_ADD(p, get_addr_reg(plane_ptr), get_addr_reg(plane_ptr), brw_clip_plane_stride(c));

      /* nr_verts >= 3 
       */
      brw_CMP(p,
	      vec1(brw_null_reg()),
	      BRW_CONDITIONAL_GE,
	      c->reg.nr_verts,
	      brw_imm_ud(3));
   
      /* && (planemask>>=1) != 0
       */
      brw_set_conditionalmod(p, BRW_CONDITIONAL_NZ);
      brw_SHR(p, c->reg.planemask, c->reg.planemask, brw_imm_ud(1));
   }
   brw_WHILE(p, plane_loop);
}
コード例 #23
0
void main() {


    float newZoom = min(cameraZoom,1.0);



    // vec4 tex4 = texture2D(Texture4, TexCoord0.xy);
    // vec4 tex5 = texture2D(Texture5, TexCoord0.xy);
    // vec4 tex6 = texture2D(Texture6, TexCoord0.xy);

    vec4 tex7 = texture2D(Texture7, TexCoord0.xy);
    vec3 worldPosition = tex7.xyz;









    // vec2 tcMod = (vec2(TexCoord0.x,1.0-TexCoord0.y)*2.0-1.0 );
    // tcMod.x *= bufferDim.x/(newZoom);
    // tcMod.y *= bufferDim.y/(newZoom);
    // tcMod.y -= cameraPos.z;

    // vec3 worldPosition = vec3(0.0,0.0,0.0);
    // worldPosition.x = tcMod.y + tcMod.x/2.0;
    // worldPosition.y = tcMod.y - tcMod.x/2.0;
    // worldPosition.x += cameraPos.x;
    // worldPosition.y += cameraPos.y;
    // worldPosition.z = 0.0;



    // float tilt = tiltAmount;
    // float itilt = 1.0-tiltAmount;
    // float baseHeight = 0.0;

    // vec3 worldPosition = vec3(0.0,0.0,0.0);
    // vec2 ssCoord = vec2(0.0);

    // ssCoord = vec2(TexCoord0.x,1.0-TexCoord0.y)*2.0-1.0;
    // ssCoord.x *= bufferDim.x/(newZoom);
    // ssCoord.y *= bufferDim.y/(newZoom);
    // ssCoord.y -= cameraPos.z*tilt*2.0;
    // ssCoord.y += baseHeight*tilt*2.0;

    // worldPosition.x = (ssCoord.y*0.5/itilt + ssCoord.x*0.5);
    // worldPosition.y = (ssCoord.y*0.5/itilt - ssCoord.x*0.5);
    // worldPosition.z = baseHeight;
    // worldPosition.x += cameraPos.x;
    // worldPosition.y += cameraPos.y;




    vec2 newPos = worldPosition.xy/waveSpacing;

    // float wm = mix(
    //     abs(
    //         sin(
    //             (curTime)/500.0 + (TexCoord0.x + TexCoord0.y) * 12.0
    //         )
    //     ),
    //     0.25,
    //     1.0
    // )*2.0;

    float waveh = (waveHeight(newPos) )*0.5+0.5;
    vec3 waven = (normalize( waveNormal(newPos) )+1.0)/2.0;

    gl_FragData[0] = vec4(waven,waveh);


}
コード例 #24
0
void PointListRenderer::generateDisplayList(const std::vector<vec3>& pointList) {

    if (glIsList(displayList_))
        glDeleteLists(displayList_, 1);

    displayList_ = glGenLists(1);
    glNewList(displayList_, GL_COMPILE);
    glPushAttrib(GL_ALL_ATTRIB_BITS);

    if (coordinateSystem_.get() != "world") {
        glMatrixMode(GL_PROJECTION);
        glPushMatrix();
        glLoadIdentity();
        glMatrixMode(GL_MODELVIEW);
        glPushMatrix();
        glLoadIdentity();
        if (coordinateSystem_.get() == "viewport") {
            glTranslatef(-1.f, -1.f, 0.f);
            glScalef(2.f/viewport_.x, 2.f/viewport_.y, 1.f);
        }
    }

    if (!depthTest_.get())
        glDisable(GL_DEPTH_TEST);

    // enable lighting for illuminated spheres
    if (renderingPrimitiveProp_.get() == "illuminated-spheres") {

        glEnable(GL_LIGHTING);
        glEnable(GL_LIGHT0);

        glLightfv(GL_LIGHT0, GL_AMBIENT, vec4(0.3f, 0.3f, 0.3f, 1.f).elem);
        glLightfv(GL_LIGHT0, GL_DIFFUSE, vec4(0.6f, 0.6f, 0.6f, 1.f).elem);
        glLightfv(GL_LIGHT0, GL_SPECULAR, vec4(0.6f, 0.6f, 0.6f, 1.f).elem);
        glLightf(GL_LIGHT0, GL_SPOT_EXPONENT, 128.f);

        tgt::Material material(color_.get(), color_.get(), color_.get(), 75.f);
        material.activate();

        glMatrixMode(GL_MODELVIEW);
        glPushMatrix();
        glLoadIdentity();
        glLightfv(GL_LIGHT0, GL_POSITION, vec4(1.f, 1.f, 10.f, 1.f).elem);
        glPopMatrix();
    }

    // render: point primitives
    if (renderingPrimitiveProp_.get() == "points") {
        glColor4fv(color_.get().elem);
        glPointSize(pointSize_.get());
        if (pointSmooth_.get())
            glEnable(GL_POINT_SMOOTH);
        glBegin(GL_POINTS);
        for (size_t i=0; i<pointList.size(); ++i) {
            tgt::vertex(pointList[i]);
        }
        glEnd();
    }

    // render: line strip
    if (renderingPrimitiveProp_.get() == "line-strip") {
        glColor4fv(color_.get().elem);
        glLineWidth(pointSize_.get());
        if (pointSmooth_.get())
            glEnable(GL_LINE_SMOOTH);
        glBegin(GL_LINE_STRIP);
        for (size_t i=0; i<pointList.size(); ++i) {
            tgt::vertex(pointList[i]);
        }
        glEnd();
    }

    // render: spheres
    else if (renderingPrimitiveProp_.get() == "spheres" || renderingPrimitiveProp_.get() == "illuminated-spheres") {
        GLUquadricObj* quadric = gluNewQuadric();
        glColor4fv(color_.get().elem);
        for (size_t i=0; i<pointList.size(); ++i) {
            glPushMatrix();
            tgt::translate(pointList[i]);
            gluSphere(quadric, sphereDiameter_.get(), sphereSlicesStacks_.get(), sphereSlicesStacks_.get());
            glPopMatrix();
        }
        gluDeleteQuadric(quadric);
    }

    if (coordinateSystem_.get() != "world") {
        glMatrixMode(GL_PROJECTION);
        glPopMatrix();
        glMatrixMode(GL_MODELVIEW);
        glPopMatrix();
    }

    glPopAttrib();
    glEndList();
}
コード例 #25
0
ファイル: aoShader.c プロジェクト: BrendanBuono/voxelquestiso
void main()	{

	vec4 baseval = texture2D( u_Texture0, v_TexCoords );



	vec3 offsetNorm;
	offsetNorm.rg = (baseval.rg-0.5)*2.0;
	offsetNorm.b = abs(sqrt( abs(1.0-(offsetNorm.r*offsetNorm.r+offsetNorm.g*offsetNorm.g) )));

	offsetNorm *= 2.0;

	vec4 samp;
	vec3 tc;

	int i;
	int j;
	int k;
	float fl;
	float fi;
	float fj;
	float fk;
	float dis;

	float fit;
	float fjt;

	float rad;

	const int iMax = 8;
	const int jMax = 5;
	const float fiMax = float(iMax);
	const float fjMax = float(jMax);
	const float pi = 3.14159;

	
	

	float totHits = 0.0;
	float totRays = 0.0;

	float hitPower;

	float phi;
	float theta;

	int counter = 1;

	

	for (int j = 2; j < jMax; j++) {

		fjt = pow( 2.0, float(j) );

		hitPower = (fjMax-fjt)/fjMax;

		

		for (int i = 0; i < iMax; i++) {

			fit = float(i)*pi/fiMax;

			theta = fit/2.0;//1.5*pi;////2.0*pi - fit/2.0;
			phi = 2.0*fit;

			rad = fjt*fit/pi;

			fi = rad*cos(phi+fjt)*sin(theta);
			fj = rad*sin(phi+fjt)*sin(theta);
			fk = rad*cos(theta);

			tc.x = (fi + offsetNorm.x)/u_Resolution.x;
			tc.y = ( (fj - offsetNorm.y) + (fk + offsetNorm.z)  )/u_Resolution.y;
			tc.z = clamp(baseval.b + (fk + offsetNorm.z)/255.0,0.0,u_MaxLayers);

			dis = clamp(sqrt(fi*fi+fj*fj+fk*fk)/fjt,0.0,1.0);

			samp = texture2D( u_Texture0, v_TexCoords + tc.xy );

			if (samp.b < tc.z) {
				totHits += hitPower;
			}

			totRays += hitPower;
		}

		counter++;
	}

	float resVal = (totHits/totRays);

	resVal = clamp(resVal,0.0,1.0);
	resVal = pow(resVal,6.0);

	



	gl_FragColor = vec4(baseval.rgb,resVal);
	//gl_FragColor = vec4(resVal,resVal,resVal,1.0);
	
}
コード例 #26
0
ファイル: Widget.cpp プロジェクト: DanielNeander/my-3d-engine
void Widget::drawSoftBorderQuad(Renderer *renderer, const SamplerStateID linearClamp, const BlendStateID blendSrcAlpha, const DepthStateID depthState, const float x0, const float y0, const float x1, const float y1, const float borderWidth, const float colScale, const float transScale){
	if (corner == TEXTURE_NONE){
		ubyte pixels[32][32][4];

		for (int y = 0; y < 32; y++){
			for (int x = 0; x < 32; x++){
				int r = 255 - int(powf(sqrtf(float(x * x + y * y)) * (255.0f / 31.0f), 1.0f));
				if (r < 0) r = 0;
				pixels[y][x][0] = r;
				pixels[y][x][1] = r;
				pixels[y][x][2] = r;
				pixels[y][x][3] = r;
			}
		}

		Image img;
		img.loadFromMemory(pixels, FORMAT_RGBA8, 32, 32, 1, 1, false);
		corner = renderer->addTexture(img, false, linearClamp);
	}

	float x0bw = x0 + borderWidth;
	float y0bw = y0 + borderWidth;
	float x1bw = x1 - borderWidth;
	float y1bw = y1 - borderWidth;

	TexVertex border[] = {
		TexVertex(vec2(x0,   y0bw), vec2(1, 0)),
		TexVertex(vec2(x0,   y0  ), vec2(1, 1)),
		TexVertex(vec2(x0bw, y0bw), vec2(0, 0)),
		TexVertex(vec2(x0bw, y0  ), vec2(0, 1)),
		TexVertex(vec2(x1bw, y0bw), vec2(0, 0)),
		TexVertex(vec2(x1bw, y0  ), vec2(0, 1)),

		TexVertex(vec2(x1bw, y0  ), vec2(0, 1)),
		TexVertex(vec2(x1,   y0  ), vec2(1, 1)),
		TexVertex(vec2(x1bw, y0bw), vec2(0, 0)),
		TexVertex(vec2(x1,   y0bw), vec2(1, 0)),
		TexVertex(vec2(x1bw, y1bw), vec2(0, 0)),
		TexVertex(vec2(x1,   y1bw), vec2(1, 0)),

		TexVertex(vec2(x1,   y1bw), vec2(1, 0)),
		TexVertex(vec2(x1,   y1  ), vec2(1, 1)),
		TexVertex(vec2(x1bw, y1bw), vec2(0, 0)),
		TexVertex(vec2(x1bw, y1  ), vec2(0, 1)),
		TexVertex(vec2(x0bw, y1bw), vec2(0, 0)),
		TexVertex(vec2(x0bw, y1  ), vec2(0, 1)),

		TexVertex(vec2(x0bw, y1  ), vec2(0, 1)),
		TexVertex(vec2(x0,   y1  ), vec2(1, 1)),
		TexVertex(vec2(x0bw, y1bw), vec2(0, 0)),
		TexVertex(vec2(x0,   y1bw), vec2(1, 0)),
		TexVertex(vec2(x0bw, y0bw), vec2(0, 0)),
		TexVertex(vec2(x0,   y0bw), vec2(1, 0)),
	};
	vec4 col = color * vec4(colScale, colScale, colScale, transScale);

	renderer->drawTextured(PRIM_TRIANGLE_STRIP, border, elementsOf(border), corner, linearClamp, blendSrcAlpha, depthState, &col);

	// Center
	vec2 center[] = { vec2(x0bw, y0bw), vec2(x1bw, y0bw), vec2(x0bw, y1bw), vec2(x1bw, y1bw) };
	renderer->drawPlain(PRIM_TRIANGLE_STRIP, center, 4, blendSrcAlpha, depthState, &col);
}
コード例 #27
0
ファイル: dirnode.cpp プロジェクト: stewartpark/Gource
void RDirNode::updateFilesVBO(quadbuf& buffer, float dt) const{

    if(in_frustum) {

        for(std::list<RFile*>::const_iterator it = files.begin(); it!=files.end(); it++) {
            RFile* f = *it;

            if(f->isHidden()) continue;

            vec3 col   = f->getColour();
            float alpha = f->getAlpha();

            buffer.add(f->graphic->textureid, f->getAbsolutePos() - f->dims*0.5f, f->dims, vec4(col.x, col.y, col.z, alpha));
        }
    }

    for(std::list<RDirNode*>::const_iterator it = children.begin(); it != children.end(); it++) {
        RDirNode* node = (*it);
        node->updateFilesVBO(buffer,dt);
    }
}
コード例 #28
0
ファイル: items.cpp プロジェクト: digideskio/HClient
void CItems::RenderLaser(const struct CNetObj_Laser *pCurrent)
{
	vec2 Pos = vec2(pCurrent->m_X, pCurrent->m_Y);
	vec2 From = vec2(pCurrent->m_FromX, pCurrent->m_FromY);
	vec2 Dir = normalize(Pos-From);

	float Ticks = (Client()->GameTick() - pCurrent->m_StartTick) + Client()->IntraGameTick(); // H-Client (Vanilla #1157)
	float Ms = (Ticks/50.0f) * 1000.0f;
	float a = Ms / m_pClient->m_Tuning.m_LaserBounceDelay;
	a = clamp(a, 0.0f, 1.0f);
	float Ia = 1-a;

	vec2 Out, Border;

	Graphics()->BlendNormal();
	Graphics()->TextureSet(-1);
	Graphics()->QuadsBegin();

	//vec4 inner_color(0.15f,0.35f,0.75f,1.0f);
	//vec4 outer_color(0.65f,0.85f,1.0f,1.0f);

    vec3 Rgb = HslToRgb(vec3(g_Config.m_hcLaserColorHue/255.0f, g_Config.m_hcLaserColorSat/255.0f, g_Config.m_hcLaserColorLht/255.0f)); //H-Client

	// do outline
	vec4 OuterColor(0.075f, 0.075f, 0.25f, 1.0f);
	if (g_Config.m_hcLaserCustomColor)
        OuterColor = vec4(Rgb.r+0.25f, Rgb.g+0.25f, Rgb.b-0.75f, g_Config.m_hcLaserColorAlpha/255.0f);
	Graphics()->SetColor(OuterColor.r, OuterColor.g, OuterColor.b, 1.0f);
	Out = vec2(Dir.y, -Dir.x) * (7.0f*Ia);

	IGraphics::CFreeformItem Freeform(
			From.x-Out.x, From.y-Out.y,
			From.x+Out.x, From.y+Out.y,
			Pos.x-Out.x, Pos.y-Out.y,
			Pos.x+Out.x, Pos.y+Out.y);
	Graphics()->QuadsDrawFreeform(&Freeform, 1);

	// do inner
	vec4 InnerColor(0.5f, 0.5f, 1.0f, 1.0f);
	if (g_Config.m_hcLaserCustomColor)
        InnerColor = vec4(Rgb.r, Rgb.g, Rgb.b, g_Config.m_hcLaserColorAlpha/255.0f);
	Out = vec2(Dir.y, -Dir.x) * (5.0f*Ia);
	Graphics()->SetColor(InnerColor.r, InnerColor.g, InnerColor.b, 1.0f); // center

	Freeform = IGraphics::CFreeformItem(
			From.x-Out.x, From.y-Out.y,
			From.x+Out.x, From.y+Out.y,
			Pos.x-Out.x, Pos.y-Out.y,
			Pos.x+Out.x, Pos.y+Out.y);
	Graphics()->QuadsDrawFreeform(&Freeform, 1);

	Graphics()->QuadsEnd();

    //H-Client
    CServerInfo Info;
    Client()->GetServerInfo(&Info);
	if(g_Config.m_hcLaserCustomColor && !str_find_nocase(Info.m_aGameType, "race") && length(Pos-From) != 0 && Pos != From)
	{
	    vec2 cPos = From;
        for (int i=0; i<length(From-Pos); i++)
        {
            m_pClient->m_pEffects->LaserTrail(cPos, Dir, InnerColor);
            cPos += Dir;
        }
	}
	//

	// render head
	{
		Graphics()->BlendNormal();
		Graphics()->TextureSet(g_pData->m_aImages[IMAGE_PARTICLES].m_Id);
		Graphics()->QuadsBegin();

		int Sprites[] = {SPRITE_PART_SPLAT01, SPRITE_PART_SPLAT02, SPRITE_PART_SPLAT03};
		RenderTools()->SelectSprite(Sprites[Client()->GameTick()%3]);
		Graphics()->QuadsSetRotation(Client()->GameTick());
		Graphics()->SetColor(OuterColor.r, OuterColor.g, OuterColor.b, 1.0f);
		IGraphics::CQuadItem QuadItem(Pos.x, Pos.y, 24, 24);
		Graphics()->QuadsDraw(&QuadItem, 1);
		Graphics()->SetColor(InnerColor.r, InnerColor.g, InnerColor.b, 1.0f);
		QuadItem = IGraphics::CQuadItem(Pos.x, Pos.y, 20, 20);
		Graphics()->QuadsDraw(&QuadItem, 1);
		Graphics()->QuadsEnd();
	}

	Graphics()->BlendNormal();
}
コード例 #29
0
ファイル: displayFragment.cpp プロジェクト: yluo1/Liquidus
void main(void){																\n\
	gl_FragColor=vec4((texture2D(tex,gl_TexCoord[0].st).xyz),1.0);				\n\
}																				\n\
コード例 #30
0
ファイル: Our_Model.cpp プロジェクト: dekel2003/Graphics
Our_Model::Our_Model(){
	vertex_positions.push_back(vec4(-1, -1, 0, 1));
	vertex_positions.push_back(vec4(1, -1, 0, 1));
	vertex_positions.push_back(vec4(0, 0, 1, 1));

	vertex_positions.push_back(vec4(1, -1, 0, 1));
	vertex_positions.push_back(vec4(-0.77, 0.77, 0, 1));
	vertex_positions.push_back(vec4(0, 0, 1, 1));

	vertex_positions.push_back(vec4(-0.77, 0.77, 0, 1));
	vertex_positions.push_back(vec4(-1, -1, 0, 1));
	vertex_positions.push_back(vec4(0, 0, 1, 1));

	vertex_positions.push_back(vec4(-0.77, 0.77, 0,1));
	vertex_positions.push_back(vec4(1, -1, 0,1));
	vertex_positions.push_back(vec4(-1, -1, 0,1));

	

	normalsToVerticesGeneralForm.push_back(vec3(-1, -1, -0.2));
	normalsToVerticesGeneralForm.push_back(vec3(1, -1, -0.2));
	normalsToVerticesGeneralForm.push_back(vec3(0, 0, 0.8));

	normalsToVerticesGeneralForm.push_back(vec3(1, -1, -0.2));
	normalsToVerticesGeneralForm.push_back(vec3(-0.77, 0.77, -0.2));
	normalsToVerticesGeneralForm.push_back(vec3(0, 0, 0.8));

	normalsToVerticesGeneralForm.push_back(vec3(-0.77, 0.77, -0.2));
	normalsToVerticesGeneralForm.push_back(vec3(-1, -1, -0.2));
	normalsToVerticesGeneralForm.push_back(vec3(0, 0, 0.8));

	normalsToVerticesGeneralForm.push_back(vec3(-0.77, 0.77, -0.2));
	normalsToVerticesGeneralForm.push_back(vec3(1, -1, -0.2));
	normalsToVerticesGeneralForm.push_back(vec3(-1, -1, -0.2));

	//normalsToVerticesGeneralForm.push_back(vec3());


	colors[0] = vec3(256, 0, 0);
	colors[1] = vec3(0, 256, 0);
	colors[2] = vec3(0, 0, 256);
	colors[3] = vec3(256, 256, 256);

	GLfloat minX=-1, minY=-1, minZ=0, maxX=1, maxY=0.77, maxZ=1;
	cube[0] = vec4(minX, minY, minZ, 1.0);
	cube[1] = vec4(minX, minY, maxZ, 1.0);
	cube[2] = vec4(minX, maxY, minZ, 1.0);
	cube[3] = vec4(minX, maxY, maxZ, 1.0);
	cube[4] = vec4(maxX, minY, minZ, 1.0);
	cube[5] = vec4(maxX, minY, maxZ, 1.0);
	cube[6] = vec4(maxX, maxY, minZ, 1.0);
	cube[7] = vec4(maxX, maxY, maxZ, 1.0);


	computeNormalsPerFace();
	

	massCenter = vec4(0, 0, 0.4, 1);
}