我的目標是讓透視圖中的照明平滑。我對透視和正射影像都使用相同的光線設置。下面的圖片顯示字形照明看起來很棒。 當我旋轉它時,透視照明看起來很毛糙並閃爍。我錯過了什麼,會使透視圖照明看起來好嗎?OpenTK C#透視圖照明看起來有點毛骨悚然
處理器:AMD FX 6100的6核3.31GHz
顯卡:AMD的Radeon HD 6800
注:我從一個OpenGL例子引用。我在玩弄不同的燈光設置,以瞭解它們的工作原理。我在本文末尾粘貼的代碼是創建圖像的代碼。
視角:http://i.stack.imgur.com/pSXul.png
正字:http://i.stack.imgur.com/Q7Yr2.png
這裏是我的繪製方法中的相關代碼。
private void glControl1_Paint(object sender, PaintEventArgs e)
{
if (!glLoaded)
return;
GL.Enable(EnableCap.DepthTest);
//GL.Enable(EnableCap.Blend);
GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
//SET PERSPECTIVE OR ORTHOGRAPHIC VIEW
if (chkPerspective.Checked)
{
double aspect = glControl1.Width/(double)glControl1.Height;
Matrix4 perspective = Matrix4.CreatePerspectiveFieldOfView(MathHelper.PiOver4, (float)aspect, 0.0001f, 5000.0f);
GL.MatrixMode(MatrixMode.Projection);
GL.LoadIdentity();
GL.LoadMatrix(ref perspective);
Matrix4 lookat = Matrix4.LookAt(eyeOffset.X, eyeOffset.Y, eyeOffset.Z, 0, 0, 0, 0, 1, 0);
GL.MatrixMode(MatrixMode.Modelview);
GL.LoadMatrix(ref lookat);
//GL.Translate(-boxOffset);
}
else
{
setupViewPort(); //Orthographic settings
GL.MatrixMode(MatrixMode.Modelview);
GL.LoadIdentity();
}
GL.Rotate(angleY, 1.0f, 0, 0);
GL.Rotate(angleX, 0, 1.0f, 0);
//LIGHTING
if (chkLighting.Checked)
{
float[] mat_specular = { 1.0f, 1.0f, 1.0f, 1.0f };
float[] mat_shininess = { 50.0f };
float[] light_position = { 1000.0f, 1000.0f, 1000.0f, 100.0f };
float[] light_ambient = { 0.5f, 0.5f, 0.5f, 1.0f };
GL.ClearColor(0.0f, 0.0f, 0.0f, 1.0f);
//GL.ShadeModel(ShadingModel.Smooth);
//GL.Material(MaterialFace.Front, MaterialParameter.Specular, mat_specular);
//GL.Material(MaterialFace.Front, MaterialParameter.Shininess, mat_shininess);
GL.Light(LightName.Light0, LightParameter.Position, light_position);
//GL.Light(LightName.Light0, LightParameter.Ambient, light_ambient);
//GL.Light(LightName.Light0, LightParameter.Diffuse, mat_specular);
GL.Enable(EnableCap.Lighting);
GL.Enable(EnableCap.Light0);
GL.Enable(EnableCap.ColorMaterial);
//GL.Enable(EnableCap.CullFace);
}
else
{
GL.Disable(EnableCap.Lighting);
GL.Disable(EnableCap.Light0);
}
foreach (Cube cube in cubes)
{
cube.drawCube(selectionCubeRadius);
}
glControl1.SwapBuffers();
}
這裏是它很重要的情況下我的正交視口中的代碼。
private void setupViewPort()
{
if (chkPerspective.Checked)
return;
int w = glControl1.Width;
int h = glControl1.Height;
GL.MatrixMode(MatrixMode.Projection);
GL.LoadIdentity();
GL.Ortho(-w, w, -h, h, -5000, 5000); // Bottom-left corner pixel has coordinate (0, 0)
GL.Viewport(0, 0, w, h); // Use all of the glControl paintingarea
}
好問題似乎有幫助專家解決它所需的所有相關信息。我絕對不是那個專家;我向你保證,你比我更瞭解這些東西。當我看到一個人時,我只知道一個好Q ... –
您確定要將100.0f作爲light_position.w而不是1.0f? –
將W更改爲1.0使得從塊的一側到另一側的光強度變化不太明顯。不過,透視圖中的閃爍仍然存在。 – user1334960