2012-05-16 56 views
1

我在C#中使用託管DirectX9。我做了一臺cnc機器的可視化。DirectX 9陰影不是線性的嗎?

在計算機1上它完美地工作。左側的圓形管呈明亮的灰色,陰影與深灰色呈線形。

在計算機2上,我得到了一些不同的東西(代碼相同!): 它只是白色在左邊,深灰色在右邊,但它不是線性的。它仍然是白色的約45%的管和黑暗的55%。一個陰影只在這兩個點之間可見....

任何想法???

看起來像我使用光線太亮,但代碼是完全一樣的...

/編輯 確定這裏是截圖: Left is wrong shading, right is correct 有問題的電腦是酷睿i3 +英特爾集成圖形+ Win7的64位 用正確的可視化能力的計算機是一個較老的英特爾與onboardgraphic和XP 32位

下面是對DirectX的設置:

PresentParameters aPresentParams = new PresentParameters(); 
aPresentParams.Windowed = true; 
aPresentParams.DeviceWindow = theControl; 
aPresentParams.DeviceWindowHandle = theControl.Handle; 
aPresentParams.SwapEffect = SwapEffect.Copy; 
aPresentParams.EnableAutoDepthStencil = true; 
aPresentParams.AutoDepthStencilFormat = DepthFormat.D16; 
CreateFlags aCreateFlags = CreateFlags.HardwareVertexProcessing; 
itsDevice = new Device(0, DeviceType.Hardware, theControl, aCreateFlags, aPresentParams); 
itsDevice.RenderState.AntiAliasedLineEnable = true; 
itsDevice.RenderState.CullMode = Cull.None; 
//some materials... 
itsMaterialBasic.Diffuse = Color.LightGray; 
itsMaterialBasic.Ambient = Color.FromArgb(0, 80, 80, 80); 
itsMaterialBasic.Specular = Color.Red; 
itsMaterialBasic.SpecularSharpness = 1000.0f; 
//... 
itsDevice.RenderState.Lighting = true; 
itsDevice.Lights[0].Type = LightType.Point; 
itsDevice.Lights[0].Diffuse = Color.LightGray; 
itsDevice.Lights[0].Range = 10000f; 
itsDevice.Lights[0].Falloff = 10f; 
itsDevice.Lights[0].Direction = new Vector3(-5, -28, 10); 
itsDevice.Lights[0].Position = new Vector3(1000, 2000, 3350); 
itsDevice.Lights[0].Attenuation0 = 0f; 
itsDevice.Lights[0].Update(); 
itsDevice.Lights[0].Enabled = true; 
itsDevice.RenderState.ShadeMode = ShadeMode.Phong; 
itsDevice.RenderState.SpecularEnable = true; 
itsDevice.RenderState.SpecularMaterialSource = ColorSource.Color1; 
itsDevice.RenderState.Ambient = Color.FromArgb(110, 110, 110); 
itsDevice.RenderState.AmbientMaterialSource = ColorSource.Color1; 
+0

屏幕截圖,或許是兩臺機器上的渲染和硬件規格的一個小列表將有所幫助。 – Ani

+1

您是否嘗試過在有問題的機器上初始化參考光柵器(DeviceType.Reference)?如果解決了這個問題 - 我會直接責怪那臺機器上的驅動程序/ GPU組合。 – Ani

+0

如果你使用自己的着色器:也許你忘了用着色器代碼複製一些文件? – miloszmaki

回答

0

我有消息! computer1..n: 英特爾酷睿i7集成圖形或新圖形卡: 軟件和hardwarevertexprocessing:錯誤

computer0: 32位WinXP的舊顯卡: Hardwarevertexprocessing:正確 Softwarevertexprocessing:錯誤

我試圖使用着色器。但我也看錯了可視化。 我通過三角形內的2個向量的交叉乘積生成三角形的三個頂點的法線(並對它們進行歸一化)。但是,當我使用這個normal.XYZ值爲pixelshader返回值(rgb)時,它應該看起來像一個法線貼圖。但有些部分只是一種顏色...

而真的很瘋狂的事情:它與來自互聯網的一個簡單的教程示例相同!我的代碼有什麼問題??????