Skip to content

Commit eccac66

Browse files
committed
GITechDemo changes:
* Implemented directional lighting using Cascaded Shadow Mapping techniques and a Percentage Closer Filter with Poisson Disc sampling for softer shadow edges * Integrated Perlin Noise for animating the directional light * Added model and texture data sources to the repository LibRenderer changes: * [Common] Added utility functions for creating API-specific projection matrices * [Common] Added scissor control to RenderState class * [Common] MRTs can now be created with different formats for each render target * [Common] Render targets can now be created without specifing width and height, resulting in it using the width and height of the backbuffer (automatically resizes when backbuffer size changes) * [Common] Fixed some shader input issues * [Common] Added some more utility functions to ShaderProgram class * [Common] Texture class is now dynamic render target aware * [DX9] Added two new depth formats: INTZ and RAWZ * [DX9] Added support for dynamic render targets * [DX9] Fixed mipmap LOD bias issues * [DX9] Fixed an issue related to shader input constants' sizes TextureCompiler changes: * Fixed an issue with textures that had a lower-left origin
1 parent 1c30028 commit eccac66

File tree

210 files changed

+3509
-687
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

210 files changed

+3509
-687
lines changed

GITechDemo/Code/AppMain/GITechDemo/GITechDemo.cpp

Lines changed: 1070 additions & 189 deletions
Large diffs are not rendered by default.

GITechDemo/Code/AppMain/GITechDemo/GITechDemo.vcxproj

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,7 @@
147147
<Message>Deleting DLL dependencies</Message>
148148
</CustomBuildStep>
149149
<CustomBuildStep>
150-
<Outputs>
151-
</Outputs>
150+
<Outputs>dummy</Outputs>
152151
</CustomBuildStep>
153152
</ItemDefinitionGroup>
154153
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
@@ -174,8 +173,7 @@
174173
<Message>Deleting DLL dependencies</Message>
175174
</CustomBuildStep>
176175
<CustomBuildStep>
177-
<Outputs>
178-
</Outputs>
176+
<Outputs>dummy</Outputs>
179177
</CustomBuildStep>
180178
</ItemDefinitionGroup>
181179
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
@@ -203,8 +201,7 @@
203201
<Message>Deleting DLL dependencies</Message>
204202
</CustomBuildStep>
205203
<CustomBuildStep>
206-
<Outputs>
207-
</Outputs>
204+
<Outputs>dummy</Outputs>
208205
</CustomBuildStep>
209206
</ItemDefinitionGroup>
210207
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
@@ -232,8 +229,7 @@
232229
<Message>Deleting DLL dependencies</Message>
233230
</CustomBuildStep>
234231
<CustomBuildStep>
235-
<Outputs>
236-
</Outputs>
232+
<Outputs>dummy</Outputs>
237233
</CustomBuildStep>
238234
</ItemDefinitionGroup>
239235
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Profile|Win32'">
@@ -261,8 +257,7 @@
261257
<Message>Deleting DLL dependencies</Message>
262258
</CustomBuildStep>
263259
<CustomBuildStep>
264-
<Outputs>
265-
</Outputs>
260+
<Outputs>dummy</Outputs>
266261
</CustomBuildStep>
267262
</ItemDefinitionGroup>
268263
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Profile|x64'">
@@ -290,21 +285,22 @@
290285
<Message>Deleting DLL dependencies</Message>
291286
</CustomBuildStep>
292287
<CustomBuildStep>
293-
<Outputs>
294-
</Outputs>
288+
<Outputs>dummy</Outputs>
295289
</CustomBuildStep>
296290
</ItemDefinitionGroup>
297291
<ItemGroup>
298292
<Text Include="ReadMe.txt" />
299293
</ItemGroup>
300294
<ItemGroup>
301295
<ClInclude Include="GITechDemo.h" />
296+
<ClInclude Include="PerlinNoise.h" />
302297
<ClInclude Include="Resource.h" />
303298
<ClInclude Include="stdafx.h" />
304299
<ClInclude Include="targetver.h" />
305300
</ItemGroup>
306301
<ItemGroup>
307302
<ClCompile Include="GITechDemo.cpp" />
303+
<ClCompile Include="PerlinNoise.cpp" />
308304
<ClCompile Include="stdafx.cpp">
309305
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
310306
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Create</PrecompiledHeader>
@@ -326,6 +322,16 @@
326322
<Project>{42b90f7f-e5d8-4b7f-be74-cac4da86c76f}</Project>
327323
</ProjectReference>
328324
</ItemGroup>
325+
<ItemGroup>
326+
<None Include="..\..\..\Data\shaders\DeferredLightAmb.hlsl" />
327+
<None Include="..\..\..\Data\shaders\DeferredLightDir.hlsl" />
328+
<None Include="..\..\..\Data\shaders\DepthCopy.hlsl" />
329+
<None Include="..\..\..\Data\shaders\DepthPass.hlsl" />
330+
<None Include="..\..\..\Data\shaders\GBufferGeneration.hlsl" />
331+
<None Include="..\..\..\Data\shaders\PostProcess.hlsl" />
332+
<None Include="..\..\..\Data\shaders\Skybox.hlsl" />
333+
<None Include="..\..\..\Data\shaders\Utils.hlsl" />
334+
</ItemGroup>
329335
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
330336
<ImportGroup Label="ExtensionTargets">
331337
</ImportGroup>

GITechDemo/Code/AppMain/GITechDemo/GITechDemo.vcxproj.filters

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
1414
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
1515
</Filter>
16+
<Filter Include="Shaders">
17+
<UniqueIdentifier>{457debdf-a71c-4c9b-8631-455f8c737ef7}</UniqueIdentifier>
18+
</Filter>
1619
</ItemGroup>
1720
<ItemGroup>
1821
<Text Include="ReadMe.txt" />
@@ -30,6 +33,9 @@
3033
<ClInclude Include="GITechDemo.h">
3134
<Filter>Header Files</Filter>
3235
</ClInclude>
36+
<ClInclude Include="PerlinNoise.h">
37+
<Filter>Header Files</Filter>
38+
</ClInclude>
3339
</ItemGroup>
3440
<ItemGroup>
3541
<ClCompile Include="stdafx.cpp">
@@ -38,6 +44,9 @@
3844
<ClCompile Include="GITechDemo.cpp">
3945
<Filter>Source Files</Filter>
4046
</ClCompile>
47+
<ClCompile Include="PerlinNoise.cpp">
48+
<Filter>Source Files</Filter>
49+
</ClCompile>
4150
</ItemGroup>
4251
<ItemGroup>
4352
<ResourceCompile Include="GITechDemo.rc">
@@ -52,4 +61,30 @@
5261
<Filter>Resource Files</Filter>
5362
</Image>
5463
</ItemGroup>
64+
<ItemGroup>
65+
<None Include="..\..\..\Data\shaders\DeferredLightDir.hlsl">
66+
<Filter>Shaders</Filter>
67+
</None>
68+
<None Include="..\..\..\Data\shaders\DepthPass.hlsl">
69+
<Filter>Shaders</Filter>
70+
</None>
71+
<None Include="..\..\..\Data\shaders\GBufferGeneration.hlsl">
72+
<Filter>Shaders</Filter>
73+
</None>
74+
<None Include="..\..\..\Data\shaders\Skybox.hlsl">
75+
<Filter>Shaders</Filter>
76+
</None>
77+
<None Include="..\..\..\Data\shaders\Utils.hlsl">
78+
<Filter>Shaders</Filter>
79+
</None>
80+
<None Include="..\..\..\Data\shaders\DepthCopy.hlsl">
81+
<Filter>Shaders</Filter>
82+
</None>
83+
<None Include="..\..\..\Data\shaders\DeferredLightAmb.hlsl">
84+
<Filter>Shaders</Filter>
85+
</None>
86+
<None Include="..\..\..\Data\shaders\PostProcess.hlsl">
87+
<Filter>Shaders</Filter>
88+
</None>
89+
</ItemGroup>
5590
</Project>
Lines changed: 241 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,241 @@
1+
/* coherent noise function over 1, 2 or 3 dimensions */
2+
/* (copyright Ken Perlin) */
3+
4+
#include "stdafx.h"
5+
6+
#include <stdlib.h>
7+
#include <stdio.h>
8+
#include <math.h>
9+
10+
#include "PerlinNoise.h"
11+
12+
#define B SAMPLE_SIZE
13+
#define BM (SAMPLE_SIZE-1)
14+
15+
#define N 0x1000
16+
#define NP 12 /* 2^N */
17+
#define NM 0xfff
18+
19+
#define s_curve(t) ( t * t * (3.0f - 2.0f * t) )
20+
#define lerp(t, a, b) ( a + t * (b - a) )
21+
22+
#define setup(i,b0,b1,r0,r1)\
23+
t = vec[i] + N;\
24+
b0 = ((int)t) & BM;\
25+
b1 = (b0+1) & BM;\
26+
r0 = t - (int)t;\
27+
r1 = r0 - 1.0f;
28+
29+
float Perlin::noise1(float arg)
30+
{
31+
int bx0, bx1;
32+
float rx0, rx1, sx, t, u, v, vec[1];
33+
34+
vec[0] = arg;
35+
36+
if (mStart)
37+
{
38+
srand(mSeed);
39+
mStart = false;
40+
init();
41+
}
42+
43+
setup(0, bx0, bx1, rx0, rx1);
44+
45+
sx = s_curve(rx0);
46+
47+
u = rx0 * g1[p[bx0]];
48+
v = rx1 * g1[p[bx1]];
49+
50+
return lerp(sx, u, v);
51+
}
52+
53+
float Perlin::noise2(float vec[2])
54+
{
55+
int bx0, bx1, by0, by1, b00, b10, b01, b11;
56+
float rx0, rx1, ry0, ry1, *q, sx, sy, a, b, t, u, v;
57+
int i, j;
58+
59+
if (mStart)
60+
{
61+
srand(mSeed);
62+
mStart = false;
63+
init();
64+
}
65+
66+
setup(0, bx0, bx1, rx0, rx1);
67+
setup(1, by0, by1, ry0, ry1);
68+
69+
i = p[bx0];
70+
j = p[bx1];
71+
72+
b00 = p[i + by0];
73+
b10 = p[j + by0];
74+
b01 = p[i + by1];
75+
b11 = p[j + by1];
76+
77+
sx = s_curve(rx0);
78+
sy = s_curve(ry0);
79+
80+
#define at2(rx,ry) ( rx * q[0] + ry * q[1] )
81+
82+
q = g2[b00];
83+
u = at2(rx0, ry0);
84+
q = g2[b10];
85+
v = at2(rx1, ry0);
86+
a = lerp(sx, u, v);
87+
88+
q = g2[b01];
89+
u = at2(rx0, ry1);
90+
q = g2[b11];
91+
v = at2(rx1, ry1);
92+
b = lerp(sx, u, v);
93+
94+
return lerp(sy, a, b);
95+
}
96+
97+
float Perlin::noise3(float vec[3])
98+
{
99+
int bx0, bx1, by0, by1, bz0, bz1, b00, b10, b01, b11;
100+
float rx0, rx1, ry0, ry1, rz0, rz1, *q, sy, sz, a, b, c, d, t, u, v;
101+
int i, j;
102+
103+
if (mStart)
104+
{
105+
srand(mSeed);
106+
mStart = false;
107+
init();
108+
}
109+
110+
setup(0, bx0, bx1, rx0, rx1);
111+
setup(1, by0, by1, ry0, ry1);
112+
setup(2, bz0, bz1, rz0, rz1);
113+
114+
i = p[bx0];
115+
j = p[bx1];
116+
117+
b00 = p[i + by0];
118+
b10 = p[j + by0];
119+
b01 = p[i + by1];
120+
b11 = p[j + by1];
121+
122+
t = s_curve(rx0);
123+
sy = s_curve(ry0);
124+
sz = s_curve(rz0);
125+
126+
#define at3(rx,ry,rz) ( rx * q[0] + ry * q[1] + rz * q[2] )
127+
128+
q = g3[b00 + bz0]; u = at3(rx0, ry0, rz0);
129+
q = g3[b10 + bz0]; v = at3(rx1, ry0, rz0);
130+
a = lerp(t, u, v);
131+
132+
q = g3[b01 + bz0]; u = at3(rx0, ry1, rz0);
133+
q = g3[b11 + bz0]; v = at3(rx1, ry1, rz0);
134+
b = lerp(t, u, v);
135+
136+
c = lerp(sy, a, b);
137+
138+
q = g3[b00 + bz1]; u = at3(rx0, ry0, rz1);
139+
q = g3[b10 + bz1]; v = at3(rx1, ry0, rz1);
140+
a = lerp(t, u, v);
141+
142+
q = g3[b01 + bz1]; u = at3(rx0, ry1, rz1);
143+
q = g3[b11 + bz1]; v = at3(rx1, ry1, rz1);
144+
b = lerp(t, u, v);
145+
146+
d = lerp(sy, a, b);
147+
148+
return lerp(sz, c, d);
149+
}
150+
151+
void Perlin::normalize2(float v[2])
152+
{
153+
float s;
154+
155+
s = (float)sqrt(v[0] * v[0] + v[1] * v[1]);
156+
s = 1.0f / s;
157+
v[0] = v[0] * s;
158+
v[1] = v[1] * s;
159+
}
160+
161+
void Perlin::normalize3(float v[3])
162+
{
163+
float s;
164+
165+
s = (float)sqrt(v[0] * v[0] + v[1] * v[1] + v[2] * v[2]);
166+
s = 1.0f / s;
167+
168+
v[0] = v[0] * s;
169+
v[1] = v[1] * s;
170+
v[2] = v[2] * s;
171+
}
172+
173+
void Perlin::init(void)
174+
{
175+
int i, j, k;
176+
177+
for (i = 0; i < B; i++)
178+
{
179+
p[i] = i;
180+
g1[i] = (float)((rand() % (B + B)) - B) / B;
181+
for (j = 0; j < 2; j++)
182+
g2[i][j] = (float)((rand() % (B + B)) - B) / B;
183+
normalize2(g2[i]);
184+
for (j = 0; j < 3; j++)
185+
g3[i][j] = (float)((rand() % (B + B)) - B) / B;
186+
normalize3(g3[i]);
187+
}
188+
189+
while (--i)
190+
{
191+
k = p[i];
192+
p[i] = p[j = rand() % B];
193+
p[j] = k;
194+
}
195+
196+
for (i = 0; i < B + 2; i++)
197+
{
198+
p[B + i] = p[i];
199+
g1[B + i] = g1[i];
200+
for (j = 0; j < 2; j++)
201+
g2[B + i][j] = g2[i][j];
202+
for (j = 0; j < 3; j++)
203+
g3[B + i][j] = g3[i][j];
204+
}
205+
206+
}
207+
208+
209+
float Perlin::perlin_noise_2D(float vec[2])
210+
{
211+
int terms = mOctaves;
212+
float freq = mFrequency;
213+
float result = 0.0f;
214+
float amp = mAmplitude;
215+
216+
vec[0] *= mFrequency;
217+
vec[1] *= mFrequency;
218+
219+
for (int i = 0; i<terms; i++)
220+
{
221+
result += noise2(vec)*amp;
222+
vec[0] *= 2.0f;
223+
vec[1] *= 2.0f;
224+
amp *= 0.5f;
225+
}
226+
227+
228+
return result;
229+
}
230+
231+
232+
233+
Perlin::Perlin(int octaves, float freq, float amp, int seed)
234+
{
235+
mOctaves = octaves;
236+
mFrequency = freq;
237+
mAmplitude = amp;
238+
mSeed = seed;
239+
mStart = true;
240+
}
241+

0 commit comments

Comments
 (0)