Wolf3d Haven Forum

Please log in or register. Smile

Join the forum, it's quick and easy

Wolf3d Haven Forum

Please log in or register. Smile

Wolf3d Haven Forum

Would you like to react to this message? Create an account in a few clicks or log in to continue.
Wolf3d Haven Forum

A friendly Wolfenstein 3D community, about Wolfenstein 3D, the game that gave birth to first person shooters...


+5
Imed
doomjedi
AlumiuN
linuxwolf
mar
9 posters

    [Tutorial] Advanced shading

    avatar
    WLHack
    Senior Member
    Senior Member


    Male
    Number of posts : 800
    Age : 35
    Location : Finland
    Registration date : 2007-03-26

    [Tutorial] Advanced shading Empty [Tutorial] Advanced shading

    Post by WLHack Sat Mar 09, 2013 11:18 am

    Time for the long waited tutorial... In this tutorial I will tell you
    how to get tile-based shading ála the_fish to work in your Wolf3D game...
    Spoiler:
    NOTE:
    If you use this code in your game, remember to credit Adam Biser,
    AlumiuN, the_fish and WSJ... Also I haven't got the 4th plane working yet
    but I am posting this tutorial anyway so if someone manages to get it
    work before I do, s/he can complete this tutorial.

    Also this tutorial is really long and complicated so here is the full source (Wolf4SDL v1.7)
    containing the necessary coding changes (not including the pickable flashlight).

    Oh, and you shouldn't use advanced shading without textured floor/ceiling as the flashlights light
    isn't working that great with solid color floor/ceiling.

    Anyway... Let's begins...



    First open version.h and search for this line:
    Code:

      #define USE_SHADING         // Enables shading support (see wl_shade.cpp)
    Underneath it add these lines:
    Code:

      #define USE_ADVSHADES       // Enables advanced shading
    //#define USE_4THPLANE        // Enables 4th plane for shading (not working yet)



    Then open wl_def.h and search for "gamestate structure"...
    Add these lines to that struct:
    Code:

    #ifdef USE_ADVSHADES
        bool        flashlight;
    #endif
    Then in the same file search for "typedef struct statestruct" and add these lines
    to the end of that struct (just below "struct  statestruct *next;"):
    Code:

    #ifdef USE_SHADING
        boolean fullbright;         // WSJs lightning effects...
    #endif
    Now search for "SpawnBJVictory (void);" and add following lines under it:
    Code:

    #ifdef USE_SHADING
    void T_LightEnemy(objtype *ob);
    #endif
    Then at the end of wl_def.h search for this block:
    Code:

    #ifdef USE_DIR3DSPR
        void Scale3DShape(byte *vbuf, unsigned vbufPitch, statobj_t *ob);
    #endif
    And change it to this:

    Code:

    #ifdef USE_DIR3DSPR
        void Scale3DShape(byte *vbuf, unsigned vbufPitch, statobj_t *ob
    #ifdef USE_ADVSHADES
                          ,int tx = 0, int ty = 0, int fx = 0, int fy = 0);
    #endif
                          );
    #endif
    Finally add these lines just after the block above:
    Code:

    #ifdef USE_SHADING
    extern int lightMap[MAPSIZE][MAPSIZE];
    #endif
    And then you can close wl_def.h ...




    When you have done that, open wl_state.cpp search
    for "MoveObj (objtype *ob" (should be near the beginning of the file) and
    add these lines:
    Code:

    #ifdef USE_SHADING
    void     T_LightEnemy(objtype *ob);
    #endif
    Then search for "= MoveObj" and add this block above it:
    Code:

    /*
    =======================
    =
    = T_LightEnemy
    =
    = Check if actor walked under lamp and then
    = try illuminate actor...
    =
    = NOTE: This is bit unnecessary with advanced shading
    = as the actors are shaded like objects.
    =
    =======================
    */
    #ifdef USE_SHADING
    void T_LightEnemy(objtype *ob)
    { // Check for lightsources in actors tile:
         if(lightMap[ob->tilex][ob->tiley]>240)      
            ob->state->fullbright = true;        
         else  
            ob->state->fullbright = false;
    }
    #endif
    Then go to the "MoveObj" function just few lines below and add
    these line at the beginning of that function:
    Code:

    #ifdef USE_SHADING
        T_LightEnemy(ob);
    #endif
    Finally search for "= KillActor" and in the end of that function add
    these lines to make the corpse light up if underneath a light source:
    Code:

    #ifdef USE_SHADING
        T_LightEnemy(ob); //Light the corpse up?
    #endif
    Now you can close wl_state.cpp....




    To make the enemies lit up when shooting, open wl_act2.cpp
    and search for "SPR_GRD_SHOOT3"... You should see something like this:
    Code:

    statetype s_grdshoot3           = {false,SPR_GRD_SHOOT3,20,NULL,NULL,&s_grdchase1};
    Change that line to this:
    Code:

    #ifdef USE_SHADING
    statetype s_grdshoot3           = {false,SPR_GRD_SHOOT3,20,NULL,NULL,&s_grdchase1,true};
    #else
    statetype s_grdshoot3           = {false,SPR_GRD_SHOOT3,20,NULL,NULL,&s_grdchase1};
    #endif
    Now search for "SPR_OFC_SHOOT3", "SPR_MUT_SHOOT2", "SPR_MUT_SHOOT4", "SPR_SS_SHOOT3"
    and make similar changes... Also remember to go through the bosses and projectiles
    (prefer the file in the packaged source for all changes).

    Close the wl_act2.cpp...




    Now when that is done, open wl_game.cpp and search for "died"...
    In the died function, search for this line:
    Code:

            gamestate.ammo = STARTAMMO;
    And add these lines under it:
    Code:

    #ifdef USE_ADVSHADES
            gamestate.flashlight = false; //Reset flashlight
    #endif
    Then in the same file search for "case ex_completed:" and underneath
    Code:

                    gamestate.keys = 0;
    Add these lines:
    Code:

    #ifdef USE_ADVSHADES
                     gamestate.flashlight = false; //Reset flashlight
    #endif
    Thats it for the wl_game.cpp




    Now open wl_main.cpp and search for "new game" and
    in that function search for this line:
    Code:

        gamestate.ammo = STARTAMMO;
    And add these lines under it:
    Code:

    #ifdef USE_ADVSHADES
        gamestate.flashlight = false; //Reset flashlight
    #endif
    Now we are done in wl_main.cpp...




    Open wl_play.cpp and scroll to "GLOBAL VARIABLES"...
    Add these lines under "madenoise":

    Code:

    #ifdef USE_SHADING
    int lightMap[MAPSIZE][MAPSIZE];
    #endif
    Then search for "SECRET CHEAT CODE: 'MLI'" and above that add:
    Code:

    #ifdef USE_ADVSHADES
        //
        // Flashlight
        //
        if(Keyboard[sc_Z])
        {  gamestate.flashlight ^= 1;
           Keyboard[sc_Z]=false;
           return;
        }
    #endif
    Now you can close the wl_play.cpp...




    To prevent player from assigning some other function for the 'Z'-key,
    open wl_menu.cpp and search for "case KEYBOARDBTNS:" (approx. line 2335).
    The change this line:
    Code:

                            if (LastScan && LastScan != sc_Escape)
    To this:
    Code:

    #ifdef USE_ADVSHADES
                            if (LastScan && (LastScan != sc_Escape || LastScan != sc_Z))
    #else
                            if (LastScan && LastScan != sc_Escape)
    #endif
    Do the same for the if-clause just a few lines below that in case "KEYBOARDMOVE"...

    Now we are done in wl_menu.cpp...




    Okay... This is the part where things are starting to get interesting...
    Open wl_shade.h and under this line:
    Code:

    extern uint8_t shadetable[SHADE_COUNT][256];
    Add these lines:
    Code:

    #ifdef USE_ADVSHADES
    extern double lightflash;
    #endif
    Go down few more lines and change this line:
    Code:

    int GetShade(int scale);
    Code:

    int GetShade(int scale
    #ifdef USE_ADVSHADES
       ,int dx=0, int dy=0,int tx1=0, int ty1=0, int tx2=0,int ty2=0, byte sx=64, byte sy=64
    #endif
       );
    Now you can close wl_shade.h.




    Next up is wl_shade.cpp. In that file under "int LSHADE_flag;" add these lines:
    Code:

    #ifdef USE_ADVSHADES
    double lightflash = 0;
    #endif
    Then scroll down to the InitLevelShadeTable - function add these lines above it:
    Code:

    #ifdef USE_ADVSHADES
    void InitLevelShadeMap(void);
    #endif
    And in the end of the InitLevelShadeTable - function add:
    Code:

    #ifdef USE_ADVSHADES
      //Fill the lightmap:
        InitLevelShadeMap();
    #endif
    Then go to the GetShade - function and replace it with this:
    Code:

    #ifdef USE_ADVSHADES
    double inline GetLightFrag(int x, int y, int tx, int ty, byte sx, byte sy);
    double inline FlashlightIntensity(int scale, double radius);
    int GetShade(int scale,int dx,int dy,int tx1, int ty1,int tx2, int ty2, byte sx, byte sy)
    {   int16_t shade;              
      //Count light fraction...  
        double pixradius = (dx*dx + dy*dy*1.4)/viewwidth;
        double lightfrag = GetLightFrag(tx1,ty1,tx2,ty2,sx,sy)/256;
      //...and limit it:
        if(lightfrag > 1) lightfrag = 1;
        if(lightfrag < 0) lightfrag = 0;
        
        if(gamestate.flashlight && pixradius < 12)
           shade = (int)(SHADE_COUNT*(FlashlightIntensity(scale, pixradius)+lightfrag+lightflash));
        else
           shade = (int)(SHADE_COUNT*(lightfrag+lightflash));
    #else    
    int GetShade(int scale)
    {
        int shade = (scale >> 1) / (((viewwidth * 3) >>  + 1 + LSHADE_flag);  // TODO: reconsider this...  
    #endif
        if(shade > SHADE_COUNT) shade = SHADE_COUNT;
        else if(shade < 1) shade = 1;

        shade = SHADE_COUNT - shade;
        return shade;
    }
    Then add the end of the wl_shade.cpp, just before the last #endif add this:
    Code:

    //
    //Get light fraction, based on the_fish's code:
    #ifdef USE_ADVSHADES
    double inline GetLightFrag(int x, int y, int tx, int ty, byte sx, byte sy){
      
       double tx1, ty1, tx2, ty2;

       if (tx > x || ty > y){
           tx1 = 0.5-((double)sx/TEXTURESIZE);
           ty1 = ((double)sy/TEXTURESIZE)-0.5;      
       }else{
           tx1 = ((double)sx/TEXTURESIZE*)-0.5;
           ty1 = 0.5-((double)sy/TEXTURESIZE);
       }
      
       tx2 = 1-fabs(tx1);
       ty2 = 1-fabs(ty1);
      

       if(tx1 > 0){
          if(ty1 > 0)
             return ((lightMap[x][y]   * (tx2*ty2)) + (lightMap[x+1][y]   * (tx1*ty2)) +
                     (lightMap[x][y+1] * (tx2*ty1)) + (lightMap[x+1][y+1] * (tx1*ty1)));    
          else{
             ty1 *= -1;
             return ((lightMap[x][y]   * (tx2*ty2)) + (lightMap[x+1][y]   * (tx1*ty2)) +
                     (lightMap[x][y-1] * (tx2*ty1)) + (lightMap[x+1][y-1] * (tx1*ty1)));            
          }
       }else{
          tx1 *= -1;
          if(ty1 > 0)
             return ((lightMap[x][y]   * (tx2*ty2)) + (lightMap[x-1][y]   * (tx1*ty2)) +
                     (lightMap[x][y+1] * (tx2*ty1)) + (lightMap[x-1][y+1] * (tx1*ty1)));          
          else{
             ty1 *= -1;
             return ((lightMap[x][y]   * (tx2*ty2)) + (lightMap[x-1][y]   * (tx1*ty2)) +
                     (lightMap[x][y-1] * (tx2*ty1)) + (lightMap[x-1][y-1] * (tx1*ty1)));            
          }    
       }  return 0;      
    }
    //
    //Get the intensity of flashlight, based on the_fish's code:
    double inline FlashlightIntensity(int scale, double radius){
       return (scale*scale) * (1 - (radius/12)*(radius/12)) / (1000);      
    }
    //
    //Fill the lightmap from either objects or 4th-plane:
    void InitLevelShadeMap(){
       for(int x=0;x<MAPSIZE;x++)
       { for(int y=0;y<MAPSIZE;y++)
         {  
    #ifdef USE_4THPLANE
             lightMap[x][y] = MAPSPOT(x,y,3);
    #else
              switch(MAPSPOT(x,y,1))
              {  
                  case 26:   //Floor lamp
                  case 27:   //Chandelier
                  case 37:   //Green lamp
    #ifdef WOLF
                  case 68:   //Stove      
    #else
    #ifdef SPEAR
                  case 63:   //Red lamp
                  case 74:   //Spear of Destiny
    #endif
    #endif
                     //Light sources cast light:
                       lightMap[x-1][y]=215; lightMap[x+1][y]=215;
                       lightMap[x][y-1]=215; lightMap[x][y+1]=215;
                       lightMap[x][y]=255;
                   break;
               }  
             //Generic shadevalues for the level
             //if(lightMap[x][y] == 0) lightMap[x][y] = 150;  
    #endif  
           }
       }  
    }
    #endif
    Now our work is done in the wl_shade.cpp, so close it...




    It is time to change the wl_draw.cpp, so open the file
    and just below "GLOBAL VARIABLES" add these lines:
    Code:

    #define MAXVISABLE 250

    typedef struct
    {
        short      viewx,
                   viewheight,
                   shapenum;
    #ifdef USE_ADVSHADES
        byte       x,y;            // Get the current tile of object
    #endif    
        short      flags;          // this must be changed to uint32_t, when you
                                   // you need more than 16-flags for drawing
    #ifdef USE_DIR3DSPR
        statobj_t *transsprite;
        objtype   *transactor;
    #endif
    } visobj_t;

    visobj_t vislist[MAXVISABLE];
    visobj_t *visptr,*visstep,*farthest;
    Now search for the "#define MAXVISABLE 250" and remove the lines similar to the ones
    you just added (should be just above the DrawScaleds-function)...

    Return back to the global variables and add these lines just above "3 - D Definitions":
    Code:

    int texture;
    //Shading variables for the_fish's advanced shading
    #ifdef USE_ADVSHADES
    int tmpX,tmpY,faceX,faceY;
    byte sdwX, sdwY;
    bool isHoriz;
    void inline GetTileCoords();
    bool inline GetLight(int shapenum, uint32_t flags);
    #endif
    Now search for "int texture" in wl_draw.cpp, and remove those lines
    (should be 4 - 6 instances not including the line you just added)...

    When that is done, add these lines to the very end of the file:
    Code:

    /*
    ========================
    =
    = GetTileCoords()
    =
    = Set the face/tmp X/Y values
    = Basef on the_fish's routine
    =
    ========================
    */
    #ifdef USE_ADVSHADES
    void inline GetTileCoords(){
      if (!isHoriz)
        {
            faceY = tmpY;
            if (player->x >> (TILESHIFT-1) > (tmpX*2))
                faceX = tmpX+1;
            else
                faceX = tmpX-1;            
        }
        else
        {  
            faceX = tmpX;
            if (player->y >> (TILESHIFT-1) > (tmpY*2))  
                faceY = tmpY+1;
            else
                faceY = tmpY-1;
        }
    }
    /*
    ========================
    =
    = GetLight()
    =
    = Check whether to lit the object
    =
    ========================
    */
    bool inline GetLight(int shapenum, uint32_t flags){
         if(flags & FL_FULLBRIGHT) return true;
         switch (shapenum){
           //Add here sprites you want to light but you can't set
           //with FL_FULLBRIGHT-flag (e.g. animation frames):
             case 0:
             case 1:
                  return true;
                  break;
            
        }   return false;  
    }
    #endif
    Now when that is done, it is finally time to alter the shading...
    Go back up till you find the ScalePost - function and in that function
    change these lines:
    Code:

    #ifdef USE_SHADING
        byte *curshades = shadetable[GetShade(wallheight[postx])];
    #endif
    To these:
    Code:

    #ifdef USE_SHADING
    #ifdef USE_ADVSHADES
        int  vHeight = 0, vWidth = 0;
    #endif
        byte *curshades = shadetable[GetShade(wallheight[postx])];
    #endif
    Now go few lines down and change this:
    Code:

    #ifdef USE_SHADING
        col = curshades[postsource[yw]];
    To this:
    Code:

    #ifdef USE_SHADING
    #ifdef USE_ADVSHADES
        vWidth  = pixx-(viewwidth/2);
        vHeight = (yendoffs/vbufPitch)-(viewheight/2);
        if(!isHoriz){
            sdwX = TEXTURESIZE/2;
            sdwY = texture>>TEXTURESHIFT;
        }else{
            sdwX = texture>>TEXTURESHIFT;
            sdwY = TEXTURESIZE/2;
        }   curshades = shadetable[GetShade(yd,vWidth,vHeight,faceX,faceY,tmpX,tmpY,sdwX,sdwY)];
    #endif
        col = curshades[postsource[yw]];
    Still in ScalePost go down few lines more and when you see this again:
    Code:

    #ifdef USE_SHADING
                col = curshades[postsource[yw]];
    Change it to this:
    Code:

    #ifdef USE_SHADING
    #ifdef USE_ADVSHADES
                if(gamestate.flashlight){
                   vHeight = (yendoffs/vbufPitch) - (viewheight/2);                      
                   curshades = shadetable[GetShade(yd,vWidth,vHeight,faceX,faceY,tmpX,tmpY,sdwX,sdwY)];
                }  
    #endif
                col = curshades[postsource[yw]];
    Now when that is done, go to the HitVertWall - function and add these lines:
    Code:

    #ifdef USE_ADVSHADES
        isHoriz = false; GetTileCoords(); //Set horizontal flag
    #endif
    Under this block:
    Code:
        texture = ((yintercept+texdelta)>>TEXTUREFROMFIXEDSHIFT)&TEXTUREMASK;
        if (xtilestep == -1)
        {
            texture = TEXTUREMASK-texture;
            xintercept += TILEGLOBAL;
        }
    Then in HitHorizWall - function add these lines under "int wallpic;":
    Code:

    #ifdef USE_ADVSHADES
        isHoriz = true; GetTileCoords(); //Set horizontal flag
    #endif
    Go to the HitHorizDoor - function and add these lines under "int doornum;":
    Code:

    #ifdef USE_ADVSHADES
        isHoriz = true; GetTileCoords(); //Set horizontal flag
    #endif
    And in HitVertDoor add these lines under "int doornum;":
    Code:

    #ifdef USE_ADVSHADES
        isHoriz = false; GetTileCoords(); //Set horizontal flag
    #endif
    NOTE: if your code has HitHorizPWall and HitVertPWall then remember to
    add these lines under "int wallpic" (isHoriz must be TRUE for HitHorizPWall):
    Code:

    #ifdef USE_ADVSHADES
        isHoriz = false; GetTileCoords(); //Set horizontal flag
    #endif
    When that is done, go down to the ScaleShape - function and change this block:
    Code:

    #ifdef USE_SHADING
        byte *curshades;
        if(flags & FL_FULLBRIGHT)
            curshades = shadetable[0];
        else
            curshades = shadetable[GetShade(height)];
    #endif
    To this:
    Code:

    #ifdef USE_SHADING
        byte *curshades;
    #ifdef USE_ADVSHADES
        bool isLight = GetLight(shapenum,flags);
    #else
        if(flags & FL_FULLBRIGHT)
            curshades = shadetable[0];
        else
            curshades = shadetable[GetShade(height)];
    #endif
    #endif
    Still in ScaleShape scroll down till you see this:
    Code:

    #ifdef USE_SHADING
                                    col=curshades[((byte *)shape)[newstart+j]];
    And change it to this:
    Code:

    #ifdef USE_SHADING
    #ifdef USE_ADVSHADES
                                   if(isLight){
                                      curshades = shadetable[0];
                                   }else{                                
                                      curshades = shadetable[GetShade(scale,rpix-viewwidth/2,scrstarty-(viewheight/2),
                                                  farthest->x,farthest->y,tmpX,tmpY,sdwX,sdwY)];
                                   }
    #endif
                                    col=curshades[((byte *)shape)[newstart+j]];
    Now go to the SimpleScaleShape - function and seek for this line:

    Code:

                                col=((byte *)shape)[newstart+j];
    And change it to this:

    Code:

    #ifdef USE_ADVSHADES
                                   byte *curshades = shadetable[GetShade(scale,xcenter+lpix-(viewwidth),
                                         scrstarty-(viewheight/2),player->tilex,player->tiley,tmpX,tmpY,sdwX,sdwY)];
                                   col = curshades[((byte *)shape)[newstart+j]];
    #else                                              
                                   col=((byte *)shape)[newstart+j];
    #endif
    When you have done that, go to the DrawScaleds - function and look for this block:
    Code:

    #ifdef USE_DIR3DSPR
            if(statptr->flags & FL_DIR_MASK)
                visptr->transsprite=statptr;
            else
                visptr->transsprite=NULL;
    #endif

    Under that block add this one:

    Code:

    #ifdef USE_ADVSHADES
          //Encode the tile coordinates:
            visptr->x = statptr->tilex;
            visptr->y = statptr->tiley;
    #endif

    Go few lines down until you see:
    Code:

            //
            // could be in any of the nine surrounding tiles
            //
    Add these lines above them:
    Code:

    #ifdef USE_ADVSHADES
          //Encode the tile coordinates:
            visptr->x = statptr->tilex;
            visptr->y = statptr->tiley;
    #endif
    Now go few more lines down until you see this:
    Code:

                if (obj->state->rotate)
                    visptr->shapenum += CalcRotate (obj);
    And add this block under it:
    Code:

    #ifdef USE_ADVSHADES
               //WSJs glowing enemies:
                 if (obj->state->fullbright == true)
                     obj->flags |= FL_FULLBRIGHT;    // actor is "lit up"
                 else if(obj->flags & FL_FULLBRIGHT)
                     obj->flags &= ~FL_FULLBRIGHT;   // back to normal lighting
    #endif
    Last thing to do in DrawScaleds is to look for these lines:
    Code:

    #ifdef USE_DIR3DSPR
            if(farthest->transsprite)
                Scale3DShape(vbuf, vbufPitch, farthest->transsprite);

    And change them to this:

    Code:

    #ifdef USE_DIR3DSPR
            if(farthest->transsprite)
    #ifdef USE_ADVSHADES
               Scale3DShape(vbuf, vbufPitch, farthest->transsprite, tmpX, tmpY, farthest->x, farthest->y);
    #else
               Scale3DShape(vbuf, vbufPitch, farthest->transsprite);
    #endif
    Then go to the DrawPlayerWeapon - function and look for this line:
    Code:

           SimpleScaleShape(viewwidth/2,shapenum,viewheight+1);
    And add this block above it:
    Code:

    #ifdef USE_ADVSHADES
          //Light area when shooting
            if(shapenum == weaponscale[gamestate.weapon]+3 && gamestate.weapon != wp_knife)
               lightflash = 1;
            else
               lightflash = 0;
            if(lightflash>0){
               lightflash*=2; //Adjust for intensity
               SimpleScaleShape(viewwidth/2,shapenum,viewheight+1);
               lightflash/=2; //Must match the line above
            } else
    #endif
    Now we need to change AsmRefresh - function a bit...
    Search for "vertentry:" and when you have found it go down until you see these lines:
    Code:

                if(xspot>=maparea) break;
                tilehit=((uint16_t *)tilemap)[xspot];
    Add these lines under them:
    Code:

    #ifdef USE_ADVSHADES
              //Get tile coordinates
                tmpX = xspot>>6;
                tmpY = xspot & 0x3F;
    #endif
    Now scroll down to "horizentry:" in AsmRefresh and look for these lines:
    Code:

                if(yspot>=maparea) break;
                tilehit=((byte *)tilemap)[yspot];
    Add these lines under them:
    Code:

              //Get tile coordinates:
                tmpX = yspot>>6;
                tmpY = yspot & 0x3F;


    After that is done, go to the WallRefresh - function and add these
    lines just before the call for ScalePost:

    Code:

    #ifdef USE_ADVSHADES
        GetTileCoords();
    #endif
    Now go to the ThreeDRefresh and add these lines just before call for DrawScaleds:
    Code:

    #ifdef USE_ADVSHADES
        sdwX = 64; sdwY = 64;           //Reset shadow
    #endif


    And thats it for the wl_draw.cpp!!!




    Open the wl_dir3dspr.cpp and change the beginning of Scale3DShaper - function from this:
    Code:

    void Scale3DShaper(int x1, int x2, int shapenum, uint32_t flags, fixed ny1, fixed ny2,
                       fixed nx1, fixed nx2, byte *vbuf, unsigned vbufPitch)
    To this:
    Code:

    void Scale3DShaper(int x1, int x2, int shapenum, uint32_t flags, fixed ny1, fixed ny2,
                       fixed nx1, fixed nx2, byte *vbuf, unsigned vbufPitch
    #ifdef USE_ADVSHADES
                       ,int tx, int ty, int fx, int fy
    #endif
                       )
    Then in the Scale3DShaper, scroll down till you see this block:
    Code:

    #ifdef USE_SHADING
                    byte *curshades;
                    if(flags & FL_FULLBRIGHT)
                        curshades = shadetable[0];
                    else
                        curshades = shadetable[GetShade(scale1<<3)];
    #endif
    Change it to this:
    Code:

    #ifdef USE_SHADING
                    byte *curshades;
    #ifdef USE_ADVSHADES
                    bool isLight = (flags & FL_FULLBRIGHT)? true : false;
    #else
                    if(flags & FL_FULLBRIGHT)
                        curshades = shadetable[0];
                    else
                        curshades = shadetable[GetShade(scale1<<3)];
    #endif
    #endif
    Scroll few more lines down till you see this:
    Code:

    #ifdef USE_SHADING
                                col=curshades[((byte *)shape)[newstart+j]];
    And change it to this:
    Code:

    #ifdef USE_SHADING
    #ifdef USE_ADVSHADES
                                if(isLight)
                                   curshades = shadetable[0];
                                else
                                   curshades = shadetable[GetShade(scale1,xpos[i]-(viewwidth/2),
                                                          scrstarty-(viewheight/2),tx,ty,fx,fy)];
    #endif
                                col=curshades[((byte *)shape)[newstart+j]];
    Go down to Scale3DShape - function and change the beginning of it from this:
    Code:

    void Scale3DShape(byte *vbuf, unsigned vbufPitch, statobj_t *ob)
    To this:
    Code:

    void Scale3DShape(byte *vbuf, unsigned vbufPitch, statobj_t *ob
    #ifdef USE_ADVSHADES
                     ,int tx, int ty, int fx, int fy
    #endif
                     )
    Then in the end of the Scale3DShape - function search for this block:
    Code:

        if(viewx2 < viewx1)
        {
            Scale3DShaper(viewx2,viewx1,ob->shapenum,ob->flags,ny2,ny1,nx2,nx1,vbuf,vbufPitch);
        }
        else
        {
            Scale3DShaper(viewx1,viewx2,ob->shapenum,ob->flags,ny1,ny2,nx1,nx2,vbuf,vbufPitch);
        }
    And replace it with this:
    Code:

        if(viewx2 < viewx1)
        {
            Scale3DShaper(viewx2,viewx1,ob->shapenum,ob->flags,ny2,ny1,nx2,nx1,vbuf,vbufPitch
    #ifdef USE_ADVSHADES
                         ,tx,ty,fx,fy
    #endif                
                         );
        }
        else
        {
            Scale3DShaper(viewx1,viewx2,ob->shapenum,ob->flags,ny1,ny2,nx1,nx2,vbuf,vbufPitch
    #ifdef USE_ADVSHADES
                         ,tx,ty,fx,fy
    #endif
                         );
        }
    Now we have no more business in wl_dir3dspr.cpp, so close the file.


    It is time to open the last file we need to edit: wl_floorceiling.cpp!
    In DrawFloorAndCeiling - function search for these lines
    Code:

    #ifdef USE_SHADING
            byte *curshades = shadetable[GetShade(y << 3)];
    #endif
    And change them to these:

    Code:

    #ifdef USE_SHADING
    #ifndef USE_ADVSHADES
            byte *curshades = shadetable[GetShade(y << 3)];
    #endif
    #endif
    Now scroll down until you see these lines:
    Code:

                        unsigned texoffs = (u << TEXTURESHIFT) + (TEXTURESIZE - 1) - v;    
    #ifdef USE_SHADING
    And replace all the lines from there to the curly bracket with this block:
    Code:

                        unsigned texoffs = (u << TEXTURESHIFT) + (TEXTURESIZE - 1) - v;    
                     // Needed for AlumiuNs transperent ceiling fix
                        byte color1=*(toptex+texoffs);
                        byte color2=*(bottex+texoffs);
    #ifdef USE_SHADING
    #ifdef USE_ADVSHADES
                        unsigned short shade = GetShade(y,x-(viewwidth/2),y,curx,cury,curx,cury,u,v);
                        if(curtoptex && color1 != 0xff)
                            vbuf[top_add] = shadetable[shade][color1];
                        if(curbottex && color2 != 0xff)
                            vbuf[bot_add] = shadetable[shade][color2];
    #else
                        if(curtoptex && color1 != 0xff)
                            vbuf[top_add] = curshades[toptex[texoffs]];
                        if(curbottex && color2 != 0xff)
                            vbuf[bot_add] = curshades[bottex[texoffs]];
    #endif
    #else
                        if(curtoptex && color1 != 0xff)
                            vbuf[top_add] = toptex[texoffs];
                        if(curbottex && color2 != 0xff)
                            vbuf[bot_add] = bottex[texoffs];
    #endif


    If you want the flashlight to be a pickable object, do the following changes...
    Search for bo_alpo in the files (search should return

    In wl_def.h search for "bo_alpo" and add this line under it:
    Code:

        bo_flashlight,
    Then search for flashlight in that file and you should see this

    Code:

        bool        flashlight;
    Add following line under it

    Code:

        bool        gotlight;
    Now search for "gamestate.flashlight = false;" in files and when for every instance
    found, add this line under them:
    Code:

        gamestate.gotlight = false; //Player has no flashlight
     

    Then search for "flashlight" in wl_play.cpp and replace this line

    Code:
     
        if(Keyboard[sc_Z])
    With this one:

    Code:

        if(Keyboard[sc_Z] && gamestate.gotlight)
    Now in wl_act1.cpp search for "bo_alpo:" and add this line under it:

    Code:

            case    bo_flashlight:
    Finally open wl_agent.cpp and once again search for "bo_alpo:"...
    After the bo_alpo - case add the following block:

    Code:

            case    bo_flashlight:
                if(gamestate.gotlight) return; //Player already has light

                SD_PlaySound (BONUS1SND);
                gamestate.gotlight = true;
                break;
    Of course you need to add object for "bo_flashlight" or modify existing one in wl_act1.cpp
    to be your new flashlight item...




    Okay... Last thing you want to do is to add the fourth plane to the game because it would
    give you more freedom to create lightmaps than trying to generate the lightmap from maps objects...
    Here is tutorial from Adam Biser for adding 4th plane (modified it a bit)...

    Open wl_ca.h and in the beginning of file replace this block:

    Code:

    #ifdef USE_FLOORCEILINGTEX
        #define MAPPLANES       3
    #else
        #define MAPPLANES       2
    #endif
    With this one:

    Code:

    //You propably will be using textured floors and ceilings anyway...
    #ifdef USE_4THPLANE
        #define MAPPLANES       4
    #else
    #ifdef USE_FLOORCEILINGTEX
        #define MAPPLANES       3
    #else
        #define MAPPLANES       2
    #endif
    #endif
    Then few lines under that you should see:

    Code:

    typedef struct
    {
        int32_t planestart[3];
        word    planelength[3];
    Replace the number '3' with "MAPPLANES"

    Then open wl_ca.cpp and search for mapfiletype - struct...
    And change it to this:

    Code:

    typedef struct
    {   word     RLEWtag;
        int16_t  numplanes;
        int32_t  headeroffsets[100];
        byte     tileinfo[];
    } mapfiletype;
    Last thing we need to do is to read the values from 4th plane to the lightMap-array... To do this we need to go SetupGameLevel in WL_Game.Cpp and add this block:
    Code:

      //
      // Read fourth plane:
      //
    #ifdef USE_4THPLANE
        map = mapsegs[3];
        for (y=0;y<mapheight;y++)
        {
            for (x=0;x<mapwidth;x++)
            {
                tile = *map++;
    #ifdef USE_ADVSHADES
              //Fill the lightmap:
                lightMap[x][y] = (int)tile;
    #endif
            }
        }
    #endif

    After these lines:
    Code:

    //
    // take out the ambush markers
    //
        map = mapsegs[0];
        for (y=0;y<mapheight;y++)
        {
            for (x=0;x<mapwidth;x++)
            {
                tile = *map++;
                if (tile == AMBUSHTILE)
                {
                    tilemap[x][y] = 0;
                    if ( (unsigned)(uintptr_t)actorat[x][y] == AMBUSHTILE)
                        actorat[x][y] = NULL;

                    if (*map >= AREATILE)
                        tile = *map;
                    if (*(map-1-mapwidth) >= AREATILE)
                        tile = *(map-1-mapwidth);
                    if (*(map-1+mapwidth) >= AREATILE)
                        tile = *(map-1+mapwidth);
                    if ( *(map-2) >= AREATILE)
                        tile = *(map-2);

                    *(map-1) = tile;
                }
            }
        }

    IMPORTANT! Creating and editing the 4th plane only works in WDC...


    Last edited by WLHack on Fri Aug 29, 2014 8:19 am; edited 8 times in total



    Hammer: I can see it now: you and the moon - wear a necktie so I'll know you.
    Building a new webpage...
    linuxwolf
    linuxwolf
    Bring em' On!
    Bring em' On!


    Male
    Number of posts : 160
    Age : 42
    Location : Australia
    Hobbie : Games
    Registration date : 2011-12-25

    [Tutorial] Advanced shading Empty Re: [Tutorial] Advanced shading

    Post by linuxwolf Sat Mar 09, 2013 2:46 pm

    This looks very interesting. Do you have a screen shot of this feature in action? I'd like to see how this looks in-game.
    avatar
    WLHack
    Senior Member
    Senior Member


    Male
    Number of posts : 800
    Age : 35
    Location : Finland
    Registration date : 2007-03-26

    [Tutorial] Advanced shading Empty Re: [Tutorial] Advanced shading

    Post by WLHack Sat Mar 09, 2013 9:08 pm

    linuxwolf wrote:This looks very interesting. Do you have a screen shot of this feature in action? I'd like to see how this looks in-game.
    Look inside the spoiler tag...



    Hammer: I can see it now: you and the moon - wear a necktie so I'll know you.
    Building a new webpage...
    linuxwolf
    linuxwolf
    Bring em' On!
    Bring em' On!


    Male
    Number of posts : 160
    Age : 42
    Location : Australia
    Hobbie : Games
    Registration date : 2011-12-25

    [Tutorial] Advanced shading Empty Re: [Tutorial] Advanced shading

    Post by linuxwolf Sun Mar 10, 2013 2:38 pm

    Very nice indeed. I would love to develop a new mod using this tutorial when all my current projects are out of the way. Very exciting stuff! Smile

    If you don't mind, could you please explain the mathematical basis behind it? What equations are you using to compute brightness for wall, floor and ceiling elements?
    avatar
    WLHack
    Senior Member
    Senior Member


    Male
    Number of posts : 800
    Age : 35
    Location : Finland
    Registration date : 2007-03-26

    [Tutorial] Advanced shading Empty Re: [Tutorial] Advanced shading

    Post by WLHack Sun Mar 10, 2013 2:55 pm

    linuxwolf wrote:Very nice indeed. I would love to develop a new mod using this tutorial when all my current projects are out of the way. Very exciting stuff! Smile

    If you don't mind, could you please explain the mathematical basis behind it? What equations are you using to compute brightness for wall, floor and ceiling elements?

    As I was just porting the_fish original code, I haven't really though about
    the mathematics behind the feature... But it seems to use grid based interpolation
    for shading.



    Hammer: I can see it now: you and the moon - wear a necktie so I'll know you.
    Building a new webpage...
    mar
    mar
    Can I Play, Daddy?
    Can I Play, Daddy?


    Male
    Number of posts : 27
    Age : 45
    Location : Czech republic
    Job : Programmer
    Hobbie : Oldschool games
    Registration date : 2012-05-25

    [Tutorial] Advanced shading Empty Re: [Tutorial] Advanced shading

    Post by mar Sun Mar 10, 2013 3:31 pm

    Very nice attempt WLHACK yet I have a few remarks (regard it as constructive criticism please):
    AFAIK your code just shades a 2D circle/ellipse around flashlight center.
    The code does expensive calls per pixel (I understand you didn't optimize yet).
    Linuxwolf has a much better engine (I know Smile and can reach much more convincing effect by simply tracing a ray
    forward and spawning a dynamic light there, which will look more natural because it will capture
    the geometry feeling (that way flashlight in good old Half-Life was done).
    Anyway very nice job, congratulations!
    avatar
    WLHack
    Senior Member
    Senior Member


    Male
    Number of posts : 800
    Age : 35
    Location : Finland
    Registration date : 2007-03-26

    [Tutorial] Advanced shading Empty Re: [Tutorial] Advanced shading

    Post by WLHack Sun Mar 10, 2013 3:49 pm

    mar wrote:Very nice attempt WLHACK yet I have a few remarks (regard it as constructive criticism please):
    AFAIK your code just shades a 2D circle/ellipse around flashlight center.
    The code does expensive calls per pixel (I understand you didn't optimize yet).
    Linuxwolf has a much better engine (I know Smile and can reach much more convincing effect by simply tracing a ray
    forward and spawning a dynamic light there, which will look more natural because it will capture
    the geometry feeling (that way flashlight in good old Half-Life was done).
    Anyway very nice job, congratulations!
    Thanks, yeah I know there is a lot of room for improvements but I am still working
    on this (I am just glad that I got this work in the first place).



    Hammer: I can see it now: you and the moon - wear a necktie so I'll know you.
    Building a new webpage...
    avatar
    WLHack
    Senior Member
    Senior Member


    Male
    Number of posts : 800
    Age : 35
    Location : Finland
    Registration date : 2007-03-26

    [Tutorial] Advanced shading Empty Re: [Tutorial] Advanced shading

    Post by WLHack Sun Mar 10, 2013 3:52 pm

    I have been working for an improvement for this feature, and here is an idea
    for what you could do:
    - Change the "lightMap" to a three dimensional array... Now we will be
    using the new lightMap like this lightMap[x][y][layer].

    - In InitLevelShadeMap() store the shade values to both first and the second layer.
    Now we can safely alter the lightMap without fearing to lose the lightMaps data
    -> allows dynamical shading changes (Okay... There might be a better way to do this).

    - To check the advantages of this change, open wl_act2.cpp and
    in the end of T_Projectile - function add this line:
    Code:

    lightMap[ob->tilex][ob->tiley][0] = 255;

    Now go to the playloop in wl_play.cpp and there add something like this:
    Code:

    for(int x = 0; x < MAPSIZE; x++)
        for(int y = 0; y < MAPSIZE; y++)
            lightMap[x][y][0] = lightMap[x][y][1];
    Of course to get this work, you need to search for "lightMap" in all files
    and where you see something like this:
    Code:
    lightMap[ * ][ * ] =
    Change it to this:
    Code:
    lightMap[ * ][ * ][0] =


    As a result when the projectile moves, it will temporarily light
    the tile where it is...

    tl;dr;
    Add third dimension to lightMap for dynamic shading changes...
    When you want to change the shading use the first layer (the one that
    GetLightFrag uses) and then in the playloop use the second layer
    to reset the first layers values.



    Hammer: I can see it now: you and the moon - wear a necktie so I'll know you.
    Building a new webpage...
    avatar
    WLHack
    Senior Member
    Senior Member


    Male
    Number of posts : 800
    Age : 35
    Location : Finland
    Registration date : 2007-03-26

    [Tutorial] Advanced shading Empty Re: [Tutorial] Advanced shading

    Post by WLHack Mon Mar 11, 2013 7:52 am

    Fixed small bug from my tutorial that prevented from using original shading by commenting out "USE_ADVSHADES"...

    In wl_draw.cpp change this block:
    Code:

    #define MAXVISABLE 250

    typedef struct
    {
        short      viewx,
                  viewheight,
                  shapenum;
    #ifdef USE_ADVSHADES
        byte      x,y;            // Get the current tile of object
        short      flags;          // this must be changed to uint32_t, when you
    #endif                        // you need more than 16-flags for drawing
    #ifdef USE_DIR3DSPR
        statobj_t *transsprite;
        objtype  *transactor;
    #endif
    } visobj_t;

    visobj_t vislist[MAXVISABLE];
    visobj_t *visptr,*visstep,*farthest;

    To this:
    Code:

    #define MAXVISABLE 250

    typedef struct
    {
        short      viewx,
                  viewheight,
                  shapenum;
    #ifdef USE_ADVSHADES
        byte      x,y;            // Get the current tile of object
    #endif                        // <-- flags are used in other places!!!
        short      flags;          // this must be changed to uint32_t, when you
                                  // you need more than 16-flags for drawing
    #ifdef USE_DIR3DSPR
        statobj_t *transsprite;
        objtype  *transactor;
    #endif
    } visobj_t;

    visobj_t vislist[MAXVISABLE];
    visobj_t *visptr,*visstep,*farthest;



    Hammer: I can see it now: you and the moon - wear a necktie so I'll know you.
    Building a new webpage...
    linuxwolf
    linuxwolf
    Bring em' On!
    Bring em' On!


    Male
    Number of posts : 160
    Age : 42
    Location : Australia
    Hobbie : Games
    Registration date : 2011-12-25

    [Tutorial] Advanced shading Empty Re: [Tutorial] Advanced shading

    Post by linuxwolf Wed Mar 13, 2013 10:31 pm

    The problem with advanced lighting is that it makes the level design process much longer. This is more a problem in Batman: No Man's Land where levels can take up to 1 hour of computer time to finish processing. There is also the time spent by the level designer on the design and placement of lights in their maps. This can be especially time consuming as well.

    Unfortunately I can't think of a magical solution to this. Ideally advanced lighting would come for free just like distance shading in Wolf4SDL. I just can't figure out a scheme to make this look good.
    avatar
    WLHack
    Senior Member
    Senior Member


    Male
    Number of posts : 800
    Age : 35
    Location : Finland
    Registration date : 2007-03-26

    [Tutorial] Advanced shading Empty Re: [Tutorial] Advanced shading

    Post by WLHack Thu Mar 14, 2013 12:16 am

    linuxwolf wrote:The problem with advanced lighting is that it makes the level design process much longer. This is more a problem in Batman: No Man's Land where levels can take up to 1 hour of computer time to finish processing. There is also the time spent by the level designer on the design and placement of lights in their maps. This can be especially time consuming as well.

    Unfortunately I can't think of a magical solution to this. Ideally advanced lighting would come for free just like distance shading in Wolf4SDL. I just can't figure out a scheme to make this look good.

    I am not sure is that what you meant, but here is some of my thoughs about this subject (NOTE: To get exactly the shading you wanted, using own plane is recommended).

    First when you generate the shademap, use the floorcodes instead of general shading.
    Q: But what if I want to use different shades in room X than in room Y but those
    two rooms need to share the same floorcode?
    A: Add more floorcodes and make and link them... E.g. floorcode 142 and 155 are
    treated as the same by the enemies but when the levels shademap is created - they
    have different values.
    ...

    When that is done change the light sources to cast light according to the room
    shading so instead of using lightMap[x][y] = 255; , use lightMap[x][y] += 50;
    (remember to add check that the value is not over 255)...
    Q: But I don't want all my lights to be 50 points brighter than the current rooms shade...
    A: When you go through the light sources, you can add variation... Let's say
    that the chandelier has value +70, floorlamp +60 and ceiling lights +50.

    Then add shadow for the normal objects according to the room shade by doing
    something like this: lightMap[x][y] -= 30; and make sure that the values is always
    0 or greater.

    Q: But what if I want shadows to places where there is now objects?

    A: Nothing prevents you from adding invisible objects that cast darkness instead.

    Finally I think you want to make walls to cast shadows to their left side:
    Code:

    [  ][  ][  ][  ]
    [  ][wl][x2][  ] , where wl = wall, x1 = darkest shadow 
    [  ][x2][x1][  ]  & x2 is bit lighter shadow.
    [  ][  ][  ][  ]

    In otherwords when you generate lightMap, do this
    Step 1:
    Check floorcodes for rooms general lighning and also check walls to
    add shadows to the corners of rooms (some walls can also cast light!)

    Step 2:
    Go through objects to add darkness/light sources to the map...

    Step 3:
    Add shadows for the rest of the objects...




    One last thing that I think that it will improve both this and the original
    shading system... With objects casting light, instead of using shadetable[0],
    make them shaded as well, but only use third of the shades in the shadetable
    so they will be much lighter than rest of the environment.



    Hammer: I can see it now: you and the moon - wear a necktie so I'll know you.
    Building a new webpage...
    linuxwolf
    linuxwolf
    Bring em' On!
    Bring em' On!


    Male
    Number of posts : 160
    Age : 42
    Location : Australia
    Hobbie : Games
    Registration date : 2011-12-25

    [Tutorial] Advanced shading Empty Re: [Tutorial] Advanced shading

    Post by linuxwolf Thu Mar 14, 2013 2:04 am

    The area codes doubling as room shading is a smart way to re-use existing map plane for lighting. Since every tile in a room uses the same area code, it means lighting will be constant everywhere in that room - which is okay. It is sufficiently easy for a level designer to work with and this is the main advantage of your scheme.

    Is it possible for level designer to insert two adjacent rooms with different area codes but same shade?

    As an alternative to the use of area codes, why can't a level designer insert one or more special objects (an invisible dummy object or non-invisible static scenery light) into the room they want shaded? By default, if no such special object is inserted, the room will be shaded at 100%. Otherwise the room will be shaded at 10%, 20%, etc, depending on which special object is used. Area codes work as they previously did in Wolf4SDL and Wolf3D.

    I'm thinking the exact location of the static scenery lights should not have a major impact on the brightness of the room. You can insert the static scenery light anywhere in the room and it will have more-or-less the same effect on every tile. I don't think the level designer has enough time to place every light exactly where it should be.
    avatar
    WLHack
    Senior Member
    Senior Member


    Male
    Number of posts : 800
    Age : 35
    Location : Finland
    Registration date : 2007-03-26

    [Tutorial] Advanced shading Empty Re: [Tutorial] Advanced shading

    Post by WLHack Thu Mar 14, 2013 2:12 am

    linuxwolf wrote:The area codes doubling as room shading is a smart way to re-use existing map plane for lighting. Since every tile in a room uses the same area code, it means lighting will be constant everywhere in that room - which is okay. It is sufficiently easy for a level designer to work with and this is the main advantage of your scheme.

    Is it possible for level designer to insert two adjacent rooms with different area codes but same shade?
    Depends on the coding...

    linuxwolf wrote:As an alternative to the use of area codes, why can't a level designer insert one or more special objects (an invisible dummy object or non-invisible static scenery light) into the room they want shaded? By default, if no such special object is inserted, the room will be shaded at 100%. Otherwise the room will be shaded at 10%, 20%, etc, depending on which special object is used. Area codes work as they previously did in Wolf4SDL and Wolf3D.
    I like this idea a lot... And it would be lot easier to do.



    Hammer: I can see it now: you and the moon - wear a necktie so I'll know you.
    Building a new webpage...
    AlumiuN
    AlumiuN
    Don't Hurt Me!
    Don't Hurt Me!


    Number of posts : 52
    Age : 32
    Location : Christchurch, New Zealand
    Registration date : 2013-08-31

    [Tutorial] Advanced shading Empty Re: [Tutorial] Advanced shading

    Post by AlumiuN Mon Sep 02, 2013 10:21 pm

    Sorry to resurrect an old thread, but has anyone found a fix for this not shading south-facing sides of walls correctly? It's the only thing that's stopping me from using this >.<
    avatar
    WLHack
    Senior Member
    Senior Member


    Male
    Number of posts : 800
    Age : 35
    Location : Finland
    Registration date : 2007-03-26

    [Tutorial] Advanced shading Empty Re: [Tutorial] Advanced shading

    Post by WLHack Tue Sep 03, 2013 1:33 pm

    AlumiuN wrote:Sorry to resurrect an old thread, but has anyone found a fix for this not shading south-facing sides of walls correctly? It's the only thing that's stopping me from using this >.<
    I am working on it...



    Hammer: I can see it now: you and the moon - wear a necktie so I'll know you.
    Building a new webpage...
    AlumiuN
    AlumiuN
    Don't Hurt Me!
    Don't Hurt Me!


    Number of posts : 52
    Age : 32
    Location : Christchurch, New Zealand
    Registration date : 2013-08-31

    [Tutorial] Advanced shading Empty Re: [Tutorial] Advanced shading

    Post by AlumiuN Tue Sep 03, 2013 5:04 pm

    That's good to hear. I tried to take a look myself but my mathematical knowledge isn't really up to scratch for troubleshooting this sort of thing >.<
    avatar
    WLHack
    Senior Member
    Senior Member


    Male
    Number of posts : 800
    Age : 35
    Location : Finland
    Registration date : 2007-03-26

    [Tutorial] Advanced shading Empty Re: [Tutorial] Advanced shading

    Post by WLHack Mon Sep 16, 2013 2:42 am

    AlumiuN wrote:Sorry to resurrect an old thread, but has anyone found a fix for this not shading south-facing sides of walls correctly? It's the only thing that's stopping me from using this >.<
    Actually if you are referencing the bug in project X, we found found out that there was a couple lines missing from the code (that are in the tutorial).



    Hammer: I can see it now: you and the moon - wear a necktie so I'll know you.
    Building a new webpage...
    AlumiuN
    AlumiuN
    Don't Hurt Me!
    Don't Hurt Me!


    Number of posts : 52
    Age : 32
    Location : Christchurch, New Zealand
    Registration date : 2013-08-31

    [Tutorial] Advanced shading Empty Re: [Tutorial] Advanced shading

    Post by AlumiuN Mon Sep 16, 2013 3:20 pm

    WLHack wrote:
    AlumiuN wrote:Sorry to resurrect an old thread, but has anyone found a fix for this not shading south-facing sides of walls correctly? It's the only thing that's stopping me from using this >.<
    Actually if you are referencing the bug in project X, we found found out that there was a couple lines missing from the code (that are in the tutorial).
    I am, actually, although I thought I'd put all the lines in. Which ones were missing?
    avatar
    WLHack
    Senior Member
    Senior Member


    Male
    Number of posts : 800
    Age : 35
    Location : Finland
    Registration date : 2007-03-26

    [Tutorial] Advanced shading Empty Re: [Tutorial] Advanced shading

    Post by WLHack Mon Sep 16, 2013 11:06 pm

    AlumiuN wrote:
    WLHack wrote:
    AlumiuN wrote:Sorry to resurrect an old thread, but has anyone found a fix for this not shading south-facing sides of walls correctly? It's the only thing that's stopping me from using this >.<
    Actually if you are referencing the bug in project X, we found found out that there was a couple lines missing from the code (that are in the tutorial).
    I am, actually, although I thought I'd put all the lines in. Which ones were missing?
    These ones:


    //Get tile coordinates:
    tmpX = yspot>>6;
    tmpY = yspot & 0x3F;
    You did add the previous lines that were nearly similar, so I think you might accidentally overlooked this part (I also did so many times before going through the wl_draw.cpp line by line and comparing it to my test file).



    Hammer: I can see it now: you and the moon - wear a necktie so I'll know you.
    Building a new webpage...
    AlumiuN
    AlumiuN
    Don't Hurt Me!
    Don't Hurt Me!


    Number of posts : 52
    Age : 32
    Location : Christchurch, New Zealand
    Registration date : 2013-08-31

    [Tutorial] Advanced shading Empty Re: [Tutorial] Advanced shading

    Post by AlumiuN Tue Sep 17, 2013 4:10 pm

    WLHack wrote:
    AlumiuN wrote:
    WLHack wrote:
    AlumiuN wrote:Sorry to resurrect an old thread, but has anyone found a fix for this not shading south-facing sides of walls correctly? It's the only thing that's stopping me from using this >.<
    Actually if you are referencing the bug in project X, we found found out that there was a couple lines missing from the code (that are in the tutorial).
    I am, actually, although I thought I'd put all the lines in. Which ones were missing?
    These ones:



            //Get tile coordinates:
               tmpX = yspot>>6;
               tmpY = yspot & 0x3F;
    You did add the previous lines that were nearly similar, so I think you might accidentally overlooked this part (I also did so many times before going through the wl_draw.cpp line by line and comparing it to my test file).
    Nope, didn't miss those. I'll take a look back through my code and see if I missed something else, though.

    EDIT: Nope, I don't appear to have missed anything. It must be a different issue that I'm having then. Here's a screenshot of what's happening - the unlit wall is the south facing wall, the light is centered directly in front of the player. https://i.imgur.com/TTrkwLS.png
    avatar
    WLHack
    Senior Member
    Senior Member


    Male
    Number of posts : 800
    Age : 35
    Location : Finland
    Registration date : 2007-03-26

    [Tutorial] Advanced shading Empty Re: [Tutorial] Advanced shading

    Post by WLHack Tue Sep 17, 2013 9:49 pm

    AlumiuN wrote:
    Nope, didn't miss those. I'll take a look back through my code and see if I missed something else, though.

    EDIT: Nope, I don't appear to have missed anything. It must be a different issue that I'm having then. Here's a screenshot of what's happening - the unlit wall is the south facing wall, the light is centered directly in front of the player. https://i.imgur.com/TTrkwLS.png
    Okay... At least in the source that I got from Richter, those lines were missing.
    Anyway, I will do some more testing.



    Hammer: I can see it now: you and the moon - wear a necktie so I'll know you.
    Building a new webpage...
    avatar
    WLHack
    Senior Member
    Senior Member


    Male
    Number of posts : 800
    Age : 35
    Location : Finland
    Registration date : 2007-03-26

    [Tutorial] Advanced shading Empty Re: [Tutorial] Advanced shading

    Post by WLHack Wed Oct 09, 2013 12:49 am

    Found the solution for the problem... You have to replace the GetTileCoords in WL_Draw.C with this one:

    Code:

    void inline GetTileCoords(){
        if (!isHoriz)
        {
            faceY = tmpY;
            if (player->x >> (TILESHIFT-1) > (tmpX*2))
                faceX = tmpX+1;
            else
                faceX = tmpX-1;            
        }
        else
        {   
            faceX = tmpX; 
            if (player->y >> (TILESHIFT-1) > (tmpY*2))  
                faceY = tmpY+1;
            else
                faceY = tmpY-1;
        } 
    }
    Here is a comparison between the differences with old code (top row) and the new one (bottom row)... I also noticed that the in the old code the light is shining through the walls... These changes fixes that as well...

    Spoiler:

    I updated both the tutorial and the source code .



    Hammer: I can see it now: you and the moon - wear a necktie so I'll know you.
    Building a new webpage...
    AlumiuN
    AlumiuN
    Don't Hurt Me!
    Don't Hurt Me!


    Number of posts : 52
    Age : 32
    Location : Christchurch, New Zealand
    Registration date : 2013-08-31

    [Tutorial] Advanced shading Empty Re: [Tutorial] Advanced shading

    Post by AlumiuN Wed Oct 09, 2013 1:34 am

    It works! Thanks mate Smile
    avatar
    WLHack
    Senior Member
    Senior Member


    Male
    Number of posts : 800
    Age : 35
    Location : Finland
    Registration date : 2007-03-26

    [Tutorial] Advanced shading Empty Re: [Tutorial] Advanced shading

    Post by WLHack Wed Oct 09, 2013 2:08 am

    AlumiuN wrote:It works! Thanks mate Smile
    You're welcome...
    Hehe... Now just add batteries and make the flashlight randomly flicker just before it runs out of energy.



    Hammer: I can see it now: you and the moon - wear a necktie so I'll know you.
    Building a new webpage...
    avatar
    WLHack
    Senior Member
    Senior Member


    Male
    Number of posts : 800
    Age : 35
    Location : Finland
    Registration date : 2007-03-26

    [Tutorial] Advanced shading Empty Re: [Tutorial] Advanced shading

    Post by WLHack Wed Oct 09, 2013 11:53 am

    Finally got the 4th plane working... And I must say I feel quite stupid now.
    Open WL_Game.c and go to the SetupGameLevel-function. In that function add this block:
    Code:

      //
      // Read fourth plane:
      //
    #ifdef USE_4THPLANE
        map = mapsegs[3];
        for (y=0;y<mapheight;y++)
        {
            for (x=0;x<mapwidth;x++)
            {
                tile = *map++;
    #ifdef USE_ADVSHADES
              //Fill the lightmap:
                lightMap[x][y] = (int)tile;
    #endif
            }
        }
    #endif
    After these lines:
    Code:

    //
    // take out the ambush markers
    //
        map = mapsegs[0];
        for (y=0;y<mapheight;y++)
        {
            for (x=0;x<mapwidth;x++)
            {
                tile = *map++;
                if (tile == AMBUSHTILE)
                {
                    tilemap[x][y] = 0;
                    if ( (unsigned)(uintptr_t)actorat[x][y] == AMBUSHTILE)
                        actorat[x][y] = NULL;

                    if (*map >= AREATILE)
                        tile = *map;
                    if (*(map-1-mapwidth) >= AREATILE)
                        tile = *(map-1-mapwidth);
                    if (*(map-1+mapwidth) >= AREATILE)
                        tile = *(map-1+mapwidth);
                    if ( *(map-2) >= AREATILE)
                        tile = *(map-2);

                    *(map-1) = tile;
                }
            }
        }
    EDIT: Updated the tutorial...



    Hammer: I can see it now: you and the moon - wear a necktie so I'll know you.
    Building a new webpage...
    avatar
    WLHack
    Senior Member
    Senior Member


    Male
    Number of posts : 800
    Age : 35
    Location : Finland
    Registration date : 2007-03-26

    [Tutorial] Advanced shading Empty Re: [Tutorial] Advanced shading

    Post by WLHack Wed Oct 09, 2013 12:38 pm

    Updated the source-code...
    NOTE: To edit the 4th plane you need a map editor like WDC or HWE

    Here is a new screenshot:
    [Tutorial] Advanced shading Mjag



    Hammer: I can see it now: you and the moon - wear a necktie so I'll know you.
    Building a new webpage...
    doomjedi
    doomjedi
    Hardcore Wolfer
    Hardcore Wolfer


    Male
    Number of posts : 1378
    Age : 45
    Location : Israel
    Hobbie : Gaming and Modding, Pixel Art
    Registration date : 2007-03-26

    [Tutorial] Advanced shading Empty Re: [Tutorial] Advanced shading

    Post by doomjedi Wed Oct 09, 2013 1:31 pm

    Looks good! Smile
    avatar
    Imed
    Can I Play, Daddy?
    Can I Play, Daddy?


    Number of posts : 32
    Age : 33
    Registration date : 2013-10-26

    [Tutorial] Advanced shading Empty Re: [Tutorial] Advanced shading

    Post by Imed Sat Nov 02, 2013 8:36 am

    Hi there! This is a really great tutorial that brings a whole new dimension to wolf3d modding.


    I have a little question about it; in wl_shade.cpp you put:


    (..)
    Code:
    if(tx1 > 0){
          if(ty1 > 0)
             return ((lightMap[x][y]   * (tx2*ty2)) + (lightMap[x+1][y]   * (tx1*ty2)) +
                     (lightMap[x][y+1] * (tx2*ty1)) + (lightMap[x+1][y+1] * (tx1*ty1)));    
          else{
             ty1 *= -1;
             return ((lightMap[x][y]   * (tx2*ty2)) + (lightMap[x+1][y]   * (tx1*ty2)) +
                     (lightMap[x][y-1] * (tx2*ty1)) + (lightMap[x+1][y-1] * (tx1*ty1)));            
          }
       }else{
          tx1 *= -1;
          if(ty1 > 0)
             return ((lightMap[x][y]   * (tx2*ty2)) + (lightMap[x-1][y]   * (tx1*ty2)) +
                     (lightMap[x][y+1] * (tx2*ty1)) + (lightMap[x-1][y+1] * (tx1*ty1)));          
          else{
             ty1 *= -1;
             return ((lightMap[x][y]   * (tx2*ty2)) + (lightMap[x-1][y]   * (tx1*ty2)) +
                     (lightMap[x][y-1] * (tx2*ty1)) + (lightMap[x-1][y-1] * (tx1*ty1)));            
          }    
       }  return 0;      
    }
    (...)

    Ok, my question is simple what do this? Because looks to me like and infinite loop and probably is the reason of the frame drop i am suffering.

    if i understand right, you are "drawing" the lightmap with four sections right? Plz, someone correct me if i am wrong.

    well thats all. I hope my poor english is at least understandable.

    Thanks.
    avatar
    WLHack
    Senior Member
    Senior Member


    Male
    Number of posts : 800
    Age : 35
    Location : Finland
    Registration date : 2007-03-26

    [Tutorial] Advanced shading Empty Re: [Tutorial] Advanced shading

    Post by WLHack Sat Nov 02, 2013 9:25 am

    Imed wrote:Ok, my question is simple what do this? Because looks to me like and infinite loop and probably is the reason of the frame drop i am suffering.
    There is no infinite loop here... This part returns the light fraction calculated from the surrounding four tiles from the given position. But I did notice that some tutorials (e.g. Codetech's fixed framerate) will cause significant framedrop with this tutorial...



    Hammer: I can see it now: you and the moon - wear a necktie so I'll know you.
    Building a new webpage...
    avatar
    Imed
    Can I Play, Daddy?
    Can I Play, Daddy?


    Number of posts : 32
    Age : 33
    Registration date : 2013-10-26

    [Tutorial] Advanced shading Empty Re: [Tutorial] Advanced shading

    Post by Imed Sat Nov 02, 2013 8:48 pm

    WLHack wrote:
    Imed wrote:Ok, my question is simple what do this? Because looks to me like and infinite loop and probably is the reason of the frame drop i am suffering.
    There is no infinite loop here... This part returns the light fraction calculated from the surrounding four tiles from the given position. But I did notice that some tutorials (e.g. Codetech's fixed framerate) will cause significant framedrop with this tutorial...
    Oh, thank you so much. That make more sense :oops:i will check more carefully thta code.
    mmed
    mmed
    Don't Hurt Me!
    Don't Hurt Me!


    Male
    Number of posts : 52
    Age : 30
    Registration date : 2012-07-25

    [Tutorial] Advanced shading Empty Re: [Tutorial] Advanced shading

    Post by mmed Thu Dec 19, 2013 2:04 pm

    I made this tutorial and when I start playing the game runs at 40 fps instead of 70 fps and if I turn on the flashlight down at 20fps!



    I'm not using the fourth plane for lights because the code does not compile.I try to fix it with this tutorial:http://diehardwolfers.areyep.com/viewtopic.php?t=5397
    the code compiles but when I start the first level of the first episode.the player starts at the third level!!!


    note: I did not put the fixed framerate tutorial


    any ideas?
    thanks.
    avatar
    WLHack
    Senior Member
    Senior Member


    Male
    Number of posts : 800
    Age : 35
    Location : Finland
    Registration date : 2007-03-26

    [Tutorial] Advanced shading Empty Re: [Tutorial] Advanced shading

    Post by WLHack Fri Dec 20, 2013 12:11 am

    mmed wrote:
    I made this tutorial and when I start playing the game runs at 40 fps instead of 70 fps and if I turn on the flashlight down at 20fps!
    I will try to find a way to increase the framerate...

    mmed wrote:
    I'm not using the fourth plane for lights because the code does not compile.I try to fix it with this tutorial:http://diehardwolfers.areyep.com/viewtopic.php?t=5397
    The fourth plane code should compile, so would you post the error you are having.
    Also if you are using the code in that link, you still need to read the data from the 4th plane
    in the SetupGameLevel.

    mmed wrote:
    the code compiles but when I start the first level of the first episode.the player starts at the third level!!!
    This sounds like you accidentally changed the starting level in the new game.
    I think you should check that out.



    Hammer: I can see it now: you and the moon - wear a necktie so I'll know you.
    Building a new webpage...
    mmed
    mmed
    Don't Hurt Me!
    Don't Hurt Me!


    Male
    Number of posts : 52
    Age : 30
    Registration date : 2012-07-25

    [Tutorial] Advanced shading Empty Re: [Tutorial] Advanced shading

    Post by mmed Sat Dec 21, 2013 6:58 am

    ok, I will do it again  Very Happy
    mmed
    mmed
    Don't Hurt Me!
    Don't Hurt Me!


    Male
    Number of posts : 52
    Age : 30
    Registration date : 2012-07-25

    [Tutorial] Advanced shading Empty Re: [Tutorial] Advanced shading

    Post by mmed Fri Jan 24, 2014 5:08 am

    apparently if you try to play in 640x480 wolf4SDL.This consumes 87% CPU =62-70fps!!!
    and the advanced shading is dropped frames 99%=20-40fps


    and you?








    My english is bad .because i don't speak english....  Very Happy
    Dark_wizzie
    Dark_wizzie
    I am Death Incarnate!
    I am Death Incarnate!


    Female
    Number of posts : 5120
    Age : 30
    Location : California, USA
    Job : Investor
    Hobbie : Computers, chess, computer chess, fashion, and philosophy
    Message : I made this forum when I was 13 High on Drugs
    Registration date : 2007-03-24

    [Tutorial] Advanced shading Empty Re: [Tutorial] Advanced shading

    Post by Dark_wizzie Wed Aug 27, 2014 7:07 pm

    mmed wrote:apparently if you try to play in 640x480 wolf4SDL.This consumes 87% CPU =62-70fps!!!
    and the advanced shading is dropped frames 99%=20-40fps


    and you?








    My english is bad .because i don't speak english....  Very Happy
    Well, what CPU do you have? How much ram?



    Wolf3d Haven
    Minute Logic Blog
    avatar
    WLHack
    Senior Member
    Senior Member


    Male
    Number of posts : 800
    Age : 35
    Location : Finland
    Registration date : 2007-03-26

    [Tutorial] Advanced shading Empty Re: [Tutorial] Advanced shading

    Post by WLHack Fri Aug 29, 2014 8:17 am

    Important! There has been reports of the 4th plane not working and the game turning into a mess of garbled textures. Well, I made some research and noticed and interesting thing: Adding and editing the 4th plane works only in WDC. If you added or edited the 4th plane with HWE the doesn't read the 4th plane right.



    Hammer: I can see it now: you and the moon - wear a necktie so I'll know you.
    Building a new webpage...
    mmed
    mmed
    Don't Hurt Me!
    Don't Hurt Me!


    Male
    Number of posts : 52
    Age : 30
    Registration date : 2012-07-25

    [Tutorial] Advanced shading Empty Re: [Tutorial] Advanced shading

    Post by mmed Fri Aug 29, 2014 12:51 pm

    Dark_wizzie wrote:
    mmed wrote:apparently if you try to play in 640x480 wolf4SDL.This consumes 87% CPU =62-70fps!!!
    and the advanced shading is dropped frames 99%=20-40fps


    and you?








    My english is bad .because i don't speak english....  Very Happy
    Well, what CPU do you have? How much ram?

    AMD quad core 2.4Ghz (just 1 core is active)
    2GB ram  (RAM does not matter in wolf4sdl ...only uses 24mb)

    I think it is not necessary that the game is calculating the shadows several times....would have to be calculated only once

    when the game loads files (in the main menu)
    Mega Luigi
    Mega Luigi
    Bring em' On!
    Bring em' On!


    Number of posts : 161
    Age : 14
    Registration date : 2012-11-01

    [Tutorial] Advanced shading Empty Re: [Tutorial] Advanced shading

    Post by Mega Luigi Fri Aug 29, 2014 4:29 pm

    mmed wrote:
    Dark_wizzie wrote:
    mmed wrote:apparently if you try to play in 640x480 wolf4SDL.This consumes 87% CPU =62-70fps!!!
    and the advanced shading is dropped frames 99%=20-40fps


    and you?








    My english is bad .because i don't speak english....  Very Happy
    Well, what CPU do you have? How much ram?

    AMD quad core 2.4Ghz (just 1 core is active)
    2GB ram  (RAM does not matter in wolf4sdl ...only uses 24mb)

    I think it is not necessary that the game is calculating the shadows several times....would have to be calculated only once

    when the game loads files (in the main menu)

    You can't say wolf4sdl only uses 24mb, that depends a lot on what you do with your code. Also, I don't think it calculates it several times. It just uses the values stored in the shadetable, which is not calculated several times, as you say. Just as a comment, even with regular shading, if you try to calculate it repeatedly during the game, you will experience nice slowdowns. I estimated (obviously basing in my computer's specs) that one shade table (again, regular one) takes 28.9 ms with my processor at 3.4 GHz or around 25ms with it at 4GHz. See, if I calculated that every frame, not even considering everything else that must be processed, I would run at 35~40fps. That being said, I really don't think that is the case here.
    mmed
    mmed
    Don't Hurt Me!
    Don't Hurt Me!


    Male
    Number of posts : 52
    Age : 30
    Registration date : 2012-07-25

    [Tutorial] Advanced shading Empty Re: [Tutorial] Advanced shading

    Post by mmed Fri Aug 29, 2014 5:39 pm

    Mega Luigi wrote:
    mmed wrote:
    Dark_wizzie wrote:
    mmed wrote:apparently if you try to play in 640x480 wolf4SDL.This consumes 87% CPU =62-70fps!!!
    and the advanced shading is dropped frames 99%=20-40fps


    and you?








    My english is bad .because i don't speak english....  Very Happy
    Well, what CPU do you have? How much ram?

    AMD quad core 2.4Ghz (just 1 core is active)
    2GB ram  (RAM does not matter in wolf4sdl ...only uses 24mb)

    I think it is not necessary that the game is calculating the shadows several times....would have to be calculated only once

    when the game loads files (in the main menu)

    You can't say wolf4sdl only uses 24mb, that depends a lot on what you do with your code. Also, I don't think it calculates it several times. It just uses the values stored in the shadetable, which is not calculated several times, as you say. Just as a comment, even with regular shading, if you try to calculate it repeatedly during the game, you will experience nice slowdowns. I estimated (obviously basing in my computer's specs) that one shade table (again, regular one) takes 28.9 ms with my processor at 3.4 GHz or around 25ms with it at 4GHz. See, if I calculated that every frame, not even considering everything else that must be processed, I would run at 35~40fps. That being said, I really don't think that is the case here.


    24mb is used by my mod (for now.I thought it was obvious Razz )

    I think the shadetable serves to shape the shading.I change the values and it worked
    wolf4sdl original (and my mod) runs at 60~70fps on a pc with 1.6ghz and 70fps in my AMD .I checked it out.no good would sacrifice almost 40fps in a visual effect
    I do not think the problem is in the shadetable. it may be elsewhere
    Mega Luigi
    Mega Luigi
    Bring em' On!
    Bring em' On!


    Number of posts : 161
    Age : 14
    Registration date : 2012-11-01

    [Tutorial] Advanced shading Empty Re: [Tutorial] Advanced shading

    Post by Mega Luigi Fri Aug 29, 2014 6:16 pm

    mmed wrote:
    Mega Luigi wrote:
    mmed wrote:
    Dark_wizzie wrote:
    mmed wrote:apparently if you try to play in 640x480 wolf4SDL.This consumes 87% CPU =62-70fps!!!
    and the advanced shading is dropped frames 99%=20-40fps


    and you?








    My english is bad .because i don't speak english....  Very Happy
    Well, what CPU do you have? How much ram?

    AMD quad core 2.4Ghz (just 1 core is active)
    2GB ram  (RAM does not matter in wolf4sdl ...only uses 24mb)

    I think it is not necessary that the game is calculating the shadows several times....would have to be calculated only once

    when the game loads files (in the main menu)

    You can't say wolf4sdl only uses 24mb, that depends a lot on what you do with your code. Also, I don't think it calculates it several times. It just uses the values stored in the shadetable, which is not calculated several times, as you say. Just as a comment, even with regular shading, if you try to calculate it repeatedly during the game, you will experience nice slowdowns. I estimated (obviously basing in my computer's specs) that one shade table (again, regular one) takes 28.9 ms with my processor at 3.4 GHz or around 25ms with it at 4GHz. See, if I calculated that every frame, not even considering everything else that must be processed, I would run at 35~40fps. That being said, I really don't think that is the case here.


    24mb is used by my mod (for now.I thought it was obvious Razz )

    I think the shadetable serves to shape the shading.I change the values and it worked
    wolf4sdl original (and my mod) runs at 60~70fps on a pc with 1.6ghz and 70fps in my AMD .I checked it out.no good would sacrifice almost 40fps in a visual effect
    I do not think the problem is in the shadetable. it may be elsewhere
    Ah, my bad then. I agree, 40 frames is a lot to sacrifice. My point is, at least for the regular shading, the slowest part of the process is the creation of shadetables (or calculations, as you say), which store the value for each color for each step toward the destination color. So, if it calculated it repeatedly, my guess is that you would lose more than 40 frames.
    mmed
    mmed
    Don't Hurt Me!
    Don't Hurt Me!


    Male
    Number of posts : 52
    Age : 30
    Registration date : 2012-07-25

    [Tutorial] Advanced shading Empty Re: [Tutorial] Advanced shading

    Post by mmed Sat Aug 30, 2014 7:13 am

    Mega Luigi wrote:
    mmed wrote:
    Mega Luigi wrote:
    mmed wrote:
    Dark_wizzie wrote:
    mmed wrote:apparently if you try to play in 640x480 wolf4SDL.This consumes 87% CPU =62-70fps!!!
    and the advanced shading is dropped frames 99%=20-40fps


    and you?








    My english is bad .because i don't speak english....  Very Happy
    Well, what CPU do you have? How much ram?

    AMD quad core 2.4Ghz (just 1 core is active)
    2GB ram  (RAM does not matter in wolf4sdl ...only uses 24mb)

    I think it is not necessary that the game is calculating the shadows several times....would have to be calculated only once

    when the game loads files (in the main menu)

    You can't say wolf4sdl only uses 24mb, that depends a lot on what you do with your code. Also, I don't think it calculates it several times. It just uses the values stored in the shadetable, which is not calculated several times, as you say. Just as a comment, even with regular shading, if you try to calculate it repeatedly during the game, you will experience nice slowdowns. I estimated (obviously basing in my computer's specs) that one shade table (again, regular one) takes 28.9 ms with my processor at 3.4 GHz or around 25ms with it at 4GHz. See, if I calculated that every frame, not even considering everything else that must be processed, I would run at 35~40fps. That being said, I really don't think that is the case here.


    24mb is used by my mod (for now.I thought it was obvious Razz )

    I think the shadetable serves to shape the shading.I change the values and it worked
    wolf4sdl original (and my mod) runs at 60~70fps on a pc with 1.6ghz and 70fps in my AMD .I checked it out.no good would sacrifice almost 40fps in a visual effect
    I do not think the problem is in the shadetable. it may be elsewhere
    Ah, my bad then. I agree, 40 frames is a lot to sacrifice. My point is, at least for the regular shading, the slowest part of the process is the creation of shadetables (or calculations, as you say), which store the value for each color for each step toward the destination color. So, if it calculated it repeatedly, my guess is that you would lose more than 40 frames.

    I think the problem is on the pc this "reading" functions many times (in real time).so:



    it is possible to pre-render the scene? I think that it can not because it is a 2D engine  Neutral
    Mega Luigi
    Mega Luigi
    Bring em' On!
    Bring em' On!


    Number of posts : 161
    Age : 14
    Registration date : 2012-11-01

    [Tutorial] Advanced shading Empty Re: [Tutorial] Advanced shading

    Post by Mega Luigi Sat Aug 30, 2014 9:14 am

    mmed wrote:
    Mega Luigi wrote:
    mmed wrote:
    Mega Luigi wrote:
    mmed wrote:
    Dark_wizzie wrote:
    mmed wrote:apparently if you try to play in 640x480 wolf4SDL.This consumes 87% CPU =62-70fps!!!
    and the advanced shading is dropped frames 99%=20-40fps


    and you?








    My english is bad .because i don't speak english....  Very Happy
    Well, what CPU do you have? How much ram?

    AMD quad core 2.4Ghz (just 1 core is active)
    2GB ram  (RAM does not matter in wolf4sdl ...only uses 24mb)

    I think it is not necessary that the game is calculating the shadows several times....would have to be calculated only once

    when the game loads files (in the main menu)

    You can't say wolf4sdl only uses 24mb, that depends a lot on what you do with your code. Also, I don't think it calculates it several times. It just uses the values stored in the shadetable, which is not calculated several times, as you say. Just as a comment, even with regular shading, if you try to calculate it repeatedly during the game, you will experience nice slowdowns. I estimated (obviously basing in my computer's specs) that one shade table (again, regular one) takes 28.9 ms with my processor at 3.4 GHz or around 25ms with it at 4GHz. See, if I calculated that every frame, not even considering everything else that must be processed, I would run at 35~40fps. That being said, I really don't think that is the case here.


    24mb is used by my mod (for now.I thought it was obvious Razz )

    I think the shadetable serves to shape the shading.I change the values and it worked
    wolf4sdl original (and my mod) runs at 60~70fps on a pc with 1.6ghz and 70fps in my AMD .I checked it out.no good would sacrifice almost 40fps in a visual effect
    I do not think the problem is in the shadetable. it may be elsewhere
    Ah, my bad then. I agree, 40 frames is a lot to sacrifice. My point is, at least for the regular shading, the slowest part of the process is the creation of shadetables (or calculations, as you say), which store the value for each color for each step toward the destination color. So, if it calculated it repeatedly, my guess is that you would lose more than 40 frames.

    I think the problem is on the pc this "reading" functions many times (in real time).so:



    it is possible to pre-render the scene? I think that it can not because it is a 2D engine  Neutral

    Yeah, I suppose that could be the problem. However, I don't think there is an easy way to do what you want.

    Sponsored content


    [Tutorial] Advanced shading Empty Re: [Tutorial] Advanced shading

    Post by Sponsored content


      Current date/time is Mon Oct 14, 2024 10:52 am