Code: Select all
Procedure RenderScene(*Scene.Scene,*ViewPort.Camera)
Width.w=*Scene\ScreenWidth
hieght.w=*Scene\ScreenHeight
If *Scene\SamplingAccuracy=1 ;1:1 method
Color.Color
y=0
While y<hieght
x=0
While x<Width
RayCounter+1
;Plot(x,y,#White) ;debug
*ViewPort\Direction\x = CameraVectors(x,y)\x
*ViewPort\Direction\y = CameraVectors(x,y)\y
*ViewPort\Direction\z = CameraVectors(x,y)\z
TraceRay(*ViewPort\Origin,*ViewPort\Direction,0,1.0,Color) ;refract must be set to 1 for air unless your underwater or somthing...
;(1-Pow(#E,-(Color\Red**ViewPort\Apature)))*255
;(1-Pow(#E,-(Color\Green**ViewPort\Apature)))*255
;(1-Pow(#E,-(Color\Blue**ViewPort\Apature)))*255 ;exposure
Plot(x,y,RGB(Color\Red*255,Color\Green*255,Color\Blue*255))
x+1
Wend ;next x
y+1
Wend ;next y
Else
;render the standard grid
Accuracy.f=*Scene\SamplingAccuracy
Spacing.b=*Scene\SamplingSpacing
Dim Plots.Color(Width+Spacing,hieght+Spacing)
I1.Color
I2.Color
I3.Color
I4.Color
;calulate even grid
y=0
While y<hieght
x=0
While x<Width
RayCounter+1
;Plot(x,y,#White) ;debug
*ViewPort\Direction\x = CameraVectors(x,y)\x
*ViewPort\Direction\y = CameraVectors(x,y)\y
*ViewPort\Direction\z = CameraVectors(x,y)\z
TraceRay(*ViewPort\Origin,*ViewPort\Direction,0,1.0,Plots(x,y))
x+Spacing
Wend ;next x
y+Spacing
Wend ;next y
Repeat
Threshold.f=Pow(Accuracy, Spacing)
;vert halfways
HalfSpacing.b=Spacing*0.5
y=HalfSpacing
While y<=hieght+HalfSpacing
x=HalfSpacing
While x<=Width+HalfSpacing
x1=x
y1=y-HalfSpacing
I1\Red=Plots(x1+HalfSpacing,y1)\Red
I1\Green=Plots(x1+HalfSpacing,y1)\Green
I1\Blue=Plots(x1+HalfSpacing,y1)\Blue
I2\Red=Plots(x1-HalfSpacing,y1)\Red
I2\Green=Plots(x1-HalfSpacing,y1)\Green
I2\Blue=Plots(x1-HalfSpacing,y1)\Blue
If Ratio2(I1\Red,I2\Red)>Threshold Or Ratio2(I1\Green,I2\Green)>Threshold Or Ratio2(I1\Blue,I2\Blue)>Threshold
Plots(x1,y1)\Red=(I1\Red+I2\Red)*0.5
Plots(x1,y1)\Green=(I1\Green+I2\Green)*0.5
Plots(x1,y1)\Blue=(I1\Blue+I2\Blue)*0.5
Else
Ray1Counter+1
;Plot(x1,y1,#White) ;debug
*ViewPort\Direction\x = CameraVectors(x1,y1)\x
*ViewPort\Direction\y = CameraVectors(x1,y1)\y
*ViewPort\Direction\z = CameraVectors(x1,y1)\z
TraceRay(*ViewPort\Origin,*ViewPort\Direction,0,1.0,Plots(x1,y1))
EndIf
;horz halfway
x1=x-HalfSpacing
y1=y
I1\Red=Plots(x1,y1+HalfSpacing)\Red
I1\Green=Plots(x1,y1+HalfSpacing)\Green
I1\Blue=Plots(x1,y1+HalfSpacing)\Blue
I2\Red=Plots(x1,y1-HalfSpacing)\Red
I2\Green=Plots(x1,y1-HalfSpacing)\Green
I2\Blue=Plots(x1,y1-HalfSpacing)\Blue
If Ratio2(I1\Red,I2\Red)>Threshold Or Ratio2(I1\Green,I2\Green)>Threshold Or Ratio2(I1\Blue,I2\Blue)>Threshold
Plots(x1,y1)\Red=(I1\Red+I2\Red)*0.5
Plots(x1,y1)\Green=(I1\Green+I2\Green)*0.5
Plots(x1,y1)\Blue=(I1\Blue+I2\Blue)*0.5
Else
Ray1Counter+1
;Plot(x1,y1,#White) ;debug
*ViewPort\Direction\x = CameraVectors(x1,y1)\x
*ViewPort\Direction\y = CameraVectors(x1,y1)\y
*ViewPort\Direction\z = CameraVectors(x1,y1)\z
TraceRay(*ViewPort\Origin,*ViewPort\Direction,0,1.0,Plots(x1,y1))
EndIf
;center
;from vert
I1\Red=Plots(x+HalfSpacing,y-HalfSpacing)\Red
I1\Green=Plots(x+HalfSpacing,y-HalfSpacing)\Green
I1\Blue=Plots(x+HalfSpacing,y-HalfSpacing)\Blue
I2\Red=Plots(x-HalfSpacing,y-HalfSpacing)\Red
I2\Green=Plots(x-HalfSpacing,y-HalfSpacing)\Green
I2\Blue=Plots(x-HalfSpacing,y-HalfSpacing)\Blue
;from horz
I3\Red=Plots(x-HalfSpacing,y+HalfSpacing)\Red
I3\Green=Plots(x-HalfSpacing,y+HalfSpacing)\Green
I3\Blue=Plots(x-HalfSpacing,y+HalfSpacing)\Blue
I4\Red=Plots(x-HalfSpacing,y-HalfSpacing)\Red
I4\Green=Plots(x-HalfSpacing,y-HalfSpacing)\Green
I4\Blue=Plots(x-HalfSpacing,y-HalfSpacing)\Blue
If Ratio4(I1\Red,I2\Red,I3\Red,I4\Red)>Threshold Or Ratio4(I1\Green,I2\Green,I3\Green,I4\Green)>Threshold Or Ratio4(I1\Blue,I2\Blue,I3\Blue,I4\Blue)>Threshold
Plots(x,y)\Red=(I1\Red+I2\Red+I3\Red+I4\Red)*0.25
Plots(x,y)\Green=(I1\Green+I2\Green+I3\Green+I4\Green)*0.25
Plots(x,y)\Blue=(I1\Blue+I2\Blue+I3\Blue+I4\Blue)*0.25
Else
RayCounter+1
;Plot(x,y,#White) ;debug
*ViewPort\Direction\x = CameraVectors(x,y)\x
*ViewPort\Direction\y = CameraVectors(x,y)\y
*ViewPort\Direction\z = CameraVectors(x,y)\z
TraceRay(*ViewPort\Origin,*ViewPort\Direction,0,1.0,Plots(x,y))
EndIf
x+Spacing
Wend ;next x
y+Spacing
Wend ;next y
Spacing*0.5
Until Spacing=1
For y=0 To hieght-1
For x=0 To Width-1
;(1-Pow(#E,-(Color\Red**ViewPort\Apature)))*255
;(1-Pow(#E,-(Color\Green**ViewPort\Apature)))*255
;(1-Pow(#E,-(Color\Blue**ViewPort\Apature)))*255 ;exposure
Plot(x,y,RGB(Plots(x,y)\Red*255,Plots(x,y)\Green*255,Plots(x,y)\Blue*255))
Next x
Next y
EndIf
; Debug "Leaving RenderScene()"
; etime.l=ElapsedMilliseconds()
; LastProcedureTime=etime-stime
EndProcedure