diff --git a/Effects/ws30.eff b/Effects/ws30.eff index 89107e5bd..df8bfdcb2 100644 --- a/Effects/ws30.eff +++ b/Effects/ws30.eff @@ -84,7 +84,7 @@ 0 0.5 0.0 - 0.5 + 0.9 0.0 1.0 1.0 diff --git a/Shaders/ws30-ALS-detailed.frag b/Shaders/ws30-ALS-detailed.frag index a8872895b..2a7725704 100644 --- a/Shaders/ws30-ALS-detailed.frag +++ b/Shaders/ws30-ALS-detailed.frag @@ -44,9 +44,9 @@ varying vec4 light_diffuse_comp; varying vec3 normal; varying vec3 relPos; varying vec3 rawPos; -//varying vec3 worldPos; +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); +//vec3 worldPos = vec3(5000.0, 6000.0, 7000.0) + vec3(vec2(rawPos), 600.0); // vec3(100.0, 10.0, 3.0); //varying vec2 orthoTexCoord; varying vec4 eyePos; @@ -84,11 +84,17 @@ uniform int quality_level; uniform int tquality_level; // Passed from VPBTechnique, not the Effect -uniform bool photoScenery; -uniform vec4 dimensionsArray[128]; -uniform vec4 ambientArray[128]; -uniform vec4 diffuseArray[128]; -uniform vec4 specularArray[128]; +uniform float fg_tileWidth; +uniform float fg_tileHeight; +uniform bool fg_photoScenery; +uniform vec4 fg_dimensionsArray[128]; +uniform vec4 fg_ambientArray[128]; +uniform vec4 fg_diffuseArray[128]; +uniform vec4 fg_specularArray[128]; +uniform vec4 fg_textureLookup1[128]; +uniform vec4 fg_textureLookup2[128]; +uniform mat4 fg_zUpTransform; +uniform vec3 fg_modelOffset; const float EarthRadius = 5800000.0; const float terminator_width = 200000.0; @@ -283,13 +289,11 @@ float noise_2000m = Noise3D(worldPos.xyz, 2000.0); float index = float(lc)/512.0; vec4 index_n = vec4(lc_n)/512.0; - float mat_shininess = dimensionsArray[lc].z; - vec4 mat_ambient = ambientArray[lc]; - vec4 mat_diffuse = diffuseArray[lc]; - vec4 mat_specular = specularArray[lc]; - - - + float mat_shininess = fg_dimensionsArray[lc].z; + vec4 mat_ambient = fg_ambientArray[lc]; + vec4 mat_diffuse = fg_diffuseArray[lc]; + vec4 mat_specular = fg_specularArray[lc]; + vec2 st = gl_TexCoord[0].st; // Testing code: // Use rlc even when looking up textures to recreate the extra performance hit @@ -297,7 +301,7 @@ float noise_2000m = Noise3D(worldPos.xyz, 2000.0); // color.rgb = color.rgb+0.00001*float(get_random_landclass(tile_coord.st, tile_size)); - if (photoScenery) { + if (fg_photoScenery) { // In the photoscenery case we don't have landclass or materials available, so we // just use constants for the material properties. mat_ambient = vec4(0.2,0.2,0.2,1.0); @@ -311,8 +315,13 @@ float noise_2000m = Noise3D(worldPos.xyz, 2000.0); // rather than the material color from ambientArray/diffuseArray. mat_ambient = vec4(1.0,1.0,1.0,1.0); mat_diffuse = vec4(1.0,1.0,1.0,1.0); - mat_specular = specularArray[lc]; - mat_shininess = dimensionsArray[lc].z; + mat_specular = fg_specularArray[lc]; + mat_shininess = fg_dimensionsArray[lc].z; + + // Different textures have different have different dimensions. + vec2 atlas_dimensions = fg_dimensionsArray[lc].st; + vec2 atlas_scale = vec2(fg_tileWidth / atlas_dimensions.s, fg_tileHeight / atlas_dimensions.t ); + st = atlas_scale * gl_TexCoord[0].st; // Look up ground textures by indexing into the texture array. // Different textures are stretched along the ground to different @@ -352,66 +361,76 @@ float noise_2000m = Noise3D(worldPos.xyz, 2000.0); //vec4 green = vec4(0.0, 0.5, 0.0, 0.0); //texel = mix(texel, green, (mfact[2])); - // Testing code: temp - mix_texel = texel; - detail_texel = texel; int flag = 1; - int mix_flag = 1; + int mix_flag = 1; + float local_autumn_factor = texel.a; - float local_autumn_factor = texel.a; - - if (photoScenery) { + if (fg_photoScenery) { flag = 0; mix_flag = 0; } - float distortion_factor = 1.0; - vec2 stprime; + float distortion_factor = 1.0; + vec2 stprime; - float noise_term; - float snow_alpha; + float noise_term; + float snow_alpha; - //float view_angle = abs(dot(normal, normalize(ecViewdir))); + //float view_angle = abs(dot(normal, normalize(ecViewdir))); - if ((quality_level > 3)&&(relPos.z + eye_alt +500.0 > snowlevel)) + if ((quality_level > 3)&&(rawPos.z +500.0 > snowlevel)) { + float sfactor; + snow_texel = vec4 (0.95, 0.95, 0.95, 1.0) * (0.9 + 0.1* noise_500m + 0.1* (1.0 - noise_10m) ); + snow_texel.r = snow_texel.r * (0.9 + 0.05 * (noise_10m + noise_5m)); + snow_texel.g = snow_texel.g * (0.9 + 0.05 * (noise_10m + noise_5m)); + snow_texel.a = 1.0; + noise_term = 0.1 * (noise_500m-0.5); + sfactor = sqrt(2.0 * (1.0-steepness)/0.03) + abs(ct)/0.15; + noise_term = noise_term + 0.2 * (noise_50m -0.5) * (1.0 - smoothstep(18000.0*sfactor, 40000.0*sfactor, dist) ) ; + noise_term = noise_term + 0.3 * (noise_10m -0.5) * (1.0 - smoothstep(4000.0 * sfactor, 8000.0 * sfactor, dist) ) ; + + if (dist < 3000.0*sfactor) { + noise_term = noise_term + 0.3 * (noise_5m -0.5) * (1.0 - smoothstep(1000.0 * sfactor, 3000.0 *sfactor, dist) ); + } + + snow_texel.a = snow_texel.a * 0.2+0.8* smoothstep(0.2,0.8, 0.3 +noise_term + snow_thickness_factor +0.0001*(rawPos.z -snowlevel) ); + + } + + mix_flag = 1; + flag = 0; + + if ((tquality_level > 2) && (mix_flag == 1)) { - float sfactor; - snow_texel = vec4 (0.95, 0.95, 0.95, 1.0) * (0.9 + 0.1* noise_500m + 0.1* (1.0 - noise_10m) ); - snow_texel.r = snow_texel.r * (0.9 + 0.05 * (noise_10m + noise_5m)); - snow_texel.g = snow_texel.g * (0.9 + 0.05 * (noise_10m + noise_5m)); - snow_texel.a = 1.0; - noise_term = 0.1 * (noise_500m-0.5); - sfactor = sqrt(2.0 * (1.0-steepness)/0.03) + abs(ct)/0.15; - noise_term = noise_term + 0.2 * (noise_50m -0.5) * (1.0 - smoothstep(18000.0*sfactor, 40000.0*sfactor, dist) ) ; - noise_term = noise_term + 0.3 * (noise_10m -0.5) * (1.0 - smoothstep(4000.0 * sfactor, 8000.0 * sfactor, dist) ) ; - if (dist < 3000.0*sfactor){ noise_term = noise_term + 0.3 * (noise_5m -0.5) * (1.0 - smoothstep(1000.0 * sfactor, 3000.0 *sfactor, dist) );} - snow_texel.a = snow_texel.a * 0.2+0.8* smoothstep(0.2,0.8, 0.3 +noise_term + snow_thickness_factor +0.0001*(relPos.z +eye_alt -snowlevel) ); - - } + // Mix texture is material texture 15, which is mapped to the b channel of fg_textureLookup1 + int tex2 = int(fg_textureLookup1[lc].b * 255.0 + 0.5); + mix_texel = texture(textureArray, vec3(gl_TexCoord[0].st * 1.3, tex2)); - if ((tquality_level > 2) && (mix_flag == 1)) - { - //mix_texel = texture2D(mix_texture, gl_TexCoord[0].st * 1.3); // temp - if (mix_texel.a <0.1) {mix_flag = 0;} + //mix_texel = texture2D(mix_texture, gl_TexCoord[0].st * 1.3); // temp + if (tex2 < 0) { mix_flag = 0;} } - - if (tquality_level > 3 && (flag == 1)) + if (tquality_level > 3 && (flag == 1)) { - stprime = vec2 (0.86*gl_TexCoord[0].s + 0.5*gl_TexCoord[0].t, 0.5*gl_TexCoord[0].s - 0.86*gl_TexCoord[0].t); - //distortion_factor = 0.9375 + (1.0 * nvL[2]); - distortion_factor = 0.97 + 0.06 * noise_500m; - stprime = stprime * distortion_factor * 15.0; - if (quality_level > 4) + stprime = vec2 (0.86*gl_TexCoord[0].s + 0.5*gl_TexCoord[0].t, 0.5*gl_TexCoord[0].s - 0.86*gl_TexCoord[0].t); + //distortion_factor = 0.9375 + (1.0 * nvL[2]); + distortion_factor = 0.97 + 0.06 * noise_500m; + stprime = stprime * distortion_factor * 15.0; + if (quality_level > 4) { - stprime = stprime + normalize(relPos).xy * 0.02 * (noise_10m + 0.5 * noise_5m - 0.75); + stprime = stprime + normalize(relPos).xy * 0.02 * (noise_10m + 0.5 * noise_5m - 0.75); } - //detail_texel = texture2D(detail_texture, stprime); // temp - if (detail_texel.a <0.1) {flag = 0;} - } + // Detail texture is material texture 11, which is mapped to the g channel of fg_textureLookup1 + int tex3 = int(fg_textureLookup1[lc].g * 255.0 + 0.5); + detail_texel = texture(textureArray, vec3(stprime, tex3)); + + //detail_texel = texture2D(detail_texture, stprime); // temp + + if (tex3 < 0) {flag = 0;} + } // texture preparation according to detail level @@ -421,44 +440,40 @@ float dist_fact; float nSum; float mix_factor; -if (tquality_level > 2) - { - // first the second texture overlay - // transition model 0: random patch overlay without any gradient information - // transition model 1: only gradient-driven transitions, no randomness +if (tquality_level > 2) { + // first the second texture overlay + // transition model 0: random patch overlay without any gradient information + // transition model 1: only gradient-driven transitions, no randomness - if (mix_flag == 1) - { - nSum = 0.18 * (2.0 * noise_2000m + 2.0 * noise_1500m + noise_500m); - nSum = mix(nSum, 0.5, max(0.0, 2.0 * (transition_model - 0.5))); - nSum = nSum + 0.4 * (1.0 -smoothstep(0.9,0.95, abs(steepness)+ 0.05 * (noise_50m - 0.5))) * min(1.0, 2.0 * transition_model); - mix_factor = smoothstep(0.5, 0.54, nSum); - texel = mix(texel, mix_texel, mix_factor); - local_autumn_factor = texel.a; - } - - // then the detail texture overlay + if (mix_flag == 1) { + nSum = 0.18 * (2.0 * noise_2000m + 2.0 * noise_1500m + noise_500m); + nSum = mix(nSum, 0.5, max(0.0, 2.0 * (transition_model - 0.5))); + nSum = nSum + 0.4 * (1.0 -smoothstep(0.9,0.95, abs(steepness)+ 0.05 * (noise_50m - 0.5))) * min(1.0, 2.0 * transition_model); + mix_factor = smoothstep(0.5, 0.54, nSum); + texel = mix(texel, mix_texel, mix_factor); + local_autumn_factor = texel.a; } + +} -if (tquality_level > 3) - { - if (dist < 40000.0) - { - if (flag == 1) - { - //noise_50m = Noise2D(rawPos.xy, 50.0); - //noise_250m = Noise2D(rawPos.xy, 250.0); - dist_fact = 0.1 * smoothstep(15000.0,40000.0, dist) - 0.03 * (1.0 - smoothstep(500.0,5000.0, dist)); - nSum = ((1.0 -noise_2000m) + noise_1500m + 2.0 * noise_250m +noise_50m)/5.0; - nSum = nSum - 0.08 * (1.0 -smoothstep(0.9,0.95, abs(steepness))); - mix_factor = smoothstep(0.47, 0.54, nSum +hires_overlay_bias - dist_fact); - if (mix_factor > 0.8) {mix_factor = 0.8;} - texel = mix(texel, detail_texel,mix_factor); - local_autumn_factor = texel.a; - } - } - } +if (tquality_level > 3) { + // then the detail texture overlay + if (dist < 40000.0) + { + if (flag == 1) { + //noise_50m = Noise2D(rawPos.xy, 50.0); + //noise_250m = Noise2D(rawPos.xy, 250.0); + dist_fact = 0.1 * smoothstep(15000.0,40000.0, dist) - 0.03 * (1.0 - smoothstep(500.0,5000.0, dist)); + nSum = ((1.0 -noise_2000m) + noise_1500m + 2.0 * noise_250m +noise_50m)/5.0; + nSum = nSum - 0.08 * (1.0 -smoothstep(0.9,0.95, abs(steepness))); + mix_factor = smoothstep(0.47, 0.54, nSum +hires_overlay_bias - dist_fact); + if (mix_factor > 0.8) {mix_factor = 0.8;} + texel = mix(texel, detail_texel,mix_factor); + local_autumn_factor = texel.a; + } + } +} @@ -493,18 +508,18 @@ if (quality_level > 3) texel = mix(texel, dust_color, clamp(0.5 * dust_cover_factor + 3.0 * dust_cover_factor * (((noise_1500m - 0.5) * 0.125)+0.125 ),0.0, 1.0) ); // mix snow - if (relPos.z + eye_alt +500.0 > snowlevel) + if (rawPos.z +500.0 > snowlevel) { snow_alpha = smoothstep(0.75, 0.85, abs(steepness)); //texel = mix(texel, snow_texel, texel_snow_fraction); - texel = mix(texel, snow_texel, snow_texel.a* smoothstep(snowlevel, snowlevel+200.0, snow_alpha * (relPos.z + eye_alt)+ (noise_2000m + 0.1 * noise_10m -0.55) *400.0)); + texel = mix(texel, snow_texel, snow_texel.a* smoothstep(snowlevel, snowlevel+200.0, snow_alpha * (rawPos.z)+ (noise_2000m + 0.1 * noise_10m -0.55) *400.0)); } } -else if (relPos.z + eye_alt +500.0 > snowlevel) +else if (rawPos.z +500.0 > snowlevel) { - float snow_alpha = 0.5+0.5* smoothstep(0.2,0.8, 0.3 + snow_thickness_factor +0.0001*(relPos.z +eye_alt -snowlevel) ); + float snow_alpha = 0.5+0.5* smoothstep(0.2,0.8, 0.3 + snow_thickness_factor +0.0001*(rawPos.z -snowlevel) ); // texel = vec4(dot(vec3(0.2989, 0.5870, 0.1140), texel.rgb)); - texel = mix(texel, vec4(1.0), snow_alpha* smoothstep(snowlevel, snowlevel+200.0, (relPos.z + eye_alt))); + texel = mix(texel, vec4(1.0), snow_alpha* smoothstep(snowlevel, snowlevel+200.0, (rawPos.z))); } diff --git a/Shaders/ws30-ALS-detailed.vert b/Shaders/ws30-ALS-detailed.vert index 094b182b4..0eb906e96 100644 --- a/Shaders/ws30-ALS-detailed.vert +++ b/Shaders/ws30-ALS-detailed.vert @@ -52,8 +52,8 @@ uniform bool use_IR_vision; uniform mat4 osg_ViewMatrixInverse; // From VPBTechnique.cxx -uniform mat4 zUpTransform; -uniform vec3 modelOffset; +uniform mat4 fg_zUpTransform; +uniform vec3 fg_modelOffset; float earthShade; float yprime_alt; @@ -95,9 +95,10 @@ void main() float vertex_alt; float scattering; - rawPos = (zUpTransform * gl_Vertex).xyz; + rawPos = (fg_zUpTransform * gl_Vertex).xyz; + worldPos = fg_modelOffset + gl_Vertex.xyz; eyePos = gl_ModelViewMatrix * gl_Vertex; - steepness = dot(normalize(gl_Normal), vec3 (0.0, 0.0, 1.0)); + steepness = dot(normalize(vec3(fg_zUpTransform * vec4(gl_Normal,1.0))), vec3 (0.0, 0.0, 1.0)); // this code is copied from default.vert @@ -116,7 +117,7 @@ void main() vec4 ep = gl_ModelViewMatrixInverse * vec4(0.0,0.0,0.0,1.0); // and relative position to vector - relPos = (zUpTransform * vec4(vec4(modelOffset, 1.0) + gl_Vertex - ep)).xyz; + relPos = (fg_zUpTransform * vec4(gl_Vertex - ep)).xyz; //ecViewdir = (gl_ModelViewMatrix * (ep - gl_Vertex)).xyz; @@ -125,7 +126,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(relPos.z,100.0); + vertex_alt = max(rawPos.z,100.0); scattering = ground_scattering + (1.0 - ground_scattering) * smoothstep(hazeLayerAltitude -100.0, hazeLayerAltitude + 100.0, vertex_alt); diff --git a/Shaders/ws30-ALS-landclass-search-functions.frag b/Shaders/ws30-ALS-landclass-search-functions.frag index 2e8da28ca..af480b089 100644 --- a/Shaders/ws30-ALS-landclass-search-functions.frag +++ b/Shaders/ws30-ALS-landclass-search-functions.frag @@ -230,17 +230,24 @@ uniform sampler2DArray textureArray; uniform sampler2D perlin; // Passed from VPBTechnique, not the Effect -uniform int tile_level; -uniform float tile_width; -uniform float tile_height; -uniform vec4 dimensionsArray[128]; +uniform float fg_tileWidth; +uniform float fg_tileHeight; +uniform bool fg_photoScenery; +uniform vec4 fg_dimensionsArray[128]; +uniform vec4 fg_ambientArray[128]; +uniform vec4 fg_diffuseArray[128]; +uniform vec4 fg_specularArray[128]; +uniform vec4 fg_textureLookup1[128]; +uniform vec4 fg_textureLookup2[128]; +uniform mat4 fg_zUpTransform; +uniform vec3 fg_modelOffset; // These should be sent as uniforms // Tile dimensions in meters // vec2 tile_size = vec2(tile_width , tile_height); // Testing: texture coords are sent flipped right now: -vec2 tile_size = vec2(tile_height , tile_width); +vec2 tile_size = vec2(fg_tileHeight , fg_tileWidth); // These are defined in noise.frag float rand2D(in vec2 co); @@ -257,12 +264,12 @@ int get_random_landclass(in vec2 co, in vec2 tile_size) // Look up texture coordinates and stretching scale of ground textures -void get_ground_texture_data(in int textureIndex, in vec2 tile_coord, +void get_ground_texture_data(in int lc, in vec2 tile_coord, out vec2 st, out vec2 g_texture_scale, inout vec2 dx, inout vec2 dy) { // Look up stretching dimensions of ground textures in m - scaled to // fit in [0..1], so rescale - vec2 g_texture_stretch_dim = dimensionsArray[textureIndex].st; + vec2 g_texture_stretch_dim = fg_dimensionsArray[lc].st; g_texture_scale = tile_size.xy / g_texture_stretch_dim.xy; // Correct partial derivatives to account for stretching of different textures dx = dx * g_texture_scale; @@ -351,7 +358,8 @@ vec4 lookup_ground_texture_array(in vec2 tile_coord, in int landclass_id, //texel = texture(textureArray, vec3(st, lc)); //texel = textureLod(textureArray, vec3(st, lc), 12.0); - texel = textureGrad(textureArray, vec3(st, lc), dx, dy); + uint tex1 = uint(fg_textureLookup1[lc].r * 255.0 + 0.5); + texel = textureGrad(textureArray, vec3(st, tex1), dx, dy); return texel; } @@ -362,7 +370,7 @@ int read_landclass_id(in vec2 tile_coord) vec2 dy = dFdy(tile_coord.st); int lc; - if (landclass_source == 0) lc = (int(texture2D(landclass, tile_coord.st).g * 255.0 + 0.5)); + if (landclass_source == 0) lc = (int(texture2D(landclass, tile_coord.st).r * 255.0 + 0.5)); else lc = (get_random_landclass(tile_coord.st, tile_size)); return lc; } diff --git a/Shaders/ws30-ALS-ultra.frag b/Shaders/ws30-ALS-ultra.frag index aa66c0988..f1cca6043 100644 --- a/Shaders/ws30-ALS-ultra.frag +++ b/Shaders/ws30-ALS-ultra.frag @@ -44,9 +44,9 @@ varying vec4 light_diffuse_comp; varying vec3 normal; varying vec3 relPos; varying vec3 rawPos; -//varying vec3 worldPos; +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); +//vec3 worldPos = vec3(5000.0, 6000.0, 7000.0) + vec3(vec2(rawPos), 600.0); // vec3(100.0, 10.0, 3.0); varying vec3 ecViewdir; varying vec2 grad_dir; //varying vec2 orthoTexCoord; @@ -105,13 +105,17 @@ uniform int use_alt_landing_light; uniform int swatch_size; //in metres, typically 1000 or 2000 // Passed from VPBTechnique, not the Effect -uniform bool photoScenery; -uniform vec4 dimensionsArray[128]; -uniform vec4 ambientArray[128]; -uniform vec4 diffuseArray[128]; -uniform vec4 specularArray[128]; -varying vec4 zUpPosition; -uniform vec3 modelOffset; +uniform float fg_tileWidth; +uniform float fg_tileHeight; +uniform bool fg_photoScenery; +uniform vec4 fg_dimensionsArray[128]; +uniform vec4 fg_ambientArray[128]; +uniform vec4 fg_diffuseArray[128]; +uniform vec4 fg_specularArray[128]; +uniform vec4 fg_textureLookup1[128]; +uniform vec4 fg_textureLookup2[128]; +uniform mat4 fg_zUpTransform; +uniform vec3 fg_modelOffset; const float EarthRadius = 5800000.0; const float terminator_width = 200000.0; @@ -380,19 +384,18 @@ float snownoise_50m = mix(noise_50m, slopenoise_100m, clamp(3.0*(1.0-steepness), float index = float(lc)/512.0; vec4 index_n = vec4(lc_n)/512.0; - float mat_shininess = dimensionsArray[lc].z; - vec4 mat_ambient = ambientArray[lc]; - vec4 mat_diffuse = diffuseArray[lc]; - vec4 mat_specular = specularArray[lc]; - - + float mat_shininess = fg_dimensionsArray[lc].z; + vec4 mat_ambient = fg_ambientArray[lc]; + vec4 mat_diffuse = fg_diffuseArray[lc]; + vec4 mat_specular = fg_specularArray[lc]; + vec2 st = gl_TexCoord[0].st; // Testing code: // Use rlc even when looking up textures to recreate the extra performance hit // so any performance difference between the two is due to the texture lookup // color.rgb = color.rgb+0.00001*float(get_random_landclass(tile_coord.st, tile_size)); - if (photoScenery) { + if (fg_photoScenery) { // In the photoscenery case we don't have landclass or materials available, so we // just use constants for the material properties. mat_ambient = vec4(0.2,0.2,0.2,1.0); @@ -410,14 +413,17 @@ float snownoise_50m = mix(noise_50m, slopenoise_100m, clamp(3.0*(1.0-steepness), // rather than the material color from ambientArray/diffuseArray. mat_ambient = vec4(1.0,1.0,1.0,1.0); mat_diffuse = vec4(1.0,1.0,1.0,1.0); - mat_specular = specularArray[lc]; - mat_shininess = dimensionsArray[lc].z; + mat_specular = fg_specularArray[lc]; + mat_shininess = fg_dimensionsArray[lc].z; // Look up ground textures by indexing into the texture array. // Different textures are stretched along the ground to different // lengths along each axes as set by and // regional definitions parameters + vec2 atlas_dimensions = fg_dimensionsArray[lc].st; + vec2 atlas_scale = vec2(fg_tileWidth / atlas_dimensions.s, fg_tileHeight / atlas_dimensions.t ); + st = atlas_scale * gl_TexCoord[0].st; // Look up texture coordinates and scale of ground textures @@ -454,13 +460,27 @@ float snownoise_50m = mix(noise_50m, slopenoise_100m, clamp(3.0*(1.0-steepness), //vec4 green = vec4(0.0, 0.5, 0.0, 0.0); //texel = mix(texel, green, (mfact[2])); + // Mix texture is material texture 12, which is mapped to the b channel of fg_textureLookup1 + int tex2 = int(fg_textureLookup1[lc].b * 255.0 + 0.5); + mix_texel = texture(textureArray, vec3(gl_TexCoord[0].st * 1.3, tex2)); + if (tex2 < 0) mix_flag = 0; // Disable if no index found - // Testing: temp values - dot_texel = texel;// texture2D(dot_texture, vec2 (stprime.y, stprime.x) ); - detail_texel = texel; - mix_texel = texel; - grain_texel = texel; - gradient_texel = texel; + // Dot texture is material texture 15, which is mapped to the g channel of fg_textureLookup2 + tex2 = int(fg_textureLookup2[lc].g * 255.0 + 0.5); + dot_texel = texture(textureArray, vec3(gl_TexCoord[0].st * 1.3, tex2)); + + // Detail texture is material texture 11, which is mapped to the g channel of fg_textureLookup1 + tex2 = int(fg_textureLookup1[lc].g * 255.0 + 0.5); + detail_texel = texture(textureArray, vec3(gl_TexCoord[0].st * 1.3, tex2)); + if (tex2 < 0) flag = 0; // Disable if no index found + + // Grain texture is material texture 14, which is mapped to the r channel of fg_textureLookup2 + tex2 = int(fg_textureLookup2[lc].r * 255.0 + 0.5); + grain_texel = texture(textureArray, vec3(gl_TexCoord[0].st * 1.3, tex2)); + + // Gradient texture is material texture 13, which is mapped to the a channel of fg_textureLookup1 + tex2 = int(fg_textureLookup1[lc].a * 255.0 + 0.5); + gradient_texel = texture(textureArray, vec3(gl_TexCoord[0].st * 1.3, tex2)); // Testing: WS2 code after this @@ -492,12 +512,6 @@ float snownoise_50m = mix(noise_50m, slopenoise_100m, clamp(3.0*(1.0-steepness), snow_texel.a = snow_texel.a * 0.2+0.8* smoothstep(0.2,0.8, 0.3 +noise_term + snow_thickness_factor +0.0001*(msl_altitude -snowlevel) ); } - // the mixture/gradient texture - if (mix_flag == 1) { - //mix_texel = texture2D(mix_texture, gl_TexCoord[0].st * 1.3); // temp - if (mix_texel.a <0.1) {mix_flag = 0;} - } - // the hires overlay texture is loaded with parallax mapping if (flag == 1) { @@ -507,7 +521,6 @@ float snownoise_50m = mix(noise_50m, slopenoise_100m, clamp(3.0*(1.0-steepness), stprime = stprime + normalize(relPos).xy * 0.022 * (noise_10m + 0.5 * noise_5m +0.25 * noise_2m - 0.875 ); //detail_texel = texture2D(detail_texture, stprime); // temp - if (detail_texel.a <0.1) {flag = 0;} } // texture preparation according to detail level @@ -521,7 +534,8 @@ float mix_factor; // first the second texture overlay // transition model 0: random patch overlay without any gradient information // transition model 1: only gradient-driven transitions, no randomness - + + mix_flag = 0; if (mix_flag == 1) { diff --git a/Shaders/ws30-ALS-ultra.vert b/Shaders/ws30-ALS-ultra.vert index 21f91c407..15b7bc6a0 100644 --- a/Shaders/ws30-ALS-ultra.vert +++ b/Shaders/ws30-ALS-ultra.vert @@ -57,8 +57,8 @@ uniform bool use_IR_vision; uniform mat4 osg_ViewMatrixInverse; // From VPBTechnique.cxx -uniform mat4 zUpTransform; -uniform vec3 modelOffset; +uniform mat4 fg_zUpTransform; +uniform vec3 fg_modelOffset; float earthShade; float yprime_alt; @@ -103,11 +103,11 @@ void main() float vertex_alt; float scattering; - rawPos = (zUpTransform * gl_Vertex).xyz; - worldPos = (osg_ViewMatrixInverse *gl_ModelViewMatrix * gl_Vertex).xyz; + rawPos = (fg_zUpTransform * gl_Vertex).xyz; + worldPos = fg_modelOffset + gl_Vertex.xyz; - steepness = dot(normalize(gl_Normal), vec3 (0.0, 0.0, 1.0)); + steepness = dot(normalize(vec3(fg_zUpTransform * vec4(gl_Normal,1.0))), vec3 (0.0, 0.0, 1.0)); grad_dir = normalize(gl_Normal.xy); vec4 pos = gl_Vertex; @@ -134,7 +134,7 @@ void main() vec4 ep = gl_ModelViewMatrixInverse * vec4(0.0,0.0,0.0,1.0); // and relative position to vector - relPos = (zUpTransform * vec4(vec4(modelOffset, 1.0) + gl_Vertex - ep)).xyz; + relPos = (fg_zUpTransform * vec4(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 @@ -142,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(relPos.z,100.0); + vertex_alt = max(rawPos.z,100.0); scattering = ground_scattering + (1.0 - ground_scattering) * smoothstep(hazeLayerAltitude -100.0, hazeLayerAltitude + 100.0, vertex_alt); diff --git a/Shaders/ws30-ALS.frag b/Shaders/ws30-ALS.frag index 64ad3ebd2..4a516f4a4 100644 --- a/Shaders/ws30-ALS.frag +++ b/Shaders/ws30-ALS.frag @@ -62,14 +62,19 @@ uniform float eye_alt; uniform float cloud_self_shading; // Passed from VPBTechnique, not the Effect -uniform int tile_level; -uniform float tile_width; -uniform float tile_height; -uniform bool photoScenery; -uniform vec4 dimensionsArray[128]; -uniform vec4 ambientArray[128]; -uniform vec4 diffuseArray[128]; -uniform vec4 specularArray[128]; +// Passed from VPBTechnique, not the Effect +uniform float fg_tileWidth; +uniform float fg_tileHeight; +uniform bool fg_photoScenery; +uniform vec4 fg_dimensionsArray[128]; +uniform vec4 fg_ambientArray[128]; +uniform vec4 fg_diffuseArray[128]; +uniform vec4 fg_specularArray[128]; +uniform vec4 fg_textureLookup1[128]; +uniform vec4 fg_textureLookup2[128]; +#define MAX_TEXTURES 8 +uniform mat4 fg_zUpTransform; +uniform vec3 fg_modelOffset; const float EarthRadius = 5800000.0; const float terminator_width = 200000.0; @@ -225,7 +230,7 @@ void main() vec4 mat_diffuse, mat_ambient, mat_specular; float mat_shininess; - if (photoScenery) { + if (fg_photoScenery) { mat_ambient = vec4(1.0,1.0,1.0,1.0); mat_diffuse = vec4(1.0,1.0,1.0,1.0); mat_specular = vec4(0.1, 0.1, 0.1, 1.0); @@ -238,8 +243,8 @@ void main() // rather than the material color from ambientArray/diffuseArray. mat_ambient = vec4(1.0,1.0,1.0,1.0); mat_diffuse = vec4(1.0,1.0,1.0,1.0); - mat_specular = specularArray[lc]; - mat_shininess = dimensionsArray[lc].z; + mat_specular = fg_specularArray[lc]; + mat_shininess = fg_dimensionsArray[lc].z; // Look up ground textures by indexing into the texture array. // Different textures are stretched along the ground to different diff --git a/Shaders/ws30-ALS.vert b/Shaders/ws30-ALS.vert index 6d0ded7eb..0ef6387a9 100644 --- a/Shaders/ws30-ALS.vert +++ b/Shaders/ws30-ALS.vert @@ -17,8 +17,8 @@ #define MODE_AMBIENT_AND_DIFFUSE 2 // From VPBTechnique.cxx -uniform mat4 zUpTransform; -uniform vec3 modelOffset; +uniform mat4 fg_zUpTransform; +uniform vec3 fg_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 @@ -92,7 +92,7 @@ void main() vec4 ep = gl_ModelViewMatrixInverse * vec4(0.0,0.0,0.0,1.0); // and relative position to vector - relPos = (zUpTransform * vec4(vec4(modelOffset, 1.0) + gl_Vertex - ep)).xyz; + relPos = (fg_zUpTransform * vec4(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 diff --git a/Shaders/ws30-q1.frag b/Shaders/ws30-q1.frag index eac4365a7..987886d0e 100644 --- a/Shaders/ws30-q1.frag +++ b/Shaders/ws30-q1.frag @@ -12,15 +12,17 @@ uniform sampler2DArray atlas; uniform sampler2D perlin; // Passed from VPBTechnique, not the Effect -uniform float tile_width; -uniform float tile_height; -uniform bool photoScenery; -uniform vec4 dimensionsArray[128]; -uniform vec4 ambientArray[128]; -uniform vec4 diffuseArray[128]; -uniform vec4 specularArray[128]; -uniform mat4 zUpTransform; -uniform vec3 modelOffset; +uniform float fg_tileWidth; +uniform float fg_tileHeight; +uniform bool fg_photoScenery; +uniform vec4 fg_dimensionsArray[128]; +uniform vec4 fg_ambientArray[128]; +uniform vec4 fg_diffuseArray[128]; +uniform vec4 fg_specularArray[128]; +uniform vec4 fg_textureLookup1[128]; +uniform vec4 fg_textureLookup2[128]; +uniform mat4 fg_zUpTransform; +uniform vec3 fg_modelOffset; // See include_fog.frag uniform int fogType; @@ -46,7 +48,7 @@ void main() vec4 mat_diffuse, mat_ambient, mat_specular; float mat_shininess; - if (photoScenery) { + if (fg_photoScenery) { mat_ambient = vec4(1.0,1.0,1.0,1.0); mat_diffuse = vec4(1.0,1.0,1.0,1.0); mat_specular = vec4(0.1, 0.1, 0.1, 1.0); @@ -56,19 +58,20 @@ void main() } else { // The Landclass for this particular fragment. This can be used to // index into the atlas textures. - int lc = int(texture2D(landclass, gl_TexCoord[0].st).g * 255.0 + 0.5); + int lc = int(texture2D(landclass, gl_TexCoord[0].st).r * 255.0 + 0.5); + uint tex1 = uint(fg_textureLookup1[lc].r * 255.0 + 0.5); // Color Mode is always AMBIENT_AND_DIFFUSE, which means // using a base colour of white for ambient/diffuse, // rather than the material color from ambientArray/diffuseArray. mat_ambient = vec4(1.0,1.0,1.0,1.0); mat_diffuse = vec4(1.0,1.0,1.0,1.0); - mat_specular = specularArray[lc]; - mat_shininess = dimensionsArray[lc].z; + mat_specular = fg_specularArray[lc]; + mat_shininess = fg_dimensionsArray[lc].z; // Different textures have different have different dimensions. - vec2 atlas_dimensions = dimensionsArray[lc].st; - vec2 atlas_scale = vec2(tile_width / atlas_dimensions.s, tile_height / atlas_dimensions.t ); + vec2 atlas_dimensions = fg_dimensionsArray[lc].st; + vec2 atlas_scale = vec2(fg_tileWidth / atlas_dimensions.s, fg_tileHeight / atlas_dimensions.t ); vec2 st = atlas_scale * gl_TexCoord[0].st; // Rotate texture using the perlin texture as a mask to reduce tiling @@ -80,7 +83,8 @@ void main() st = -st; } - texel = texture(atlas, vec3(st, lc)); + texel = texture(atlas, vec3(st, tex1)); + } vec4 color = mat_ambient * (gl_LightModel.ambient + gl_LightSource[0].ambient); diff --git a/Shaders/ws30.frag b/Shaders/ws30.frag index 07fc8e163..006b94383 100644 --- a/Shaders/ws30.frag +++ b/Shaders/ws30.frag @@ -11,13 +11,18 @@ uniform sampler2D landclass; uniform sampler2DArray atlas; // Passed from VPBTechnique, not the Effect -uniform float tile_width; -uniform float tile_height; -uniform bool photoScenery; -uniform vec4 dimensionsArray[128]; -uniform vec4 ambientArray[128]; -uniform vec4 diffuseArray[128]; -uniform vec4 specularArray[128]; +uniform float fg_tileWidth; +uniform float fg_tileHeight; +uniform bool fg_photoScenery; +uniform vec4 fg_dimensionsArray[128]; +uniform vec4 fg_ambientArray[128]; +uniform vec4 fg_diffuseArray[128]; +uniform vec4 fg_specularArray[128]; +uniform vec4 fg_textureLookup1[128]; +uniform vec4 fg_textureLookup2[128]; +#define MAX_TEXTURES 8 +uniform mat4 fg_zUpTransform; +uniform vec3 fg_modelOffset; // See include_fog.frag uniform int fogType; @@ -42,7 +47,7 @@ void main() vec4 mat_diffuse, mat_ambient, mat_specular; float mat_shininess; - if (photoScenery) { + if (fg_photoScenery) { mat_ambient = vec4(1.0,1.0,1.0,1.0); mat_diffuse = vec4(1.0,1.0,1.0,1.0); mat_specular = vec4(0.1, 0.1, 0.1, 1.0); @@ -52,21 +57,21 @@ void main() } else { // The Landclass for this particular fragment. This can be used to // index into the atlas textures. - int lc = int(texture2D(landclass, gl_TexCoord[0].st).g * 255.0 + 0.5); + int lc = int(texture2D(landclass, gl_TexCoord[0].st).r * 255.0 + 0.5); // Color Mode is always AMBIENT_AND_DIFFUSE, which means // using a base colour of white for ambient/diffuse, // rather than the material color from ambientArray/diffuseArray. mat_ambient = vec4(1.0,1.0,1.0,1.0); mat_diffuse = vec4(1.0,1.0,1.0,1.0); - mat_specular = specularArray[lc]; - mat_shininess = dimensionsArray[lc].z; + mat_specular = fg_specularArray[lc]; + mat_shininess = fg_dimensionsArray[lc].z; // Different textures have different have different dimensions. - vec2 atlas_dimensions = dimensionsArray[lc].st; - vec2 atlas_scale = vec2(tile_width / atlas_dimensions.s, tile_height / atlas_dimensions.t ); + vec2 atlas_dimensions = fg_dimensionsArray[lc].st; + vec2 atlas_scale = vec2(fg_tileWidth / atlas_dimensions.s, fg_tileHeight / atlas_dimensions.t ); - texel = texture(atlas, vec3(atlas_scale * gl_TexCoord[0].st, lc)); + texel = texture(atlas, vec3(atlas_scale * gl_TexCoord[0].st, int(texture2D(landclass, gl_TexCoord[0].st).g * 255.0 + 0.5))); } vec4 color = mat_ambient * (gl_LightModel.ambient + gl_LightSource[0].ambient);