Some tweaks again.
Fix compilation errors for older OpenGL
This commit is contained in:
parent
6b5f23003b
commit
6af29d0fcf
@ -85,12 +85,12 @@ float fresnel_dielectric(vec3 Incoming, vec3 Normal, float eta)
|
||||
void main (void)
|
||||
{
|
||||
|
||||
vec2 fragCoord = fragPos.xz;
|
||||
vec2 fragCoord = fragPos.xy;
|
||||
fragCoord = clamp(fragCoord,0.002,0.998);
|
||||
vec3 sunPos = vec3(0.0);
|
||||
sunPos.x=sin((timeOfDay-0.5)*3.14159);
|
||||
float timer = timeOfDay*1600;
|
||||
cameraPos = eyePosition;
|
||||
//cameraPos = eyePosition;
|
||||
|
||||
//normal map
|
||||
vec2 nCoord = vec2(0.0); //normal coords
|
||||
@ -166,7 +166,7 @@ vec2 fragCoord = fragPos.xz;
|
||||
|
||||
//fresnel term
|
||||
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 fresnel = fresnel_dielectric(-vVec,nVec,eta);
|
||||
|
||||
|
@ -1,14 +1,10 @@
|
||||
|
||||
uniform mat4 mWorldViewProj;
|
||||
uniform mat4 mInvWorld;
|
||||
uniform mat4 mTransWorld;
|
||||
uniform float dayNightRatio;
|
||||
uniform float timeOfDay;
|
||||
uniform vec3 eyePosition;
|
||||
|
||||
uniform float enableWaterWave;
|
||||
uniform float waterWaveHeight;
|
||||
uniform float waterWaveSpeed;
|
||||
uniform float waterWaveLength;
|
||||
uniform float timeOfDay;
|
||||
|
||||
varying vec3 vPosition;
|
||||
varying vec3 viewVec;
|
||||
@ -26,16 +22,18 @@ float rand(vec2 co)
|
||||
|
||||
void main(void)
|
||||
{
|
||||
gl_Position = mWorldViewProj * gl_Vertex;
|
||||
if (enableWaterWave == 1.0)
|
||||
{
|
||||
float height_randomness = 1.0;
|
||||
vec4 pos2 = gl_Vertex;
|
||||
pos2.y -= 3.0;
|
||||
pos2.y -= sin (pos2.z/waterWaveLength + timeOfDay * waterWaveSpeed * waterWaveLength) * waterWaveHeight
|
||||
+ sin ((pos2.z/waterWaveLength + timeOfDay * waterWaveSpeed * waterWaveLength)/7) * waterWaveHeight * height_randomness;
|
||||
gl_Position = mWorldViewProj * pos2;
|
||||
}
|
||||
int wavelength = 20;
|
||||
float waveheight = 1.0;
|
||||
int wavespeed = 50;
|
||||
int height_randomness = 1;
|
||||
|
||||
vec4 pos2 = gl_Vertex;
|
||||
pos2.y -= 3.0;
|
||||
pos2.y -= sin (pos2.z/wavelength + timeOfDay * wavespeed * wavelength) * waveheight
|
||||
+ sin ((pos2.z/wavelength + timeOfDay * wavespeed * wavelength)/7) * waveheight * height_randomness;
|
||||
|
||||
gl_Position = mWorldViewProj * pos2;
|
||||
|
||||
vPosition = (mWorldViewProj * gl_Vertex).xyz;
|
||||
vec3 pos = vec3(gl_Vertex);
|
||||
|
||||
@ -51,7 +49,7 @@ void main(void)
|
||||
worldPos = vec3(mTransWorld * gl_Vertex);
|
||||
fragPos = ftransform();
|
||||
viewPos = pos - gl_ModelViewMatrixInverse[3].xyz;
|
||||
//cameraPos = eyePosition;
|
||||
cameraPos = eyePosition;
|
||||
|
||||
vec4 color;
|
||||
//color = vec4(1.0, 1.0, 1.0, 1.0);
|
||||
|
@ -15,21 +15,26 @@ uniform vec3 eyePosition;
|
||||
varying vec3 vPosition;
|
||||
varying vec3 tsEyeVec;
|
||||
varying vec3 eyeVec;
|
||||
varying vec4 vColor;
|
||||
|
||||
const float e = 2.718281828459;
|
||||
|
||||
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;
|
||||
|
||||
vec3 color;
|
||||
vec2 uv = gl_TexCoord[0].st;
|
||||
float height;
|
||||
vec2 tsEye = -tsEyeVec.xy;
|
||||
vec2 tsEye = tsEyeVec.xy;
|
||||
|
||||
if ((parallaxMappingMode == 1.0) && (use_normalmap > 0.0)) {
|
||||
float map_height = texture2D(normalTexture, uv).a;
|
||||
float height = parallaxMappingScale * map_height - parallaxMappingBias;
|
||||
uv = uv + height * tsEye;
|
||||
if (map_height < 1.0){
|
||||
float height = parallaxMappingScale * map_height - parallaxMappingBias;
|
||||
uv = uv + height * tsEyeVec.xy;
|
||||
}
|
||||
}
|
||||
|
||||
if ((parallaxMappingMode == 2.0) && (use_normalmap > 0.0)) {
|
||||
@ -51,10 +56,10 @@ void main (void)
|
||||
|
||||
if ((enable_bumpmapping == 1.0) && (use_normalmap > 0.0)) {
|
||||
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 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 specular = pow(clamp(dot(R, lVec), 0.0, 1.0),1.0);
|
||||
color = diffuse * base + 0.1 * specular * diffuse;
|
||||
@ -64,13 +69,13 @@ void main (void)
|
||||
|
||||
float alpha = texture2D(baseTexture, uv).a;
|
||||
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 = col * col; // SRGB -> Linear
|
||||
col *= 1.8;
|
||||
col.r = 1.0 - exp(1.0 - col.r) / e_const;
|
||||
col.g = 1.0 - exp(1.0 - col.g) / e_const;
|
||||
col.b = 1.0 - exp(1.0 - col.b) / e_const;
|
||||
col.r = 1.0 - exp(1.0 - col.r) / e;
|
||||
col.g = 1.0 - exp(1.0 - col.g) / e;
|
||||
col.b = 1.0 - exp(1.0 - col.b) / e;
|
||||
col = sqrt(col); // Linear -> SRGB
|
||||
if(fogDistance != 0.0){
|
||||
float d = max(0.0, min(vPosition.z / fogDistance * 1.5 - 0.6, 1.0));
|
||||
|
@ -1,13 +1,14 @@
|
||||
uniform mat4 mWorldViewProj;
|
||||
uniform mat4 mInvWorld;
|
||||
uniform mat4 mTransWorld;
|
||||
|
||||
uniform float dayNightRatio;
|
||||
|
||||
uniform vec3 eyePosition;
|
||||
|
||||
varying vec3 vPosition;
|
||||
varying vec3 eyeVec;
|
||||
varying vec3 tsEyeVec;
|
||||
varying vec4 vColor;
|
||||
|
||||
void main(void)
|
||||
{
|
||||
@ -43,9 +44,9 @@ void main(void)
|
||||
binormal = normalize(gl_NormalMatrix * vec3( 0.0, -1.0, 0.0));
|
||||
}
|
||||
|
||||
mat3 tbnMatrix = mat3( tangent.x, binormal.x, normal.x,
|
||||
tangent.y, binormal.y, normal.y,
|
||||
tangent.z, binormal.z, normal.z);
|
||||
mat3 tbnMatrix = mat3(tangent.x, binormal.x, normal.x,
|
||||
tangent.y, binormal.y, normal.y,
|
||||
tangent.z, binormal.z, normal.z);
|
||||
|
||||
eyeVec = (gl_ModelViewMatrix * gl_Vertex).xyz;
|
||||
tsEyeVec = normalize(eyeVec * tbnMatrix);
|
||||
@ -90,7 +91,8 @@ void main(void)
|
||||
|
||||
color.a = gl_Color.a;
|
||||
|
||||
gl_FrontColor = gl_BackColor = color;
|
||||
vColor = gl_FrontColor = gl_BackColor = color;
|
||||
|
||||
gl_TexCoord[0] = gl_MultiTexCoord0;
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user