Emulating more advanced shader effects with specular by SFSW15th May 2008 12:42
|
---|
Summary Using the specular shader in DBC to produce pixel-shader-like and surface texture effects. Description Examples show how to use multiple layers for an improved specular effect (using no pixel shaders, just the new fixed function specular shader, works on virtually any 3D card), allowing for tiled surfaces, shimmering light on rough textures (metal for example), along with high and low shine effects. Also illustrates how you can create mild light shifting from white when under direct light, to a softer color when at an angle, to the original color of the surface being reflected. Use the arrow keys to move the center sphere around so it's easier to see the shimmering, the golden shimmer at the edges of the full light level. Media and source is included in the attached ZIP. Code ` This code was downloaded from The Game Creators ` It is reproduced here with full permission ` http://www.thegamecreators.com rem Specular Effects rem Designed to illustrate some simple uses for the specular command rem Written by Shawn, www.starwraith.com set window on set display mode 1024,768,32 sync on sync rate 0 hide mouse enable tnl autocam off draw to front set ambient light 10 load image "base1.jpg",1 load image "base2.jpg",2 load image "ship2_0.jpg",3 load image "brick.jpg",4 load image "brickbump.jpg",5 load image "tile.jpg",20 load image "tilebump.jpg",21 make object plain 5,20,20 color object 5,0 position object 5,0,0,10 make object sphere 1,3 texture object 1,1 scale object texture 1,2,2 position object 1,0,0,5 set object ambient 1,rgb(10,10,10) set object diffuse 1,rgb(255,255,255) set object specular 1,rgb(255,255,200),15 make object sphere 2,3 texture object 2,2 scale object texture 2,2,2 ghost object on 2,1 position object 2,0,0,5 set object ambient 2,rgb(10,10,10) set object diffuse 2,rgb(255,255,255) roll object right 1,30 roll object right 2,30 rem full specular object example make object sphere 3,1.5 texture object 3,3 position object 3,-2.5,2,5 set object ambient 3,rgb(10,10,10) set object diffuse 3,rgb(255,255,255) set object specular 3,rgb(255,255,255),15 roll object right 3,30 rem tiled brick example make object sphere 10,2 texture object 10,4 scale object texture 10,4,4 position object 10,2.5,1.5,5 set object ambient 10,rgb(10,10,10) set object diffuse 10,rgb(255,255,255) set object specular 10,rgb(255,200,200),15 make object sphere 11,2 texture object 11,5 scale object texture 11,4,4 ghost object on 11,1 position object 11,2.5,1.5,5 set object ambient 11,rgb(10,10,10) set object diffuse 11,rgb(255,255,255) roll object right 10,30 roll object right 11,30 rem high gloss tile example make object sphere 20,2 texture object 20,20 scale object texture 20,14,8 position object 20,2.5,-2,5 set object ambient 20,rgb(10,10,10) set object diffuse 20,rgb(255,255,255) set object specular 20,rgb(255,255,255),15 make object sphere 21,2 texture object 21,21 scale object texture 21,14,8 ghost object on 21,1 position object 21,2.5,-2,5 set object ambient 21,rgb(10,10,10) set object diffuse 21,rgb(255,255,255) roll object right 20,30 roll object right 21,30 make light 1 set spot light 1,5,75 position light 1,-5,5,2.5 point light 1,0,0,5 repeat ink rgb(255,255,255),0 center text 150,250,"Full Specular Shine" center text 512,575,"Defined Shine" center text 512,590,"(uses two layers to define height/shine areas, much like a bumpmap)" center text 512,605,"Soft yellowish metallic glow illustrated here, with dark/unreflective areas" center text 512,620,"Gives a rough textured appearance with shimmering light" center text 700,725,"High-gloss tiled specular Shine" center text 850,320,"Semi-gloss tiled brick effect" turn object left 1,0.1 turn object left 2,0.1 turn object left 10,0.1 turn object left 11,0.1 if upkey()>0 then pitch object down 1,0.05:pitch object down 2,0.05 if downkey()>0 then pitch object up 1,0.05:pitch object up 2,0.05 if rightkey()>0 then turn object right 1,0.15:turn object right 2,0.15 if leftkey()>0 then turn object left 1,0.05:turn object left 2,0.05 turn object left 3,0.1 turn object left 20,0.1 turn object left 21,0.1 sync until spacekey()>0 |