Jump to content

  • Log In with Google      Sign In   
  • Create Account


N1ghtDr34m3r

Member Since 19 Aug 2012
Offline Last Active Sep 16 2014 11:00 AM

Topics I've Started

Perlin Noise gives too small values?

04 August 2014 - 03:12 PM

Hello.

 

Today I've implemented a perlin noise algorithm with extra methods like pertubation and eroding to create a terrain. smile.png

I found the code for it here: Click me smile.png

 

After the "addPerlinNoise()" method, you can see 3 reference pictures on that page (in the middle), build with the frequencies 1.0f, 4.0f and 1.0f + 8.0f (without perturb or sth like that, just plain noise).

 

If I use a frequency of 4.0f, this is my output (plain noise): https://imgur.com/7OElD3n

 

And when I use 64.0f as my frequency, I get this: https://imgur.com/dqA04N6

 

Can you help me to achieve something like the reference pictures with the reference frequencies (1.0f, 4.0f, 1.0f + 8.0f)?

I only understand a little behind the maths of it, so I can't really do something to fix it. sad.png

 

The code on the linked site is in C#, mine is in C++.

 

The only things, which are different between my code and the code on the site is the following part:

void PerlinGenerator::initGradients()
{
	//Type of random number distribution
	std::uniform_real_distribution<float> dist(0.0f, 1.0f);  //(min, max)

	//Mersenne Twister: Good quality random number generator
	std::mt19937 rng;
	//Initialize with non-deterministic seeds
	rng.seed(std::random_device{}());

	for (int i = 0; i < gradientTableSize; i++)
	{
		float z = 1.0f - 2.0f * dist(rng);
		float r = (float)sqrt(1.0f - z * z);
		float theta = 2 * (float)M_PI * dist(rng);
		gradients[i * 3] = r * cos(theta);
		gradients[i * 3 + 1] = r * sin(theta);
		gradients[i * 3 + 2] = z;
	}
}

Can it be the random double, which is used for the computing?

 

For the rendering I determine the vertex coordinates for a VBO like this and render it with glDrawElements(...) :

void Terrain::createVBO()
{
	// Create vertex data
	float *vertices = new float[3 * heightMap->size * heightMap->size];
	float blockSize = 16.0f;
	int vertex = 0;

	for (int y = 0; y < heightMap->size; y++) {
		for (int x = 0; x < heightMap->size; x++) {
			vertices[vertex++] = x * blockSize;
			vertices[vertex++] = y * blockSize;
			vertices[vertex++] = heightMap->heights[y][x] * blockSize;
		}
	}

	// Create index data
	[...]

	// Create VAO
	[...]

	// Create VBO
	[...]

	// Create EBO
	[...]

	// Handle vertex attributes in shader prog
	[...]
}

Hopefully you can help me, thanks,

NightDreamer


glAlphaFunc in gl20 ? or How do I enable alpha in gl20 ?

04 November 2012 - 03:23 PM

Hey guys.

I'm currently coding a little game with the libGdx library and I wanted to have a slight fade in/fade out effect if the screen changes (e.g. from MainMenu into the game).
After some time, I've got the idea, that I draw a black filled rectangle over the whole screen with an increasing alpha value. At the point where the alpha value is 0.0f (so, the whole screen is black) I change the screen to my game, where at this point my alpha value is getting bigger (so it will be transparent more and more).

So I implemented something like this:

// init
Gdx.gl.glEnable( GL10.GL_ALPHA_TEST );
// [...]
// render
Gdx.gl10.glAlphaFunc( GL10.GL_GREATER, 0 );
// render my quad

While having my project setting up with LwjglApplicationConfig.useGL20 = false; it will work very well.
But enabling gl20, it won't start, saying that there is a problem with GL10.GL_ALPHA_TEST
So I searched if gl20 have something like that... but now it's 30 minutes later and I don't have any solution.

Could you help?
What I have to enable in gl20 ( and setting up) to use alpha like in gl10 ?

Greets,
N1ghtDr34m3r

Problem with width and height of quads

06 September 2012 - 10:56 AM

Hello dudes,

I've got a little problem, but maybe I am only too silly to solve it. unsure.pngbiggrin.png

I've got a window (1280x720) and a perspective from 0.01f till 1000.0f.
So, when I will render a normal quad with the width and height of the whole screen, I don't know where the vertices of the quad must be.
I try with (-1/-1), (-1/1), (1/-1), (1/1) and for each z-Axis coordinate 1 (I'm rendering with trianglestrips!), but then it is way too big! dry.png

So my question is, how I could know the true coordinates of each vertex for rendering a quad which is as big as the screen? wacko.png
Are there any mathematical tricks or something like that? mellow.png

Problems with Vertex-/Pixelshader in DirectX 9 & C++

05 September 2012 - 01:31 PM

Hello dudes.
This is my forst post in this forum, so be patient with me, if it's the wrong section for this. Posted Image

First I must say, that I allready wrote applications and small games in Java and OpenGL and since ~4 months I learn C++ and DirectX9.
Due to the fact, that I wanted to make something different (the last I did, was a small 3D Environment in C++ & OpenGL, but I didn't finished it).
This gave me the idea of making a little 2D Environment with lighting (shadows) and so on.
Also I wanted and fortunately want to learn HLSL. Posted Image
After some time of "googleing" I found this topic here in this forum and there I read a little tutorial about simple shaders in DirectX 9 from "Two Kings".
I managed it to "learn" something about the code and the HLSL, but unfortunately my code doesn't work properly. Posted Image
I make a MessageBox if CreateVertexShader() failed, it doesn't appear.
I make a MessageBox if CreatePixelShader() failed, it appear! And my programm is terminated. Posted Image

So I need your help, because I didn't find much about DirectX 9 Shader on the internet. Posted Image

N1ghtDr34m3r

PS:
You can look up my code at github.
If you want me to insert the relevant code here, I will do so. Posted Image

edited my problem description

PARTNERS