• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
Narf the Mouse

A perlin noise function on the GPU

2 posts in this topic

As an idle thought, I've written my perlin noise function in NVidia FX Composer. However, there's a slight problem...Outputting data. I'm limited to a GeForce 8800GT, so I'm using Shader Model 3.0. No dynamic array indexing, which means I can't just output to an array stored in the effect file. And Google doesn't seem to know about modifying a texture.

I suppose I could output the perlin noise to the screen and take a screenshot, but that's not really what I'm after...
0

Share this post


Link to post
Share on other sites
Ok, I solved that, I think. Just output to a surface I create. However, I've got a new problem. In FX Composer, my code compiles fine. Try to load it as a SlimDX Effect and I get X3000 "Unexpected Token" on this: I've bolded the unexpected token.

uint MercenneOnce(uint seed)
{
return (1812433253 * (seed - (seed * (uint)pow(2, 30))) + 1); // 0x6c078965
}

float Noise2D(int x, int y)
{
int n = x + y * 1376312627;
n = (1 - ((n * (n * n * 15727 + 789181) + (int)1376312627) - (int)0x7fffffff) / (int)1073741827);
return MercenneOnce(n / 4294967295) * 2.0;
}

How is that unexpected?
0

Share this post


Link to post
Share on other sites
Alright, my GPU Perlin functions are returning the maximum float value as a negative and I don't know why.


texture Data;

/* uint MercenneOnce(uint seed)
{
return (uint)abs((1812433253 * ((int)seed - (int)(seed * (int)pow(2, 30))) + 1)); // 0x6c078965
} */

int MercenneOnce(int seed)
{
return (1812433253 * (seed - (seed * (int)pow(2, 30))) + 1); // 0x6c078965
}

float Noise2D(int x, int y)
{
int n = x + y * 1376312627;
n = (1 - ((n * (n * n * 15727 + 789181) + (int)1376312627) - (int)0x7fffffff) / (int)1073741827);
// uint n2 = (uint)n / 4294967295;
// return MercenneOnce((uint)abs( (uint)abs(n) / 2147483647.0)) * 2.0;
// return MercenneOnce((uint)abs( n )) * 2.0;
// return n / 2147483647.0;
return MercenneOnce(n) / 2147483647.0;
// return 1.0;
}

float SmoothedNoise2D(int x, int y)
{
float corners = (Noise2D(x - 1, y - 1) + Noise2D(x + 1, y - 1) + Noise2D(x - 1, y + 1) + Noise2D(x + 1, y + 1)) / 16;
float sides = (Noise2D(x - 1, y) + Noise2D(x + 1, y) + Noise2D(x, y - 1) + Noise2D(x, y + 1)) / 8;
float center = Noise2D(x, y) / 4;

return corners + sides + center;
}

float CosineInterpolate(float a, float b, float interpolation)
{
float f = (1 - cos(interpolation * 3.1415926535897932384626433832795)) * .5;

return a * (1 - f) + b * f;
}

float InterpolatedNoise2D(float x, float y)
{
int integer_X = (int)x;
float fractional_X = x - integer_X;

int integer_Y = (int)y;
float fractional_Y = y - integer_Y;

float v1 = SmoothedNoise2D(integer_X, integer_Y);
float v2 = SmoothedNoise2D(integer_X + 1, integer_Y);
float v3 = SmoothedNoise2D(integer_X, integer_Y + 1);
float v4 = SmoothedNoise2D(integer_X + 1, integer_Y + 1);

float i1 = CosineInterpolate(v1, v2, fractional_X);
float i2 = CosineInterpolate(v3, v4, fractional_X);

return CosineInterpolate(i1, i2, fractional_Y);
}


float PerlinNoise2D(float x, float y, float persistance, int octaves, int shift)
{
float total = 0;
float p = persistance;
int n = octaves;

for (int i = 0; i < n; ++i)
{
float frequency = pow(2, i + shift);
float amplitude = pow(p, i + shift);

total = total + InterpolatedNoise2D(x * frequency, y * frequency) * amplitude;
}

return total / persistance;
}

struct VertexShader_Input
{
float4 Position : Position0;
};

struct VertexShader_Output
{
float4 Position : Position0;
float3 Pos : TexCoord0;
float4 Color : Color;
};

VertexShader_Output mainVS(VertexShader_Input input)
{
VertexShader_Output output;
output.Position = input.Position;
output.Pos = input.Position.xyz;
// data[(int)output.Pos.x][(int)output.Pos.z] = PerlinNoise2D(output.Pos.x / 512.0, output.Pos.z / 512.0, 5, 5, 0);
output.Color = float4(1.0, 1.0, 1.0, 1.0) * (PerlinNoise2D(output.Pos.x / 512.0, output.Pos.z / 512.0, 5, 5, 0));
return output;
}

float4 mainPS(VertexShader_Output input) : COLOR
{

return input.Color;
}

technique technique0 {
pass p0 {
// CullMode = None;
VertexShader = compile vs_3_0 mainVS();
PixelShader = compile ps_3_0 mainPS();
}
}
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0