mirror of
https://github.com/xemu-project/nxdk_pgraph_tests.git
synced 2024-11-27 03:50:22 +00:00
43 lines
1.0 KiB
Plaintext
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;
|
|
}
|