• XNA Deferred rendering
    19 replies, posted
I'm following [url]http://www.ziggyware.com/readarticle.php?article_id=155&rowstart=0[/url] But something's breaking at some point and I'm getting [img]http://upl.luahelp.com/uploads/u7m1TqG6/depth.png[/img] [img]http://upl.luahelp.com/uploads/PU9JXlh8/diffuse.png[/img] [img]http://upl.luahelp.com/uploads/8MbALXJa/normals.png[/img] A video: [media]http://www.youtube.com/watch?v=CXyj-AIfWUQ[/media] This happens with my code and theirs. Can't seem to find a solution anywhere. It happens when I rotate the camera or zoom out. Any ideas?
That has nothing to do with deferred rendering. Your camera is fucked up - either the near/far values (the projection matrix) or the view matrix.
[QUOTE=nullsquared;16185871]That has nothing to do with deferred rendering. Your camera is fucked up - either the near/far values (the projection matrix) or the view matrix.[/QUOTE] As far as I can see there is nothing wrong with the camera. I'll ditch the camera class they provide and see if that helps.
Try to maybe output the scene in wireframe.
Matrix projection = Matrix.CreatePerspectiveFieldOfView( MathHelper.PiOver4, dev.PresentationParameters.BackBufferWidth / dev.PresentationParameters.BackBufferHeight, 1, 1000 ); Matrix view = Matrix.CreateLookAt( new Vector3( 0, 100, -dist ), Vector3.Zero, Vector3.Up ); Still happens. If I disable the depth buffer, it stops happening. But of course this breaks other things. (As you can probably tell I don't really know what I'm doing)
Nonono something is definitely wrong with the camera... Can I see your gbuffer-generation shader?
[code] float4x4 World; float4x4 View; float4x4 Projection; float specIntensity = 0.8f; float specPower = 0.5f; texture Texture; sampler diffuseSampler = sampler_state { Texture = ( Texture ); MAGFILTER = LINEAR; MAGFILTER = LINEAR; MINFILTER = LINEAR; MIPFILTER = LINEAR; AddressU = Wrap; AddressV = Wrap; }; struct vsi { float4 Position : POSITION0; float3 Normal : NORMAL0; float2 TexCoord : TEXCOORD0; }; struct vso { float4 Position : POSITION0; float2 TexCoord : TEXCOORD0; float3 Normal : TEXCOORD1; float Depth : TEXCOORD2; }; vso VertexShaderFunction( vsi input ) { vso output; float4 world = mul( input.Position, World ); float4 view = mul( world, View ); output.Position = mul( view, Projection ); output.TexCoord = input.TexCoord; output.Normal = mul( input.Normal, World ); output.Depth = output.Position.z / output.Position.w; return output; } struct pso { half4 Colour : COLOR0; half4 Normal : COLOR1; half4 Depth : COLOR2; }; pso PixelShaderFunction( vso input ) { pso output; output.Colour = tex2D( diffuseSampler, input.TexCoord ); output.Colour.a = specIntensity; output.Normal.rgb = 0.5f * ( normalize( input.Normal ) + 1.0f ); output.Normal.a = specPower; output.Depth = input.Depth;//.x / input.Depth.y; return output; } technique Technique1 { pass Pass1 { VertexShader = compile vs_2_0 VertexShaderFunction(); PixelShader = compile ps_2_0 PixelShaderFunction(); } } [/code] This is probably the part where you spot a stupid mistake. Edit: Going to sleep. If you need to see anything download [url=http://www.ziggyware.com/downloads.php?cat_id=4&download_id=97]this[/url], it's not my code but it does the same thing.
Hm, nope, I don't see anything (just for the record, premultiply projection * view * world and then send that to the shader, it'll be more efficient). Try leaving out the view matrix multiplication (or set it as an IDENTITY matrix) - then use the world matrixt to move/rotate the object. Does the problem still occur?
This has absolutely nothing to do with your problem, but I think deferred shading is a whole lot more trouble than it's worth. I choose to write a deferred renderer for my game engine (that I've given up on) and it made certain tasks very difficult (blending is one example).
[QUOTE=ROBO_DONUT;16189693]This has absolutely nothing to do with your problem, but I think deferred shading is a whole lot more trouble than it's worth. I choose to write a deferred renderer for my game engine (that I've given up on) and it made certain tasks very difficult (blending is one example).[/QUOTE] It depends on the needs of your project. It can be trouble, or it can be good.
[img]http://upl.luahelp.com/uploads/ScaQoNsy/diffuse.png[/img] Still happens.
[QUOTE=Xera;16197797][img]http://upl.luahelp.com/uploads/ScaQoNsy/diffuse.png[/img] Still happens.[/QUOTE] What if you take out the world/view multiplications and just "zoom" via lowering/highering the FOV?
[QUOTE=nullsquared;16198217]What if you take out the world/view multiplications and just "zoom" via lowering/highering the FOV?[/QUOTE] Still happens. :|
Hm, this is weird. Try another method of calculating your projection matrix (use some manual math or something, Google it).
Can you give us reference images so we know what the model is [I]supposed[/I] to look like? If I had to guess, it is doing backface culling wrong. Like you aren't transforming the normal vectors into screenspace. Or first just turn off backface culling and see if it looks right.
Nothing wrong with the world/view/proj matrix because its roughly the right shape and in my experience unless your using more than just CreatePerspectiveFieldOfView() and CreateLookAt() that means that thats all fine. It sounds like your not clearing your zbuffer in the right place/at all. I cant remember how to do that in XNA, but just try experimenting with that for a while.
[QUOTE=qPixel;16200365]Nothing wrong with the world/view/proj matrix because its roughly the right shape and in my experience unless your using more than just CreatePerspectiveFieldOfView() and CreateLookAt() that means that thats all fine. It sounds like your not clearing your zbuffer in the right place/at all. I cant remember how to do that in XNA, but just try experimenting with that for a while.[/QUOTE] GraphicsDevice.Clear( ClearOptions.DepthBuffer, Color.Black, 1, 0 ); This fixed it. ._. Thanks for the help guys.
Post a screenshot how it looks now.
[img]http://upl.luahelp.com/uploads/F1FS8E0I/diffuse.png[/img] [img]http://upl.luahelp.com/uploads/RWo56GuX/normals.png[/img] [img]http://upl.luahelp.com/uploads/8MbALXJa/depth.png[/img]
that's weird that not clearing the depth buffer was causing that. I'll keep that in mind.
Sorry, you need to Log In to post a reply to this thread.