Ignore:
Timestamp:
May 23, 2000, 10:41:28 PM (25 years ago)
Author:
jeroen
Message:

* empty log message *

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/opengl/mesa/shade.c

    r2938 r3598  
    1 /* $Id: shade.c,v 1.1 2000-02-29 00:50:10 sandervl Exp $ */
     1/* $Id: shade.c,v 1.2 2000-05-23 20:40:53 jeroen Exp $ */
    22
    33/*
    44 * Mesa 3-D graphics library
    5  * Version:  3.1
     5 * Version:  3.3
    66 *
    77 * Copyright (C) 1999  Brian Paul   All Rights Reserved.
     
    3232#include "all.h"
    3333#else
    34 #ifndef XFree86Server
    35 #include <math.h>
    36 #include <stdio.h>
    37 #else
    38 #include "GL/xf86glx.h"
    39 #endif
     34#include "glheader.h"
    4035#include "light.h"
    4136#include "macros.h"
     
    5146
    5247
    53 #define GET_SHINE_TAB_ENTRY( tab, dp, result )  \
    54 do {                                                    \
    55    int k = (int) (dp * SHINE_TABLE_SIZE);       \
    56    result = tab->tab[k];                                \
     48#define GET_SHINE_TAB_ENTRY( tab, dp, result )  \
     49do {                                                    \
     50   int k = (int) (dp * SHINE_TABLE_SIZE);       \
     51   result = tab->tab[k];                                \
    5752} while(0)
    5853
     
    203198   if (ctx->Visual->RGBAflag) {
    204199      if (ctx->Light.NeedVertices) {
    205         if (ctx->Texture.Enabled &&
    206              ctx->Light.Model.ColorControl==GL_SEPARATE_SPECULAR_COLOR)
    207             idx = SHADE_RGBA_SPEC;
    208         else
    209             idx = SHADE_RGBA_VERTICES; 
     200        if (ctx->Texture.Enabled &&
     201             ctx->Light.Model.ColorControl==GL_SEPARATE_SPECULAR_COLOR)
     202            idx = SHADE_RGBA_SPEC;
     203        else
     204            idx = SHADE_RGBA_VERTICES;
    210205      }
    211206      else
    212         idx = SHADE_RGBA_NORMALS;
     207        idx = SHADE_RGBA_NORMALS;
    213208   }
    214209   else
     
    230225 */
    231226void gl_shade_rastpos( GLcontext *ctx,
    232                        GLfloat vertex[4],
    233                        GLfloat normal[3],
    234                        GLfloat Rcolor[4],
    235                        GLuint *index )
     227                       GLfloat vertex[4],
     228                       GLfloat normal[3],
     229                       GLfloat Rcolor[4],
     230                       GLuint *index )
    236231{
    237232   GLfloat (*base)[3] = ctx->Light.BaseColor;
     
    254249
    255250      if (!(light->Flags & LIGHT_POSITIONAL)) {
    256         COPY_3V(VP, light->VP_inf_norm);
    257         attenuation = light->VP_inf_spot_attenuation;
     251        COPY_3V(VP, light->VP_inf_norm);
     252        attenuation = light->VP_inf_spot_attenuation;
    258253      }
    259254      else {
    260         GLfloat d;
    261        
    262         SUB_3V(VP, light->Position, vertex);
    263         d = LEN_3FV( VP );
    264        
    265         if ( d > 1e-6) {
    266             GLfloat invd = 1.0F / d;
    267             SELF_SCALE_SCALAR_3V(VP, invd);
    268         }
    269         attenuation = 1.0F / (light->ConstantAttenuation + d *
    270                                (light->LinearAttenuation + d *
    271                                 light->QuadraticAttenuation));
    272        
    273         if (light->Flags & LIGHT_SPOT)
    274         {
    275             GLfloat PV_dot_dir = - DOT3(VP, light->NormDirection);
    276        
    277             if (PV_dot_dir<light->CosCutoff) {
    278                continue;
    279             }
    280             else
    281             {
    282                double x = PV_dot_dir * (EXP_TABLE_SIZE-1);
    283                int k = (int) x;
    284                GLfloat spot = (GLfloat) (light->SpotExpTable[k][0]
    285                                + (x-k)*light->SpotExpTable[k][1]);
    286                attenuation *= spot;
    287             }
    288         }
     255        GLfloat d;
     256
     257        SUB_3V(VP, light->Position, vertex);
     258        d = LEN_3FV( VP );
     259
     260        if ( d > 1e-6) {
     261            GLfloat invd = 1.0F / d;
     262            SELF_SCALE_SCALAR_3V(VP, invd);
     263        }
     264        attenuation = 1.0F / (light->ConstantAttenuation + d *
     265                               (light->LinearAttenuation + d *
     266                                light->QuadraticAttenuation));
     267
     268        if (light->Flags & LIGHT_SPOT)
     269        {
     270            GLfloat PV_dot_dir = - DOT3(VP, light->NormDirection);
     271
     272            if (PV_dot_dir<light->CosCutoff) {
     273               continue;
     274            }
     275            else
     276            {
     277               double x = PV_dot_dir * (EXP_TABLE_SIZE-1);
     278               int k = (int) x;
     279               GLfloat spot = (GLfloat) (light->SpotExpTable[k][0]
     280                               + (x-k)*light->SpotExpTable[k][1]);
     281               attenuation *= spot;
     282            }
     283        }
    289284      }
    290285
    291286      if (attenuation < 1e-3)
    292         continue;
     287        continue;
    293288
    294289      n_dot_VP = DOT3( normal, VP );
    295290
    296291      if (n_dot_VP < 0.0F) {
    297         ACC_SCALE_SCALAR_3V(color, attenuation, light->MatAmbient[0]);
    298         continue;
     292        ACC_SCALE_SCALAR_3V(color, attenuation, light->MatAmbient[0]);
     293        continue;
    299294      }
    300295
     
    304299
    305300      if (light->IsMatSpecular[0]) {
    306         if (ctx->Light.Model.LocalViewer) {
    307             GLfloat v[3];
    308             COPY_3V(v, vertex);
    309             NORMALIZE_3FV(v);
    310             SUB_3V(VP, VP, v);
    311             h = VP;
    312             normalized = 0;
    313         }
    314         else if (light->Flags & LIGHT_POSITIONAL) {
    315             h = VP;
    316             ACC_3V(h, ctx->EyeZDir);
    317             normalized = 0;
    318         }
     301        if (ctx->Light.Model.LocalViewer) {
     302            GLfloat v[3];
     303            COPY_3V(v, vertex);
     304            NORMALIZE_3FV(v);
     305            SUB_3V(VP, VP, v);
     306            h = VP;
     307            normalized = 0;
     308        }
     309        else if (light->Flags & LIGHT_POSITIONAL) {
     310            h = VP;
     311            ACC_3V(h, ctx->EyeZDir);
     312            normalized = 0;
     313        }
    319314         else {
    320             h = light->h_inf_norm;
    321             normalized = 1;
    322         }
    323        
    324         n_dot_h = DOT3(normal, h);
    325 
    326         if (n_dot_h > 0.0F) {
    327             struct gl_material *mat = &ctx->Light.Material[0];
    328             GLfloat spec_coef;
    329             GLfloat shininess = mat->Shininess;
    330 
    331             if (!normalized) {
    332                n_dot_h *= n_dot_h;
    333                n_dot_h /= LEN_SQUARED_3FV( h );
    334                shininess *= .5;
    335             }
    336        
    337             if (n_dot_h>1.0) {
    338                spec_coef = (GLfloat) pow( n_dot_h, shininess );
    339             }
     315            h = light->h_inf_norm;
     316            normalized = 1;
     317        }
     318
     319        n_dot_h = DOT3(normal, h);
     320
     321        if (n_dot_h > 0.0F) {
     322            struct gl_material *mat = &ctx->Light.Material[0];
     323            GLfloat spec_coef;
     324            GLfloat shininess = mat->Shininess;
     325
     326            if (!normalized) {
     327               n_dot_h *= n_dot_h;
     328               n_dot_h /= LEN_SQUARED_3FV( h );
     329               shininess *= .5;
     330            }
     331
     332            if (n_dot_h>1.0) {
     333               spec_coef = (GLfloat) pow( n_dot_h, shininess );
     334            }
    340335            else {
    341                struct gl_shine_tab *tab = ctx->ShineTable[0];
    342                GET_SHINE_TAB_ENTRY( tab, n_dot_h, spec_coef );
    343             }
    344 
    345             if (spec_coef > 1.0e-10) {
    346                ACC_SCALE_SCALAR_3V( contrib, spec_coef,
    347                                     light->MatSpecular[0]);
    348                specular += spec_coef * light->sli * attenuation;
    349             }
    350         }
     336               struct gl_shine_tab *tab = ctx->ShineTable[0];
     337               GET_SHINE_TAB_ENTRY( tab, n_dot_h, spec_coef );
     338            }
     339
     340            if (spec_coef > 1.0e-10) {
     341               ACC_SCALE_SCALAR_3V( contrib, spec_coef,
     342                                    light->MatSpecular[0]);
     343               specular += spec_coef * light->sli * attenuation;
     344            }
     345        }
    351346      }
    352347
     
    368363                  + specular * s_a;
    369364      if (ind > mat->SpecularIndex) {
    370         ind = mat->SpecularIndex;
     365        ind = mat->SpecularIndex;
    371366      }
    372367      *index = (GLuint) (GLint) ind;
Note: See TracChangeset for help on using the changeset viewer.