Light Shader

Started by
39 comments, last by belfegor 10 years, 11 months ago

I think in second pass you don't need to write to zbuffer, try adding this:


...
device->SetRenderState( D3DRS_ZWRITEENABLE, FALSE ); // disable
Object.Draw();
device->SetRenderState( D3DRS_ZWRITEENABLE, TRUE ); // reenable after done with "lightning objects"

Does that solve z-fighting?

Advertisement

No, still getting Z-Fighting.

I don't see z-fighting even with ridiculous near/far values and with low quality D16 DS buffer, and even left zwriteeneble on.

There is a source in attachment with point light. Hold left mouse and move to rotate and w/s/a/d to move camera.

Hmm... I guess the Z-Fighting is actually expected, since I'm drawing two meshes on each others, the first one sometimes will appear and the second one other times will appear.

I don't know why you don't have Z-Fighting in your project, but drawing two meshes on each others will normally cause Z-Fighting.

Btw, I'm not using shaders yet, I'm just trying to blend two meshes on each others.

Here is what I'm doing:


device->SetTexture(...);
device->SetMaterial(...);

device->SetRenderState( D3DRS_ALPHABLENDENABLE, TRUE );
mesh->DrawSubset(0);

device->SetRenderState( D3DRS_SRCBLEND, D3DBLEND_ONE );
device->SetRenderState( D3DRS_DESTBLEND, D3DBLEND_ONE );
device->SetRenderState( D3DRS_ZWRITEENABLE, FALSE );

mesh->DrawSubset(0);

Up, tried different ways on my project and still getting z-fighting.

Any idea what could be causing the problem?

Damn it i lost my crystal ball. biggrin.png

Could you attach minimal project files that reproduces the problem so we can spot what is wrong.

Sorry for the delay.

Since the project is too large, I'm unable to upload any real source code.

However, I'm still doing some work, I tried to do the following on a separate mesh:


device->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE); // If FALSE, the mesh will appear normally, if TRUE I will see undesired transparent mesh
device->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_ZERO);
device->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_ONE);
// Draw
boxMesh->DrawSubset(0);

device->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);
device->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_ONE);
device->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_ONE);
// Draw again
boxMesh->DrawSubset(0);

1. I notice that the entire mesh is transparent (which is undesired), when I set D3DRS_ALPHABLENDENABLE to FALSE in the first draw, I get normal mesh, however I will need D3DRS_ALPHABLENDENABLE to be TRUE in some meshes, why the mesh is transparent in the above code? I want to enable alpha blending but not make the mesh transparent.

2. How do I give the shader multiples lights? sometimes I will have 500 different light in the scene, how do I give 500 light to the shader and specify the light type and other properties as well in each light?

You cant make new minimal project that reproduces the same problem?

How do you expect someone to help you if you are lazy?

1.

I want to enable alpha blending but not make the mesh transparent.

Why do you need alpha blending in the first pass enabled then?

2. I gave you the link with examples for multiple lights in previous page. Do you even try to read them?

You need to manage lights that are not visible or very far away and which contribution is minimal so that you can skip some work.

If you need that many lights in scene then you probably want to switch to other rendering techniques, so search forum for "deferred rendering" and "light pre pass".

But i think that that will be pretty hard-core for you right now to understand.

> Why do you need alpha blending in the first pass enabled then?
For example, If I have a glass mesh, I would need alpha blending to be enabled in the first pass.
> If you need that many lights in scene then you probably want to switch to other rendering techniques, so search forum for "deferred rendering" and "light pre pass".
But i think that that will be pretty hard-core for you right now to understand.
So, what you think I should do right now to get multiple lights working? BTW, I still have many things to do so I don't want to spend long time just for lights.

1.

You should partition your list of objects into opaque and transparent. Draw transparent after opaque.

2.

...what you think I should do right now to get multiple lights working?

Read about common lightning techniques and then decide which fits you the most.

Its all about compromise, each have its own pros and cons.

I still have many things to do so I don't want to spend long time just for lights.

If you are not ready to spend lot of time on this then you should consider using some graphic library to do job for you?

This topic is closed to new replies.

Advertisement