-
Notifications
You must be signed in to change notification settings - Fork 4
/
bumptest.bmx
76 lines (53 loc) · 1.64 KB
/
bumptest.bmx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
SuperStrict
Framework mky.mojo2
?Not opengles
Import brl.GLGraphics
?opengles
Import sdl.sdlgraphics
?
Import brl.pngloader
Graphics 640, 480, 0
'generate color texture
Local colortex:TTexture=New TTexture.Create( 256,256,PF_RGBA8888,TTexture.ClampST|TTexture.RenderTarget )
Local rcanvas:TCanvas=New TCanvas.CreateCanvas( colortex )
rcanvas.Clear( 1,1,1 )
rcanvas.Flush
'generate normal texture
Local normtex:TTexture=New TTexture.Create( 256,256,PF_RGBA8888,TTexture.ClampST|TTexture.RenderTarget )
rcanvas.SetRenderTarget( normtex )
rcanvas.Clear( .5,.5,1.0,0.0 )
For Local x:Int=0 Until 256 'Step 32
For Local y:Int=0 Until 256 'Step 32
Local dx:Float=x-127.5
Local dy:Float=y-127.5
Local dz:Float=127.5*127.5-dx*dx-dy*dy
If dz<=0 Continue
dz=Sqr( dz )
Local r:Float=(dx+127.5)/255.0
Local g:Float=(dy+127.5)/-255.0
Local b:Float=(dz+127.5)/255.0
rcanvas.SetColor( r,g,b,1 )
rcanvas.DrawPoint( x,y )
Next
Next
rcanvas.Flush
Local material:TMaterial=New TMaterial.Create( TShader.BumpShader() )
material.SetTexture( "ColorTexture",colortex )
material.SetTexture( "NormalTexture",normtex )
material.SetVector( "AmbientColor",[0.0,0.0,0.0,1.0] )
Local image:TImage=New TImage.CreateMaterial( material,.5,.5 )
Local canvas:TCanvas=New TCanvas.CreateCanvas()
canvas.SetAmbientLight .2,.2,.2
Local rot:Float
While Not KeyDown(key_escape)
canvas.Clear 0,0,0
'Set light 0
canvas.SetLightType 0,1
canvas.SetLightColor 0,.3,.3,.3
canvas.SetLightPosition 0,MouseX(),MouseY(),-100
canvas.SetLightRange 0,400
rot:+1
canvas.DrawImageXYZS image,GraphicsWidth()/2,GraphicsHeight()/2,rot,.5,.5
canvas.Flush
Flip
Wend