Программирование графических процессоров с использованием Direct3D и HLSL


float4x4 WorldViewProj; float4x4 World; float4


float4x4 WorldViewProj; float4x4 World; float4 Light;
texture Tex0 < string name = "texture.bmp"; >;
struct VS_INPUT { float4 position : POSITION; float3 normal : NORMAL; float2 texcoord : TEXCOORD0; };
struct VS_OUTPUT { float4 position : POSITION; float4 color : COLOR0; float2 texcoord : TEXCOORD0; };
VS_OUTPUT main_vs( VS_INPUT In ) { VS_OUTPUT Out; Out.position = mul( In.position, WorldViewProj ); float3 pos = mul( In.position, World ); float3 light = normalize(vecLight-pos); float3 normal = normalize(mul( In.normal, World )); float4 green = {0.0f, 1.0f, 0.0f, 1.0f}; Out.texcoord = In.texcoord; Out.color = green*dot(light, normal); return Out; }
sampler Sampler = sampler_state { Texture = (Tex0); MipFilter = LINEAR; MinFilter = LINEAR; MagFilter = LINEAR; };
struct PS_INPUT { float2 texcoord : TEXCOORD0; float4 color : COLOR0; };
float4 main_ps( PS_INPUT In ) : COLOR0 { return tex2D(Sampler, In.texcoord ) * In.color; }
technique tec0 { pass p0 { VertexShader = compile vs_1_1 main_vs(); PixelShader = compile ps_1_1 main_ps(); } }
Пример 6.2.
Закрыть окно




float4x4 WorldViewProj;


float4x4 World;
float4 Light;
texture Tex0 < string name = "texture.bmp"; >;
struct VS_INPUT
{
float4 position : POSITION;
float3 normal : NORMAL;
float2 texcoord : TEXCOORD0;
};
struct VS_OUTPUT
{
float4 position : POSITION;
float4 color : COLOR0;
float2 texcoord : TEXCOORD0;
};
VS_OUTPUT main_vs( VS_INPUT In )
{
VS_OUTPUT Out;
Out.position = mul( In.position, WorldViewProj );
float3 pos = mul( In.position, World );
float3 light = normalize(vecLight-pos);
float3 normal = normalize(mul( In.normal, World ));
float4 green = {0.0f, 1.0f, 0.0f, 1.0f};
Out.texcoord = In.texcoord;
Out.color = green*dot(light, normal);
return Out;
}
sampler Sampler = sampler_state
{
Texture = (Tex0);
MipFilter = LINEAR;
MinFilter = LINEAR;
MagFilter = LINEAR;
};
struct PS_INPUT
{
float2 texcoord : TEXCOORD0;
float4 color : COLOR0;
};
float4 main_ps( PS_INPUT In ) : COLOR0
{
return tex2D(Sampler, In.texcoord ) * In.color;
}
technique tec0
{
pass p0
{
VertexShader = compile vs_1_1 main_vs();
PixelShader = compile ps_1_1 main_ps();
}
}

Содержание раздела