Oversized Shadow

Report bugs, bug fixes and workarounds here.
Avatar
Topic author
PlutonianEmpire M
Posts: 1374
Joined: 09.09.2004
Age: 40
With us: 20 years 2 months
Location: MinneSNOWta
Contact:

Oversized Shadow

Post #1by PlutonianEmpire » 19.10.2008, 18:30

In one of my systems, a moon casts a very large shadow on it's planet, even though they are really close to their sun:

Image

Image

This is in Open GL 2.0

My system:
HP Pavilion dv6815m laptop, with 1 GB NVIDIA Geforce Go 7150m graphics, 2 GH AMD Turion 64 Mobile Tech TL-60 processor, 3 GB RAM, and Windows Vista Home Premium.

Here's the shaders log

Code: Select all

Vertex shader source:
  1: #version 110
  2: uniform vec3 light0_direction;
  3: uniform vec3 light0_diffuse;
  4: uniform vec3 light0_specular;
  5: uniform vec3 light0_halfVector;
  6: uniform vec3 eyePosition;
  7: varying vec2 diffTexCoord;
  8: varying vec2 normTexCoord;
  9: varying vec2 specTexCoord;
 10: varying vec2 nightTexCoord;
 11: uniform float textureOffset;
 12: uniform vec3 atmosphereRadius;
 13: uniform float mieCoeff;
 14: uniform float mieH;
 15: uniform float mieK;
 16: uniform vec3 rayleighCoeff;
 17: uniform float rayleighH;
 18: uniform vec3 scatterCoeffSum;
 19: uniform vec3 invScatterCoeffSum;
 20: uniform vec3 extinctionCoeff;
 21: vec3 eyeDir = normalize(eyePosition - gl_Vertex.xyz);
 22: attribute vec3 tangent;
 23: varying vec3 lightDir_tan_0;
 24: varying vec3 eyeDir_tan;
 25: varying vec3 scatterEx;
 26:
 27: void main(void)
 28: {
 29: float NL;
 30: vec3 bitangent = cross(gl_Normal, tangent);
 31: eyeDir_tan.x = dot(tangent, eyeDir);
 32: eyeDir_tan.y = dot(-bitangent, eyeDir);
 33: eyeDir_tan.z = dot(gl_Normal, eyeDir);
 34: NL = max(0.0, dot(gl_Normal, light0_direction));
 35: lightDir_tan_0.x = dot(tangent, light0_direction);
 36: lightDir_tan_0.y = dot(-bitangent, light0_direction);
 37: lightDir_tan_0.z = dot(gl_Normal, light0_direction);
 38: diffTexCoord = gl_MultiTexCoord0.st + vec2(textureOffset, 0.0);
 39: normTexCoord = gl_MultiTexCoord1.st + vec2(textureOffset, 0.0);
 40: specTexCoord = gl_MultiTexCoord2.st;
 41: nightTexCoord = gl_MultiTexCoord3.st;
 42: {
 43:     float rq = dot(eyePosition, eyeDir);
 44:     float qq = dot(eyePosition, eyePosition) - atmosphereRadius.y;
 45:     float d = sqrt(rq * rq - qq);
 46:     vec3 atmEnter = eyePosition + min(0.0, (-rq + d)) * eyeDir;
 47:     vec3 atmLeave = gl_Vertex.xyz;
 48:     vec3 atmSamplePoint = (atmEnter + atmLeave) * 0.5;
 49:     vec3 atmSamplePointSun = atmEnter * 0.5 + atmLeave * 0.5;
 50:     rq = dot(atmSamplePointSun, light0_direction);
 51:     qq = dot(atmSamplePointSun, atmSamplePointSun) - atmosphereRadius.y;
 52:     d = sqrt(rq * rq - qq);
 53:     float distSun = -rq + d;
 54:     float distAtm = length(atmEnter - atmLeave);
 55:     float density = 0.0;
 56:     atmSamplePoint = atmEnter * 0.333 + atmLeave * 0.667;
 57:     float h = max(0.0, length(atmSamplePoint) - atmosphereRadius.z);
 58:     density += exp(-h * mieH);
 59:     atmSamplePoint = atmEnter * 0.667 + atmLeave * 0.333;
 60:     h = max(0.0, length(atmSamplePoint) - atmosphereRadius.z);
 61:     density += exp(-h * mieH);
 62:     vec3 sunColor = exp(-extinctionCoeff * density * distSun);
 63:     vec3 ex = exp(-extinctionCoeff * density * distAtm);
 64:     float cosTheta = dot(eyeDir, light0_direction);
 65:     float phMie = (1.0 - mieK * mieK) / ((1.0 - mieK * cosTheta) * (1.0 - mieK * cosTheta));
 66:     float phRayleigh = 1.0;
 67:     scatterEx = ex;
 68:     gl_FrontSecondaryColor.rgb = (phRayleigh * rayleighCoeff + phMie * mieCoeff) * invScatterCoeffSum * sunColor * (1.0 - exp(-scatterCoeffSum * density * distAtm));
 69: }
 70: gl_Position = ftransform();
 71: }

Fragment shader source:
  1: #version 110
  2: uniform sampler2D diffTex;
  3: uniform sampler2D normTex;
  4: uniform sampler2D specTex;
  5: uniform sampler2D nightTex;
  6: varying vec2 diffTexCoord;
  7: varying vec2 normTexCoord;
  8: varying vec2 specTexCoord;
  9: varying vec2 nightTexCoord;
 10: uniform vec3 ambientColor;
 11: uniform float opacity;
 12: vec4 diff = vec4(ambientColor, opacity);
 13: varying vec3 eyeDir_tan;
 14: vec4 spec = vec4(0.0);
 15: uniform float shininess;
 16: varying vec3 lightDir_tan_0;
 17: uniform vec3 lightcolor0;
 18: uniform vec3 lightspecColor0;
 19: varying vec3 scatterEx;
 20:
 21: void main(void)
 22: {
 23: vec4 color;
 24: vec3 n = texture2D(normTex, normTexCoord.st).xyz * 2.0 - vec3(1.0, 1.0, 1.0);
 25: float l;
 26: vec3 V = normalize(eyeDir_tan);
 27: vec3 H;
 28: float NH;
 29: float NL;
 30: NL = dot(lightDir_tan_0, n);
 31: l = max(0.0, dot(lightDir_tan_0, n)) * clamp(lightDir_tan_0.z * 8.0, 0.0, 1.0);
 32: float totalLight = l;
 33: diff.rgb += l * lightcolor0;
 34: H = normalize(eyeDir_tan + lightDir_tan_0);
 35: NH = max(0.0, dot(n, H));
 36: spec.rgb += l * pow(NH, shininess) * lightspecColor0;
 37: color = texture2D(diffTex, diffTexCoord.st);
 38: gl_FragColor = color * diff + texture2D(specTex, specTexCoord.st) * spec;
 39: totalLight = 1.0 - totalLight;
 40: totalLight = totalLight * totalLight * totalLight * totalLight;
 41: gl_FragColor += texture2D(nightTex, nightTexCoord.st) * totalLight;
 42: gl_FragColor.rgb = gl_FragColor.rgb * scatterEx + gl_SecondaryColor.rgb;
 43: }

Vertex shader source:
  1: #version 110
  2: uniform vec3 light0_direction;
  3: uniform vec3 light0_diffuse;
  4: uniform vec3 light0_specular;
  5: uniform vec3 light0_halfVector;
  6: uniform vec3 eyePosition;
  7: varying vec2 diffTexCoord;
  8: uniform float textureOffset;
  9: uniform vec3 atmosphereRadius;
 10: uniform float mieCoeff;
 11: uniform float mieH;
 12: uniform float mieK;
 13: uniform vec3 rayleighCoeff;
 14: uniform float rayleighH;
 15: uniform vec3 scatterCoeffSum;
 16: uniform vec3 invScatterCoeffSum;
 17: uniform vec3 extinctionCoeff;
 18: vec3 eyeDir = normalize(eyePosition - gl_Vertex.xyz);
 19: float NV = dot(gl_Normal, eyeDir);
 20: uniform vec3 ambientColor;
 21: uniform float opacity;
 22: varying vec4 diff;
 23: varying vec3 scatterEx;
 24:
 25: void main(void)
 26: {
 27: float NL;
 28: diff = vec4(ambientColor, opacity);
 29: NL = max(0.0, dot(gl_Normal, light0_direction));
 30: diff.rgb += light0_diffuse * NL;
 31: diffTexCoord = gl_MultiTexCoord0.st + vec2(textureOffset, 0.0);
 32: {
 33:     float rq = dot(eyePosition, eyeDir);
 34:     float qq = dot(eyePosition, eyePosition) - atmosphereRadius.y;
 35:     float d = sqrt(rq * rq - qq);
 36:     vec3 atmEnter = eyePosition + min(0.0, (-rq + d)) * eyeDir;
 37:     vec3 atmLeave = gl_Vertex.xyz;
 38:     vec3 atmSamplePoint = (atmEnter + atmLeave) * 0.5;
 39:     vec3 atmSamplePointSun = atmEnter * 0.5 + atmLeave * 0.5;
 40:     rq = dot(atmSamplePointSun, light0_direction);
 41:     qq = dot(atmSamplePointSun, atmSamplePointSun) - atmosphereRadius.y;
 42:     d = sqrt(rq * rq - qq);
 43:     float distSun = -rq + d;
 44:     float distAtm = length(atmEnter - atmLeave);
 45:     float density = 0.0;
 46:     atmSamplePoint = atmEnter * 0.333 + atmLeave * 0.667;
 47:     float h = max(0.0, length(atmSamplePoint) - atmosphereRadius.z);
 48:     density += exp(-h * mieH);
 49:     atmSamplePoint = atmEnter * 0.667 + atmLeave * 0.333;
 50:     h = max(0.0, length(atmSamplePoint) - atmosphereRadius.z);
 51:     density += exp(-h * mieH);
 52:     vec3 sunColor = exp(-extinctionCoeff * density * distSun);
 53:     vec3 ex = exp(-extinctionCoeff * density * distAtm);
 54:     float cosTheta = dot(eyeDir, light0_direction);
 55:     float phMie = (1.0 - mieK * mieK) / ((1.0 - mieK * cosTheta) * (1.0 - mieK * cosTheta));
 56:     float phRayleigh = 1.0;
 57:     scatterEx = ex;
 58:     gl_FrontSecondaryColor.rgb = (phRayleigh * rayleighCoeff + phMie * mieCoeff) * invScatterCoeffSum * sunColor * (1.0 - exp(-scatterCoeffSum * density * distAtm));
 59: }
 60: gl_Position = ftransform();
 61: }

Fragment shader source:
  1: #version 110
  2: uniform sampler2D diffTex;
  3: varying vec2 diffTexCoord;
  4: varying vec4 diff;
  5: varying vec3 scatterEx;
  6:
  7: void main(void)
  8: {
  9: vec4 color;
 10: color = texture2D(diffTex, diffTexCoord.st);
 11: gl_FragColor = color * diff;
 12: gl_FragColor.rgb = gl_FragColor.rgb * scatterEx + gl_SecondaryColor.rgb;
 13: }

Vertex shader source:
  1: #version 110
  2: uniform vec3 light0_direction;
  3: uniform vec3 light0_diffuse;
  4: uniform vec3 light0_specular;
  5: uniform vec3 light0_halfVector;
  6: uniform vec3 eyePosition;
  7: uniform vec3 atmosphereRadius;
  8: uniform float mieCoeff;
  9: uniform float mieH;
 10: uniform float mieK;
 11: uniform vec3 rayleighCoeff;
 12: uniform float rayleighH;
 13: uniform vec3 scatterCoeffSum;
 14: uniform vec3 invScatterCoeffSum;
 15: uniform vec3 extinctionCoeff;
 16: varying vec3 scatteredColor0;
 17: vec3 eyeDir = normalize(eyePosition - gl_Vertex.xyz);
 18: float NV = dot(gl_Normal, eyeDir);
 19: varying vec3 scatterEx;
 20: varying vec3 eyeDir_obj;
 21:
 22: void main(void)
 23: {
 24: float NL;
 25: {
 26:     float rq = dot(eyePosition, eyeDir);
 27:     float qq = dot(eyePosition, eyePosition) - atmosphereRadius.y;
 28:     float d = sqrt(rq * rq - qq);
 29:     vec3 atmEnter = eyePosition + min(0.0, (-rq + d)) * eyeDir;
 30:     vec3 atmLeave = gl_Vertex.xyz;
 31:     vec3 atmSamplePoint = (atmEnter + atmLeave) * 0.5;
 32:     vec3 atmSamplePointSun = atmEnter * 0.5 + atmLeave * 0.5;
 33:     rq = dot(atmSamplePointSun, light0_direction);
 34:     qq = dot(atmSamplePointSun, atmSamplePointSun) - atmosphereRadius.y;
 35:     d = sqrt(rq * rq - qq);
 36:     float distSun = -rq + d;
 37:     float distAtm = length(atmEnter - atmLeave);
 38:     float density = 0.0;
 39:     atmSamplePoint = atmEnter * 0.333 + atmLeave * 0.667;
 40:     float h = max(0.0, length(atmSamplePoint) - atmosphereRadius.z);
 41:     density += exp(-h * mieH);
 42:     atmSamplePoint = atmEnter * 0.667 + atmLeave * 0.333;
 43:     h = max(0.0, length(atmSamplePoint) - atmosphereRadius.z);
 44:     density += exp(-h * mieH);
 45:     vec3 sunColor = exp(-extinctionCoeff * density * distSun);
 46:     vec3 ex = exp(-extinctionCoeff * density * distAtm);
 47:     scatterEx = ex;
 48:     scatteredColor0 = sunColor * (1.0 - exp(-scatterCoeffSum * density * distAtm));
 49: }
 50: eyeDir_obj = eyeDir;
 51: gl_Position = ftransform();
 52: }

Fragment shader source:
  1: #version 110
  2: varying vec3 scatterEx;
  3: varying vec3 eyeDir_obj;
  4: uniform float mieK;
  5: uniform float mieCoeff;
  6: uniform vec3  rayleighCoeff;
  7: uniform vec3  invScatterCoeffSum;
  8: uniform vec3 light0_direction;
  9: varying vec3 scatteredColor0;
 10:
 11: void main(void)
 12: {
 13: vec3 color = vec3(0.0, 0.0, 0.0);
 14: vec3 V = normalize(eyeDir_obj);
 15:     float cosTheta = dot(V, light0_direction);
 16:     float phMie = (1.0 - mieK * mieK) / ((1.0 - mieK * cosTheta) * (1.0 - mieK * cosTheta));
 17:     float phRayleigh = 1.0;
 18:     color += (phRayleigh * rayleighCoeff + phMie * mieCoeff) * invScatterCoeffSum * scatteredColor0;
 19:     gl_FragColor = vec4(color, dot(scatterEx, vec3(0.333, 0.333, 0.333)));
 20: }

Vertex shader source:
  1: #version 110
  2: uniform vec3 light0_direction;
  3: uniform vec3 light0_diffuse;
  4: uniform vec3 light0_specular;
  5: uniform vec3 light0_halfVector;
  6: uniform vec3 eyePosition;
  7: varying vec2 diffTexCoord;
  8: varying vec2 normTexCoord;
  9: varying vec2 specTexCoord;
 10: uniform float textureOffset;
 11: uniform vec3 atmosphereRadius;
 12: uniform float mieCoeff;
 13: uniform float mieH;
 14: uniform float mieK;
 15: uniform vec3 rayleighCoeff;
 16: uniform float rayleighH;
 17: uniform vec3 scatterCoeffSum;
 18: uniform vec3 invScatterCoeffSum;
 19: uniform vec3 extinctionCoeff;
 20: vec3 eyeDir = normalize(eyePosition - gl_Vertex.xyz);
 21: attribute vec3 tangent;
 22: varying vec3 lightDir_tan_0;
 23: varying vec3 eyeDir_tan;
 24: varying vec3 scatterEx;
 25:
 26: void main(void)
 27: {
 28: float NL;
 29: vec3 bitangent = cross(gl_Normal, tangent);
 30: eyeDir_tan.x = dot(tangent, eyeDir);
 31: eyeDir_tan.y = dot(-bitangent, eyeDir);
 32: eyeDir_tan.z = dot(gl_Normal, eyeDir);
 33: NL = max(0.0, dot(gl_Normal, light0_direction));
 34: lightDir_tan_0.x = dot(tangent, light0_direction);
 35: lightDir_tan_0.y = dot(-bitangent, light0_direction);
 36: lightDir_tan_0.z = dot(gl_Normal, light0_direction);
 37: diffTexCoord = gl_MultiTexCoord0.st + vec2(textureOffset, 0.0);
 38: normTexCoord = gl_MultiTexCoord1.st + vec2(textureOffset, 0.0);
 39: specTexCoord = gl_MultiTexCoord2.st;
 40: {
 41:     float rq = dot(eyePosition, eyeDir);
 42:     float qq = dot(eyePosition, eyePosition) - atmosphereRadius.y;
 43:     float d = sqrt(rq * rq - qq);
 44:     vec3 atmEnter = eyePosition + min(0.0, (-rq + d)) * eyeDir;
 45:     vec3 atmLeave = gl_Vertex.xyz;
 46:     vec3 atmSamplePoint = (atmEnter + atmLeave) * 0.5;
 47:     vec3 atmSamplePointSun = atmEnter * 0.5 + atmLeave * 0.5;
 48:     rq = dot(atmSamplePointSun, light0_direction);
 49:     qq = dot(atmSamplePointSun, atmSamplePointSun) - atmosphereRadius.y;
 50:     d = sqrt(rq * rq - qq);
 51:     float distSun = -rq + d;
 52:     float distAtm = length(atmEnter - atmLeave);
 53:     float density = 0.0;
 54:     atmSamplePoint = atmEnter * 0.333 + atmLeave * 0.667;
 55:     float h = max(0.0, length(atmSamplePoint) - atmosphereRadius.z);
 56:     density += exp(-h * mieH);
 57:     atmSamplePoint = atmEnter * 0.667 + atmLeave * 0.333;
 58:     h = max(0.0, length(atmSamplePoint) - atmosphereRadius.z);
 59:     density += exp(-h * mieH);
 60:     vec3 sunColor = exp(-extinctionCoeff * density * distSun);
 61:     vec3 ex = exp(-extinctionCoeff * density * distAtm);
 62:     float cosTheta = dot(eyeDir, light0_direction);
 63:     float phMie = (1.0 - mieK * mieK) / ((1.0 - mieK * cosTheta) * (1.0 - mieK * cosTheta));
 64:     float phRayleigh = 1.0;
 65:     scatterEx = ex;
 66:     gl_FrontSecondaryColor.rgb = (phRayleigh * rayleighCoeff + phMie * mieCoeff) * invScatterCoeffSum * sunColor * (1.0 - exp(-scatterCoeffSum * density * distAtm));
 67: }
 68: gl_Position = ftransform();
 69: }

Fragment shader source:
  1: #version 110
  2: uniform sampler2D diffTex;
  3: uniform sampler2D normTex;
  4: uniform sampler2D specTex;
  5: varying vec2 diffTexCoord;
  6: varying vec2 normTexCoord;
  7: varying vec2 specTexCoord;
  8: uniform vec3 ambientColor;
  9: uniform float opacity;
 10: vec4 diff = vec4(ambientColor, opacity);
 11: varying vec3 eyeDir_tan;
 12: vec4 spec = vec4(0.0);
 13: uniform float shininess;
 14: varying vec3 lightDir_tan_0;
 15: uniform vec3 lightcolor0;
 16: uniform vec3 lightspecColor0;
 17: varying vec3 scatterEx;
 18:
 19: void main(void)
 20: {
 21: vec4 color;
 22: vec3 n = texture2D(normTex, normTexCoord.st).xyz * 2.0 - vec3(1.0, 1.0, 1.0);
 23: float l;
 24: vec3 V = normalize(eyeDir_tan);
 25: vec3 H;
 26: float NH;
 27: float NL;
 28: NL = dot(lightDir_tan_0, n);
 29: l = max(0.0, dot(lightDir_tan_0, n)) * clamp(lightDir_tan_0.z * 8.0, 0.0, 1.0);
 30: diff.rgb += l * lightcolor0;
 31: H = normalize(eyeDir_tan + lightDir_tan_0);
 32: NH = max(0.0, dot(n, H));
 33: spec.rgb += l * pow(NH, shininess) * lightspecColor0;
 34: color = texture2D(diffTex, diffTexCoord.st);
 35: gl_FragColor = color * diff + texture2D(specTex, specTexCoord.st) * spec;
 36: gl_FragColor.rgb = gl_FragColor.rgb * scatterEx + gl_SecondaryColor.rgb;
 37: }

Terraformed Pluto: Now with New Horizons maps! :D

chris
Site Admin
Posts: 4211
Joined: 28.01.2002
With us: 22 years 9 months
Location: Seattle, Washington, USA

Re: Oversized Shadow

Post #2by chris » 19.10.2008, 20:43

Can you provide a simplified version of the add-on that shows the problem. Just a simple ssc file (and no textures or meshes) should be adequate.

I think I know the source of the problem--the shadow is probably the right size, but it's much darker than it should be.

--Chris

Avatar
Topic author
PlutonianEmpire M
Posts: 1374
Joined: 09.09.2004
Age: 40
With us: 20 years 2 months
Location: MinneSNOWta
Contact:

Re: Oversized Shadow

Post #3by PlutonianEmpire » 19.10.2008, 20:53

chris wrote:Can you provide a simplified version of the add-on that shows the problem. Just a simple ssc file (and no textures or meshes) should be adequate.

I think I know the source of the problem--the shadow is probably the right size, but it's much darker than it should be.

--Chris

ssc:

Code: Select all

"Vulcean" "PSC Cen" {
   Texture "vulcean.png"
   Radius 9821

   EllipticalOrbit {
      Period            0.0111
      SemiMajorAxis     0.0500
      Eccentricity      0.1000
      Inclination       3.0000
      MeanAnomaly      13.3529
   }

   Obliquity                18.00
   
   Albedo           0.05
}

"Venoso" "PSC Cen/Vulcean" {
   Texture "gc_rocky_04.jpg"
   Radius 1800

   EllipticalOrbit {
      Period            0.8140
      SemiMajorAxis     80000.0000
      Eccentricity      0.0030
      Inclination       0.1000
      MeanAnomaly       337.8778
   }

   Obliquity                     0.100
   EquatorAscendingNode         90.000

   Albedo       0.430
}


stc:

Code: Select all

200000 "Pisces Centauri:P.C.:Pisces Centau:PSC Cen:New Sol" {
   RA  19.93750000
   Dec 10.83333333
   Distance 2.00
   SpectralType "G2V"
   #AbsMag 4.06
   AppMag -2.00
}
Terraformed Pluto: Now with New Horizons maps! :D


Return to “Bugs”