Posts tagged ‘improvement’

Code refactory

Introduction

I’ve spent the last few days (yes, Christmas too…) working on a big refactory of the code of my programs, most of the code is Object Oriented now and I’m planning to make everything OO soon.

The changes

I’ve introduced 3 news classes:

  • Shader : a vertex or a fragment shader, the code loads, compiles and manages a shader
  • ShaderProgram : a shader program, it’s connected to two Shader
  • PingPongTexture : a couple of textures needed by the Ping-Pong technique

Furthermore I’ve rearranged the shaders, now all the sources are in a separate directory and they can be easily used in both the programs.

Example of code

This code manages the erosion using the old code:

glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb);

vs = InitShader(GL_VERTEX_SHADER, “src/shad.vert”);
fs = InitShader(GL_FRAGMENT_SHADER, “src/shad3.frag”);
p = InitProgram(vs, fs);

tex0_loc = glGetUniformLocation(p, “Tex0″);
alpha_loc = glGetUniformLocation(p, “alpha”);

glUniform1i(tex0_loc, 0);
glUniform1f(alpha_loc, alpha);

for(int i = 0; i < eros_it; i++)
{
	glDrawBuffer(att_point[write_tex]);

	glActiveTexture(GL_TEXTURE0);
	glBindTexture(GL_TEXTURE_2D, tex[read_tex]);

	ShaderDraw();

	if(read_tex)
	{
		read_tex = 0;
		write_tex = 1;
	}
	else
	{
		read_tex = 1;
		write_tex = 0;
	}
}

This code manages the same stuff using the new code:

glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb);

p->AttachShader(eros1_shader);
p->LinkProgram();
p->UseProgram();

eros1_shader->SetUniformInt(“Tex0″, 0);
eros1_shader->SetUniformFloat(“alpha”, alpha);

for(int i = 0; i < eros_it; i++)
{
	pp_tex->SetDrawBuffer();

	glActiveTexture(GL_TEXTURE0);
	pp_tex->BindTexture(READ_TEX);

	p->Run(W, H);

	pp_tex->Swap();
}

The difference is really evident!

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

Circles algorthm and floating point textures

Introduction

This post discuss the use of floating point (16 bits) textures with the Circles algorithm.

Results summary

Using floating point textures  gives a good improvement because it fixes a problem that affects several maps generated with this algorithm. In fact, when the number of iterations is bigger than 500 or when some parameters like the radius of the circle are bigger than the default values, the map shows several white regions.

Thanks to floating point textures and to the normalization phase those regions are normalized and all the maps are usable.

Some examples

This is a terrain of type 2 generated by 500 iterations using a 16-bits texture before (left) and after (right) the normalization phase:

          

It’s possible to notice the white regions in the first image.

This is a terrain of type 1 generated by 1000 iterations using a 16-bits texture before (left) and after (right) the normalization phase:

         

Also here it’s possible to notice the white region in the first image.

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

Fault Formation and floating point textures

Introduction

This post discuss the use of floating point (16 bits) textures with the Fault Formation algorithm.

Results summary

Using floating point textures don’t give a real improvement to the Fault Formation technique, in fact the terrains generated using fp textures are usually too homogeneous and are made mostly of high values (light gray/white pixels), usually these terrains require one of the two erosion algorithms showed in the circles algorithm post to be more realistic.

For these reasons, and for the higher execution times caused by the fp data, I think that the fp textures are not a good choice for this technique.

Some examples

This is a terrain generated by 500 iterations using a 8-bits texture (left) and a 16-bits texture (right):

          

These images are the results of 6 iterations of blur (blur radius = 10) and of the second erosion technique from the circles algorithm on the terrain generated with the fp texture:

          

As it’s possible to notice the final image is similar to the result of the generation/erosion process with the 8-bit texture.

This is the terrain generated by 1000 iterations using a 8-bits texture (left) and a 16-bits texture (right):

          

These images are the result of 6 iterations of blur (blur radius = 10) and of the second erosion technique from the circles algorithm on the terrain generated with the fp texture:

          

In this case the 8-bits and the 16-bits textures give two really different terrains.

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]