• ### Popular Now

• 12
• 12
• 9
• 10
• 13

This topic is 2531 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hello everyone,

i'm using vb.net and managed d3d to make a converter of some game 3d files to the known obj file format. i used to make maxscript but decided to change to a standalone app.

importing data from the binary files was pretty easy, i've dealt with d3d before, and so was rendering stuff on screen. but then i wanted to use environment reflections, normal and specular maps, so i turned to shaders.

standard d3d pipeline:
[attachment=1887:d3dpipeline.jpg]

i've made sure the normals are imported correctly, i've also tried different computers/drivers, all the same.

btw the models are from nfs shift 2.

has anyone seen anything like that before? any ideas/tips?

toon shading is really not what i want to do right now

##### Share on other sites
Maybe you accidentally (although unllikely) use fixed pipeline? Try

 DeviceInterface->SetRenderState(D3DRS_SHADEMODE, D3DSHADE_GOURAUD); 
and see if that solves the problem.

##### Share on other sites
I've tried turning on/off all my initialisation parameters to see what's happening but nothing changed. since we'd reach a point when i'd have to show what's done, here's my current initialisation:

 graphicsDevice.RenderState.ZBufferEnable = True graphicsDevice.RenderState.Lighting = True With graphicsDevice.SamplerState(0) .MinFilter = TextureFilter.Linear .MagFilter = TextureFilter.Linear End With With graphicsDevice.Lights(0) .Type = LightType.Directional .Diffuse = System.Drawing.Color.White .Ambient = System.Drawing.Color.Black .Specular = System.Drawing.Color.White .Position = New Vector3(5.0F, 5.0F, 1.0F) .Direction = New Vector3(-2.0F, -3.0F, -1.0F) .Enabled = True .Update() End With 

the way i pass a value to the shader is through a handle:
 carShader = Effect.FromFile(graphicsDevice, Application.StartupPath & "\diffuse.fx", Nothing, Nothing, ShaderFlags.None, Nothing) h_tech = carShader.GetTechnique("Complete") carShader.Technique = h_tech h_WorldViewProj = carShader.GetParameter(Nothing, "wvp") carShader.SetValue(h_WorldViewProj, tempmatrix) 

and render loop is something like:
 graphicsDevice.Clear(ClearFlags.Target Or ClearFlags.ZBuffer, System.Drawing.Color.Gray, 1.0F, 0) graphicsDevice.BeginScene() <here i pass matrices and light position to the shader> 'then i loop through all the primitives of all the meshes (mesh,prim) graphicsDevice.SetStreamSource(0, myscene.meshes(mesh).vb, 0) graphicsDevice.Indices = myscene.meshes(mesh).ib(prim) Dim numpasses As Integer = carShader.Begin(FX.DoNotSaveShaderState) For pass As Integer = 0 To numpasses - 1 carShader.BeginPass(pass) m.DrawSubset(0) graphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, numverts, 0, numfaces) carShader.EndPass() Next carShader.End() graphicsDevice.EndScene() graphicsDevice.Present() 

i really can't trace where the problem is...
Edit: i just tried with a teapot mesh in case it was a normals problems, but it's doing exactly the same thing.

##### Share on other sites
I usually just use one or two triangles by hand when debugging a shader. Are you sure the normals are ok? Every vertex should have actually one normal (so it tyically is not the normal of the plane that the triangle lies in). So every triangle should have three different normals.if the two triangles share an edge you would end up with 3 different normals (assuming the triangles are not in the same plane).

##### Share on other sites
You set fixed function parameters (GraphicsDevice.Lights(0)) and then use a shader. If you use a shader you have to provide all information through shader parameters (material, light, etc), just like you set the wvp parameter now.

I assume the latter is correct (tempmatrix), since the rendering at least transforms the car correctly. But for lighting you (normally) have to submit also the world (or world inverse transpose) matrix to transform the normals correctly. Currently, we only see you set one shader parameter. Anyway, we don't know for sure what your shader expects. Could you please show us the full diffuse.fx shader code please - or at least the shaders from that "Complete" technique - and all the parameters you set ? That should clarify things.

Also: When working with shaders, get back the error string. Even if it compiles, there might be relevant warnings.

As an aside, this is a bit weird:
 m.DrawSubset(0) graphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, numverts, 0, numfaces) 
As I understand you draw the same thing twice. This is superflous. Either use Mesh.DrawSubset or a (manual) DrawIndexPrimitive.

Also: If you don't already know: With PIX you can debug your rendering quite fine.