Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
Dario Seyb
edge-of-space
Commits
b195c6c2
Commit
b195c6c2
authored
Feb 04, 2016
by
Kaspar Scharf
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
slight changes inside the terrain shader to allow imports of different noise-files
replaced sin()-water by ridged-noise water
parent
0cb3af52
Changes
12
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
56 additions
and
37 deletions
+56
-37
data/shader/WaterSurface.fsh
data/shader/WaterSurface.fsh
+3
-0
data/shader/WaterSurface.tesh
data/shader/WaterSurface.tesh
+2
-0
data/shader/noise/noise4d.glsl
data/shader/noise/noise4d.glsl
+23
-24
data/shader/planets/earth.fsh
data/shader/planets/earth.fsh
+3
-0
data/shader/planets/earth.tesh
data/shader/planets/earth.tesh
+2
-0
data/shader/planets/earth_texture.glsl
data/shader/planets/earth_texture.glsl
+0
-5
data/shader/planets/moon.fsh
data/shader/planets/moon.fsh
+1
-0
data/shader/planets/moon.tesh
data/shader/planets/moon.tesh
+2
-0
data/shader/planets/moon_texture.glsl
data/shader/planets/moon_texture.glsl
+0
-5
data/shader/terrain/dispMappingWithWater_fsh.glsl
data/shader/terrain/dispMappingWithWater_fsh.glsl
+2
-2
data/shader/terrain/generic_water_texture.glsl
data/shader/terrain/generic_water_texture.glsl
+14
-1
data/shader/terrain/normalApproximation.glsl
data/shader/terrain/normalApproximation.glsl
+4
-0
No files found.
data/shader/WaterSurface.fsh
View file @
b195c6c2
...
...
@@ -2,6 +2,9 @@
#define LAST_SHADER GEOMETRY
#pragma import "noise/noise3d.glsl"
#pragma import "noise/noise4d.glsl"
#pragma import "Utils.glsl"
#pragma import "CommonDeferredFrag.glsl"
...
...
data/shader/WaterSurface.tesh
View file @
b195c6c2
...
...
@@ -2,6 +2,8 @@
uniform float uTime;
#pragma import "noise/noise3d.glsl"
#pragma import "Utils.glsl"
#pragma import "terrain/generic_water_texture.glsl"
...
...
data/shader/noise/noise4d.glsl
View file @
b195c6c2
...
...
@@ -15,31 +15,31 @@
// https://github.com/ashima/webgl-noise
//
vec4
mod289
(
vec4
x
)
{
vec4
mod289
_4d
(
vec4
x
)
{
return
x
-
floor
(
x
*
(
1
.
0
/
289
.
0
))
*
289
.
0
;
}
float
mod289
(
float
x
)
{
float
mod289
_4d
(
float
x
)
{
return
x
-
floor
(
x
*
(
1
.
0
/
289
.
0
))
*
289
.
0
;
}
vec4
permute
(
vec4
x
)
{
return
mod289
(((
x
*
34
.
0
)
+
1
.
0
)
*
x
);
vec4
permute
_4d
(
vec4
x
)
{
return
mod289
_4d
(((
x
*
34
.
0
)
+
1
.
0
)
*
x
);
}
float
permute
(
float
x
)
{
return
mod289
(((
x
*
34
.
0
)
+
1
.
0
)
*
x
);
float
permute
_4d
(
float
x
)
{
return
mod289
_4d
(((
x
*
34
.
0
)
+
1
.
0
)
*
x
);
}
vec4
taylorInvSqrt
(
vec4
r
)
vec4
taylorInvSqrt
_4d
(
vec4
r
)
{
return
1
.
79284291400159
-
0
.
85373472095314
*
r
;
}
float
taylorInvSqrt
(
float
r
)
float
taylorInvSqrt
_4d
(
float
r
)
{
return
1
.
79284291400159
-
0
.
85373472095314
*
r
;
}
vec4
grad4
(
float
j
,
vec4
ip
)
vec4
grad4
_4d
(
float
j
,
vec4
ip
)
{
const
vec4
ones
=
vec4
(
1
.
0
,
1
.
0
,
1
.
0
,
-
1
.
0
);
vec4
p
,
s
;
...
...
@@ -55,7 +55,7 @@ vec4 grad4(float j, vec4 ip)
// (sqrt(5) - 1)/4 = F4, used once below
#define F4 0.309016994374947451
float
snoise
(
vec4
v
)
float
snoise
_4d
(
vec4
v
)
{
const
vec4
C
=
vec4
(
0
.
138196601125011
,
// (5 - sqrt(5))/20 G4
0
.
276393202250021
,
// 2 * G4
...
...
@@ -97,9 +97,9 @@ float snoise(vec4 v)
vec4
x4
=
x0
+
C
.
wwww
;
// Permutations
i
=
mod289
(
i
);
float
j0
=
permute
(
permute
(
permute
(
permute
(
i
.
w
)
+
i
.
z
)
+
i
.
y
)
+
i
.
x
);
vec4
j1
=
permute
(
permute
(
permute
(
permute
(
i
=
mod289
_4d
(
i
);
float
j0
=
permute
_4d
(
permute
_4d
(
permute
_4d
(
permute
_4d
(
i
.
w
)
+
i
.
z
)
+
i
.
y
)
+
i
.
x
);
vec4
j1
=
permute
_4d
(
permute
_4d
(
permute
_4d
(
permute
_4d
(
i
.
w
+
vec4
(
i1
.
w
,
i2
.
w
,
i3
.
w
,
1
.
0
))
+
i
.
z
+
vec4
(
i1
.
z
,
i2
.
z
,
i3
.
z
,
1
.
0
))
+
i
.
y
+
vec4
(
i1
.
y
,
i2
.
y
,
i3
.
y
,
1
.
0
))
...
...
@@ -109,19 +109,19 @@ float snoise(vec4 v)
// 7*7*6 = 294, which is close to the ring size 17*17 = 289.
vec4
ip
=
vec4
(
1
.
0
/
294
.
0
,
1
.
0
/
49
.
0
,
1
.
0
/
7
.
0
,
0
.
0
)
;
vec4
p0
=
grad4
(
j0
,
ip
);
vec4
p1
=
grad4
(
j1
.
x
,
ip
);
vec4
p2
=
grad4
(
j1
.
y
,
ip
);
vec4
p3
=
grad4
(
j1
.
z
,
ip
);
vec4
p4
=
grad4
(
j1
.
w
,
ip
);
vec4
p0
=
grad4
_4d
(
j0
,
ip
);
vec4
p1
=
grad4
_4d
(
j1
.
x
,
ip
);
vec4
p2
=
grad4
_4d
(
j1
.
y
,
ip
);
vec4
p3
=
grad4
_4d
(
j1
.
z
,
ip
);
vec4
p4
=
grad4
_4d
(
j1
.
w
,
ip
);
// Normalise gradients
vec4
norm
=
taylorInvSqrt
(
vec4
(
dot
(
p0
,
p0
),
dot
(
p1
,
p1
),
dot
(
p2
,
p2
),
dot
(
p3
,
p3
)));
vec4
norm
=
taylorInvSqrt
_4d
(
vec4
(
dot
(
p0
,
p0
),
dot
(
p1
,
p1
),
dot
(
p2
,
p2
),
dot
(
p3
,
p3
)));
p0
*=
norm
.
x
;
p1
*=
norm
.
y
;
p2
*=
norm
.
z
;
p3
*=
norm
.
w
;
p4
*=
taylorInvSqrt
(
dot
(
p4
,
p4
));
p4
*=
taylorInvSqrt
_4d
(
dot
(
p4
,
p4
));
// Mix contributions from the five corners
vec3
m0
=
max
(
0
.
6
-
vec3
(
dot
(
x0
,
x0
),
dot
(
x1
,
x1
),
dot
(
x2
,
x2
)),
0
.
0
);
...
...
@@ -139,16 +139,15 @@ float snoise(vec4 v)
// https://github.com/ashima/webgl-noise/blob/master/demo/common/noisedemoMain.frag
// (13.12.2015)
//================================
float
sumUpOctavesSimple
_4d
(
vec4
coords
,
int
numberOfOcts
)
{
float
fbm
_4d
(
vec4
coords
,
int
numberOfOcts
,
float
frequency
)
{
// coords to be given in range [0., 1.]
float
frequencyFactor
=
1
.;
float
weight
=
0
.
5
;
float
noiseValue
=
0
.;
for
(
int
i
=
0
;
i
<
numberOfOcts
;
i
++
)
{
noiseValue
+=
weight
*
snoise
(
frequency
Factor
*
coords
);
noiseValue
+=
weight
*
snoise
_4d
(
frequency
*
coords
);
weight
=
weight
/
2
.;
frequency
Factor
=
frequency
Factor
*
2
;
frequency
=
frequency
*
2
;
}
return
noiseValue
;
...
...
data/shader/planets/earth.fsh
View file @
b195c6c2
...
...
@@ -2,6 +2,9 @@
#define LAST_SHADER GEOMETRY
#pragma import "../noise/noise3d.glsl"
#pragma import "../noise/noise4d.glsl"
#pragma import "../Utils.glsl"
#pragma import "../CommonDeferredFrag.glsl"
...
...
data/shader/planets/earth.tesh
View file @
b195c6c2
#pragma import "../noise/noise3d.glsl"
#pragma import "../Utils.glsl"
#pragma import "earth_texture.glsl"
...
...
data/shader/planets/earth_texture.glsl
View file @
b195c6c2
#pragma import "../noise/noise3d.glsl"
//needed for calculation of modified normal-vector; change until you get a good result for normals:
#define SAMPLE_ANGLE__NORMAL_VECTOR 0.000005
float
getContinentHeightNoise
(
vec3
normalizedPosInModelspace
)
{
return
2
*
(
fbm_3d
(
normalizedPosInModelspace
,
2
,
1
.
25
));
}
...
...
data/shader/planets/moon.fsh
View file @
b195c6c2
...
...
@@ -2,6 +2,7 @@
#define LAST_SHADER GEOMETRY
#pragma import "../noise/noise3d.glsl"
#pragma import "../Utils.glsl"
#pragma import "../CommonDeferredFrag.glsl"
...
...
data/shader/planets/moon.tesh
View file @
b195c6c2
#pragma import "../noise/noise3d.glsl"
#pragma import "../Utils.glsl"
#pragma import "earth_texture.glsl"
...
...
data/shader/planets/moon_texture.glsl
View file @
b195c6c2
#pragma import "../noise/noise3d.glsl"
#define M_PI 3.1415926535897932384626433832795
#define SAMPLE_ANGLE__NORMAL_VECTOR 0.0005
float
getHeight
(
vec3
normalizedPosInModelspace
)
{
return
(
fbm_3d
(
normalizedPosInModelspace
,
4
,
80
.)
/
2
.
+
2
*
fbm_3d
(
normalizedPosInModelspace
,
2
,
1
.
25
));
}
...
...
data/shader/terrain/dispMappingWithWater_fsh.glsl
View file @
b195c6c2
...
...
@@ -52,7 +52,7 @@ vec4 color() {
vec4
emissive
()
{
//return uEmissiveColor;
if
(
isWater
)
{
return
vec4
(
0
.,
0
.,
.
2
,
1
.);
return
vec4
(
0
.,
0
.,
.
8
,
1
.);
}
else
{
return
vec4
(
0
.,
0
.,
0
.,
1
.);
}
...
...
@@ -64,7 +64,7 @@ vec3 normal() {
vec4
specularSmoothness
()
{
if
(
isWater
)
{
return
vec4
(
0
.
4
,
0
.
4
,
0
.
8
,
0
.
85
);
return
vec4
(
0
.
4
,
0
.
4
,
0
.
8
,
.
85
);
}
else
{
return
vec4
(
0
.
2
,
0
.
2
,
0
.
2
,
0
.
1
);
}
...
...
data/shader/terrain/generic_water_texture.glsl
View file @
b195c6c2
float
texture_water_getRidgedDetailsHeightNoise
(
vec3
normalizedPosInModelspace
)
{
return
(.
75
-
abs
(
fbm_3d
(
vec3
(
normalizedPosInModelspace
+
vec3
(
uTime
*
0
.
0005
))
,
3
,
320
.)))
*
0
.
0003
;
//return 0.;
}
float
texture_water_getWaterLevelHeightAt
(
vec3
normalizedPosInModelspace
)
{
return
sin
(
75
*
2
*
M_PI
*
/*uTime*/
1
.
*
normalizedPosInModelspace
.
x
*
normalizedPosInModelspace
.
y
*
normalizedPosInModelspace
.
z
)
*
0
.
000025
;
return
texture_water_getRidgedDetailsHeightNoise
(
normalizedPosInModelspace
)
;
}
//float texture_water_getWaterLevelHeightAt(vec3 normalizedPosInModelspace) {
// return sin(75 * 2 * M_PI * /*uTime*/1. * normalizedPosInModelspace.x * normalizedPosInModelspace.y * normalizedPosInModelspace.z) * 0.000025;
//}
vec3
texture_water_getDisplacedPosition_modelspace
(
vec3
normalizedPosInModelspace
,
vec3
normalizedNormal
)
{
vec3
newPosition
=
normalizedPosInModelspace
+
normalizedNormal
*
texture_water_getWaterLevelHeightAt
(
normalizedPosInModelspace
);
return
newPosition
;
}
data/shader/terrain/normalApproximation.glsl
View file @
b195c6c2
//================================ NORMAL APROXIMATION: ==========0
#define SAMPLE_ANGLE__NORMAL_VECTOR 0.000005
//forward declarations, for the case that one of the functions is not implemented/the according approxNormal funciton not used
vec3
texture_getDisplacedPosition_modelspace
(
vec3
normalizedPosInModelspace
,
vec3
normalizedNormal
);
vec3
texture_water_getDisplacedPosition_modelspace
(
vec3
normalizedPosInModelspace
,
vec3
normalizedNormal
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a 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