beyond-all-reason / spring

A powerful free cross-platform RTS game engine
https://beyond-all-reason.github.io/spring/
Other
205 stars 98 forks source link

Document shader interface (uniforms etc) #1381

Open sprunk opened 6 months ago

sprunk commented 6 months ago

Looks like each shader type can have its own set of uniforms and they can also depend on other settings. E.g. map shader seems to have a bunch of map textures bound and then more when adv map shading is enabled: https://github.com/beyond-all-reason/spring/blob/b0dde959f2504a6031748a995c294ba3084925f0/rts/Map/SMF/SMFRenderState.cpp#L136-L145

The task is to document all of this.

badosu commented 6 months ago

Expose a custom type or table, and reference it on places where a texture is used.

Good candidates for example are all places that parse texture names in unsyncedctrl (using ParseLuaTextureData), e.g.

/*** @function Spring.SetMapShadingTexture
 * @string texType
 * @string texName
 * @treturn bool success
 * @usage Spring.SetMapShadingTexture("$ssmf_specular", "name_of_my_shiny_texture")
 */

If a custom type is not possible with current LuaDoc, then just @see to a new module defining a bogus custom table on LuaOpenGLUtils

lhog commented 6 months ago

What's the purpose of documenting that? The map shader is not available outside of engine internals and if someone still wants to use custom map shading they need to deal with uniforms (and their names) themselves.

sprunk commented 6 months ago

map shader is not available outside of engine internals

Good, I didn't know that.

What about these? https://github.com/beyond-all-reason/Beyond-All-Reason/blob/934c5991fb511937c5341dac09d6ad478a1b99b9/luaui/Widgets/Include/LuaShader.lua#L56-L65

lhog commented 6 months ago

gl.GetEngineUniformBufferDef() takes care of that, but it's not documented yet.

lhog commented 6 months ago

https://github.com/beyond-all-reason/spring/commit/558c7c7627a35a6ba3f2b35f18dd1c91da38aecb

sprunk commented 6 months ago

558c7c7627a35a6ba3f2b35f18dd1c91da38aecb is alright but "the GLSL compliant definition of UniformParamsBuffer" still doesn't describe what the params buffer contains (which what a dev will want to know). You can call the function to learn the names but you still won't know the meanings or the values behind those names.

To be more clear what I want. Here's a small snippet from a hypothetical page I would want to exist. The real page would have them all:

name what is it value remarks
fogParams.x start of the fog relative to camera 0.0 - 1.0
fogParams.y end of the fog relative to camera 0.0 - 1.0
timeInfo.x sim frame
timeInfo.y real (wall clock) time always flows at real time (even when e.g. paused)
timeInfo.z game time stops when paused, slows at x0.5 gamespeed etc
mouseStatus bitfield, from least significant: LMB, RMB, MMB, isOffscreen, isScrollingViaMMB, confined
windInfo.xyz wind direction normalized 0.0 - 1.0
windInfo.w wind strength
badosu commented 6 months ago

Texname and/or textype does not reference $whatevertex?

lhog commented 6 months ago

Texture names reference the actual textures, yes. But it's not related to the shader uniform names mentioned in https://github.com/beyond-all-reason/spring/issues/1381#issue-2195109032

badosu commented 6 months ago

I see, we still want to document the texnames

badosu commented 6 months ago

There's some stuff here that could be improved. https://beyond-all-reason.github.io/spring/ldoc/modules/Shaders.html

sprunk commented 2 months ago

Some docs on getting a shader to work would be good too.