Ooops
January 26, 2021, 12:04:44 PM

Author Topic: [bb] Underwater Scene by jfk EO-11110 [ 1+ years ago ]  (Read 679 times)

Offline BlitzBot

  • Jr. Member
  • **
  • Posts: 1
[bb] Underwater Scene by jfk EO-11110 [ 1+ years ago ]
« on: June 29, 2017, 12:28:39 AM »
Title : Underwater Scene
Author : jfk EO-11110
Posted : 1+ years ago

Description : Plasmabased Water with Waveshade-Projection on Seaground

Code :
Code: BlitzBasic
  1. ; Plasmabased Water with Seaground-Projection
  2. ; by CSP 2002
  3. ;
  4. Graphics3D 640,480,16,1
  5.  
  6. SetBuffer BackBuffer()
  7. AmbientLight 90,90,100
  8.  
  9. ; Camera
  10. camera=CreateCamera()
  11. CameraRange camera,0.1,17000
  12. CameraFogMode camera,1
  13. CameraFogRange camera,400,2500
  14. CameraFogColor camera,150,170,200
  15. CameraClsMode camera,1,1
  16. CameraClsColor camera,150,170,200
  17.  
  18. light=CreateLight()
  19. RotateEntity light,0,0,45
  20. PositionEntity light,40,300,45
  21.  
  22. ; init Cam Position
  23. Kx#=3528.0
  24. Ky#=-120.0
  25. Kz#=6069.0
  26.  
  27.  
  28. PositionEntity camera,Kx#,Ky#,Kz#
  29. myangel#=110;70
  30. RotateEntity camera,0,myangel,0
  31.  
  32. EntityType camera,TYPE_PLAYER
  33. EntityRadius camera,3.4;3.4
  34.  
  35.  
  36. ; seafloor terrain
  37. If FileType("seahmap1.bmp")=1       ; if File exist then
  38.  ground=LoadTerrain("seahmap1.bmp") ; use this 128*128 heightmap !!!
  39. Else
  40.  ground=CreateTerrain(128)          ; else create one on the fly
  41.  For i=0 To 127
  42.   For j=0 To 127
  43.    If (i And $f)=8
  44.     ModifyTerrain ground,(i),(j),Rnd(0.7,0.9)
  45.    Else
  46.     ModifyTerrain ground,(i),(j),Rnd(0.2)
  47.    EndIf
  48.   Next
  49.  Next
  50. EndIf
  51.  
  52. ; terrain noise
  53. For i=0 To 127
  54.  For j=0 To 127
  55.   tlo#=(TerrainHeight(ground,i,j)+Rnd(-0.1,0.1))/2
  56.   If tlo#<0 Then tlo#=0
  57.   If tlo#>0.62 Then tlo#=0.65
  58.   ModifyTerrain ground,(i),(j),tlo#
  59.  Next
  60. Next
  61.  
  62. ; terrain border
  63. h059#=0.65
  64. For i=0 To 128
  65.  ModifyTerrain ground,i,0,h059#
  66.  ModifyTerrain ground,i,127,h059#
  67.  ModifyTerrain ground,0,i,h059#
  68.  ModifyTerrain ground,127,i,h059#
  69. Next
  70. TerrainShading ground,1  
  71.  
  72.  
  73. ScaleEntity ground,125,1000,125
  74. PositionEntity ground,-8000,0,-6000
  75. TranslateEntity ground,0,-650,0
  76.  
  77. ; init Water etc.
  78. Dim cosinus(640)
  79. position = 0
  80. For c = 0 To 640
  81.  cosinus(c) = Cos((115*3.14159265358 * c) / 320) * 32 + 32
  82. Next
  83. Dim div10(320)
  84. For i=0 To 320
  85.  div10(i)=i/10
  86. Next
  87. Dim f3(255),f45(255),f5(255)
  88. For i=0 To 255
  89.  f3(i)=3*i
  90.  f45(i)=4.5*i
  91.  f5(i)=5*i
  92. Next
  93. mywater=CreateTexture(32,32,9) ; used 4 texture on water
  94. mywater2=CreateTexture(32,32,9) ; used 4 watershade blend on ground
  95. Gosub water
  96. water=CreateTerrain(1)
  97. ScaleTexture mywater,0.01,0.01
  98. ScaleTexture mywater2,2,2
  99. EntityTexture water, mywater,0
  100. ScaleEntity water,500*32,500*32,500*32
  101. PositionEntity water,-8000,0,-6000
  102. EntityAlpha water,0.6
  103. EntityFX water,17
  104.  
  105. ; init sky
  106. sky=CreateSphere()
  107. FlipMesh sky
  108. If FileType("sky.bmp")=1 Then
  109.  sky_tex=LoadTexture("sky.bmp"); use a seamless sky-texture
  110. Else
  111.  sky_tex=CreateTexture(256,256)
  112.  SetBuffer TextureBuffer(sky_tex)
  113.  Color 100,175,255
  114.  Rect 0,0,640,480,1
  115.  SetBuffer BackBuffer()
  116. EndIf
  117. EntityTexture sky,sky_tex
  118. ScaleTexture sky_tex,0.2,0.2
  119. ScaleEntity sky,6000,12000,6000
  120. EntityFX sky,9
  121. EntityOrder sky,1
  122. PositionEntity sky,Kx#,Ky#,Kz#
  123.  
  124. ; cube around camera for additional 'fog'
  125. trueb=CreateCube()
  126. FlipMesh trueb
  127. ScaleEntity trueb,10,10,10
  128. EntityTexture trueb,mywater2
  129. EntityAlpha trueb,0.6
  130. EntityFX trueb,1
  131.  
  132. ; blended Ground-Texture
  133. If FileType("rockground.jpg")=1
  134.  groundtex=LoadTexture("rockground.jpg") ; use a 512*512 Texture (alter Scaling if smaller)
  135. Else
  136.  groundtex=CreateTexture(512,512)
  137.  SetBuffer TextureBuffer(groundtex)
  138.  Color 255,220,100
  139.  Rect 0,0,512,512,1
  140.  For i=0 To 1000
  141.  patt=Rand(80,255)
  142.   Color patt,patt*0.6,patt*0.3
  143.   Line Rand(512),Rand(512),Rand(512),Rand(512)
  144.  Next
  145.  SetBuffer BackBuffer()
  146. EndIf
  147. ScaleTexture groundtex,10,10 ; relatice to Texture-Size
  148. TextureBlend groundtex,3
  149. EntityTexture ground,groundtex,0,0
  150. EntityTexture ground,mywater2,0,1 ; projecting waves onto Floor
  151.  
  152. ; init fps-counter
  153. tt=MilliSecs()
  154. tt2=tt-50
  155. HidePointer
  156.  
  157.  
  158. ; ______________________________________MAINLOOP_____________________________________
  159. While KeyDown(1)=0
  160.  
  161.  Gosub water ; update waves
  162.  
  163.  ; Cam Nav
  164.  my=MouseYSpeed()*5
  165.  If KeyDown(200)=1
  166.   If speed#<50
  167.    speed#=speed#+2
  168.   EndIf
  169.  EndIf
  170.  If speed#>0
  171.   speed#=speed#-1
  172.   If speed#<0
  173.    speed#=0
  174.   EndIf
  175.  EndIf
  176.  Kx#=kx#-Cos(myangel#-90)*speed#
  177.  Kz#=kz#-Sin(myangel#-90)*speed#
  178.  camy#=camy#-my
  179.  If camy#>70 Then camy#=70
  180.  If camy#<-500 Then camy#=-500
  181.  terry#=TerrainY(ground,kx#,0,kz#)+20
  182.  If camy#<terry# Then camy#=terry#
  183.  PositionEntity camera,Kx#,camy#,Kz#
  184.  moro#=MouseXSpeed()
  185.  myangel2#=myangel2#-moro#
  186.  If myangel2#<>myangel#
  187.   myangel#=myangel#+((myangel2#-myangel#)/5)
  188.  EndIf
  189.  RotateEntity camera,0,myangel#,0
  190.  trueby#=camy#
  191.  If trueby#>-10 Then trueby#=-10
  192.  PositionEntity trueb,Kx#,trueby#,Kz#
  193.  RotateEntity trueb,0,myangel#,0
  194.  PositionEntity sky,Kx#,0,Kz#
  195.  MoveMouse 320,240
  196.  
  197.  UpdateWorld()
  198.  RenderWorld()
  199.  
  200.  tt=MilliSecs()
  201.  fps=1000.0/(tt-tt2)
  202.  tt2=tt
  203.  Text 0,0,fps
  204.  
  205.  Flip
  206.  
  207. Wend
  208. ; ------------------------------------- eo mainloop -------------------------------------
  209.  
  210. End
  211.  
  212. .water
  213.  wave1% = wave1% + 4
  214.  wave2% = wave2% + 2
  215. ; use this if the waves are moving to fast:
  216. ; wave1% = wave1% + 2
  217. ; wave2% = wave2% + 1
  218.  If wave1% >= 320 Then wave1% = 0
  219.  If wave2% >= 320 Then wave2% = 0
  220.  SetBuffer TextureBuffer(mywater)
  221.  LockBuffer
  222.    For y% = 0 To 319 Step 10
  223.     y10=div10(y)
  224.     d = cosinus(y + wave2) + cosinus(Y + wave2)
  225.     For x% = 0 To 319 Step 10
  226.      x10=div10(x)
  227.      f = 1 + Abs(((cosinus(x + wave1) + cosinus(x + y) + d) / 8) - 16)
  228.      rr=105-f3(f)
  229.      If rr<0 Then rr=0
  230.      gg=185-f45(f)
  231.      If gg<0 Then gg=0
  232.      bb=195-f5(f)
  233.      If bb<0 Then bb=0
  234.     WritePixelFast x10,y10,((rr Shl 16) Or (gg Shl 8) Or bb)
  235.    Next
  236.   Next
  237.  UnlockBuffer
  238. CopyRect 0,0,32,32,0,0, TextureBuffer(mywater), TextureBuffer(mywater2)
  239. SetBuffer BackBuffer()
  240. Return


Comments :


mag.(Posted 1+ years ago)

 this look great


Trader3564(Posted 1+ years ago)

 nice, it would need "waves" tough.


bytecode77(Posted 1+ years ago)

 looking great. i always love to take a look into your code archive entries...


 

SimplePortal 2.3.6 © 2008-2014, SimplePortal