XNA中的阴影效果 [英] Shadow Effect in XNA

查看:119
本文介绍了XNA中的阴影效果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是文档带有xna 4.0的3D图形" 中的代码示例.当我在本书中构建有关阴影效应"的示例代码失败时.我已经对其进行了编辑,但效果不佳.像这样:

-图片效果阴影:效果阴影 [我的图片 [代码示例阴影 [我的代码 [ ^ ]

希望你能帮助我!

#-------------(编辑-elybob)-----------
#
#在Compare ++(文件夹diff模式)中打开了两个文件夹
#以下是相对于代码(逐个区分)的信息
#文字是从原始海报的角度而言的
#-----------------------------------------------

它说内容文件夹是相同的.
有2个不同的文件.
Game1.cs(我的):

This is code sample in document "3D graphic with xna 4.0". And When I built sample code about "Shawdow effect" in this book has failed''. I have edit it but it were not good. Like this:

-Picture effect shadow: effect shadow[^]

-Picture my code: my picture[^]

-3D graphic with xna 4.0 code: code sample shadow[^]

-My code: my code[^]

Hope you help me!!

#-------------(edit - elybob)-----------
#
# opened up the two folders in Compare++ (folder diff mode)
# Below is the information which is relivant from the code (diff-wise)
# wording is in terms of original posters perspective
#-----------------------------------------------

and it says that the content folders are the same.
there are 2 files which are not the same.
Game1.cs (mine):

new PPPointLight(new Vector3(0, 1000, -1000), Color.White * .85f, 2000000),
new PPPointLight(new Vector3(0, 1000, 1000), Color.White * .85f, 2000000),


他们的:


theirs:

new PPPointLight(new Vector3(0, 1000, -1000), Color.White * .85f, 20000),
                new PPPointLight(new Vector3(0, 1000, 1000), Color.White * .85f, 20000),


请注意,我将20000 00 设置为20000
并且我已经添加了我的Draw(mine):


note that I''m setting the 2000000 vs 20000
and I''ve added in my Draw(mine):

// For reach compatibility
GraphicsDevice.SamplerStates[0] = SamplerState.AnisotropicClamp;



在PrelightingRenderer.cs中:
(我的):



in PrelightingRenderer.cs:
(mine):

void drawDepthNormalMap()
        {
            // Set the render targets to 'slots' 1 and 2
            graphicsDevice.SetRenderTargets(normalTarg);

            // Clear the render target to 1 (infinite depth)
            graphicsDevice.Clear(Color.White);

            // Draw each model with the PPDepthNormal effect
            foreach (CModel model in Models)
            {
                model.CacheEffects();
                model.SetModelEffect(depthNormalEffect, false);
                model.Draw(Camera.View, Camera.Projection,
                    ((FreeCamera)Camera).Position);
                model.RestoreEffects();
            }
            // Set the render targets to 'slots' 1 and 2
            graphicsDevice.SetRenderTargets(depthTarg);

            // Clear the render target to 1 (infinite depth)
            graphicsDevice.Clear(Color.White);

            // Draw each model with the PPDepthNormal effect
            foreach (CModel model in Models)
            {
                model.CacheEffects();
                model.SetModelEffect(depthNormalEffect, false);
                model.Draw(Camera.View, Camera.Projection,
                    ((FreeCamera)Camera).Position);
                model.RestoreEffects();
            }
            // Un-set the render targets
            graphicsDevice.SetRenderTargets(null);
        }



他们的:



theirs:

void drawDepthNormalMap()
        {
            // Set the render targets to 'slots' 1 and 2
            graphicsDevice.SetRenderTargets(normalTarg, depthTarg);

            // Clear the render target to 1 (infinite depth)
            graphicsDevice.Clear(Color.White);

            // Draw each model with the PPDepthNormal effect
            foreach (CModel model in Models)
            {
                model.CacheEffects();
                model.SetModelEffect(depthNormalEffect, false);
                model.Draw(Camera.View, Camera.Projection, 
                    ((FreeCamera)Camera).Position);
                model.RestoreEffects();
            }

            // Un-set the render targets
            graphicsDevice.SetRenderTargets(null);
        }



还(我):



also (mine):

// Draw the point-light-sphere
                // For reach compatibility
                /////////////////////////////////////////////////////
                graphicsDevice.SamplerStates[0] = SamplerState.AnisotropicClamp;
                graphicsDevice.SamplerStates[1] = SamplerState.AnisotropicClamp;
                graphicsDevice.SamplerStates[2] = SamplerState.AnisotropicClamp;
                lightMesh.Meshes[0].Draw();


他们的:


theirs:

// Draw the point-light-sphere
                lightMesh.Meshes[0].Draw();

推荐答案

我不知道"记得确切的规格.但是,我知道阴影的API截面对于使用哪种硬件功能非常挑剔.您可以从以下资源开始:
http://xbox.create.msdn.com/zh-CN/education/catalog/sample/shadow_mapping_1 [ ^ ]

http://xboxforums.create.msdn.com/forums/p/50998/307994.aspx [ ^ ]

改善阴影深度图的常用技术 [ http://xbox.create.msdn.com/zh-CN/education/catalog/sample/avatar_shadows [ ^ ]

我建议您的图形车是否具有修改驱动程序设置的能力,以进行尝试(请务必记下启动状态,以便在不起作用时可以撤消所做的任何更改)...

我不想成为坏消息的承担者,但是如果这不能解决问题,并且代码在另一台计算机的图形卡上运行,则可能需要外出并升级图形卡. ...
I don''t remember the exact Spec., however I know that the API cross section for shadows was very picky as to which hardware capabilities it works with. you can start with these resources:
http://xbox.create.msdn.com/en-US/education/catalog/sample/shadow_mapping_1[^]

http://xboxforums.create.msdn.com/forums/p/50998/307994.aspx[^]

Common Techniques to Improve Shadow Depth Maps[^]

http://xbox.create.msdn.com/en-US/education/catalog/sample/avatar_shadows[^]

I recommend if your graphics car has the ability to modify driver settings, to try that out (be sure to write down the starting state, so you can undo any changes you make if they do not work)...

I don''t want to be the bearer of bad news, but if that doesn''t fix it, and the code runs on a different machine''s graphics card, you may need to go out and upgrade your Graphics card....


这篇关于XNA中的阴影效果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆