ok. without going to writing that math up more so xD
I think it goes like, as it relies on the fact waterlevel - pos.z diminishing to zero when going at surface as waterlevel is itself hardcoded to -1 in exterior........... or so
volume = player distance from water surface in z, multiplied with proportional amount of underwater terrain points on grid with number of tiles on side from NearWaterPoints value. one tile's size is near constant determined by NearWaterRadius.
haven't datamined the reverse engineering or tried mods / vanilla , but the sound is hard to get played even in open sea. have to look further but from the soundmanager part it might be that it get's run over by update or sound index checking afetr if(mNearWaterSound) part the volume variable being trigger for looping.
there's the underwater fog calculation
https://github.com/OpenMW/openmw/blob/m ... r.cpp#L469
Code: Select all
setFogColor(mUnderwaterColor * mUnderwaterWeight + mFogColor * (1.f-mUnderwaterWeight));
mStateUpdater->setFogStart(mViewDistance * (1 - mUnderwaterFog));
mStateUpdater->setFogEnd(mViewDistance);
-
Spoiler: Show
- map_alpha is mostly visual and affects how much it shows in map. 1 making it dark blue in world and light blue in local supposedly rendering your water texture
- world_alpha is the actual world rendering. 0 makes it basically invisible and 1 is "solid". ripples and other water effects applies. having shaders turned on overrides these.
- SurfaceFPS determines the flickering "waving" rate ie. the speed on which the water textures are shown over
- Surfacetexture is the texturename used to look in textures/water
- Surfaceframecount affects the waving somewhat differently than fps. specifically the number of textures used like from water00 to water31 the last number determined by (SurfaceFrameCount-1). using 33 or over causes pink texture not found colorization in vanilla case
- Rippletexture as basename used for "particle" ripples when moving across engine defined water surface
RippleFrameCount number of searched ripple textures starting from 00 suffix
- RippleLifetime is the lifetime of single ripple, larger values causing slower expansion rate -> longer tail. doesn't seem to effect generation rate while moving.
- RippleRotSpeed causes the ripple particles rotate more seeming as flashing ingame. value 100 causes a bit more pronounced flickering
- NearWaterRadius and NearWaterPoints defines a grid with tile width of nearly constant NearWaterRadius and number of NearWaterPoints, which is used to "see" how much of the surrounding terrain is underwater from the player affecting sound volume.
- NearWaterIndoorTolerance
NearWaterOutdoorTolerance the minimum distance the player must be to the water surface for the water sound to play taken in z axis.
- NearWaterIndoorID
NearWaterOutdoorID presumably the sound looped when near shore in exterior or interior behaving like exterior, but hard to hear
- Underwater[Time of day]Fog are used for calculating underwater fog start in given time, tretching it to viewdistance. mViewDistance * (1 - mUnderwaterFog) at the time of writing and negative numbers seems to go to backside of the player.
- UnderwaterColor determines the base color used underwater. for example 200, 150, 100 makes it orange and 100,150,200 light blue.
- UnderwaterColorWeight from 0 to 1 determines how much UnderwaterColor is used for underwaterfog instead of weather dependant one. values over 1 causes the weather dependant going negative in calculations ie. clitching most probably. with light blue little pronounced at testing with this one at 1, lighter in 0.2, turns water cyan at 100
-----------------------------------------------------------------------------------
Then for the shaders: using water as example:
the pipeline seems to be defined via uniform which are by the definition the info what is given from application to the GLSL shaders. the gl_lightposition , gl_position , gl_ .... are essentially uniforms defined in opengl itself as preset functions.
basically vertex shader names punch of variables with style : varying type name, modified / defined after
- varying vec3 screenCoordsPassthrough;
varying vec4 position;
varying float depthPassthrough;
which can be used in this case, in fragment shader, vertex handling the vertex information on the scene and fragment shader then uses that to modify what's shown on the screen..
- gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
gl_position should define the position from individual vertices, but more generally it's the variable that is passed forward to fragment shader. for googling that, there's multiple versions of GLSL in exixtence, used defined in shader with #version at the start. openmw's are in 120 = 1.2
- vec, mat are vectors and matrices with number given dimensions. the shaders being vector and matrix mathematics in short or vector matrix arithmetics
like with changing the
depthPassthrough = gl_Position.z; line to
depthPassthrough = gl_Position.z * gl_Position.x * gl_Position.y;
i have kinda no idea how the resulting matrix is deformed by that action but this was the result
comparing to the originals
so don't know how that excessive clipping can be avoided
Then in the fragment shader Uniform Sampler2D or 3D can be used to take texture coordinates from the engine.
otherwise haven't looked into that part yet.
DISCLAIMER: This is probably much saver in fragment shader. good to have package for reinstall to different folder as this can corrupt the shader pathway somehow.
ie. with geometry shader function water turned all black in surface and got normal map showing dependent on view angle.
-----------------------------------------------------------------------------------
there's written uniform definitions in the code:
osg::Uniform("envMapColor", osg::Vec4f(1,1,1,1))
osg::Uniform("diffuseMap", texunit)
osg::Uniform("normalMap", 0)
osg::Uniform("reflectionMap", 1)
osg::Uniform("near", mNearClip)
osg::Uniform("far", mViewDistance)
osg::Uniform("envMapColor", mColor)
source code places:
-
Spoiler: Show
- https://github.com/OpenMW/openmw/blob/m ... r.cpp#L546
https://github.com/OpenMW/openmw/blob/m ... l.cpp#L133
https://github.com/OpenMW/openmw/blob/m ... r.cpp#L522
https://github.com/OpenMW/openmw/blob/m ... r.cpp#L255
https://github.com/OpenMW/openmw/blob/m ... n.cpp#L289
this one wonders: seems to iterate over shader text with adduniform and define shadertemplates for the vertex and fragment shaders.
https://github.com/OpenMW/openmw/blob/m ... r.cpp#L299
-----------------------------------------------------------------------------------
Tutorials:
basics: