Followers 0

## 40 posts in this topic

Damn it i lost my crystal ball.

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

0

##### Share on other sites

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?

0

##### Share on other sites

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.

0

##### Share on other sites
> 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.
0

##### Share on other sites

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?

0

##### Share on other sites

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.

I checked the code sample "Direct3D 9 Normal Mapping Demo" which is a good example, however it's using one single light in the entire scene, sometimes I will have a mesh which is getting affected by multiple lights at the same time.

Does that means that the project is useless and I must look for other technique such as "deferred rendering" and "light pre pass"? If yes, any deferred rendering shader out there?

0

##### Share on other sites

Does that means that the project is useless and I must look for other technique such as "deferred rendering" and "light pre pass"? If yes, any deferred rendering shader out there?

It's not useless. You can use normal mapping with almost any lighting technique you want. I would advise against using the deferred techniques for now. They are a lot harder to implement and bring their own problems with them (transparent objects for example). You can't just throw a "deferred rendering shader" on there and expect it to work.

Choosing a lighting technique is an important decision and will fundamentally change the way your rendering pipeline works and performs.

- Multi-pass: Render the object multiple times and apply one light source with each pass.

- "Uber-shader": Multiple lights in one pass plus anything else you might need and enable/disable the parts you need.

- Combination of the above

- Deferred: Render scene to a G-Buffer and calculate lighting independently

What does your typical scene look like? How many lights are we talking? How large are they? How many objects do they affect?

2

##### Share on other sites

First of all I want to mention that it's FPS game.

I don't know how many light I will be having in the scene, it depends on the game mission, but I expect many different lights.

For example: I could have 30-40 light in a scene as well as multiple lights affecting many meshes, rendering each mesh 30-40 times is just a total waste of performance.

0

##### Share on other sites

If you want to listen to me, you should go with forward renderer and multi-pass lights, since you are accustomed with it and it is easiest way.

If you have 30-40 lights in the scene then be smart where do you place them, have 3 or 4 as max light count affecting some object, choose by some priority for example for outdoor scene sun would always be included, player flashlight is priority, then choose rest by distance, cull occluded lights, for point lights test light bounding sphere against objects bounding volume for intersection to see if it should contribute...

0

##### Share on other sites

As other people recommended, you can check whether the object is affected by the light, here's how with a Point Light!

Bounding Spheres

Bounding Spheres is if you were to collect all the vertices in the mesh and make a sphere encapsulate them, like this:

RABBITS!

To get this result, you need two things:

1. The center of the mesh
2. The radius of the mesh from the center

Calculating the center:

• Declare the variable
• Loop over all your vertices and add them to the center
• Divide the center by the number of vertices.
• THAT'S IT!
D3DXVECTOR3 center = D3DXVECTOR3(0, 0, 0);

for(int v = 0; v < mVertices.size(); v++ )
{
center += mVertices[v];
}

center /= mVertices.size();


Calculating the radius: (With the center)

• Declare the variable
• Loop over all the vertices
• Get the distance between the vertices and the center
• Find the greatest length
float radius = 0.0f;
for (int v = 0; v < mVertices.size(); v ++)
{
D3DXVECTOR3 diff = mVertices[v] - center;

float length = sqrtf(D3DXVec3Dot(&diff, &diff));

}


To visualize the result, you just need to translate a sphere (or stuff) to this location: sphere->Translate(mesh->Position + mesh->Center), and also scale it by the meshes radius.

Testing for collision between Sphere-Sphere

As you know the point light has a radius, and so does, hopefully, the mesh with these calculations. To see if they collide, just do the following

• Find the vector between the mesh center and the point light's position.
• Get the length of that vector
• Check whether that length is smaller than both the point light's radius and the mesh's radius.
• If true, they collide!!!
D3DXVECTOR3 mDistance = mesh->center + pointLight.Position;
float d = sqrtf( D3DXVec3Dot( &mDistance, &mDistance) );

if (d < (mesh->BoundingSphere.radius + pointLight.Range) )
// They collide!!!


In other words, if they collide, the light will affect the mesh.

Mini Tutorials!

Edited by Migi0027
1

##### Share on other sites

First of all I want to mention that it's FPS game.

I don't know how many light I will be having in the scene, it depends on the game mission, but I expect many different lights.

For example: I could have 30-40 light in a scene as well as multiple lights affecting many meshes, rendering each mesh 30-40 times is just a total waste of performance.

Lights are additive, so you loop through all lights in the shader and add the outgoing irradiance values for each light. You should read up on lighting and BRDFs if you are serious about having 30-40 lights in a scene.

If you are serious about learning graphics programming, I highly recommend this book:
http://www.amazon.com/Real-Time-Rendering-Third-Edition-Akenine-Moller/dp/1568814240/ref=sr_1_1_bnp_1_har?ie=UTF8&qid=1370474265&sr=8-1&keywords=real+time+rendering

That's just one of many books you will need if you want to be a graphics programmer.

Best of luck, I hope you soon come to realize that this is the absolute wrong way to ask for help.

Edit - On another note, have you asked yourself whether you even want to be doing the graphics yourself? Consider using an engine that already has done the lighting stuff for you. Edited by metsfan
1

##### Share on other sites

@metsfan: Maybe you misunderstood me, I have already done a lot of things other than lights, so I don't really need to start graphics programming from the beginning.

The thing that I don't have experience with is shader, I thought I could use FFP light but I couldn't since I can't use it while using shaders.

I will not use another game engine since I have already programmed almost 60%-70% of the game engine, so it's not wise to just throw what I have done so far away.

BTW, when I ask for code samples, it doesn't mean that I'm lazy, it means that I want to get the idea on how it should be done.

@Migi0027: I have heard I could pass light array to the shader, why would I test for collision? why not just pass the light array and calculate the final light accordingly?

0

##### Share on other sites

@metsfan: Maybe you misunderstood me, I have already done a lot of things other than lights, so I don't really need to start graphics programming from the beginning.

The thing that I don't have experience with is shader, I thought I could use FFP light but I couldn't since I can't use it while using shaders.

I will not use another game engine since I have already programmed almost 60%-70% of the game engine, so it's not wise to just throw what I have done so far away.

BTW, when I ask for code samples, it doesn't mean that I'm lazy, it means that I want to get the idea on how it should be done.

@Migi0027: I have heard I could pass light array to the shader, why would I test for collision? why not just pass the light array and calculate the final light accordingly?

What he is saying is this:  Each point light has an area of influence.  Additionally, each light adds complexity to the final shading equation, since the shading equation must be performed for each light.  You can cull away lights which do not affect your object, thus increasing performance.  This can be done, as he showed, using Sphere-Sphere  intersection.  One sphere would be the area of influence for the light, the 2nd sphere would be a bounding sphere approximation for your 3D model.

0

##### Share on other sites

@metsfan: Any examples for passing and processing different kind of LIGHT ARRAY to pixel shader?

0

##### Share on other sites

@metsfan: Any examples for passing and processing different kind of LIGHT ARRAY to pixel shader?

You can pass your light data to HLSL using a constant buffer. Edited by metsfan
0

## Create an account

Register a new account