1
0
Fork 0
fgdata/Shaders/ws30-ALS-ultra.vert

431 lines
14 KiB
GLSL
Raw Normal View History

WS30: landclass and texture lookups in fragment shader commit e131ffaca7b2c934474f0e447b5852cb4c7c8d4a Author: vs <vs2009@mail.com> Date: Fri Oct 15 22:19:42 2021 +1000 WS30: landclass and texture lookups in fragment shader: Changelog: - Testing: Procedural random landclass function, get_random_landclass(). 1). Avoids a texture lookup for profiling. 2). Creates squares of configurable size with controllable random landclass ranges - to test landclass transition algorithms and quickly profile lots of landclasses in view. It's also possible to put pressure on GPU memory even with 1 lookup of ground textures per fragment, by reducing size to <20m and viewing from altitude. - Add ALS ultra technique as no 5, move existing ALS technique to no. 6. Add WS30-ALS-ultra frag & vert in preparation for eventual ALS ultra port. Change comments/variables to match using a texture array instead of atlas. Sampler name: atlas -> textureArray. - Testing/optimisation of de-tiling: WS30-ALS.frag: reorder perlin detiling to make noise source easier to switch. WS30-ALS-ultra.frag: Create alternative to perlin noise used for reducing tiling that avoids a texture lookup - to profile and optimise. This is commented out. The performance difference in the final version depends on memory pressure versus arithmetic load of the full shader. It varies by GPU and what's in view. In future, once a full ALS port is done, maybe it'll be more efficient to run a higher quality de-tiling algorithm all the time to avoid branching overhead due to effects like agriculture which need more de-tiling. De-tiling code in shaders should /eventually/ match CPU-side de-tiling of texture masks used for object and vegetation placement. De-tiling code in GPUs might be subject to precision and numerical artifacts, and if so maybe the texture lookup version would work better. The same applies to noise used for rendering WS3 water waves and collision queries. One option is to use exactly the same glsl code, with a C++ header to convert glsl syntax e.g. https://github.com/g-truc/glm .
2021-10-21 20:31:03 +00:00
// WS30 VERTEX SHADER
// -*-C++-*-
#version 120
// Shader that uses OpenGL state values to do per-pixel lighting
//
// The only light used is gl_LightSource[0], which is assumed to be
// directional.
//
// Colors are not assigned in this shader, as they will come from
// the landclass lookup in the fragment shader.
// Haze part added by Thorsten Renk, Oct. 2011
#define MODE_OFF 0
#define MODE_DIFFUSE 1
#define MODE_AMBIENT_AND_DIFFUSE 2
// 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
// bugs with gl_FrontFacing in the fragment shader.
WS30 : terrain shaders from vs Squashed commit of the following: commit e7c89ffb600d1bf5cee2936b7dbff31089452745 Author: vs <vs2009@mail.com> Date: Fri Nov 5 23:44:35 2021 +1000 WS30 shaders: - WS30-ALS and WS30-ALS-ultra fargment and vertex shaders: Fix NDotL being used before it is initialised. Rename varying diffuse_term from WS2 terrain shaders to light_diffuse_comp as the full diffuse term is not calculated until the fragment shader. - WS30-ALS-ultra.frag: Enable haze and lighting by default. commit 9b55ad051a8d7f3568dfdcd6890655942999e8d0 Author: vs <vs2009@mail.com> Date: Wed Nov 3 22:50:29 2021 +1000 WS30 terrain shaders: ws30-ALS-ultra.frag - For power users looking to profile transitions on different GPUs: The test phase toggles and settings for different transition options are available at the start of ws30-ALS-ultra.frag, along with explanations, and how to get accurate profile results on different GPUs. Just need to change a few numbers, save, and debug menu > configure dev extensions > reload shaders to activate. - Note: at a minimum, small scale transitions to remove the 'squareness' due to the landclass texture need to be used even on old GPUs. - All transition options are off by default. ws30-ALS-ultra.frag is active when the terrain quality slider is set to Ultra. Start by turning one of small or large scale transitions. - Texture mixing for small and large scale transitions don't work together, to reduce texture lookups. Turn one off when using the other. - Landclasses with contrasting colours make transition issues more visble. The driver control panel texture filtering settings reduces issues with seams at landclass borders. - ws30-ALS.frag is left untouched in this commit, for comparison and reviewing. ws30-ALS.frag is active when terrain quality slider is set High to Low. Changes: - Implement large scale transitions and small scale de-pixelisation of landclasses by searching the landclass texture. Several options and quality levels are available for profiling on different GPUs. - There are fixes for multiple issues dealing with texture rendering. Changelog: 1.0 - Small-scale transitions: -- a) Remove squareness due to landclass texture by growing neighbour landclasses onto others depending on a growth priority. This feature uses 2 landclass texture lookups, 1 noise lookup, and only 1 ground texture lookup per point. For now the growth priority is simply the landclass id number. If this approach is used, growth priority would be a materials parameter. A way to set default growth priority by landclass via an xml file would be needed. There is flickering noise at long ranges due to small scale detail in the noise function used for growing landclasses. Partial derivative are used to turn off the feature, but turning off the feature too quickly still shows some square ness in distant landclasses. -- b) Reduce squareness due to landclass texture by mixing base textures of neighbouring landclasses. This is not perfect, as perfectly square shapes turn into perfectly square shapes with perfectly smudged edges. This uses 2 landclass texture lookups, and 2-3 ground texture lookups. -- c) - a) and b) can be run at once. This option will also fade the growths gradually with distance. This uses 2 landclass texture lookups, 1 noise lookup, and 2-3 ground texture lookups. 2.0 - Large scale transitions: -- a) Implemented by searching the landclass texture. The search pattern is current landlcass for the fragment at the center, and n search points in four directions along the s and t axes forming a cross. The search directions are configurable in the code, adn a minimum of 3 directions are needed. The step size is configurable. The fewer the steps, the larger the bands formed in the transitions. There are 1+4*n landclass lookups per n search points. e.g. 1 search point: 5 lookups, 4 search points:17 lookups, 10 search points: 41 lookups. -- b) An option to dither the transition bands by adding mixing noise is availble. This breaks up the visual impact of bands. -- c) There is some functionality to grow neighbours on a large scale. No growth priority is used - bothe neighbours will lose definition. A more advanced implementation can use several material parameters to define the nature of the transition: some transitions are very sharp in nature like with agriculture, other transitions can be very gradual, some transitions are patchy. Materials can have competing parameters, to determine which neighbour grows or has a shorter transition on one side. These parameters will need a way of specifying defaults by landclass. 3.0 - Fixes -- a) - Fix seams at landclass borders. These are caused by different ground textures being stretched by different amounts. At the border, an incorrect mip-map level is looked up, causing a colour disontinuity in addition to the difference between landclasses. The reason the mip-map LoD is incorrect is because GPUs use 4 neighbouring pixels to figure out how fast texture coordinates change with respect to screenspace x and y (i.e. partial derivaitves), and use that information to pick a mip-map level. At a landlcass border, this calculation is incorrect. -- b) Fix seams at borders caused by the current detiling function. This is due to the detiling function changing the amount textures are stretched, as well as messing with coordinates. -- c) The solution to a) and b) is to use textureGrad() to lookup textures. It allows specifying partial derivatives. The partial derivatives for the normal texture coordinates are obtained by built-in funcions, and these need to be multiplied by each stretching factor, including different stretching inside conditionals. All future texture lookups that use custom coordinate scaling/manipulation need to use textureGrad. This fixes various signs of incorrect mip-map lod with distance and view angle (textures look stable/solid). -- d) Fix ground textures being stretched out of proportion in the detiling function. This is caused by tile dimensions not being unequal and texture stretching.
2021-11-05 19:59:32 +00:00
varying vec4 light_diffuse_comp;
WS30: landclass and texture lookups in fragment shader commit e131ffaca7b2c934474f0e447b5852cb4c7c8d4a Author: vs <vs2009@mail.com> Date: Fri Oct 15 22:19:42 2021 +1000 WS30: landclass and texture lookups in fragment shader: Changelog: - Testing: Procedural random landclass function, get_random_landclass(). 1). Avoids a texture lookup for profiling. 2). Creates squares of configurable size with controllable random landclass ranges - to test landclass transition algorithms and quickly profile lots of landclasses in view. It's also possible to put pressure on GPU memory even with 1 lookup of ground textures per fragment, by reducing size to <20m and viewing from altitude. - Add ALS ultra technique as no 5, move existing ALS technique to no. 6. Add WS30-ALS-ultra frag & vert in preparation for eventual ALS ultra port. Change comments/variables to match using a texture array instead of atlas. Sampler name: atlas -> textureArray. - Testing/optimisation of de-tiling: WS30-ALS.frag: reorder perlin detiling to make noise source easier to switch. WS30-ALS-ultra.frag: Create alternative to perlin noise used for reducing tiling that avoids a texture lookup - to profile and optimise. This is commented out. The performance difference in the final version depends on memory pressure versus arithmetic load of the full shader. It varies by GPU and what's in view. In future, once a full ALS port is done, maybe it'll be more efficient to run a higher quality de-tiling algorithm all the time to avoid branching overhead due to effects like agriculture which need more de-tiling. De-tiling code in shaders should /eventually/ match CPU-side de-tiling of texture masks used for object and vegetation placement. De-tiling code in GPUs might be subject to precision and numerical artifacts, and if so maybe the texture lookup version would work better. The same applies to noise used for rendering WS3 water waves and collision queries. One option is to use exactly the same glsl code, with a C++ header to convert glsl syntax e.g. https://github.com/g-truc/glm .
2021-10-21 20:31:03 +00:00
varying vec3 normal;
varying vec3 relPos;
WS30: MR #267: Improved texture lookups from VS Squashed commit of the following: commit 115511888c20c53670eba17a82c81c9af99d7302 Author: vs <vs2009@mail.com> Date: Mon Dec 6 18:52:06 2021 +1000 WS30 effects and shaders: Changelog: ws30-ALS-ultra.frag: - Ground textures lookups use their own coordinates separate from the landclass texture lookup. - Partial derivatives dFdx and Dfdy are packed together in a vec4, so simple multiplication to scale can be done in 1 instruction. dFdx = s and t components. dFdy = p and q components. These must be scaled properly for ground texture access as ground texture stretching and detiling of tex coords mean textures are scaled differently. - Added calculation of partial derivatives for texture coordinates used by the 5 non- base textures. dFdx() and dFdy() were called for nontrivial texture coordinate manipulation. - New control randomise_texture_lookups added at top of ws30-ALS-ultra.frag, in the development tools section. Setting this to 1 will do a stress test of ground texture array lookups. A fast random number generation function is used to assign each landclass 4 random textures from the ground texture array - this is done by . Performance will not be as bad in the full ALS port as some texture slots will better caching in memory - e.g. have 1 or a few variants. - Possible optimisation: use a 2nd or 3rd texture array for some of the non-base texture slots that typically have 256, 512, or 1024 textures. The resolutions of these arrays should change based on the largest loaded texture size in the active regional definitions - this will allow taking full advantage of smaller texture sizes in some areas. The disadvantage is some texture duplication with more slots. - Possible optimisation: offer the option to shrink textures by 50% or 25% - for texture slots that use large textures like base or mix slots. - Very temporary - reduce procedural normal map features with photoscenery active without breaking profiling, as the inputs to shaders are effect defaults or placeholder (by request on ML). ---- ws30-ALS-ultra.vert: - Start of conversion of geocentic world space xyz into lat/lon coords used for ground texture lookups. Currently commented out as it's unknown what model space coords are in (not geocentric it seems). ws20-ALS-landclass-search-functions.frag: - Add control for changing the ground texture array lookup function for debugging in case old compilers/GPUs have issues. tex_lookup_type: 0: normal( textureGrad(), 1: textureLod (manual Lod calculation), 2: texture() with no partial derivative adjustment. - New get6_random_integers() will extract 6 limited random values from the full precision of a 32 bit random value. - Old landclass_texel_size_m references are removed since textureSize() is used. There are no 'const in float' arguments that may cause issues on AMD compilers. ---- WS30-overlay effect (Inactive): - ws30-overlay.eff (derived from terrain-overlay.eff). Technique no "4" is used for two passes. The 1st pass is a copy of the ALS ultra pass (technique no "5") from ws30.eff. The 2nd pass is the same as terrain-overlay.eff. The 2nd pass uses terrain- overlay.frag from WS2. - grass-ALS.vert copied to ws30-ovelay-ALS.vert. To do: needs texture coords that don't change with tiles. - terrain-overlay-ALS.geom copied to ws30-overlay-ALS.geom. To do: uses gl_PositionIn [i].xy for position in the horizontal plane - assumes z is vertical. Tile model space doesn't seem to match this. - WS3 doesn't seem to have a way of switching references to terrain-overlay.eff (which inherits from terrain-default.eff) to the new ws3-overlay.eff (which needs to inherit from ws30.eff). The ws3-overlay.eff included /might/ just work without any other changes: the first pass is the WS3 als ultra settings pass, and the second overlay pass is unchanged from WS2 (the same terrain overlay shaders should probably work apart from texcoords and rawpos not being correct). - Materials/base/materials-base.xml: ws30Road material: uncomment line declaring terrain-default as the effect. The target effect for ws30 roads is road-*.eff and it's added to ws30Road and ws30Freeway but commented out as it's not working currently. - Misc: large scale transitions are turned on in ws30-ALS-landclass-search-functions.frag by default. Grow landclass borders with large scale transitions is now on by default. ---- Changes after the multi-texture support commit: ws30-ALS-ultra.vert - Added documentation: WS30 model space and z up space - for future people working on WS30, and people looking through shaders to rule out possibilities e.g. when fixing bugs, or interpreting visual bug reports. ws30-ALS-landclass-search-functions.frag: - For now, lookup_ground_texture_array() also looks up the relevant texture's index based on an integer. - Add get_mixed_texel() - looks up texel for this fragment and any neighbors before mixing. Moves currently shared mixing code out of 3 fragment shaders. Misc: changed indentation from mixed tabs/spaces to spaces in ws30-ALS-ultra frag and vert. The indentation can be changed again when the porting is complete. ws30-ALS vert/frag and ws30-ALS-detailed vert/frag: - Add varying for ground texture coordiante, currently set to gl_TexCoord[0]. Apply texture stretching dimensions in fragment shaders. - Misc: varying rawPos is set to vec2 for now, as relPos.z+eye_alt might be faster. Misc: keep WS2 mixing logic for now , including turning off mixing via the alpha channel of the textures ---- Changes after sending material parameters in uniform arrays commit: - Materials parameter for rock_strata is cast into an int so rock_strata==1 should work. Misc: Left over uniform for rock strata cleaned up. - ws30-ALS-ultra.frag and ws30-ALS-detailed.frag: Add missing mat_shininess for photoscenery case .
2022-01-03 15:43:29 +00:00
varying vec2 ground_tex_coord;
varying vec2 rawPos;
WS30 shaders: Add WS3 detailed technique using the "6" slot. Port the ALS haze, lighting, and math parts of the detailed and ultra shaders. The texture lookups are left out. Shader selection based on terrain quality setting: - Ultra - ws30-ALS-ultra frag/vert. - High and Medium - ws30-ALS-detailed frag/vert. The shaders switch code paths based on quality level uniform. - Low - ws30-ALS frag/vert. Changelog: ws30-ALS vertex shaders: - Ambient colour material colour doesn't seem to be used in the vertex shader, and isn't sent to fragment shaders currently. Regional materials only define non-default ambient colour of vec4(0.0) for water, ocean etc. Otherwise the default value of vec4(0.2, 0.2, 0.2, 1.0) is used. ws30-ALS.frag: - Set alpha of color to diffuse_term.a, to be consistent with WS2 implementation. ws30-ALS-ultra.frag and ws30-ALS-detailed.frag - World pos is assigned a value to allow noise functions to compile. - Swatch_size is temporarily set to 2000m instead of the xsize texture dimension to allow noise math to run while landclass search and texture arrays are being looked up. Swatch_size is used to adjust the wavelength of multiple overlay mixing noise wavelengths based on how far the textures are stretched (WiP WS2 feature). There are some noise calculations that could run while the first landclass lookup happens. If this is not enough, the selection of calculated noise wavelengths to add could change based on how far the textures are stretched, instead of changing the wavelengths at calculation time. - Move photoscenery technique no "4" after technique no "7" without changing the index (in case the low index is needed for photoscenery). This makes viewing a diff with the WS2 effect easier. Performance: Currently there's only 1 ground texture lookup and landclass transitions for that texture. The ultra shader looks up 5 more textures. Probably transitions for 1 more texture need to be supported, as often a base and overlay texture are mixed contributing heavily to visible colour. The math overhead is mostly present, except for noise math being better hidden than in the eventual version. Some of the texture array lookups in the full version may be hidden by the math - depending on GPU memory handling compared to calculation speed.
2021-11-09 14:25:09 +00:00
varying vec3 worldPos;
varying vec3 ecViewdir;
varying vec2 grad_dir;
WS30: landclass and texture lookups in fragment shader commit e131ffaca7b2c934474f0e447b5852cb4c7c8d4a Author: vs <vs2009@mail.com> Date: Fri Oct 15 22:19:42 2021 +1000 WS30: landclass and texture lookups in fragment shader: Changelog: - Testing: Procedural random landclass function, get_random_landclass(). 1). Avoids a texture lookup for profiling. 2). Creates squares of configurable size with controllable random landclass ranges - to test landclass transition algorithms and quickly profile lots of landclasses in view. It's also possible to put pressure on GPU memory even with 1 lookup of ground textures per fragment, by reducing size to <20m and viewing from altitude. - Add ALS ultra technique as no 5, move existing ALS technique to no. 6. Add WS30-ALS-ultra frag & vert in preparation for eventual ALS ultra port. Change comments/variables to match using a texture array instead of atlas. Sampler name: atlas -> textureArray. - Testing/optimisation of de-tiling: WS30-ALS.frag: reorder perlin detiling to make noise source easier to switch. WS30-ALS-ultra.frag: Create alternative to perlin noise used for reducing tiling that avoids a texture lookup - to profile and optimise. This is commented out. The performance difference in the final version depends on memory pressure versus arithmetic load of the full shader. It varies by GPU and what's in view. In future, once a full ALS port is done, maybe it'll be more efficient to run a higher quality de-tiling algorithm all the time to avoid branching overhead due to effects like agriculture which need more de-tiling. De-tiling code in shaders should /eventually/ match CPU-side de-tiling of texture masks used for object and vegetation placement. De-tiling code in GPUs might be subject to precision and numerical artifacts, and if so maybe the texture lookup version would work better. The same applies to noise used for rendering WS3 water waves and collision queries. One option is to use exactly the same glsl code, with a C++ header to convert glsl syntax e.g. https://github.com/g-truc/glm .
2021-10-21 20:31:03 +00:00
varying vec4 ecPosition;
varying vec3 vertVec;
WS30: landclass and texture lookups in fragment shader commit e131ffaca7b2c934474f0e447b5852cb4c7c8d4a Author: vs <vs2009@mail.com> Date: Fri Oct 15 22:19:42 2021 +1000 WS30: landclass and texture lookups in fragment shader: Changelog: - Testing: Procedural random landclass function, get_random_landclass(). 1). Avoids a texture lookup for profiling. 2). Creates squares of configurable size with controllable random landclass ranges - to test landclass transition algorithms and quickly profile lots of landclasses in view. It's also possible to put pressure on GPU memory even with 1 lookup of ground textures per fragment, by reducing size to <20m and viewing from altitude. - Add ALS ultra technique as no 5, move existing ALS technique to no. 6. Add WS30-ALS-ultra frag & vert in preparation for eventual ALS ultra port. Change comments/variables to match using a texture array instead of atlas. Sampler name: atlas -> textureArray. - Testing/optimisation of de-tiling: WS30-ALS.frag: reorder perlin detiling to make noise source easier to switch. WS30-ALS-ultra.frag: Create alternative to perlin noise used for reducing tiling that avoids a texture lookup - to profile and optimise. This is commented out. The performance difference in the final version depends on memory pressure versus arithmetic load of the full shader. It varies by GPU and what's in view. In future, once a full ALS port is done, maybe it'll be more efficient to run a higher quality de-tiling algorithm all the time to avoid branching overhead due to effects like agriculture which need more de-tiling. De-tiling code in shaders should /eventually/ match CPU-side de-tiling of texture masks used for object and vegetation placement. De-tiling code in GPUs might be subject to precision and numerical artifacts, and if so maybe the texture lookup version would work better. The same applies to noise used for rendering WS3 water waves and collision queries. One option is to use exactly the same glsl code, with a C++ header to convert glsl syntax e.g. https://github.com/g-truc/glm .
2021-10-21 20:31:03 +00:00
// For water calculations
varying float earthShade;
varying vec3 lightdir;
varying vec4 waterTex1;
varying vec4 waterTex2;
varying vec4 waterTex4;
varying vec3 specular_light;
uniform float osg_SimulationTime;
uniform float WindN;
uniform float WindE;
WS30 shaders: Add WS3 detailed technique using the "6" slot. Port the ALS haze, lighting, and math parts of the detailed and ultra shaders. The texture lookups are left out. Shader selection based on terrain quality setting: - Ultra - ws30-ALS-ultra frag/vert. - High and Medium - ws30-ALS-detailed frag/vert. The shaders switch code paths based on quality level uniform. - Low - ws30-ALS frag/vert. Changelog: ws30-ALS vertex shaders: - Ambient colour material colour doesn't seem to be used in the vertex shader, and isn't sent to fragment shaders currently. Regional materials only define non-default ambient colour of vec4(0.0) for water, ocean etc. Otherwise the default value of vec4(0.2, 0.2, 0.2, 1.0) is used. ws30-ALS.frag: - Set alpha of color to diffuse_term.a, to be consistent with WS2 implementation. ws30-ALS-ultra.frag and ws30-ALS-detailed.frag - World pos is assigned a value to allow noise functions to compile. - Swatch_size is temporarily set to 2000m instead of the xsize texture dimension to allow noise math to run while landclass search and texture arrays are being looked up. Swatch_size is used to adjust the wavelength of multiple overlay mixing noise wavelengths based on how far the textures are stretched (WiP WS2 feature). There are some noise calculations that could run while the first landclass lookup happens. If this is not enough, the selection of calculated noise wavelengths to add could change based on how far the textures are stretched, instead of changing the wavelengths at calculation time. - Move photoscenery technique no "4" after technique no "7" without changing the index (in case the low index is needed for photoscenery). This makes viewing a diff with the WS2 effect easier. Performance: Currently there's only 1 ground texture lookup and landclass transitions for that texture. The ultra shader looks up 5 more textures. Probably transitions for 1 more texture need to be supported, as often a base and overlay texture are mixed contributing heavily to visible colour. The math overhead is mostly present, except for noise math being better hidden than in the eventual version. Some of the texture array lookups in the full version may be hidden by the math - depending on GPU memory handling compared to calculation speed.
2021-11-09 14:25:09 +00:00
// Sent packed into alpha channels
//varying float yprime_alt;
WS30: landclass and texture lookups in fragment shader commit e131ffaca7b2c934474f0e447b5852cb4c7c8d4a Author: vs <vs2009@mail.com> Date: Fri Oct 15 22:19:42 2021 +1000 WS30: landclass and texture lookups in fragment shader: Changelog: - Testing: Procedural random landclass function, get_random_landclass(). 1). Avoids a texture lookup for profiling. 2). Creates squares of configurable size with controllable random landclass ranges - to test landclass transition algorithms and quickly profile lots of landclasses in view. It's also possible to put pressure on GPU memory even with 1 lookup of ground textures per fragment, by reducing size to <20m and viewing from altitude. - Add ALS ultra technique as no 5, move existing ALS technique to no. 6. Add WS30-ALS-ultra frag & vert in preparation for eventual ALS ultra port. Change comments/variables to match using a texture array instead of atlas. Sampler name: atlas -> textureArray. - Testing/optimisation of de-tiling: WS30-ALS.frag: reorder perlin detiling to make noise source easier to switch. WS30-ALS-ultra.frag: Create alternative to perlin noise used for reducing tiling that avoids a texture lookup - to profile and optimise. This is commented out. The performance difference in the final version depends on memory pressure versus arithmetic load of the full shader. It varies by GPU and what's in view. In future, once a full ALS port is done, maybe it'll be more efficient to run a higher quality de-tiling algorithm all the time to avoid branching overhead due to effects like agriculture which need more de-tiling. De-tiling code in shaders should /eventually/ match CPU-side de-tiling of texture masks used for object and vegetation placement. De-tiling code in GPUs might be subject to precision and numerical artifacts, and if so maybe the texture lookup version would work better. The same applies to noise used for rendering WS3 water waves and collision queries. One option is to use exactly the same glsl code, with a C++ header to convert glsl syntax e.g. https://github.com/g-truc/glm .
2021-10-21 20:31:03 +00:00
varying float mie_angle;
WS30 shaders: Add WS3 detailed technique using the "6" slot. Port the ALS haze, lighting, and math parts of the detailed and ultra shaders. The texture lookups are left out. Shader selection based on terrain quality setting: - Ultra - ws30-ALS-ultra frag/vert. - High and Medium - ws30-ALS-detailed frag/vert. The shaders switch code paths based on quality level uniform. - Low - ws30-ALS frag/vert. Changelog: ws30-ALS vertex shaders: - Ambient colour material colour doesn't seem to be used in the vertex shader, and isn't sent to fragment shaders currently. Regional materials only define non-default ambient colour of vec4(0.0) for water, ocean etc. Otherwise the default value of vec4(0.2, 0.2, 0.2, 1.0) is used. ws30-ALS.frag: - Set alpha of color to diffuse_term.a, to be consistent with WS2 implementation. ws30-ALS-ultra.frag and ws30-ALS-detailed.frag - World pos is assigned a value to allow noise functions to compile. - Swatch_size is temporarily set to 2000m instead of the xsize texture dimension to allow noise math to run while landclass search and texture arrays are being looked up. Swatch_size is used to adjust the wavelength of multiple overlay mixing noise wavelengths based on how far the textures are stretched (WiP WS2 feature). There are some noise calculations that could run while the first landclass lookup happens. If this is not enough, the selection of calculated noise wavelengths to add could change based on how far the textures are stretched, instead of changing the wavelengths at calculation time. - Move photoscenery technique no "4" after technique no "7" without changing the index (in case the low index is needed for photoscenery). This makes viewing a diff with the WS2 effect easier. Performance: Currently there's only 1 ground texture lookup and landclass transitions for that texture. The ultra shader looks up 5 more textures. Probably transitions for 1 more texture need to be supported, as often a base and overlay texture are mixed contributing heavily to visible colour. The math overhead is mostly present, except for noise math being better hidden than in the eventual version. Some of the texture array lookups in the full version may be hidden by the math - depending on GPU memory handling compared to calculation speed.
2021-11-09 14:25:09 +00:00
varying float steepness;
WS30: landclass and texture lookups in fragment shader commit e131ffaca7b2c934474f0e447b5852cb4c7c8d4a Author: vs <vs2009@mail.com> Date: Fri Oct 15 22:19:42 2021 +1000 WS30: landclass and texture lookups in fragment shader: Changelog: - Testing: Procedural random landclass function, get_random_landclass(). 1). Avoids a texture lookup for profiling. 2). Creates squares of configurable size with controllable random landclass ranges - to test landclass transition algorithms and quickly profile lots of landclasses in view. It's also possible to put pressure on GPU memory even with 1 lookup of ground textures per fragment, by reducing size to <20m and viewing from altitude. - Add ALS ultra technique as no 5, move existing ALS technique to no. 6. Add WS30-ALS-ultra frag & vert in preparation for eventual ALS ultra port. Change comments/variables to match using a texture array instead of atlas. Sampler name: atlas -> textureArray. - Testing/optimisation of de-tiling: WS30-ALS.frag: reorder perlin detiling to make noise source easier to switch. WS30-ALS-ultra.frag: Create alternative to perlin noise used for reducing tiling that avoids a texture lookup - to profile and optimise. This is commented out. The performance difference in the final version depends on memory pressure versus arithmetic load of the full shader. It varies by GPU and what's in view. In future, once a full ALS port is done, maybe it'll be more efficient to run a higher quality de-tiling algorithm all the time to avoid branching overhead due to effects like agriculture which need more de-tiling. De-tiling code in shaders should /eventually/ match CPU-side de-tiling of texture masks used for object and vegetation placement. De-tiling code in GPUs might be subject to precision and numerical artifacts, and if so maybe the texture lookup version would work better. The same applies to noise used for rendering WS3 water waves and collision queries. One option is to use exactly the same glsl code, with a C++ header to convert glsl syntax e.g. https://github.com/g-truc/glm .
2021-10-21 20:31:03 +00:00
uniform int colorMode;
WS30 shaders: Add WS3 detailed technique using the "6" slot. Port the ALS haze, lighting, and math parts of the detailed and ultra shaders. The texture lookups are left out. Shader selection based on terrain quality setting: - Ultra - ws30-ALS-ultra frag/vert. - High and Medium - ws30-ALS-detailed frag/vert. The shaders switch code paths based on quality level uniform. - Low - ws30-ALS frag/vert. Changelog: ws30-ALS vertex shaders: - Ambient colour material colour doesn't seem to be used in the vertex shader, and isn't sent to fragment shaders currently. Regional materials only define non-default ambient colour of vec4(0.0) for water, ocean etc. Otherwise the default value of vec4(0.2, 0.2, 0.2, 1.0) is used. ws30-ALS.frag: - Set alpha of color to diffuse_term.a, to be consistent with WS2 implementation. ws30-ALS-ultra.frag and ws30-ALS-detailed.frag - World pos is assigned a value to allow noise functions to compile. - Swatch_size is temporarily set to 2000m instead of the xsize texture dimension to allow noise math to run while landclass search and texture arrays are being looked up. Swatch_size is used to adjust the wavelength of multiple overlay mixing noise wavelengths based on how far the textures are stretched (WiP WS2 feature). There are some noise calculations that could run while the first landclass lookup happens. If this is not enough, the selection of calculated noise wavelengths to add could change based on how far the textures are stretched, instead of changing the wavelengths at calculation time. - Move photoscenery technique no "4" after technique no "7" without changing the index (in case the low index is needed for photoscenery). This makes viewing a diff with the WS2 effect easier. Performance: Currently there's only 1 ground texture lookup and landclass transitions for that texture. The ultra shader looks up 5 more textures. Probably transitions for 1 more texture need to be supported, as often a base and overlay texture are mixed contributing heavily to visible colour. The math overhead is mostly present, except for noise math being better hidden than in the eventual version. Some of the texture array lookups in the full version may be hidden by the math - depending on GPU memory handling compared to calculation speed.
2021-11-09 14:25:09 +00:00
uniform bool raise_vertex;
WS30: landclass and texture lookups in fragment shader commit e131ffaca7b2c934474f0e447b5852cb4c7c8d4a Author: vs <vs2009@mail.com> Date: Fri Oct 15 22:19:42 2021 +1000 WS30: landclass and texture lookups in fragment shader: Changelog: - Testing: Procedural random landclass function, get_random_landclass(). 1). Avoids a texture lookup for profiling. 2). Creates squares of configurable size with controllable random landclass ranges - to test landclass transition algorithms and quickly profile lots of landclasses in view. It's also possible to put pressure on GPU memory even with 1 lookup of ground textures per fragment, by reducing size to <20m and viewing from altitude. - Add ALS ultra technique as no 5, move existing ALS technique to no. 6. Add WS30-ALS-ultra frag & vert in preparation for eventual ALS ultra port. Change comments/variables to match using a texture array instead of atlas. Sampler name: atlas -> textureArray. - Testing/optimisation of de-tiling: WS30-ALS.frag: reorder perlin detiling to make noise source easier to switch. WS30-ALS-ultra.frag: Create alternative to perlin noise used for reducing tiling that avoids a texture lookup - to profile and optimise. This is commented out. The performance difference in the final version depends on memory pressure versus arithmetic load of the full shader. It varies by GPU and what's in view. In future, once a full ALS port is done, maybe it'll be more efficient to run a higher quality de-tiling algorithm all the time to avoid branching overhead due to effects like agriculture which need more de-tiling. De-tiling code in shaders should /eventually/ match CPU-side de-tiling of texture masks used for object and vegetation placement. De-tiling code in GPUs might be subject to precision and numerical artifacts, and if so maybe the texture lookup version would work better. The same applies to noise used for rendering WS3 water waves and collision queries. One option is to use exactly the same glsl code, with a C++ header to convert glsl syntax e.g. https://github.com/g-truc/glm .
2021-10-21 20:31:03 +00:00
uniform float hazeLayerAltitude;
uniform float terminator;
uniform float terrain_alt;
uniform float avisibility;
uniform float visibility;
uniform float overcast;
uniform float ground_scattering;
WS30 shaders: Add WS3 detailed technique using the "6" slot. Port the ALS haze, lighting, and math parts of the detailed and ultra shaders. The texture lookups are left out. Shader selection based on terrain quality setting: - Ultra - ws30-ALS-ultra frag/vert. - High and Medium - ws30-ALS-detailed frag/vert. The shaders switch code paths based on quality level uniform. - Low - ws30-ALS frag/vert. Changelog: ws30-ALS vertex shaders: - Ambient colour material colour doesn't seem to be used in the vertex shader, and isn't sent to fragment shaders currently. Regional materials only define non-default ambient colour of vec4(0.0) for water, ocean etc. Otherwise the default value of vec4(0.2, 0.2, 0.2, 1.0) is used. ws30-ALS.frag: - Set alpha of color to diffuse_term.a, to be consistent with WS2 implementation. ws30-ALS-ultra.frag and ws30-ALS-detailed.frag - World pos is assigned a value to allow noise functions to compile. - Swatch_size is temporarily set to 2000m instead of the xsize texture dimension to allow noise math to run while landclass search and texture arrays are being looked up. Swatch_size is used to adjust the wavelength of multiple overlay mixing noise wavelengths based on how far the textures are stretched (WiP WS2 feature). There are some noise calculations that could run while the first landclass lookup happens. If this is not enough, the selection of calculated noise wavelengths to add could change based on how far the textures are stretched, instead of changing the wavelengths at calculation time. - Move photoscenery technique no "4" after technique no "7" without changing the index (in case the low index is needed for photoscenery). This makes viewing a diff with the WS2 effect easier. Performance: Currently there's only 1 ground texture lookup and landclass transitions for that texture. The ultra shader looks up 5 more textures. Probably transitions for 1 more texture need to be supported, as often a base and overlay texture are mixed contributing heavily to visible colour. The math overhead is mostly present, except for noise math being better hidden than in the eventual version. Some of the texture array lookups in the full version may be hidden by the math - depending on GPU memory handling compared to calculation speed.
2021-11-09 14:25:09 +00:00
uniform float eye_alt;
WS30: landclass and texture lookups in fragment shader commit e131ffaca7b2c934474f0e447b5852cb4c7c8d4a Author: vs <vs2009@mail.com> Date: Fri Oct 15 22:19:42 2021 +1000 WS30: landclass and texture lookups in fragment shader: Changelog: - Testing: Procedural random landclass function, get_random_landclass(). 1). Avoids a texture lookup for profiling. 2). Creates squares of configurable size with controllable random landclass ranges - to test landclass transition algorithms and quickly profile lots of landclasses in view. It's also possible to put pressure on GPU memory even with 1 lookup of ground textures per fragment, by reducing size to <20m and viewing from altitude. - Add ALS ultra technique as no 5, move existing ALS technique to no. 6. Add WS30-ALS-ultra frag & vert in preparation for eventual ALS ultra port. Change comments/variables to match using a texture array instead of atlas. Sampler name: atlas -> textureArray. - Testing/optimisation of de-tiling: WS30-ALS.frag: reorder perlin detiling to make noise source easier to switch. WS30-ALS-ultra.frag: Create alternative to perlin noise used for reducing tiling that avoids a texture lookup - to profile and optimise. This is commented out. The performance difference in the final version depends on memory pressure versus arithmetic load of the full shader. It varies by GPU and what's in view. In future, once a full ALS port is done, maybe it'll be more efficient to run a higher quality de-tiling algorithm all the time to avoid branching overhead due to effects like agriculture which need more de-tiling. De-tiling code in shaders should /eventually/ match CPU-side de-tiling of texture masks used for object and vegetation placement. De-tiling code in GPUs might be subject to precision and numerical artifacts, and if so maybe the texture lookup version would work better. The same applies to noise used for rendering WS3 water waves and collision queries. One option is to use exactly the same glsl code, with a C++ header to convert glsl syntax e.g. https://github.com/g-truc/glm .
2021-10-21 20:31:03 +00:00
uniform float moonlight;
WS30 shaders: Add WS3 detailed technique using the "6" slot. Port the ALS haze, lighting, and math parts of the detailed and ultra shaders. The texture lookups are left out. Shader selection based on terrain quality setting: - Ultra - ws30-ALS-ultra frag/vert. - High and Medium - ws30-ALS-detailed frag/vert. The shaders switch code paths based on quality level uniform. - Low - ws30-ALS frag/vert. Changelog: ws30-ALS vertex shaders: - Ambient colour material colour doesn't seem to be used in the vertex shader, and isn't sent to fragment shaders currently. Regional materials only define non-default ambient colour of vec4(0.0) for water, ocean etc. Otherwise the default value of vec4(0.2, 0.2, 0.2, 1.0) is used. ws30-ALS.frag: - Set alpha of color to diffuse_term.a, to be consistent with WS2 implementation. ws30-ALS-ultra.frag and ws30-ALS-detailed.frag - World pos is assigned a value to allow noise functions to compile. - Swatch_size is temporarily set to 2000m instead of the xsize texture dimension to allow noise math to run while landclass search and texture arrays are being looked up. Swatch_size is used to adjust the wavelength of multiple overlay mixing noise wavelengths based on how far the textures are stretched (WiP WS2 feature). There are some noise calculations that could run while the first landclass lookup happens. If this is not enough, the selection of calculated noise wavelengths to add could change based on how far the textures are stretched, instead of changing the wavelengths at calculation time. - Move photoscenery technique no "4" after technique no "7" without changing the index (in case the low index is needed for photoscenery). This makes viewing a diff with the WS2 effect easier. Performance: Currently there's only 1 ground texture lookup and landclass transitions for that texture. The ultra shader looks up 5 more textures. Probably transitions for 1 more texture need to be supported, as often a base and overlay texture are mixed contributing heavily to visible colour. The math overhead is mostly present, except for noise math being better hidden than in the eventual version. Some of the texture array lookups in the full version may be hidden by the math - depending on GPU memory handling compared to calculation speed.
2021-11-09 14:25:09 +00:00
uniform bool use_IR_vision;
uniform mat4 osg_ViewMatrixInverse;
// From VPBTechnique.cxx
uniform mat4 fg_zUpTransform;
uniform vec3 fg_modelOffset;
WS30 shaders: Add WS3 detailed technique using the "6" slot. Port the ALS haze, lighting, and math parts of the detailed and ultra shaders. The texture lookups are left out. Shader selection based on terrain quality setting: - Ultra - ws30-ALS-ultra frag/vert. - High and Medium - ws30-ALS-detailed frag/vert. The shaders switch code paths based on quality level uniform. - Low - ws30-ALS frag/vert. Changelog: ws30-ALS vertex shaders: - Ambient colour material colour doesn't seem to be used in the vertex shader, and isn't sent to fragment shaders currently. Regional materials only define non-default ambient colour of vec4(0.0) for water, ocean etc. Otherwise the default value of vec4(0.2, 0.2, 0.2, 1.0) is used. ws30-ALS.frag: - Set alpha of color to diffuse_term.a, to be consistent with WS2 implementation. ws30-ALS-ultra.frag and ws30-ALS-detailed.frag - World pos is assigned a value to allow noise functions to compile. - Swatch_size is temporarily set to 2000m instead of the xsize texture dimension to allow noise math to run while landclass search and texture arrays are being looked up. Swatch_size is used to adjust the wavelength of multiple overlay mixing noise wavelengths based on how far the textures are stretched (WiP WS2 feature). There are some noise calculations that could run while the first landclass lookup happens. If this is not enough, the selection of calculated noise wavelengths to add could change based on how far the textures are stretched, instead of changing the wavelengths at calculation time. - Move photoscenery technique no "4" after technique no "7" without changing the index (in case the low index is needed for photoscenery). This makes viewing a diff with the WS2 effect easier. Performance: Currently there's only 1 ground texture lookup and landclass transitions for that texture. The ultra shader looks up 5 more textures. Probably transitions for 1 more texture need to be supported, as often a base and overlay texture are mixed contributing heavily to visible colour. The math overhead is mostly present, except for noise math being better hidden than in the eventual version. Some of the texture array lookups in the full version may be hidden by the math - depending on GPU memory handling compared to calculation speed.
2021-11-09 14:25:09 +00:00
float yprime_alt;
vec3 moonlight_perception (in vec3 light);
WS30: landclass and texture lookups in fragment shader commit e131ffaca7b2c934474f0e447b5852cb4c7c8d4a Author: vs <vs2009@mail.com> Date: Fri Oct 15 22:19:42 2021 +1000 WS30: landclass and texture lookups in fragment shader: Changelog: - Testing: Procedural random landclass function, get_random_landclass(). 1). Avoids a texture lookup for profiling. 2). Creates squares of configurable size with controllable random landclass ranges - to test landclass transition algorithms and quickly profile lots of landclasses in view. It's also possible to put pressure on GPU memory even with 1 lookup of ground textures per fragment, by reducing size to <20m and viewing from altitude. - Add ALS ultra technique as no 5, move existing ALS technique to no. 6. Add WS30-ALS-ultra frag & vert in preparation for eventual ALS ultra port. Change comments/variables to match using a texture array instead of atlas. Sampler name: atlas -> textureArray. - Testing/optimisation of de-tiling: WS30-ALS.frag: reorder perlin detiling to make noise source easier to switch. WS30-ALS-ultra.frag: Create alternative to perlin noise used for reducing tiling that avoids a texture lookup - to profile and optimise. This is commented out. The performance difference in the final version depends on memory pressure versus arithmetic load of the full shader. It varies by GPU and what's in view. In future, once a full ALS port is done, maybe it'll be more efficient to run a higher quality de-tiling algorithm all the time to avoid branching overhead due to effects like agriculture which need more de-tiling. De-tiling code in shaders should /eventually/ match CPU-side de-tiling of texture masks used for object and vegetation placement. De-tiling code in GPUs might be subject to precision and numerical artifacts, and if so maybe the texture lookup version would work better. The same applies to noise used for rendering WS3 water waves and collision queries. One option is to use exactly the same glsl code, with a C++ header to convert glsl syntax e.g. https://github.com/g-truc/glm .
2021-10-21 20:31:03 +00:00
void setupShadows(vec4 eyeSpacePos);
// This is the value used in the skydome scattering shader - use the same here for consistency?
const float EarthRadius = 5800000.0;
const float terminator_width = 200000.0;
WS30 shaders: Add WS3 detailed technique using the "6" slot. Port the ALS haze, lighting, and math parts of the detailed and ultra shaders. The texture lookups are left out. Shader selection based on terrain quality setting: - Ultra - ws30-ALS-ultra frag/vert. - High and Medium - ws30-ALS-detailed frag/vert. The shaders switch code paths based on quality level uniform. - Low - ws30-ALS frag/vert. Changelog: ws30-ALS vertex shaders: - Ambient colour material colour doesn't seem to be used in the vertex shader, and isn't sent to fragment shaders currently. Regional materials only define non-default ambient colour of vec4(0.0) for water, ocean etc. Otherwise the default value of vec4(0.2, 0.2, 0.2, 1.0) is used. ws30-ALS.frag: - Set alpha of color to diffuse_term.a, to be consistent with WS2 implementation. ws30-ALS-ultra.frag and ws30-ALS-detailed.frag - World pos is assigned a value to allow noise functions to compile. - Swatch_size is temporarily set to 2000m instead of the xsize texture dimension to allow noise math to run while landclass search and texture arrays are being looked up. Swatch_size is used to adjust the wavelength of multiple overlay mixing noise wavelengths based on how far the textures are stretched (WiP WS2 feature). There are some noise calculations that could run while the first landclass lookup happens. If this is not enough, the selection of calculated noise wavelengths to add could change based on how far the textures are stretched, instead of changing the wavelengths at calculation time. - Move photoscenery technique no "4" after technique no "7" without changing the index (in case the low index is needed for photoscenery). This makes viewing a diff with the WS2 effect easier. Performance: Currently there's only 1 ground texture lookup and landclass transitions for that texture. The ultra shader looks up 5 more textures. Probably transitions for 1 more texture need to be supported, as often a base and overlay texture are mixed contributing heavily to visible colour. The math overhead is mostly present, except for noise math being better hidden than in the eventual version. Some of the texture array lookups in the full version may be hidden by the math - depending on GPU memory handling compared to calculation speed.
2021-11-09 14:25:09 +00:00
WS30: landclass and texture lookups in fragment shader commit e131ffaca7b2c934474f0e447b5852cb4c7c8d4a Author: vs <vs2009@mail.com> Date: Fri Oct 15 22:19:42 2021 +1000 WS30: landclass and texture lookups in fragment shader: Changelog: - Testing: Procedural random landclass function, get_random_landclass(). 1). Avoids a texture lookup for profiling. 2). Creates squares of configurable size with controllable random landclass ranges - to test landclass transition algorithms and quickly profile lots of landclasses in view. It's also possible to put pressure on GPU memory even with 1 lookup of ground textures per fragment, by reducing size to <20m and viewing from altitude. - Add ALS ultra technique as no 5, move existing ALS technique to no. 6. Add WS30-ALS-ultra frag & vert in preparation for eventual ALS ultra port. Change comments/variables to match using a texture array instead of atlas. Sampler name: atlas -> textureArray. - Testing/optimisation of de-tiling: WS30-ALS.frag: reorder perlin detiling to make noise source easier to switch. WS30-ALS-ultra.frag: Create alternative to perlin noise used for reducing tiling that avoids a texture lookup - to profile and optimise. This is commented out. The performance difference in the final version depends on memory pressure versus arithmetic load of the full shader. It varies by GPU and what's in view. In future, once a full ALS port is done, maybe it'll be more efficient to run a higher quality de-tiling algorithm all the time to avoid branching overhead due to effects like agriculture which need more de-tiling. De-tiling code in shaders should /eventually/ match CPU-side de-tiling of texture masks used for object and vegetation placement. De-tiling code in GPUs might be subject to precision and numerical artifacts, and if so maybe the texture lookup version would work better. The same applies to noise used for rendering WS3 water waves and collision queries. One option is to use exactly the same glsl code, with a C++ header to convert glsl syntax e.g. https://github.com/g-truc/glm .
2021-10-21 20:31:03 +00:00
float light_func (in float x, in float a, in float b, in float c, in float d, in float e)
{
WS30: MR #267: Improved texture lookups from VS Squashed commit of the following: commit 115511888c20c53670eba17a82c81c9af99d7302 Author: vs <vs2009@mail.com> Date: Mon Dec 6 18:52:06 2021 +1000 WS30 effects and shaders: Changelog: ws30-ALS-ultra.frag: - Ground textures lookups use their own coordinates separate from the landclass texture lookup. - Partial derivatives dFdx and Dfdy are packed together in a vec4, so simple multiplication to scale can be done in 1 instruction. dFdx = s and t components. dFdy = p and q components. These must be scaled properly for ground texture access as ground texture stretching and detiling of tex coords mean textures are scaled differently. - Added calculation of partial derivatives for texture coordinates used by the 5 non- base textures. dFdx() and dFdy() were called for nontrivial texture coordinate manipulation. - New control randomise_texture_lookups added at top of ws30-ALS-ultra.frag, in the development tools section. Setting this to 1 will do a stress test of ground texture array lookups. A fast random number generation function is used to assign each landclass 4 random textures from the ground texture array - this is done by . Performance will not be as bad in the full ALS port as some texture slots will better caching in memory - e.g. have 1 or a few variants. - Possible optimisation: use a 2nd or 3rd texture array for some of the non-base texture slots that typically have 256, 512, or 1024 textures. The resolutions of these arrays should change based on the largest loaded texture size in the active regional definitions - this will allow taking full advantage of smaller texture sizes in some areas. The disadvantage is some texture duplication with more slots. - Possible optimisation: offer the option to shrink textures by 50% or 25% - for texture slots that use large textures like base or mix slots. - Very temporary - reduce procedural normal map features with photoscenery active without breaking profiling, as the inputs to shaders are effect defaults or placeholder (by request on ML). ---- ws30-ALS-ultra.vert: - Start of conversion of geocentic world space xyz into lat/lon coords used for ground texture lookups. Currently commented out as it's unknown what model space coords are in (not geocentric it seems). ws20-ALS-landclass-search-functions.frag: - Add control for changing the ground texture array lookup function for debugging in case old compilers/GPUs have issues. tex_lookup_type: 0: normal( textureGrad(), 1: textureLod (manual Lod calculation), 2: texture() with no partial derivative adjustment. - New get6_random_integers() will extract 6 limited random values from the full precision of a 32 bit random value. - Old landclass_texel_size_m references are removed since textureSize() is used. There are no 'const in float' arguments that may cause issues on AMD compilers. ---- WS30-overlay effect (Inactive): - ws30-overlay.eff (derived from terrain-overlay.eff). Technique no "4" is used for two passes. The 1st pass is a copy of the ALS ultra pass (technique no "5") from ws30.eff. The 2nd pass is the same as terrain-overlay.eff. The 2nd pass uses terrain- overlay.frag from WS2. - grass-ALS.vert copied to ws30-ovelay-ALS.vert. To do: needs texture coords that don't change with tiles. - terrain-overlay-ALS.geom copied to ws30-overlay-ALS.geom. To do: uses gl_PositionIn [i].xy for position in the horizontal plane - assumes z is vertical. Tile model space doesn't seem to match this. - WS3 doesn't seem to have a way of switching references to terrain-overlay.eff (which inherits from terrain-default.eff) to the new ws3-overlay.eff (which needs to inherit from ws30.eff). The ws3-overlay.eff included /might/ just work without any other changes: the first pass is the WS3 als ultra settings pass, and the second overlay pass is unchanged from WS2 (the same terrain overlay shaders should probably work apart from texcoords and rawpos not being correct). - Materials/base/materials-base.xml: ws30Road material: uncomment line declaring terrain-default as the effect. The target effect for ws30 roads is road-*.eff and it's added to ws30Road and ws30Freeway but commented out as it's not working currently. - Misc: large scale transitions are turned on in ws30-ALS-landclass-search-functions.frag by default. Grow landclass borders with large scale transitions is now on by default. ---- Changes after the multi-texture support commit: ws30-ALS-ultra.vert - Added documentation: WS30 model space and z up space - for future people working on WS30, and people looking through shaders to rule out possibilities e.g. when fixing bugs, or interpreting visual bug reports. ws30-ALS-landclass-search-functions.frag: - For now, lookup_ground_texture_array() also looks up the relevant texture's index based on an integer. - Add get_mixed_texel() - looks up texel for this fragment and any neighbors before mixing. Moves currently shared mixing code out of 3 fragment shaders. Misc: changed indentation from mixed tabs/spaces to spaces in ws30-ALS-ultra frag and vert. The indentation can be changed again when the porting is complete. ws30-ALS vert/frag and ws30-ALS-detailed vert/frag: - Add varying for ground texture coordiante, currently set to gl_TexCoord[0]. Apply texture stretching dimensions in fragment shaders. - Misc: varying rawPos is set to vec2 for now, as relPos.z+eye_alt might be faster. Misc: keep WS2 mixing logic for now , including turning off mixing via the alpha channel of the textures ---- Changes after sending material parameters in uniform arrays commit: - Materials parameter for rock_strata is cast into an int so rock_strata==1 should work. Misc: Left over uniform for rock strata cleaned up. - ws30-ALS-ultra.frag and ws30-ALS-detailed.frag: Add missing mat_shininess for photoscenery case .
2022-01-03 15:43:29 +00:00
//x = x - 0.5;
// use the asymptotics to shorten computations
if (x < -15.0) {return 0.0;}
return e / pow((1.0 + a * exp(-b * (x-c)) ),(1.0/d));
WS30: landclass and texture lookups in fragment shader commit e131ffaca7b2c934474f0e447b5852cb4c7c8d4a Author: vs <vs2009@mail.com> Date: Fri Oct 15 22:19:42 2021 +1000 WS30: landclass and texture lookups in fragment shader: Changelog: - Testing: Procedural random landclass function, get_random_landclass(). 1). Avoids a texture lookup for profiling. 2). Creates squares of configurable size with controllable random landclass ranges - to test landclass transition algorithms and quickly profile lots of landclasses in view. It's also possible to put pressure on GPU memory even with 1 lookup of ground textures per fragment, by reducing size to <20m and viewing from altitude. - Add ALS ultra technique as no 5, move existing ALS technique to no. 6. Add WS30-ALS-ultra frag & vert in preparation for eventual ALS ultra port. Change comments/variables to match using a texture array instead of atlas. Sampler name: atlas -> textureArray. - Testing/optimisation of de-tiling: WS30-ALS.frag: reorder perlin detiling to make noise source easier to switch. WS30-ALS-ultra.frag: Create alternative to perlin noise used for reducing tiling that avoids a texture lookup - to profile and optimise. This is commented out. The performance difference in the final version depends on memory pressure versus arithmetic load of the full shader. It varies by GPU and what's in view. In future, once a full ALS port is done, maybe it'll be more efficient to run a higher quality de-tiling algorithm all the time to avoid branching overhead due to effects like agriculture which need more de-tiling. De-tiling code in shaders should /eventually/ match CPU-side de-tiling of texture masks used for object and vegetation placement. De-tiling code in GPUs might be subject to precision and numerical artifacts, and if so maybe the texture lookup version would work better. The same applies to noise used for rendering WS3 water waves and collision queries. One option is to use exactly the same glsl code, with a C++ header to convert glsl syntax e.g. https://github.com/g-truc/glm .
2021-10-21 20:31:03 +00:00
}
void createRotationMatrix(in float angle, out mat4 rotmat)
{
rotmat = mat4( cos( angle ), -sin( angle ), 0.0, 0.0,
sin( angle ), cos( angle ), 0.0, 0.0,
0.0 , 0.0 , 1.0, 0.0,
0.0 , 0.0 , 0.0, 1.0 );
}
WS30: landclass and texture lookups in fragment shader commit e131ffaca7b2c934474f0e447b5852cb4c7c8d4a Author: vs <vs2009@mail.com> Date: Fri Oct 15 22:19:42 2021 +1000 WS30: landclass and texture lookups in fragment shader: Changelog: - Testing: Procedural random landclass function, get_random_landclass(). 1). Avoids a texture lookup for profiling. 2). Creates squares of configurable size with controllable random landclass ranges - to test landclass transition algorithms and quickly profile lots of landclasses in view. It's also possible to put pressure on GPU memory even with 1 lookup of ground textures per fragment, by reducing size to <20m and viewing from altitude. - Add ALS ultra technique as no 5, move existing ALS technique to no. 6. Add WS30-ALS-ultra frag & vert in preparation for eventual ALS ultra port. Change comments/variables to match using a texture array instead of atlas. Sampler name: atlas -> textureArray. - Testing/optimisation of de-tiling: WS30-ALS.frag: reorder perlin detiling to make noise source easier to switch. WS30-ALS-ultra.frag: Create alternative to perlin noise used for reducing tiling that avoids a texture lookup - to profile and optimise. This is commented out. The performance difference in the final version depends on memory pressure versus arithmetic load of the full shader. It varies by GPU and what's in view. In future, once a full ALS port is done, maybe it'll be more efficient to run a higher quality de-tiling algorithm all the time to avoid branching overhead due to effects like agriculture which need more de-tiling. De-tiling code in shaders should /eventually/ match CPU-side de-tiling of texture masks used for object and vegetation placement. De-tiling code in GPUs might be subject to precision and numerical artifacts, and if so maybe the texture lookup version would work better. The same applies to noise used for rendering WS3 water waves and collision queries. One option is to use exactly the same glsl code, with a C++ header to convert glsl syntax e.g. https://github.com/g-truc/glm .
2021-10-21 20:31:03 +00:00
void main()
{
WS30: MR #267: Improved texture lookups from VS Squashed commit of the following: commit 115511888c20c53670eba17a82c81c9af99d7302 Author: vs <vs2009@mail.com> Date: Mon Dec 6 18:52:06 2021 +1000 WS30 effects and shaders: Changelog: ws30-ALS-ultra.frag: - Ground textures lookups use their own coordinates separate from the landclass texture lookup. - Partial derivatives dFdx and Dfdy are packed together in a vec4, so simple multiplication to scale can be done in 1 instruction. dFdx = s and t components. dFdy = p and q components. These must be scaled properly for ground texture access as ground texture stretching and detiling of tex coords mean textures are scaled differently. - Added calculation of partial derivatives for texture coordinates used by the 5 non- base textures. dFdx() and dFdy() were called for nontrivial texture coordinate manipulation. - New control randomise_texture_lookups added at top of ws30-ALS-ultra.frag, in the development tools section. Setting this to 1 will do a stress test of ground texture array lookups. A fast random number generation function is used to assign each landclass 4 random textures from the ground texture array - this is done by . Performance will not be as bad in the full ALS port as some texture slots will better caching in memory - e.g. have 1 or a few variants. - Possible optimisation: use a 2nd or 3rd texture array for some of the non-base texture slots that typically have 256, 512, or 1024 textures. The resolutions of these arrays should change based on the largest loaded texture size in the active regional definitions - this will allow taking full advantage of smaller texture sizes in some areas. The disadvantage is some texture duplication with more slots. - Possible optimisation: offer the option to shrink textures by 50% or 25% - for texture slots that use large textures like base or mix slots. - Very temporary - reduce procedural normal map features with photoscenery active without breaking profiling, as the inputs to shaders are effect defaults or placeholder (by request on ML). ---- ws30-ALS-ultra.vert: - Start of conversion of geocentic world space xyz into lat/lon coords used for ground texture lookups. Currently commented out as it's unknown what model space coords are in (not geocentric it seems). ws20-ALS-landclass-search-functions.frag: - Add control for changing the ground texture array lookup function for debugging in case old compilers/GPUs have issues. tex_lookup_type: 0: normal( textureGrad(), 1: textureLod (manual Lod calculation), 2: texture() with no partial derivative adjustment. - New get6_random_integers() will extract 6 limited random values from the full precision of a 32 bit random value. - Old landclass_texel_size_m references are removed since textureSize() is used. There are no 'const in float' arguments that may cause issues on AMD compilers. ---- WS30-overlay effect (Inactive): - ws30-overlay.eff (derived from terrain-overlay.eff). Technique no "4" is used for two passes. The 1st pass is a copy of the ALS ultra pass (technique no "5") from ws30.eff. The 2nd pass is the same as terrain-overlay.eff. The 2nd pass uses terrain- overlay.frag from WS2. - grass-ALS.vert copied to ws30-ovelay-ALS.vert. To do: needs texture coords that don't change with tiles. - terrain-overlay-ALS.geom copied to ws30-overlay-ALS.geom. To do: uses gl_PositionIn [i].xy for position in the horizontal plane - assumes z is vertical. Tile model space doesn't seem to match this. - WS3 doesn't seem to have a way of switching references to terrain-overlay.eff (which inherits from terrain-default.eff) to the new ws3-overlay.eff (which needs to inherit from ws30.eff). The ws3-overlay.eff included /might/ just work without any other changes: the first pass is the WS3 als ultra settings pass, and the second overlay pass is unchanged from WS2 (the same terrain overlay shaders should probably work apart from texcoords and rawpos not being correct). - Materials/base/materials-base.xml: ws30Road material: uncomment line declaring terrain-default as the effect. The target effect for ws30 roads is road-*.eff and it's added to ws30Road and ws30Freeway but commented out as it's not working currently. - Misc: large scale transitions are turned on in ws30-ALS-landclass-search-functions.frag by default. Grow landclass borders with large scale transitions is now on by default. ---- Changes after the multi-texture support commit: ws30-ALS-ultra.vert - Added documentation: WS30 model space and z up space - for future people working on WS30, and people looking through shaders to rule out possibilities e.g. when fixing bugs, or interpreting visual bug reports. ws30-ALS-landclass-search-functions.frag: - For now, lookup_ground_texture_array() also looks up the relevant texture's index based on an integer. - Add get_mixed_texel() - looks up texel for this fragment and any neighbors before mixing. Moves currently shared mixing code out of 3 fragment shaders. Misc: changed indentation from mixed tabs/spaces to spaces in ws30-ALS-ultra frag and vert. The indentation can be changed again when the porting is complete. ws30-ALS vert/frag and ws30-ALS-detailed vert/frag: - Add varying for ground texture coordiante, currently set to gl_TexCoord[0]. Apply texture stretching dimensions in fragment shaders. - Misc: varying rawPos is set to vec2 for now, as relPos.z+eye_alt might be faster. Misc: keep WS2 mixing logic for now , including turning off mixing via the alpha channel of the textures ---- Changes after sending material parameters in uniform arrays commit: - Materials parameter for rock_strata is cast into an int so rock_strata==1 should work. Misc: Left over uniform for rock strata cleaned up. - ws30-ALS-ultra.frag and ws30-ALS-detailed.frag: Add missing mat_shininess for photoscenery case .
2022-01-03 15:43:29 +00:00
WS30: landclass and texture lookups in fragment shader commit e131ffaca7b2c934474f0e447b5852cb4c7c8d4a Author: vs <vs2009@mail.com> Date: Fri Oct 15 22:19:42 2021 +1000 WS30: landclass and texture lookups in fragment shader: Changelog: - Testing: Procedural random landclass function, get_random_landclass(). 1). Avoids a texture lookup for profiling. 2). Creates squares of configurable size with controllable random landclass ranges - to test landclass transition algorithms and quickly profile lots of landclasses in view. It's also possible to put pressure on GPU memory even with 1 lookup of ground textures per fragment, by reducing size to <20m and viewing from altitude. - Add ALS ultra technique as no 5, move existing ALS technique to no. 6. Add WS30-ALS-ultra frag & vert in preparation for eventual ALS ultra port. Change comments/variables to match using a texture array instead of atlas. Sampler name: atlas -> textureArray. - Testing/optimisation of de-tiling: WS30-ALS.frag: reorder perlin detiling to make noise source easier to switch. WS30-ALS-ultra.frag: Create alternative to perlin noise used for reducing tiling that avoids a texture lookup - to profile and optimise. This is commented out. The performance difference in the final version depends on memory pressure versus arithmetic load of the full shader. It varies by GPU and what's in view. In future, once a full ALS port is done, maybe it'll be more efficient to run a higher quality de-tiling algorithm all the time to avoid branching overhead due to effects like agriculture which need more de-tiling. De-tiling code in shaders should /eventually/ match CPU-side de-tiling of texture masks used for object and vegetation placement. De-tiling code in GPUs might be subject to precision and numerical artifacts, and if so maybe the texture lookup version would work better. The same applies to noise used for rendering WS3 water waves and collision queries. One option is to use exactly the same glsl code, with a C++ header to convert glsl syntax e.g. https://github.com/g-truc/glm .
2021-10-21 20:31:03 +00:00
vec4 light_diffuse;
vec4 light_ambient;
vec3 shadedFogColor = vec3(0.55, 0.67, 0.88);
WS30 shaders: Add WS3 detailed technique using the "6" slot. Port the ALS haze, lighting, and math parts of the detailed and ultra shaders. The texture lookups are left out. Shader selection based on terrain quality setting: - Ultra - ws30-ALS-ultra frag/vert. - High and Medium - ws30-ALS-detailed frag/vert. The shaders switch code paths based on quality level uniform. - Low - ws30-ALS frag/vert. Changelog: ws30-ALS vertex shaders: - Ambient colour material colour doesn't seem to be used in the vertex shader, and isn't sent to fragment shaders currently. Regional materials only define non-default ambient colour of vec4(0.0) for water, ocean etc. Otherwise the default value of vec4(0.2, 0.2, 0.2, 1.0) is used. ws30-ALS.frag: - Set alpha of color to diffuse_term.a, to be consistent with WS2 implementation. ws30-ALS-ultra.frag and ws30-ALS-detailed.frag - World pos is assigned a value to allow noise functions to compile. - Swatch_size is temporarily set to 2000m instead of the xsize texture dimension to allow noise math to run while landclass search and texture arrays are being looked up. Swatch_size is used to adjust the wavelength of multiple overlay mixing noise wavelengths based on how far the textures are stretched (WiP WS2 feature). There are some noise calculations that could run while the first landclass lookup happens. If this is not enough, the selection of calculated noise wavelengths to add could change based on how far the textures are stretched, instead of changing the wavelengths at calculation time. - Move photoscenery technique no "4" after technique no "7" without changing the index (in case the low index is needed for photoscenery). This makes viewing a diff with the WS2 effect easier. Performance: Currently there's only 1 ground texture lookup and landclass transitions for that texture. The ultra shader looks up 5 more textures. Probably transitions for 1 more texture need to be supported, as often a base and overlay texture are mixed contributing heavily to visible colour. The math overhead is mostly present, except for noise math being better hidden than in the eventual version. Some of the texture array lookups in the full version may be hidden by the math - depending on GPU memory handling compared to calculation speed.
2021-11-09 14:25:09 +00:00
vec3 moonLightColor = vec3 (0.095, 0.095, 0.15) * moonlight + vec3 (0.005, 0.005, 0.005);
WS30: MR #267: Improved texture lookups from VS Squashed commit of the following: commit 115511888c20c53670eba17a82c81c9af99d7302 Author: vs <vs2009@mail.com> Date: Mon Dec 6 18:52:06 2021 +1000 WS30 effects and shaders: Changelog: ws30-ALS-ultra.frag: - Ground textures lookups use their own coordinates separate from the landclass texture lookup. - Partial derivatives dFdx and Dfdy are packed together in a vec4, so simple multiplication to scale can be done in 1 instruction. dFdx = s and t components. dFdy = p and q components. These must be scaled properly for ground texture access as ground texture stretching and detiling of tex coords mean textures are scaled differently. - Added calculation of partial derivatives for texture coordinates used by the 5 non- base textures. dFdx() and dFdy() were called for nontrivial texture coordinate manipulation. - New control randomise_texture_lookups added at top of ws30-ALS-ultra.frag, in the development tools section. Setting this to 1 will do a stress test of ground texture array lookups. A fast random number generation function is used to assign each landclass 4 random textures from the ground texture array - this is done by . Performance will not be as bad in the full ALS port as some texture slots will better caching in memory - e.g. have 1 or a few variants. - Possible optimisation: use a 2nd or 3rd texture array for some of the non-base texture slots that typically have 256, 512, or 1024 textures. The resolutions of these arrays should change based on the largest loaded texture size in the active regional definitions - this will allow taking full advantage of smaller texture sizes in some areas. The disadvantage is some texture duplication with more slots. - Possible optimisation: offer the option to shrink textures by 50% or 25% - for texture slots that use large textures like base or mix slots. - Very temporary - reduce procedural normal map features with photoscenery active without breaking profiling, as the inputs to shaders are effect defaults or placeholder (by request on ML). ---- ws30-ALS-ultra.vert: - Start of conversion of geocentic world space xyz into lat/lon coords used for ground texture lookups. Currently commented out as it's unknown what model space coords are in (not geocentric it seems). ws20-ALS-landclass-search-functions.frag: - Add control for changing the ground texture array lookup function for debugging in case old compilers/GPUs have issues. tex_lookup_type: 0: normal( textureGrad(), 1: textureLod (manual Lod calculation), 2: texture() with no partial derivative adjustment. - New get6_random_integers() will extract 6 limited random values from the full precision of a 32 bit random value. - Old landclass_texel_size_m references are removed since textureSize() is used. There are no 'const in float' arguments that may cause issues on AMD compilers. ---- WS30-overlay effect (Inactive): - ws30-overlay.eff (derived from terrain-overlay.eff). Technique no "4" is used for two passes. The 1st pass is a copy of the ALS ultra pass (technique no "5") from ws30.eff. The 2nd pass is the same as terrain-overlay.eff. The 2nd pass uses terrain- overlay.frag from WS2. - grass-ALS.vert copied to ws30-ovelay-ALS.vert. To do: needs texture coords that don't change with tiles. - terrain-overlay-ALS.geom copied to ws30-overlay-ALS.geom. To do: uses gl_PositionIn [i].xy for position in the horizontal plane - assumes z is vertical. Tile model space doesn't seem to match this. - WS3 doesn't seem to have a way of switching references to terrain-overlay.eff (which inherits from terrain-default.eff) to the new ws3-overlay.eff (which needs to inherit from ws30.eff). The ws3-overlay.eff included /might/ just work without any other changes: the first pass is the WS3 als ultra settings pass, and the second overlay pass is unchanged from WS2 (the same terrain overlay shaders should probably work apart from texcoords and rawpos not being correct). - Materials/base/materials-base.xml: ws30Road material: uncomment line declaring terrain-default as the effect. The target effect for ws30 roads is road-*.eff and it's added to ws30Road and ws30Freeway but commented out as it's not working currently. - Misc: large scale transitions are turned on in ws30-ALS-landclass-search-functions.frag by default. Grow landclass borders with large scale transitions is now on by default. ---- Changes after the multi-texture support commit: ws30-ALS-ultra.vert - Added documentation: WS30 model space and z up space - for future people working on WS30, and people looking through shaders to rule out possibilities e.g. when fixing bugs, or interpreting visual bug reports. ws30-ALS-landclass-search-functions.frag: - For now, lookup_ground_texture_array() also looks up the relevant texture's index based on an integer. - Add get_mixed_texel() - looks up texel for this fragment and any neighbors before mixing. Moves currently shared mixing code out of 3 fragment shaders. Misc: changed indentation from mixed tabs/spaces to spaces in ws30-ALS-ultra frag and vert. The indentation can be changed again when the porting is complete. ws30-ALS vert/frag and ws30-ALS-detailed vert/frag: - Add varying for ground texture coordiante, currently set to gl_TexCoord[0]. Apply texture stretching dimensions in fragment shaders. - Misc: varying rawPos is set to vec2 for now, as relPos.z+eye_alt might be faster. Misc: keep WS2 mixing logic for now , including turning off mixing via the alpha channel of the textures ---- Changes after sending material parameters in uniform arrays commit: - Materials parameter for rock_strata is cast into an int so rock_strata==1 should work. Misc: Left over uniform for rock strata cleaned up. - ws30-ALS-ultra.frag and ws30-ALS-detailed.frag: Add missing mat_shininess for photoscenery case .
2022-01-03 15:43:29 +00:00
WS30 shaders: Add WS3 detailed technique using the "6" slot. Port the ALS haze, lighting, and math parts of the detailed and ultra shaders. The texture lookups are left out. Shader selection based on terrain quality setting: - Ultra - ws30-ALS-ultra frag/vert. - High and Medium - ws30-ALS-detailed frag/vert. The shaders switch code paths based on quality level uniform. - Low - ws30-ALS frag/vert. Changelog: ws30-ALS vertex shaders: - Ambient colour material colour doesn't seem to be used in the vertex shader, and isn't sent to fragment shaders currently. Regional materials only define non-default ambient colour of vec4(0.0) for water, ocean etc. Otherwise the default value of vec4(0.2, 0.2, 0.2, 1.0) is used. ws30-ALS.frag: - Set alpha of color to diffuse_term.a, to be consistent with WS2 implementation. ws30-ALS-ultra.frag and ws30-ALS-detailed.frag - World pos is assigned a value to allow noise functions to compile. - Swatch_size is temporarily set to 2000m instead of the xsize texture dimension to allow noise math to run while landclass search and texture arrays are being looked up. Swatch_size is used to adjust the wavelength of multiple overlay mixing noise wavelengths based on how far the textures are stretched (WiP WS2 feature). There are some noise calculations that could run while the first landclass lookup happens. If this is not enough, the selection of calculated noise wavelengths to add could change based on how far the textures are stretched, instead of changing the wavelengths at calculation time. - Move photoscenery technique no "4" after technique no "7" without changing the index (in case the low index is needed for photoscenery). This makes viewing a diff with the WS2 effect easier. Performance: Currently there's only 1 ground texture lookup and landclass transitions for that texture. The ultra shader looks up 5 more textures. Probably transitions for 1 more texture need to be supported, as often a base and overlay texture are mixed contributing heavily to visible colour. The math overhead is mostly present, except for noise math being better hidden than in the eventual version. Some of the texture array lookups in the full version may be hidden by the math - depending on GPU memory handling compared to calculation speed.
2021-11-09 14:25:09 +00:00
moonLightColor = moonlight_perception (moonLightColor);
WS30: MR #267: Improved texture lookups from VS Squashed commit of the following: commit 115511888c20c53670eba17a82c81c9af99d7302 Author: vs <vs2009@mail.com> Date: Mon Dec 6 18:52:06 2021 +1000 WS30 effects and shaders: Changelog: ws30-ALS-ultra.frag: - Ground textures lookups use their own coordinates separate from the landclass texture lookup. - Partial derivatives dFdx and Dfdy are packed together in a vec4, so simple multiplication to scale can be done in 1 instruction. dFdx = s and t components. dFdy = p and q components. These must be scaled properly for ground texture access as ground texture stretching and detiling of tex coords mean textures are scaled differently. - Added calculation of partial derivatives for texture coordinates used by the 5 non- base textures. dFdx() and dFdy() were called for nontrivial texture coordinate manipulation. - New control randomise_texture_lookups added at top of ws30-ALS-ultra.frag, in the development tools section. Setting this to 1 will do a stress test of ground texture array lookups. A fast random number generation function is used to assign each landclass 4 random textures from the ground texture array - this is done by . Performance will not be as bad in the full ALS port as some texture slots will better caching in memory - e.g. have 1 or a few variants. - Possible optimisation: use a 2nd or 3rd texture array for some of the non-base texture slots that typically have 256, 512, or 1024 textures. The resolutions of these arrays should change based on the largest loaded texture size in the active regional definitions - this will allow taking full advantage of smaller texture sizes in some areas. The disadvantage is some texture duplication with more slots. - Possible optimisation: offer the option to shrink textures by 50% or 25% - for texture slots that use large textures like base or mix slots. - Very temporary - reduce procedural normal map features with photoscenery active without breaking profiling, as the inputs to shaders are effect defaults or placeholder (by request on ML). ---- ws30-ALS-ultra.vert: - Start of conversion of geocentic world space xyz into lat/lon coords used for ground texture lookups. Currently commented out as it's unknown what model space coords are in (not geocentric it seems). ws20-ALS-landclass-search-functions.frag: - Add control for changing the ground texture array lookup function for debugging in case old compilers/GPUs have issues. tex_lookup_type: 0: normal( textureGrad(), 1: textureLod (manual Lod calculation), 2: texture() with no partial derivative adjustment. - New get6_random_integers() will extract 6 limited random values from the full precision of a 32 bit random value. - Old landclass_texel_size_m references are removed since textureSize() is used. There are no 'const in float' arguments that may cause issues on AMD compilers. ---- WS30-overlay effect (Inactive): - ws30-overlay.eff (derived from terrain-overlay.eff). Technique no "4" is used for two passes. The 1st pass is a copy of the ALS ultra pass (technique no "5") from ws30.eff. The 2nd pass is the same as terrain-overlay.eff. The 2nd pass uses terrain- overlay.frag from WS2. - grass-ALS.vert copied to ws30-ovelay-ALS.vert. To do: needs texture coords that don't change with tiles. - terrain-overlay-ALS.geom copied to ws30-overlay-ALS.geom. To do: uses gl_PositionIn [i].xy for position in the horizontal plane - assumes z is vertical. Tile model space doesn't seem to match this. - WS3 doesn't seem to have a way of switching references to terrain-overlay.eff (which inherits from terrain-default.eff) to the new ws3-overlay.eff (which needs to inherit from ws30.eff). The ws3-overlay.eff included /might/ just work without any other changes: the first pass is the WS3 als ultra settings pass, and the second overlay pass is unchanged from WS2 (the same terrain overlay shaders should probably work apart from texcoords and rawpos not being correct). - Materials/base/materials-base.xml: ws30Road material: uncomment line declaring terrain-default as the effect. The target effect for ws30 roads is road-*.eff and it's added to ws30Road and ws30Freeway but commented out as it's not working currently. - Misc: large scale transitions are turned on in ws30-ALS-landclass-search-functions.frag by default. Grow landclass borders with large scale transitions is now on by default. ---- Changes after the multi-texture support commit: ws30-ALS-ultra.vert - Added documentation: WS30 model space and z up space - for future people working on WS30, and people looking through shaders to rule out possibilities e.g. when fixing bugs, or interpreting visual bug reports. ws30-ALS-landclass-search-functions.frag: - For now, lookup_ground_texture_array() also looks up the relevant texture's index based on an integer. - Add get_mixed_texel() - looks up texel for this fragment and any neighbors before mixing. Moves currently shared mixing code out of 3 fragment shaders. Misc: changed indentation from mixed tabs/spaces to spaces in ws30-ALS-ultra frag and vert. The indentation can be changed again when the porting is complete. ws30-ALS vert/frag and ws30-ALS-detailed vert/frag: - Add varying for ground texture coordiante, currently set to gl_TexCoord[0]. Apply texture stretching dimensions in fragment shaders. - Misc: varying rawPos is set to vec2 for now, as relPos.z+eye_alt might be faster. Misc: keep WS2 mixing logic for now , including turning off mixing via the alpha channel of the textures ---- Changes after sending material parameters in uniform arrays commit: - Materials parameter for rock_strata is cast into an int so rock_strata==1 should work. Misc: Left over uniform for rock strata cleaned up. - ws30-ALS-ultra.frag and ws30-ALS-detailed.frag: Add missing mat_shininess for photoscenery case .
2022-01-03 15:43:29 +00:00
WS30: landclass and texture lookups in fragment shader commit e131ffaca7b2c934474f0e447b5852cb4c7c8d4a Author: vs <vs2009@mail.com> Date: Fri Oct 15 22:19:42 2021 +1000 WS30: landclass and texture lookups in fragment shader: Changelog: - Testing: Procedural random landclass function, get_random_landclass(). 1). Avoids a texture lookup for profiling. 2). Creates squares of configurable size with controllable random landclass ranges - to test landclass transition algorithms and quickly profile lots of landclasses in view. It's also possible to put pressure on GPU memory even with 1 lookup of ground textures per fragment, by reducing size to <20m and viewing from altitude. - Add ALS ultra technique as no 5, move existing ALS technique to no. 6. Add WS30-ALS-ultra frag & vert in preparation for eventual ALS ultra port. Change comments/variables to match using a texture array instead of atlas. Sampler name: atlas -> textureArray. - Testing/optimisation of de-tiling: WS30-ALS.frag: reorder perlin detiling to make noise source easier to switch. WS30-ALS-ultra.frag: Create alternative to perlin noise used for reducing tiling that avoids a texture lookup - to profile and optimise. This is commented out. The performance difference in the final version depends on memory pressure versus arithmetic load of the full shader. It varies by GPU and what's in view. In future, once a full ALS port is done, maybe it'll be more efficient to run a higher quality de-tiling algorithm all the time to avoid branching overhead due to effects like agriculture which need more de-tiling. De-tiling code in shaders should /eventually/ match CPU-side de-tiling of texture masks used for object and vegetation placement. De-tiling code in GPUs might be subject to precision and numerical artifacts, and if so maybe the texture lookup version would work better. The same applies to noise used for rendering WS3 water waves and collision queries. One option is to use exactly the same glsl code, with a C++ header to convert glsl syntax e.g. https://github.com/g-truc/glm .
2021-10-21 20:31:03 +00:00
//float yprime_alt;
float yprime;
float lightArg;
float intensity;
float vertex_alt;
float scattering;
WS30: MR #267: Improved texture lookups from VS Squashed commit of the following: commit 115511888c20c53670eba17a82c81c9af99d7302 Author: vs <vs2009@mail.com> Date: Mon Dec 6 18:52:06 2021 +1000 WS30 effects and shaders: Changelog: ws30-ALS-ultra.frag: - Ground textures lookups use their own coordinates separate from the landclass texture lookup. - Partial derivatives dFdx and Dfdy are packed together in a vec4, so simple multiplication to scale can be done in 1 instruction. dFdx = s and t components. dFdy = p and q components. These must be scaled properly for ground texture access as ground texture stretching and detiling of tex coords mean textures are scaled differently. - Added calculation of partial derivatives for texture coordinates used by the 5 non- base textures. dFdx() and dFdy() were called for nontrivial texture coordinate manipulation. - New control randomise_texture_lookups added at top of ws30-ALS-ultra.frag, in the development tools section. Setting this to 1 will do a stress test of ground texture array lookups. A fast random number generation function is used to assign each landclass 4 random textures from the ground texture array - this is done by . Performance will not be as bad in the full ALS port as some texture slots will better caching in memory - e.g. have 1 or a few variants. - Possible optimisation: use a 2nd or 3rd texture array for some of the non-base texture slots that typically have 256, 512, or 1024 textures. The resolutions of these arrays should change based on the largest loaded texture size in the active regional definitions - this will allow taking full advantage of smaller texture sizes in some areas. The disadvantage is some texture duplication with more slots. - Possible optimisation: offer the option to shrink textures by 50% or 25% - for texture slots that use large textures like base or mix slots. - Very temporary - reduce procedural normal map features with photoscenery active without breaking profiling, as the inputs to shaders are effect defaults or placeholder (by request on ML). ---- ws30-ALS-ultra.vert: - Start of conversion of geocentic world space xyz into lat/lon coords used for ground texture lookups. Currently commented out as it's unknown what model space coords are in (not geocentric it seems). ws20-ALS-landclass-search-functions.frag: - Add control for changing the ground texture array lookup function for debugging in case old compilers/GPUs have issues. tex_lookup_type: 0: normal( textureGrad(), 1: textureLod (manual Lod calculation), 2: texture() with no partial derivative adjustment. - New get6_random_integers() will extract 6 limited random values from the full precision of a 32 bit random value. - Old landclass_texel_size_m references are removed since textureSize() is used. There are no 'const in float' arguments that may cause issues on AMD compilers. ---- WS30-overlay effect (Inactive): - ws30-overlay.eff (derived from terrain-overlay.eff). Technique no "4" is used for two passes. The 1st pass is a copy of the ALS ultra pass (technique no "5") from ws30.eff. The 2nd pass is the same as terrain-overlay.eff. The 2nd pass uses terrain- overlay.frag from WS2. - grass-ALS.vert copied to ws30-ovelay-ALS.vert. To do: needs texture coords that don't change with tiles. - terrain-overlay-ALS.geom copied to ws30-overlay-ALS.geom. To do: uses gl_PositionIn [i].xy for position in the horizontal plane - assumes z is vertical. Tile model space doesn't seem to match this. - WS3 doesn't seem to have a way of switching references to terrain-overlay.eff (which inherits from terrain-default.eff) to the new ws3-overlay.eff (which needs to inherit from ws30.eff). The ws3-overlay.eff included /might/ just work without any other changes: the first pass is the WS3 als ultra settings pass, and the second overlay pass is unchanged from WS2 (the same terrain overlay shaders should probably work apart from texcoords and rawpos not being correct). - Materials/base/materials-base.xml: ws30Road material: uncomment line declaring terrain-default as the effect. The target effect for ws30 roads is road-*.eff and it's added to ws30Road and ws30Freeway but commented out as it's not working currently. - Misc: large scale transitions are turned on in ws30-ALS-landclass-search-functions.frag by default. Grow landclass borders with large scale transitions is now on by default. ---- Changes after the multi-texture support commit: ws30-ALS-ultra.vert - Added documentation: WS30 model space and z up space - for future people working on WS30, and people looking through shaders to rule out possibilities e.g. when fixing bugs, or interpreting visual bug reports. ws30-ALS-landclass-search-functions.frag: - For now, lookup_ground_texture_array() also looks up the relevant texture's index based on an integer. - Add get_mixed_texel() - looks up texel for this fragment and any neighbors before mixing. Moves currently shared mixing code out of 3 fragment shaders. Misc: changed indentation from mixed tabs/spaces to spaces in ws30-ALS-ultra frag and vert. The indentation can be changed again when the porting is complete. ws30-ALS vert/frag and ws30-ALS-detailed vert/frag: - Add varying for ground texture coordiante, currently set to gl_TexCoord[0]. Apply texture stretching dimensions in fragment shaders. - Misc: varying rawPos is set to vec2 for now, as relPos.z+eye_alt might be faster. Misc: keep WS2 mixing logic for now , including turning off mixing via the alpha channel of the textures ---- Changes after sending material parameters in uniform arrays commit: - Materials parameter for rock_strata is cast into an int so rock_strata==1 should work. Misc: Left over uniform for rock strata cleaned up. - ws30-ALS-ultra.frag and ws30-ALS-detailed.frag: Add missing mat_shininess for photoscenery case .
2022-01-03 15:43:29 +00:00
// The ALS code assumes that units are in meters - e.g. model space vertices (gl_Vertex) are in meters
// WS30 model space, Nov 21, 2021:
// Coordinate axes are the same for geocentric, but not the origin.
// +z direction points from the Earth center to North pole.
// +x direction points from the Earth center to longitude = 0 on the equator.
// +y direction points from the Earth center to logntitude = East on the equator.
// Model space origin is at sea level. Units are in meters.
// Each tile, for each LoD level, its own model origin
// modelOffset is the model origin relative to the Earth center. It is in a geocentric
// space with the same axes, but with the Earth center as the origin. Units are in meters.
vec4 pos = gl_Vertex;
if (raise_vertex)
{
pos.z+=0.1;
gl_Position = gl_ModelViewProjectionMatrix * pos;
}
else gl_Position = ftransform();
// this code is copied from default.vert
ecPosition = gl_ModelViewMatrix * gl_Vertex;
//gl_Position = ftransform();
gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0;
normal = gl_NormalMatrix * gl_Normal;
WS30: landclass and texture lookups in fragment shader commit e131ffaca7b2c934474f0e447b5852cb4c7c8d4a Author: vs <vs2009@mail.com> Date: Fri Oct 15 22:19:42 2021 +1000 WS30: landclass and texture lookups in fragment shader: Changelog: - Testing: Procedural random landclass function, get_random_landclass(). 1). Avoids a texture lookup for profiling. 2). Creates squares of configurable size with controllable random landclass ranges - to test landclass transition algorithms and quickly profile lots of landclasses in view. It's also possible to put pressure on GPU memory even with 1 lookup of ground textures per fragment, by reducing size to <20m and viewing from altitude. - Add ALS ultra technique as no 5, move existing ALS technique to no. 6. Add WS30-ALS-ultra frag & vert in preparation for eventual ALS ultra port. Change comments/variables to match using a texture array instead of atlas. Sampler name: atlas -> textureArray. - Testing/optimisation of de-tiling: WS30-ALS.frag: reorder perlin detiling to make noise source easier to switch. WS30-ALS-ultra.frag: Create alternative to perlin noise used for reducing tiling that avoids a texture lookup - to profile and optimise. This is commented out. The performance difference in the final version depends on memory pressure versus arithmetic load of the full shader. It varies by GPU and what's in view. In future, once a full ALS port is done, maybe it'll be more efficient to run a higher quality de-tiling algorithm all the time to avoid branching overhead due to effects like agriculture which need more de-tiling. De-tiling code in shaders should /eventually/ match CPU-side de-tiling of texture masks used for object and vegetation placement. De-tiling code in GPUs might be subject to precision and numerical artifacts, and if so maybe the texture lookup version would work better. The same applies to noise used for rendering WS3 water waves and collision queries. One option is to use exactly the same glsl code, with a C++ header to convert glsl syntax e.g. https://github.com/g-truc/glm .
2021-10-21 20:31:03 +00:00
// Required for water calculations
lightdir = normalize(vec3(fg_zUpTransform * vec4(gl_ModelViewMatrixInverse * gl_LightSource[0].position)));
waterTex4 = vec4( ecPosition.xzy, 0.0 );
vec4 t1 = vec4(0.0, osg_SimulationTime * 0.005217, 0.0, 0.0);
vec4 t2 = vec4(0.0, osg_SimulationTime * -0.0012, 0.0, 0.0);
float Angle;
float windFactor = sqrt(WindE * WindE + WindN * WindN) * 0.05;
if (WindN == 0.0 && WindE == 0.0) {
Angle = 0.0;
} else {
Angle = atan(-WindN, WindE) - atan(1.0);
}
mat4 RotationMatrix;
createRotationMatrix(Angle, RotationMatrix);
waterTex1 = gl_MultiTexCoord0 * RotationMatrix - t1 * windFactor;
waterTex2 = gl_MultiTexCoord0 * RotationMatrix - t2 * windFactor;
WS30: MR #267: Improved texture lookups from VS Squashed commit of the following: commit 115511888c20c53670eba17a82c81c9af99d7302 Author: vs <vs2009@mail.com> Date: Mon Dec 6 18:52:06 2021 +1000 WS30 effects and shaders: Changelog: ws30-ALS-ultra.frag: - Ground textures lookups use their own coordinates separate from the landclass texture lookup. - Partial derivatives dFdx and Dfdy are packed together in a vec4, so simple multiplication to scale can be done in 1 instruction. dFdx = s and t components. dFdy = p and q components. These must be scaled properly for ground texture access as ground texture stretching and detiling of tex coords mean textures are scaled differently. - Added calculation of partial derivatives for texture coordinates used by the 5 non- base textures. dFdx() and dFdy() were called for nontrivial texture coordinate manipulation. - New control randomise_texture_lookups added at top of ws30-ALS-ultra.frag, in the development tools section. Setting this to 1 will do a stress test of ground texture array lookups. A fast random number generation function is used to assign each landclass 4 random textures from the ground texture array - this is done by . Performance will not be as bad in the full ALS port as some texture slots will better caching in memory - e.g. have 1 or a few variants. - Possible optimisation: use a 2nd or 3rd texture array for some of the non-base texture slots that typically have 256, 512, or 1024 textures. The resolutions of these arrays should change based on the largest loaded texture size in the active regional definitions - this will allow taking full advantage of smaller texture sizes in some areas. The disadvantage is some texture duplication with more slots. - Possible optimisation: offer the option to shrink textures by 50% or 25% - for texture slots that use large textures like base or mix slots. - Very temporary - reduce procedural normal map features with photoscenery active without breaking profiling, as the inputs to shaders are effect defaults or placeholder (by request on ML). ---- ws30-ALS-ultra.vert: - Start of conversion of geocentic world space xyz into lat/lon coords used for ground texture lookups. Currently commented out as it's unknown what model space coords are in (not geocentric it seems). ws20-ALS-landclass-search-functions.frag: - Add control for changing the ground texture array lookup function for debugging in case old compilers/GPUs have issues. tex_lookup_type: 0: normal( textureGrad(), 1: textureLod (manual Lod calculation), 2: texture() with no partial derivative adjustment. - New get6_random_integers() will extract 6 limited random values from the full precision of a 32 bit random value. - Old landclass_texel_size_m references are removed since textureSize() is used. There are no 'const in float' arguments that may cause issues on AMD compilers. ---- WS30-overlay effect (Inactive): - ws30-overlay.eff (derived from terrain-overlay.eff). Technique no "4" is used for two passes. The 1st pass is a copy of the ALS ultra pass (technique no "5") from ws30.eff. The 2nd pass is the same as terrain-overlay.eff. The 2nd pass uses terrain- overlay.frag from WS2. - grass-ALS.vert copied to ws30-ovelay-ALS.vert. To do: needs texture coords that don't change with tiles. - terrain-overlay-ALS.geom copied to ws30-overlay-ALS.geom. To do: uses gl_PositionIn [i].xy for position in the horizontal plane - assumes z is vertical. Tile model space doesn't seem to match this. - WS3 doesn't seem to have a way of switching references to terrain-overlay.eff (which inherits from terrain-default.eff) to the new ws3-overlay.eff (which needs to inherit from ws30.eff). The ws3-overlay.eff included /might/ just work without any other changes: the first pass is the WS3 als ultra settings pass, and the second overlay pass is unchanged from WS2 (the same terrain overlay shaders should probably work apart from texcoords and rawpos not being correct). - Materials/base/materials-base.xml: ws30Road material: uncomment line declaring terrain-default as the effect. The target effect for ws30 roads is road-*.eff and it's added to ws30Road and ws30Freeway but commented out as it's not working currently. - Misc: large scale transitions are turned on in ws30-ALS-landclass-search-functions.frag by default. Grow landclass borders with large scale transitions is now on by default. ---- Changes after the multi-texture support commit: ws30-ALS-ultra.vert - Added documentation: WS30 model space and z up space - for future people working on WS30, and people looking through shaders to rule out possibilities e.g. when fixing bugs, or interpreting visual bug reports. ws30-ALS-landclass-search-functions.frag: - For now, lookup_ground_texture_array() also looks up the relevant texture's index based on an integer. - Add get_mixed_texel() - looks up texel for this fragment and any neighbors before mixing. Moves currently shared mixing code out of 3 fragment shaders. Misc: changed indentation from mixed tabs/spaces to spaces in ws30-ALS-ultra frag and vert. The indentation can be changed again when the porting is complete. ws30-ALS vert/frag and ws30-ALS-detailed vert/frag: - Add varying for ground texture coordiante, currently set to gl_TexCoord[0]. Apply texture stretching dimensions in fragment shaders. - Misc: varying rawPos is set to vec2 for now, as relPos.z+eye_alt might be faster. Misc: keep WS2 mixing logic for now , including turning off mixing via the alpha channel of the textures ---- Changes after sending material parameters in uniform arrays commit: - Materials parameter for rock_strata is cast into an int so rock_strata==1 should work. Misc: Left over uniform for rock strata cleaned up. - ws30-ALS-ultra.frag and ws30-ALS-detailed.frag: Add missing mat_shininess for photoscenery case .
2022-01-03 15:43:29 +00:00
///////////////////////////////////////////
// Test phase code:
//
// Coords for ground textures
// Due to precision issues coordinates should restart (i.e. go to zero) every 5000m or so.
const float restart_dist_m = 5000.0;
// Model position
vec3 mp = gl_Vertex.xyz;
WS30 shaders: Add WS3 detailed technique using the "6" slot. Port the ALS haze, lighting, and math parts of the detailed and ultra shaders. The texture lookups are left out. Shader selection based on terrain quality setting: - Ultra - ws30-ALS-ultra frag/vert. - High and Medium - ws30-ALS-detailed frag/vert. The shaders switch code paths based on quality level uniform. - Low - ws30-ALS frag/vert. Changelog: ws30-ALS vertex shaders: - Ambient colour material colour doesn't seem to be used in the vertex shader, and isn't sent to fragment shaders currently. Regional materials only define non-default ambient colour of vec4(0.0) for water, ocean etc. Otherwise the default value of vec4(0.2, 0.2, 0.2, 1.0) is used. ws30-ALS.frag: - Set alpha of color to diffuse_term.a, to be consistent with WS2 implementation. ws30-ALS-ultra.frag and ws30-ALS-detailed.frag - World pos is assigned a value to allow noise functions to compile. - Swatch_size is temporarily set to 2000m instead of the xsize texture dimension to allow noise math to run while landclass search and texture arrays are being looked up. Swatch_size is used to adjust the wavelength of multiple overlay mixing noise wavelengths based on how far the textures are stretched (WiP WS2 feature). There are some noise calculations that could run while the first landclass lookup happens. If this is not enough, the selection of calculated noise wavelengths to add could change based on how far the textures are stretched, instead of changing the wavelengths at calculation time. - Move photoscenery technique no "4" after technique no "7" without changing the index (in case the low index is needed for photoscenery). This makes viewing a diff with the WS2 effect easier. Performance: Currently there's only 1 ground texture lookup and landclass transitions for that texture. The ultra shader looks up 5 more textures. Probably transitions for 1 more texture need to be supported, as often a base and overlay texture are mixed contributing heavily to visible colour. The math overhead is mostly present, except for noise math being better hidden than in the eventual version. Some of the texture array lookups in the full version may be hidden by the math - depending on GPU memory handling compared to calculation speed.
2021-11-09 14:25:09 +00:00
WS30: MR #267: Improved texture lookups from VS Squashed commit of the following: commit 115511888c20c53670eba17a82c81c9af99d7302 Author: vs <vs2009@mail.com> Date: Mon Dec 6 18:52:06 2021 +1000 WS30 effects and shaders: Changelog: ws30-ALS-ultra.frag: - Ground textures lookups use their own coordinates separate from the landclass texture lookup. - Partial derivatives dFdx and Dfdy are packed together in a vec4, so simple multiplication to scale can be done in 1 instruction. dFdx = s and t components. dFdy = p and q components. These must be scaled properly for ground texture access as ground texture stretching and detiling of tex coords mean textures are scaled differently. - Added calculation of partial derivatives for texture coordinates used by the 5 non- base textures. dFdx() and dFdy() were called for nontrivial texture coordinate manipulation. - New control randomise_texture_lookups added at top of ws30-ALS-ultra.frag, in the development tools section. Setting this to 1 will do a stress test of ground texture array lookups. A fast random number generation function is used to assign each landclass 4 random textures from the ground texture array - this is done by . Performance will not be as bad in the full ALS port as some texture slots will better caching in memory - e.g. have 1 or a few variants. - Possible optimisation: use a 2nd or 3rd texture array for some of the non-base texture slots that typically have 256, 512, or 1024 textures. The resolutions of these arrays should change based on the largest loaded texture size in the active regional definitions - this will allow taking full advantage of smaller texture sizes in some areas. The disadvantage is some texture duplication with more slots. - Possible optimisation: offer the option to shrink textures by 50% or 25% - for texture slots that use large textures like base or mix slots. - Very temporary - reduce procedural normal map features with photoscenery active without breaking profiling, as the inputs to shaders are effect defaults or placeholder (by request on ML). ---- ws30-ALS-ultra.vert: - Start of conversion of geocentic world space xyz into lat/lon coords used for ground texture lookups. Currently commented out as it's unknown what model space coords are in (not geocentric it seems). ws20-ALS-landclass-search-functions.frag: - Add control for changing the ground texture array lookup function for debugging in case old compilers/GPUs have issues. tex_lookup_type: 0: normal( textureGrad(), 1: textureLod (manual Lod calculation), 2: texture() with no partial derivative adjustment. - New get6_random_integers() will extract 6 limited random values from the full precision of a 32 bit random value. - Old landclass_texel_size_m references are removed since textureSize() is used. There are no 'const in float' arguments that may cause issues on AMD compilers. ---- WS30-overlay effect (Inactive): - ws30-overlay.eff (derived from terrain-overlay.eff). Technique no "4" is used for two passes. The 1st pass is a copy of the ALS ultra pass (technique no "5") from ws30.eff. The 2nd pass is the same as terrain-overlay.eff. The 2nd pass uses terrain- overlay.frag from WS2. - grass-ALS.vert copied to ws30-ovelay-ALS.vert. To do: needs texture coords that don't change with tiles. - terrain-overlay-ALS.geom copied to ws30-overlay-ALS.geom. To do: uses gl_PositionIn [i].xy for position in the horizontal plane - assumes z is vertical. Tile model space doesn't seem to match this. - WS3 doesn't seem to have a way of switching references to terrain-overlay.eff (which inherits from terrain-default.eff) to the new ws3-overlay.eff (which needs to inherit from ws30.eff). The ws3-overlay.eff included /might/ just work without any other changes: the first pass is the WS3 als ultra settings pass, and the second overlay pass is unchanged from WS2 (the same terrain overlay shaders should probably work apart from texcoords and rawpos not being correct). - Materials/base/materials-base.xml: ws30Road material: uncomment line declaring terrain-default as the effect. The target effect for ws30 roads is road-*.eff and it's added to ws30Road and ws30Freeway but commented out as it's not working currently. - Misc: large scale transitions are turned on in ws30-ALS-landclass-search-functions.frag by default. Grow landclass borders with large scale transitions is now on by default. ---- Changes after the multi-texture support commit: ws30-ALS-ultra.vert - Added documentation: WS30 model space and z up space - for future people working on WS30, and people looking through shaders to rule out possibilities e.g. when fixing bugs, or interpreting visual bug reports. ws30-ALS-landclass-search-functions.frag: - For now, lookup_ground_texture_array() also looks up the relevant texture's index based on an integer. - Add get_mixed_texel() - looks up texel for this fragment and any neighbors before mixing. Moves currently shared mixing code out of 3 fragment shaders. Misc: changed indentation from mixed tabs/spaces to spaces in ws30-ALS-ultra frag and vert. The indentation can be changed again when the porting is complete. ws30-ALS vert/frag and ws30-ALS-detailed vert/frag: - Add varying for ground texture coordiante, currently set to gl_TexCoord[0]. Apply texture stretching dimensions in fragment shaders. - Misc: varying rawPos is set to vec2 for now, as relPos.z+eye_alt might be faster. Misc: keep WS2 mixing logic for now , including turning off mixing via the alpha channel of the textures ---- Changes after sending material parameters in uniform arrays commit: - Materials parameter for rock_strata is cast into an int so rock_strata==1 should work. Misc: Left over uniform for rock strata cleaned up. - ws30-ALS-ultra.frag and ws30-ALS-detailed.frag: Add missing mat_shininess for photoscenery case .
2022-01-03 15:43:29 +00:00
// Temporary approximation to get shaders to compile:
ground_tex_coord = gl_TexCoord[0].st;
WS30: landclass and texture lookups in fragment shader commit e131ffaca7b2c934474f0e447b5852cb4c7c8d4a Author: vs <vs2009@mail.com> Date: Fri Oct 15 22:19:42 2021 +1000 WS30: landclass and texture lookups in fragment shader: Changelog: - Testing: Procedural random landclass function, get_random_landclass(). 1). Avoids a texture lookup for profiling. 2). Creates squares of configurable size with controllable random landclass ranges - to test landclass transition algorithms and quickly profile lots of landclasses in view. It's also possible to put pressure on GPU memory even with 1 lookup of ground textures per fragment, by reducing size to <20m and viewing from altitude. - Add ALS ultra technique as no 5, move existing ALS technique to no. 6. Add WS30-ALS-ultra frag & vert in preparation for eventual ALS ultra port. Change comments/variables to match using a texture array instead of atlas. Sampler name: atlas -> textureArray. - Testing/optimisation of de-tiling: WS30-ALS.frag: reorder perlin detiling to make noise source easier to switch. WS30-ALS-ultra.frag: Create alternative to perlin noise used for reducing tiling that avoids a texture lookup - to profile and optimise. This is commented out. The performance difference in the final version depends on memory pressure versus arithmetic load of the full shader. It varies by GPU and what's in view. In future, once a full ALS port is done, maybe it'll be more efficient to run a higher quality de-tiling algorithm all the time to avoid branching overhead due to effects like agriculture which need more de-tiling. De-tiling code in shaders should /eventually/ match CPU-side de-tiling of texture masks used for object and vegetation placement. De-tiling code in GPUs might be subject to precision and numerical artifacts, and if so maybe the texture lookup version would work better. The same applies to noise used for rendering WS3 water waves and collision queries. One option is to use exactly the same glsl code, with a C++ header to convert glsl syntax e.g. https://github.com/g-truc/glm .
2021-10-21 20:31:03 +00:00
WS30: MR #267: Improved texture lookups from VS Squashed commit of the following: commit 115511888c20c53670eba17a82c81c9af99d7302 Author: vs <vs2009@mail.com> Date: Mon Dec 6 18:52:06 2021 +1000 WS30 effects and shaders: Changelog: ws30-ALS-ultra.frag: - Ground textures lookups use their own coordinates separate from the landclass texture lookup. - Partial derivatives dFdx and Dfdy are packed together in a vec4, so simple multiplication to scale can be done in 1 instruction. dFdx = s and t components. dFdy = p and q components. These must be scaled properly for ground texture access as ground texture stretching and detiling of tex coords mean textures are scaled differently. - Added calculation of partial derivatives for texture coordinates used by the 5 non- base textures. dFdx() and dFdy() were called for nontrivial texture coordinate manipulation. - New control randomise_texture_lookups added at top of ws30-ALS-ultra.frag, in the development tools section. Setting this to 1 will do a stress test of ground texture array lookups. A fast random number generation function is used to assign each landclass 4 random textures from the ground texture array - this is done by . Performance will not be as bad in the full ALS port as some texture slots will better caching in memory - e.g. have 1 or a few variants. - Possible optimisation: use a 2nd or 3rd texture array for some of the non-base texture slots that typically have 256, 512, or 1024 textures. The resolutions of these arrays should change based on the largest loaded texture size in the active regional definitions - this will allow taking full advantage of smaller texture sizes in some areas. The disadvantage is some texture duplication with more slots. - Possible optimisation: offer the option to shrink textures by 50% or 25% - for texture slots that use large textures like base or mix slots. - Very temporary - reduce procedural normal map features with photoscenery active without breaking profiling, as the inputs to shaders are effect defaults or placeholder (by request on ML). ---- ws30-ALS-ultra.vert: - Start of conversion of geocentic world space xyz into lat/lon coords used for ground texture lookups. Currently commented out as it's unknown what model space coords are in (not geocentric it seems). ws20-ALS-landclass-search-functions.frag: - Add control for changing the ground texture array lookup function for debugging in case old compilers/GPUs have issues. tex_lookup_type: 0: normal( textureGrad(), 1: textureLod (manual Lod calculation), 2: texture() with no partial derivative adjustment. - New get6_random_integers() will extract 6 limited random values from the full precision of a 32 bit random value. - Old landclass_texel_size_m references are removed since textureSize() is used. There are no 'const in float' arguments that may cause issues on AMD compilers. ---- WS30-overlay effect (Inactive): - ws30-overlay.eff (derived from terrain-overlay.eff). Technique no "4" is used for two passes. The 1st pass is a copy of the ALS ultra pass (technique no "5") from ws30.eff. The 2nd pass is the same as terrain-overlay.eff. The 2nd pass uses terrain- overlay.frag from WS2. - grass-ALS.vert copied to ws30-ovelay-ALS.vert. To do: needs texture coords that don't change with tiles. - terrain-overlay-ALS.geom copied to ws30-overlay-ALS.geom. To do: uses gl_PositionIn [i].xy for position in the horizontal plane - assumes z is vertical. Tile model space doesn't seem to match this. - WS3 doesn't seem to have a way of switching references to terrain-overlay.eff (which inherits from terrain-default.eff) to the new ws3-overlay.eff (which needs to inherit from ws30.eff). The ws3-overlay.eff included /might/ just work without any other changes: the first pass is the WS3 als ultra settings pass, and the second overlay pass is unchanged from WS2 (the same terrain overlay shaders should probably work apart from texcoords and rawpos not being correct). - Materials/base/materials-base.xml: ws30Road material: uncomment line declaring terrain-default as the effect. The target effect for ws30 roads is road-*.eff and it's added to ws30Road and ws30Freeway but commented out as it's not working currently. - Misc: large scale transitions are turned on in ws30-ALS-landclass-search-functions.frag by default. Grow landclass borders with large scale transitions is now on by default. ---- Changes after the multi-texture support commit: ws30-ALS-ultra.vert - Added documentation: WS30 model space and z up space - for future people working on WS30, and people looking through shaders to rule out possibilities e.g. when fixing bugs, or interpreting visual bug reports. ws30-ALS-landclass-search-functions.frag: - For now, lookup_ground_texture_array() also looks up the relevant texture's index based on an integer. - Add get_mixed_texel() - looks up texel for this fragment and any neighbors before mixing. Moves currently shared mixing code out of 3 fragment shaders. Misc: changed indentation from mixed tabs/spaces to spaces in ws30-ALS-ultra frag and vert. The indentation can be changed again when the porting is complete. ws30-ALS vert/frag and ws30-ALS-detailed vert/frag: - Add varying for ground texture coordiante, currently set to gl_TexCoord[0]. Apply texture stretching dimensions in fragment shaders. - Misc: varying rawPos is set to vec2 for now, as relPos.z+eye_alt might be faster. Misc: keep WS2 mixing logic for now , including turning off mixing via the alpha channel of the textures ---- Changes after sending material parameters in uniform arrays commit: - Materials parameter for rock_strata is cast into an int so rock_strata==1 should work. Misc: Left over uniform for rock strata cleaned up. - ws30-ALS-ultra.frag and ws30-ALS-detailed.frag: Add missing mat_shininess for photoscenery case .
2022-01-03 15:43:29 +00:00
//
// End test phase code
///////////////////////////////////////////
// WS2:
// first current altitude of eye position in model space
// vec4 ep = gl_ModelViewMatrixInverse * vec4(0.0,0.0,0.0,1.0);
// and relative position to vector
//relPos = gl_Vertex.xyz - ep.xyz;
// Transform for frame of reference where:
// +z is in the up direction.
// The orientation of x and y axes are unknown currently.
// The origin is at the same position as the model space origin.
// The units are in meters.
mat4 viewSpaceToZUpSpace = fg_zUpTransform * gl_ModelViewMatrixInverse;
vec4 vertexZUp = fg_zUpTransform * gl_Vertex;
WS30: landclass and texture lookups in fragment shader commit e131ffaca7b2c934474f0e447b5852cb4c7c8d4a Author: vs <vs2009@mail.com> Date: Fri Oct 15 22:19:42 2021 +1000 WS30: landclass and texture lookups in fragment shader: Changelog: - Testing: Procedural random landclass function, get_random_landclass(). 1). Avoids a texture lookup for profiling. 2). Creates squares of configurable size with controllable random landclass ranges - to test landclass transition algorithms and quickly profile lots of landclasses in view. It's also possible to put pressure on GPU memory even with 1 lookup of ground textures per fragment, by reducing size to <20m and viewing from altitude. - Add ALS ultra technique as no 5, move existing ALS technique to no. 6. Add WS30-ALS-ultra frag & vert in preparation for eventual ALS ultra port. Change comments/variables to match using a texture array instead of atlas. Sampler name: atlas -> textureArray. - Testing/optimisation of de-tiling: WS30-ALS.frag: reorder perlin detiling to make noise source easier to switch. WS30-ALS-ultra.frag: Create alternative to perlin noise used for reducing tiling that avoids a texture lookup - to profile and optimise. This is commented out. The performance difference in the final version depends on memory pressure versus arithmetic load of the full shader. It varies by GPU and what's in view. In future, once a full ALS port is done, maybe it'll be more efficient to run a higher quality de-tiling algorithm all the time to avoid branching overhead due to effects like agriculture which need more de-tiling. De-tiling code in shaders should /eventually/ match CPU-side de-tiling of texture masks used for object and vegetation placement. De-tiling code in GPUs might be subject to precision and numerical artifacts, and if so maybe the texture lookup version would work better. The same applies to noise used for rendering WS3 water waves and collision queries. One option is to use exactly the same glsl code, with a C++ header to convert glsl syntax e.g. https://github.com/g-truc/glm .
2021-10-21 20:31:03 +00:00
WS30: MR #267: Improved texture lookups from VS Squashed commit of the following: commit 115511888c20c53670eba17a82c81c9af99d7302 Author: vs <vs2009@mail.com> Date: Mon Dec 6 18:52:06 2021 +1000 WS30 effects and shaders: Changelog: ws30-ALS-ultra.frag: - Ground textures lookups use their own coordinates separate from the landclass texture lookup. - Partial derivatives dFdx and Dfdy are packed together in a vec4, so simple multiplication to scale can be done in 1 instruction. dFdx = s and t components. dFdy = p and q components. These must be scaled properly for ground texture access as ground texture stretching and detiling of tex coords mean textures are scaled differently. - Added calculation of partial derivatives for texture coordinates used by the 5 non- base textures. dFdx() and dFdy() were called for nontrivial texture coordinate manipulation. - New control randomise_texture_lookups added at top of ws30-ALS-ultra.frag, in the development tools section. Setting this to 1 will do a stress test of ground texture array lookups. A fast random number generation function is used to assign each landclass 4 random textures from the ground texture array - this is done by . Performance will not be as bad in the full ALS port as some texture slots will better caching in memory - e.g. have 1 or a few variants. - Possible optimisation: use a 2nd or 3rd texture array for some of the non-base texture slots that typically have 256, 512, or 1024 textures. The resolutions of these arrays should change based on the largest loaded texture size in the active regional definitions - this will allow taking full advantage of smaller texture sizes in some areas. The disadvantage is some texture duplication with more slots. - Possible optimisation: offer the option to shrink textures by 50% or 25% - for texture slots that use large textures like base or mix slots. - Very temporary - reduce procedural normal map features with photoscenery active without breaking profiling, as the inputs to shaders are effect defaults or placeholder (by request on ML). ---- ws30-ALS-ultra.vert: - Start of conversion of geocentic world space xyz into lat/lon coords used for ground texture lookups. Currently commented out as it's unknown what model space coords are in (not geocentric it seems). ws20-ALS-landclass-search-functions.frag: - Add control for changing the ground texture array lookup function for debugging in case old compilers/GPUs have issues. tex_lookup_type: 0: normal( textureGrad(), 1: textureLod (manual Lod calculation), 2: texture() with no partial derivative adjustment. - New get6_random_integers() will extract 6 limited random values from the full precision of a 32 bit random value. - Old landclass_texel_size_m references are removed since textureSize() is used. There are no 'const in float' arguments that may cause issues on AMD compilers. ---- WS30-overlay effect (Inactive): - ws30-overlay.eff (derived from terrain-overlay.eff). Technique no "4" is used for two passes. The 1st pass is a copy of the ALS ultra pass (technique no "5") from ws30.eff. The 2nd pass is the same as terrain-overlay.eff. The 2nd pass uses terrain- overlay.frag from WS2. - grass-ALS.vert copied to ws30-ovelay-ALS.vert. To do: needs texture coords that don't change with tiles. - terrain-overlay-ALS.geom copied to ws30-overlay-ALS.geom. To do: uses gl_PositionIn [i].xy for position in the horizontal plane - assumes z is vertical. Tile model space doesn't seem to match this. - WS3 doesn't seem to have a way of switching references to terrain-overlay.eff (which inherits from terrain-default.eff) to the new ws3-overlay.eff (which needs to inherit from ws30.eff). The ws3-overlay.eff included /might/ just work without any other changes: the first pass is the WS3 als ultra settings pass, and the second overlay pass is unchanged from WS2 (the same terrain overlay shaders should probably work apart from texcoords and rawpos not being correct). - Materials/base/materials-base.xml: ws30Road material: uncomment line declaring terrain-default as the effect. The target effect for ws30 roads is road-*.eff and it's added to ws30Road and ws30Freeway but commented out as it's not working currently. - Misc: large scale transitions are turned on in ws30-ALS-landclass-search-functions.frag by default. Grow landclass borders with large scale transitions is now on by default. ---- Changes after the multi-texture support commit: ws30-ALS-ultra.vert - Added documentation: WS30 model space and z up space - for future people working on WS30, and people looking through shaders to rule out possibilities e.g. when fixing bugs, or interpreting visual bug reports. ws30-ALS-landclass-search-functions.frag: - For now, lookup_ground_texture_array() also looks up the relevant texture's index based on an integer. - Add get_mixed_texel() - looks up texel for this fragment and any neighbors before mixing. Moves currently shared mixing code out of 3 fragment shaders. Misc: changed indentation from mixed tabs/spaces to spaces in ws30-ALS-ultra frag and vert. The indentation can be changed again when the porting is complete. ws30-ALS vert/frag and ws30-ALS-detailed vert/frag: - Add varying for ground texture coordiante, currently set to gl_TexCoord[0]. Apply texture stretching dimensions in fragment shaders. - Misc: varying rawPos is set to vec2 for now, as relPos.z+eye_alt might be faster. Misc: keep WS2 mixing logic for now , including turning off mixing via the alpha channel of the textures ---- Changes after sending material parameters in uniform arrays commit: - Materials parameter for rock_strata is cast into an int so rock_strata==1 should work. Misc: Left over uniform for rock strata cleaned up. - ws30-ALS-ultra.frag and ws30-ALS-detailed.frag: Add missing mat_shininess for photoscenery case .
2022-01-03 15:43:29 +00:00
// WS2: rawPos = gl_Vertex.xy;
rawPos = vertexZUp.xy;
WS30: landclass and texture lookups in fragment shader commit e131ffaca7b2c934474f0e447b5852cb4c7c8d4a Author: vs <vs2009@mail.com> Date: Fri Oct 15 22:19:42 2021 +1000 WS30: landclass and texture lookups in fragment shader: Changelog: - Testing: Procedural random landclass function, get_random_landclass(). 1). Avoids a texture lookup for profiling. 2). Creates squares of configurable size with controllable random landclass ranges - to test landclass transition algorithms and quickly profile lots of landclasses in view. It's also possible to put pressure on GPU memory even with 1 lookup of ground textures per fragment, by reducing size to <20m and viewing from altitude. - Add ALS ultra technique as no 5, move existing ALS technique to no. 6. Add WS30-ALS-ultra frag & vert in preparation for eventual ALS ultra port. Change comments/variables to match using a texture array instead of atlas. Sampler name: atlas -> textureArray. - Testing/optimisation of de-tiling: WS30-ALS.frag: reorder perlin detiling to make noise source easier to switch. WS30-ALS-ultra.frag: Create alternative to perlin noise used for reducing tiling that avoids a texture lookup - to profile and optimise. This is commented out. The performance difference in the final version depends on memory pressure versus arithmetic load of the full shader. It varies by GPU and what's in view. In future, once a full ALS port is done, maybe it'll be more efficient to run a higher quality de-tiling algorithm all the time to avoid branching overhead due to effects like agriculture which need more de-tiling. De-tiling code in shaders should /eventually/ match CPU-side de-tiling of texture masks used for object and vegetation placement. De-tiling code in GPUs might be subject to precision and numerical artifacts, and if so maybe the texture lookup version would work better. The same applies to noise used for rendering WS3 water waves and collision queries. One option is to use exactly the same glsl code, with a C++ header to convert glsl syntax e.g. https://github.com/g-truc/glm .
2021-10-21 20:31:03 +00:00
WS30: MR #267: Improved texture lookups from VS Squashed commit of the following: commit 115511888c20c53670eba17a82c81c9af99d7302 Author: vs <vs2009@mail.com> Date: Mon Dec 6 18:52:06 2021 +1000 WS30 effects and shaders: Changelog: ws30-ALS-ultra.frag: - Ground textures lookups use their own coordinates separate from the landclass texture lookup. - Partial derivatives dFdx and Dfdy are packed together in a vec4, so simple multiplication to scale can be done in 1 instruction. dFdx = s and t components. dFdy = p and q components. These must be scaled properly for ground texture access as ground texture stretching and detiling of tex coords mean textures are scaled differently. - Added calculation of partial derivatives for texture coordinates used by the 5 non- base textures. dFdx() and dFdy() were called for nontrivial texture coordinate manipulation. - New control randomise_texture_lookups added at top of ws30-ALS-ultra.frag, in the development tools section. Setting this to 1 will do a stress test of ground texture array lookups. A fast random number generation function is used to assign each landclass 4 random textures from the ground texture array - this is done by . Performance will not be as bad in the full ALS port as some texture slots will better caching in memory - e.g. have 1 or a few variants. - Possible optimisation: use a 2nd or 3rd texture array for some of the non-base texture slots that typically have 256, 512, or 1024 textures. The resolutions of these arrays should change based on the largest loaded texture size in the active regional definitions - this will allow taking full advantage of smaller texture sizes in some areas. The disadvantage is some texture duplication with more slots. - Possible optimisation: offer the option to shrink textures by 50% or 25% - for texture slots that use large textures like base or mix slots. - Very temporary - reduce procedural normal map features with photoscenery active without breaking profiling, as the inputs to shaders are effect defaults or placeholder (by request on ML). ---- ws30-ALS-ultra.vert: - Start of conversion of geocentic world space xyz into lat/lon coords used for ground texture lookups. Currently commented out as it's unknown what model space coords are in (not geocentric it seems). ws20-ALS-landclass-search-functions.frag: - Add control for changing the ground texture array lookup function for debugging in case old compilers/GPUs have issues. tex_lookup_type: 0: normal( textureGrad(), 1: textureLod (manual Lod calculation), 2: texture() with no partial derivative adjustment. - New get6_random_integers() will extract 6 limited random values from the full precision of a 32 bit random value. - Old landclass_texel_size_m references are removed since textureSize() is used. There are no 'const in float' arguments that may cause issues on AMD compilers. ---- WS30-overlay effect (Inactive): - ws30-overlay.eff (derived from terrain-overlay.eff). Technique no "4" is used for two passes. The 1st pass is a copy of the ALS ultra pass (technique no "5") from ws30.eff. The 2nd pass is the same as terrain-overlay.eff. The 2nd pass uses terrain- overlay.frag from WS2. - grass-ALS.vert copied to ws30-ovelay-ALS.vert. To do: needs texture coords that don't change with tiles. - terrain-overlay-ALS.geom copied to ws30-overlay-ALS.geom. To do: uses gl_PositionIn [i].xy for position in the horizontal plane - assumes z is vertical. Tile model space doesn't seem to match this. - WS3 doesn't seem to have a way of switching references to terrain-overlay.eff (which inherits from terrain-default.eff) to the new ws3-overlay.eff (which needs to inherit from ws30.eff). The ws3-overlay.eff included /might/ just work without any other changes: the first pass is the WS3 als ultra settings pass, and the second overlay pass is unchanged from WS2 (the same terrain overlay shaders should probably work apart from texcoords and rawpos not being correct). - Materials/base/materials-base.xml: ws30Road material: uncomment line declaring terrain-default as the effect. The target effect for ws30 roads is road-*.eff and it's added to ws30Road and ws30Freeway but commented out as it's not working currently. - Misc: large scale transitions are turned on in ws30-ALS-landclass-search-functions.frag by default. Grow landclass borders with large scale transitions is now on by default. ---- Changes after the multi-texture support commit: ws30-ALS-ultra.vert - Added documentation: WS30 model space and z up space - for future people working on WS30, and people looking through shaders to rule out possibilities e.g. when fixing bugs, or interpreting visual bug reports. ws30-ALS-landclass-search-functions.frag: - For now, lookup_ground_texture_array() also looks up the relevant texture's index based on an integer. - Add get_mixed_texel() - looks up texel for this fragment and any neighbors before mixing. Moves currently shared mixing code out of 3 fragment shaders. Misc: changed indentation from mixed tabs/spaces to spaces in ws30-ALS-ultra frag and vert. The indentation can be changed again when the porting is complete. ws30-ALS vert/frag and ws30-ALS-detailed vert/frag: - Add varying for ground texture coordiante, currently set to gl_TexCoord[0]. Apply texture stretching dimensions in fragment shaders. - Misc: varying rawPos is set to vec2 for now, as relPos.z+eye_alt might be faster. Misc: keep WS2 mixing logic for now , including turning off mixing via the alpha channel of the textures ---- Changes after sending material parameters in uniform arrays commit: - Materials parameter for rock_strata is cast into an int so rock_strata==1 should work. Misc: Left over uniform for rock strata cleaned up. - ws30-ALS-ultra.frag and ws30-ALS-detailed.frag: Add missing mat_shininess for photoscenery case .
2022-01-03 15:43:29 +00:00
// WS2: worldPos = (osg_ViewMatrixInverse *gl_ModelViewMatrix * gl_Vertex).xyz;
worldPos = fg_modelOffset + gl_Vertex.xyz;
steepness = abs(dot(normalize(vec3(fg_zUpTransform * vec4(gl_Normal,1.0))), vec3 (0.0, 0.0, 1.0)));
WS30: MR #267: Improved texture lookups from VS Squashed commit of the following: commit 115511888c20c53670eba17a82c81c9af99d7302 Author: vs <vs2009@mail.com> Date: Mon Dec 6 18:52:06 2021 +1000 WS30 effects and shaders: Changelog: ws30-ALS-ultra.frag: - Ground textures lookups use their own coordinates separate from the landclass texture lookup. - Partial derivatives dFdx and Dfdy are packed together in a vec4, so simple multiplication to scale can be done in 1 instruction. dFdx = s and t components. dFdy = p and q components. These must be scaled properly for ground texture access as ground texture stretching and detiling of tex coords mean textures are scaled differently. - Added calculation of partial derivatives for texture coordinates used by the 5 non- base textures. dFdx() and dFdy() were called for nontrivial texture coordinate manipulation. - New control randomise_texture_lookups added at top of ws30-ALS-ultra.frag, in the development tools section. Setting this to 1 will do a stress test of ground texture array lookups. A fast random number generation function is used to assign each landclass 4 random textures from the ground texture array - this is done by . Performance will not be as bad in the full ALS port as some texture slots will better caching in memory - e.g. have 1 or a few variants. - Possible optimisation: use a 2nd or 3rd texture array for some of the non-base texture slots that typically have 256, 512, or 1024 textures. The resolutions of these arrays should change based on the largest loaded texture size in the active regional definitions - this will allow taking full advantage of smaller texture sizes in some areas. The disadvantage is some texture duplication with more slots. - Possible optimisation: offer the option to shrink textures by 50% or 25% - for texture slots that use large textures like base or mix slots. - Very temporary - reduce procedural normal map features with photoscenery active without breaking profiling, as the inputs to shaders are effect defaults or placeholder (by request on ML). ---- ws30-ALS-ultra.vert: - Start of conversion of geocentic world space xyz into lat/lon coords used for ground texture lookups. Currently commented out as it's unknown what model space coords are in (not geocentric it seems). ws20-ALS-landclass-search-functions.frag: - Add control for changing the ground texture array lookup function for debugging in case old compilers/GPUs have issues. tex_lookup_type: 0: normal( textureGrad(), 1: textureLod (manual Lod calculation), 2: texture() with no partial derivative adjustment. - New get6_random_integers() will extract 6 limited random values from the full precision of a 32 bit random value. - Old landclass_texel_size_m references are removed since textureSize() is used. There are no 'const in float' arguments that may cause issues on AMD compilers. ---- WS30-overlay effect (Inactive): - ws30-overlay.eff (derived from terrain-overlay.eff). Technique no "4" is used for two passes. The 1st pass is a copy of the ALS ultra pass (technique no "5") from ws30.eff. The 2nd pass is the same as terrain-overlay.eff. The 2nd pass uses terrain- overlay.frag from WS2. - grass-ALS.vert copied to ws30-ovelay-ALS.vert. To do: needs texture coords that don't change with tiles. - terrain-overlay-ALS.geom copied to ws30-overlay-ALS.geom. To do: uses gl_PositionIn [i].xy for position in the horizontal plane - assumes z is vertical. Tile model space doesn't seem to match this. - WS3 doesn't seem to have a way of switching references to terrain-overlay.eff (which inherits from terrain-default.eff) to the new ws3-overlay.eff (which needs to inherit from ws30.eff). The ws3-overlay.eff included /might/ just work without any other changes: the first pass is the WS3 als ultra settings pass, and the second overlay pass is unchanged from WS2 (the same terrain overlay shaders should probably work apart from texcoords and rawpos not being correct). - Materials/base/materials-base.xml: ws30Road material: uncomment line declaring terrain-default as the effect. The target effect for ws30 roads is road-*.eff and it's added to ws30Road and ws30Freeway but commented out as it's not working currently. - Misc: large scale transitions are turned on in ws30-ALS-landclass-search-functions.frag by default. Grow landclass borders with large scale transitions is now on by default. ---- Changes after the multi-texture support commit: ws30-ALS-ultra.vert - Added documentation: WS30 model space and z up space - for future people working on WS30, and people looking through shaders to rule out possibilities e.g. when fixing bugs, or interpreting visual bug reports. ws30-ALS-landclass-search-functions.frag: - For now, lookup_ground_texture_array() also looks up the relevant texture's index based on an integer. - Add get_mixed_texel() - looks up texel for this fragment and any neighbors before mixing. Moves currently shared mixing code out of 3 fragment shaders. Misc: changed indentation from mixed tabs/spaces to spaces in ws30-ALS-ultra frag and vert. The indentation can be changed again when the porting is complete. ws30-ALS vert/frag and ws30-ALS-detailed vert/frag: - Add varying for ground texture coordiante, currently set to gl_TexCoord[0]. Apply texture stretching dimensions in fragment shaders. - Misc: varying rawPos is set to vec2 for now, as relPos.z+eye_alt might be faster. Misc: keep WS2 mixing logic for now , including turning off mixing via the alpha channel of the textures ---- Changes after sending material parameters in uniform arrays commit: - Materials parameter for rock_strata is cast into an int so rock_strata==1 should work. Misc: Left over uniform for rock strata cleaned up. - ws30-ALS-ultra.frag and ws30-ALS-detailed.frag: Add missing mat_shininess for photoscenery case .
2022-01-03 15:43:29 +00:00
// Gradient direction used for small scale noise. In the same space as noise coords, rawpos.xy.
grad_dir = normalize(gl_Normal.xy);
// here start computations for the haze layer
// we need several geometrical quantities
// Eye position in z up space
vec4 epZUp = viewSpaceToZUpSpace * vec4(0.0,0.0,0.0,1.0);
// Position of vertex relative to the eye position in z up space
vec3 relPosZUp = (vertexZUp - epZUp).xyz;
// first current altitude of eye position in model space
vec4 ep = gl_ModelViewMatrixInverse * vec4(0.0,0.0,0.0,1.0);
// Eye position in model space
vec4 epMS = gl_ModelViewMatrixInverse * vec4(0.0,0.0,0.0,1.0);
/*
//old: and relative position to vector. This is also used for cloud shadow positioning.
relPosOld = (fg_zUpTransform * vec4(gl_Vertex - ep)).xyz;
if (any(notEqual(relPosOld, relPosZUp))) relPos = vec3(1000000.0);
*/
WS30: landclass and texture lookups in fragment shader commit e131ffaca7b2c934474f0e447b5852cb4c7c8d4a Author: vs <vs2009@mail.com> Date: Fri Oct 15 22:19:42 2021 +1000 WS30: landclass and texture lookups in fragment shader: Changelog: - Testing: Procedural random landclass function, get_random_landclass(). 1). Avoids a texture lookup for profiling. 2). Creates squares of configurable size with controllable random landclass ranges - to test landclass transition algorithms and quickly profile lots of landclasses in view. It's also possible to put pressure on GPU memory even with 1 lookup of ground textures per fragment, by reducing size to <20m and viewing from altitude. - Add ALS ultra technique as no 5, move existing ALS technique to no. 6. Add WS30-ALS-ultra frag & vert in preparation for eventual ALS ultra port. Change comments/variables to match using a texture array instead of atlas. Sampler name: atlas -> textureArray. - Testing/optimisation of de-tiling: WS30-ALS.frag: reorder perlin detiling to make noise source easier to switch. WS30-ALS-ultra.frag: Create alternative to perlin noise used for reducing tiling that avoids a texture lookup - to profile and optimise. This is commented out. The performance difference in the final version depends on memory pressure versus arithmetic load of the full shader. It varies by GPU and what's in view. In future, once a full ALS port is done, maybe it'll be more efficient to run a higher quality de-tiling algorithm all the time to avoid branching overhead due to effects like agriculture which need more de-tiling. De-tiling code in shaders should /eventually/ match CPU-side de-tiling of texture masks used for object and vegetation placement. De-tiling code in GPUs might be subject to precision and numerical artifacts, and if so maybe the texture lookup version would work better. The same applies to noise used for rendering WS3 water waves and collision queries. One option is to use exactly the same glsl code, with a C++ header to convert glsl syntax e.g. https://github.com/g-truc/glm .
2021-10-21 20:31:03 +00:00
WS30: MR #267: Improved texture lookups from VS Squashed commit of the following: commit 115511888c20c53670eba17a82c81c9af99d7302 Author: vs <vs2009@mail.com> Date: Mon Dec 6 18:52:06 2021 +1000 WS30 effects and shaders: Changelog: ws30-ALS-ultra.frag: - Ground textures lookups use their own coordinates separate from the landclass texture lookup. - Partial derivatives dFdx and Dfdy are packed together in a vec4, so simple multiplication to scale can be done in 1 instruction. dFdx = s and t components. dFdy = p and q components. These must be scaled properly for ground texture access as ground texture stretching and detiling of tex coords mean textures are scaled differently. - Added calculation of partial derivatives for texture coordinates used by the 5 non- base textures. dFdx() and dFdy() were called for nontrivial texture coordinate manipulation. - New control randomise_texture_lookups added at top of ws30-ALS-ultra.frag, in the development tools section. Setting this to 1 will do a stress test of ground texture array lookups. A fast random number generation function is used to assign each landclass 4 random textures from the ground texture array - this is done by . Performance will not be as bad in the full ALS port as some texture slots will better caching in memory - e.g. have 1 or a few variants. - Possible optimisation: use a 2nd or 3rd texture array for some of the non-base texture slots that typically have 256, 512, or 1024 textures. The resolutions of these arrays should change based on the largest loaded texture size in the active regional definitions - this will allow taking full advantage of smaller texture sizes in some areas. The disadvantage is some texture duplication with more slots. - Possible optimisation: offer the option to shrink textures by 50% or 25% - for texture slots that use large textures like base or mix slots. - Very temporary - reduce procedural normal map features with photoscenery active without breaking profiling, as the inputs to shaders are effect defaults or placeholder (by request on ML). ---- ws30-ALS-ultra.vert: - Start of conversion of geocentic world space xyz into lat/lon coords used for ground texture lookups. Currently commented out as it's unknown what model space coords are in (not geocentric it seems). ws20-ALS-landclass-search-functions.frag: - Add control for changing the ground texture array lookup function for debugging in case old compilers/GPUs have issues. tex_lookup_type: 0: normal( textureGrad(), 1: textureLod (manual Lod calculation), 2: texture() with no partial derivative adjustment. - New get6_random_integers() will extract 6 limited random values from the full precision of a 32 bit random value. - Old landclass_texel_size_m references are removed since textureSize() is used. There are no 'const in float' arguments that may cause issues on AMD compilers. ---- WS30-overlay effect (Inactive): - ws30-overlay.eff (derived from terrain-overlay.eff). Technique no "4" is used for two passes. The 1st pass is a copy of the ALS ultra pass (technique no "5") from ws30.eff. The 2nd pass is the same as terrain-overlay.eff. The 2nd pass uses terrain- overlay.frag from WS2. - grass-ALS.vert copied to ws30-ovelay-ALS.vert. To do: needs texture coords that don't change with tiles. - terrain-overlay-ALS.geom copied to ws30-overlay-ALS.geom. To do: uses gl_PositionIn [i].xy for position in the horizontal plane - assumes z is vertical. Tile model space doesn't seem to match this. - WS3 doesn't seem to have a way of switching references to terrain-overlay.eff (which inherits from terrain-default.eff) to the new ws3-overlay.eff (which needs to inherit from ws30.eff). The ws3-overlay.eff included /might/ just work without any other changes: the first pass is the WS3 als ultra settings pass, and the second overlay pass is unchanged from WS2 (the same terrain overlay shaders should probably work apart from texcoords and rawpos not being correct). - Materials/base/materials-base.xml: ws30Road material: uncomment line declaring terrain-default as the effect. The target effect for ws30 roads is road-*.eff and it's added to ws30Road and ws30Freeway but commented out as it's not working currently. - Misc: large scale transitions are turned on in ws30-ALS-landclass-search-functions.frag by default. Grow landclass borders with large scale transitions is now on by default. ---- Changes after the multi-texture support commit: ws30-ALS-ultra.vert - Added documentation: WS30 model space and z up space - for future people working on WS30, and people looking through shaders to rule out possibilities e.g. when fixing bugs, or interpreting visual bug reports. ws30-ALS-landclass-search-functions.frag: - For now, lookup_ground_texture_array() also looks up the relevant texture's index based on an integer. - Add get_mixed_texel() - looks up texel for this fragment and any neighbors before mixing. Moves currently shared mixing code out of 3 fragment shaders. Misc: changed indentation from mixed tabs/spaces to spaces in ws30-ALS-ultra frag and vert. The indentation can be changed again when the porting is complete. ws30-ALS vert/frag and ws30-ALS-detailed vert/frag: - Add varying for ground texture coordiante, currently set to gl_TexCoord[0]. Apply texture stretching dimensions in fragment shaders. - Misc: varying rawPos is set to vec2 for now, as relPos.z+eye_alt might be faster. Misc: keep WS2 mixing logic for now , including turning off mixing via the alpha channel of the textures ---- Changes after sending material parameters in uniform arrays commit: - Materials parameter for rock_strata is cast into an int so rock_strata==1 should work. Misc: Left over uniform for rock strata cleaned up. - ws30-ALS-ultra.frag and ws30-ALS-detailed.frag: Add missing mat_shininess for photoscenery case .
2022-01-03 15:43:29 +00:00
relPos = relPosZUp;
vertVec = relPosZUp;
WS30: MR #267: Improved texture lookups from VS Squashed commit of the following: commit 115511888c20c53670eba17a82c81c9af99d7302 Author: vs <vs2009@mail.com> Date: Mon Dec 6 18:52:06 2021 +1000 WS30 effects and shaders: Changelog: ws30-ALS-ultra.frag: - Ground textures lookups use their own coordinates separate from the landclass texture lookup. - Partial derivatives dFdx and Dfdy are packed together in a vec4, so simple multiplication to scale can be done in 1 instruction. dFdx = s and t components. dFdy = p and q components. These must be scaled properly for ground texture access as ground texture stretching and detiling of tex coords mean textures are scaled differently. - Added calculation of partial derivatives for texture coordinates used by the 5 non- base textures. dFdx() and dFdy() were called for nontrivial texture coordinate manipulation. - New control randomise_texture_lookups added at top of ws30-ALS-ultra.frag, in the development tools section. Setting this to 1 will do a stress test of ground texture array lookups. A fast random number generation function is used to assign each landclass 4 random textures from the ground texture array - this is done by . Performance will not be as bad in the full ALS port as some texture slots will better caching in memory - e.g. have 1 or a few variants. - Possible optimisation: use a 2nd or 3rd texture array for some of the non-base texture slots that typically have 256, 512, or 1024 textures. The resolutions of these arrays should change based on the largest loaded texture size in the active regional definitions - this will allow taking full advantage of smaller texture sizes in some areas. The disadvantage is some texture duplication with more slots. - Possible optimisation: offer the option to shrink textures by 50% or 25% - for texture slots that use large textures like base or mix slots. - Very temporary - reduce procedural normal map features with photoscenery active without breaking profiling, as the inputs to shaders are effect defaults or placeholder (by request on ML). ---- ws30-ALS-ultra.vert: - Start of conversion of geocentic world space xyz into lat/lon coords used for ground texture lookups. Currently commented out as it's unknown what model space coords are in (not geocentric it seems). ws20-ALS-landclass-search-functions.frag: - Add control for changing the ground texture array lookup function for debugging in case old compilers/GPUs have issues. tex_lookup_type: 0: normal( textureGrad(), 1: textureLod (manual Lod calculation), 2: texture() with no partial derivative adjustment. - New get6_random_integers() will extract 6 limited random values from the full precision of a 32 bit random value. - Old landclass_texel_size_m references are removed since textureSize() is used. There are no 'const in float' arguments that may cause issues on AMD compilers. ---- WS30-overlay effect (Inactive): - ws30-overlay.eff (derived from terrain-overlay.eff). Technique no "4" is used for two passes. The 1st pass is a copy of the ALS ultra pass (technique no "5") from ws30.eff. The 2nd pass is the same as terrain-overlay.eff. The 2nd pass uses terrain- overlay.frag from WS2. - grass-ALS.vert copied to ws30-ovelay-ALS.vert. To do: needs texture coords that don't change with tiles. - terrain-overlay-ALS.geom copied to ws30-overlay-ALS.geom. To do: uses gl_PositionIn [i].xy for position in the horizontal plane - assumes z is vertical. Tile model space doesn't seem to match this. - WS3 doesn't seem to have a way of switching references to terrain-overlay.eff (which inherits from terrain-default.eff) to the new ws3-overlay.eff (which needs to inherit from ws30.eff). The ws3-overlay.eff included /might/ just work without any other changes: the first pass is the WS3 als ultra settings pass, and the second overlay pass is unchanged from WS2 (the same terrain overlay shaders should probably work apart from texcoords and rawpos not being correct). - Materials/base/materials-base.xml: ws30Road material: uncomment line declaring terrain-default as the effect. The target effect for ws30 roads is road-*.eff and it's added to ws30Road and ws30Freeway but commented out as it's not working currently. - Misc: large scale transitions are turned on in ws30-ALS-landclass-search-functions.frag by default. Grow landclass borders with large scale transitions is now on by default. ---- Changes after the multi-texture support commit: ws30-ALS-ultra.vert - Added documentation: WS30 model space and z up space - for future people working on WS30, and people looking through shaders to rule out possibilities e.g. when fixing bugs, or interpreting visual bug reports. ws30-ALS-landclass-search-functions.frag: - For now, lookup_ground_texture_array() also looks up the relevant texture's index based on an integer. - Add get_mixed_texel() - looks up texel for this fragment and any neighbors before mixing. Moves currently shared mixing code out of 3 fragment shaders. Misc: changed indentation from mixed tabs/spaces to spaces in ws30-ALS-ultra frag and vert. The indentation can be changed again when the porting is complete. ws30-ALS vert/frag and ws30-ALS-detailed vert/frag: - Add varying for ground texture coordiante, currently set to gl_TexCoord[0]. Apply texture stretching dimensions in fragment shaders. - Misc: varying rawPos is set to vec2 for now, as relPos.z+eye_alt might be faster. Misc: keep WS2 mixing logic for now , including turning off mixing via the alpha channel of the textures ---- Changes after sending material parameters in uniform arrays commit: - Materials parameter for rock_strata is cast into an int so rock_strata==1 should work. Misc: Left over uniform for rock strata cleaned up. - ws30-ALS-ultra.frag and ws30-ALS-detailed.frag: Add missing mat_shininess for photoscenery case .
2022-01-03 15:43:29 +00:00
ecViewdir = (gl_ModelViewMatrix * (epMS - gl_Vertex)).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 above mean sea level in meters.
// This is equal to vertexZUp.z as the model space origin is at mean sea level.
// Somehow zero leads to artefacts, so ensure it is at least 100m.
//WS2: vertex_alt = max(gl_Vertex.z,100.0);
vertex_alt = max(vertexZUp.z,100.0);
scattering = ground_scattering + (1.0 - ground_scattering) * smoothstep(hazeLayerAltitude -100.0, hazeLayerAltitude + 100.0, vertex_alt);
WS30: landclass and texture lookups in fragment shader commit e131ffaca7b2c934474f0e447b5852cb4c7c8d4a Author: vs <vs2009@mail.com> Date: Fri Oct 15 22:19:42 2021 +1000 WS30: landclass and texture lookups in fragment shader: Changelog: - Testing: Procedural random landclass function, get_random_landclass(). 1). Avoids a texture lookup for profiling. 2). Creates squares of configurable size with controllable random landclass ranges - to test landclass transition algorithms and quickly profile lots of landclasses in view. It's also possible to put pressure on GPU memory even with 1 lookup of ground textures per fragment, by reducing size to <20m and viewing from altitude. - Add ALS ultra technique as no 5, move existing ALS technique to no. 6. Add WS30-ALS-ultra frag & vert in preparation for eventual ALS ultra port. Change comments/variables to match using a texture array instead of atlas. Sampler name: atlas -> textureArray. - Testing/optimisation of de-tiling: WS30-ALS.frag: reorder perlin detiling to make noise source easier to switch. WS30-ALS-ultra.frag: Create alternative to perlin noise used for reducing tiling that avoids a texture lookup - to profile and optimise. This is commented out. The performance difference in the final version depends on memory pressure versus arithmetic load of the full shader. It varies by GPU and what's in view. In future, once a full ALS port is done, maybe it'll be more efficient to run a higher quality de-tiling algorithm all the time to avoid branching overhead due to effects like agriculture which need more de-tiling. De-tiling code in shaders should /eventually/ match CPU-side de-tiling of texture masks used for object and vegetation placement. De-tiling code in GPUs might be subject to precision and numerical artifacts, and if so maybe the texture lookup version would work better. The same applies to noise used for rendering WS3 water waves and collision queries. One option is to use exactly the same glsl code, with a C++ header to convert glsl syntax e.g. https://github.com/g-truc/glm .
2021-10-21 20:31:03 +00:00
WS30: MR #267: Improved texture lookups from VS Squashed commit of the following: commit 115511888c20c53670eba17a82c81c9af99d7302 Author: vs <vs2009@mail.com> Date: Mon Dec 6 18:52:06 2021 +1000 WS30 effects and shaders: Changelog: ws30-ALS-ultra.frag: - Ground textures lookups use their own coordinates separate from the landclass texture lookup. - Partial derivatives dFdx and Dfdy are packed together in a vec4, so simple multiplication to scale can be done in 1 instruction. dFdx = s and t components. dFdy = p and q components. These must be scaled properly for ground texture access as ground texture stretching and detiling of tex coords mean textures are scaled differently. - Added calculation of partial derivatives for texture coordinates used by the 5 non- base textures. dFdx() and dFdy() were called for nontrivial texture coordinate manipulation. - New control randomise_texture_lookups added at top of ws30-ALS-ultra.frag, in the development tools section. Setting this to 1 will do a stress test of ground texture array lookups. A fast random number generation function is used to assign each landclass 4 random textures from the ground texture array - this is done by . Performance will not be as bad in the full ALS port as some texture slots will better caching in memory - e.g. have 1 or a few variants. - Possible optimisation: use a 2nd or 3rd texture array for some of the non-base texture slots that typically have 256, 512, or 1024 textures. The resolutions of these arrays should change based on the largest loaded texture size in the active regional definitions - this will allow taking full advantage of smaller texture sizes in some areas. The disadvantage is some texture duplication with more slots. - Possible optimisation: offer the option to shrink textures by 50% or 25% - for texture slots that use large textures like base or mix slots. - Very temporary - reduce procedural normal map features with photoscenery active without breaking profiling, as the inputs to shaders are effect defaults or placeholder (by request on ML). ---- ws30-ALS-ultra.vert: - Start of conversion of geocentic world space xyz into lat/lon coords used for ground texture lookups. Currently commented out as it's unknown what model space coords are in (not geocentric it seems). ws20-ALS-landclass-search-functions.frag: - Add control for changing the ground texture array lookup function for debugging in case old compilers/GPUs have issues. tex_lookup_type: 0: normal( textureGrad(), 1: textureLod (manual Lod calculation), 2: texture() with no partial derivative adjustment. - New get6_random_integers() will extract 6 limited random values from the full precision of a 32 bit random value. - Old landclass_texel_size_m references are removed since textureSize() is used. There are no 'const in float' arguments that may cause issues on AMD compilers. ---- WS30-overlay effect (Inactive): - ws30-overlay.eff (derived from terrain-overlay.eff). Technique no "4" is used for two passes. The 1st pass is a copy of the ALS ultra pass (technique no "5") from ws30.eff. The 2nd pass is the same as terrain-overlay.eff. The 2nd pass uses terrain- overlay.frag from WS2. - grass-ALS.vert copied to ws30-ovelay-ALS.vert. To do: needs texture coords that don't change with tiles. - terrain-overlay-ALS.geom copied to ws30-overlay-ALS.geom. To do: uses gl_PositionIn [i].xy for position in the horizontal plane - assumes z is vertical. Tile model space doesn't seem to match this. - WS3 doesn't seem to have a way of switching references to terrain-overlay.eff (which inherits from terrain-default.eff) to the new ws3-overlay.eff (which needs to inherit from ws30.eff). The ws3-overlay.eff included /might/ just work without any other changes: the first pass is the WS3 als ultra settings pass, and the second overlay pass is unchanged from WS2 (the same terrain overlay shaders should probably work apart from texcoords and rawpos not being correct). - Materials/base/materials-base.xml: ws30Road material: uncomment line declaring terrain-default as the effect. The target effect for ws30 roads is road-*.eff and it's added to ws30Road and ws30Freeway but commented out as it's not working currently. - Misc: large scale transitions are turned on in ws30-ALS-landclass-search-functions.frag by default. Grow landclass borders with large scale transitions is now on by default. ---- Changes after the multi-texture support commit: ws30-ALS-ultra.vert - Added documentation: WS30 model space and z up space - for future people working on WS30, and people looking through shaders to rule out possibilities e.g. when fixing bugs, or interpreting visual bug reports. ws30-ALS-landclass-search-functions.frag: - For now, lookup_ground_texture_array() also looks up the relevant texture's index based on an integer. - Add get_mixed_texel() - looks up texel for this fragment and any neighbors before mixing. Moves currently shared mixing code out of 3 fragment shaders. Misc: changed indentation from mixed tabs/spaces to spaces in ws30-ALS-ultra frag and vert. The indentation can be changed again when the porting is complete. ws30-ALS vert/frag and ws30-ALS-detailed vert/frag: - Add varying for ground texture coordiante, currently set to gl_TexCoord[0]. Apply texture stretching dimensions in fragment shaders. - Misc: varying rawPos is set to vec2 for now, as relPos.z+eye_alt might be faster. Misc: keep WS2 mixing logic for now , including turning off mixing via the alpha channel of the textures ---- Changes after sending material parameters in uniform arrays commit: - Materials parameter for rock_strata is cast into an int so rock_strata==1 should work. Misc: Left over uniform for rock strata cleaned up. - ws30-ALS-ultra.frag and ws30-ALS-detailed.frag: Add missing mat_shininess for photoscenery case .
2022-01-03 15:43:29 +00:00
// branch dependent on daytime
WS30: landclass and texture lookups in fragment shader commit e131ffaca7b2c934474f0e447b5852cb4c7c8d4a Author: vs <vs2009@mail.com> Date: Fri Oct 15 22:19:42 2021 +1000 WS30: landclass and texture lookups in fragment shader: Changelog: - Testing: Procedural random landclass function, get_random_landclass(). 1). Avoids a texture lookup for profiling. 2). Creates squares of configurable size with controllable random landclass ranges - to test landclass transition algorithms and quickly profile lots of landclasses in view. It's also possible to put pressure on GPU memory even with 1 lookup of ground textures per fragment, by reducing size to <20m and viewing from altitude. - Add ALS ultra technique as no 5, move existing ALS technique to no. 6. Add WS30-ALS-ultra frag & vert in preparation for eventual ALS ultra port. Change comments/variables to match using a texture array instead of atlas. Sampler name: atlas -> textureArray. - Testing/optimisation of de-tiling: WS30-ALS.frag: reorder perlin detiling to make noise source easier to switch. WS30-ALS-ultra.frag: Create alternative to perlin noise used for reducing tiling that avoids a texture lookup - to profile and optimise. This is commented out. The performance difference in the final version depends on memory pressure versus arithmetic load of the full shader. It varies by GPU and what's in view. In future, once a full ALS port is done, maybe it'll be more efficient to run a higher quality de-tiling algorithm all the time to avoid branching overhead due to effects like agriculture which need more de-tiling. De-tiling code in shaders should /eventually/ match CPU-side de-tiling of texture masks used for object and vegetation placement. De-tiling code in GPUs might be subject to precision and numerical artifacts, and if so maybe the texture lookup version would work better. The same applies to noise used for rendering WS3 water waves and collision queries. One option is to use exactly the same glsl code, with a C++ header to convert glsl syntax e.g. https://github.com/g-truc/glm .
2021-10-21 20:31:03 +00:00
if (terminator < 1000000.0) // the full, sunrise and sunset computation
{
// establish coordinates relative to sun position
WS30: MR #267: Improved texture lookups from VS Squashed commit of the following: commit 115511888c20c53670eba17a82c81c9af99d7302 Author: vs <vs2009@mail.com> Date: Mon Dec 6 18:52:06 2021 +1000 WS30 effects and shaders: Changelog: ws30-ALS-ultra.frag: - Ground textures lookups use their own coordinates separate from the landclass texture lookup. - Partial derivatives dFdx and Dfdy are packed together in a vec4, so simple multiplication to scale can be done in 1 instruction. dFdx = s and t components. dFdy = p and q components. These must be scaled properly for ground texture access as ground texture stretching and detiling of tex coords mean textures are scaled differently. - Added calculation of partial derivatives for texture coordinates used by the 5 non- base textures. dFdx() and dFdy() were called for nontrivial texture coordinate manipulation. - New control randomise_texture_lookups added at top of ws30-ALS-ultra.frag, in the development tools section. Setting this to 1 will do a stress test of ground texture array lookups. A fast random number generation function is used to assign each landclass 4 random textures from the ground texture array - this is done by . Performance will not be as bad in the full ALS port as some texture slots will better caching in memory - e.g. have 1 or a few variants. - Possible optimisation: use a 2nd or 3rd texture array for some of the non-base texture slots that typically have 256, 512, or 1024 textures. The resolutions of these arrays should change based on the largest loaded texture size in the active regional definitions - this will allow taking full advantage of smaller texture sizes in some areas. The disadvantage is some texture duplication with more slots. - Possible optimisation: offer the option to shrink textures by 50% or 25% - for texture slots that use large textures like base or mix slots. - Very temporary - reduce procedural normal map features with photoscenery active without breaking profiling, as the inputs to shaders are effect defaults or placeholder (by request on ML). ---- ws30-ALS-ultra.vert: - Start of conversion of geocentic world space xyz into lat/lon coords used for ground texture lookups. Currently commented out as it's unknown what model space coords are in (not geocentric it seems). ws20-ALS-landclass-search-functions.frag: - Add control for changing the ground texture array lookup function for debugging in case old compilers/GPUs have issues. tex_lookup_type: 0: normal( textureGrad(), 1: textureLod (manual Lod calculation), 2: texture() with no partial derivative adjustment. - New get6_random_integers() will extract 6 limited random values from the full precision of a 32 bit random value. - Old landclass_texel_size_m references are removed since textureSize() is used. There are no 'const in float' arguments that may cause issues on AMD compilers. ---- WS30-overlay effect (Inactive): - ws30-overlay.eff (derived from terrain-overlay.eff). Technique no "4" is used for two passes. The 1st pass is a copy of the ALS ultra pass (technique no "5") from ws30.eff. The 2nd pass is the same as terrain-overlay.eff. The 2nd pass uses terrain- overlay.frag from WS2. - grass-ALS.vert copied to ws30-ovelay-ALS.vert. To do: needs texture coords that don't change with tiles. - terrain-overlay-ALS.geom copied to ws30-overlay-ALS.geom. To do: uses gl_PositionIn [i].xy for position in the horizontal plane - assumes z is vertical. Tile model space doesn't seem to match this. - WS3 doesn't seem to have a way of switching references to terrain-overlay.eff (which inherits from terrain-default.eff) to the new ws3-overlay.eff (which needs to inherit from ws30.eff). The ws3-overlay.eff included /might/ just work without any other changes: the first pass is the WS3 als ultra settings pass, and the second overlay pass is unchanged from WS2 (the same terrain overlay shaders should probably work apart from texcoords and rawpos not being correct). - Materials/base/materials-base.xml: ws30Road material: uncomment line declaring terrain-default as the effect. The target effect for ws30 roads is road-*.eff and it's added to ws30Road and ws30Freeway but commented out as it's not working currently. - Misc: large scale transitions are turned on in ws30-ALS-landclass-search-functions.frag by default. Grow landclass borders with large scale transitions is now on by default. ---- Changes after the multi-texture support commit: ws30-ALS-ultra.vert - Added documentation: WS30 model space and z up space - for future people working on WS30, and people looking through shaders to rule out possibilities e.g. when fixing bugs, or interpreting visual bug reports. ws30-ALS-landclass-search-functions.frag: - For now, lookup_ground_texture_array() also looks up the relevant texture's index based on an integer. - Add get_mixed_texel() - looks up texel for this fragment and any neighbors before mixing. Moves currently shared mixing code out of 3 fragment shaders. Misc: changed indentation from mixed tabs/spaces to spaces in ws30-ALS-ultra frag and vert. The indentation can be changed again when the porting is complete. ws30-ALS vert/frag and ws30-ALS-detailed vert/frag: - Add varying for ground texture coordiante, currently set to gl_TexCoord[0]. Apply texture stretching dimensions in fragment shaders. - Misc: varying rawPos is set to vec2 for now, as relPos.z+eye_alt might be faster. Misc: keep WS2 mixing logic for now , including turning off mixing via the alpha channel of the textures ---- Changes after sending material parameters in uniform arrays commit: - Materials parameter for rock_strata is cast into an int so rock_strata==1 should work. Misc: Left over uniform for rock strata cleaned up. - ws30-ALS-ultra.frag and ws30-ALS-detailed.frag: Add missing mat_shininess for photoscenery case .
2022-01-03 15:43:29 +00:00
WS30: landclass and texture lookups in fragment shader commit e131ffaca7b2c934474f0e447b5852cb4c7c8d4a Author: vs <vs2009@mail.com> Date: Fri Oct 15 22:19:42 2021 +1000 WS30: landclass and texture lookups in fragment shader: Changelog: - Testing: Procedural random landclass function, get_random_landclass(). 1). Avoids a texture lookup for profiling. 2). Creates squares of configurable size with controllable random landclass ranges - to test landclass transition algorithms and quickly profile lots of landclasses in view. It's also possible to put pressure on GPU memory even with 1 lookup of ground textures per fragment, by reducing size to <20m and viewing from altitude. - Add ALS ultra technique as no 5, move existing ALS technique to no. 6. Add WS30-ALS-ultra frag & vert in preparation for eventual ALS ultra port. Change comments/variables to match using a texture array instead of atlas. Sampler name: atlas -> textureArray. - Testing/optimisation of de-tiling: WS30-ALS.frag: reorder perlin detiling to make noise source easier to switch. WS30-ALS-ultra.frag: Create alternative to perlin noise used for reducing tiling that avoids a texture lookup - to profile and optimise. This is commented out. The performance difference in the final version depends on memory pressure versus arithmetic load of the full shader. It varies by GPU and what's in view. In future, once a full ALS port is done, maybe it'll be more efficient to run a higher quality de-tiling algorithm all the time to avoid branching overhead due to effects like agriculture which need more de-tiling. De-tiling code in shaders should /eventually/ match CPU-side de-tiling of texture masks used for object and vegetation placement. De-tiling code in GPUs might be subject to precision and numerical artifacts, and if so maybe the texture lookup version would work better. The same applies to noise used for rendering WS3 water waves and collision queries. One option is to use exactly the same glsl code, with a C++ header to convert glsl syntax e.g. https://github.com/g-truc/glm .
2021-10-21 20:31:03 +00:00
vec3 lightFull = (gl_ModelViewMatrixInverse * gl_LightSource[0].position).xyz;
vec3 lightHorizon = normalize(vec3(lightFull.x,lightFull.y, 0.0));
// yprime is the distance of the vertex into sun direction
yprime = -dot(relPos, lightHorizon);
WS30: MR #267: Improved texture lookups from VS Squashed commit of the following: commit 115511888c20c53670eba17a82c81c9af99d7302 Author: vs <vs2009@mail.com> Date: Mon Dec 6 18:52:06 2021 +1000 WS30 effects and shaders: Changelog: ws30-ALS-ultra.frag: - Ground textures lookups use their own coordinates separate from the landclass texture lookup. - Partial derivatives dFdx and Dfdy are packed together in a vec4, so simple multiplication to scale can be done in 1 instruction. dFdx = s and t components. dFdy = p and q components. These must be scaled properly for ground texture access as ground texture stretching and detiling of tex coords mean textures are scaled differently. - Added calculation of partial derivatives for texture coordinates used by the 5 non- base textures. dFdx() and dFdy() were called for nontrivial texture coordinate manipulation. - New control randomise_texture_lookups added at top of ws30-ALS-ultra.frag, in the development tools section. Setting this to 1 will do a stress test of ground texture array lookups. A fast random number generation function is used to assign each landclass 4 random textures from the ground texture array - this is done by . Performance will not be as bad in the full ALS port as some texture slots will better caching in memory - e.g. have 1 or a few variants. - Possible optimisation: use a 2nd or 3rd texture array for some of the non-base texture slots that typically have 256, 512, or 1024 textures. The resolutions of these arrays should change based on the largest loaded texture size in the active regional definitions - this will allow taking full advantage of smaller texture sizes in some areas. The disadvantage is some texture duplication with more slots. - Possible optimisation: offer the option to shrink textures by 50% or 25% - for texture slots that use large textures like base or mix slots. - Very temporary - reduce procedural normal map features with photoscenery active without breaking profiling, as the inputs to shaders are effect defaults or placeholder (by request on ML). ---- ws30-ALS-ultra.vert: - Start of conversion of geocentic world space xyz into lat/lon coords used for ground texture lookups. Currently commented out as it's unknown what model space coords are in (not geocentric it seems). ws20-ALS-landclass-search-functions.frag: - Add control for changing the ground texture array lookup function for debugging in case old compilers/GPUs have issues. tex_lookup_type: 0: normal( textureGrad(), 1: textureLod (manual Lod calculation), 2: texture() with no partial derivative adjustment. - New get6_random_integers() will extract 6 limited random values from the full precision of a 32 bit random value. - Old landclass_texel_size_m references are removed since textureSize() is used. There are no 'const in float' arguments that may cause issues on AMD compilers. ---- WS30-overlay effect (Inactive): - ws30-overlay.eff (derived from terrain-overlay.eff). Technique no "4" is used for two passes. The 1st pass is a copy of the ALS ultra pass (technique no "5") from ws30.eff. The 2nd pass is the same as terrain-overlay.eff. The 2nd pass uses terrain- overlay.frag from WS2. - grass-ALS.vert copied to ws30-ovelay-ALS.vert. To do: needs texture coords that don't change with tiles. - terrain-overlay-ALS.geom copied to ws30-overlay-ALS.geom. To do: uses gl_PositionIn [i].xy for position in the horizontal plane - assumes z is vertical. Tile model space doesn't seem to match this. - WS3 doesn't seem to have a way of switching references to terrain-overlay.eff (which inherits from terrain-default.eff) to the new ws3-overlay.eff (which needs to inherit from ws30.eff). The ws3-overlay.eff included /might/ just work without any other changes: the first pass is the WS3 als ultra settings pass, and the second overlay pass is unchanged from WS2 (the same terrain overlay shaders should probably work apart from texcoords and rawpos not being correct). - Materials/base/materials-base.xml: ws30Road material: uncomment line declaring terrain-default as the effect. The target effect for ws30 roads is road-*.eff and it's added to ws30Road and ws30Freeway but commented out as it's not working currently. - Misc: large scale transitions are turned on in ws30-ALS-landclass-search-functions.frag by default. Grow landclass borders with large scale transitions is now on by default. ---- Changes after the multi-texture support commit: ws30-ALS-ultra.vert - Added documentation: WS30 model space and z up space - for future people working on WS30, and people looking through shaders to rule out possibilities e.g. when fixing bugs, or interpreting visual bug reports. ws30-ALS-landclass-search-functions.frag: - For now, lookup_ground_texture_array() also looks up the relevant texture's index based on an integer. - Add get_mixed_texel() - looks up texel for this fragment and any neighbors before mixing. Moves currently shared mixing code out of 3 fragment shaders. Misc: changed indentation from mixed tabs/spaces to spaces in ws30-ALS-ultra frag and vert. The indentation can be changed again when the porting is complete. ws30-ALS vert/frag and ws30-ALS-detailed vert/frag: - Add varying for ground texture coordiante, currently set to gl_TexCoord[0]. Apply texture stretching dimensions in fragment shaders. - Misc: varying rawPos is set to vec2 for now, as relPos.z+eye_alt might be faster. Misc: keep WS2 mixing logic for now , including turning off mixing via the alpha channel of the textures ---- Changes after sending material parameters in uniform arrays commit: - Materials parameter for rock_strata is cast into an int so rock_strata==1 should work. Misc: Left over uniform for rock strata cleaned up. - ws30-ALS-ultra.frag and ws30-ALS-detailed.frag: Add missing mat_shininess for photoscenery case .
2022-01-03 15:43:29 +00:00
WS30: landclass and texture lookups in fragment shader commit e131ffaca7b2c934474f0e447b5852cb4c7c8d4a Author: vs <vs2009@mail.com> Date: Fri Oct 15 22:19:42 2021 +1000 WS30: landclass and texture lookups in fragment shader: Changelog: - Testing: Procedural random landclass function, get_random_landclass(). 1). Avoids a texture lookup for profiling. 2). Creates squares of configurable size with controllable random landclass ranges - to test landclass transition algorithms and quickly profile lots of landclasses in view. It's also possible to put pressure on GPU memory even with 1 lookup of ground textures per fragment, by reducing size to <20m and viewing from altitude. - Add ALS ultra technique as no 5, move existing ALS technique to no. 6. Add WS30-ALS-ultra frag & vert in preparation for eventual ALS ultra port. Change comments/variables to match using a texture array instead of atlas. Sampler name: atlas -> textureArray. - Testing/optimisation of de-tiling: WS30-ALS.frag: reorder perlin detiling to make noise source easier to switch. WS30-ALS-ultra.frag: Create alternative to perlin noise used for reducing tiling that avoids a texture lookup - to profile and optimise. This is commented out. The performance difference in the final version depends on memory pressure versus arithmetic load of the full shader. It varies by GPU and what's in view. In future, once a full ALS port is done, maybe it'll be more efficient to run a higher quality de-tiling algorithm all the time to avoid branching overhead due to effects like agriculture which need more de-tiling. De-tiling code in shaders should /eventually/ match CPU-side de-tiling of texture masks used for object and vegetation placement. De-tiling code in GPUs might be subject to precision and numerical artifacts, and if so maybe the texture lookup version would work better. The same applies to noise used for rendering WS3 water waves and collision queries. One option is to use exactly the same glsl code, with a C++ header to convert glsl syntax e.g. https://github.com/g-truc/glm .
2021-10-21 20:31:03 +00:00
// this gets an altitude correction, higher terrain gets to see the sun earlier
yprime_alt = yprime - sqrt(2.0 * EarthRadius * vertex_alt);
WS30: MR #267: Improved texture lookups from VS Squashed commit of the following: commit 115511888c20c53670eba17a82c81c9af99d7302 Author: vs <vs2009@mail.com> Date: Mon Dec 6 18:52:06 2021 +1000 WS30 effects and shaders: Changelog: ws30-ALS-ultra.frag: - Ground textures lookups use their own coordinates separate from the landclass texture lookup. - Partial derivatives dFdx and Dfdy are packed together in a vec4, so simple multiplication to scale can be done in 1 instruction. dFdx = s and t components. dFdy = p and q components. These must be scaled properly for ground texture access as ground texture stretching and detiling of tex coords mean textures are scaled differently. - Added calculation of partial derivatives for texture coordinates used by the 5 non- base textures. dFdx() and dFdy() were called for nontrivial texture coordinate manipulation. - New control randomise_texture_lookups added at top of ws30-ALS-ultra.frag, in the development tools section. Setting this to 1 will do a stress test of ground texture array lookups. A fast random number generation function is used to assign each landclass 4 random textures from the ground texture array - this is done by . Performance will not be as bad in the full ALS port as some texture slots will better caching in memory - e.g. have 1 or a few variants. - Possible optimisation: use a 2nd or 3rd texture array for some of the non-base texture slots that typically have 256, 512, or 1024 textures. The resolutions of these arrays should change based on the largest loaded texture size in the active regional definitions - this will allow taking full advantage of smaller texture sizes in some areas. The disadvantage is some texture duplication with more slots. - Possible optimisation: offer the option to shrink textures by 50% or 25% - for texture slots that use large textures like base or mix slots. - Very temporary - reduce procedural normal map features with photoscenery active without breaking profiling, as the inputs to shaders are effect defaults or placeholder (by request on ML). ---- ws30-ALS-ultra.vert: - Start of conversion of geocentic world space xyz into lat/lon coords used for ground texture lookups. Currently commented out as it's unknown what model space coords are in (not geocentric it seems). ws20-ALS-landclass-search-functions.frag: - Add control for changing the ground texture array lookup function for debugging in case old compilers/GPUs have issues. tex_lookup_type: 0: normal( textureGrad(), 1: textureLod (manual Lod calculation), 2: texture() with no partial derivative adjustment. - New get6_random_integers() will extract 6 limited random values from the full precision of a 32 bit random value. - Old landclass_texel_size_m references are removed since textureSize() is used. There are no 'const in float' arguments that may cause issues on AMD compilers. ---- WS30-overlay effect (Inactive): - ws30-overlay.eff (derived from terrain-overlay.eff). Technique no "4" is used for two passes. The 1st pass is a copy of the ALS ultra pass (technique no "5") from ws30.eff. The 2nd pass is the same as terrain-overlay.eff. The 2nd pass uses terrain- overlay.frag from WS2. - grass-ALS.vert copied to ws30-ovelay-ALS.vert. To do: needs texture coords that don't change with tiles. - terrain-overlay-ALS.geom copied to ws30-overlay-ALS.geom. To do: uses gl_PositionIn [i].xy for position in the horizontal plane - assumes z is vertical. Tile model space doesn't seem to match this. - WS3 doesn't seem to have a way of switching references to terrain-overlay.eff (which inherits from terrain-default.eff) to the new ws3-overlay.eff (which needs to inherit from ws30.eff). The ws3-overlay.eff included /might/ just work without any other changes: the first pass is the WS3 als ultra settings pass, and the second overlay pass is unchanged from WS2 (the same terrain overlay shaders should probably work apart from texcoords and rawpos not being correct). - Materials/base/materials-base.xml: ws30Road material: uncomment line declaring terrain-default as the effect. The target effect for ws30 roads is road-*.eff and it's added to ws30Road and ws30Freeway but commented out as it's not working currently. - Misc: large scale transitions are turned on in ws30-ALS-landclass-search-functions.frag by default. Grow landclass borders with large scale transitions is now on by default. ---- Changes after the multi-texture support commit: ws30-ALS-ultra.vert - Added documentation: WS30 model space and z up space - for future people working on WS30, and people looking through shaders to rule out possibilities e.g. when fixing bugs, or interpreting visual bug reports. ws30-ALS-landclass-search-functions.frag: - For now, lookup_ground_texture_array() also looks up the relevant texture's index based on an integer. - Add get_mixed_texel() - looks up texel for this fragment and any neighbors before mixing. Moves currently shared mixing code out of 3 fragment shaders. Misc: changed indentation from mixed tabs/spaces to spaces in ws30-ALS-ultra frag and vert. The indentation can be changed again when the porting is complete. ws30-ALS vert/frag and ws30-ALS-detailed vert/frag: - Add varying for ground texture coordiante, currently set to gl_TexCoord[0]. Apply texture stretching dimensions in fragment shaders. - Misc: varying rawPos is set to vec2 for now, as relPos.z+eye_alt might be faster. Misc: keep WS2 mixing logic for now , including turning off mixing via the alpha channel of the textures ---- Changes after sending material parameters in uniform arrays commit: - Materials parameter for rock_strata is cast into an int so rock_strata==1 should work. Misc: Left over uniform for rock strata cleaned up. - ws30-ALS-ultra.frag and ws30-ALS-detailed.frag: Add missing mat_shininess for photoscenery case .
2022-01-03 15:43:29 +00:00
WS30: landclass and texture lookups in fragment shader commit e131ffaca7b2c934474f0e447b5852cb4c7c8d4a Author: vs <vs2009@mail.com> Date: Fri Oct 15 22:19:42 2021 +1000 WS30: landclass and texture lookups in fragment shader: Changelog: - Testing: Procedural random landclass function, get_random_landclass(). 1). Avoids a texture lookup for profiling. 2). Creates squares of configurable size with controllable random landclass ranges - to test landclass transition algorithms and quickly profile lots of landclasses in view. It's also possible to put pressure on GPU memory even with 1 lookup of ground textures per fragment, by reducing size to <20m and viewing from altitude. - Add ALS ultra technique as no 5, move existing ALS technique to no. 6. Add WS30-ALS-ultra frag & vert in preparation for eventual ALS ultra port. Change comments/variables to match using a texture array instead of atlas. Sampler name: atlas -> textureArray. - Testing/optimisation of de-tiling: WS30-ALS.frag: reorder perlin detiling to make noise source easier to switch. WS30-ALS-ultra.frag: Create alternative to perlin noise used for reducing tiling that avoids a texture lookup - to profile and optimise. This is commented out. The performance difference in the final version depends on memory pressure versus arithmetic load of the full shader. It varies by GPU and what's in view. In future, once a full ALS port is done, maybe it'll be more efficient to run a higher quality de-tiling algorithm all the time to avoid branching overhead due to effects like agriculture which need more de-tiling. De-tiling code in shaders should /eventually/ match CPU-side de-tiling of texture masks used for object and vegetation placement. De-tiling code in GPUs might be subject to precision and numerical artifacts, and if so maybe the texture lookup version would work better. The same applies to noise used for rendering WS3 water waves and collision queries. One option is to use exactly the same glsl code, with a C++ header to convert glsl syntax e.g. https://github.com/g-truc/glm .
2021-10-21 20:31:03 +00:00
// two times terminator width governs how quickly light fades into shadow
// now the light-dimming factor
earthShade = 0.6 * (1.0 - smoothstep(-terminator_width+ terminator, terminator_width + terminator, yprime_alt)) + 0.4;
WS30: MR #267: Improved texture lookups from VS Squashed commit of the following: commit 115511888c20c53670eba17a82c81c9af99d7302 Author: vs <vs2009@mail.com> Date: Mon Dec 6 18:52:06 2021 +1000 WS30 effects and shaders: Changelog: ws30-ALS-ultra.frag: - Ground textures lookups use their own coordinates separate from the landclass texture lookup. - Partial derivatives dFdx and Dfdy are packed together in a vec4, so simple multiplication to scale can be done in 1 instruction. dFdx = s and t components. dFdy = p and q components. These must be scaled properly for ground texture access as ground texture stretching and detiling of tex coords mean textures are scaled differently. - Added calculation of partial derivatives for texture coordinates used by the 5 non- base textures. dFdx() and dFdy() were called for nontrivial texture coordinate manipulation. - New control randomise_texture_lookups added at top of ws30-ALS-ultra.frag, in the development tools section. Setting this to 1 will do a stress test of ground texture array lookups. A fast random number generation function is used to assign each landclass 4 random textures from the ground texture array - this is done by . Performance will not be as bad in the full ALS port as some texture slots will better caching in memory - e.g. have 1 or a few variants. - Possible optimisation: use a 2nd or 3rd texture array for some of the non-base texture slots that typically have 256, 512, or 1024 textures. The resolutions of these arrays should change based on the largest loaded texture size in the active regional definitions - this will allow taking full advantage of smaller texture sizes in some areas. The disadvantage is some texture duplication with more slots. - Possible optimisation: offer the option to shrink textures by 50% or 25% - for texture slots that use large textures like base or mix slots. - Very temporary - reduce procedural normal map features with photoscenery active without breaking profiling, as the inputs to shaders are effect defaults or placeholder (by request on ML). ---- ws30-ALS-ultra.vert: - Start of conversion of geocentic world space xyz into lat/lon coords used for ground texture lookups. Currently commented out as it's unknown what model space coords are in (not geocentric it seems). ws20-ALS-landclass-search-functions.frag: - Add control for changing the ground texture array lookup function for debugging in case old compilers/GPUs have issues. tex_lookup_type: 0: normal( textureGrad(), 1: textureLod (manual Lod calculation), 2: texture() with no partial derivative adjustment. - New get6_random_integers() will extract 6 limited random values from the full precision of a 32 bit random value. - Old landclass_texel_size_m references are removed since textureSize() is used. There are no 'const in float' arguments that may cause issues on AMD compilers. ---- WS30-overlay effect (Inactive): - ws30-overlay.eff (derived from terrain-overlay.eff). Technique no "4" is used for two passes. The 1st pass is a copy of the ALS ultra pass (technique no "5") from ws30.eff. The 2nd pass is the same as terrain-overlay.eff. The 2nd pass uses terrain- overlay.frag from WS2. - grass-ALS.vert copied to ws30-ovelay-ALS.vert. To do: needs texture coords that don't change with tiles. - terrain-overlay-ALS.geom copied to ws30-overlay-ALS.geom. To do: uses gl_PositionIn [i].xy for position in the horizontal plane - assumes z is vertical. Tile model space doesn't seem to match this. - WS3 doesn't seem to have a way of switching references to terrain-overlay.eff (which inherits from terrain-default.eff) to the new ws3-overlay.eff (which needs to inherit from ws30.eff). The ws3-overlay.eff included /might/ just work without any other changes: the first pass is the WS3 als ultra settings pass, and the second overlay pass is unchanged from WS2 (the same terrain overlay shaders should probably work apart from texcoords and rawpos not being correct). - Materials/base/materials-base.xml: ws30Road material: uncomment line declaring terrain-default as the effect. The target effect for ws30 roads is road-*.eff and it's added to ws30Road and ws30Freeway but commented out as it's not working currently. - Misc: large scale transitions are turned on in ws30-ALS-landclass-search-functions.frag by default. Grow landclass borders with large scale transitions is now on by default. ---- Changes after the multi-texture support commit: ws30-ALS-ultra.vert - Added documentation: WS30 model space and z up space - for future people working on WS30, and people looking through shaders to rule out possibilities e.g. when fixing bugs, or interpreting visual bug reports. ws30-ALS-landclass-search-functions.frag: - For now, lookup_ground_texture_array() also looks up the relevant texture's index based on an integer. - Add get_mixed_texel() - looks up texel for this fragment and any neighbors before mixing. Moves currently shared mixing code out of 3 fragment shaders. Misc: changed indentation from mixed tabs/spaces to spaces in ws30-ALS-ultra frag and vert. The indentation can be changed again when the porting is complete. ws30-ALS vert/frag and ws30-ALS-detailed vert/frag: - Add varying for ground texture coordiante, currently set to gl_TexCoord[0]. Apply texture stretching dimensions in fragment shaders. - Misc: varying rawPos is set to vec2 for now, as relPos.z+eye_alt might be faster. Misc: keep WS2 mixing logic for now , including turning off mixing via the alpha channel of the textures ---- Changes after sending material parameters in uniform arrays commit: - Materials parameter for rock_strata is cast into an int so rock_strata==1 should work. Misc: Left over uniform for rock strata cleaned up. - ws30-ALS-ultra.frag and ws30-ALS-detailed.frag: Add missing mat_shininess for photoscenery case .
2022-01-03 15:43:29 +00:00
// parametrized version of the Flightgear ground lighting function
WS30: landclass and texture lookups in fragment shader commit e131ffaca7b2c934474f0e447b5852cb4c7c8d4a Author: vs <vs2009@mail.com> Date: Fri Oct 15 22:19:42 2021 +1000 WS30: landclass and texture lookups in fragment shader: Changelog: - Testing: Procedural random landclass function, get_random_landclass(). 1). Avoids a texture lookup for profiling. 2). Creates squares of configurable size with controllable random landclass ranges - to test landclass transition algorithms and quickly profile lots of landclasses in view. It's also possible to put pressure on GPU memory even with 1 lookup of ground textures per fragment, by reducing size to <20m and viewing from altitude. - Add ALS ultra technique as no 5, move existing ALS technique to no. 6. Add WS30-ALS-ultra frag & vert in preparation for eventual ALS ultra port. Change comments/variables to match using a texture array instead of atlas. Sampler name: atlas -> textureArray. - Testing/optimisation of de-tiling: WS30-ALS.frag: reorder perlin detiling to make noise source easier to switch. WS30-ALS-ultra.frag: Create alternative to perlin noise used for reducing tiling that avoids a texture lookup - to profile and optimise. This is commented out. The performance difference in the final version depends on memory pressure versus arithmetic load of the full shader. It varies by GPU and what's in view. In future, once a full ALS port is done, maybe it'll be more efficient to run a higher quality de-tiling algorithm all the time to avoid branching overhead due to effects like agriculture which need more de-tiling. De-tiling code in shaders should /eventually/ match CPU-side de-tiling of texture masks used for object and vegetation placement. De-tiling code in GPUs might be subject to precision and numerical artifacts, and if so maybe the texture lookup version would work better. The same applies to noise used for rendering WS3 water waves and collision queries. One option is to use exactly the same glsl code, with a C++ header to convert glsl syntax e.g. https://github.com/g-truc/glm .
2021-10-21 20:31:03 +00:00
lightArg = (terminator-yprime_alt)/100000.0;
// directional scattering for low sun
if (lightArg < 10.0)
WS30: MR #267: Improved texture lookups from VS Squashed commit of the following: commit 115511888c20c53670eba17a82c81c9af99d7302 Author: vs <vs2009@mail.com> Date: Mon Dec 6 18:52:06 2021 +1000 WS30 effects and shaders: Changelog: ws30-ALS-ultra.frag: - Ground textures lookups use their own coordinates separate from the landclass texture lookup. - Partial derivatives dFdx and Dfdy are packed together in a vec4, so simple multiplication to scale can be done in 1 instruction. dFdx = s and t components. dFdy = p and q components. These must be scaled properly for ground texture access as ground texture stretching and detiling of tex coords mean textures are scaled differently. - Added calculation of partial derivatives for texture coordinates used by the 5 non- base textures. dFdx() and dFdy() were called for nontrivial texture coordinate manipulation. - New control randomise_texture_lookups added at top of ws30-ALS-ultra.frag, in the development tools section. Setting this to 1 will do a stress test of ground texture array lookups. A fast random number generation function is used to assign each landclass 4 random textures from the ground texture array - this is done by . Performance will not be as bad in the full ALS port as some texture slots will better caching in memory - e.g. have 1 or a few variants. - Possible optimisation: use a 2nd or 3rd texture array for some of the non-base texture slots that typically have 256, 512, or 1024 textures. The resolutions of these arrays should change based on the largest loaded texture size in the active regional definitions - this will allow taking full advantage of smaller texture sizes in some areas. The disadvantage is some texture duplication with more slots. - Possible optimisation: offer the option to shrink textures by 50% or 25% - for texture slots that use large textures like base or mix slots. - Very temporary - reduce procedural normal map features with photoscenery active without breaking profiling, as the inputs to shaders are effect defaults or placeholder (by request on ML). ---- ws30-ALS-ultra.vert: - Start of conversion of geocentic world space xyz into lat/lon coords used for ground texture lookups. Currently commented out as it's unknown what model space coords are in (not geocentric it seems). ws20-ALS-landclass-search-functions.frag: - Add control for changing the ground texture array lookup function for debugging in case old compilers/GPUs have issues. tex_lookup_type: 0: normal( textureGrad(), 1: textureLod (manual Lod calculation), 2: texture() with no partial derivative adjustment. - New get6_random_integers() will extract 6 limited random values from the full precision of a 32 bit random value. - Old landclass_texel_size_m references are removed since textureSize() is used. There are no 'const in float' arguments that may cause issues on AMD compilers. ---- WS30-overlay effect (Inactive): - ws30-overlay.eff (derived from terrain-overlay.eff). Technique no "4" is used for two passes. The 1st pass is a copy of the ALS ultra pass (technique no "5") from ws30.eff. The 2nd pass is the same as terrain-overlay.eff. The 2nd pass uses terrain- overlay.frag from WS2. - grass-ALS.vert copied to ws30-ovelay-ALS.vert. To do: needs texture coords that don't change with tiles. - terrain-overlay-ALS.geom copied to ws30-overlay-ALS.geom. To do: uses gl_PositionIn [i].xy for position in the horizontal plane - assumes z is vertical. Tile model space doesn't seem to match this. - WS3 doesn't seem to have a way of switching references to terrain-overlay.eff (which inherits from terrain-default.eff) to the new ws3-overlay.eff (which needs to inherit from ws30.eff). The ws3-overlay.eff included /might/ just work without any other changes: the first pass is the WS3 als ultra settings pass, and the second overlay pass is unchanged from WS2 (the same terrain overlay shaders should probably work apart from texcoords and rawpos not being correct). - Materials/base/materials-base.xml: ws30Road material: uncomment line declaring terrain-default as the effect. The target effect for ws30 roads is road-*.eff and it's added to ws30Road and ws30Freeway but commented out as it's not working currently. - Misc: large scale transitions are turned on in ws30-ALS-landclass-search-functions.frag by default. Grow landclass borders with large scale transitions is now on by default. ---- Changes after the multi-texture support commit: ws30-ALS-ultra.vert - Added documentation: WS30 model space and z up space - for future people working on WS30, and people looking through shaders to rule out possibilities e.g. when fixing bugs, or interpreting visual bug reports. ws30-ALS-landclass-search-functions.frag: - For now, lookup_ground_texture_array() also looks up the relevant texture's index based on an integer. - Add get_mixed_texel() - looks up texel for this fragment and any neighbors before mixing. Moves currently shared mixing code out of 3 fragment shaders. Misc: changed indentation from mixed tabs/spaces to spaces in ws30-ALS-ultra frag and vert. The indentation can be changed again when the porting is complete. ws30-ALS vert/frag and ws30-ALS-detailed vert/frag: - Add varying for ground texture coordiante, currently set to gl_TexCoord[0]. Apply texture stretching dimensions in fragment shaders. - Misc: varying rawPos is set to vec2 for now, as relPos.z+eye_alt might be faster. Misc: keep WS2 mixing logic for now , including turning off mixing via the alpha channel of the textures ---- Changes after sending material parameters in uniform arrays commit: - Materials parameter for rock_strata is cast into an int so rock_strata==1 should work. Misc: Left over uniform for rock strata cleaned up. - ws30-ALS-ultra.frag and ws30-ALS-detailed.frag: Add missing mat_shininess for photoscenery case .
2022-01-03 15:43:29 +00:00
{mie_angle = (0.5 * dot(normalize(relPos), normalize(lightFull)) ) + 0.5;}
WS30: landclass and texture lookups in fragment shader commit e131ffaca7b2c934474f0e447b5852cb4c7c8d4a Author: vs <vs2009@mail.com> Date: Fri Oct 15 22:19:42 2021 +1000 WS30: landclass and texture lookups in fragment shader: Changelog: - Testing: Procedural random landclass function, get_random_landclass(). 1). Avoids a texture lookup for profiling. 2). Creates squares of configurable size with controllable random landclass ranges - to test landclass transition algorithms and quickly profile lots of landclasses in view. It's also possible to put pressure on GPU memory even with 1 lookup of ground textures per fragment, by reducing size to <20m and viewing from altitude. - Add ALS ultra technique as no 5, move existing ALS technique to no. 6. Add WS30-ALS-ultra frag & vert in preparation for eventual ALS ultra port. Change comments/variables to match using a texture array instead of atlas. Sampler name: atlas -> textureArray. - Testing/optimisation of de-tiling: WS30-ALS.frag: reorder perlin detiling to make noise source easier to switch. WS30-ALS-ultra.frag: Create alternative to perlin noise used for reducing tiling that avoids a texture lookup - to profile and optimise. This is commented out. The performance difference in the final version depends on memory pressure versus arithmetic load of the full shader. It varies by GPU and what's in view. In future, once a full ALS port is done, maybe it'll be more efficient to run a higher quality de-tiling algorithm all the time to avoid branching overhead due to effects like agriculture which need more de-tiling. De-tiling code in shaders should /eventually/ match CPU-side de-tiling of texture masks used for object and vegetation placement. De-tiling code in GPUs might be subject to precision and numerical artifacts, and if so maybe the texture lookup version would work better. The same applies to noise used for rendering WS3 water waves and collision queries. One option is to use exactly the same glsl code, with a C++ header to convert glsl syntax e.g. https://github.com/g-truc/glm .
2021-10-21 20:31:03 +00:00
else
WS30: MR #267: Improved texture lookups from VS Squashed commit of the following: commit 115511888c20c53670eba17a82c81c9af99d7302 Author: vs <vs2009@mail.com> Date: Mon Dec 6 18:52:06 2021 +1000 WS30 effects and shaders: Changelog: ws30-ALS-ultra.frag: - Ground textures lookups use their own coordinates separate from the landclass texture lookup. - Partial derivatives dFdx and Dfdy are packed together in a vec4, so simple multiplication to scale can be done in 1 instruction. dFdx = s and t components. dFdy = p and q components. These must be scaled properly for ground texture access as ground texture stretching and detiling of tex coords mean textures are scaled differently. - Added calculation of partial derivatives for texture coordinates used by the 5 non- base textures. dFdx() and dFdy() were called for nontrivial texture coordinate manipulation. - New control randomise_texture_lookups added at top of ws30-ALS-ultra.frag, in the development tools section. Setting this to 1 will do a stress test of ground texture array lookups. A fast random number generation function is used to assign each landclass 4 random textures from the ground texture array - this is done by . Performance will not be as bad in the full ALS port as some texture slots will better caching in memory - e.g. have 1 or a few variants. - Possible optimisation: use a 2nd or 3rd texture array for some of the non-base texture slots that typically have 256, 512, or 1024 textures. The resolutions of these arrays should change based on the largest loaded texture size in the active regional definitions - this will allow taking full advantage of smaller texture sizes in some areas. The disadvantage is some texture duplication with more slots. - Possible optimisation: offer the option to shrink textures by 50% or 25% - for texture slots that use large textures like base or mix slots. - Very temporary - reduce procedural normal map features with photoscenery active without breaking profiling, as the inputs to shaders are effect defaults or placeholder (by request on ML). ---- ws30-ALS-ultra.vert: - Start of conversion of geocentic world space xyz into lat/lon coords used for ground texture lookups. Currently commented out as it's unknown what model space coords are in (not geocentric it seems). ws20-ALS-landclass-search-functions.frag: - Add control for changing the ground texture array lookup function for debugging in case old compilers/GPUs have issues. tex_lookup_type: 0: normal( textureGrad(), 1: textureLod (manual Lod calculation), 2: texture() with no partial derivative adjustment. - New get6_random_integers() will extract 6 limited random values from the full precision of a 32 bit random value. - Old landclass_texel_size_m references are removed since textureSize() is used. There are no 'const in float' arguments that may cause issues on AMD compilers. ---- WS30-overlay effect (Inactive): - ws30-overlay.eff (derived from terrain-overlay.eff). Technique no "4" is used for two passes. The 1st pass is a copy of the ALS ultra pass (technique no "5") from ws30.eff. The 2nd pass is the same as terrain-overlay.eff. The 2nd pass uses terrain- overlay.frag from WS2. - grass-ALS.vert copied to ws30-ovelay-ALS.vert. To do: needs texture coords that don't change with tiles. - terrain-overlay-ALS.geom copied to ws30-overlay-ALS.geom. To do: uses gl_PositionIn [i].xy for position in the horizontal plane - assumes z is vertical. Tile model space doesn't seem to match this. - WS3 doesn't seem to have a way of switching references to terrain-overlay.eff (which inherits from terrain-default.eff) to the new ws3-overlay.eff (which needs to inherit from ws30.eff). The ws3-overlay.eff included /might/ just work without any other changes: the first pass is the WS3 als ultra settings pass, and the second overlay pass is unchanged from WS2 (the same terrain overlay shaders should probably work apart from texcoords and rawpos not being correct). - Materials/base/materials-base.xml: ws30Road material: uncomment line declaring terrain-default as the effect. The target effect for ws30 roads is road-*.eff and it's added to ws30Road and ws30Freeway but commented out as it's not working currently. - Misc: large scale transitions are turned on in ws30-ALS-landclass-search-functions.frag by default. Grow landclass borders with large scale transitions is now on by default. ---- Changes after the multi-texture support commit: ws30-ALS-ultra.vert - Added documentation: WS30 model space and z up space - for future people working on WS30, and people looking through shaders to rule out possibilities e.g. when fixing bugs, or interpreting visual bug reports. ws30-ALS-landclass-search-functions.frag: - For now, lookup_ground_texture_array() also looks up the relevant texture's index based on an integer. - Add get_mixed_texel() - looks up texel for this fragment and any neighbors before mixing. Moves currently shared mixing code out of 3 fragment shaders. Misc: changed indentation from mixed tabs/spaces to spaces in ws30-ALS-ultra frag and vert. The indentation can be changed again when the porting is complete. ws30-ALS vert/frag and ws30-ALS-detailed vert/frag: - Add varying for ground texture coordiante, currently set to gl_TexCoord[0]. Apply texture stretching dimensions in fragment shaders. - Misc: varying rawPos is set to vec2 for now, as relPos.z+eye_alt might be faster. Misc: keep WS2 mixing logic for now , including turning off mixing via the alpha channel of the textures ---- Changes after sending material parameters in uniform arrays commit: - Materials parameter for rock_strata is cast into an int so rock_strata==1 should work. Misc: Left over uniform for rock strata cleaned up. - ws30-ALS-ultra.frag and ws30-ALS-detailed.frag: Add missing mat_shininess for photoscenery case .
2022-01-03 15:43:29 +00:00
{mie_angle = 1.0;}
WS30: landclass and texture lookups in fragment shader commit e131ffaca7b2c934474f0e447b5852cb4c7c8d4a Author: vs <vs2009@mail.com> Date: Fri Oct 15 22:19:42 2021 +1000 WS30: landclass and texture lookups in fragment shader: Changelog: - Testing: Procedural random landclass function, get_random_landclass(). 1). Avoids a texture lookup for profiling. 2). Creates squares of configurable size with controllable random landclass ranges - to test landclass transition algorithms and quickly profile lots of landclasses in view. It's also possible to put pressure on GPU memory even with 1 lookup of ground textures per fragment, by reducing size to <20m and viewing from altitude. - Add ALS ultra technique as no 5, move existing ALS technique to no. 6. Add WS30-ALS-ultra frag & vert in preparation for eventual ALS ultra port. Change comments/variables to match using a texture array instead of atlas. Sampler name: atlas -> textureArray. - Testing/optimisation of de-tiling: WS30-ALS.frag: reorder perlin detiling to make noise source easier to switch. WS30-ALS-ultra.frag: Create alternative to perlin noise used for reducing tiling that avoids a texture lookup - to profile and optimise. This is commented out. The performance difference in the final version depends on memory pressure versus arithmetic load of the full shader. It varies by GPU and what's in view. In future, once a full ALS port is done, maybe it'll be more efficient to run a higher quality de-tiling algorithm all the time to avoid branching overhead due to effects like agriculture which need more de-tiling. De-tiling code in shaders should /eventually/ match CPU-side de-tiling of texture masks used for object and vegetation placement. De-tiling code in GPUs might be subject to precision and numerical artifacts, and if so maybe the texture lookup version would work better. The same applies to noise used for rendering WS3 water waves and collision queries. One option is to use exactly the same glsl code, with a C++ header to convert glsl syntax e.g. https://github.com/g-truc/glm .
2021-10-21 20:31:03 +00:00
WS30: MR #267: Improved texture lookups from VS Squashed commit of the following: commit 115511888c20c53670eba17a82c81c9af99d7302 Author: vs <vs2009@mail.com> Date: Mon Dec 6 18:52:06 2021 +1000 WS30 effects and shaders: Changelog: ws30-ALS-ultra.frag: - Ground textures lookups use their own coordinates separate from the landclass texture lookup. - Partial derivatives dFdx and Dfdy are packed together in a vec4, so simple multiplication to scale can be done in 1 instruction. dFdx = s and t components. dFdy = p and q components. These must be scaled properly for ground texture access as ground texture stretching and detiling of tex coords mean textures are scaled differently. - Added calculation of partial derivatives for texture coordinates used by the 5 non- base textures. dFdx() and dFdy() were called for nontrivial texture coordinate manipulation. - New control randomise_texture_lookups added at top of ws30-ALS-ultra.frag, in the development tools section. Setting this to 1 will do a stress test of ground texture array lookups. A fast random number generation function is used to assign each landclass 4 random textures from the ground texture array - this is done by . Performance will not be as bad in the full ALS port as some texture slots will better caching in memory - e.g. have 1 or a few variants. - Possible optimisation: use a 2nd or 3rd texture array for some of the non-base texture slots that typically have 256, 512, or 1024 textures. The resolutions of these arrays should change based on the largest loaded texture size in the active regional definitions - this will allow taking full advantage of smaller texture sizes in some areas. The disadvantage is some texture duplication with more slots. - Possible optimisation: offer the option to shrink textures by 50% or 25% - for texture slots that use large textures like base or mix slots. - Very temporary - reduce procedural normal map features with photoscenery active without breaking profiling, as the inputs to shaders are effect defaults or placeholder (by request on ML). ---- ws30-ALS-ultra.vert: - Start of conversion of geocentic world space xyz into lat/lon coords used for ground texture lookups. Currently commented out as it's unknown what model space coords are in (not geocentric it seems). ws20-ALS-landclass-search-functions.frag: - Add control for changing the ground texture array lookup function for debugging in case old compilers/GPUs have issues. tex_lookup_type: 0: normal( textureGrad(), 1: textureLod (manual Lod calculation), 2: texture() with no partial derivative adjustment. - New get6_random_integers() will extract 6 limited random values from the full precision of a 32 bit random value. - Old landclass_texel_size_m references are removed since textureSize() is used. There are no 'const in float' arguments that may cause issues on AMD compilers. ---- WS30-overlay effect (Inactive): - ws30-overlay.eff (derived from terrain-overlay.eff). Technique no "4" is used for two passes. The 1st pass is a copy of the ALS ultra pass (technique no "5") from ws30.eff. The 2nd pass is the same as terrain-overlay.eff. The 2nd pass uses terrain- overlay.frag from WS2. - grass-ALS.vert copied to ws30-ovelay-ALS.vert. To do: needs texture coords that don't change with tiles. - terrain-overlay-ALS.geom copied to ws30-overlay-ALS.geom. To do: uses gl_PositionIn [i].xy for position in the horizontal plane - assumes z is vertical. Tile model space doesn't seem to match this. - WS3 doesn't seem to have a way of switching references to terrain-overlay.eff (which inherits from terrain-default.eff) to the new ws3-overlay.eff (which needs to inherit from ws30.eff). The ws3-overlay.eff included /might/ just work without any other changes: the first pass is the WS3 als ultra settings pass, and the second overlay pass is unchanged from WS2 (the same terrain overlay shaders should probably work apart from texcoords and rawpos not being correct). - Materials/base/materials-base.xml: ws30Road material: uncomment line declaring terrain-default as the effect. The target effect for ws30 roads is road-*.eff and it's added to ws30Road and ws30Freeway but commented out as it's not working currently. - Misc: large scale transitions are turned on in ws30-ALS-landclass-search-functions.frag by default. Grow landclass borders with large scale transitions is now on by default. ---- Changes after the multi-texture support commit: ws30-ALS-ultra.vert - Added documentation: WS30 model space and z up space - for future people working on WS30, and people looking through shaders to rule out possibilities e.g. when fixing bugs, or interpreting visual bug reports. ws30-ALS-landclass-search-functions.frag: - For now, lookup_ground_texture_array() also looks up the relevant texture's index based on an integer. - Add get_mixed_texel() - looks up texel for this fragment and any neighbors before mixing. Moves currently shared mixing code out of 3 fragment shaders. Misc: changed indentation from mixed tabs/spaces to spaces in ws30-ALS-ultra frag and vert. The indentation can be changed again when the porting is complete. ws30-ALS vert/frag and ws30-ALS-detailed vert/frag: - Add varying for ground texture coordiante, currently set to gl_TexCoord[0]. Apply texture stretching dimensions in fragment shaders. - Misc: varying rawPos is set to vec2 for now, as relPos.z+eye_alt might be faster. Misc: keep WS2 mixing logic for now , including turning off mixing via the alpha channel of the textures ---- Changes after sending material parameters in uniform arrays commit: - Materials parameter for rock_strata is cast into an int so rock_strata==1 should work. Misc: Left over uniform for rock strata cleaned up. - ws30-ALS-ultra.frag and ws30-ALS-detailed.frag: Add missing mat_shininess for photoscenery case .
2022-01-03 15:43:29 +00:00
light_diffuse.b = light_func(lightArg, 1.330e-05, 0.264, 3.827, 1.08e-05, 1.0);
light_diffuse.g = light_func(lightArg, 3.931e-06, 0.264, 3.827, 7.93e-06, 1.0);
light_diffuse.r = light_func(lightArg, 8.305e-06, 0.161, 3.827, 3.04e-05, 1.0);
light_diffuse.a = 1.0;
light_diffuse = light_diffuse * scattering;
WS30: landclass and texture lookups in fragment shader commit e131ffaca7b2c934474f0e447b5852cb4c7c8d4a Author: vs <vs2009@mail.com> Date: Fri Oct 15 22:19:42 2021 +1000 WS30: landclass and texture lookups in fragment shader: Changelog: - Testing: Procedural random landclass function, get_random_landclass(). 1). Avoids a texture lookup for profiling. 2). Creates squares of configurable size with controllable random landclass ranges - to test landclass transition algorithms and quickly profile lots of landclasses in view. It's also possible to put pressure on GPU memory even with 1 lookup of ground textures per fragment, by reducing size to <20m and viewing from altitude. - Add ALS ultra technique as no 5, move existing ALS technique to no. 6. Add WS30-ALS-ultra frag & vert in preparation for eventual ALS ultra port. Change comments/variables to match using a texture array instead of atlas. Sampler name: atlas -> textureArray. - Testing/optimisation of de-tiling: WS30-ALS.frag: reorder perlin detiling to make noise source easier to switch. WS30-ALS-ultra.frag: Create alternative to perlin noise used for reducing tiling that avoids a texture lookup - to profile and optimise. This is commented out. The performance difference in the final version depends on memory pressure versus arithmetic load of the full shader. It varies by GPU and what's in view. In future, once a full ALS port is done, maybe it'll be more efficient to run a higher quality de-tiling algorithm all the time to avoid branching overhead due to effects like agriculture which need more de-tiling. De-tiling code in shaders should /eventually/ match CPU-side de-tiling of texture masks used for object and vegetation placement. De-tiling code in GPUs might be subject to precision and numerical artifacts, and if so maybe the texture lookup version would work better. The same applies to noise used for rendering WS3 water waves and collision queries. One option is to use exactly the same glsl code, with a C++ header to convert glsl syntax e.g. https://github.com/g-truc/glm .
2021-10-21 20:31:03 +00:00
WS30: MR #267: Improved texture lookups from VS Squashed commit of the following: commit 115511888c20c53670eba17a82c81c9af99d7302 Author: vs <vs2009@mail.com> Date: Mon Dec 6 18:52:06 2021 +1000 WS30 effects and shaders: Changelog: ws30-ALS-ultra.frag: - Ground textures lookups use their own coordinates separate from the landclass texture lookup. - Partial derivatives dFdx and Dfdy are packed together in a vec4, so simple multiplication to scale can be done in 1 instruction. dFdx = s and t components. dFdy = p and q components. These must be scaled properly for ground texture access as ground texture stretching and detiling of tex coords mean textures are scaled differently. - Added calculation of partial derivatives for texture coordinates used by the 5 non- base textures. dFdx() and dFdy() were called for nontrivial texture coordinate manipulation. - New control randomise_texture_lookups added at top of ws30-ALS-ultra.frag, in the development tools section. Setting this to 1 will do a stress test of ground texture array lookups. A fast random number generation function is used to assign each landclass 4 random textures from the ground texture array - this is done by . Performance will not be as bad in the full ALS port as some texture slots will better caching in memory - e.g. have 1 or a few variants. - Possible optimisation: use a 2nd or 3rd texture array for some of the non-base texture slots that typically have 256, 512, or 1024 textures. The resolutions of these arrays should change based on the largest loaded texture size in the active regional definitions - this will allow taking full advantage of smaller texture sizes in some areas. The disadvantage is some texture duplication with more slots. - Possible optimisation: offer the option to shrink textures by 50% or 25% - for texture slots that use large textures like base or mix slots. - Very temporary - reduce procedural normal map features with photoscenery active without breaking profiling, as the inputs to shaders are effect defaults or placeholder (by request on ML). ---- ws30-ALS-ultra.vert: - Start of conversion of geocentic world space xyz into lat/lon coords used for ground texture lookups. Currently commented out as it's unknown what model space coords are in (not geocentric it seems). ws20-ALS-landclass-search-functions.frag: - Add control for changing the ground texture array lookup function for debugging in case old compilers/GPUs have issues. tex_lookup_type: 0: normal( textureGrad(), 1: textureLod (manual Lod calculation), 2: texture() with no partial derivative adjustment. - New get6_random_integers() will extract 6 limited random values from the full precision of a 32 bit random value. - Old landclass_texel_size_m references are removed since textureSize() is used. There are no 'const in float' arguments that may cause issues on AMD compilers. ---- WS30-overlay effect (Inactive): - ws30-overlay.eff (derived from terrain-overlay.eff). Technique no "4" is used for two passes. The 1st pass is a copy of the ALS ultra pass (technique no "5") from ws30.eff. The 2nd pass is the same as terrain-overlay.eff. The 2nd pass uses terrain- overlay.frag from WS2. - grass-ALS.vert copied to ws30-ovelay-ALS.vert. To do: needs texture coords that don't change with tiles. - terrain-overlay-ALS.geom copied to ws30-overlay-ALS.geom. To do: uses gl_PositionIn [i].xy for position in the horizontal plane - assumes z is vertical. Tile model space doesn't seem to match this. - WS3 doesn't seem to have a way of switching references to terrain-overlay.eff (which inherits from terrain-default.eff) to the new ws3-overlay.eff (which needs to inherit from ws30.eff). The ws3-overlay.eff included /might/ just work without any other changes: the first pass is the WS3 als ultra settings pass, and the second overlay pass is unchanged from WS2 (the same terrain overlay shaders should probably work apart from texcoords and rawpos not being correct). - Materials/base/materials-base.xml: ws30Road material: uncomment line declaring terrain-default as the effect. The target effect for ws30 roads is road-*.eff and it's added to ws30Road and ws30Freeway but commented out as it's not working currently. - Misc: large scale transitions are turned on in ws30-ALS-landclass-search-functions.frag by default. Grow landclass borders with large scale transitions is now on by default. ---- Changes after the multi-texture support commit: ws30-ALS-ultra.vert - Added documentation: WS30 model space and z up space - for future people working on WS30, and people looking through shaders to rule out possibilities e.g. when fixing bugs, or interpreting visual bug reports. ws30-ALS-landclass-search-functions.frag: - For now, lookup_ground_texture_array() also looks up the relevant texture's index based on an integer. - Add get_mixed_texel() - looks up texel for this fragment and any neighbors before mixing. Moves currently shared mixing code out of 3 fragment shaders. Misc: changed indentation from mixed tabs/spaces to spaces in ws30-ALS-ultra frag and vert. The indentation can be changed again when the porting is complete. ws30-ALS vert/frag and ws30-ALS-detailed vert/frag: - Add varying for ground texture coordiante, currently set to gl_TexCoord[0]. Apply texture stretching dimensions in fragment shaders. - Misc: varying rawPos is set to vec2 for now, as relPos.z+eye_alt might be faster. Misc: keep WS2 mixing logic for now , including turning off mixing via the alpha channel of the textures ---- Changes after sending material parameters in uniform arrays commit: - Materials parameter for rock_strata is cast into an int so rock_strata==1 should work. Misc: Left over uniform for rock strata cleaned up. - ws30-ALS-ultra.frag and ws30-ALS-detailed.frag: Add missing mat_shininess for photoscenery case .
2022-01-03 15:43:29 +00:00
//light_ambient.b = light_func(lightArg, 0.000506, 0.131, -3.315, 0.000457, 0.5);
//light_ambient.g = light_func(lightArg, 2.264e-05, 0.134, 0.967, 3.66e-05, 0.4);
light_ambient.r = light_func(lightArg, 0.236, 0.253, 1.073, 0.572, 0.33);
light_ambient.g = light_ambient.r * 0.4/0.33; //light_func(lightArg, 0.236, 0.253, 1.073, 0.572, 0.4);
light_ambient.b = light_ambient.r * 0.5/0.33; //light_func(lightArg, 0.236, 0.253, 1.073, 0.572, 0.5);
light_ambient.a = 1.0;
WS30: landclass and texture lookups in fragment shader commit e131ffaca7b2c934474f0e447b5852cb4c7c8d4a Author: vs <vs2009@mail.com> Date: Fri Oct 15 22:19:42 2021 +1000 WS30: landclass and texture lookups in fragment shader: Changelog: - Testing: Procedural random landclass function, get_random_landclass(). 1). Avoids a texture lookup for profiling. 2). Creates squares of configurable size with controllable random landclass ranges - to test landclass transition algorithms and quickly profile lots of landclasses in view. It's also possible to put pressure on GPU memory even with 1 lookup of ground textures per fragment, by reducing size to <20m and viewing from altitude. - Add ALS ultra technique as no 5, move existing ALS technique to no. 6. Add WS30-ALS-ultra frag & vert in preparation for eventual ALS ultra port. Change comments/variables to match using a texture array instead of atlas. Sampler name: atlas -> textureArray. - Testing/optimisation of de-tiling: WS30-ALS.frag: reorder perlin detiling to make noise source easier to switch. WS30-ALS-ultra.frag: Create alternative to perlin noise used for reducing tiling that avoids a texture lookup - to profile and optimise. This is commented out. The performance difference in the final version depends on memory pressure versus arithmetic load of the full shader. It varies by GPU and what's in view. In future, once a full ALS port is done, maybe it'll be more efficient to run a higher quality de-tiling algorithm all the time to avoid branching overhead due to effects like agriculture which need more de-tiling. De-tiling code in shaders should /eventually/ match CPU-side de-tiling of texture masks used for object and vegetation placement. De-tiling code in GPUs might be subject to precision and numerical artifacts, and if so maybe the texture lookup version would work better. The same applies to noise used for rendering WS3 water waves and collision queries. One option is to use exactly the same glsl code, with a C++ header to convert glsl syntax e.g. https://github.com/g-truc/glm .
2021-10-21 20:31:03 +00:00
// Water specular calculations
specular_light.b = light_func(lightArg, 1.330e-05, 0.264, 3.827, 1.08e-05, 1.0);
specular_light.g = light_func(lightArg, 3.931e-06, 0.264, 3.827, 7.93e-06, 1.0);
specular_light.r = light_func(lightArg, 8.305e-06, 0.161, 3.827, 3.04e-05, 1.0);
specular_light = max(specular_light * scattering, vec3 (0.05, 0.05, 0.05));
intensity = length(specular_light.rgb);
specular_light.rgb = intensity * normalize(mix(specular_light.rgb, shadedFogColor, 1.0 -smoothstep(0.1, 0.6,ground_scattering) ));
specular_light.rgb = intensity * normalize(mix(specular_light.rgb, shadedFogColor, 1.0 -smoothstep(0.5, 0.7,earthShade)));
WS30: landclass and texture lookups in fragment shader commit e131ffaca7b2c934474f0e447b5852cb4c7c8d4a Author: vs <vs2009@mail.com> Date: Fri Oct 15 22:19:42 2021 +1000 WS30: landclass and texture lookups in fragment shader: Changelog: - Testing: Procedural random landclass function, get_random_landclass(). 1). Avoids a texture lookup for profiling. 2). Creates squares of configurable size with controllable random landclass ranges - to test landclass transition algorithms and quickly profile lots of landclasses in view. It's also possible to put pressure on GPU memory even with 1 lookup of ground textures per fragment, by reducing size to <20m and viewing from altitude. - Add ALS ultra technique as no 5, move existing ALS technique to no. 6. Add WS30-ALS-ultra frag & vert in preparation for eventual ALS ultra port. Change comments/variables to match using a texture array instead of atlas. Sampler name: atlas -> textureArray. - Testing/optimisation of de-tiling: WS30-ALS.frag: reorder perlin detiling to make noise source easier to switch. WS30-ALS-ultra.frag: Create alternative to perlin noise used for reducing tiling that avoids a texture lookup - to profile and optimise. This is commented out. The performance difference in the final version depends on memory pressure versus arithmetic load of the full shader. It varies by GPU and what's in view. In future, once a full ALS port is done, maybe it'll be more efficient to run a higher quality de-tiling algorithm all the time to avoid branching overhead due to effects like agriculture which need more de-tiling. De-tiling code in shaders should /eventually/ match CPU-side de-tiling of texture masks used for object and vegetation placement. De-tiling code in GPUs might be subject to precision and numerical artifacts, and if so maybe the texture lookup version would work better. The same applies to noise used for rendering WS3 water waves and collision queries. One option is to use exactly the same glsl code, with a C++ header to convert glsl syntax e.g. https://github.com/g-truc/glm .
2021-10-21 20:31:03 +00:00
WS30: MR #267: Improved texture lookups from VS Squashed commit of the following: commit 115511888c20c53670eba17a82c81c9af99d7302 Author: vs <vs2009@mail.com> Date: Mon Dec 6 18:52:06 2021 +1000 WS30 effects and shaders: Changelog: ws30-ALS-ultra.frag: - Ground textures lookups use their own coordinates separate from the landclass texture lookup. - Partial derivatives dFdx and Dfdy are packed together in a vec4, so simple multiplication to scale can be done in 1 instruction. dFdx = s and t components. dFdy = p and q components. These must be scaled properly for ground texture access as ground texture stretching and detiling of tex coords mean textures are scaled differently. - Added calculation of partial derivatives for texture coordinates used by the 5 non- base textures. dFdx() and dFdy() were called for nontrivial texture coordinate manipulation. - New control randomise_texture_lookups added at top of ws30-ALS-ultra.frag, in the development tools section. Setting this to 1 will do a stress test of ground texture array lookups. A fast random number generation function is used to assign each landclass 4 random textures from the ground texture array - this is done by . Performance will not be as bad in the full ALS port as some texture slots will better caching in memory - e.g. have 1 or a few variants. - Possible optimisation: use a 2nd or 3rd texture array for some of the non-base texture slots that typically have 256, 512, or 1024 textures. The resolutions of these arrays should change based on the largest loaded texture size in the active regional definitions - this will allow taking full advantage of smaller texture sizes in some areas. The disadvantage is some texture duplication with more slots. - Possible optimisation: offer the option to shrink textures by 50% or 25% - for texture slots that use large textures like base or mix slots. - Very temporary - reduce procedural normal map features with photoscenery active without breaking profiling, as the inputs to shaders are effect defaults or placeholder (by request on ML). ---- ws30-ALS-ultra.vert: - Start of conversion of geocentic world space xyz into lat/lon coords used for ground texture lookups. Currently commented out as it's unknown what model space coords are in (not geocentric it seems). ws20-ALS-landclass-search-functions.frag: - Add control for changing the ground texture array lookup function for debugging in case old compilers/GPUs have issues. tex_lookup_type: 0: normal( textureGrad(), 1: textureLod (manual Lod calculation), 2: texture() with no partial derivative adjustment. - New get6_random_integers() will extract 6 limited random values from the full precision of a 32 bit random value. - Old landclass_texel_size_m references are removed since textureSize() is used. There are no 'const in float' arguments that may cause issues on AMD compilers. ---- WS30-overlay effect (Inactive): - ws30-overlay.eff (derived from terrain-overlay.eff). Technique no "4" is used for two passes. The 1st pass is a copy of the ALS ultra pass (technique no "5") from ws30.eff. The 2nd pass is the same as terrain-overlay.eff. The 2nd pass uses terrain- overlay.frag from WS2. - grass-ALS.vert copied to ws30-ovelay-ALS.vert. To do: needs texture coords that don't change with tiles. - terrain-overlay-ALS.geom copied to ws30-overlay-ALS.geom. To do: uses gl_PositionIn [i].xy for position in the horizontal plane - assumes z is vertical. Tile model space doesn't seem to match this. - WS3 doesn't seem to have a way of switching references to terrain-overlay.eff (which inherits from terrain-default.eff) to the new ws3-overlay.eff (which needs to inherit from ws30.eff). The ws3-overlay.eff included /might/ just work without any other changes: the first pass is the WS3 als ultra settings pass, and the second overlay pass is unchanged from WS2 (the same terrain overlay shaders should probably work apart from texcoords and rawpos not being correct). - Materials/base/materials-base.xml: ws30Road material: uncomment line declaring terrain-default as the effect. The target effect for ws30 roads is road-*.eff and it's added to ws30Road and ws30Freeway but commented out as it's not working currently. - Misc: large scale transitions are turned on in ws30-ALS-landclass-search-functions.frag by default. Grow landclass borders with large scale transitions is now on by default. ---- Changes after the multi-texture support commit: ws30-ALS-ultra.vert - Added documentation: WS30 model space and z up space - for future people working on WS30, and people looking through shaders to rule out possibilities e.g. when fixing bugs, or interpreting visual bug reports. ws30-ALS-landclass-search-functions.frag: - For now, lookup_ground_texture_array() also looks up the relevant texture's index based on an integer. - Add get_mixed_texel() - looks up texel for this fragment and any neighbors before mixing. Moves currently shared mixing code out of 3 fragment shaders. Misc: changed indentation from mixed tabs/spaces to spaces in ws30-ALS-ultra frag and vert. The indentation can be changed again when the porting is complete. ws30-ALS vert/frag and ws30-ALS-detailed vert/frag: - Add varying for ground texture coordiante, currently set to gl_TexCoord[0]. Apply texture stretching dimensions in fragment shaders. - Misc: varying rawPos is set to vec2 for now, as relPos.z+eye_alt might be faster. Misc: keep WS2 mixing logic for now , including turning off mixing via the alpha channel of the textures ---- Changes after sending material parameters in uniform arrays commit: - Materials parameter for rock_strata is cast into an int so rock_strata==1 should work. Misc: Left over uniform for rock strata cleaned up. - ws30-ALS-ultra.frag and ws30-ALS-detailed.frag: Add missing mat_shininess for photoscenery case .
2022-01-03 15:43:29 +00:00
// correct ambient light intensity and hue before sunrise
if (earthShade < 0.5)
{
intensity = length(light_ambient.rgb);
light_ambient.rgb = intensity * normalize(mix(light_ambient.rgb, shadedFogColor, 1.0 -smoothstep(0.4, 0.8,earthShade) ));
light_ambient.rgb = light_ambient.rgb + moonLightColor * (1.0 - smoothstep(0.4, 0.5, earthShade));
intensity = length(light_diffuse.rgb);
light_diffuse.rgb = intensity * normalize(mix(light_diffuse.rgb, shadedFogColor, 1.0 -smoothstep(0.4, 0.7,earthShade) ));
}
WS30: landclass and texture lookups in fragment shader commit e131ffaca7b2c934474f0e447b5852cb4c7c8d4a Author: vs <vs2009@mail.com> Date: Fri Oct 15 22:19:42 2021 +1000 WS30: landclass and texture lookups in fragment shader: Changelog: - Testing: Procedural random landclass function, get_random_landclass(). 1). Avoids a texture lookup for profiling. 2). Creates squares of configurable size with controllable random landclass ranges - to test landclass transition algorithms and quickly profile lots of landclasses in view. It's also possible to put pressure on GPU memory even with 1 lookup of ground textures per fragment, by reducing size to <20m and viewing from altitude. - Add ALS ultra technique as no 5, move existing ALS technique to no. 6. Add WS30-ALS-ultra frag & vert in preparation for eventual ALS ultra port. Change comments/variables to match using a texture array instead of atlas. Sampler name: atlas -> textureArray. - Testing/optimisation of de-tiling: WS30-ALS.frag: reorder perlin detiling to make noise source easier to switch. WS30-ALS-ultra.frag: Create alternative to perlin noise used for reducing tiling that avoids a texture lookup - to profile and optimise. This is commented out. The performance difference in the final version depends on memory pressure versus arithmetic load of the full shader. It varies by GPU and what's in view. In future, once a full ALS port is done, maybe it'll be more efficient to run a higher quality de-tiling algorithm all the time to avoid branching overhead due to effects like agriculture which need more de-tiling. De-tiling code in shaders should /eventually/ match CPU-side de-tiling of texture masks used for object and vegetation placement. De-tiling code in GPUs might be subject to precision and numerical artifacts, and if so maybe the texture lookup version would work better. The same applies to noise used for rendering WS3 water waves and collision queries. One option is to use exactly the same glsl code, with a C++ header to convert glsl syntax e.g. https://github.com/g-truc/glm .
2021-10-21 20:31:03 +00:00
// directional scattering for low sun
if (lightArg < 10.0) {
mie_angle = (0.5 * dot(normalize(relPos), lightdir) ) + 0.5;
} else {
mie_angle = 1.0;
}
WS30: landclass and texture lookups in fragment shader commit e131ffaca7b2c934474f0e447b5852cb4c7c8d4a Author: vs <vs2009@mail.com> Date: Fri Oct 15 22:19:42 2021 +1000 WS30: landclass and texture lookups in fragment shader: Changelog: - Testing: Procedural random landclass function, get_random_landclass(). 1). Avoids a texture lookup for profiling. 2). Creates squares of configurable size with controllable random landclass ranges - to test landclass transition algorithms and quickly profile lots of landclasses in view. It's also possible to put pressure on GPU memory even with 1 lookup of ground textures per fragment, by reducing size to <20m and viewing from altitude. - Add ALS ultra technique as no 5, move existing ALS technique to no. 6. Add WS30-ALS-ultra frag & vert in preparation for eventual ALS ultra port. Change comments/variables to match using a texture array instead of atlas. Sampler name: atlas -> textureArray. - Testing/optimisation of de-tiling: WS30-ALS.frag: reorder perlin detiling to make noise source easier to switch. WS30-ALS-ultra.frag: Create alternative to perlin noise used for reducing tiling that avoids a texture lookup - to profile and optimise. This is commented out. The performance difference in the final version depends on memory pressure versus arithmetic load of the full shader. It varies by GPU and what's in view. In future, once a full ALS port is done, maybe it'll be more efficient to run a higher quality de-tiling algorithm all the time to avoid branching overhead due to effects like agriculture which need more de-tiling. De-tiling code in shaders should /eventually/ match CPU-side de-tiling of texture masks used for object and vegetation placement. De-tiling code in GPUs might be subject to precision and numerical artifacts, and if so maybe the texture lookup version would work better. The same applies to noise used for rendering WS3 water waves and collision queries. One option is to use exactly the same glsl code, with a C++ header to convert glsl syntax e.g. https://github.com/g-truc/glm .
2021-10-21 20:31:03 +00:00
WS30: MR #267: Improved texture lookups from VS Squashed commit of the following: commit 115511888c20c53670eba17a82c81c9af99d7302 Author: vs <vs2009@mail.com> Date: Mon Dec 6 18:52:06 2021 +1000 WS30 effects and shaders: Changelog: ws30-ALS-ultra.frag: - Ground textures lookups use their own coordinates separate from the landclass texture lookup. - Partial derivatives dFdx and Dfdy are packed together in a vec4, so simple multiplication to scale can be done in 1 instruction. dFdx = s and t components. dFdy = p and q components. These must be scaled properly for ground texture access as ground texture stretching and detiling of tex coords mean textures are scaled differently. - Added calculation of partial derivatives for texture coordinates used by the 5 non- base textures. dFdx() and dFdy() were called for nontrivial texture coordinate manipulation. - New control randomise_texture_lookups added at top of ws30-ALS-ultra.frag, in the development tools section. Setting this to 1 will do a stress test of ground texture array lookups. A fast random number generation function is used to assign each landclass 4 random textures from the ground texture array - this is done by . Performance will not be as bad in the full ALS port as some texture slots will better caching in memory - e.g. have 1 or a few variants. - Possible optimisation: use a 2nd or 3rd texture array for some of the non-base texture slots that typically have 256, 512, or 1024 textures. The resolutions of these arrays should change based on the largest loaded texture size in the active regional definitions - this will allow taking full advantage of smaller texture sizes in some areas. The disadvantage is some texture duplication with more slots. - Possible optimisation: offer the option to shrink textures by 50% or 25% - for texture slots that use large textures like base or mix slots. - Very temporary - reduce procedural normal map features with photoscenery active without breaking profiling, as the inputs to shaders are effect defaults or placeholder (by request on ML). ---- ws30-ALS-ultra.vert: - Start of conversion of geocentic world space xyz into lat/lon coords used for ground texture lookups. Currently commented out as it's unknown what model space coords are in (not geocentric it seems). ws20-ALS-landclass-search-functions.frag: - Add control for changing the ground texture array lookup function for debugging in case old compilers/GPUs have issues. tex_lookup_type: 0: normal( textureGrad(), 1: textureLod (manual Lod calculation), 2: texture() with no partial derivative adjustment. - New get6_random_integers() will extract 6 limited random values from the full precision of a 32 bit random value. - Old landclass_texel_size_m references are removed since textureSize() is used. There are no 'const in float' arguments that may cause issues on AMD compilers. ---- WS30-overlay effect (Inactive): - ws30-overlay.eff (derived from terrain-overlay.eff). Technique no "4" is used for two passes. The 1st pass is a copy of the ALS ultra pass (technique no "5") from ws30.eff. The 2nd pass is the same as terrain-overlay.eff. The 2nd pass uses terrain- overlay.frag from WS2. - grass-ALS.vert copied to ws30-ovelay-ALS.vert. To do: needs texture coords that don't change with tiles. - terrain-overlay-ALS.geom copied to ws30-overlay-ALS.geom. To do: uses gl_PositionIn [i].xy for position in the horizontal plane - assumes z is vertical. Tile model space doesn't seem to match this. - WS3 doesn't seem to have a way of switching references to terrain-overlay.eff (which inherits from terrain-default.eff) to the new ws3-overlay.eff (which needs to inherit from ws30.eff). The ws3-overlay.eff included /might/ just work without any other changes: the first pass is the WS3 als ultra settings pass, and the second overlay pass is unchanged from WS2 (the same terrain overlay shaders should probably work apart from texcoords and rawpos not being correct). - Materials/base/materials-base.xml: ws30Road material: uncomment line declaring terrain-default as the effect. The target effect for ws30 roads is road-*.eff and it's added to ws30Road and ws30Freeway but commented out as it's not working currently. - Misc: large scale transitions are turned on in ws30-ALS-landclass-search-functions.frag by default. Grow landclass borders with large scale transitions is now on by default. ---- Changes after the multi-texture support commit: ws30-ALS-ultra.vert - Added documentation: WS30 model space and z up space - for future people working on WS30, and people looking through shaders to rule out possibilities e.g. when fixing bugs, or interpreting visual bug reports. ws30-ALS-landclass-search-functions.frag: - For now, lookup_ground_texture_array() also looks up the relevant texture's index based on an integer. - Add get_mixed_texel() - looks up texel for this fragment and any neighbors before mixing. Moves currently shared mixing code out of 3 fragment shaders. Misc: changed indentation from mixed tabs/spaces to spaces in ws30-ALS-ultra frag and vert. The indentation can be changed again when the porting is complete. ws30-ALS vert/frag and ws30-ALS-detailed vert/frag: - Add varying for ground texture coordiante, currently set to gl_TexCoord[0]. Apply texture stretching dimensions in fragment shaders. - Misc: varying rawPos is set to vec2 for now, as relPos.z+eye_alt might be faster. Misc: keep WS2 mixing logic for now , including turning off mixing via the alpha channel of the textures ---- Changes after sending material parameters in uniform arrays commit: - Materials parameter for rock_strata is cast into an int so rock_strata==1 should work. Misc: Left over uniform for rock strata cleaned up. - ws30-ALS-ultra.frag and ws30-ALS-detailed.frag: Add missing mat_shininess for photoscenery case .
2022-01-03 15:43:29 +00:00
// the haze gets the light at the altitude of the haze top if the vertex in view is below
// but the light at the vertex if the vertex is above
vertex_alt = max(vertex_alt,hazeLayerAltitude);
if (vertex_alt > hazeLayerAltitude)
{
if (dist > 0.8 * avisibility)
{
vertex_alt = mix(vertex_alt, hazeLayerAltitude, smoothstep(0.8*avisibility, avisibility, dist));
yprime_alt = yprime -sqrt(2.0 * EarthRadius * vertex_alt);
}
}
else
{
vertex_alt = hazeLayerAltitude;
yprime_alt = yprime -sqrt(2.0 * EarthRadius * vertex_alt);
}
} // End if (terminator < 1000000.0)
else // the faster, full-day version without lightfields
{
WS30: landclass and texture lookups in fragment shader commit e131ffaca7b2c934474f0e447b5852cb4c7c8d4a Author: vs <vs2009@mail.com> Date: Fri Oct 15 22:19:42 2021 +1000 WS30: landclass and texture lookups in fragment shader: Changelog: - Testing: Procedural random landclass function, get_random_landclass(). 1). Avoids a texture lookup for profiling. 2). Creates squares of configurable size with controllable random landclass ranges - to test landclass transition algorithms and quickly profile lots of landclasses in view. It's also possible to put pressure on GPU memory even with 1 lookup of ground textures per fragment, by reducing size to <20m and viewing from altitude. - Add ALS ultra technique as no 5, move existing ALS technique to no. 6. Add WS30-ALS-ultra frag & vert in preparation for eventual ALS ultra port. Change comments/variables to match using a texture array instead of atlas. Sampler name: atlas -> textureArray. - Testing/optimisation of de-tiling: WS30-ALS.frag: reorder perlin detiling to make noise source easier to switch. WS30-ALS-ultra.frag: Create alternative to perlin noise used for reducing tiling that avoids a texture lookup - to profile and optimise. This is commented out. The performance difference in the final version depends on memory pressure versus arithmetic load of the full shader. It varies by GPU and what's in view. In future, once a full ALS port is done, maybe it'll be more efficient to run a higher quality de-tiling algorithm all the time to avoid branching overhead due to effects like agriculture which need more de-tiling. De-tiling code in shaders should /eventually/ match CPU-side de-tiling of texture masks used for object and vegetation placement. De-tiling code in GPUs might be subject to precision and numerical artifacts, and if so maybe the texture lookup version would work better. The same applies to noise used for rendering WS3 water waves and collision queries. One option is to use exactly the same glsl code, with a C++ header to convert glsl syntax e.g. https://github.com/g-truc/glm .
2021-10-21 20:31:03 +00:00
//vertex_alt = max(gl_Vertex.z,100.0);
WS30: MR #267: Improved texture lookups from VS Squashed commit of the following: commit 115511888c20c53670eba17a82c81c9af99d7302 Author: vs <vs2009@mail.com> Date: Mon Dec 6 18:52:06 2021 +1000 WS30 effects and shaders: Changelog: ws30-ALS-ultra.frag: - Ground textures lookups use their own coordinates separate from the landclass texture lookup. - Partial derivatives dFdx and Dfdy are packed together in a vec4, so simple multiplication to scale can be done in 1 instruction. dFdx = s and t components. dFdy = p and q components. These must be scaled properly for ground texture access as ground texture stretching and detiling of tex coords mean textures are scaled differently. - Added calculation of partial derivatives for texture coordinates used by the 5 non- base textures. dFdx() and dFdy() were called for nontrivial texture coordinate manipulation. - New control randomise_texture_lookups added at top of ws30-ALS-ultra.frag, in the development tools section. Setting this to 1 will do a stress test of ground texture array lookups. A fast random number generation function is used to assign each landclass 4 random textures from the ground texture array - this is done by . Performance will not be as bad in the full ALS port as some texture slots will better caching in memory - e.g. have 1 or a few variants. - Possible optimisation: use a 2nd or 3rd texture array for some of the non-base texture slots that typically have 256, 512, or 1024 textures. The resolutions of these arrays should change based on the largest loaded texture size in the active regional definitions - this will allow taking full advantage of smaller texture sizes in some areas. The disadvantage is some texture duplication with more slots. - Possible optimisation: offer the option to shrink textures by 50% or 25% - for texture slots that use large textures like base or mix slots. - Very temporary - reduce procedural normal map features with photoscenery active without breaking profiling, as the inputs to shaders are effect defaults or placeholder (by request on ML). ---- ws30-ALS-ultra.vert: - Start of conversion of geocentic world space xyz into lat/lon coords used for ground texture lookups. Currently commented out as it's unknown what model space coords are in (not geocentric it seems). ws20-ALS-landclass-search-functions.frag: - Add control for changing the ground texture array lookup function for debugging in case old compilers/GPUs have issues. tex_lookup_type: 0: normal( textureGrad(), 1: textureLod (manual Lod calculation), 2: texture() with no partial derivative adjustment. - New get6_random_integers() will extract 6 limited random values from the full precision of a 32 bit random value. - Old landclass_texel_size_m references are removed since textureSize() is used. There are no 'const in float' arguments that may cause issues on AMD compilers. ---- WS30-overlay effect (Inactive): - ws30-overlay.eff (derived from terrain-overlay.eff). Technique no "4" is used for two passes. The 1st pass is a copy of the ALS ultra pass (technique no "5") from ws30.eff. The 2nd pass is the same as terrain-overlay.eff. The 2nd pass uses terrain- overlay.frag from WS2. - grass-ALS.vert copied to ws30-ovelay-ALS.vert. To do: needs texture coords that don't change with tiles. - terrain-overlay-ALS.geom copied to ws30-overlay-ALS.geom. To do: uses gl_PositionIn [i].xy for position in the horizontal plane - assumes z is vertical. Tile model space doesn't seem to match this. - WS3 doesn't seem to have a way of switching references to terrain-overlay.eff (which inherits from terrain-default.eff) to the new ws3-overlay.eff (which needs to inherit from ws30.eff). The ws3-overlay.eff included /might/ just work without any other changes: the first pass is the WS3 als ultra settings pass, and the second overlay pass is unchanged from WS2 (the same terrain overlay shaders should probably work apart from texcoords and rawpos not being correct). - Materials/base/materials-base.xml: ws30Road material: uncomment line declaring terrain-default as the effect. The target effect for ws30 roads is road-*.eff and it's added to ws30Road and ws30Freeway but commented out as it's not working currently. - Misc: large scale transitions are turned on in ws30-ALS-landclass-search-functions.frag by default. Grow landclass borders with large scale transitions is now on by default. ---- Changes after the multi-texture support commit: ws30-ALS-ultra.vert - Added documentation: WS30 model space and z up space - for future people working on WS30, and people looking through shaders to rule out possibilities e.g. when fixing bugs, or interpreting visual bug reports. ws30-ALS-landclass-search-functions.frag: - For now, lookup_ground_texture_array() also looks up the relevant texture's index based on an integer. - Add get_mixed_texel() - looks up texel for this fragment and any neighbors before mixing. Moves currently shared mixing code out of 3 fragment shaders. Misc: changed indentation from mixed tabs/spaces to spaces in ws30-ALS-ultra frag and vert. The indentation can be changed again when the porting is complete. ws30-ALS vert/frag and ws30-ALS-detailed vert/frag: - Add varying for ground texture coordiante, currently set to gl_TexCoord[0]. Apply texture stretching dimensions in fragment shaders. - Misc: varying rawPos is set to vec2 for now, as relPos.z+eye_alt might be faster. Misc: keep WS2 mixing logic for now , including turning off mixing via the alpha channel of the textures ---- Changes after sending material parameters in uniform arrays commit: - Materials parameter for rock_strata is cast into an int so rock_strata==1 should work. Misc: Left over uniform for rock strata cleaned up. - ws30-ALS-ultra.frag and ws30-ALS-detailed.frag: Add missing mat_shininess for photoscenery case .
2022-01-03 15:43:29 +00:00
WS30: landclass and texture lookups in fragment shader commit e131ffaca7b2c934474f0e447b5852cb4c7c8d4a Author: vs <vs2009@mail.com> Date: Fri Oct 15 22:19:42 2021 +1000 WS30: landclass and texture lookups in fragment shader: Changelog: - Testing: Procedural random landclass function, get_random_landclass(). 1). Avoids a texture lookup for profiling. 2). Creates squares of configurable size with controllable random landclass ranges - to test landclass transition algorithms and quickly profile lots of landclasses in view. It's also possible to put pressure on GPU memory even with 1 lookup of ground textures per fragment, by reducing size to <20m and viewing from altitude. - Add ALS ultra technique as no 5, move existing ALS technique to no. 6. Add WS30-ALS-ultra frag & vert in preparation for eventual ALS ultra port. Change comments/variables to match using a texture array instead of atlas. Sampler name: atlas -> textureArray. - Testing/optimisation of de-tiling: WS30-ALS.frag: reorder perlin detiling to make noise source easier to switch. WS30-ALS-ultra.frag: Create alternative to perlin noise used for reducing tiling that avoids a texture lookup - to profile and optimise. This is commented out. The performance difference in the final version depends on memory pressure versus arithmetic load of the full shader. It varies by GPU and what's in view. In future, once a full ALS port is done, maybe it'll be more efficient to run a higher quality de-tiling algorithm all the time to avoid branching overhead due to effects like agriculture which need more de-tiling. De-tiling code in shaders should /eventually/ match CPU-side de-tiling of texture masks used for object and vegetation placement. De-tiling code in GPUs might be subject to precision and numerical artifacts, and if so maybe the texture lookup version would work better. The same applies to noise used for rendering WS3 water waves and collision queries. One option is to use exactly the same glsl code, with a C++ header to convert glsl syntax e.g. https://github.com/g-truc/glm .
2021-10-21 20:31:03 +00:00
earthShade = 1.0;
mie_angle = 1.0;
if (terminator > 3000000.0)
WS30: MR #267: Improved texture lookups from VS Squashed commit of the following: commit 115511888c20c53670eba17a82c81c9af99d7302 Author: vs <vs2009@mail.com> Date: Mon Dec 6 18:52:06 2021 +1000 WS30 effects and shaders: Changelog: ws30-ALS-ultra.frag: - Ground textures lookups use their own coordinates separate from the landclass texture lookup. - Partial derivatives dFdx and Dfdy are packed together in a vec4, so simple multiplication to scale can be done in 1 instruction. dFdx = s and t components. dFdy = p and q components. These must be scaled properly for ground texture access as ground texture stretching and detiling of tex coords mean textures are scaled differently. - Added calculation of partial derivatives for texture coordinates used by the 5 non- base textures. dFdx() and dFdy() were called for nontrivial texture coordinate manipulation. - New control randomise_texture_lookups added at top of ws30-ALS-ultra.frag, in the development tools section. Setting this to 1 will do a stress test of ground texture array lookups. A fast random number generation function is used to assign each landclass 4 random textures from the ground texture array - this is done by . Performance will not be as bad in the full ALS port as some texture slots will better caching in memory - e.g. have 1 or a few variants. - Possible optimisation: use a 2nd or 3rd texture array for some of the non-base texture slots that typically have 256, 512, or 1024 textures. The resolutions of these arrays should change based on the largest loaded texture size in the active regional definitions - this will allow taking full advantage of smaller texture sizes in some areas. The disadvantage is some texture duplication with more slots. - Possible optimisation: offer the option to shrink textures by 50% or 25% - for texture slots that use large textures like base or mix slots. - Very temporary - reduce procedural normal map features with photoscenery active without breaking profiling, as the inputs to shaders are effect defaults or placeholder (by request on ML). ---- ws30-ALS-ultra.vert: - Start of conversion of geocentic world space xyz into lat/lon coords used for ground texture lookups. Currently commented out as it's unknown what model space coords are in (not geocentric it seems). ws20-ALS-landclass-search-functions.frag: - Add control for changing the ground texture array lookup function for debugging in case old compilers/GPUs have issues. tex_lookup_type: 0: normal( textureGrad(), 1: textureLod (manual Lod calculation), 2: texture() with no partial derivative adjustment. - New get6_random_integers() will extract 6 limited random values from the full precision of a 32 bit random value. - Old landclass_texel_size_m references are removed since textureSize() is used. There are no 'const in float' arguments that may cause issues on AMD compilers. ---- WS30-overlay effect (Inactive): - ws30-overlay.eff (derived from terrain-overlay.eff). Technique no "4" is used for two passes. The 1st pass is a copy of the ALS ultra pass (technique no "5") from ws30.eff. The 2nd pass is the same as terrain-overlay.eff. The 2nd pass uses terrain- overlay.frag from WS2. - grass-ALS.vert copied to ws30-ovelay-ALS.vert. To do: needs texture coords that don't change with tiles. - terrain-overlay-ALS.geom copied to ws30-overlay-ALS.geom. To do: uses gl_PositionIn [i].xy for position in the horizontal plane - assumes z is vertical. Tile model space doesn't seem to match this. - WS3 doesn't seem to have a way of switching references to terrain-overlay.eff (which inherits from terrain-default.eff) to the new ws3-overlay.eff (which needs to inherit from ws30.eff). The ws3-overlay.eff included /might/ just work without any other changes: the first pass is the WS3 als ultra settings pass, and the second overlay pass is unchanged from WS2 (the same terrain overlay shaders should probably work apart from texcoords and rawpos not being correct). - Materials/base/materials-base.xml: ws30Road material: uncomment line declaring terrain-default as the effect. The target effect for ws30 roads is road-*.eff and it's added to ws30Road and ws30Freeway but commented out as it's not working currently. - Misc: large scale transitions are turned on in ws30-ALS-landclass-search-functions.frag by default. Grow landclass borders with large scale transitions is now on by default. ---- Changes after the multi-texture support commit: ws30-ALS-ultra.vert - Added documentation: WS30 model space and z up space - for future people working on WS30, and people looking through shaders to rule out possibilities e.g. when fixing bugs, or interpreting visual bug reports. ws30-ALS-landclass-search-functions.frag: - For now, lookup_ground_texture_array() also looks up the relevant texture's index based on an integer. - Add get_mixed_texel() - looks up texel for this fragment and any neighbors before mixing. Moves currently shared mixing code out of 3 fragment shaders. Misc: changed indentation from mixed tabs/spaces to spaces in ws30-ALS-ultra frag and vert. The indentation can be changed again when the porting is complete. ws30-ALS vert/frag and ws30-ALS-detailed vert/frag: - Add varying for ground texture coordiante, currently set to gl_TexCoord[0]. Apply texture stretching dimensions in fragment shaders. - Misc: varying rawPos is set to vec2 for now, as relPos.z+eye_alt might be faster. Misc: keep WS2 mixing logic for now , including turning off mixing via the alpha channel of the textures ---- Changes after sending material parameters in uniform arrays commit: - Materials parameter for rock_strata is cast into an int so rock_strata==1 should work. Misc: Left over uniform for rock strata cleaned up. - ws30-ALS-ultra.frag and ws30-ALS-detailed.frag: Add missing mat_shininess for photoscenery case .
2022-01-03 15:43:29 +00:00
{
light_diffuse = vec4 (1.0, 1.0, 1.0, 1.0);
light_ambient = vec4 (0.33, 0.4, 0.5, 1.0);
specular_light = vec3 (1.0, 1.0, 1.0);
WS30: MR #267: Improved texture lookups from VS Squashed commit of the following: commit 115511888c20c53670eba17a82c81c9af99d7302 Author: vs <vs2009@mail.com> Date: Mon Dec 6 18:52:06 2021 +1000 WS30 effects and shaders: Changelog: ws30-ALS-ultra.frag: - Ground textures lookups use their own coordinates separate from the landclass texture lookup. - Partial derivatives dFdx and Dfdy are packed together in a vec4, so simple multiplication to scale can be done in 1 instruction. dFdx = s and t components. dFdy = p and q components. These must be scaled properly for ground texture access as ground texture stretching and detiling of tex coords mean textures are scaled differently. - Added calculation of partial derivatives for texture coordinates used by the 5 non- base textures. dFdx() and dFdy() were called for nontrivial texture coordinate manipulation. - New control randomise_texture_lookups added at top of ws30-ALS-ultra.frag, in the development tools section. Setting this to 1 will do a stress test of ground texture array lookups. A fast random number generation function is used to assign each landclass 4 random textures from the ground texture array - this is done by . Performance will not be as bad in the full ALS port as some texture slots will better caching in memory - e.g. have 1 or a few variants. - Possible optimisation: use a 2nd or 3rd texture array for some of the non-base texture slots that typically have 256, 512, or 1024 textures. The resolutions of these arrays should change based on the largest loaded texture size in the active regional definitions - this will allow taking full advantage of smaller texture sizes in some areas. The disadvantage is some texture duplication with more slots. - Possible optimisation: offer the option to shrink textures by 50% or 25% - for texture slots that use large textures like base or mix slots. - Very temporary - reduce procedural normal map features with photoscenery active without breaking profiling, as the inputs to shaders are effect defaults or placeholder (by request on ML). ---- ws30-ALS-ultra.vert: - Start of conversion of geocentic world space xyz into lat/lon coords used for ground texture lookups. Currently commented out as it's unknown what model space coords are in (not geocentric it seems). ws20-ALS-landclass-search-functions.frag: - Add control for changing the ground texture array lookup function for debugging in case old compilers/GPUs have issues. tex_lookup_type: 0: normal( textureGrad(), 1: textureLod (manual Lod calculation), 2: texture() with no partial derivative adjustment. - New get6_random_integers() will extract 6 limited random values from the full precision of a 32 bit random value. - Old landclass_texel_size_m references are removed since textureSize() is used. There are no 'const in float' arguments that may cause issues on AMD compilers. ---- WS30-overlay effect (Inactive): - ws30-overlay.eff (derived from terrain-overlay.eff). Technique no "4" is used for two passes. The 1st pass is a copy of the ALS ultra pass (technique no "5") from ws30.eff. The 2nd pass is the same as terrain-overlay.eff. The 2nd pass uses terrain- overlay.frag from WS2. - grass-ALS.vert copied to ws30-ovelay-ALS.vert. To do: needs texture coords that don't change with tiles. - terrain-overlay-ALS.geom copied to ws30-overlay-ALS.geom. To do: uses gl_PositionIn [i].xy for position in the horizontal plane - assumes z is vertical. Tile model space doesn't seem to match this. - WS3 doesn't seem to have a way of switching references to terrain-overlay.eff (which inherits from terrain-default.eff) to the new ws3-overlay.eff (which needs to inherit from ws30.eff). The ws3-overlay.eff included /might/ just work without any other changes: the first pass is the WS3 als ultra settings pass, and the second overlay pass is unchanged from WS2 (the same terrain overlay shaders should probably work apart from texcoords and rawpos not being correct). - Materials/base/materials-base.xml: ws30Road material: uncomment line declaring terrain-default as the effect. The target effect for ws30 roads is road-*.eff and it's added to ws30Road and ws30Freeway but commented out as it's not working currently. - Misc: large scale transitions are turned on in ws30-ALS-landclass-search-functions.frag by default. Grow landclass borders with large scale transitions is now on by default. ---- Changes after the multi-texture support commit: ws30-ALS-ultra.vert - Added documentation: WS30 model space and z up space - for future people working on WS30, and people looking through shaders to rule out possibilities e.g. when fixing bugs, or interpreting visual bug reports. ws30-ALS-landclass-search-functions.frag: - For now, lookup_ground_texture_array() also looks up the relevant texture's index based on an integer. - Add get_mixed_texel() - looks up texel for this fragment and any neighbors before mixing. Moves currently shared mixing code out of 3 fragment shaders. Misc: changed indentation from mixed tabs/spaces to spaces in ws30-ALS-ultra frag and vert. The indentation can be changed again when the porting is complete. ws30-ALS vert/frag and ws30-ALS-detailed vert/frag: - Add varying for ground texture coordiante, currently set to gl_TexCoord[0]. Apply texture stretching dimensions in fragment shaders. - Misc: varying rawPos is set to vec2 for now, as relPos.z+eye_alt might be faster. Misc: keep WS2 mixing logic for now , including turning off mixing via the alpha channel of the textures ---- Changes after sending material parameters in uniform arrays commit: - Materials parameter for rock_strata is cast into an int so rock_strata==1 should work. Misc: Left over uniform for rock strata cleaned up. - ws30-ALS-ultra.frag and ws30-ALS-detailed.frag: Add missing mat_shininess for photoscenery case .
2022-01-03 15:43:29 +00:00
}
WS30: landclass and texture lookups in fragment shader commit e131ffaca7b2c934474f0e447b5852cb4c7c8d4a Author: vs <vs2009@mail.com> Date: Fri Oct 15 22:19:42 2021 +1000 WS30: landclass and texture lookups in fragment shader: Changelog: - Testing: Procedural random landclass function, get_random_landclass(). 1). Avoids a texture lookup for profiling. 2). Creates squares of configurable size with controllable random landclass ranges - to test landclass transition algorithms and quickly profile lots of landclasses in view. It's also possible to put pressure on GPU memory even with 1 lookup of ground textures per fragment, by reducing size to <20m and viewing from altitude. - Add ALS ultra technique as no 5, move existing ALS technique to no. 6. Add WS30-ALS-ultra frag & vert in preparation for eventual ALS ultra port. Change comments/variables to match using a texture array instead of atlas. Sampler name: atlas -> textureArray. - Testing/optimisation of de-tiling: WS30-ALS.frag: reorder perlin detiling to make noise source easier to switch. WS30-ALS-ultra.frag: Create alternative to perlin noise used for reducing tiling that avoids a texture lookup - to profile and optimise. This is commented out. The performance difference in the final version depends on memory pressure versus arithmetic load of the full shader. It varies by GPU and what's in view. In future, once a full ALS port is done, maybe it'll be more efficient to run a higher quality de-tiling algorithm all the time to avoid branching overhead due to effects like agriculture which need more de-tiling. De-tiling code in shaders should /eventually/ match CPU-side de-tiling of texture masks used for object and vegetation placement. De-tiling code in GPUs might be subject to precision and numerical artifacts, and if so maybe the texture lookup version would work better. The same applies to noise used for rendering WS3 water waves and collision queries. One option is to use exactly the same glsl code, with a C++ header to convert glsl syntax e.g. https://github.com/g-truc/glm .
2021-10-21 20:31:03 +00:00
else
WS30: MR #267: Improved texture lookups from VS Squashed commit of the following: commit 115511888c20c53670eba17a82c81c9af99d7302 Author: vs <vs2009@mail.com> Date: Mon Dec 6 18:52:06 2021 +1000 WS30 effects and shaders: Changelog: ws30-ALS-ultra.frag: - Ground textures lookups use their own coordinates separate from the landclass texture lookup. - Partial derivatives dFdx and Dfdy are packed together in a vec4, so simple multiplication to scale can be done in 1 instruction. dFdx = s and t components. dFdy = p and q components. These must be scaled properly for ground texture access as ground texture stretching and detiling of tex coords mean textures are scaled differently. - Added calculation of partial derivatives for texture coordinates used by the 5 non- base textures. dFdx() and dFdy() were called for nontrivial texture coordinate manipulation. - New control randomise_texture_lookups added at top of ws30-ALS-ultra.frag, in the development tools section. Setting this to 1 will do a stress test of ground texture array lookups. A fast random number generation function is used to assign each landclass 4 random textures from the ground texture array - this is done by . Performance will not be as bad in the full ALS port as some texture slots will better caching in memory - e.g. have 1 or a few variants. - Possible optimisation: use a 2nd or 3rd texture array for some of the non-base texture slots that typically have 256, 512, or 1024 textures. The resolutions of these arrays should change based on the largest loaded texture size in the active regional definitions - this will allow taking full advantage of smaller texture sizes in some areas. The disadvantage is some texture duplication with more slots. - Possible optimisation: offer the option to shrink textures by 50% or 25% - for texture slots that use large textures like base or mix slots. - Very temporary - reduce procedural normal map features with photoscenery active without breaking profiling, as the inputs to shaders are effect defaults or placeholder (by request on ML). ---- ws30-ALS-ultra.vert: - Start of conversion of geocentic world space xyz into lat/lon coords used for ground texture lookups. Currently commented out as it's unknown what model space coords are in (not geocentric it seems). ws20-ALS-landclass-search-functions.frag: - Add control for changing the ground texture array lookup function for debugging in case old compilers/GPUs have issues. tex_lookup_type: 0: normal( textureGrad(), 1: textureLod (manual Lod calculation), 2: texture() with no partial derivative adjustment. - New get6_random_integers() will extract 6 limited random values from the full precision of a 32 bit random value. - Old landclass_texel_size_m references are removed since textureSize() is used. There are no 'const in float' arguments that may cause issues on AMD compilers. ---- WS30-overlay effect (Inactive): - ws30-overlay.eff (derived from terrain-overlay.eff). Technique no "4" is used for two passes. The 1st pass is a copy of the ALS ultra pass (technique no "5") from ws30.eff. The 2nd pass is the same as terrain-overlay.eff. The 2nd pass uses terrain- overlay.frag from WS2. - grass-ALS.vert copied to ws30-ovelay-ALS.vert. To do: needs texture coords that don't change with tiles. - terrain-overlay-ALS.geom copied to ws30-overlay-ALS.geom. To do: uses gl_PositionIn [i].xy for position in the horizontal plane - assumes z is vertical. Tile model space doesn't seem to match this. - WS3 doesn't seem to have a way of switching references to terrain-overlay.eff (which inherits from terrain-default.eff) to the new ws3-overlay.eff (which needs to inherit from ws30.eff). The ws3-overlay.eff included /might/ just work without any other changes: the first pass is the WS3 als ultra settings pass, and the second overlay pass is unchanged from WS2 (the same terrain overlay shaders should probably work apart from texcoords and rawpos not being correct). - Materials/base/materials-base.xml: ws30Road material: uncomment line declaring terrain-default as the effect. The target effect for ws30 roads is road-*.eff and it's added to ws30Road and ws30Freeway but commented out as it's not working currently. - Misc: large scale transitions are turned on in ws30-ALS-landclass-search-functions.frag by default. Grow landclass borders with large scale transitions is now on by default. ---- Changes after the multi-texture support commit: ws30-ALS-ultra.vert - Added documentation: WS30 model space and z up space - for future people working on WS30, and people looking through shaders to rule out possibilities e.g. when fixing bugs, or interpreting visual bug reports. ws30-ALS-landclass-search-functions.frag: - For now, lookup_ground_texture_array() also looks up the relevant texture's index based on an integer. - Add get_mixed_texel() - looks up texel for this fragment and any neighbors before mixing. Moves currently shared mixing code out of 3 fragment shaders. Misc: changed indentation from mixed tabs/spaces to spaces in ws30-ALS-ultra frag and vert. The indentation can be changed again when the porting is complete. ws30-ALS vert/frag and ws30-ALS-detailed vert/frag: - Add varying for ground texture coordiante, currently set to gl_TexCoord[0]. Apply texture stretching dimensions in fragment shaders. - Misc: varying rawPos is set to vec2 for now, as relPos.z+eye_alt might be faster. Misc: keep WS2 mixing logic for now , including turning off mixing via the alpha channel of the textures ---- Changes after sending material parameters in uniform arrays commit: - Materials parameter for rock_strata is cast into an int so rock_strata==1 should work. Misc: Left over uniform for rock strata cleaned up. - ws30-ALS-ultra.frag and ws30-ALS-detailed.frag: Add missing mat_shininess for photoscenery case .
2022-01-03 15:43:29 +00:00
{
lightArg = (terminator/100000.0 - 10.0)/20.0;
light_diffuse.b = 0.78 + lightArg * 0.21;
light_diffuse.g = 0.907 + lightArg * 0.091;
light_diffuse.r = 0.904 + lightArg * 0.092;
light_diffuse.a = 1.0;
WS30: landclass and texture lookups in fragment shader commit e131ffaca7b2c934474f0e447b5852cb4c7c8d4a Author: vs <vs2009@mail.com> Date: Fri Oct 15 22:19:42 2021 +1000 WS30: landclass and texture lookups in fragment shader: Changelog: - Testing: Procedural random landclass function, get_random_landclass(). 1). Avoids a texture lookup for profiling. 2). Creates squares of configurable size with controllable random landclass ranges - to test landclass transition algorithms and quickly profile lots of landclasses in view. It's also possible to put pressure on GPU memory even with 1 lookup of ground textures per fragment, by reducing size to <20m and viewing from altitude. - Add ALS ultra technique as no 5, move existing ALS technique to no. 6. Add WS30-ALS-ultra frag & vert in preparation for eventual ALS ultra port. Change comments/variables to match using a texture array instead of atlas. Sampler name: atlas -> textureArray. - Testing/optimisation of de-tiling: WS30-ALS.frag: reorder perlin detiling to make noise source easier to switch. WS30-ALS-ultra.frag: Create alternative to perlin noise used for reducing tiling that avoids a texture lookup - to profile and optimise. This is commented out. The performance difference in the final version depends on memory pressure versus arithmetic load of the full shader. It varies by GPU and what's in view. In future, once a full ALS port is done, maybe it'll be more efficient to run a higher quality de-tiling algorithm all the time to avoid branching overhead due to effects like agriculture which need more de-tiling. De-tiling code in shaders should /eventually/ match CPU-side de-tiling of texture masks used for object and vegetation placement. De-tiling code in GPUs might be subject to precision and numerical artifacts, and if so maybe the texture lookup version would work better. The same applies to noise used for rendering WS3 water waves and collision queries. One option is to use exactly the same glsl code, with a C++ header to convert glsl syntax e.g. https://github.com/g-truc/glm .
2021-10-21 20:31:03 +00:00
WS30: MR #267: Improved texture lookups from VS Squashed commit of the following: commit 115511888c20c53670eba17a82c81c9af99d7302 Author: vs <vs2009@mail.com> Date: Mon Dec 6 18:52:06 2021 +1000 WS30 effects and shaders: Changelog: ws30-ALS-ultra.frag: - Ground textures lookups use their own coordinates separate from the landclass texture lookup. - Partial derivatives dFdx and Dfdy are packed together in a vec4, so simple multiplication to scale can be done in 1 instruction. dFdx = s and t components. dFdy = p and q components. These must be scaled properly for ground texture access as ground texture stretching and detiling of tex coords mean textures are scaled differently. - Added calculation of partial derivatives for texture coordinates used by the 5 non- base textures. dFdx() and dFdy() were called for nontrivial texture coordinate manipulation. - New control randomise_texture_lookups added at top of ws30-ALS-ultra.frag, in the development tools section. Setting this to 1 will do a stress test of ground texture array lookups. A fast random number generation function is used to assign each landclass 4 random textures from the ground texture array - this is done by . Performance will not be as bad in the full ALS port as some texture slots will better caching in memory - e.g. have 1 or a few variants. - Possible optimisation: use a 2nd or 3rd texture array for some of the non-base texture slots that typically have 256, 512, or 1024 textures. The resolutions of these arrays should change based on the largest loaded texture size in the active regional definitions - this will allow taking full advantage of smaller texture sizes in some areas. The disadvantage is some texture duplication with more slots. - Possible optimisation: offer the option to shrink textures by 50% or 25% - for texture slots that use large textures like base or mix slots. - Very temporary - reduce procedural normal map features with photoscenery active without breaking profiling, as the inputs to shaders are effect defaults or placeholder (by request on ML). ---- ws30-ALS-ultra.vert: - Start of conversion of geocentic world space xyz into lat/lon coords used for ground texture lookups. Currently commented out as it's unknown what model space coords are in (not geocentric it seems). ws20-ALS-landclass-search-functions.frag: - Add control for changing the ground texture array lookup function for debugging in case old compilers/GPUs have issues. tex_lookup_type: 0: normal( textureGrad(), 1: textureLod (manual Lod calculation), 2: texture() with no partial derivative adjustment. - New get6_random_integers() will extract 6 limited random values from the full precision of a 32 bit random value. - Old landclass_texel_size_m references are removed since textureSize() is used. There are no 'const in float' arguments that may cause issues on AMD compilers. ---- WS30-overlay effect (Inactive): - ws30-overlay.eff (derived from terrain-overlay.eff). Technique no "4" is used for two passes. The 1st pass is a copy of the ALS ultra pass (technique no "5") from ws30.eff. The 2nd pass is the same as terrain-overlay.eff. The 2nd pass uses terrain- overlay.frag from WS2. - grass-ALS.vert copied to ws30-ovelay-ALS.vert. To do: needs texture coords that don't change with tiles. - terrain-overlay-ALS.geom copied to ws30-overlay-ALS.geom. To do: uses gl_PositionIn [i].xy for position in the horizontal plane - assumes z is vertical. Tile model space doesn't seem to match this. - WS3 doesn't seem to have a way of switching references to terrain-overlay.eff (which inherits from terrain-default.eff) to the new ws3-overlay.eff (which needs to inherit from ws30.eff). The ws3-overlay.eff included /might/ just work without any other changes: the first pass is the WS3 als ultra settings pass, and the second overlay pass is unchanged from WS2 (the same terrain overlay shaders should probably work apart from texcoords and rawpos not being correct). - Materials/base/materials-base.xml: ws30Road material: uncomment line declaring terrain-default as the effect. The target effect for ws30 roads is road-*.eff and it's added to ws30Road and ws30Freeway but commented out as it's not working currently. - Misc: large scale transitions are turned on in ws30-ALS-landclass-search-functions.frag by default. Grow landclass borders with large scale transitions is now on by default. ---- Changes after the multi-texture support commit: ws30-ALS-ultra.vert - Added documentation: WS30 model space and z up space - for future people working on WS30, and people looking through shaders to rule out possibilities e.g. when fixing bugs, or interpreting visual bug reports. ws30-ALS-landclass-search-functions.frag: - For now, lookup_ground_texture_array() also looks up the relevant texture's index based on an integer. - Add get_mixed_texel() - looks up texel for this fragment and any neighbors before mixing. Moves currently shared mixing code out of 3 fragment shaders. Misc: changed indentation from mixed tabs/spaces to spaces in ws30-ALS-ultra frag and vert. The indentation can be changed again when the porting is complete. ws30-ALS vert/frag and ws30-ALS-detailed vert/frag: - Add varying for ground texture coordiante, currently set to gl_TexCoord[0]. Apply texture stretching dimensions in fragment shaders. - Misc: varying rawPos is set to vec2 for now, as relPos.z+eye_alt might be faster. Misc: keep WS2 mixing logic for now , including turning off mixing via the alpha channel of the textures ---- Changes after sending material parameters in uniform arrays commit: - Materials parameter for rock_strata is cast into an int so rock_strata==1 should work. Misc: Left over uniform for rock strata cleaned up. - ws30-ALS-ultra.frag and ws30-ALS-detailed.frag: Add missing mat_shininess for photoscenery case .
2022-01-03 15:43:29 +00:00
//light_ambient.b = 0.41 + lightArg * 0.08;
//light_ambient.g = 0.333 + lightArg * 0.06;
light_ambient.r = 0.316 + lightArg * 0.016;
light_ambient.g = light_ambient.r * 0.4/0.33;
light_ambient.b = light_ambient.r * 0.5/0.33;
light_ambient.a = 1.0;
specular_light.b = 0.78 + lightArg * 0.21;
specular_light.g = 0.907 + lightArg * 0.091;
specular_light.r = 0.904 + lightArg * 0.092;
WS30: MR #267: Improved texture lookups from VS Squashed commit of the following: commit 115511888c20c53670eba17a82c81c9af99d7302 Author: vs <vs2009@mail.com> Date: Mon Dec 6 18:52:06 2021 +1000 WS30 effects and shaders: Changelog: ws30-ALS-ultra.frag: - Ground textures lookups use their own coordinates separate from the landclass texture lookup. - Partial derivatives dFdx and Dfdy are packed together in a vec4, so simple multiplication to scale can be done in 1 instruction. dFdx = s and t components. dFdy = p and q components. These must be scaled properly for ground texture access as ground texture stretching and detiling of tex coords mean textures are scaled differently. - Added calculation of partial derivatives for texture coordinates used by the 5 non- base textures. dFdx() and dFdy() were called for nontrivial texture coordinate manipulation. - New control randomise_texture_lookups added at top of ws30-ALS-ultra.frag, in the development tools section. Setting this to 1 will do a stress test of ground texture array lookups. A fast random number generation function is used to assign each landclass 4 random textures from the ground texture array - this is done by . Performance will not be as bad in the full ALS port as some texture slots will better caching in memory - e.g. have 1 or a few variants. - Possible optimisation: use a 2nd or 3rd texture array for some of the non-base texture slots that typically have 256, 512, or 1024 textures. The resolutions of these arrays should change based on the largest loaded texture size in the active regional definitions - this will allow taking full advantage of smaller texture sizes in some areas. The disadvantage is some texture duplication with more slots. - Possible optimisation: offer the option to shrink textures by 50% or 25% - for texture slots that use large textures like base or mix slots. - Very temporary - reduce procedural normal map features with photoscenery active without breaking profiling, as the inputs to shaders are effect defaults or placeholder (by request on ML). ---- ws30-ALS-ultra.vert: - Start of conversion of geocentic world space xyz into lat/lon coords used for ground texture lookups. Currently commented out as it's unknown what model space coords are in (not geocentric it seems). ws20-ALS-landclass-search-functions.frag: - Add control for changing the ground texture array lookup function for debugging in case old compilers/GPUs have issues. tex_lookup_type: 0: normal( textureGrad(), 1: textureLod (manual Lod calculation), 2: texture() with no partial derivative adjustment. - New get6_random_integers() will extract 6 limited random values from the full precision of a 32 bit random value. - Old landclass_texel_size_m references are removed since textureSize() is used. There are no 'const in float' arguments that may cause issues on AMD compilers. ---- WS30-overlay effect (Inactive): - ws30-overlay.eff (derived from terrain-overlay.eff). Technique no "4" is used for two passes. The 1st pass is a copy of the ALS ultra pass (technique no "5") from ws30.eff. The 2nd pass is the same as terrain-overlay.eff. The 2nd pass uses terrain- overlay.frag from WS2. - grass-ALS.vert copied to ws30-ovelay-ALS.vert. To do: needs texture coords that don't change with tiles. - terrain-overlay-ALS.geom copied to ws30-overlay-ALS.geom. To do: uses gl_PositionIn [i].xy for position in the horizontal plane - assumes z is vertical. Tile model space doesn't seem to match this. - WS3 doesn't seem to have a way of switching references to terrain-overlay.eff (which inherits from terrain-default.eff) to the new ws3-overlay.eff (which needs to inherit from ws30.eff). The ws3-overlay.eff included /might/ just work without any other changes: the first pass is the WS3 als ultra settings pass, and the second overlay pass is unchanged from WS2 (the same terrain overlay shaders should probably work apart from texcoords and rawpos not being correct). - Materials/base/materials-base.xml: ws30Road material: uncomment line declaring terrain-default as the effect. The target effect for ws30 roads is road-*.eff and it's added to ws30Road and ws30Freeway but commented out as it's not working currently. - Misc: large scale transitions are turned on in ws30-ALS-landclass-search-functions.frag by default. Grow landclass borders with large scale transitions is now on by default. ---- Changes after the multi-texture support commit: ws30-ALS-ultra.vert - Added documentation: WS30 model space and z up space - for future people working on WS30, and people looking through shaders to rule out possibilities e.g. when fixing bugs, or interpreting visual bug reports. ws30-ALS-landclass-search-functions.frag: - For now, lookup_ground_texture_array() also looks up the relevant texture's index based on an integer. - Add get_mixed_texel() - looks up texel for this fragment and any neighbors before mixing. Moves currently shared mixing code out of 3 fragment shaders. Misc: changed indentation from mixed tabs/spaces to spaces in ws30-ALS-ultra frag and vert. The indentation can be changed again when the porting is complete. ws30-ALS vert/frag and ws30-ALS-detailed vert/frag: - Add varying for ground texture coordiante, currently set to gl_TexCoord[0]. Apply texture stretching dimensions in fragment shaders. - Misc: varying rawPos is set to vec2 for now, as relPos.z+eye_alt might be faster. Misc: keep WS2 mixing logic for now , including turning off mixing via the alpha channel of the textures ---- Changes after sending material parameters in uniform arrays commit: - Materials parameter for rock_strata is cast into an int so rock_strata==1 should work. Misc: Left over uniform for rock strata cleaned up. - ws30-ALS-ultra.frag and ws30-ALS-detailed.frag: Add missing mat_shininess for photoscenery case .
2022-01-03 15:43:29 +00:00
}
WS30: landclass and texture lookups in fragment shader commit e131ffaca7b2c934474f0e447b5852cb4c7c8d4a Author: vs <vs2009@mail.com> Date: Fri Oct 15 22:19:42 2021 +1000 WS30: landclass and texture lookups in fragment shader: Changelog: - Testing: Procedural random landclass function, get_random_landclass(). 1). Avoids a texture lookup for profiling. 2). Creates squares of configurable size with controllable random landclass ranges - to test landclass transition algorithms and quickly profile lots of landclasses in view. It's also possible to put pressure on GPU memory even with 1 lookup of ground textures per fragment, by reducing size to <20m and viewing from altitude. - Add ALS ultra technique as no 5, move existing ALS technique to no. 6. Add WS30-ALS-ultra frag & vert in preparation for eventual ALS ultra port. Change comments/variables to match using a texture array instead of atlas. Sampler name: atlas -> textureArray. - Testing/optimisation of de-tiling: WS30-ALS.frag: reorder perlin detiling to make noise source easier to switch. WS30-ALS-ultra.frag: Create alternative to perlin noise used for reducing tiling that avoids a texture lookup - to profile and optimise. This is commented out. The performance difference in the final version depends on memory pressure versus arithmetic load of the full shader. It varies by GPU and what's in view. In future, once a full ALS port is done, maybe it'll be more efficient to run a higher quality de-tiling algorithm all the time to avoid branching overhead due to effects like agriculture which need more de-tiling. De-tiling code in shaders should /eventually/ match CPU-side de-tiling of texture masks used for object and vegetation placement. De-tiling code in GPUs might be subject to precision and numerical artifacts, and if so maybe the texture lookup version would work better. The same applies to noise used for rendering WS3 water waves and collision queries. One option is to use exactly the same glsl code, with a C++ header to convert glsl syntax e.g. https://github.com/g-truc/glm .
2021-10-21 20:31:03 +00:00
light_diffuse = light_diffuse * scattering;
specular_light = specular_light * scattering;
WS30: landclass and texture lookups in fragment shader commit e131ffaca7b2c934474f0e447b5852cb4c7c8d4a Author: vs <vs2009@mail.com> Date: Fri Oct 15 22:19:42 2021 +1000 WS30: landclass and texture lookups in fragment shader: Changelog: - Testing: Procedural random landclass function, get_random_landclass(). 1). Avoids a texture lookup for profiling. 2). Creates squares of configurable size with controllable random landclass ranges - to test landclass transition algorithms and quickly profile lots of landclasses in view. It's also possible to put pressure on GPU memory even with 1 lookup of ground textures per fragment, by reducing size to <20m and viewing from altitude. - Add ALS ultra technique as no 5, move existing ALS technique to no. 6. Add WS30-ALS-ultra frag & vert in preparation for eventual ALS ultra port. Change comments/variables to match using a texture array instead of atlas. Sampler name: atlas -> textureArray. - Testing/optimisation of de-tiling: WS30-ALS.frag: reorder perlin detiling to make noise source easier to switch. WS30-ALS-ultra.frag: Create alternative to perlin noise used for reducing tiling that avoids a texture lookup - to profile and optimise. This is commented out. The performance difference in the final version depends on memory pressure versus arithmetic load of the full shader. It varies by GPU and what's in view. In future, once a full ALS port is done, maybe it'll be more efficient to run a higher quality de-tiling algorithm all the time to avoid branching overhead due to effects like agriculture which need more de-tiling. De-tiling code in shaders should /eventually/ match CPU-side de-tiling of texture masks used for object and vegetation placement. De-tiling code in GPUs might be subject to precision and numerical artifacts, and if so maybe the texture lookup version would work better. The same applies to noise used for rendering WS3 water waves and collision queries. One option is to use exactly the same glsl code, with a C++ header to convert glsl syntax e.g. https://github.com/g-truc/glm .
2021-10-21 20:31:03 +00:00
yprime_alt = -sqrt(2.0 * EarthRadius * hazeLayerAltitude);
WS30: MR #267: Improved texture lookups from VS Squashed commit of the following: commit 115511888c20c53670eba17a82c81c9af99d7302 Author: vs <vs2009@mail.com> Date: Mon Dec 6 18:52:06 2021 +1000 WS30 effects and shaders: Changelog: ws30-ALS-ultra.frag: - Ground textures lookups use their own coordinates separate from the landclass texture lookup. - Partial derivatives dFdx and Dfdy are packed together in a vec4, so simple multiplication to scale can be done in 1 instruction. dFdx = s and t components. dFdy = p and q components. These must be scaled properly for ground texture access as ground texture stretching and detiling of tex coords mean textures are scaled differently. - Added calculation of partial derivatives for texture coordinates used by the 5 non- base textures. dFdx() and dFdy() were called for nontrivial texture coordinate manipulation. - New control randomise_texture_lookups added at top of ws30-ALS-ultra.frag, in the development tools section. Setting this to 1 will do a stress test of ground texture array lookups. A fast random number generation function is used to assign each landclass 4 random textures from the ground texture array - this is done by . Performance will not be as bad in the full ALS port as some texture slots will better caching in memory - e.g. have 1 or a few variants. - Possible optimisation: use a 2nd or 3rd texture array for some of the non-base texture slots that typically have 256, 512, or 1024 textures. The resolutions of these arrays should change based on the largest loaded texture size in the active regional definitions - this will allow taking full advantage of smaller texture sizes in some areas. The disadvantage is some texture duplication with more slots. - Possible optimisation: offer the option to shrink textures by 50% or 25% - for texture slots that use large textures like base or mix slots. - Very temporary - reduce procedural normal map features with photoscenery active without breaking profiling, as the inputs to shaders are effect defaults or placeholder (by request on ML). ---- ws30-ALS-ultra.vert: - Start of conversion of geocentic world space xyz into lat/lon coords used for ground texture lookups. Currently commented out as it's unknown what model space coords are in (not geocentric it seems). ws20-ALS-landclass-search-functions.frag: - Add control for changing the ground texture array lookup function for debugging in case old compilers/GPUs have issues. tex_lookup_type: 0: normal( textureGrad(), 1: textureLod (manual Lod calculation), 2: texture() with no partial derivative adjustment. - New get6_random_integers() will extract 6 limited random values from the full precision of a 32 bit random value. - Old landclass_texel_size_m references are removed since textureSize() is used. There are no 'const in float' arguments that may cause issues on AMD compilers. ---- WS30-overlay effect (Inactive): - ws30-overlay.eff (derived from terrain-overlay.eff). Technique no "4" is used for two passes. The 1st pass is a copy of the ALS ultra pass (technique no "5") from ws30.eff. The 2nd pass is the same as terrain-overlay.eff. The 2nd pass uses terrain- overlay.frag from WS2. - grass-ALS.vert copied to ws30-ovelay-ALS.vert. To do: needs texture coords that don't change with tiles. - terrain-overlay-ALS.geom copied to ws30-overlay-ALS.geom. To do: uses gl_PositionIn [i].xy for position in the horizontal plane - assumes z is vertical. Tile model space doesn't seem to match this. - WS3 doesn't seem to have a way of switching references to terrain-overlay.eff (which inherits from terrain-default.eff) to the new ws3-overlay.eff (which needs to inherit from ws30.eff). The ws3-overlay.eff included /might/ just work without any other changes: the first pass is the WS3 als ultra settings pass, and the second overlay pass is unchanged from WS2 (the same terrain overlay shaders should probably work apart from texcoords and rawpos not being correct). - Materials/base/materials-base.xml: ws30Road material: uncomment line declaring terrain-default as the effect. The target effect for ws30 roads is road-*.eff and it's added to ws30Road and ws30Freeway but commented out as it's not working currently. - Misc: large scale transitions are turned on in ws30-ALS-landclass-search-functions.frag by default. Grow landclass borders with large scale transitions is now on by default. ---- Changes after the multi-texture support commit: ws30-ALS-ultra.vert - Added documentation: WS30 model space and z up space - for future people working on WS30, and people looking through shaders to rule out possibilities e.g. when fixing bugs, or interpreting visual bug reports. ws30-ALS-landclass-search-functions.frag: - For now, lookup_ground_texture_array() also looks up the relevant texture's index based on an integer. - Add get_mixed_texel() - looks up texel for this fragment and any neighbors before mixing. Moves currently shared mixing code out of 3 fragment shaders. Misc: changed indentation from mixed tabs/spaces to spaces in ws30-ALS-ultra frag and vert. The indentation can be changed again when the porting is complete. ws30-ALS vert/frag and ws30-ALS-detailed vert/frag: - Add varying for ground texture coordiante, currently set to gl_TexCoord[0]. Apply texture stretching dimensions in fragment shaders. - Misc: varying rawPos is set to vec2 for now, as relPos.z+eye_alt might be faster. Misc: keep WS2 mixing logic for now , including turning off mixing via the alpha channel of the textures ---- Changes after sending material parameters in uniform arrays commit: - Materials parameter for rock_strata is cast into an int so rock_strata==1 should work. Misc: Left over uniform for rock strata cleaned up. - ws30-ALS-ultra.frag and ws30-ALS-detailed.frag: Add missing mat_shininess for photoscenery case .
2022-01-03 15:43:29 +00:00
} //End the faster, full-day version without lightfields
WS30: landclass and texture lookups in fragment shader commit e131ffaca7b2c934474f0e447b5852cb4c7c8d4a Author: vs <vs2009@mail.com> Date: Fri Oct 15 22:19:42 2021 +1000 WS30: landclass and texture lookups in fragment shader: Changelog: - Testing: Procedural random landclass function, get_random_landclass(). 1). Avoids a texture lookup for profiling. 2). Creates squares of configurable size with controllable random landclass ranges - to test landclass transition algorithms and quickly profile lots of landclasses in view. It's also possible to put pressure on GPU memory even with 1 lookup of ground textures per fragment, by reducing size to <20m and viewing from altitude. - Add ALS ultra technique as no 5, move existing ALS technique to no. 6. Add WS30-ALS-ultra frag & vert in preparation for eventual ALS ultra port. Change comments/variables to match using a texture array instead of atlas. Sampler name: atlas -> textureArray. - Testing/optimisation of de-tiling: WS30-ALS.frag: reorder perlin detiling to make noise source easier to switch. WS30-ALS-ultra.frag: Create alternative to perlin noise used for reducing tiling that avoids a texture lookup - to profile and optimise. This is commented out. The performance difference in the final version depends on memory pressure versus arithmetic load of the full shader. It varies by GPU and what's in view. In future, once a full ALS port is done, maybe it'll be more efficient to run a higher quality de-tiling algorithm all the time to avoid branching overhead due to effects like agriculture which need more de-tiling. De-tiling code in shaders should /eventually/ match CPU-side de-tiling of texture masks used for object and vegetation placement. De-tiling code in GPUs might be subject to precision and numerical artifacts, and if so maybe the texture lookup version would work better. The same applies to noise used for rendering WS3 water waves and collision queries. One option is to use exactly the same glsl code, with a C++ header to convert glsl syntax e.g. https://github.com/g-truc/glm .
2021-10-21 20:31:03 +00:00
WS30: MR #267: Improved texture lookups from VS Squashed commit of the following: commit 115511888c20c53670eba17a82c81c9af99d7302 Author: vs <vs2009@mail.com> Date: Mon Dec 6 18:52:06 2021 +1000 WS30 effects and shaders: Changelog: ws30-ALS-ultra.frag: - Ground textures lookups use their own coordinates separate from the landclass texture lookup. - Partial derivatives dFdx and Dfdy are packed together in a vec4, so simple multiplication to scale can be done in 1 instruction. dFdx = s and t components. dFdy = p and q components. These must be scaled properly for ground texture access as ground texture stretching and detiling of tex coords mean textures are scaled differently. - Added calculation of partial derivatives for texture coordinates used by the 5 non- base textures. dFdx() and dFdy() were called for nontrivial texture coordinate manipulation. - New control randomise_texture_lookups added at top of ws30-ALS-ultra.frag, in the development tools section. Setting this to 1 will do a stress test of ground texture array lookups. A fast random number generation function is used to assign each landclass 4 random textures from the ground texture array - this is done by . Performance will not be as bad in the full ALS port as some texture slots will better caching in memory - e.g. have 1 or a few variants. - Possible optimisation: use a 2nd or 3rd texture array for some of the non-base texture slots that typically have 256, 512, or 1024 textures. The resolutions of these arrays should change based on the largest loaded texture size in the active regional definitions - this will allow taking full advantage of smaller texture sizes in some areas. The disadvantage is some texture duplication with more slots. - Possible optimisation: offer the option to shrink textures by 50% or 25% - for texture slots that use large textures like base or mix slots. - Very temporary - reduce procedural normal map features with photoscenery active without breaking profiling, as the inputs to shaders are effect defaults or placeholder (by request on ML). ---- ws30-ALS-ultra.vert: - Start of conversion of geocentic world space xyz into lat/lon coords used for ground texture lookups. Currently commented out as it's unknown what model space coords are in (not geocentric it seems). ws20-ALS-landclass-search-functions.frag: - Add control for changing the ground texture array lookup function for debugging in case old compilers/GPUs have issues. tex_lookup_type: 0: normal( textureGrad(), 1: textureLod (manual Lod calculation), 2: texture() with no partial derivative adjustment. - New get6_random_integers() will extract 6 limited random values from the full precision of a 32 bit random value. - Old landclass_texel_size_m references are removed since textureSize() is used. There are no 'const in float' arguments that may cause issues on AMD compilers. ---- WS30-overlay effect (Inactive): - ws30-overlay.eff (derived from terrain-overlay.eff). Technique no "4" is used for two passes. The 1st pass is a copy of the ALS ultra pass (technique no "5") from ws30.eff. The 2nd pass is the same as terrain-overlay.eff. The 2nd pass uses terrain- overlay.frag from WS2. - grass-ALS.vert copied to ws30-ovelay-ALS.vert. To do: needs texture coords that don't change with tiles. - terrain-overlay-ALS.geom copied to ws30-overlay-ALS.geom. To do: uses gl_PositionIn [i].xy for position in the horizontal plane - assumes z is vertical. Tile model space doesn't seem to match this. - WS3 doesn't seem to have a way of switching references to terrain-overlay.eff (which inherits from terrain-default.eff) to the new ws3-overlay.eff (which needs to inherit from ws30.eff). The ws3-overlay.eff included /might/ just work without any other changes: the first pass is the WS3 als ultra settings pass, and the second overlay pass is unchanged from WS2 (the same terrain overlay shaders should probably work apart from texcoords and rawpos not being correct). - Materials/base/materials-base.xml: ws30Road material: uncomment line declaring terrain-default as the effect. The target effect for ws30 roads is road-*.eff and it's added to ws30Road and ws30Freeway but commented out as it's not working currently. - Misc: large scale transitions are turned on in ws30-ALS-landclass-search-functions.frag by default. Grow landclass borders with large scale transitions is now on by default. ---- Changes after the multi-texture support commit: ws30-ALS-ultra.vert - Added documentation: WS30 model space and z up space - for future people working on WS30, and people looking through shaders to rule out possibilities e.g. when fixing bugs, or interpreting visual bug reports. ws30-ALS-landclass-search-functions.frag: - For now, lookup_ground_texture_array() also looks up the relevant texture's index based on an integer. - Add get_mixed_texel() - looks up texel for this fragment and any neighbors before mixing. Moves currently shared mixing code out of 3 fragment shaders. Misc: changed indentation from mixed tabs/spaces to spaces in ws30-ALS-ultra frag and vert. The indentation can be changed again when the porting is complete. ws30-ALS vert/frag and ws30-ALS-detailed vert/frag: - Add varying for ground texture coordiante, currently set to gl_TexCoord[0]. Apply texture stretching dimensions in fragment shaders. - Misc: varying rawPos is set to vec2 for now, as relPos.z+eye_alt might be faster. Misc: keep WS2 mixing logic for now , including turning off mixing via the alpha channel of the textures ---- Changes after sending material parameters in uniform arrays commit: - Materials parameter for rock_strata is cast into an int so rock_strata==1 should work. Misc: Left over uniform for rock strata cleaned up. - ws30-ALS-ultra.frag and ws30-ALS-detailed.frag: Add missing mat_shininess for photoscenery case .
2022-01-03 15:43:29 +00:00
// a sky/earth irradiation map model - the sky creates much more diffuse radiation than the ground, so
// steep faces end up shaded more
light_ambient = light_ambient * ((1.0+steepness)/2.0 * 1.2 + (1.0-steepness)/2.0 * 0.2);
WS30 shaders: Add WS3 detailed technique using the "6" slot. Port the ALS haze, lighting, and math parts of the detailed and ultra shaders. The texture lookups are left out. Shader selection based on terrain quality setting: - Ultra - ws30-ALS-ultra frag/vert. - High and Medium - ws30-ALS-detailed frag/vert. The shaders switch code paths based on quality level uniform. - Low - ws30-ALS frag/vert. Changelog: ws30-ALS vertex shaders: - Ambient colour material colour doesn't seem to be used in the vertex shader, and isn't sent to fragment shaders currently. Regional materials only define non-default ambient colour of vec4(0.0) for water, ocean etc. Otherwise the default value of vec4(0.2, 0.2, 0.2, 1.0) is used. ws30-ALS.frag: - Set alpha of color to diffuse_term.a, to be consistent with WS2 implementation. ws30-ALS-ultra.frag and ws30-ALS-detailed.frag - World pos is assigned a value to allow noise functions to compile. - Swatch_size is temporarily set to 2000m instead of the xsize texture dimension to allow noise math to run while landclass search and texture arrays are being looked up. Swatch_size is used to adjust the wavelength of multiple overlay mixing noise wavelengths based on how far the textures are stretched (WiP WS2 feature). There are some noise calculations that could run while the first landclass lookup happens. If this is not enough, the selection of calculated noise wavelengths to add could change based on how far the textures are stretched, instead of changing the wavelengths at calculation time. - Move photoscenery technique no "4" after technique no "7" without changing the index (in case the low index is needed for photoscenery). This makes viewing a diff with the WS2 effect easier. Performance: Currently there's only 1 ground texture lookup and landclass transitions for that texture. The ultra shader looks up 5 more textures. Probably transitions for 1 more texture need to be supported, as often a base and overlay texture are mixed contributing heavily to visible colour. The math overhead is mostly present, except for noise math being better hidden than in the eventual version. Some of the texture array lookups in the full version may be hidden by the math - depending on GPU memory handling compared to calculation speed.
2021-11-09 14:25:09 +00:00
WS30: MR #267: Improved texture lookups from VS Squashed commit of the following: commit 115511888c20c53670eba17a82c81c9af99d7302 Author: vs <vs2009@mail.com> Date: Mon Dec 6 18:52:06 2021 +1000 WS30 effects and shaders: Changelog: ws30-ALS-ultra.frag: - Ground textures lookups use their own coordinates separate from the landclass texture lookup. - Partial derivatives dFdx and Dfdy are packed together in a vec4, so simple multiplication to scale can be done in 1 instruction. dFdx = s and t components. dFdy = p and q components. These must be scaled properly for ground texture access as ground texture stretching and detiling of tex coords mean textures are scaled differently. - Added calculation of partial derivatives for texture coordinates used by the 5 non- base textures. dFdx() and dFdy() were called for nontrivial texture coordinate manipulation. - New control randomise_texture_lookups added at top of ws30-ALS-ultra.frag, in the development tools section. Setting this to 1 will do a stress test of ground texture array lookups. A fast random number generation function is used to assign each landclass 4 random textures from the ground texture array - this is done by . Performance will not be as bad in the full ALS port as some texture slots will better caching in memory - e.g. have 1 or a few variants. - Possible optimisation: use a 2nd or 3rd texture array for some of the non-base texture slots that typically have 256, 512, or 1024 textures. The resolutions of these arrays should change based on the largest loaded texture size in the active regional definitions - this will allow taking full advantage of smaller texture sizes in some areas. The disadvantage is some texture duplication with more slots. - Possible optimisation: offer the option to shrink textures by 50% or 25% - for texture slots that use large textures like base or mix slots. - Very temporary - reduce procedural normal map features with photoscenery active without breaking profiling, as the inputs to shaders are effect defaults or placeholder (by request on ML). ---- ws30-ALS-ultra.vert: - Start of conversion of geocentic world space xyz into lat/lon coords used for ground texture lookups. Currently commented out as it's unknown what model space coords are in (not geocentric it seems). ws20-ALS-landclass-search-functions.frag: - Add control for changing the ground texture array lookup function for debugging in case old compilers/GPUs have issues. tex_lookup_type: 0: normal( textureGrad(), 1: textureLod (manual Lod calculation), 2: texture() with no partial derivative adjustment. - New get6_random_integers() will extract 6 limited random values from the full precision of a 32 bit random value. - Old landclass_texel_size_m references are removed since textureSize() is used. There are no 'const in float' arguments that may cause issues on AMD compilers. ---- WS30-overlay effect (Inactive): - ws30-overlay.eff (derived from terrain-overlay.eff). Technique no "4" is used for two passes. The 1st pass is a copy of the ALS ultra pass (technique no "5") from ws30.eff. The 2nd pass is the same as terrain-overlay.eff. The 2nd pass uses terrain- overlay.frag from WS2. - grass-ALS.vert copied to ws30-ovelay-ALS.vert. To do: needs texture coords that don't change with tiles. - terrain-overlay-ALS.geom copied to ws30-overlay-ALS.geom. To do: uses gl_PositionIn [i].xy for position in the horizontal plane - assumes z is vertical. Tile model space doesn't seem to match this. - WS3 doesn't seem to have a way of switching references to terrain-overlay.eff (which inherits from terrain-default.eff) to the new ws3-overlay.eff (which needs to inherit from ws30.eff). The ws3-overlay.eff included /might/ just work without any other changes: the first pass is the WS3 als ultra settings pass, and the second overlay pass is unchanged from WS2 (the same terrain overlay shaders should probably work apart from texcoords and rawpos not being correct). - Materials/base/materials-base.xml: ws30Road material: uncomment line declaring terrain-default as the effect. The target effect for ws30 roads is road-*.eff and it's added to ws30Road and ws30Freeway but commented out as it's not working currently. - Misc: large scale transitions are turned on in ws30-ALS-landclass-search-functions.frag by default. Grow landclass borders with large scale transitions is now on by default. ---- Changes after the multi-texture support commit: ws30-ALS-ultra.vert - Added documentation: WS30 model space and z up space - for future people working on WS30, and people looking through shaders to rule out possibilities e.g. when fixing bugs, or interpreting visual bug reports. ws30-ALS-landclass-search-functions.frag: - For now, lookup_ground_texture_array() also looks up the relevant texture's index based on an integer. - Add get_mixed_texel() - looks up texel for this fragment and any neighbors before mixing. Moves currently shared mixing code out of 3 fragment shaders. Misc: changed indentation from mixed tabs/spaces to spaces in ws30-ALS-ultra frag and vert. The indentation can be changed again when the porting is complete. ws30-ALS vert/frag and ws30-ALS-detailed vert/frag: - Add varying for ground texture coordiante, currently set to gl_TexCoord[0]. Apply texture stretching dimensions in fragment shaders. - Misc: varying rawPos is set to vec2 for now, as relPos.z+eye_alt might be faster. Misc: keep WS2 mixing logic for now , including turning off mixing via the alpha channel of the textures ---- Changes after sending material parameters in uniform arrays commit: - Materials parameter for rock_strata is cast into an int so rock_strata==1 should work. Misc: Left over uniform for rock strata cleaned up. - ws30-ALS-ultra.frag and ws30-ALS-detailed.frag: Add missing mat_shininess for photoscenery case .
2022-01-03 15:43:29 +00:00
// deeper shadows when there is lots of direct light
WS30: landclass and texture lookups in fragment shader commit e131ffaca7b2c934474f0e447b5852cb4c7c8d4a Author: vs <vs2009@mail.com> Date: Fri Oct 15 22:19:42 2021 +1000 WS30: landclass and texture lookups in fragment shader: Changelog: - Testing: Procedural random landclass function, get_random_landclass(). 1). Avoids a texture lookup for profiling. 2). Creates squares of configurable size with controllable random landclass ranges - to test landclass transition algorithms and quickly profile lots of landclasses in view. It's also possible to put pressure on GPU memory even with 1 lookup of ground textures per fragment, by reducing size to <20m and viewing from altitude. - Add ALS ultra technique as no 5, move existing ALS technique to no. 6. Add WS30-ALS-ultra frag & vert in preparation for eventual ALS ultra port. Change comments/variables to match using a texture array instead of atlas. Sampler name: atlas -> textureArray. - Testing/optimisation of de-tiling: WS30-ALS.frag: reorder perlin detiling to make noise source easier to switch. WS30-ALS-ultra.frag: Create alternative to perlin noise used for reducing tiling that avoids a texture lookup - to profile and optimise. This is commented out. The performance difference in the final version depends on memory pressure versus arithmetic load of the full shader. It varies by GPU and what's in view. In future, once a full ALS port is done, maybe it'll be more efficient to run a higher quality de-tiling algorithm all the time to avoid branching overhead due to effects like agriculture which need more de-tiling. De-tiling code in shaders should /eventually/ match CPU-side de-tiling of texture masks used for object and vegetation placement. De-tiling code in GPUs might be subject to precision and numerical artifacts, and if so maybe the texture lookup version would work better. The same applies to noise used for rendering WS3 water waves and collision queries. One option is to use exactly the same glsl code, with a C++ header to convert glsl syntax e.g. https://github.com/g-truc/glm .
2021-10-21 20:31:03 +00:00
WS30: MR #267: Improved texture lookups from VS Squashed commit of the following: commit 115511888c20c53670eba17a82c81c9af99d7302 Author: vs <vs2009@mail.com> Date: Mon Dec 6 18:52:06 2021 +1000 WS30 effects and shaders: Changelog: ws30-ALS-ultra.frag: - Ground textures lookups use their own coordinates separate from the landclass texture lookup. - Partial derivatives dFdx and Dfdy are packed together in a vec4, so simple multiplication to scale can be done in 1 instruction. dFdx = s and t components. dFdy = p and q components. These must be scaled properly for ground texture access as ground texture stretching and detiling of tex coords mean textures are scaled differently. - Added calculation of partial derivatives for texture coordinates used by the 5 non- base textures. dFdx() and dFdy() were called for nontrivial texture coordinate manipulation. - New control randomise_texture_lookups added at top of ws30-ALS-ultra.frag, in the development tools section. Setting this to 1 will do a stress test of ground texture array lookups. A fast random number generation function is used to assign each landclass 4 random textures from the ground texture array - this is done by . Performance will not be as bad in the full ALS port as some texture slots will better caching in memory - e.g. have 1 or a few variants. - Possible optimisation: use a 2nd or 3rd texture array for some of the non-base texture slots that typically have 256, 512, or 1024 textures. The resolutions of these arrays should change based on the largest loaded texture size in the active regional definitions - this will allow taking full advantage of smaller texture sizes in some areas. The disadvantage is some texture duplication with more slots. - Possible optimisation: offer the option to shrink textures by 50% or 25% - for texture slots that use large textures like base or mix slots. - Very temporary - reduce procedural normal map features with photoscenery active without breaking profiling, as the inputs to shaders are effect defaults or placeholder (by request on ML). ---- ws30-ALS-ultra.vert: - Start of conversion of geocentic world space xyz into lat/lon coords used for ground texture lookups. Currently commented out as it's unknown what model space coords are in (not geocentric it seems). ws20-ALS-landclass-search-functions.frag: - Add control for changing the ground texture array lookup function for debugging in case old compilers/GPUs have issues. tex_lookup_type: 0: normal( textureGrad(), 1: textureLod (manual Lod calculation), 2: texture() with no partial derivative adjustment. - New get6_random_integers() will extract 6 limited random values from the full precision of a 32 bit random value. - Old landclass_texel_size_m references are removed since textureSize() is used. There are no 'const in float' arguments that may cause issues on AMD compilers. ---- WS30-overlay effect (Inactive): - ws30-overlay.eff (derived from terrain-overlay.eff). Technique no "4" is used for two passes. The 1st pass is a copy of the ALS ultra pass (technique no "5") from ws30.eff. The 2nd pass is the same as terrain-overlay.eff. The 2nd pass uses terrain- overlay.frag from WS2. - grass-ALS.vert copied to ws30-ovelay-ALS.vert. To do: needs texture coords that don't change with tiles. - terrain-overlay-ALS.geom copied to ws30-overlay-ALS.geom. To do: uses gl_PositionIn [i].xy for position in the horizontal plane - assumes z is vertical. Tile model space doesn't seem to match this. - WS3 doesn't seem to have a way of switching references to terrain-overlay.eff (which inherits from terrain-default.eff) to the new ws3-overlay.eff (which needs to inherit from ws30.eff). The ws3-overlay.eff included /might/ just work without any other changes: the first pass is the WS3 als ultra settings pass, and the second overlay pass is unchanged from WS2 (the same terrain overlay shaders should probably work apart from texcoords and rawpos not being correct). - Materials/base/materials-base.xml: ws30Road material: uncomment line declaring terrain-default as the effect. The target effect for ws30 roads is road-*.eff and it's added to ws30Road and ws30Freeway but commented out as it's not working currently. - Misc: large scale transitions are turned on in ws30-ALS-landclass-search-functions.frag by default. Grow landclass borders with large scale transitions is now on by default. ---- Changes after the multi-texture support commit: ws30-ALS-ultra.vert - Added documentation: WS30 model space and z up space - for future people working on WS30, and people looking through shaders to rule out possibilities e.g. when fixing bugs, or interpreting visual bug reports. ws30-ALS-landclass-search-functions.frag: - For now, lookup_ground_texture_array() also looks up the relevant texture's index based on an integer. - Add get_mixed_texel() - looks up texel for this fragment and any neighbors before mixing. Moves currently shared mixing code out of 3 fragment shaders. Misc: changed indentation from mixed tabs/spaces to spaces in ws30-ALS-ultra frag and vert. The indentation can be changed again when the porting is complete. ws30-ALS vert/frag and ws30-ALS-detailed vert/frag: - Add varying for ground texture coordiante, currently set to gl_TexCoord[0]. Apply texture stretching dimensions in fragment shaders. - Misc: varying rawPos is set to vec2 for now, as relPos.z+eye_alt might be faster. Misc: keep WS2 mixing logic for now , including turning off mixing via the alpha channel of the textures ---- Changes after sending material parameters in uniform arrays commit: - Materials parameter for rock_strata is cast into an int so rock_strata==1 should work. Misc: Left over uniform for rock strata cleaned up. - ws30-ALS-ultra.frag and ws30-ALS-detailed.frag: Add missing mat_shininess for photoscenery case .
2022-01-03 15:43:29 +00:00
float shade_depth = 1.0 * smoothstep (0.6,0.95,ground_scattering) * (1.0-smoothstep(0.1,0.5,overcast)) * smoothstep(0.4,1.5,earthShade);
light_ambient.rgb = light_ambient.rgb * (1.0 - shade_depth);
light_diffuse.rgb = light_diffuse.rgb * (1.0 + 1.2 * shade_depth);
specular_light.rgb *= (1.0 + 1.2 * shade_depth);
WS30: MR #267: Improved texture lookups from VS Squashed commit of the following: commit 115511888c20c53670eba17a82c81c9af99d7302 Author: vs <vs2009@mail.com> Date: Mon Dec 6 18:52:06 2021 +1000 WS30 effects and shaders: Changelog: ws30-ALS-ultra.frag: - Ground textures lookups use their own coordinates separate from the landclass texture lookup. - Partial derivatives dFdx and Dfdy are packed together in a vec4, so simple multiplication to scale can be done in 1 instruction. dFdx = s and t components. dFdy = p and q components. These must be scaled properly for ground texture access as ground texture stretching and detiling of tex coords mean textures are scaled differently. - Added calculation of partial derivatives for texture coordinates used by the 5 non- base textures. dFdx() and dFdy() were called for nontrivial texture coordinate manipulation. - New control randomise_texture_lookups added at top of ws30-ALS-ultra.frag, in the development tools section. Setting this to 1 will do a stress test of ground texture array lookups. A fast random number generation function is used to assign each landclass 4 random textures from the ground texture array - this is done by . Performance will not be as bad in the full ALS port as some texture slots will better caching in memory - e.g. have 1 or a few variants. - Possible optimisation: use a 2nd or 3rd texture array for some of the non-base texture slots that typically have 256, 512, or 1024 textures. The resolutions of these arrays should change based on the largest loaded texture size in the active regional definitions - this will allow taking full advantage of smaller texture sizes in some areas. The disadvantage is some texture duplication with more slots. - Possible optimisation: offer the option to shrink textures by 50% or 25% - for texture slots that use large textures like base or mix slots. - Very temporary - reduce procedural normal map features with photoscenery active without breaking profiling, as the inputs to shaders are effect defaults or placeholder (by request on ML). ---- ws30-ALS-ultra.vert: - Start of conversion of geocentic world space xyz into lat/lon coords used for ground texture lookups. Currently commented out as it's unknown what model space coords are in (not geocentric it seems). ws20-ALS-landclass-search-functions.frag: - Add control for changing the ground texture array lookup function for debugging in case old compilers/GPUs have issues. tex_lookup_type: 0: normal( textureGrad(), 1: textureLod (manual Lod calculation), 2: texture() with no partial derivative adjustment. - New get6_random_integers() will extract 6 limited random values from the full precision of a 32 bit random value. - Old landclass_texel_size_m references are removed since textureSize() is used. There are no 'const in float' arguments that may cause issues on AMD compilers. ---- WS30-overlay effect (Inactive): - ws30-overlay.eff (derived from terrain-overlay.eff). Technique no "4" is used for two passes. The 1st pass is a copy of the ALS ultra pass (technique no "5") from ws30.eff. The 2nd pass is the same as terrain-overlay.eff. The 2nd pass uses terrain- overlay.frag from WS2. - grass-ALS.vert copied to ws30-ovelay-ALS.vert. To do: needs texture coords that don't change with tiles. - terrain-overlay-ALS.geom copied to ws30-overlay-ALS.geom. To do: uses gl_PositionIn [i].xy for position in the horizontal plane - assumes z is vertical. Tile model space doesn't seem to match this. - WS3 doesn't seem to have a way of switching references to terrain-overlay.eff (which inherits from terrain-default.eff) to the new ws3-overlay.eff (which needs to inherit from ws30.eff). The ws3-overlay.eff included /might/ just work without any other changes: the first pass is the WS3 als ultra settings pass, and the second overlay pass is unchanged from WS2 (the same terrain overlay shaders should probably work apart from texcoords and rawpos not being correct). - Materials/base/materials-base.xml: ws30Road material: uncomment line declaring terrain-default as the effect. The target effect for ws30 roads is road-*.eff and it's added to ws30Road and ws30Freeway but commented out as it's not working currently. - Misc: large scale transitions are turned on in ws30-ALS-landclass-search-functions.frag by default. Grow landclass borders with large scale transitions is now on by default. ---- Changes after the multi-texture support commit: ws30-ALS-ultra.vert - Added documentation: WS30 model space and z up space - for future people working on WS30, and people looking through shaders to rule out possibilities e.g. when fixing bugs, or interpreting visual bug reports. ws30-ALS-landclass-search-functions.frag: - For now, lookup_ground_texture_array() also looks up the relevant texture's index based on an integer. - Add get_mixed_texel() - looks up texel for this fragment and any neighbors before mixing. Moves currently shared mixing code out of 3 fragment shaders. Misc: changed indentation from mixed tabs/spaces to spaces in ws30-ALS-ultra frag and vert. The indentation can be changed again when the porting is complete. ws30-ALS vert/frag and ws30-ALS-detailed vert/frag: - Add varying for ground texture coordiante, currently set to gl_TexCoord[0]. Apply texture stretching dimensions in fragment shaders. - Misc: varying rawPos is set to vec2 for now, as relPos.z+eye_alt might be faster. Misc: keep WS2 mixing logic for now , including turning off mixing via the alpha channel of the textures ---- Changes after sending material parameters in uniform arrays commit: - Materials parameter for rock_strata is cast into an int so rock_strata==1 should work. Misc: Left over uniform for rock strata cleaned up. - ws30-ALS-ultra.frag and ws30-ALS-detailed.frag: Add missing mat_shininess for photoscenery case .
2022-01-03 15:43:29 +00:00
if (use_IR_vision)
{
light_ambient.rgb = max(light_ambient.rgb, vec3 (0.5, 0.5, 0.5));
}
WS30 shaders: Add WS3 detailed technique using the "6" slot. Port the ALS haze, lighting, and math parts of the detailed and ultra shaders. The texture lookups are left out. Shader selection based on terrain quality setting: - Ultra - ws30-ALS-ultra frag/vert. - High and Medium - ws30-ALS-detailed frag/vert. The shaders switch code paths based on quality level uniform. - Low - ws30-ALS frag/vert. Changelog: ws30-ALS vertex shaders: - Ambient colour material colour doesn't seem to be used in the vertex shader, and isn't sent to fragment shaders currently. Regional materials only define non-default ambient colour of vec4(0.0) for water, ocean etc. Otherwise the default value of vec4(0.2, 0.2, 0.2, 1.0) is used. ws30-ALS.frag: - Set alpha of color to diffuse_term.a, to be consistent with WS2 implementation. ws30-ALS-ultra.frag and ws30-ALS-detailed.frag - World pos is assigned a value to allow noise functions to compile. - Swatch_size is temporarily set to 2000m instead of the xsize texture dimension to allow noise math to run while landclass search and texture arrays are being looked up. Swatch_size is used to adjust the wavelength of multiple overlay mixing noise wavelengths based on how far the textures are stretched (WiP WS2 feature). There are some noise calculations that could run while the first landclass lookup happens. If this is not enough, the selection of calculated noise wavelengths to add could change based on how far the textures are stretched, instead of changing the wavelengths at calculation time. - Move photoscenery technique no "4" after technique no "7" without changing the index (in case the low index is needed for photoscenery). This makes viewing a diff with the WS2 effect easier. Performance: Currently there's only 1 ground texture lookup and landclass transitions for that texture. The ultra shader looks up 5 more textures. Probably transitions for 1 more texture need to be supported, as often a base and overlay texture are mixed contributing heavily to visible colour. The math overhead is mostly present, except for noise math being better hidden than in the eventual version. Some of the texture array lookups in the full version may be hidden by the math - depending on GPU memory handling compared to calculation speed.
2021-11-09 14:25:09 +00:00
WS30: landclass and texture lookups in fragment shader commit e131ffaca7b2c934474f0e447b5852cb4c7c8d4a Author: vs <vs2009@mail.com> Date: Fri Oct 15 22:19:42 2021 +1000 WS30: landclass and texture lookups in fragment shader: Changelog: - Testing: Procedural random landclass function, get_random_landclass(). 1). Avoids a texture lookup for profiling. 2). Creates squares of configurable size with controllable random landclass ranges - to test landclass transition algorithms and quickly profile lots of landclasses in view. It's also possible to put pressure on GPU memory even with 1 lookup of ground textures per fragment, by reducing size to <20m and viewing from altitude. - Add ALS ultra technique as no 5, move existing ALS technique to no. 6. Add WS30-ALS-ultra frag & vert in preparation for eventual ALS ultra port. Change comments/variables to match using a texture array instead of atlas. Sampler name: atlas -> textureArray. - Testing/optimisation of de-tiling: WS30-ALS.frag: reorder perlin detiling to make noise source easier to switch. WS30-ALS-ultra.frag: Create alternative to perlin noise used for reducing tiling that avoids a texture lookup - to profile and optimise. This is commented out. The performance difference in the final version depends on memory pressure versus arithmetic load of the full shader. It varies by GPU and what's in view. In future, once a full ALS port is done, maybe it'll be more efficient to run a higher quality de-tiling algorithm all the time to avoid branching overhead due to effects like agriculture which need more de-tiling. De-tiling code in shaders should /eventually/ match CPU-side de-tiling of texture masks used for object and vegetation placement. De-tiling code in GPUs might be subject to precision and numerical artifacts, and if so maybe the texture lookup version would work better. The same applies to noise used for rendering WS3 water waves and collision queries. One option is to use exactly the same glsl code, with a C++ header to convert glsl syntax e.g. https://github.com/g-truc/glm .
2021-10-21 20:31:03 +00:00
WS30: MR #267: Improved texture lookups from VS Squashed commit of the following: commit 115511888c20c53670eba17a82c81c9af99d7302 Author: vs <vs2009@mail.com> Date: Mon Dec 6 18:52:06 2021 +1000 WS30 effects and shaders: Changelog: ws30-ALS-ultra.frag: - Ground textures lookups use their own coordinates separate from the landclass texture lookup. - Partial derivatives dFdx and Dfdy are packed together in a vec4, so simple multiplication to scale can be done in 1 instruction. dFdx = s and t components. dFdy = p and q components. These must be scaled properly for ground texture access as ground texture stretching and detiling of tex coords mean textures are scaled differently. - Added calculation of partial derivatives for texture coordinates used by the 5 non- base textures. dFdx() and dFdy() were called for nontrivial texture coordinate manipulation. - New control randomise_texture_lookups added at top of ws30-ALS-ultra.frag, in the development tools section. Setting this to 1 will do a stress test of ground texture array lookups. A fast random number generation function is used to assign each landclass 4 random textures from the ground texture array - this is done by . Performance will not be as bad in the full ALS port as some texture slots will better caching in memory - e.g. have 1 or a few variants. - Possible optimisation: use a 2nd or 3rd texture array for some of the non-base texture slots that typically have 256, 512, or 1024 textures. The resolutions of these arrays should change based on the largest loaded texture size in the active regional definitions - this will allow taking full advantage of smaller texture sizes in some areas. The disadvantage is some texture duplication with more slots. - Possible optimisation: offer the option to shrink textures by 50% or 25% - for texture slots that use large textures like base or mix slots. - Very temporary - reduce procedural normal map features with photoscenery active without breaking profiling, as the inputs to shaders are effect defaults or placeholder (by request on ML). ---- ws30-ALS-ultra.vert: - Start of conversion of geocentic world space xyz into lat/lon coords used for ground texture lookups. Currently commented out as it's unknown what model space coords are in (not geocentric it seems). ws20-ALS-landclass-search-functions.frag: - Add control for changing the ground texture array lookup function for debugging in case old compilers/GPUs have issues. tex_lookup_type: 0: normal( textureGrad(), 1: textureLod (manual Lod calculation), 2: texture() with no partial derivative adjustment. - New get6_random_integers() will extract 6 limited random values from the full precision of a 32 bit random value. - Old landclass_texel_size_m references are removed since textureSize() is used. There are no 'const in float' arguments that may cause issues on AMD compilers. ---- WS30-overlay effect (Inactive): - ws30-overlay.eff (derived from terrain-overlay.eff). Technique no "4" is used for two passes. The 1st pass is a copy of the ALS ultra pass (technique no "5") from ws30.eff. The 2nd pass is the same as terrain-overlay.eff. The 2nd pass uses terrain- overlay.frag from WS2. - grass-ALS.vert copied to ws30-ovelay-ALS.vert. To do: needs texture coords that don't change with tiles. - terrain-overlay-ALS.geom copied to ws30-overlay-ALS.geom. To do: uses gl_PositionIn [i].xy for position in the horizontal plane - assumes z is vertical. Tile model space doesn't seem to match this. - WS3 doesn't seem to have a way of switching references to terrain-overlay.eff (which inherits from terrain-default.eff) to the new ws3-overlay.eff (which needs to inherit from ws30.eff). The ws3-overlay.eff included /might/ just work without any other changes: the first pass is the WS3 als ultra settings pass, and the second overlay pass is unchanged from WS2 (the same terrain overlay shaders should probably work apart from texcoords and rawpos not being correct). - Materials/base/materials-base.xml: ws30Road material: uncomment line declaring terrain-default as the effect. The target effect for ws30 roads is road-*.eff and it's added to ws30Road and ws30Freeway but commented out as it's not working currently. - Misc: large scale transitions are turned on in ws30-ALS-landclass-search-functions.frag by default. Grow landclass borders with large scale transitions is now on by default. ---- Changes after the multi-texture support commit: ws30-ALS-ultra.vert - Added documentation: WS30 model space and z up space - for future people working on WS30, and people looking through shaders to rule out possibilities e.g. when fixing bugs, or interpreting visual bug reports. ws30-ALS-landclass-search-functions.frag: - For now, lookup_ground_texture_array() also looks up the relevant texture's index based on an integer. - Add get_mixed_texel() - looks up texel for this fragment and any neighbors before mixing. Moves currently shared mixing code out of 3 fragment shaders. Misc: changed indentation from mixed tabs/spaces to spaces in ws30-ALS-ultra frag and vert. The indentation can be changed again when the porting is complete. ws30-ALS vert/frag and ws30-ALS-detailed vert/frag: - Add varying for ground texture coordiante, currently set to gl_TexCoord[0]. Apply texture stretching dimensions in fragment shaders. - Misc: varying rawPos is set to vec2 for now, as relPos.z+eye_alt might be faster. Misc: keep WS2 mixing logic for now , including turning off mixing via the alpha channel of the textures ---- Changes after sending material parameters in uniform arrays commit: - Materials parameter for rock_strata is cast into an int so rock_strata==1 should work. Misc: Left over uniform for rock strata cleaned up. - ws30-ALS-ultra.frag and ws30-ALS-detailed.frag: Add missing mat_shininess for photoscenery case .
2022-01-03 15:43:29 +00:00
// default lighting based on texture and material using the light we have just computed
light_diffuse_comp = light_diffuse;
//Testing phase code: ambient colours are not sent to fragement shader yet.
// They are all default except for water/ocean etc. currently
// Emission is all set to the default of vec4(0.0, 0.0, 0.0, 1.0)
//To do: Fix this once ambient colour becomes available in the fragment shaders.
//const vec4 ambient_color = vec4(0.2, 0.2, 0.2, 1.0);
const vec4 ambient_color = vec4(1.0);
vec4 constant_term = ambient_color * (gl_LightModel.ambient + light_ambient);
light_diffuse_comp.a = yprime_alt;
gl_FrontColor.rgb = constant_term.rgb; // gl_FrontColor.a = 1.0;
gl_BackColor.rgb = constant_term.rgb; // gl_BackColor.a = 0.0;
gl_FrontColor.a = mie_angle;
gl_BackColor.a = mie_angle;
setupShadows(ecPosition);
WS30: landclass and texture lookups in fragment shader commit e131ffaca7b2c934474f0e447b5852cb4c7c8d4a Author: vs <vs2009@mail.com> Date: Fri Oct 15 22:19:42 2021 +1000 WS30: landclass and texture lookups in fragment shader: Changelog: - Testing: Procedural random landclass function, get_random_landclass(). 1). Avoids a texture lookup for profiling. 2). Creates squares of configurable size with controllable random landclass ranges - to test landclass transition algorithms and quickly profile lots of landclasses in view. It's also possible to put pressure on GPU memory even with 1 lookup of ground textures per fragment, by reducing size to <20m and viewing from altitude. - Add ALS ultra technique as no 5, move existing ALS technique to no. 6. Add WS30-ALS-ultra frag & vert in preparation for eventual ALS ultra port. Change comments/variables to match using a texture array instead of atlas. Sampler name: atlas -> textureArray. - Testing/optimisation of de-tiling: WS30-ALS.frag: reorder perlin detiling to make noise source easier to switch. WS30-ALS-ultra.frag: Create alternative to perlin noise used for reducing tiling that avoids a texture lookup - to profile and optimise. This is commented out. The performance difference in the final version depends on memory pressure versus arithmetic load of the full shader. It varies by GPU and what's in view. In future, once a full ALS port is done, maybe it'll be more efficient to run a higher quality de-tiling algorithm all the time to avoid branching overhead due to effects like agriculture which need more de-tiling. De-tiling code in shaders should /eventually/ match CPU-side de-tiling of texture masks used for object and vegetation placement. De-tiling code in GPUs might be subject to precision and numerical artifacts, and if so maybe the texture lookup version would work better. The same applies to noise used for rendering WS3 water waves and collision queries. One option is to use exactly the same glsl code, with a C++ header to convert glsl syntax e.g. https://github.com/g-truc/glm .
2021-10-21 20:31:03 +00:00
}