• Create Account

### #ActualMigi0027

Posted 22 May 2013 - 12:11 PM

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.

### #11Migi0027

Posted 22 May 2013 - 12:09 PM

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.

### #10Migi0027

Posted 22 May 2013 - 12:02 PM

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


This should get you going.

### #9Migi0027

Posted 22 May 2013 - 12:01 PM

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


This should get you going.

### #8Migi0027

Posted 22 May 2013 - 11:57 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;
};


This should get you going.

### #7Migi0027

Posted 22 May 2013 - 11:55 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;
};


This should get you going.