Jump to content

  • Log In with Google      Sign In   
  • Create Account

Migi0027

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

#5067718 Light Shader

Posted by Migi0027 on 05 June 2013 - 04:22 PM

From seeing your comments, I can easily see that you aren't happy about the performance happy.png

 

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:

530px-Tighter_bounding_sphere.pngRABBITS!biggrin.png

 

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 ohmy.png
  • 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 laugh.png
  • 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));

    if (length > radius)
        radius = length;
}

 

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! laugh.png




#5064272 DX11 - Depth Mapping - How?

Posted by Migi0027 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?




#5063904 Light Shader

Posted by Migi0027 on 22 May 2013 - 11:42 AM

Assuming that you know the basic concepts, such as: Normals and Vectorshuh.png

 

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

 

Vertex Shader:

  • 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;

 

Pixel Shader:

  • 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;
};

 

Shader If Needed, click below...

Spoiler

 

This should get you going. wink.png

 

If any further issues, please reply.




#5063234 [MaxScript] Transform > [MaxSDK] ?

Posted by Migi0027 on 20 May 2013 - 08:34 AM

I don't think that's related to this forum huh.png

 

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




#5053922 Useful links

Posted by Migi0027 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 wink.png



#5046320 I'm in the right way?

Posted by Migi0027 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




#5045729 Far Mesh Become Invisible

Posted by Migi0027 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?




#4966095 C++ Directx Ambient Light issue.

Posted by Migi0027 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