1
0
Fork 0

WS30: Add zUpTransform and modelOffset, fix snow

This commit is contained in:
Stuart Buchanan 2021-11-19 22:06:34 +00:00
parent e0fb796bad
commit 688bbbc167
6 changed files with 30 additions and 15 deletions

View file

@ -43,7 +43,7 @@
varying vec4 light_diffuse_comp;
varying vec3 normal;
varying vec3 relPos;
varying vec2 rawPos;
varying vec3 rawPos;
//varying vec3 worldPos;
// Testing code:
vec3 worldPos = vec3(5000.0, 6000.0, 7000.0) + vec3(vec2(rawPos), 600.0); // vec3(100.0, 10.0, 3.0);

View file

@ -25,7 +25,7 @@ attribute vec2 orthophotoTexCoord;
varying vec4 light_diffuse_comp;
varying vec3 normal;
varying vec3 relPos;
varying vec2 rawPos;
varying vec3 rawPos;
varying vec3 worldPos;
//varying vec2 orthoTexCoord;
varying vec4 eyePos;
@ -51,6 +51,10 @@ uniform bool use_IR_vision;
uniform mat4 osg_ViewMatrixInverse;
// From VPBTechnique.cxx
uniform mat4 zUpTransform;
uniform vec3 modelOffset;
float earthShade;
float yprime_alt;
//float mie_angle;
@ -91,9 +95,8 @@ void main()
float vertex_alt;
float scattering;
rawPos = gl_Vertex.xy;
rawPos = (zUpTransform * gl_Vertex).xyz;
eyePos = gl_ModelViewMatrix * gl_Vertex;
worldPos = (osg_ViewMatrixInverse * eyePos).xyz;
steepness = dot(normalize(gl_Normal), vec3 (0.0, 0.0, 1.0));
@ -113,7 +116,7 @@ void main()
vec4 ep = gl_ModelViewMatrixInverse * vec4(0.0,0.0,0.0,1.0);
// and relative position to vector
relPos = gl_Vertex.xyz - ep.xyz;
relPos = (zUpTransform * vec4(vec4(modelOffset, 1.0) + gl_Vertex - ep)).xyz;
//ecViewdir = (gl_ModelViewMatrix * (ep - gl_Vertex)).xyz;
@ -122,7 +125,7 @@ void main()
float dist = length(relPos);
// altitude of the vertex in question, somehow zero leads to artefacts, so ensure it is at least 100m
vertex_alt = max(gl_Vertex.z,100.0);
vertex_alt = max(relPos.z,100.0);
scattering = ground_scattering + (1.0 - ground_scattering) * smoothstep(hazeLayerAltitude -100.0, hazeLayerAltitude + 100.0, vertex_alt);

View file

@ -43,7 +43,7 @@
varying vec4 light_diffuse_comp;
varying vec3 normal;
varying vec3 relPos;
varying vec2 rawPos;
varying vec3 rawPos;
//varying vec3 worldPos;
// Testing code:
vec3 worldPos = vec3(5000.0, 6000.0, 7000.0) + vec3(vec2(rawPos), 600.0); // vec3(100.0, 10.0, 3.0);
@ -110,6 +110,8 @@ uniform vec4 dimensionsArray[128];
uniform vec4 ambientArray[128];
uniform vec4 diffuseArray[128];
uniform vec4 specularArray[128];
varying vec4 zUpPosition;
uniform vec3 modelOffset;
const float EarthRadius = 5800000.0;
const float terminator_width = 200000.0;
@ -315,8 +317,8 @@ float dotnoisegrad_10m;
// slope noise
float slopenoise_50m = SlopeLines2D(rawPos, grad_dir, 50.0, steepness);
float slopenoise_100m = SlopeLines2D(rawPos, grad_dir, 100.0, steepness);
float slopenoise_50m = SlopeLines2D(rawPos.xy, grad_dir, 50.0, steepness);
float slopenoise_100m = SlopeLines2D(rawPos.xy, grad_dir, 100.0, steepness);
float snownoise_25m = mix(noise_25m, slopenoise_50m, clamp(3.0*(1.0-steepness),0.0,1.0));
float snownoise_50m = mix(noise_50m, slopenoise_100m, clamp(3.0*(1.0-steepness),0.0,1.0));

View file

@ -25,7 +25,7 @@
varying vec4 light_diffuse_comp;
varying vec3 normal;
varying vec3 relPos;
varying vec2 rawPos;
varying vec3 rawPos;
varying vec3 worldPos;
varying vec3 ecViewdir;
varying vec2 grad_dir;
@ -56,6 +56,10 @@ uniform bool use_IR_vision;
uniform mat4 osg_ViewMatrixInverse;
// From VPBTechnique.cxx
uniform mat4 zUpTransform;
uniform vec3 modelOffset;
float earthShade;
float yprime_alt;
@ -99,7 +103,7 @@ void main()
float vertex_alt;
float scattering;
rawPos = gl_Vertex.xy;
rawPos = (zUpTransform * gl_Vertex).xyz;
worldPos = (osg_ViewMatrixInverse *gl_ModelViewMatrix * gl_Vertex).xyz;
@ -130,7 +134,7 @@ void main()
vec4 ep = gl_ModelViewMatrixInverse * vec4(0.0,0.0,0.0,1.0);
// and relative position to vector
relPos = gl_Vertex.xyz - ep.xyz;
relPos = (zUpTransform * vec4(vec4(modelOffset, 1.0) + gl_Vertex - ep)).xyz;
ecViewdir = (gl_ModelViewMatrix * (ep - gl_Vertex)).xyz;
// unfortunately, we need the distance in the vertex shader, although the more accurate version
@ -138,7 +142,7 @@ void main()
float dist = length(relPos);
// altitude of the vertex in question, somehow zero leads to artefacts, so ensure it is at least 100m
vertex_alt = max(gl_Vertex.z,100.0);
vertex_alt = max(relPos.z,100.0);
scattering = ground_scattering + (1.0 - ground_scattering) * smoothstep(hazeLayerAltitude -100.0, hazeLayerAltitude + 100.0, vertex_alt);

View file

@ -16,6 +16,10 @@
#define MODE_DIFFUSE 1
#define MODE_AMBIENT_AND_DIFFUSE 2
// From VPBTechnique.cxx
uniform mat4 zUpTransform;
uniform vec3 modelOffset;
// The constant term of the lighting equation that doesn't depend on
// the surface normal is passed in gl_{Front,Back}Color. The alpha
// component is set to 1 for front, 0 for back in order to work around
@ -88,14 +92,14 @@ void main()
vec4 ep = gl_ModelViewMatrixInverse * vec4(0.0,0.0,0.0,1.0);
// and relative position to vector
relPos = gl_Vertex.xyz - ep.xyz;
relPos = (zUpTransform * vec4(vec4(modelOffset, 1.0) + gl_Vertex - ep)).xyz;
// unfortunately, we need the distance in the vertex shader, although the more accurate version
// is later computed in the fragment shader again
float dist = length(relPos);
// altitude of the vertex in question, somehow zero leads to artefacts, so ensure it is at least 100m
vertex_alt = max(gl_Vertex.z,100.0);
vertex_alt = max(relPos.z,100.0);
scattering = ground_scattering + (1.0 - ground_scattering) * smoothstep(hazeLayerAltitude -100.0, hazeLayerAltitude + 100.0, vertex_alt);

View file

@ -19,6 +19,8 @@ uniform vec4 dimensionsArray[128];
uniform vec4 ambientArray[128];
uniform vec4 diffuseArray[128];
uniform vec4 specularArray[128];
uniform mat4 zUpTransform;
uniform vec3 modelOffset;
// See include_fog.frag
uniform int fogType;