Commit b195c6c2 authored by Kaspar Scharf's avatar Kaspar Scharf

slight changes inside the terrain shader to allow imports of different noise-files

replaced sin()-water by ridged-noise water
parent 0cb3af52
......@@ -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"
......
......@@ -2,6 +2,8 @@
uniform float uTime;
#pragma import "noise/noise3d.glsl"
#pragma import "Utils.glsl"
#pragma import "terrain/generic_water_texture.glsl"
......
......@@ -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(frequencyFactor * coords);
noiseValue += weight * snoise_4d(frequency * coords);
weight = weight / 2.;
frequencyFactor = frequencyFactor * 2;
frequency = frequency * 2;
}
return noiseValue;
......
......@@ -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"
......
#pragma import "../noise/noise3d.glsl"
#pragma import "../Utils.glsl"
#pragma import "earth_texture.glsl"
......
#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));
}
......
......@@ -2,6 +2,7 @@
#define LAST_SHADER GEOMETRY
#pragma import "../noise/noise3d.glsl"
#pragma import "../Utils.glsl"
#pragma import "../CommonDeferredFrag.glsl"
......
#pragma import "../noise/noise3d.glsl"
#pragma import "../Utils.glsl"
#pragma import "earth_texture.glsl"
......
#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));
}
......
......@@ -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);
}
......
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;
}
//================================ 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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment