Jump to content
  • Advertisement

MrSplosion

Member
  • Content Count

    23
  • Joined

  • Last visited

Community Reputation

100 Neutral

About MrSplosion

  • Rank
    Member
  1. MrSplosion

    Improving Perlin Noise

    Thank you guys! This works here's the best I've been able to make: I'll tweak it around but if anyone know a better or more efficiency way or whatever I'm open to anything.
  2. MrSplosion

    Improving Perlin Noise

    You mean like say if this value is under x make it white and if it's over x make it black? Because I've already thought about this and it doesn't quite have the desired look: It doesn't look clumpy enough if you will. Maybe it's because I should do this for every octave instead of just the summed up one? Or maybe there's more to it? Maybe instead of making each octave a value between 0 and 1 I make it a value of either 0 or 1. I just don't know.
  3. So I've created perlin noise (with the help of the community) but I'm not quite finished yet. Here is what I've been able to produce (ignore the outlying pixels): With this accomplished I would now like to make it look more "cloudy". Where most of the image is white but there are certain spots with black. Like this: I checked out this article but It didn't work out very well as all I could accomplish was this: Yeah it looks pretty good and I've been tweaking the variables but nothing look as good as my picture. I would image the function for this would be pretty complex and I'm not a math wizard. So how can I accomplish this? Is it even possible? Thanks!
  4. Thanks for the script but you don't seem to be looping through each pixel in the texture. Where would that go? Would this line get looped with the x and y parameters changing?: total += Smooth(x * frequency, y * frequency) * amplitude; Or perhaps the whole PerlinNoise2d(float x, float y) function gets looped with the x and y parameters changing?
  5. Right it produces an all white texture with everything implemented exactly that script above. Oh and by the way it's only all white if persistence is 1 or higher else it's all black sorry for the confusion didn't think that would be a big deal. As for the other images not being all white that's because everything isn't implemented. In number 1 I said I fill a texture with random color values. That's all I did I looped through each pixel in the texture and assigned it a random color value nothing else, that's why it's not all white. Same thing for the other image, I didn't have frequency or amplitude I just smoothed it out with each octave. However with frequency and amplitude implemented yes, the texture is all white or black. I simply did not implement everything in order to better illustrate each answer.
  6. What do you mean? That first one was about multiple octaves which got solved. The other one was about interpolating 2D noise which I'm still a little fuzzy on but think I got the hang of and this one is about frequency. Now that I think about it I should have probably made one thread but It would have been a little weird talking about one thing that doesn't have to do with the other. Sorry that offends you or whatever but there aren't many tutorials/articles/guides over this and a lot of them suggest I have a degree in math or don't quite go into enough detail. Not to mention each one does it a different way than the other. [/quote] honestly I didn't read your other post, just noticed you keep posting about perlin noise. how bout checking out http://lmgtfy.com/?q...ng+perlin+noise I'm not 100% sure I follow your code, but ... 1: What does this do, is it just returning a random number or is it doing something more (float)random.NextDouble(); 2: Your smooth function looks like it just adds all the neighboring colors together meaning, your color values are going to be way above 100%, meaning all white. never mind, didn't notice the divide by 3. 3: What does persistence equal? when does it get set? How is it used in this function.. what does this function do exactly? float amplitude = Mathf.Pow(persistence, o); 4: In your smooth noise function, you don't take into account the fact that your interating through the octaves loop over and over again resetting the texture data each time. Looks like only the last iteration will ever matter. 5: What does octaves equal? How high does it go? 6: what does noise2D * aamplitude return when amplitude is above 2 ? are you scaling the values at all? or do you just let them go above 100% like a suspect is happening? [/quote] First of all sorry for the delayed post I was kinda busy anyway... 1. Yes, that is just returning a random number. First I fill a texture with random color values shown here which is why I need that. 2. Yeah I'm averaging the surrounding pixels to smooth it out. 3. I've been making persistence usually 0.25 or 0.5 because in that first article I linked there is a diagram with those values. I could be making that value totally wrong though. It gets set before anything happens then with each octave amplitude gets raised to the power of the current octave. So if I set persistence to 0.25 the first octave will have a amplitude of 1 (0.25^0) the second octave will have a amplitude of 0.25 (0.25^1) and so on. 4. No I'm not resetting the texture data I'm running the loop over and over with each successive octave. This better shows it. Right now it just smooths it out more and more because I need to implement frequency. 5. Like you saw in the image in number 4 it can be anything. The article says usually 8 octaves is good but I've been making it all over the place for testing. But again like I've said before all adding octaves does is smooth the texture out more are more because I need to implement frequency. 6. Noise2D() * amplitude seems to make the texture darker. I'm not sure on what it's suppose to accomplish but I just implemented it like shown in the article. I've just been setting it to 1 so nothing happens because I've been focusing on frequency right now but help on that would be great too. Hope that answered all your questions so I can get some feedback .
  7. What do you mean? That first one was about multiple octaves which got solved. The other one was about interpolating 2D noise which I'm still a little fuzzy on but think I got the hang of and this one is about frequency. Now that I think about it I should have probably made one thread but It would have been a little weird talking about one thing that doesn't have to do with the other. Sorry that offends you or whatever but there aren't many tutorials/articles/guides over this and a lot of them suggest I have a degree in math or don't quite go into enough detail. Not to mention each one does it a different way than the other.
  8. So I've been experimenting with Perlin Noise recently but I've encountered a problem that I can't figure out. Articles such as this say that frequency is implemented by taking 2 to the power of the current octave then you multiply x and y by that. As shown here: function PerlinNoise_2D(float x, float y) total = 0 p = persistence n = Number_Of_Octaves - 1 loop i from 0 to n frequency = 2i //2 to the power of the current octave amplitude = pi total = total + InterpolatedNoisei(x * frequency, y * frequency) * amplitude //multiply x and y by that end of i loop return total end function Adding this into my script doesn't work and I have no idea why it just gives me a pure white texture. My script uses Unity3D but don't worry you can easily tell what it's doing: using UnityEngine; using System.Collections; public class noise2 : MonoBehaviour { public int width; public int height; public int octaves; public float persistence; void Start(){ Texture2D texture = new Texture2D(width, height, TextureFormat.ARGB32, false); genorateWhiteNoise(texture); texture.Apply(); genorateSmoothNoise(texture); texture.Apply(); renderer.material.mainTexture = texture; } void genorateWhiteNoise(Texture2D texture){ System.Random random = new System.Random(0); //seed to 0 for testing for(int x = 0; x < width; x++){ for(int y = 0; y < height; y++){ float perlinValue = (float)random.NextDouble(); Color perlinColor = new Color(perlinValue, perlinValue, perlinValue, 1); texture.SetPixel(x, y, perlinColor); } } } void genorateSmoothNoise(Texture2D texture){ for(int o = 0; o < octaves; o++){ int frequency = Mathf.Pow(2, o); //same thing as above take 2 to the power of the current octave float amplitude = Mathf.Pow(persistence, o); for(int x = 0; x < width; x++){ for(int y = 0; y < height; y++){ float perlinValue = noise2D(x * frequency, y * frequency, texture) * amplitude;//multiply x and y by that Color perlinColor = new Color(perlinValue, perlinValue, perlinValue); texture.SetPixel(x, y, perlinColor); } } } } public float noise2D(int x, int y, Texture2D t){ Color corners = (t.GetPixel(x-1, y-1) + t.GetPixel(x-1, y+1) + t.GetPixel(x+1, y-1) + t.GetPixel(x+1, y+1))/4; Color sides = (t.GetPixel(x-1, y) + t.GetPixel(x+1, y) + t.GetPixel(x, y-1) + t.GetPixel(x, y+1))/4; Color center = t.GetPixel(x, y); return (corners.r + sides.r + center.r)/3; } } Could I get help on implementing frequency into my script? Thanks!
  9. So I've been trying to make perlin noise but haven't been successful. I find there aren't many sources out there and articles such as this and this don't really go into enough detail. Anyway here I go... First, could I be confirmed my concept on perlin noise it right? From what I understand and please correct me if I'm wrong, you create a texture with random color values by looping through each pixel. From doing this you get pure randomness. The next step is to smooth that texture out by averaging out the neighboring pixel values. Now you have this. After that you... well I don't know here is where I'm stuck. The first article I linked talks about interpolating. Which brings me to another question. What is the point of interpolating 2D noise? I understand doing it with 1D noise because it smooths out the line instead of a harsh liner one. However, with 2D noise there is no line, just a bunch of pixels. Plus I'm already smoothing it out by averaging the surrounding pixel as explained before so why do it again? Continuing on to another problem... That first article also talks about using multiple octaves witch I'm pretty sure I understand. You create multiple smoothed out textures add them up and there you go. In the pseudo code (at bottom of article) for every x octaves you have you call the function x times. Straight from the code (with a few of my comments) here is that function: function PerlinNoise_2D(float x, float y) total = 0 p = persistence n = Number_Of_Octaves - 1 loop i from 0 to n //run function once for each octave frequency = 2i amplitude = pi //loop through each pixel in texture here total = total + InterpolatedNoisei(x * frequency, y * frequency) * amplitude //end of pixel loop end of i loop return total end function Calling my function once for each octave like above gives me this. [color="#111111"][font="Helvetica, Arial, sans-serif"]Obviously it isn't noisy enough to really be used as anything unless you want something really subtle. Now my logic tells me that the texture looks that way because I'm not multiplying each pixel by the frequency. Adding this to my script breaks it though and I get a pure black texture. The texture might also look like that because I'm not interpolating which I don't understand as explained before.[/font] [color="#111111"][font="Helvetica, Arial, sans-serif"] [/font] [color="#111111"][font="Helvetica, Arial, sans-serif"]Short Version: What is the concept behind interpolating 2D noise? Also how can I add persistence, octaves, frequency and amplitude to create a nice cloudy texture?[/font] [font="Helvetica, Arial, sans-serif"] [/font] [font="Helvetica, Arial, sans-serif"][color="#111111"]Here is my script:[/font] [font="Helvetica, Arial, sans-serif"][color="#111111"] void Start () { System.Random random = new System.Random(); //purely randomize the texture for(int x = 0; x < width; x++){ for(int y = 0; y < height; y++){ float numb = (float)random.NextDouble(); //set pixel color to the numb value } } //now smooth the random texture for(int i = 0; i < octaves; i++){ for(int x = 0; x < width; x++){ for(int y = 0; y < height; y++){ float numb = smoothNoise(x, y); //i realize it should be "float numb = smoothNoise(x * frequency, y * frequency) * amplitude" but like explained above it didn't work. //set pixel to the numb value } } } } public float smoothNoise(int x, int y){ //here "t" is just the texture. "GetPixel()" gets the color of the pixel at the specified x and y cordinate Color corners = (t.GetPixel(x-1, y-1) + t.GetPixel(x-1, y+1) + t.GetPixel(x+1, y-1) + t.GetPixel(x+1, y+1))/16; Color sides = (t.GetPixel(x-1, y) + t.GetPixel(x+1, y) + t.GetPixel(x, y-1) + t.GetPixel(x, y+1))/8; Color center = t.GetPixel(x, y)/4; return corners.r + sides.r + center.r; } [/font] [font="Helvetica, Arial, sans-serif"] [/font][color="#111111"][font="Helvetica, Arial, sans-serif"] [/font] [color="#111111"][font="Helvetica, Arial, sans-serif"]Anything is welcome and I need all the help I can get but please don't just post your script (unless it's simple) because usually when people do that they're five times more complex and just add to my confusion.[/font] [color="#111111"][font="Helvetica, Arial, sans-serif"] [/font] [color="#111111"][font="Helvetica, Arial, sans-serif"]Thanks![/font]
  10. So I've been experimenting with perlin noise but I'm having trouble adding multiple octaves together. There aren't that many sources out there and articles such as this and this don't quite go into enough detail. The first article I linked really doesn't talk about it at all and the other says I should make a array of both an x and y number then multiply it by 2 squared by the current octave. I've tried this method but haven't had any success. I'm confused could someone please help me or go into more detail about adding multiple octaves together? Script: function PerlinNoise(){ var texture = new Texture2D(width, height, TextureFormat.ARGB32, false); for(q=0; q<=width; q++){ for(w=0; w<=height; w++){ var a = Noise2d(q, w); var b = new Color(a, a, a, 0); texture.SetPixel(q, w, b); } } texture.Apply(); renderer.material.mainTexture = texture; } function Noise2d(x : int, y : int){ var n; n = x + y * 57; n = (n<<13) ^ n; var res = (1.0 - ((n * (n * n * 15731 + 789221) + 1376312589) & 0x7fffffff) / 1073741824.0); return res; } Pics Thanks!
  11. MrSplosion

    Creating Perlin Noise

    I see, thanks for the help! I will use this to make multiple octaves then try to combine them together. Chances are I'll ask another question but interpolating doesn't too difficult.
  12. MrSplosion

    Creating Perlin Noise

    That's what having multiple octaves are for. It sounds to me like you're only doing one octave. You should be doing multiple octaves, and then sum each octave up (but each successive octave has a higher frequency and a lower amplitude). Are you getting stuck on how to combine the octaves/making each successive octave have a higher frequency and lower amplitude? [edit] On second thought, is it the interpolation method you're struggling with? Because you need to interpolate between the octaves as well. I know there can be a lot of new terms when it comes to making perlin noise (octaves, amplitude, frequency, interpolation, etc.), but I'm not sure which one of them it is you're struggling with so I'm not sure exactly what more to say. [/quote] Ah! I see what you're saying quick question though: In the link you provided why is all that necessary? I bet if you just simply looped though each pixel and randomly picked if it was black or white it would look the exact same. Or is there more to it? Does each pixel have a certain color to it or is it just binary black or white?
  13. MrSplosion

    Creating Perlin Noise

    That's pure noise though, I want smooth coherent noise such as: Sorry probably should have made that more apparent.
  14. Ok, so I've been having difficulties on how to implement 2D perlin noise in my game. The problem that the articles I've read such as this and this really don't explain the concept very well. The best article I've found is this, however I still think it doesn't go into enough detail, plus there different methods. I want to turn a texture into perlin nose. From what I understand (please correct me if I'm wrong and keep in mind I'm discussing 2D noise) you need a function that takes in a x and y grid point and returns a value with which you can then use for the gray-scale of that point or pixel in the texture. So I would loop through every pixel in my texture and assign it a gray-scale value using the function. Generating this color value is the hard part though. Again correct me if I'm wrong but I'm pretty sure you use the grid points and make a random number out of it between 0 and 1. Let's just use (2, 4) as an example. First I need a number to give the generator, how about the average of the two points? So I put in 3 and it gives me something like 0.634. After this I get completely confused because I need to check the neighboring values and have that effect my value 0.634 right? If I don't It will look completely random and not have "patches" of a color somewhere. Nothing explains how to do this well and I need help badly!!! Could someone please explain this concept to me in a little bit better detail? Thanks!
  15. MrSplosion

    Can't Seek Over Pre-existing Data?

    I can't prepend data? So there is no way to simply move the pointer somewhere and start writing without deleting whats after the pointer? I can only do it in some other mode other than append mode which will deleting whats after the pointer? And yes I'm using System.IO.StreamWriter.
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!