Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 7784 in orxonox.OLD


Ignore:
Timestamp:
May 24, 2006, 2:59:44 AM (18 years ago)
Author:
amaechler
Message:

branches/atmospheric_engine: random animated and generated clouds, veerrryyyy slow hmm

Location:
branches/atmospheric_engine/src/lib/graphics/effects
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/atmospheric_engine/src/lib/graphics/effects/cloud_effect.cc

    r7782 r7784  
    1919
    2020#include "glincl.h"
    21 #include "graphics_engine.h"
    22 
     21//#include "graphics_engine.h"
    2322
    2423#include "parser/tinyxml/tinyxml.h"
     
    4847{
    4948        WeatherEffect::loadParams(root);
     49
     50        LoadParam(root, "animSpeed", this, CloudEffect, setCloudAnimation);
     51
    5052}
    5153
     
    5355bool CloudEffect::init()
    5456{
    55         //Default values
    56 
    57         CloudEffect::setNoise(map32);
    58 
    59 }
    60 
    61 bool CloudEffect::activate()
    62 {
    63         PRINTF(0)( "Activating CloudEffect\n");
    64 
    65         //Our cloud function 
    66         CloudEffect::overlapOctaves(map32, map256);
    67         CloudEffect::expFilter(map256);
    68 
    69         for(int i=0; i<256; i++)         //Set cloud color value to temporary array
    70                 for(int j=0; j<256; j++)
    71                 {
    72                         float color = map256[i*256+j];
    73                         texture[i][j][0] = (char) color;
    74                         texture[i][j][1] = (char) color;
    75                         texture[i][j][2] = (char) color;
    76                 }
    77 
    78                 /* for(int n=0; n<256; n++) {
    79                         for(int i=0; i<256; i++)
    80                                 PRINTF(0)("%f ", map256[n*i]);
    81                         PRINTF(0)("\n");
    82                 } */
     57        // default values
     58        this->cloudAnimTimeStep = 0;
    8359
    8460        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
     
    8763        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
    8864
    89         glGenTextures(1, &texID[0]);           //Texture binding
     65        // Generate noise map a
     66        CloudEffect::genNoiseMap(cloudMap32_a);
     67       
     68        if (this->cloudAnimTimeStep > 0) {
     69                // Generate noise map b
     70                CloudEffect::genNoiseMap(cloudMap32_b);
     71        }
     72}
     73
     74bool CloudEffect::activate()
     75{
     76        PRINTF(0)( "Activating CloudEffect\n");
     77        if (this->cloudAnimTimeStep == 0) {
     78                for (int i = 0; i < 32*32; i++)
     79                        cloudMap32_c[i] = cloudMap32_a[i];
     80
     81                CloudEffect::overlapOctaves();
     82                CloudEffect::expFilter();
     83                CloudEffect::genCloudTexture();
     84        }
     85}
     86
     87bool CloudEffect::deactivate()
     88{
     89        PRINTF(0)("Deactivating CloudEffect\n");
     90}
     91
     92void CloudEffect::genCloudTexture() {
     93        for(int i=0; i<256; i++)
     94                for(int j=0; j<256; j++)
     95                {
     96                        float color = cloudMap256[i*256+j];
     97                        cloudTexture[i][j][0] = (char) color;
     98                        cloudTexture[i][j][1] = (char) color;
     99                        cloudTexture[i][j][2] = (char) color;
     100                }
     101
     102        glGenTextures(2, &texID[0]);
    90103        glBindTexture(GL_TEXTURE_2D, texID[0]);
    91        
    92         gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGB, 256, 256, GL_RGB, GL_UNSIGNED_BYTE, texture);
    93 }
    94 
    95 
    96 bool CloudEffect::deactivate()
    97 {
    98         PRINTF(0)("Deactivating CloudEffect\n");
     104        gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGB, 256, 256, GL_RGB, GL_UNSIGNED_BYTE, cloudTexture);
     105}
     106
     107void CloudEffect::calcAnimMap(float timer) {
     108
     109        for (int x=0; x<32*32; x++)
     110                cloudMap32_c[x] = (cloudMap32_a[x] * ((this->cloudAnimTimeStep - timer) / this->cloudAnimTimeStep)) + (cloudMap32_b[x] * (timer / this->cloudAnimTimeStep));
     111
    99112}
    100113
    101114void CloudEffect::draw() const
    102115{
    103         //glPushAttrib(GL_ENABLE_BIT);
    104         //glMatrixMode(GL_MODELVIEW);
    105 
    106116        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    107117
     
    109119        glEnable(GL_TEXTURE_2D);
    110120
    111         //glLoadIdentity();
    112121        glBindTexture(GL_TEXTURE_2D, texID[0]);
    113122
    114         //glMatrixMode(GL_TEXTURE);        //Let's move the clouds from left to right
    115         //static float x;   
    116         //x+=0.01f;
    117         //glTranslatef(x,0,0);
    118 
     123        // FIXME : Bind this to the sky - how do I do this?
    119124        glBegin(GL_QUADS);
    120                 // Front Face
    121125                glTexCoord2f(0.0f, 0.0f); glVertex3f(20, 20,  60);      // Bottom Left Of The Texture and Quad
    122126                glTexCoord2f(1.0f, 0.0f); glVertex3f(60, 20,  60);      // Bottom Right Of The Texture and Quad
     
    126130
    127131        glPopMatrix();
    128         //glPopAttrib();
    129 
    130132}
    131133
    132134void CloudEffect::tick (float dt)
    133135{
     136        if (this->cloudAnimTimeStep > 0) {
     137                if (timer >= this->cloudAnimTimeStep) {
     138                        timer -= this->cloudAnimTimeStep;
     139                        for (int i = 0; i < 32*32; i++)
     140                                cloudMap32_a[i] = cloudMap32_b[i];
     141                        CloudEffect::genNoiseMap(cloudMap32_b);
     142                }
     143
     144                //map32anim = (map32a * (10 - timer)) + (map32b * timer);
     145                CloudEffect::calcAnimMap(timer);
     146
     147                CloudEffect::overlapOctaves();
     148                CloudEffect::expFilter();
     149                CloudEffect::genCloudTexture();
     150
     151                timer += dt;
     152        }
    134153}
    135154
     
    148167        Set noise for the 32*32 noise map:
    149168*/
    150 void CloudEffect::setNoise(float  *map)
     169void CloudEffect::genNoiseMap(float  *map)
    151170{
    152171        float temp[34][34];
    153 
    154 /* We declare a temporary array to make our function cleaner. Why does the array hold 34*34 elements instead of 32*32? This is because we will need extra elements for side and corner mirroring, as we shall see soon. */
    155172
    156173        int random = rand() % 5000;
     
    181198                        float corners = (temp[x+1][y+1] + temp[x+1][y-1] + temp[x-1][y+1] + temp[x-1][y-1])/16.0f;
    182199
    183                         map32[((x-1)*32) + (y-1)] = center + sides + corners;
     200                        map[((x-1)*32) + (y-1)] = center + sides + corners;
    184201                }
    185202}
     
    211228        Octaves are overlapped together to give cloud more turbulence. We will use four octaves for our cloud.
    212229*/
    213 void CloudEffect::overlapOctaves(float  *map32, float  *map256)
     230void CloudEffect::overlapOctaves()
    214231{
    215232        for (int x=0; x<256*256; x++)
    216233        {
    217                 map256[x] = 0;
     234                cloudMap256[x] = 0;
    218235        }
    219236
     
    223240                        {
    224241                                float scale = 1 / pow(2, 3-octave);
    225                                 float noise = CloudEffect::interpolate(x*scale, y*scale , map32);
     242                                float noise = CloudEffect::interpolate(x*scale, y*scale , cloudMap32_c);
    226243
    227244                                //The octaves are added together with the proper weight factors.
    228245                                //You could replace pow(2, i) with 1<<i for faster computation
    229                                 map256[(y*256) + x] += noise / pow(2, octave);
     246                                cloudMap256[(y*256) + x] += noise / pow(2, octave);
    230247                        }
    231248}
     
    235252        Filter the noise with exponential function
    236253*/
    237 void CloudEffect::expFilter(float  *map)
     254void CloudEffect::expFilter()
    238255{
    239256        float cover = 20.0f;
     
    242259        for (int x=0; x<256*256; x++)
    243260        {
    244                 float c = map[x] - (255.0f-cover);
     261                float c = cloudMap256[x] - (255.0f-cover);
    245262                if (c<0)     c = 0;
    246                 map[x] = 255.0f - ((float)(pow(sharpness, c))*255.0f);
    247         }
    248 }
     263                cloudMap256[x] = 255.0f - ((float)(pow(sharpness, c))*255.0f);
     264        }
     265}
     266
     267
  • branches/atmospheric_engine/src/lib/graphics/effects/cloud_effect.h

    r7782 r7784  
    3030                virtual void tick(float dt);
    3131
     32                inline void setCloudAnimation(float timestep) { this->cloudAnimTimeStep = timestep; }
     33
    3234        private:
    33                 // Basic noise map 32x32
    34                 float map32[32 * 32];
     35                // Basic noise maps 32x32
     36                float                                                                                                           cloudMap32_a[32 * 32];
     37                float                                                                                                           cloudMap32_b[32 * 32];
     38                float                                                                                                           cloudMap32_c[32 * 32];
    3539
    36                 // The cloud map
    37                 float map256[256 * 256];
     40                // The cloud map 256x256
     41                float                                                                                                           cloudMap256[256 * 256];
    3842
    39                 char texture[256][256][3];       //Temporary array to hold texture RGB values
     43                // Temporary array to hold texture RGB values
     44                char                                                                                                                    cloudTexture[256][256][3];
    4045
    41                 float noise(int x, int y, int random);
    42                 void setNoise(float  *map);
    43                 float interpolate(float x, float y, float  *map);
    44                 void overlapOctaves(float  *map32, float  *map256);
    45                 void expFilter(float  *map);
    46                 GLuint texID[1];
     46                GLuint                                                                                                          texID[2];
     47                float                                                                                                           timer;
     48
     49                bool                                                                                                                    cloudAnimTimeStep;
     50
     51                float                                                                                                           noise(int x, int y, int random);
     52                float                                                                                                           interpolate(float x, float y, float  *map);
     53                void                                                                                                            overlapOctaves();
     54                void                                                                                                            expFilter();
     55
     56                void                                                                                                            genNoiseMap(float  *map);
     57                void                                                                                                            genCloudTexture();
     58                void                                                                                                            calcAnimMap(float timer);
    4759
    4860};
  • branches/atmospheric_engine/src/lib/graphics/effects/rain_effect.cc

    r7696 r7784  
    7474        WeatherEffect::loadParams(root);
    7575
    76         // LoadParam(root, "moverain", this, RainEffect, setMoveRain);
    7776        LoadParam(root, "coord", this, RainEffect, setRainCoord);
    7877        LoadParam(root, "size", this, RainEffect, setRainSize);
Note: See TracChangeset for help on using the changeset viewer.