• Create Account

# Migi0027

Member Since 02 Jul 2012
Offline Last Active Jun 14 2013 12:21 PM

Posted by on 05 June 2013 - 04:22 PM

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
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!

### #5064272DX11 - Depth Mapping - How?

Posted by on 23 May 2013 - 03:30 PM

Objective: To visualize depth in a texture

___

So instead I should do the following:

depthValue = input.depthPosition.z / (input.depthPosition.w / 1000.0f);

or

depthValue = (input.depthPosition.w / 1000.0f);

Is this correct?

Posted by on 22 May 2013 - 11:42 AM

Assuming that you know the basic concepts, such as: Normals and Vectors

One simple type of lighting you could try to implement is directional lighting, such as the sun (Assuming that the rays are directional):

• Multiply the mesh's normal by its rotation mesh to get the world normal (Position and Scaling does not change the normal, at least not in the simple cases).
• In the 2nd line we calculate how visible this normal is in comparison to the light direction/vector, by using the dot function with the light vector and the world normal. The saturate function makes sure that the value is in between 0 and 1.
• Now send the color to the pixel shader, the variable "color" is defined in the input layout for the pixel shader, which is returned by the vertex shader, and that has to be done by you.

Code (VS):

float4 n = normalize(mul(rotationMatrix, normal));
float diffusebrightness = saturate(dot(n, lDir));
output.color = lColor * diffusebrightness;

• Well if you don't have anything other to do, just return the color, as directional lighting only affects faces.

Code (PS):

return input.color;

Input Layout:

An example of an input layout:

struct VOut
{
float4 position : SV_POSITION;
float4 color : COLOR;
};

Spoiler

This should get you going.

### #5063234[MaxScript] Transform > [MaxSDK] ?

Posted by on 20 May 2013 - 08:34 AM

I don't think that's related to this forum

You probably won't get a good answer here, try another forum involving this area.

Posted by on 16 April 2013 - 11:56 AM

Hello! I have some links that could be very good for a lot of people, here they are:

http://www.applicachia.com/index.php - Navigate throught the sections on the left of the page
http://directxtutorial.com/LessonList.aspx?listid=11 - Starting  Tutorials - Some premium
http://www.gamerendering.com/ - Samples and some Links to free books!

I hope you will add them as they could be very useful

### #5046320I'm in the right way?

Posted by on 24 March 2013 - 03:12 PM

This tutorial covers some of the basics:

http://directxtutorial.com/Lesson.aspx?lessonid=11-4-1

And then how to use some of them:

http://directxtutorial.com/Lesson.aspx?lessonid=11-4-2

### #5045729Far Mesh Become Invisible

Posted by on 22 March 2013 - 03:18 PM

I tried setting farView to 100000000.0f (same when rendering the sky mesh) and the problem persist, the weird thing is that the sky is visible (even it's more far than other meshes).

In my sky (skymap) system, if this is your case, I actually render a quad and then use the model view projection, and kind of trick the player to think it's far away, though it's not. This could be your case. And as zacaj recommended, if you really wan't such a far range, then 'use a smaller unit for your world', like:

Before:

CamSpeed = 3;

Tree.Scale = 3,3,3

After:

CamSpeed = 1

Tree.Scale = 1,1,1

And if you do all this for all things (with more properties), it will look exactly the same!

But just ask yourself this: Do I really need such a large FarView?

### #4966095C++ Directx Ambient Light issue.

Posted by on 04 August 2012 - 07:33 AM

Ohh snap, I've fixed it.

I forgot to send the rotation matrix. I feel very dumb xD

Well well, thank you for trying to help me!

PARTNERS