SetAlphamap von Vertex |
Hi! Kleine Funktion zum setzen einer Alphamap auf eine Textur. [code:1:2377e3ce6a] Function SetAlphamap(Texture,Alphamap) Local OldBuffer,TexBuffer,AlphaBuffer Local TexWidth,TexHeight,AlphaWidth Local AlphaHeight,M1#,M2#,X,Y,RGB1,R,G,B Local RGB2,A,ARGB OldBuffer = GraphicsBuffer() TexBuffer = TextureBuffer(Texture) AlphaBuffer = TextureBuffer(Alphamap) TexWidth = TextureWidth(Texture) TexHeight = TextureHeight(Texture) AlphaWidth = TextureWidth(Alphamap) AlphaHeight = TextureHeight(Alphamap) M1# = Float#(TexWidth) / Float#(AlphaWidth) M2# = Float#(TexHeight) / Float#(AlphaHeight) SetBuffer TexBuffer : LockBuffer LockBuffer AlphaBuffer For X = 0 To TexWidth - 1 For Y = 0 To TexHeight - 1 RGB1 = ReadPixelFast(X,Y,TexBuffer) R = (RGB1 And $FF0000) / $10000 G = (RGB1 And $FF00) / $100 B = (RGB1 And $FF) RGB2 = ReadPixelFast(M1# * X,M2# * Y,AlphaBuffer) A = (RGB2 And $FF0000) / $10000 ARGB = A * $1000000 + R * $10000 + G * $100 + B WritePixelFast(X,Y,ARGB,TexBuffer) Next Next UnlockBuffer AlphaBuffer UnlockBuffer : SetBuffer OldBuffer End Function [/code:1:2377e3ce6a] Die Textur Texture muss im Modus 2 geladen sein. also z.B. : Texture = LoadTexture("MeineTextur.png",2) Alphamap = LoadTexture("MeineAlphamap.png",256) SetAlphamap(Texture,Alphamap) FreeTexture Alphamap Je nach dem könnt ihr die Funktion auch ändern, damit man als Alphamap keine Textur sondern ein Image angeben braucht. (Einfach nur TextureBuffer in ImageBuffer, TextureWidth und ImageWidth und TextureHeight und ImageHeight umändern) Die Funktion berücksichtigt die Größenverhältnisse, und skaliert automatisch die Alphamap auf Größe der Textur. Anwendung findet diese Funktion z.B. in meinem Milkshape-Importer: http://vertex.art-fx.org/index.php?id=0102001 mfg olli |