Shader / RenderMonkey Problem

Started by
15 comments, last by Paul7 19 years, 6 months ago
Have tries all sort of things to fix this but no luck.

Anyone else have any more suggestions?

Thanks.
Advertisement
Have you got the debug runtimes turned on and the warnings turned up? Try doing that and ticking 'maximum validation' as well and see if you get any debug spew.

Are you rendering anything else in your app? If you are try disabling the rendering of everything else (including things like FPS counters, menu text etc.) and seeing if that fixes the problem. If it does it's highly likely that you're relying on some render state being set to a particular value and some other bit of code is changing it. The other thing to check is that you're not leaving any other streams set - SetStreamSource() to NULL for streams you're not using.

I'd also suggest using vertex declarations rather than FVFs - FVFs are deprecated and were only kept around to ease the transition to DX9 from earlier versions of DX. Using SetVertexDeclaration() instead lets you be much more explicit about the layout of your streams and doesn't have the restrictions on ordering and the limitation to a single stream that FVFs do. I think that's probably not your problem here but I find it's much easier to tell what the data layout is supposed to be from looking at a vertex declaration than from an FVF.

Game Programming Blog: www.mattnewport.com/blog

Actually, I just looked at your FVF and I was wrong about it probably not being your problem - it almost certainly is. Those FVF flags are just ordinary bit flags so when you do
#define D3DFVF_VERTEX_POS_NORM (D3DFVF_XYZ | D3DFVF_NORMAL| D3DFVF_TEX1| D3DFVF_XYZ)

that's exactly the same as
#define D3DFVF_VERTEX_POS_NORM (D3DFVF_XYZ | D3DFVF_NORMAL| D3DFVF_TEX1)

If you want to use a tangent with an FVF you need to pass it as another set of tex coords. Again, I'd recommend you ditch FVFs and use vertex declarations where you won't have this sort of problem. Vertex declarations actually have a usage for tangents and binormals as well so you don't have to use a texture coordinate.

Game Programming Blog: www.mattnewport.com/blog

Thanks for that, so to use setvertex declaration do I do this:

//Initialisation codeD3DVERTEXELEMENT9 g_VertexDeclaration[] = {{ 0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0 },{ 0, 12, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_NORMAL, 0 },{ 0, 24, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0 },{ 0, 32, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TANGENT, 2 },D3DDECL_END()};if( FAILED(gDevice->CreateVertexDeclaration(g_VertexDeclaration, &vertex_decl)))			return FALSE;//then to render replace setFVF with:gDevice->SetVertexDeclaration(vertex_decl);


Do I still need to use the FVF with DrawIndexedPrimitive() or can the vertex declaration be used?

The way I have set it up to use the vertex declaration (as above) still results in the same problem!

Turning the debug output up gives me this:

Direct3D9: :====> ENTER: DLLMAIN(00c636a0): Process Attach: 000006a4, tid=000006a8Direct3D9: :====> EXIT: DLLMAIN(00c636a0): Process Attach: 000006a4Direct3D9: (INFO) :Direct3D9 Debug Runtime selected.Direct3D9: (INFO) :======================= Hal HWVP device selectedDirect3D9: (INFO) :HalDevice Driver Style 9Direct3D9: :BackBufferCount not specified, considered default 1 Direct3D9: :DoneExclusiveModeDirect3D9: (INFO) :Failed to create driver indexbufferD3D9 Helper: Warning: Default value for D3DRS_POINTSIZE_MAX is 2.19902e+012f, not 7.79599e-317f.  This is ok.D3D9 Helper: Error: Default value for D3DSAMP_DMAPOFFSET[0] is incorrect.  Expected 0x100, Returned 0x0D3D9 Helper: Error: Default value for D3DSAMP_DMAPOFFSET[1] is incorrect.  Expected 0x100, Returned 0x0D3D9 Helper: Error: Default value for D3DSAMP_DMAPOFFSET[2] is incorrect.  Expected 0x100, Returned 0x0D3D9 Helper: Error: Default value for D3DSAMP_DMAPOFFSET[3] is incorrect.  Expected 0x100, Returned 0x0D3D9 Helper: Error: Default value for D3DSAMP_DMAPOFFSET[4] is incorrect.  Expected 0x100, Returned 0x0D3D9 Helper: Error: Default value for D3DSAMP_DMAPOFFSET[5] is incorrect.  Expected 0x100, Returned 0x0D3D9 Helper: Error: Default value for D3DSAMP_DMAPOFFSET[6] is incorrect.  Expected 0x100, Returned 0x0D3D9 Helper: Error: Default value for D3DSAMP_DMAPOFFSET[7] is incorrect.  Expected 0x100, Returned 0x0D3D9 Helper: Error: Default value for D3DSAMP_DMAPOFFSET[8] is incorrect.  Expected 0x100, Returned 0x0D3D9 Helper: Error: Default value for D3DSAMP_DMAPOFFSET[9] is incorrect.  Expected 0x100, Returned 0x0D3D9 Helper: Error: Default value for D3DSAMP_DMAPOFFSET[10] is incorrect.  Expected 0x100, Returned 0x0D3D9 Helper: Error: Default value for D3DSAMP_DMAPOFFSET[11] is incorrect.  Expected 0x100, Returned 0x0D3D9 Helper: Error: Default value for D3DSAMP_DMAPOFFSET[12] is incorrect.  Expected 0x100, Returned 0x0D3D9 Helper: Error: Default value for D3DSAMP_DMAPOFFSET[13] is incorrect.  Expected 0x100, Returned 0x0D3D9 Helper: Error: Default value for D3DSAMP_DMAPOFFSET[14] is incorrect.  Expected 0x100, Returned 0x0D3D9 Helper: Error: Default value for D3DSAMP_DMAPOFFSET[15] is incorrect.  Expected 0x100, Returned 0x0Direct3D9: (WARN) :Ignoring redundant SetRenderState - 7'CgpProject.exe': Loaded 'C:\WINDOWS\system32\hid.dll', No symbols loaded.'CgpProject.exe': Loaded 'C:\WINDOWS\system32\setupapi.dll', No symbols loaded.'CgpProject.exe': Loaded 'C:\WINDOWS\system32\wintrust.dll', No symbols loaded.'CgpProject.exe': Loaded 'C:\WINDOWS\system32\crypt32.dll', No symbols loaded.'CgpProject.exe': Loaded 'C:\WINDOWS\system32\msasn1.dll', No symbols loaded.'CgpProject.exe': Loaded 'C:\WINDOWS\system32\imagehlp.dll', No symbols loaded.D3DX: (INFO) Using SSE2 InstructionsD3DX: Matrix should be 16-byte aligned for better performanceDirect3D9: (WARN) :Ignoring redundant SetSamplerState Sampler: 0, State: 13Direct3D9: (WARN) :Ignoring redundant SetSamplerState Sampler: 0, State: 14Direct3D9: (WARN) :Ignoring redundant SetSamplerState Sampler: 0, State: 25Direct3D9: (WARN) :Ignoring redundant SetSamplerState Sampler: 0, State: 15Direct3D9: (WARN) :Ignoring redundant SetSamplerState Sampler: 0, State: 16Direct3D9: (WARN) :Ignoring redundant SetSamplerState Sampler: 0, State: 17Direct3D9: (WARN) :Ignoring redundant SetSamplerState Sampler: 0, State: 18Direct3D9: (WARN) :Ignoring redundant SetSamplerState Sampler: 0, State: 19


with the Ignoring redundant SetSamplerState Sampler lines repeating continuously while the program is running. It does this when the program is working properly also so I dont think this is the problem. Would like to stop it doing this though!

[Edited by - Paul7 on October 19, 2004 11:10:35 AM]
You don't need FVFs anywhere if you're using vertex declarations. Make sure you're not setting an FVF when you're creating your vertex buffer - just use 0. There should be no SetFVF() calls or any other FVF references in your code once you've switched over to vertex declarations.

The code you posted looks more or less right but I'm not sure why you're putting 2 for the usage index for the tangents - shouldn't that be 0? Also, a little tip - use the ANSI C macro offsetof() from stddef.h rather than hardcoding the offset of the elements:
#include <cstddef>struct Vertex_pos_norm{    D3DXVECTOR3 position; // Vertex position    D3DXVECTOR3 normal;    D3DXVECTOR2 UV;    D3DXVECTOR3 tangent;};D3DVERTEXELEMENT9 g_VertexDeclaration[] = {    { 0, offsetof(Vertex_pos_norm, position), D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0 },    { 0, offsetof(Vertex_pos_norm, normal), D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_NORMAL, 0 },    { 0, offsetof(Vertex_pos_norm, UV), D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0 },    { 0, offsetof(Vertex_pos_norm, tangent), D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TANGENT, 0 },    D3DDECL_END()};

If changing the usage index doesn't fix things try some of the other suggestions (making sure the other streams are all cleared, checking the debug output, disabling any other rendering in the app).

Game Programming Blog: www.mattnewport.com/blog

The warnings about redundant sampler states are harmless - it just means you're setting a state to the same value it's already set to. That is an unnecessary performance cost but it doesn't do any harm. To eliminate it you need to do redundant state checking yourself - track the current render state at all times and only call SetRenderState/SetSamplerState/SetTextureStageState when you actually need to.

Game Programming Blog: www.mattnewport.com/blog

Just copied the code from somewhere else thats y the usage index was 2 for the tangent.

Changing thats fixed the problem! thanks alot mattnewport youve made my day!

This topic is closed to new replies.

Advertisement