1 | //--------------------------------------------------------------------------------------
|
---|
2 | // Input and Output structs
|
---|
3 | //--------------------------------------------------------------------------------------
|
---|
4 |
|
---|
5 |
|
---|
6 |
|
---|
7 | struct VertexInput
|
---|
8 | {
|
---|
9 | float4 position: POSITION;
|
---|
10 | float3 normal: NORMAL;
|
---|
11 | float3 color: COLOR;
|
---|
12 | float2 texcoord: TEXCOORD0;
|
---|
13 | };
|
---|
14 |
|
---|
15 |
|
---|
16 | // vtx output
|
---|
17 | struct vtxout
|
---|
18 | {
|
---|
19 | float4 position: POSITION; // eye space
|
---|
20 | float4 texCoord: TEXCOORD0;
|
---|
21 |
|
---|
22 | float4 color: COLOR0;
|
---|
23 | float4 worldPos: TEXCOORD1; // world position
|
---|
24 | float3 normal: TEXCOORD2;
|
---|
25 | float4 mypos: TEXCOORD3;
|
---|
26 | float4 color2: TEXCOORD4;
|
---|
27 | };
|
---|
28 |
|
---|
29 |
|
---|
30 | struct pixel
|
---|
31 | {
|
---|
32 | float4 col: COLOR0;
|
---|
33 | float4 norm: COLOR1;
|
---|
34 | float3 pos: COLOR2;
|
---|
35 | };
|
---|
36 |
|
---|
37 |
|
---|
38 | // fragment input
|
---|
39 | struct fragin
|
---|
40 | {
|
---|
41 | float4 color: COLOR0;
|
---|
42 | float4 position: POSITION; // eye space
|
---|
43 | float4 texCoord: TEXCOORD0;
|
---|
44 |
|
---|
45 | float4 projPos: WPOS;
|
---|
46 | float4 worldPos: TEXCOORD1; // world position
|
---|
47 | float3 normal: TEXCOORD2;
|
---|
48 | float4 mypos: TEXCOORD3;
|
---|
49 | float4 color2: TEXCOORD4;
|
---|
50 | };
|
---|
51 | //--------------------------------------------------------------------------------------
|
---|
52 | // Vertex Shaders
|
---|
53 | //--------------------------------------------------------------------------------------
|
---|
54 |
|
---|
55 |
|
---|
56 | vtxout default_vs(VertexInput IN,
|
---|
57 | uniform float3 lightDir,
|
---|
58 | uniform float2 thetaSun,
|
---|
59 | uniform float3 zenithColor,
|
---|
60 | uniform float3 aColor,
|
---|
61 | uniform float3 bColor,
|
---|
62 | uniform float3 cColor,
|
---|
63 | uniform float3 dColor,
|
---|
64 | uniform float3 eColor,
|
---|
65 | uniform float4x4 ModelView,
|
---|
66 | uniform float multiplier)
|
---|
67 | {
|
---|
68 | vtxout OUT;
|
---|
69 |
|
---|
70 | OUT.position = mul(glstate.matrix.mvp, IN.position);
|
---|
71 |
|
---|
72 |
|
---|
73 | const float dotLN = dot(lightDir, IN.normal);
|
---|
74 | const float cos2gamma = dotLN * dotLN;
|
---|
75 |
|
---|
76 | const float gamma = acos(dotLN);
|
---|
77 | const float theta = dot(float3(0.0, 0.0, 1.0), IN.normal);
|
---|
78 |
|
---|
79 | float3 num = (1.0 + aColor * exp(bColor / theta)) * (1.0 + cColor * exp(dColor * gamma) + eColor * cos2gamma);
|
---|
80 | float3 den = (1.0 + aColor * exp(bColor)) * (1.0 + cColor * exp(dColor * thetaSun.x) + eColor * thetaSun.y);
|
---|
81 | float3 xyY = (num / den) * zenithColor;
|
---|
82 |
|
---|
83 | float3 XYZ;
|
---|
84 |
|
---|
85 | XYZ.x = (xyY.x / xyY.y) * xyY.z;
|
---|
86 | XYZ.y = xyY.z;
|
---|
87 | XYZ.z = ((1.0f - xyY.x - xyY.y) / xyY.y) * xyY.z;
|
---|
88 |
|
---|
89 | const static float3x3 conv_Mat =
|
---|
90 | float3x3(3.240479, -1.537150, -0.498535,
|
---|
91 | -0.969256, 1.875992, 0.041556,
|
---|
92 | 0.055648, -0.204043, 1.057311);
|
---|
93 |
|
---|
94 | float3 hcol = mul(conv_Mat, XYZ);
|
---|
95 | OUT.color = float4(hcol, 1.0);
|
---|
96 |
|
---|
97 | OUT.color.rgb *= multiplier;
|
---|
98 |
|
---|
99 | OUT.color2 = OUT.color;
|
---|
100 | OUT.worldPos = mul(ModelView, IN.position);
|
---|
101 |
|
---|
102 | OUT.normal = IN.normal;
|
---|
103 | OUT.mypos = OUT.position;
|
---|
104 |
|
---|
105 | return OUT;
|
---|
106 | }
|
---|
107 |
|
---|
108 |
|
---|
109 | pixel frag_skydome(fragin IN)
|
---|
110 | {
|
---|
111 | pixel pix;
|
---|
112 |
|
---|
113 | pix.col = IN.color2;
|
---|
114 | pix.col.w = 1e20f;
|
---|
115 |
|
---|
116 | pix.norm.xyz = IN.normal;
|
---|
117 | pix.norm.w = IN.mypos.w;
|
---|
118 |
|
---|
119 | //pix.pos = 1e20f;
|
---|
120 |
|
---|
121 | return pix;
|
---|
122 | } |
---|