Guest User

Untitled

a guest
Sep 30th, 2016
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //===========================================================================
  2. //
  3. // Doom lighting equation exactly as calculated by zdoom.
  4. //
  5. //===========================================================================
  6. float R_DoomLightingEquation(float light)
  7. {
  8.    // Calculated from r_visibility. It differs between walls, floor and sprites.
  9.    //
  10.    // Wall: globVis = r_WallVisibility
  11.    // Floor: r_FloorVisibility / abs(plane.Zat0 - ViewPos.Z)
  12.    // Sprite: same as wall
  13.    // All are calculated in R_SetVisibility and seem to be decided by the
  14.    // aspect ratio amongst other things.
  15.    //
  16.    // 1706 is the value for walls on 1080p 16:9 displays.
  17.    float globVis = 1706.0;
  18.  
  19.    /* L is the integer light level used in the game */
  20.    float L = light * 255.0;
  21.  
  22.    /* z is the depth in view/eye space, positive going into the screen */
  23.    float z = pixelpos.w;
  24.  
  25.    /* The zdoom light equation */
  26.    float vis = globVis / z;
  27.    float shade = 64.0 - (L + 12.0) * 32.0/128.0;
  28.    float lightscale = clamp((shade - min(24.0, vis)) / 32.0, 0.0, 31.0/32.0);
  29.  
  30.    // Result is the normalized colormap index (0 bright .. 1 dark)
  31.    return lightscale;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment