This code works, and uses shaders. But it looks like almost anything else I try and run which uses plugins or shaders doesn't work.
Sync On : Sync Rate 0
Autocam Off
Set Normalization On
Set Camera Range 0.1, 10000.0
Color Backdrop 0xFF000000
Type Vec3Type
x as float
y as float
z as float
EndType
innerRadius as float
outerRadius as float
lightAngle as float
elapsed as float
duration as float
oldTimer as integer
altitude as float
maxSkyAlpha as float
null = Make Vector4(1)
innerSObjectID = 1 // Planet(space)
outerSObjectID = 2 // Atmosphere(space)
innerAObjectID = 3 // Planet(atmosphere)
outerAObjectID = 4 // Atmosphere(atmosphere)
lightObjectID = 5
innerRadius = 98.0
outerRadius = 100.0
samples = 10
maxSkyAlpha = 0.8
planetPosition as Vec3Type
planetPosition.x = 0.0
planetPosition.y = 0.0
planetPosition.z = 0.0
// Load objects
Make Object Sphere innerSObjectID, innerRadius * 2.0, 100, 100
Make Object Sphere outerSObjectID, -outerRadius * 2.0, 100, 100
Make Object Sphere innerAObjectID, innerRadius * 2.0, 100, 100
Make Object Sphere outerAObjectID, -outerRadius * 2.0, 100, 100
rotate object outerAObjectID, 90,0,0
fix object pivot outerAObjectID
rotate object outerSObjectID, 90,0,0
fix object pivot outerSObjectID
Set Object Transparency outerSObjectID, 2
Set Object Transparency outerAObjectID, 2
Make Object Cube lightObjectID, 30.0
Load Image "Diffuse.dds", 1
Texture Object innerSObjectID, 0, 1
Texture Object innerAObjectID, 0, 1
Load Image "IlluminationGround.dds", 2
Texture Object innerSObjectID, 1, 2
Texture Object innerAObjectID, 1, 2
Load Image "IlluminationSpace.dds", 3
Texture Object outerSObjectID, 0, 3
Texture Object outerAObjectID, 0, 3
Load Image "NightMap.dds", 4
Texture Object innerSObjectID, 2, 4
Texture Object innerAObjectID, 2, 4
// Load effects
Load Effect "AtmosphereSpace.fx", 1, 0
Load Effect "AtmosphereAtmo.fx" , 2, 0
Load Effect "PlanetSpace.fx" , 3, 0
Load Effect "PlanetAtmo.fx" , 4, 0
// Check for errors
for i = 2 to 0
perform checklist for effect errors i
if checklist quantity()
errorFound = 1
sync
cls
endif
for i = 1 to checklist quantity() - 1
text 5, -5 + i * 10, "Shader error: " + checklist string$( i )
next
if errorFound
sync
wait key
end
endif
next
// Set effect values
for i = 1 to 4
Set Effect Constant Float i, "innerRadius", innerRadius
Set Effect Constant Float i, "outerRadius", outerRadius
Set Effect Constant Integer i, "samples", samples
Set Effect Constant Float i, "oneDivSamples", 1.0 / (samples*1.0)
Set Effect Constant Float i, "innerDivOuter", innerRadius / outerRadius
Set Effect Constant Float i, "outDivOutSubIn", outerRadius / ( outerRadius - innerRadius )
Set Effect Constant Float i, "oneSubInnerDivOuter", 1.0 - ( innerRadius / outerRadius )
Set Effect Constant Float i, "particleDensity", 0.25
Set Effect Constant Float i, "particlePower" , 2.0
Set Vector4 1, planetPosition.x, planetPosition.y, planetPosition.z, 0.0
Set Effect Constant Vector i, "planetPosition", 1
Set Vector4 1, 0.0, -1.0, 0.0, 0.0
Set Effect Constant Vector i, "lightDirection", 1
next
Set Effect Constant Float 1, "particleDensity", 0.06
Set Effect Constant Float 2, "particleDensity", 0.06
Set Effect Constant Float 1, "depthMul", 2.0
Set Effect Constant Float 2, "depthMul", 2.0
Set Effect Constant Float 2, "maxSkyAlpha", maxSkyAlpha
Set Effect Constant Float 3, "outerDivInner", outerRadius / innerRadius
Set Effect Constant Float 4, "outerDivInner", outerRadius / innerRadius
Set Effect Constant Float 3, "normalToDepth", sin( ( 1.0 - ( innerRadius / outerRadius ) ) * 180.0 ) * ( 1.0 / ( 1.0 - ( innerRadius / outerRadius ) ) )
// Apply effect
Set Object Effect outerSObjectID, 1
Set Object Effect outerAObjectID, 2
Set Object Effect innerSObjectID, 3
Set Object Effect innerAObjectID, 4
// Default camera position
Position Camera 0.0, 0.0, - outerRadius * 2.5
Do
// Update
elapsed = oldTimer - Timer()
duration = elapsed * 0.001
oldTimer = Timer()
// Output
Text 5, 5, "FPS: " + Str$( Screen FPS() )
Center Text Screen Width() * 0.5, 5, "Press [1] to orbit camera, mouse to look, mousewheel to move"
point object outerAObjectID, Camera Position X(), Camera Position Y(), Camera Position Z()
point object outerSObjectID, Camera Position X(), Camera Position Y(), Camera Position Z()
// Basic controls
CX# = CX# + MouseMoveY()
CY# = CY# + MouseMoveX()
if CX# > 80.0 then CX# = 80.0
if CX# < -80.0 then CX# = -80.0
Rotate Camera CX# , CY# , 0.0
speed# = 0.0015 + 0.002 * ( Dist3D( planetPosition.x, planetPosition.y, planetPosition.z, Camera Position X(), Camera Position Y(), Camera Position Z() ) - innerRadius )
Move Camera MouseMoveZ() * speed#
if Keystate( 2 )
inc lightAngle, duration * 45.0
Set Vector4 1, sin( lightAngle ), 0.0, cos( lightAngle ), 0.0
Set Effect Constant Vector 1, "lightDirection", 1
Set Effect Constant Vector 2, "lightDirection", 1
Set Effect Constant Vector 3, "lightDirection", 1
Set Effect Constant Vector 4, "lightDirection", 1
endif
altitude = Dist3D( planetPosition.x, planetPosition.y, planetPosition.z, Camera Position X(), Camera Position Y(), Camera Position Z() ) - innerRadius
altitude = altitude / ( outerRadius - innerRadius )
Set Effect Constant Float 2, "invAltitude", 1.0 - altitude
// Position light source
if lightAngle
Position Object lightObjectID, sin( lightAngle ) * -500.0, 0.0, cos( lightAngle ) * -500.0
endif
// If we're inside the atmosphere
if InCameraRange( planetPosition.x, planetPosition.y, planetPosition.z, outerRadius, 0 )
Exclude Object On innerSObjectID
Exclude Object On outerSObjectID
Exclude Object Off innerAObjectID
Exclude Object Off outerAObjectID
else
Exclude Object On innerAObjectID
Exclude Object On outerAObjectID
Exclude Object Off innerSObjectID
Exclude Object Off outerSObjectID
endif
Sync
Loop
Function InCameraRange( X As Float , Y As Float , Z As Float , Distance As Float , CameraID As Integer )
If Dist3D( X , Y , Z , Camera Position X( CameraID ) , Camera Position Y( CameraID ) , Camera Position Z( CameraID ) ) <= Distance
ExitFunction 1
Endif
EndFunction 0
Function Dist3D( X1 As Float , Y1 As Float , Z1 As Float , X2 As Float , Y2 As Float , Z2 As Float )
Local X3 As Float
Local Y3 As Float
Local Z3 As Float
Local ReturnValue As Float
X3 = X1 - X2
Y3 = Y1 - Y2
Z3 = Z1 - Z2
ReturnValue = SQRT ( ( X3 * X3 ) + ( Y3 * Y3 ) + ( Z3 * Z3 ) )
Endfunction ReturnValue
I'll do some more checking and see if I can produce a list of problematic plugins, but this is the only program which uses shaders I've managed to get to run. Most programs just don't start at all, (no errors) and some crash with the program has stopped error.
I've attached the source and my compiled exe file. Have a looksy and see if the exe will run for you.
I live for video games! (And beers, and football, and cars!)
See what I live for here: [url]http:\\www.TeamDefiant.co.uk[/url]