首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >XNA4.0奇怪的颜色错误

XNA4.0奇怪的颜色错误
EN

Stack Overflow用户
提问于 2013-03-07 10:51:34
回答 1查看 215关注 0票数 2

我在用XNA绘制地形时遇到了问题,特别是用颜色(这发生在VertexPositionColorNormal和VertexPositionTextureNormal上)。我的代码如下:

代码语言:javascript
复制
public BasicEffect GetEffectForColoredTerrain()
{
    this.coloredTerrainEffect.EnableDefaultLighting();
    this.coloredTerrainEffect.SpecularPower = 0.01f; //Power of the light
    this.coloredTerrainEffect.AmbientLightColor = new Vector3(0.1f, 0.1f, 0.1f); //Color of the light when it reflects on a surface
    this.coloredTerrainEffect.EmissiveColor = new Vector3(1, 0, 0);
    this.coloredTerrainEffect.DirectionalLight0.Enabled = true; //Enable directional light
    this.coloredTerrainEffect.DirectionalLight0.DiffuseColor = (new Vector3(0.2f, 0.2f, 0.2f)); //Diffuse color
    this.coloredTerrainEffect.DirectionalLight0.SpecularColor = (new Vector3(0.2f, 0.2f, 0.2f)); //Specular color
    this.coloredTerrainEffect.DirectionalLight0.Direction = Vector3.Normalize(new Vector3(1, -1f, 1)); //Direction where the light comes from.
    this.coloredTerrainEffect.View = Camera.GetInstance().GetViewMatrix();
    this.coloredTerrainEffect.Projection = Camera.GetInstance().GetProjectionMatrix();
    this.coloredTerrainEffect.Alpha = (float)((float)Configuration.GetInstance().TerrainOpacity / (float)100);
    this.coloredTerrainEffect.VertexColorEnabled = true;

    return this.coloredTerrainEffect;
}

这个绘制地形的代码:

代码语言:javascript
复制
RasterizerState rs = new RasterizerState();
rs.CullMode = CullMode.None;
WorldContent.CommonGraphicsDevice.RasterizerState = rs;
//Restore things that SpriteBatch can have overriden
WorldContent.CommonGraphicsDevice.BlendState = BlendState.AlphaBlend;
WorldContent.CommonGraphicsDevice.DepthStencilState = DepthStencilState.Default;
WorldContent.CommonGraphicsDevice.SamplerStates[0] = SamplerState.LinearClamp;

BasicEffect shader = ShadersHandler.GetInstance().GetEffectForColoredTerrain();
foreach (EffectPass pass in shader.CurrentTechnique.Passes)
{
    pass.Apply();
    WorldContent.CommonGraphicsDevice.Indices = indexBufferVertices;
    WorldContent.CommonGraphicsDevice.SetVertexBuffer(vertexBufferVertices);
    WorldContent.CommonGraphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, vertexPositionColorNormalList.Length, 0, indicesVertices.Length / 3);
}

但是,结果确实很奇怪,正如您可以在以下图像中看到的那样:

横向地形

地形底部

颜色是从黄色到白色的渐变(黄色向上,白色向下)。但是,如果我使用Riemers教程中的效果文件( 3D系列1中的effects.fx),那么一切都是正确的,正如您在这里看到的:

横向地形良好

地形好底

如果您愿意,您可以在这里看到效果代码:效果文件

那么,问题:有人知道BasicEffect在这里发生了什么吗?我想使用Riemers文件(它看起来一切都是正确的),但是我需要使用透明性,BasicEffect对象提供给我alpha属性,这对于我正在寻找的东西来说是完美的。

PD:同样的问题发生在纹理地形上,使用VertexPositionNormalTexture

EN

回答 1

Stack Overflow用户

发布于 2013-03-08 13:08:38

看着图像,变色似乎是一个非常好的圆圈,从一个方向的光。我将尝试删除您在DirectionalLight0示例中使用的BasicEffect属性设置,并查看它是否纠正了变色。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/15269216

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档