nxdk_pgraph_tests/vs.vs.cg

43 lines
1.0 KiB
Plaintext

struct vIn {
float3 norm : NORMAL;
float2 tex : TEXCOORD;
float3 pos : POSITION;
};
struct vOut {
float4 pos : POSITION;
float4 col : COLOR;
float2 tex0 : TEXCOORD0; // Our diffuse map
};
vOut main(
vIn I,
uniform float4x4 m_model,
uniform float4x4 m_view,
uniform float4x4 m_proj,
uniform float4 camera_pos,
uniform float4 light_dir
)
{
vOut result;
// Transform position and normal
float4 pos = mul(float4(I.pos.xyz, 1.0), m_model);
float3 norm = normalize(mul(float4(I.norm.xyz, 0.0f), m_model).xyz);
// Calculate diffuse light direction and intensity
float3 light_direction = normalize(light_dir.xyz);
float light_diffuse = max(dot(norm.xyz, light_direction), 0);
// Transform pos to screen space
pos = mul(pos, m_view);
pos = mul(pos, m_proj);
pos.xyz = pos.xyz / pos.w;
result.pos = pos;
result.col = light_diffuse;
result.tex0 = I.tex;
return result;
}