Hi ,
In my scene , I need a mesh which has many objects itself.
Unfortunately I can see thru objects , so I can see even objects behind other objects
which is something I dont want :
-DX SDK s mesh viewer is able to render it properly so I dont see thru objects in the mesh
- There is no textures applied , so I am sure it has nothing to do with texture stages
-For my rendering parameters :
backface culling has turned off ( for debugging )
z buffering has been turned on
So what do you suggest me to check ?
Seeing throught objects
Sounds like you have alpha blending enabled.
Have you checked your Pixel Shader Code if the Alpha-Value gets calculated correctly?
Things you could try:
- just before the return command in your pixel shader, set your Out-Color Alpha value to 1.0f
- Turn the Alpha Blend state off for that Pixel shader
Have you checked your Pixel Shader Code if the Alpha-Value gets calculated correctly?
Things you could try:
- just before the return command in your pixel shader, set your Out-Color Alpha value to 1.0f
- Turn the Alpha Blend state off for that Pixel shader
Sorry , i forgot to mention it ,
no i turned alphablending off before rendering and it is not being turned on anywhere:
myDevice->SetRenderState( D3DRS_ALPHABLENDENABLE, FALSE );
Just in case all `alpha` values in my lights and materials are zero even i turned alpha blending off...
And also I dont have any shaders at the moment
no i turned alphablending off before rendering and it is not being turned on anywhere:
myDevice->SetRenderState( D3DRS_ALPHABLENDENABLE, FALSE );
Just in case all `alpha` values in my lights and materials are zero even i turned alpha blending off...
And also I dont have any shaders at the moment
For both cases (1 and 0) it does not change anything
( I have just 1 directional lgiht and 1 material )
( I have just 1 directional lgiht and 1 material )
Wait a minute... By "Seeing Through an Object", what exactly do you mean?
Is the object infront blended with the object in the Back? Like looking through a colored Glas window?
Or is it drawing the object in the back on top of the object infront?
Is the object infront blended with the object in the Back? Like looking through a colored Glas window?
Or is it drawing the object in the back on top of the object infront?
The first one :
"the object infront blended with the object in the Back"
For example there is a house in my scene , its door is open , DX SDK mesh viewer
just shows the interior of the house , whereas my code shows interior blendded with things in the back of that house.
Alphablending is turned off , Zbuffering is used properly, there is no textures so nothing todo with texture stages or texture blending
"the object infront blended with the object in the Back"
For example there is a house in my scene , its door is open , DX SDK mesh viewer
just shows the interior of the house , whereas my code shows interior blendded with things in the back of that house.
Alphablending is turned off , Zbuffering is used properly, there is no textures so nothing todo with texture stages or texture blending
Post your code for setting the device state ( SetRenderState(...), etc. ) and the code for rendering the mesh. Please use [code][/code] or [source][/source] tags.
the repro code is as below.
The problem is as I said , i can backs of objects...
As I play with lighting it does not change it.( if i just set ambient light something like 255-255-255-1 this time I dont see back of objects but I cant see details in the objects since intensity of light is too much )
But please note that if I fill vertex buffers customly with the vertex type
with appropriate surface normals, then i have no problem...
I have found some 3dsmax models , converted them to X by using Panda and the problem occurs for them...
Also would there be any workaround by texturing and setting texture stages properly ?
1.
2. Load a mesh , setup view and projection matrix
3. Lighting :
4. Render
The problem is as I said , i can backs of objects...
As I play with lighting it does not change it.( if i just set ambient light something like 255-255-255-1 this time I dont see back of objects but I cant see details in the objects since intensity of light is too much )
But please note that if I fill vertex buffers customly with the vertex type
with appropriate surface normals, then i have no problem...
I have found some 3dsmax models , converted them to X by using Panda and the problem occurs for them...
Also would there be any workaround by texturing and setting texture stages properly ?
1.
HRESULT SetupD3D(HWND hWnd){ // Create the D3D object. if (NULL == (g_pD3D = Direct3DCreate9(D3D_SDK_VERSION))) return E_FAIL; // Set up the structure used to create the D3DDevice D3DPRESENT_PARAMETERS d3dpp; ZeroMemory(&d3dpp, sizeof(d3dpp)); d3dpp.Windowed = TRUE; d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; d3dpp.BackBufferFormat = D3DFMT_UNKNOWN; d3dpp.EnableAutoDepthStencil = TRUE; d3dpp.AutoDepthStencilFormat = D3DFMT_D16; // Create the D3DDevice if (FAILED(g_pD3D -> CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &g_pd3dDevice))) { return E_FAIL; } // Enable the Z buffer, since we're dealing with 3D geometry. g_pd3dDevice -> SetRenderState(D3DRS_ZENABLE, D3DZB_TRUE); return S_OK;}
2. Load a mesh , setup view and projection matrix
3. Lighting :
VOID SetupLights(){ // Define a light - possesses only a diffuse colour. D3DLIGHT9 Light1; ZeroMemory(&Light1, sizeof(D3DLIGHT9)); Light1.Type = D3DLIGHT_POINT; Light1.Diffuse.r = 1.0f; Light1.Diffuse.g = 1.0f; Light1.Diffuse.b = 1.0f; Light1.Position.x = 25.0f; Light1.Position.y = 30.0f; Light1.Position.z = -50.0f; Light1.Attenuation0 = 1.0f; Light1.Attenuation1 = 0.0f; Light1.Attenuation2 = 0.0f; Light1.Range = 500.0f; // Select and enable the light. g_pd3dDevice -> SetLight(0, &Light1); g_pd3dDevice -> LightEnable(0, TRUE); g_pd3dDevice ->SetRenderState(D3DRS_LIGHTING,TRUE); }
4. Render
void Render(){ g_pd3dDevice -> Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0); // Begin the scene if (SUCCEEDED(g_pd3dDevice -> BeginScene())) { g_pd3dDevice->SetRenderState(D3DRS_ALPHABLENDENABLE,FALSE); for (DWORD i = 0; i < dwNumMaterials; i++) { g_pd3dDevice -> SetMaterial(&(MeshMaterials)); g_pd3dDevice -> SetTexture(i, MeshTextures); Mesh -> DrawSubset(i); } g_pd3dDevice -> EndScene(); } g_pd3dDevice -> Present(NULL, NULL, NULL, NULL);}
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement