I can produce the problem. This is very strange. This code uses the up and down keys to move the camera forwards and backwards. There is a certain spot where the error appears and disappears almost instantly. Which GPU is this occuring on? I get an error with an ATI 3870, so it is unlikely to be a driver error if you are using NVidia cards:
#include "engine.h"
int main(int argc, char** argv)
{
Initialize();
//Create a graphics context
Graphics(800,600);
//Create a world
TWorld world=CreateWorld();
if (!world) {
MessageBoxA(0,"Error","Failed to create world.",0);
goto exitapp;
}
//Create a render buffer
TBuffer gbuffer=CreateBuffer(800,600,BUFFER_COLOR|BUFFER_DEPTH|BUFFER_NORMAL);
//Lighting buffer
TBuffer lightbuffer=CreateBuffer(800,600,BUFFER_COLOR);
//Create a camera
TEntity campiv=CreatePivot();
PositionEntity(campiv,Vec3(0,2,0));
TCamera cam=CreateCamera(campiv);
PositionEntity(cam,Vec3(0,0,-1.95));
//Load the scene
LoadMesh("scene.gmf");
//Create a light
TLight light=CreatePointLight();
PositionEntity(light,Vec3(0,1,0));
//Create the transparency world
TWorld foreground=CreateWorld();
//Create a camera for the transparency world
TCamera fgcam=CreateCamera();
CameraClearMode(fgcam,0);
//Create the transparent object
TMesh mesh=CreateSphere();
PositionEntity(mesh,Vec3(0,2,0));
//Load the transparent material
TMaterial material=LoadMaterial("glass_refraction.mat");
SetMaterialTexture(material,GetColorBuffer(lightbuffer),2);
SetMaterialTexture(material,GetDepthBuffer(gbuffer),3);
PaintEntity(mesh,material);
TShader refractionshader=GetMaterialShader(material);
SetWorld(world);
TMesh cube=CreateCube();
ScaleEntity(cube,Vec3(0.1));
PositionEntity(cube,Vec3(0,2,1));
TMaterial cubematerial=CreateMaterial();
SetMaterialColor(cubematerial,Vec4(1,0,0,1));
PaintEntity(cube,cubematerial);
float refractionstrength=0.01;
float mx=0.0,my=0.0;
TVec3 camrotation;
HideMouse();
MoveMouse(GraphicsWidth()/2,GraphicsHeight()/2);
//Main loop
while(!KeyHit(KEY_ESCAPE)) {
mx=Curve(MouseX()-GraphicsWidth()/2,mx,3);
my=Curve(MouseY()-GraphicsHeight()/2,my,3);
MoveMouse(GraphicsWidth()/2,GraphicsHeight()/2);
camrotation=EntityRotation(campiv);
camrotation.X+=my;
camrotation.Y-=mx;
RotateEntity(campiv,camrotation);
UpdateWorld();
//Render the main world
SetBuffer(gbuffer);
SetWorld(world);
RenderWorld();
//Render lighting
SetBuffer(lightbuffer);
RenderLights(gbuffer);
CopyBuffer(lightbuffer,BackBuffer(),BUFFER_DEPTH|BUFFER_COLOR);
CopyBuffer(gbuffer,BackBuffer(),BUFFER_DEPTH);
//Set the refraction strength
if (KeyDown(KEY_UP)) {MoveEntity(cam,Vec3(0,0,0.01)); }//{ refractionstrength+=0.001 ; }
if (KeyDown(KEY_DOWN)) {MoveEntity(cam,Vec3(0,0,-0.01)); }//{ refractionstrength-=0.001 ; }
refractionstrength=max(refractionstrength,0.0);
SetShaderFloat(refractionshader,"refractionstrength",refractionstrength);
//SetBuffer(gbuffer);
//ClearBuffer();
SetBuffer(BackBuffer());
//Render transparency
SetWorld(foreground);
SetEntityMatrix(fgcam,GetEntityMatrix(cam));
RenderWorld();
SetWorld(world);
Flip();
}
exitapp:
return Terminate();
}