Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
GameDevWeek
Sommersemester 2015
Cpp
Deth Buff Arr
Commits
b8fa7617
Commit
b8fa7617
authored
Oct 03, 2015
by
Georg Schaefer
Browse files
add starfield rendering
parent
16cbeda1
Changes
2
Hide whitespace changes
Inline
Side-by-side
assets/shader/starfield.fs
View file @
b8fa7617
...
...
@@ -2,6 +2,59 @@
out
vec4
frag_color
;
uniform
vec2
resolution
;
uniform
vec2
inverse_resolution
;
uniform
vec3
origin
;
uniform
mat2
rotation
;
uniform
float
zoom
;
#
define
iterations
15
#
define
volsteps
6
#
define
sparsity
0
.
5
f
#
define
stepsize
0
.
3
f
#
define
frequency_variation
1
.
3
f
#
define
brightness
0
.
0018
f
#
define
distfading
0
.
68
f
void
main
()
{
frag_color
=
vec4
(
1
.
f
);
vec2
uv
=
gl_FragCoord
.
xy
*
inverse_resolution
-
0
.
5
f
;
uv
.
y
*=
resolution
.
y
*
inverse_resolution
.
x
;
vec3
direction
=
vec3
(
uv
*
zoom
,
1
.
f
);
direction
.
xy
*=
rotation
;
float
s
=
0
.
1
f
;
float
fade
=
0
.
01
f
;
frag_color
=
vec4
(
0
.
f
);
for
(
int
r
=
0
;
r
<
volsteps
;
++
r
)
{
vec3
p
=
origin
+
direction
*
(
s
*
0
.
5
f
);
p
=
abs
(
vec3
(
frequency_variation
)
-
mod
(
p
,
vec3
(
frequency_variation
*
2
.
f
)));
float
prevlen
=
0
.
f
;
float
a
=
0
.
f
;
for
(
int
i
=
0
;
i
<
iterations
;
++
i
)
{
p
=
abs
(
p
);
p
=
p
*
(
1
.
f
/
dot
(
p
,
p
))
+
(-
sparsity
);
float
len
=
length
(
p
);
a
+=
abs
(
len
-
prevlen
);
prevlen
=
len
;
}
a
*=
a
*
a
;
frag_color
.
rgb
+=
(
vec3
(
s
,
s
*
s
,
s
*
s
*
s
)
*
a
*
brightness
+
1
.
f
)
*
fade
;
fade
*=
distfading
;
s
+=
stepsize
;
}
frag_color
.
rgb
=
min
(
frag_color
.
rgb
,
vec3
(
1
.
2
f
));
float
intensity
=
min
(
frag_color
.
r
+
frag_color
.
g
+
frag_color
.
b
,
0
.
7
f
);
ivec2
sgn
=
(
ivec2
(
gl_FragCoord
.
xy
)
&
1
)
*
2
-
1
;
vec2
gradient
=
vec2
(
dFdx
(
intensity
)
*
sgn
.
x
,
dFdy
(
intensity
)
*
sgn
.
y
);
float
cutoff
=
max
(
max
(
gradient
.
x
,
gradient
.
y
)
-
0
.
1
f
,
0
.
f
);
frag_color
.
rgb
*=
max
(
1
.
f
-
cutoff
*
0
.
6
f
,
0
.
3
f
);
frag_color
.
a
=
1
.
f
;
}
src/rendering/rendering_system.cpp
View file @
b8fa7617
...
...
@@ -835,6 +835,19 @@ namespace gdw {
void
rendering_system
::
render_starfield
(
float
delta_time
,
camera_component
&
camera
)
{
const
static
auto
model
=
glm
::
scale
(
glm
::
mat4
(
1.
f
),
glm
::
vec3
(
500.
f
));
const
static
auto
width
=
static_cast
<
float
>
(
engine_
.
graphics_system
().
width
());
const
static
auto
height
=
static_cast
<
float
>
(
engine_
.
graphics_system
().
height
());
static
auto
origin
=
glm
::
vec3
(
width
/
2.
f
,
height
/
2.
f
,
-
100.
f
);
origin
.
x
+=
delta_time
/
1000.
f
;
static
auto
alpha
=
0.
f
;
alpha
+=
delta_time
/
100.
f
;
if
(
alpha
>=
2.
f
*
glm
::
pi
<
float
>
())
{
alpha
=
0.
f
;
}
auto
rotation
=
glm
::
mat2
(
glm
::
cos
(
alpha
),
-
glm
::
sin
(
alpha
),
glm
::
sin
(
alpha
),
glm
::
cos
(
alpha
));
composition_buffer_
.
bind
();
...
...
@@ -847,6 +860,11 @@ namespace gdw {
starfield_program_
.
uniform
(
"projection"
,
false
,
camera
.
projection
());
starfield_program_
.
uniform
(
"view"
,
false
,
camera
.
view
());
starfield_program_
.
uniform
(
"model"
,
false
,
model
);
starfield_program_
.
uniform
(
"resolution"
,
glm
::
vec2
(
width
,
height
));
starfield_program_
.
uniform
(
"inverse_resolution"
,
1.
f
/
glm
::
vec2
(
width
,
height
));
starfield_program_
.
uniform
(
"origin"
,
origin
);
starfield_program_
.
uniform
(
"rotation"
,
false
,
rotation
);
starfield_program_
.
uniform
(
"zoom"
,
1.
f
);
starfield_
->
draw
(
starfield_program_
);
glDisable
(
GL_CULL_FACE
);
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment