fb:porticula NoPaste
Emboss_05.bas
Uploader: | Muttonhead |
Datum/Zeit: | 17.02.2014 15:56:30 |
'******************************************************************************
const as single pi =atn (1) * 4
const as single doublepi=pi*2
const as single halfpi=pi/2
'******************************************************************************
#include "fbgfx.bi"
using FB
#include "ColorDefinition.bi"
dim as ColorDefinition s,d
'******************************************************************************
'******************************************************************************
'******************************************************************************
declare function GetDiffHeight(Azimut as single, PixelCenterHeight as ubyte, PixelEastHeight as ubyte, PixelNorthHeight as ubyte, PixelWestHeight as ubyte, PixelSouthHeight as ubyte) as integer
Screen 19,32
dim as any ptr BumpSource = ImageCreate(640,480)
BLoad "BumpMap2.bmp",BumpSource
'Verortung Licht im Koordinatensystem
'Licht kommt für jedes Pixel aus einer Richtung und einer Höhe, parallele Lichtstrahlen ähnlich Sonne
dim as single LightAzimutRad,LightHeightRad
'das zu untersuchende Pixel
dim as integer PixelPosX,PixelPosY,PixelPosZ'Position desPixels
'Höhe der Nachbarpixel
dim as integer PixelEastPosZ,PixelNorthPosZ,PixelWestPosZ,PixelSouthPosZ
'Umgebung
dim as integer EnvDiffHeight' Höhendifferenz der Umgebung zur Höhe des zu untersuchenden Pixels
dim as single EnvRad'Neigungswinkel der Umgebung in Richtung Lichtquelle
dim as single LightEnvRad'Höhe Licht bezogen auf Neigung der Umgebung
'Berechnungshilfen
dim as integer EnvDist=50'künstlicher Wert, Entfernung unter der die benachbarten Pixel betrachtet werden
'Darstellung
dim as integer Xo,Yo
Xo=0
Yo=479
'Sonne
LightAzimutRad=doublepi * .33
LightHeightRad=halfpi/2
For y As integer= 0 to 479
For x As integer=0 to 639
PixelPosX=X
PixelPosY=y
'0.alle Höhen der vier anliegenden Pixel aus BumpSource holen,Farbwert Pixel merken (in d)
d.SetRGB(point(PixelPosX,Yo-PixelPosY,BumpSource))
PixelPosZ=255 * d.GetValue/100
PixelEastPosZ=PixelPosZ
PixelNorthPosZ=PixelPosZ
PixelWestPosZ=PixelPosZ
PixelSouthPosZ=PixelPosZ
if PixelPosX>0 then
s.SetRGB(point(PixelPosX+1,Yo-PixelPosY,BumpSource))
PixelEastPosZ=255 * s.GetValue/100
end if
if PixelPosX<639 then
s.SetRGB(point(PixelPosX-1,Yo-PixelPosY,BumpSource))
PixelWestPosZ=255 * s.GetValue/100
end if
if PixelPosY>0 then
s.SetRGB(point(PixelPosX,Yo-PixelPosY-1,BumpSource))
PixelNorthPosZ=255 * s.GetValue/100
end if
if PixelPosY<479 then
s.SetRGB(point(PixelPosX,Yo-PixelPosY+1,BumpSource))
PixelSouthPosZ=255 * s.GetValue/100
end if
'1. Höhendifferenz Gelände in Richtung Licht berechnen
EnvDiffHeight=GetDiffHeight(LightAzimutRad,PixelPosZ,PixelEastPosZ,PixelNorthPosZ,PixelWestPosZ,PixelSouthPosZ)
'2.Geländewinkel in Richtung Licht berechnen
'Die Höhendifferenz aus einer bestimmten"Entfernung" betrachten
EnvRad=atan2(EnvDiffHeight,EnvDist)
'3.Höhe Licht im Bezug zu Geländewinkel berechnen
LightEnvRad=LightHeightRad-EnvRad
if LightEnvRad>halfpi then LightEnvRad=pi-LightEnvRad
'4. Farbe berechnen
if LightEnvRad>(halfpi *.85)then d.SetSaturation(d.GetSaturation - 100 * (LightEnvRad/pi))'Sättigung verändern
d.SetValue(d.GetValue + 100 * (LightEnvRad/pi))'Hellwert verändern
'5. Pixel setzen
pset(PixelPosX,Yo-PixelPosY),d.GetRGB
Next x
Next y
bsave"screenshot.bmp",0
imagedestroy BumpSource
sleep
'*******************************************************************************
function GetDiffHeight(Azimut as single, PixelCenterHeight as ubyte, PixelEastHeight as ubyte, PixelNorthHeight as ubyte, PixelWestHeight as ubyte, PixelSouthHeight as ubyte) as integer
dim as integer Quadrant,QStartHeight,QEndHeight
dim as single QRad
Quadrant=int((Azimut/halfpi)+1)
select case Quadrant
case 1
QStartHeight=PixelEastHeight
QEndHeight=PixelNorthHeight
QRad=Azimut
case 2
QStartHeight=PixelNorthHeight
QEndHeight=PixelWestHeight
QRad=Azimut-halfpi
case 3
QStartHeight=PixelWestHeight
QEndHeight=PixelSouthHeight
QRad=Azimut-pi
case 4
QStartHeight=PixelSouthHeight
QEndHeight=PixelEastHeight
QRad=Azimut-(pi+halfpi)
end select
function=QStartHeight + (sin(QRad*2-halfpi)+1)/2*(QEndHeight-QStartHeight) - PixelCenterHeight
end function