Эффект искажения изображения в среде Blitz3D. Автор кода Igor.

Работает на всех разрешениях.
Кнопки:
A/D-Уменьшить/увеличить искажение.
Space-Флип меш.

Global GW#=0
Global GH#=0
Global YOffset#=0
Global PX#
Global PY#
Global URatio#=0
Global VRatio#=0
Global ScreenTexture=0

Function InitShader()
GW#=GraphicsWidth()
GH#=GraphicsHeight()
YOffset#=(GH#/GW#)/2
URatio#=1/GW#
VRatio#=1/GH#
ScreenTexture=CreateTexture(GW#,GH#,256)
ScaleTexture ScreenTexture,TextureWidth(ScreenTexture)/GW#,TextureHeight(ScreenTexture)/GH#
End Function

Function ProjectToScreen(Camera,X#,Y#,Z#)
TFormPoint X#,Y#,Z#,0,Camera
PX#=(((TFormedX#())*(1/TFormedZ#()/2))+.5)*GW#
PY#=GH-(((TFormedY#())*(1/TFormedZ#()/2))+YOffset#)*GW#
End Function

Function ProjectVertexCoords(Camera,Mesh,NRatio#=0)
For SurfaceIndex=1 To CountSurfaces(Mesh)
Local Surface=GetSurface(Mesh,SurfaceIndex)
For Vertex=0 To CountVertices(Surface)-1
Local VX#=(VertexX#(Surface,Vertex)*GetMatElement(Mesh,1,1))+VertexNX#(Surface,Vertex)*NRatio#
Local VY#=(VertexY#(Surface,Vertex)*GetMatElement(Mesh,2,2))+VertexNY#(Surface,Vertex)*NRatio#
Local VZ#=(VertexZ#(Surface,Vertex)*GetMatElement(Mesh,3,3))+VertexNZ#(Surface,Vertex)*NRatio#

TFormPoint VX#,VY#,VZ#,Mesh,0
ProjectToScreen(Camera,TFormedX#(),TFormedY#(),TFormedZ#())
If PX#>GW# PX#=0
If PX#<0 PX#=0
If PY#>GH# PY#=0
If PY#<0 PY#=0
VertexTexCoords Surface,Vertex,PX#*URatio#,PY#*VRatio#
Next
Next
End Function

Function ShaderRendering()
RenderWorld
CopyRect  0,0,GW#,GH#,0,0,BackBuffer(),TextureBuffer(ScreenTexture)
End Function

Graphics3D 800,600,32,1
SetBuffer BackBuffer()

InitShader()

Camera=CreateCamera():PositionEntity Camera,0,0,-5:CameraClsColor Camera,100,100,100
Sphere=CreateSphere(20):EntityTexture Sphere,ScreenTexture:FlipMesh Sphere
Cube=CreateCube():PositionEntity Cube,0,0,5

EntityFX Sphere,1
CreateLight()

Global NRatio#=0

While Not KeyHit(1)
If KeyHit(57) FlipMesh Sphere
If KeyDown(30) NRatio#=NRatio#-.01
If KeyDown(32) NRatio#=NRatio#+.01
mxs#=MouseXSpeed()*.01
mys#=MouseYSpeed()*.01
MoveEntity Sphere,mxs#,-mys#,0
MoveMouse GW#/2,GH#/2
HideEntity Sphere
ShaderRendering()
ShowEntity Sphere
ProjectVertexCoords(Camera,Sphere,NRatio#)
UpdateWorld
RenderWorld
Flip
Wend
End
(Visited 346 times, 1 visits today)