glob2-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [glob2-devel] To Erik: My Profiling Information


From: Kai Antweiler
Subject: Re: [glob2-devel] To Erik: My Profiling Information
Date: Tue, 11 Sep 2007 00:53:34 +0200

I don't know that code and I don't much about how efficient cpus
calculate mathematics,
but I state some ideas anyway:

> i did maths so i would have plenty of ideas to make the clouds prettier and 
> more
> structured but it gets too expensive even now.

You could try to compile the dynamic cloud files with the gcc's
-ffast-math flag.


> (a=f(x,y,t), r=g=b=sin(t)*df/dx+cos(t)*df/dy+128 to get clouds lit from a
> wandering sun. as nobody knows how shadows are drawn on a torus with a sun, 
> this
> should maybe not be done using sin/cos ;)

Don't worry to much about this.  Globs live on a topological torus -
geometrically our torus
cannot exist.

Looks like you use a small Taylor polynomials for cos and calculate it using the
Horner scheme.  I don't think this can be made faster.
Or could we use some discrete calculation for approximation?


PerlinNoise.cpp:

1.
unsigned PerlinNoise::permutationTable[ NOISE_WRAP_INDEX*2 + 2 ] = { 0 };
We could use a left shift:
unsigned PerlinNoise::permutationTable[ NOISE_WRAP_INDEX<<1 + 2 ] = { 0 };


2.
Instead of:
  float val, amp = 1.0, sum = 0.0;
  for ( int i = 0;i < oct;i++, amp *= 0.5, tp *= 2.0 ) {
    val = Noise3d( f_tp );
    if ( hard ) val = fabs( val );
    sum += amp * val;
  }
  return 0.5 + 0.5*( sum * ( ( float ) ( 1 << oct ) / ( float ) ( ( 1
<< ( oct + 1 ) ) - 1 ) ) );

We could try:
  float val, sum = 0.0;
  for ( int i = 0;i < oct;i++, tp *= 2.0 ) {
    val = Noise3d( f_tp );
    if ( hard ) val = fabs( val );
    sum += val / (float) (1<<i);
  }
  return 0.5 + 0.5*( sum * ( ( float ) ( 1 << oct ) / ( float ) ( ( 1
<< ( oct + 1 ) ) - 1 ) ) );

But that is probably worse.
Hey why isn't there a thing like float-shift?  After all this would
only require to add/subtract 1 from the exponent!
Google tells me there is such a thing:
/**
 * While we're on the subject, someone might have use for these as well?
 * Float Shift Left and Float Shift Right. Do what you want with this.
 */
void fast_BSL(double &x, register unsigned long shiftAmount) {

        *(unsigned long*)&x+=shiftAmount<<23;

}

void fast_BSR(double &x, register unsigned long shiftAmount) {

        *(unsigned long*)&x-=shiftAmount<<23;

}
http://mail.flightgear.org/pipermail/simgear-cvslogs/2003-June/000533.html


3.
DynamicClouds.cpp:
vpX += (viewPortX-vpX%64+96)%64-32;
This might be faster using a mask:
vpX += (viewPortX-vpX&63+96)&63-32;
-- 
Kai Antweiler




reply via email to

[Prev in Thread] Current Thread [Next in Thread]