[bb] Glass by jfk EO-11110 [ 1+ years ago ]

Started by BlitzBot, June 29, 2017, 00:28:42

Previous topic - Next topic

BlitzBot

Title : Glass
Author : jfk EO-11110
Posted : 1+ years ago

Description : Probably not useful for Games but nice looking in Demos etc.

Code :
Code (blitzbasic) Select
; Glass FX by norc of CSP
Graphics3D 640,480,16,2
SetBuffer BackBuffer()

; -----------------create a scene---------------------
Global camera=CreateCamera()
MoveEntity camera,0,5,-50
li=CreateLight()
RotateEntity li,45,45,45
ter=CreateCube()
ScaleEntity ter,50,50,50
tertex=CreateTexture(128,128)
Color 0,255,0
SetBuffer TextureBuffer(tertex)
For j=0 To 15
 For i=0 To 15
  Rect i*16,0,5,128
  Rect 0,j*16,128,5
 Next
Next
Color 255,0,0
Text 0,64,"Hello world",0,1
SetBuffer BackBuffer()
FlipMesh ter
EntityTexture ter,tertex

For i=0 To 15
 cube=CreateCube()
 If Rand(100)>50
  PositionEntity cube,49,Rand(-49,49),Rand(-49,49)
 Else
  PositionEntity cube,Rand(-49,49),Rand(-49,49),49
 EndIf
 EntityColor cube,Rand(255),Rand(255),Rand(255)
 ScaleEntity cube,Rnd(2,10),Rnd(2,10),Rnd(2,10)
 RotateEntity cube,Rand(360),Rand(360),Rand(360),1
 EntityParent cube,ter
Next
TurnEntity ter,0,45,0
; ----------------eo scene----------------



Global glass_o=CreateSphere(12)
Global glass_i=CreateSphere(12)
ScaleEntity glass_o,15,15,15
ScaleEntity glass_i,13.5,13.5,13.5
FlipMesh glass_o
;EntityFX glass_i,1
;EntityFX glass_o,1


Global texs=256 ; glass texture size
Global tex2=CreateTexture(texs,texs,9) ; use Bit 256 here - something's wrong with my machine...
EntityTexture glass_i,tex2
EntityTexture glass_o,tex2
;probably add enviroment mapping on the outter hull (using texture index 1 and FX 16 or as a seperate Mesh)
EntityParent glass_o,glass_i

;-------------
While KeyDown(1)=0
 a#=a#+2 Mod 360
 PositionEntity glass_i,Cos(a#)*15,Sin(a#)*15,0,1
 mapglass()
 RenderWorld()
 Flip
Wend
End
; -----------

Function mapglass()
 oro#=EntityRoll(camera,1)
 oya#=EntityYaw(camera,1)
 opi#=EntityPitch(camera,1)
 ox#=EntityX(camera,1)
 oy#=EntityY(camera,1)
 oz#=EntityZ(camera,1)
 CameraZoom camera,1.1 ; check it out
 PointEntity camera,glass_i
 PositionEntity camera,EntityX(glass_i,1),EntityY(glass_i,1),EntityZ(glass_i,1),1
 CameraViewport camera,0,0,texs,texs
 HideEntity glass_i
 HideEntity glass_o
 RenderWorld()
 CopyRect 0,0,texs,texs,0,0,BackBuffer(),TextureBuffer(tex2)
 ShowEntity glass_i
 ShowEntity glass_o
 CameraViewport camera,0,0,GraphicsWidth(),GraphicsHeight()
 PositionEntity camera,ox,oy,oz,1
 RotateEntity camera,opi,oya,oro,1
 CameraZoom camera,1.0
End Function


Comments :


Clyde(Posted 1+ years ago)

 Cheers for a great effect dude :)


puki(Posted 1+ years ago)

 Did "jfk" just release this?  I've had this for yonks.  The reason I mention this is I have just noticed that the code archives don't show the submission date for the intial code.  This needs fixing (in my opinion).


Filax(Posted 1+ years ago)

 A little update :)
; Glass FX by norc modified by filax
Graphics3D 640,480,16,2
SetBuffer BackBuffer()

Type Effect_Glass
Field Camera
Field EntityIn
Field EntityOut
Field Scale#
Field Border#
Field Glass
Field Reflect
End Type

Function Proc_CreateGlassSphere(Camera,Scale#,Border#,ReflectMap$)
F.Effect_Glass=New Effect_Glass
FCamera=Camera
FEntityIn=CreateSphere(30)
FEntityOut=CreateSphere(20)
FScale#=Scale#
FBorder#=Border#

FGlass=CreateTexture(128,128)
FReflect=LoadTexture(ReflectMap$,64)

ScaleEntity FEntityIn,FScale#-FBorder#,FScale#-FBorder#,FScale#-FBorder#
ScaleEntity FEntityOut,FScale#,FScale#,FScale#

EntityTexture FEntityIn,FGlass,0,0
EntityTexture FEntityOut,FGlass,0,0

EntityTexture FEntityIn,FReflect,0,1
EntityTexture FEntityOut,FReflect,0,1

TextureBlend FReflect,3

FlipMesh FEntityOut

EntityShininess FEntityIn,1
EntityShininess FEntityOut,1

EntityParent FEntityOut,FEntityIn

Return FEntityIn
End Function

Function Proc_UpdateGlassSphere()
For F.Effect_Glass=Each Effect_Glass
Obj_Roll#=EntityRoll(FCamera,1)
Obj_Yaw#=EntityYaw(FCamera,1)
  Obj_Pitch#=EntityPitch(FCamera,1)
  Obj_Px#=EntityX(FCamera,1)
  Obj_Py#=EntityY(FCamera,1)
  Obj_Pz#=EntityZ(FCamera,1)

CameraZoom FCamera,1.3 ; check it out
  PointEntity FCamera,FEntityIn
  PositionEntity FCamera,EntityX(FEntityIn,1),EntityY(FEntityIn,1),EntityZ(FEntityIn,1),1
 
  CameraViewport camera,0,0,TextureWidth(FGlass),TextureHeight(FGlass)
  HideEntity FEntityIn
  HideEntity FEntityOut

  RenderWorld()

CopyRect 0,0,TextureWidth(FGlass),TextureHeight(FGlass),0,0,BackBuffer(),TextureBuffer(FGlass)

ShowEntity FEntityIn
  ShowEntity FEntityOut
  CameraViewport FCamera,0,0,GraphicsWidth(),GraphicsHeight()
  PositionEntity FCamera,Obj_Px,Obj_Py,Obj_Pz,1
  RotateEntity FCamera,Obj_Pitch,Obj_Yaw,Obj_Roll,1
  CameraZoom FCamera,1.0
Next
End Function

; -----------------create a scene---------------------
Global camera=CreateCamera()
MoveEntity camera,0,5,-50
li1=CreateLight(2)
PositionEntity li1,-45,45,-45
LightRange li1,100

li2=CreateLight(2)
PositionEntity li2,45,-45,45
LightRange li2,100

ter=CreateCube()
ScaleEntity ter,50,50,50
tertex=CreateTexture(128,128)
Color 0,255,0
SetBuffer TextureBuffer(tertex)
For j=0 To 15
 For i=0 To 15
  Rect i*16,0,5,128
  Rect 0,j*16,128,5
 Next
Next
Color 255,0,0
Text 0,64,"Hello world",0,1
SetBuffer BackBuffer()
FlipMesh ter
EntityTexture ter,tertex

For i=0 To 15
 cube=CreateCube()
 If Rand(100)>50
  PositionEntity cube,49,Rand(-49,49),Rand(-49,49)
 Else
  PositionEntity cube,Rand(-49,49),Rand(-49,49),49
 EndIf
 EntityColor cube,Rand(255),Rand(255),Rand(255)
 ScaleEntity cube,Rnd(2,10),Rnd(2,10),Rnd(2,10)
 RotateEntity cube,Rand(360),Rand(360),Rand(360),1
 EntityParent cube,ter
Next
TurnEntity ter,0,45,0


MyMesh1=Proc_CreateGlassSphere(Camera,15,1,"C:FilouDemo CodingDatas-SyncronizBackground 01.jpg")
MyMesh2=Proc_CreateGlassSphere(Camera,15,1,"C:FilouDemo CodingDatas-SyncronizBackground 02.jpg")

;-------------
While KeyDown(1)=0
 a#=a#+2 Mod 360

 PositionEntity MyMesh1,Cos(a#)*15,Sin(a#)*15,Cos(a#)*15,1
 PositionEntity MyMesh2,-Cos(a#)*15,-Sin(a#)*15,-Cos(a#)*15,1
;PositionTexture tex3 ,0,a#/160
;RotateTexture tex3 ,a#/13


 Proc_UpdateGlassSphere()
 
 RenderWorld()
 Flip
Wend
End



RemiD(Posted 1+ years ago)

 @jfk>>very nice effect !


Dan(Posted 1+ years ago)

 I havent sleept very well, last night, so i thought it was a new effect, but on a closer look:Filax (Posted 11 years ago)
RemiD (Posted 11 hours ago)
)yeah, its a nice code, and runs at <a href="https://www.youtube.com/watch?v=ygE01sOhzz0" target="_blank">ludicrous speed</a>, when flip is set to false [/i]