www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/04/15/05:46:30

From: "Nick Anderson" <andersnd AT aol DOT com>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Terrain Shading in Allegro
Date: Wed, 15 Apr 1998 09:33:40 +0100
Organization: [not set]
Lines: 73
Message-ID: <6h1rfm$897$1@svr-c-02.core.theplanet.net>
References: <01bd6738$2a16aac0$a3a325cb AT jring>
NNTP-Posting-Host: gate-isdn.telsci.co.uk
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

> I have been using Allegro for drawing 3D terrains from a set of random
>points (turned into a set of edge-connected triangular polygons) and it
>works well, but I really need to shade the terrain for a bit of realism and
>better perspective (at the moment, its just a big unicolor blob with the
>polys in the right place!).  Texture mapping doesn't seem to be a realistic
>way of getting shading working so I was wondering if anyone knew how to
>shade a series of triangular polygons across the whole set of polygons (as
>if the light source was shining in one place onto the whole set of
>triangular polygons).  Any information pertaining to this subject would be
>greatly appreciated as I am relatively new to 3D programming.


Are you using a global variable like:
y[128][128] to hold the landscape in?

if so, what I do is have a colour gradient going from black to white in my
colour palette(0 to 15 in the index).

so, pal[0] = black
...
pal[7] = grey
...
pal[15] = white

I have another global matrix called
int colour[128][128];
which holds the colour at each point on the terrain.

I then say:-

void shading() {

    float gradient;

    for(x=0; x<128; x++)
        for(z=0; z<128; z++) {

        // Take the height of the next point (x+1,z) from the
        // current point (x,z) to get a gradient.

        gradient = 8 + (y[x][z] - y[x+1][z]);
        colour[x][z] = (int)gradient;

        // Now check boundary points.

        if(colour[x][z] > 15)
            colour[x][z] = 15;
        else if(colour[x][z] < 0)
            colour[x][z] = 15;

    }

}


You often need to play about with the

    colour[x][z] = 8 + (y[x][z] - y[x+1][z]);

code until it looks about right.

Yours sincerely,
Nick Anderson.
email: andersnd AT NOSPAMPLEASEhotmail DOT com - remove NOSPAMPLEASE from the email
address.


P.S. Jason, if you want, send me your email and I will
send my source for my Allegro 3d engine as soon as
it is finished.


- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019