OSDN Git Service

ライティングを実装
[shooting3/dxgi_test.git] / dxgi_test / dxgi_test.fx
1 //--------------------------------------------------------------------------------------
2 // File: Tutorial07.fx
3 //
4 // Copyright (c) Microsoft Corporation. All rights reserved.
5 //--------------------------------------------------------------------------------------
6
7 //--------------------------------------------------------------------------------------
8 // \92è\90\94\83o\83b\83t\83@
9 //--------------------------------------------------------------------------------------
10 Texture2D txDiffuse : register( t0 );
11 SamplerState samLinear : register( s0 );
12
13 cbuffer cbNeverChanges : register( b0 )
14 {
15     matrix View;
16         float4 vLightDir;
17         float4 vLightColor;
18 };
19
20 cbuffer cbChangeOnResize : register( b1 )
21 {
22     matrix Projection;
23 };
24
25 cbuffer cbChangesEveryFrame : register( b2 )
26 {
27     matrix World;
28  //   float4 vMeshColor;
29 };
30
31
32 //--------------------------------------------------------------------------------------
33 // \92¸\93_\8fî\95ñ
34 struct VS_INPUT
35 {
36     float4 Pos : POSITION;
37     float3 Norm : NORMAL;
38     float2 Tex : TEXCOORD0;
39 };
40
41 // \83s\83N\83Z\83\8b\8fî\95ñ
42 struct PS_INPUT
43 {
44     float4 Pos : SV_POSITION;
45     float4 Color : COLOR0;
46     float2 Tex : TEXCOORD0;
47 };
48
49
50 //--------------------------------------------------------------------------------------
51 // \92¸\93_\83V\83F\81[\83_\81[
52 //--------------------------------------------------------------------------------------
53 PS_INPUT VS( VS_INPUT input )
54 {
55     // \8fo\97Í\97p\95Ï\90\94\82Ì\8f\89\8aú\89»
56         PS_INPUT output = (PS_INPUT)0;
57
58         // \83\8d\81[\83J\83\8b\8dÀ\95W\82©\82ç\83\8f\81[\83\8b\83h\8dÀ\95W\82Ö\82Ì\95Ï\8a·
59     output.Pos = mul( input.Pos, World ); 
60         // \83J\83\81\83\89
61     output.Pos = mul( output.Pos, View );
62         // \8eË\89e\95Ï\8a·
63     output.Pos = mul( output.Pos, Projection );
64         // \83e\83N\83X\83`\83\83\83}\83b\83s\83\93\83O\82Ì\8dÀ\95W\95Ï\8a·\81i\8d¡\89ñ\82Í\95Ï\8a·\82Í\82µ\82È\82¢\81j
65     output.Tex = input.Tex;
66
67         // \96@\90ü\83x\83N\83g\83\8b\82Ì\8cv\8eZ
68     output.Color = mul( input.Norm, World );
69
70         //\93à\90Ï\82Ì\8cv\8eZ
71         output.Color = dot( (float3)vLightDir,(float3)output.Color) * vLightColor;
72         output.Color.a = 1;
73
74     // \8fo\97Í\82ð\95Ô\82·\81B
75         return output;
76
77 }
78
79
80 //--------------------------------------------------------------------------------------
81 // Pixel Shader
82 //--------------------------------------------------------------------------------------
83 float4 PS( PS_INPUT input) : SV_Target
84 {
85     float4 finalColor = 0;
86     finalColor = saturate(input.Color) * txDiffuse.Sample( samLinear, input.Tex );
87     return finalColor;
88 }