Per Pixel Lighting

Previous topic - Next topic

Sebastian

Vielleicht nicht gerade das kreativste Snippet und ausserdem ist fast alles aus dem Shadow Beispiel kopiert, aber ich denke der Gedanke zählt  :whistle:
English:
Maybe not the most creative snippet and almost the whole code is copied from the shadow example but I think the idea is what is really important  :whistle:

Code (glbasic) Select
// konstante Werte / Constant values
LOCAL image, bump, none, shadow, sphere, donut, cube, spot_ang, lmode, phi, lx
LOCAL ly, lz, i, psi, px, py, pz, j

none = -1
image = 0
bump = 1 // unsere Bump Map, nicht vergessen oben zu deklarieren! / our bump map, do not forget to declare in the first line!

donut  = 0
cube   = 1
sphere = 2
// Create Primitives
CreateTorus (donut, 10, 20, 36, 12, 2, 2, RGB(255,255,255))
CreateCube  (cube, -1000, RGB(255, 255, 255))

// Grafiken laden / load graphics
LOADSPRITE      "image.bmp", image
LOADBUMPTEXTURE "bump2.bmp",  bump // unsere komplett weisse bmp Datei / our complete white bmp file
LOCAL mx, my, b1, b2 // compiler warning

WHILE TRUE
// naja... / well...
mx = mx + MOUSEAXIS(0)
// MOUSESTATE mx, my, b1, b2

// 1000 ist weit genug hier / 1000 is far enough here
X_MAKE3D 1, 1700, 45

// ein Winkel für alles / one angle for everything
phi = GETTIMERALL() / 250

// eine Lichtposition / a light position
lx = SIN(-phi*3)*300
ly = 20 //(SIN(3*phi)-COS(4*phi))*100
lz = COS(-phi*3)*300

// Maus X=drehen / Mouse X=turn
X_CAMERA 400*COS(mx),120,400*SIN(mx), 0,0,0

// Licht als Punkt zeichnen / Draw light as dot
X_DOT lx,ly,lz,32,RGB(255,255,255)

// Texture setzen und Bump Map/ Set texture and bump map
X_SETTEXTURE image, bump

X_CULLMODE 1

X_SPOT_LT   -1, RGB(255,255,255), lx,ly,lz, -lx,-ly,-lz, 360 //benutze -1 für Dot3 Mapping /use -1 for Dot3 mapping

// Würfel zeichnen / Draw Cube
X_DRAWOBJ cube, 0

// Donut zeichnen / Draw Donut
X_MOVEMENT 0,0,0
X_ROTATION 90, 1,0,0
X_DRAWOBJ donut,0

// Schatten einschalten / turn on Shadows
X_SPOT_LT  -3, RGB(255,255,255), lx,ly,lz, -lx,-ly,-lz, 360

// neuzechnen von schatten-werfenden Objekten
// re-draw shadow casting objects
X_MOVEMENT 0,0,0
X_ROTATION 90, 1,0,0
X_DRAWOBJ donut,0

// Schatten zeichnen / draw shadows
X_SPOT_LT  -3, 0, 0,0,0, 0,0,0, 0
// oder / or
// X_MAKE2D, SHOWSCREEN, X_MAKE3D


// zum Zurechtfinden / for navigation
X_MAKE2D
SHOWSCREEN
WEND

bump2.bmp ist übrigens einfach ein komplett weisses (oder schwarzes oder beliebig monochromes) Quadrat. Der Trick liegt darin, dass die Hardwarelichter beim Dot3 Mapping (Bump Mapping) auf die Daten aus der Bump Map zurückgreifen und nicht auf die Vertices des 3D Objekts. D.h. anstatt ganze Vertices zu erhellen, werden die Pixel auf dem Modell erhellt, was einen viel hübscheren und feineren Eindruck macht. Das ganze funktioniert selbsverständlich auch mit "richtigen" BumpMaps, aber vielleicht habe ich ja jetzt den ein oder anderen dazu gebracht, Dot3 Mapping in seinem Projekt zu benutzen obwohl er gar keine Bump Maps benutzt  :booze:

English:
bump2.bmp is simply a complete white (or black or grey) square. The trick is that the hardware lights use the data from the bump map instead of the vertex data of the 3D mesh when using Dot3 mapping. This automatically leads to a per pixel lighting rather than a per vertex lighting. Normally this is one of the most important features in modern engines and every engine I know uses shaders for that. This shows
1. you don't need shaders for everything (I'm so totally not a fan of shaders, even with my nice SM4 card and Vista)
2. even if you are not interested in normal mapping, it might still be interesting for you if you want better lighting.

WPShadow

Kannst du mal ein geRARtes Beispiel oder einen Screenshot hoch laden? Wäre gespannt...  :nw:
AMD X2 4600, 2 GB Ram, ATI X1950 XTX, XP PRO SP2: GLB Premium 10.beta_dingsi, <(´.´<) Kirby Dance (>`.`)>
http://lostrevenant.blogspot.com
alea iacta est

Sebastian

Jap, ein Beispiel mit exe, Quellcode und Material ist in Planung.
Muss nur noch dazu kommen, es zu schreiben. Jetzt erst mal Uni  :neutral:

Sebastian

Ich werd zwar eine trotzdem eine Demo machen, aber jetzt wüsste ich zu gerne, wie der GLBasic das mit dem Dot3 Mapping macht...
Mir ist nämlich aufgefallen, dass beim normalen Lighting (ohne Echtzeitschatten) die Modelle sauber überblendet werden. Nix Vertex Lighting á la Blitz3D. Wie zum Geier funktioniert das Gernot? Das kann man ja quasi als Feature auf der Hauptseite aufführen...
Oder liegt es am Ende vielleicht an OpenGL? Macht das beim Hardware Lighting irgendwie was anderes als DirectX?  :zzz:

Kitty Hello

man muss halt saubere Normalenvektoren liefern, dann wird's weich.