• Create Account

# george7378

Member Since 24 Jan 2013
Offline Last Active Apr 19 2016 01:40 AM

### Creating a PRNG input from three values

23 March 2016 - 02:35 PM

Hi everyone,

I'm currently trying to create a simple procedural terrain system that I will later be able to expand and improve. So far I've created a quadtree-based system of cells which will divide based on camera proximity. When enough recursive division has occured, each cell is put into a queue and used to generate vertices for a dynamic buffer. I'm happy with my plane-generating system, but at the moment all it does is generate a flat plane with appropriate subdivision.

When each vertex is generated, I want to determine its height using a noise function. I'm familiar with using octaves of noise along with interpolation and 1d and 2d PRNG functions to produce perlin-style noise, but the functions I've used in the past won't quite meet my needs here. I want to have a noise function that will produce the same pseudo-random output for a given pair of x-y coordinates, but I also want to be able to set a 'seed' value that will let me generate more than one terrain output as a result.

I'm thinking that the simplest way to do this would be to use a 1D noise function like this one I've used before:
float hash_noise_1d(int input)
{
input = (input << 13)^input;
float r = 1 - ((input*(input*input*15731 + 789221) + 1376312589) & 0x7fffffff)/float(1073741824);
return (r + 1)/2;
}

...and to find a way of collapsing the x coordinate, the y coordinate and the seed down into a single integer value for input. This way, I would always get the same result for a given set of x-y coordinates combined with a given seed. So my question is: does anyone have a clever way to combine two (integer) coordinates along with an integer seed? I'm thinking that clever use of some bitwise operators would do the trick.

### Dumping every frame to an image file

05 February 2016 - 07:38 AM

Hi everyone,

I know this is quite an ugly way of doing video capture, but I'd like to be able to try the following in my DX9/C++ app:

- Force each frame in the program loop to represent a fixed time interval (e.g. 1/60th of a second - easy to do)

- Dump each frame to an external image file in a folder (I'd use a counter which is incremented in each frame to append a sequence number to the given frame's filename)

- Import each of these frames to a movie maker program in the knowledge that I am guaranteed a specific framerate

I've tried using programs such as Fraps and Camstudio to capture my screen, but the framerates are variable and often low. I'm simply making a demonstration video for my program, which doesn't even require realtime user interaction, so it doesn't matter how long it takes to render/save each frame in sequence.

Is there a way to save the frames like this? I'm using a windowed app too if that's a restriction. Perhaps you know an alternative way of saving each and every frame my program renders?

Thanks a lot!

### Unrestricted while loop?

04 November 2015 - 07:00 AM

I suspect the answer to this is going to be 'no', but I'll ask anyway. Is it possible to have a while loop in HLSL which continues indefinitely? I'm making an iterative path tracer which, for each initial ray, bounces it around the scene until it either hits a light or until its colour becomes close enough to black that I can just ignore it. At the moment, I am having to impose a maximum number of bounces because the shader refuses to compile unless I do. Has anyone done a similar project where they can share a solution?

Thanks a lot!

### Creating a custom sprite class

30 October 2015 - 07:14 AM

Hi!

At the moment, I'm using a single window-sized ID3DXSprite to display a 2D texture on screen. This sprite is drawn with a pixel shader to allow for post-processing effects to be added to the texture. The issue is that my shader contains more arithmetical operations than are allowed in ps_2_0, and so I want to use ps_3_0 instead. However, it doesn't seem like ps_3_0 and ID3DXSprite can be used together (am I right about that?). As a result, I'm probably going to have to create my own sprite class, so that I can also use a custom vertex shader (compiled with vs_3_0).

I was wondering if anyone could point me to a good online tutorial, or a reference in a book, which will show me an example of a custom 2D sprite class? It doesn't have to be complicated - basically, when the program starts I'd like to create a single instance of the sprite with the same width and height as the program's window, then on each frame I'd like to render it using my custom shaders.

Thanks for the help!

### Finding the current average of an indefinitely increasing sequence

28 October 2015 - 12:11 PM

Hi everyone,

The problem I'm currently trying to solve is this: I have a function which generates a value each time it runs, and I want to keep repeating the function indefinitely. Each time the function returns a new value, I want to find the average of ALL of the values it has generated so far. How can I do this without storing every single value?

A bit of context: I'm trying to create a path tracer which will continue to cast rays indefinitely. Each iteration will cast one ray per pixel, and I want to display an average of ALL the rays cast so far, so that I can see the rendering happening in realtime. How can I create a blended image like this without storing every frame?

Thanks a lot, I feel like this is a simple mathematical concept which will be obvious when it is pointed out to me!

PARTNERS