Some tweaks again.

Fix compilation errors for older OpenGL
master
RealBadAngel 2013-11-10 11:23:33 +01:00
parent 6b5f23003b
commit 6af29d0fcf
4 changed files with 42 additions and 37 deletions

View File

@ -85,12 +85,12 @@ float fresnel_dielectric(vec3 Incoming, vec3 Normal, float eta)
void main (void) void main (void)
{ {
vec2 fragCoord = fragPos.xz; vec2 fragCoord = fragPos.xy;
fragCoord = clamp(fragCoord,0.002,0.998); fragCoord = clamp(fragCoord,0.002,0.998);
vec3 sunPos = vec3(0.0); vec3 sunPos = vec3(0.0);
sunPos.x=sin((timeOfDay-0.5)*3.14159); sunPos.x=sin((timeOfDay-0.5)*3.14159);
float timer = timeOfDay*1600; float timer = timeOfDay*1600;
cameraPos = eyePosition; //cameraPos = eyePosition;
//normal map //normal map
vec2 nCoord = vec2(0.0); //normal coords vec2 nCoord = vec2(0.0); //normal coords
@ -166,7 +166,7 @@ vec2 fragCoord = fragPos.xz;
//fresnel term //fresnel term
float ior = 1.333; float ior = 1.333;
ior = (cameraPos.y>0.0)?(1.333/1.0):(1.0/1.333); //air to water; water to air //ior = (cameraPos.y>0.0)?(1.333/1.0):(1.0/1.333); //air to water; water to air
float eta = max(ior, 0.00001); float eta = max(ior, 0.00001);
float fresnel = fresnel_dielectric(-vVec,nVec,eta); float fresnel = fresnel_dielectric(-vVec,nVec,eta);

View File

@ -1,14 +1,10 @@
uniform mat4 mWorldViewProj; uniform mat4 mWorldViewProj;
uniform mat4 mInvWorld; uniform mat4 mInvWorld;
uniform mat4 mTransWorld; uniform mat4 mTransWorld;
uniform float dayNightRatio; uniform float dayNightRatio;
uniform float timeOfDay;
uniform vec3 eyePosition; uniform vec3 eyePosition;
uniform float timeOfDay;
uniform float enableWaterWave;
uniform float waterWaveHeight;
uniform float waterWaveSpeed;
uniform float waterWaveLength;
varying vec3 vPosition; varying vec3 vPosition;
varying vec3 viewVec; varying vec3 viewVec;
@ -26,16 +22,18 @@ float rand(vec2 co)
void main(void) void main(void)
{ {
gl_Position = mWorldViewProj * gl_Vertex; int wavelength = 20;
if (enableWaterWave == 1.0) float waveheight = 1.0;
{ int wavespeed = 50;
float height_randomness = 1.0; int height_randomness = 1;
vec4 pos2 = gl_Vertex;
pos2.y -= 3.0; vec4 pos2 = gl_Vertex;
pos2.y -= sin (pos2.z/waterWaveLength + timeOfDay * waterWaveSpeed * waterWaveLength) * waterWaveHeight pos2.y -= 3.0;
+ sin ((pos2.z/waterWaveLength + timeOfDay * waterWaveSpeed * waterWaveLength)/7) * waterWaveHeight * height_randomness; pos2.y -= sin (pos2.z/wavelength + timeOfDay * wavespeed * wavelength) * waveheight
gl_Position = mWorldViewProj * pos2; + sin ((pos2.z/wavelength + timeOfDay * wavespeed * wavelength)/7) * waveheight * height_randomness;
}
gl_Position = mWorldViewProj * pos2;
vPosition = (mWorldViewProj * gl_Vertex).xyz; vPosition = (mWorldViewProj * gl_Vertex).xyz;
vec3 pos = vec3(gl_Vertex); vec3 pos = vec3(gl_Vertex);
@ -51,7 +49,7 @@ void main(void)
worldPos = vec3(mTransWorld * gl_Vertex); worldPos = vec3(mTransWorld * gl_Vertex);
fragPos = ftransform(); fragPos = ftransform();
viewPos = pos - gl_ModelViewMatrixInverse[3].xyz; viewPos = pos - gl_ModelViewMatrixInverse[3].xyz;
//cameraPos = eyePosition; cameraPos = eyePosition;
vec4 color; vec4 color;
//color = vec4(1.0, 1.0, 1.0, 1.0); //color = vec4(1.0, 1.0, 1.0, 1.0);

View File

@ -15,21 +15,26 @@ uniform vec3 eyePosition;
varying vec3 vPosition; varying vec3 vPosition;
varying vec3 tsEyeVec; varying vec3 tsEyeVec;
varying vec3 eyeVec; varying vec3 eyeVec;
varying vec4 vColor;
const float e = 2.718281828459;
void main (void) void main (void)
{ {
float use_normalmap = texelFetch(useNormalmap,ivec2(1,1),0).r; float use_normalmap = texture2D(useNormalmap,vec2(1.0,1.0)).r;
float enable_bumpmapping = enableBumpmapping; float enable_bumpmapping = enableBumpmapping;
vec3 color; vec3 color;
vec2 uv = gl_TexCoord[0].st; vec2 uv = gl_TexCoord[0].st;
float height; float height;
vec2 tsEye = -tsEyeVec.xy; vec2 tsEye = tsEyeVec.xy;
if ((parallaxMappingMode == 1.0) && (use_normalmap > 0.0)) { if ((parallaxMappingMode == 1.0) && (use_normalmap > 0.0)) {
float map_height = texture2D(normalTexture, uv).a; float map_height = texture2D(normalTexture, uv).a;
float height = parallaxMappingScale * map_height - parallaxMappingBias; if (map_height < 1.0){
uv = uv + height * tsEye; float height = parallaxMappingScale * map_height - parallaxMappingBias;
uv = uv + height * tsEyeVec.xy;
}
} }
if ((parallaxMappingMode == 2.0) && (use_normalmap > 0.0)) { if ((parallaxMappingMode == 2.0) && (use_normalmap > 0.0)) {
@ -51,10 +56,10 @@ void main (void)
if ((enable_bumpmapping == 1.0) && (use_normalmap > 0.0)) { if ((enable_bumpmapping == 1.0) && (use_normalmap > 0.0)) {
vec4 base = texture2D(baseTexture, uv); vec4 base = texture2D(baseTexture, uv);
vec3 vVec = normalize(tsEyeVec); vec3 vVec = normalize(eyeVec);
vec3 bump = normalize(texture2D(normalTexture, uv).xyz * 2.0 - 1.0); vec3 bump = normalize(texture2D(normalTexture, uv).xyz * 2.0 - 1.0);
vec3 R = reflect(-vVec, bump); vec3 R = reflect(-vVec, bump);
vec3 lVec = normalize(vec3(0.0, -0.4, 0.5)); vec3 lVec = normalize(vVec*2);
float diffuse = max(dot(lVec, bump), 0.0); float diffuse = max(dot(lVec, bump), 0.0);
float specular = pow(clamp(dot(R, lVec), 0.0, 1.0),1.0); float specular = pow(clamp(dot(R, lVec), 0.0, 1.0),1.0);
color = diffuse * base + 0.1 * specular * diffuse; color = diffuse * base + 0.1 * specular * diffuse;
@ -64,13 +69,13 @@ void main (void)
float alpha = texture2D(baseTexture, uv).a; float alpha = texture2D(baseTexture, uv).a;
float e_const = 2.71828; float e_const = 2.71828;
vec4 col = vec4(color.r, color.g, color.b, alpha); vec4 col = vec4(color.r, color.g, color.b, alpha) * vColor;
col *= gl_Color; col *= gl_Color;
col = col * col; // SRGB -> Linear col = col * col; // SRGB -> Linear
col *= 1.8; col *= 1.8;
col.r = 1.0 - exp(1.0 - col.r) / e_const; col.r = 1.0 - exp(1.0 - col.r) / e;
col.g = 1.0 - exp(1.0 - col.g) / e_const; col.g = 1.0 - exp(1.0 - col.g) / e;
col.b = 1.0 - exp(1.0 - col.b) / e_const; col.b = 1.0 - exp(1.0 - col.b) / e;
col = sqrt(col); // Linear -> SRGB col = sqrt(col); // Linear -> SRGB
if(fogDistance != 0.0){ if(fogDistance != 0.0){
float d = max(0.0, min(vPosition.z / fogDistance * 1.5 - 0.6, 1.0)); float d = max(0.0, min(vPosition.z / fogDistance * 1.5 - 0.6, 1.0));

View File

@ -1,13 +1,14 @@
uniform mat4 mWorldViewProj; uniform mat4 mWorldViewProj;
uniform mat4 mInvWorld; uniform mat4 mInvWorld;
uniform mat4 mTransWorld; uniform mat4 mTransWorld;
uniform float dayNightRatio; uniform float dayNightRatio;
uniform vec3 eyePosition; uniform vec3 eyePosition;
varying vec3 vPosition; varying vec3 vPosition;
varying vec3 eyeVec; varying vec3 eyeVec;
varying vec3 tsEyeVec; varying vec3 tsEyeVec;
varying vec4 vColor;
void main(void) void main(void)
{ {
@ -42,14 +43,14 @@ void main(void)
tangent = normalize(gl_NormalMatrix * vec3(-1.0, 0.0, 0.0)); tangent = normalize(gl_NormalMatrix * vec3(-1.0, 0.0, 0.0));
binormal = normalize(gl_NormalMatrix * vec3( 0.0, -1.0, 0.0)); binormal = normalize(gl_NormalMatrix * vec3( 0.0, -1.0, 0.0));
} }
mat3 tbnMatrix = mat3( tangent.x, binormal.x, normal.x, mat3 tbnMatrix = mat3(tangent.x, binormal.x, normal.x,
tangent.y, binormal.y, normal.y, tangent.y, binormal.y, normal.y,
tangent.z, binormal.z, normal.z); tangent.z, binormal.z, normal.z);
eyeVec = (gl_ModelViewMatrix * gl_Vertex).xyz; eyeVec = (gl_ModelViewMatrix * gl_Vertex).xyz;
tsEyeVec = normalize(eyeVec * tbnMatrix); tsEyeVec = normalize(eyeVec * tbnMatrix);
vec4 color; vec4 color;
//color = vec4(1.0, 1.0, 1.0, 1.0); //color = vec4(1.0, 1.0, 1.0, 1.0);
@ -90,7 +91,8 @@ void main(void)
color.a = gl_Color.a; color.a = gl_Color.a;
gl_FrontColor = gl_BackColor = color; vColor = gl_FrontColor = gl_BackColor = color;
gl_TexCoord[0] = gl_MultiTexCoord0; gl_TexCoord[0] = gl_MultiTexCoord0;
} }