[SOLVED]FPS Drop

Hi,

in french xD…
J’essaye de créer une skybox entièrement avec un shader, j’ai créer mon bruit de perlin et je le passe à la fonction fbm avec 5 itérations.
Bon cela marche mais c’est pas joli pour l’instant :sweat_smile:

Et du coup j’ai voulu regarder mon framerate et je pense que c’est mal optimiser
Avec la skybox j’ai 700 FPS
Et sans la skybox je suis à 3000 FPS.

Je voulais savoir si cela était normal, j’avais lu quelque part et il y a longtemps que les premiers FPS chutaient assez vite, mais je trouve que ça chute un peu trop.
La résolution est de1280*720.

En anglais approximatif…
I try to create a skybox only with shader.
I create my own noise and pass it to a fbm fonction for create clouds (5 octaves).
It works but not beautiful yet :sweat_smile:

I wanted to watch my FPS and I have this :
With = 700FPS
Without = 3000FPS;
Is it normal ?
I read somewhere that the first drop FPS is it. But I think it’s a lot.
My resolution is 1280*720.

Thanks

1 Like

Hey, thanks for trying to post it in English too! I was still having a bit of trouble understanding what you meant; however, I ran your first section through google translate and it helped a bit. I’ll post what google translated for others…

I try to create a skybox entirely with a shader, I create my perlin noise and I pass it to the fbm function with 5 iterations.
Well it works but it is not pretty at the moment: sweat_smile:

So I wanted to watch my framerate and I think it’s bad to optimize
With the skybox I have 700 FPS
And without the skybox I am at 3000 FPS.

I wanted to know if this was normal, I had read somewhere and it was a long time ago that the first FPS dropped quite quickly, but I find that it drops a little too much.
The resolution is 1280 * 720.

It might help to run the English text of any replies through google translate if it’s hard for you to read it and convert it back to your own native French :slight_smile:

A few reference links…
Google Translate: https://translate.google.com/
Fractal Brownian Motion: https://thebookofshaders.com/13/

Anyway…!

A drop from 3000 FPS to 700 FPS does seem like a lot, so I think you’re right to be concerned. That said, I’ve never used this noise function before so I don’t have much experience but that link I posted for FBM has a shader implementation for clouds. I’m not used to this shader language, but one can kind of get the idea.

I’m seeing four calls to the fbm function in the shader which has a loop for the number of octaves. If you’re using 5 octaves that’d land at around 20 loops total per pixel, which I could see adding up, but doesn’t seem that bad. Again, I’m not sure though.

Maybe compare your implementation to this one and try dropping the number of octaves to see how it has an impact on performance?

Good luck!
(Bonne chance!)

1 Like

@Trinith, @PumpkinPudding

Thanks for your reply :slight_smile:

J’ai trouvé ce qui me causais des problèmes du coup
Dans la première méthode random j’ajoute le cosinus et je chute de 0.33ms/frame à 1.43ms/frame.
La deuxième je supprime le cosinus et je chute de 0.33ms/frame à 0.47ms/frame.

Du coup c’est beaucoup mieux, mais je continue de chercher. La fonction frac est assez gourmande et je me demande si il n’y en pas des autres que j’utiliserai trop souvent.
Merci pour le lien mais c’est celui avec lequel je me suis familiarisé avec le bruit de perlin, le rendu de nuage avec le fbm est très bien pour les aurores boréales mais moins pour les nuages basique :wink:

In english, let’s go

I have found what is wrong in my shader code.
First random technique I add a cosinus and I drop from 0.33ms/frame to 1.43ms/frame.
The second technique I remove a cosinus and I drop from 0.33ms/frame to 0.47ms/frame.

It’s really better but I search something else just in case. A frac function have an expensive cost, maybe I use something else so many times.
Thanks for this link, but I begun to learn perlin noise with this, and a final renderering it’s for aurora borealis not basic clouds :wink:

first :

 float random(float2 _st)
    {
    	float a = 12.9898;
    	float b = 70.2332;
    	float c = 52.5155;
    	float d = 126.1986;
    	float mul = 4375.5453123;
    	float2 dts = dot(_st, float2(a, b));
            float2 dtc = dot(_st, float2(c, d));
    	float2 sn = sin(dts) * mul;
            float2 cs = cos(dtc)*mul;
    	float frc = frac(sn + cs) ;
    	
    	return frc;
    }

second :

float random(float2 _st)
{
	float a = 12.9898;
	float b = 70.2332;
	float mul = 4375.5453123;
	float2 dt = dot(_st, float2(a, b));
	float2 sn = sin(dt) * mul;
	float frc = frac(sn) ;
	
	return frc ;
}

Thanks guys and @MrValentine :wink:

2 Likes

Use a noise texture

One texture fetch will be faster than all that code

Hi @Stainless

J’ai essayé de prendre une texture toute faite mais le soucis que j’ai, c’est que je n’ai plus l’effet nuage, mais j’ai des lignes à la place :frowning:

En passant par ma fonction je suis à 0.47ms/frame, et avec la texture je suis à 0.41ms/frame.
Je dois sûrement mal m’y prendre mais à part récupérer la position en x ou en y de ma texture je ne vois pas bien comment faire.
Merci quand même pour ton aide :wink:

I tried to take a noise texture, but I loose my cloud effect, I have lines now :frowning:
With my noise function I have 0.47ms/frame and with a texture 0.41ms/frame.
I make something badly but except to take x and y position of my texture i don’t know what I can do.

float noiseTex2D(float st)
{
	return tex2D(NoiseSampler, st * factor ).x;
}

Here my noise function :

float noise(float2 st)
{
	float2 i = floor(st);
	float2 f = frac(st);	
	float a = random(i);
	float b = random(i + (float2(1.0, 0.0)));
	float c = random(i + (float2(0.0, 1.0)));
	float d = random(i + (float2(1.0, 1.0)));

	float2 u = f * f *(3.0 - 2.0 * f);
	return lerp(a, b, u.x) + (c - a) * u.y * (1.0 - u.x) + (d - b) * u.x * u.y;
}

Unfortunately tex2D.x != lerp()+...

Thanks anyway :wink:

Two things here,

  • What is in your noise texture?

    Since it is just a texture you can do a lot with it. You can use a floating point texture and fill it with a single random value, or you can leave it as a RGBA texture but put different values in each term. So X is random value. Y is average of nearest 4 pixels, Z is average of nearest 8 pixels, W average of nearest 16 pixels. You can also do things like generate mipmaps and use them in your noise calculation.

Since perlin noise is basically blended noise, using mipmaps can do a lot of the hard work for you.

  • You can’t just replace a smoothed noise function with a single random value

The noiseTex2D function you added looks all wrong for a start , it should take a float2 not a float.
Also for smoothed noise done this way you should be replacing the random function with the texture fetch

I would have a look around online for tutorials on noise and how to use a noise texture for perlin noise

Hi @Stainless :slight_smile:

C’est une texture prise sur le net, mais j’en créée une avec Photoshop, j’ai enlevé tous mes tests bizarres et ça va beaucoup mieux :slight_smile:

J’ai également remis le float2 en passage à ma fonction et non plus le float :wink:
Et je suis revenu à 0.38ms/frame avec 5 itérations, c’est pas mal je pense.

I took a texture on the web, but I created my own texture with photoshop, delete all my weird test and its really better :slight_smile:

I put back my float2 to my function :wink:
Now I have 0.38ms/frame, it’s not bad I think.

float noiseTex2D(float2 st)
{
	return tex2D(NoiseSampler, st * factor );
}

Oui merci, j’ai lu cela sur ce PDF mais je n’ai pas très bien compris il faisait pour mettre 4 textures en une seule, sur Photoshop j’ai essayé de modifier les couches mais sans succés :frowning:
J’ai également essayé avec les 4 textures séparés mais cela ne fonctionne pas très bien, je dois louper quelque chose dans l’implentation mais quoi ?

Yes thanks, I read this on a PDF, but I don’t really understand how he can put 4 texture on one, I tried to modify the layers on Photoshop but without success :frowning:
I tried too with 4 texture separatly but It’s not what I expected, I miss something on implentation but what?

Here is PDF link
https://www.researchgate.net/publication/220982572_Clouds_and_stars_efficient_real-time_procedural_sky_rendering_using_3D_hardware

Thanks :slight_smile:

Thanks guys :slight_smile:

When it comes to random textures, I don’t use graphics packages, I generate them in code

It’s a nightmare to use the alpha channel as an input when using a graphics package

So for things like physically based rendering where you have a mapping something like

x = Metalic
y = Roughness
z = Ambient occlusion
w = Self illumination

I generally generate by hand 3 textures for x,y,and w then write a tool to generate AO and combine the 4 generated textures into a single texture to be used in game

You can do exactly the same for any texture you want to use as an input to a shader

For example

float [] GenerateRoughNoise(int width, int height)
{
   float [] rough = new float[width * height];
   int pos=0;
   for (y=0; y<height; y++)
   {
          for (x=0; x<width; x++)
          {
                   rough[pos++]=(float)Rand.NextDouble();
          }
   }
  return rough;
}

Will give you an array of random floats.

Then you could do something like

float[] rough = GenerateRoughNpise(width,height);
float[] smooth1 = SmoothNoise(width,height,rough);
float[] smooth2 = SmoothNoise(width,height,smooth1);
float[] smooth3 = SmoothNoise(widht,height,smooth2);

SmoothNoise just does a blend of the supplied array and returns a new array.
By calling it multiple times to increase the blending much as is done when generating mipmaps but without the change in resolution

Then you just need to generate a texture from that

Texture2D res = new Texture2D(GraphicsDevice,width,height,SurfaceFormat.Color);
Color[] data = ConvertToColor(rough,smooth1,smooth2,smooth3);
res.SetData<Color>(data);

Or …

Texture2D res = new Texture2D(GraphicsDevice,width,height,SurfaceFormat.Vector4);
Vector4[] data = ConvertToVector4(rough,smooth1,smooth2,smooth3);
res.SetData<Vector4>(data);

You see what I mean?

Much easier than messing about with an art package :smile: