Click here to Skip to main content
15,884,177 members
Please Sign up or sign in to vote.
4.50/5 (2 votes)
See more:
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):
C#
new PPPointLight(new Vector3(0, 1000, -1000), Color.White * .85f, 2000000),
new PPPointLight(new Vector3(0, 1000, 1000), Color.White * .85f, 2000000),

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

note that I'm setting the 2000000 vs 20000
and I've added in my Draw(mine):
C#
// For reach compatibility
GraphicsDevice.SamplerStates[0] = SamplerState.AnisotropicClamp;


in PrelightingRenderer.cs:
(mine):
C#
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:
C#
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):
C#
// 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:
C#
// Draw the point-light-sphere
                lightMesh.Meshes[0].Draw();
Posted
Updated 19-Oct-12 5:45am
v5
Comments
ely_bob 19-Oct-12 11:45am    
It's not very clear what those additions were meant to accomplish, could you talk about what your attempting to do?
haitrieu749 21-Oct-12 23:30pm    
Oh, thanks ely_bob!! My prolem is Graphic card and function
graphicsDevice.SetRenderTargets(normalTarg, depthTarg) in drawDepthNormalMap()
My GPU is: Intel Express Chipset Family and when I set Properties(My Project)->XNA Game Studio-> Game Profile-> Use Reach to access a limited API set supported by windows phone,Xbox 360 and Windows. I have one bug in graphicsDevice.SetRenderTargets(normalTarg, depthTarg)
(My computer is not run in "Use Hidef to access the complete API".)

My friend GPU is: Intel HD Graphics. and set Properties(My Project)->XNA Game Studio-> Game Profile->Use Hidef to access the complete API. It's run very good.
Can you give me a solution for old card graphic!
P/s: sorry about my english
haitrieu749 21-Oct-12 23:35pm    
Hope you answer soon!!
haitrieu749 2-Jan-13 16:42pm    
can you help me this question
http://www.codeproject.com/Questions/519263/Howplustoplussaveplusandplusloadplusgameplusinplus
Thanks!!

1 solution

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....
 
Share this answer
 
Comments
haitrieu749 25-Oct-12 1:18am    
Thanks very much for your solution!
haitrieu749 26-Oct-12 15:01pm    
Hi ely_bob. Can you help me create elastic springs!! I can't create it by rotation, scale and translation model. Do you have any solution for it!? Thanks
ely_bob 27-Oct-12 21:02pm    
post another question.. (and link to it here or put URL.. whatever..)
haitrieu749 28-Oct-12 8:30am    
Oh, I have solved it.I used method Matrix.Scale (float x, float y, float z). And I set variable x or y or z to change, it will be scaled in one direction.But I encountered a problem that I can not design elastic spring model (.FBX).You can design elastic spring model for me.Thanks! Do you know blender or 3D maxs??
haitrieu749 28-Oct-12 8:34am    
And how old are you? What is your profession??

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900