Skip to content

Commit

Permalink
Refactor: Rename shader snippets w/ new naming convention (see README…
Browse files Browse the repository at this point in the history
….md) (#8402)

This commit renames all shader snippet files to conform to the newly
introduced naming convention outlined in README.md.

The new naming convention uses a `prefix_name.suffix` format to clearly
indicate the purpose and target shader stage of each snippet. This
improves the overall organization and readability of the shader code,
making it easier to understand how each snippet contributes to the
shader generation process.

No functional changes were made to the shader code itself or source
code. This is purely a refactoring for clarity and maintainability.
  • Loading branch information
z3moon authored Jan 31, 2025
1 parent f1c1aa1 commit 87bdf96
Show file tree
Hide file tree
Showing 54 changed files with 262 additions and 234 deletions.
8 changes: 4 additions & 4 deletions filament/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -385,16 +385,16 @@ endforeach()

add_custom_command(
OUTPUT "${MATERIAL_DIR}/colorGrading.filamat"
DEPENDS ../shaders/src/dithering.fs
DEPENDS ../shaders/src/vignette.fs
DEPENDS ../shaders/src/inline_dithering.fs
DEPENDS ../shaders/src/inline_vignette.fs
DEPENDS src/materials/colorGrading/colorGrading.fs
APPEND
)

add_custom_command(
OUTPUT "${MATERIAL_DIR}/colorGradingAsSubpass.filamat"
DEPENDS ../shaders/src/dithering.fs
DEPENDS ../shaders/src/vignette.fs
DEPENDS ../shaders/src/inline_dithering.fs
DEPENDS ../shaders/src/inline_vignette.fs
DEPENDS src/materials/colorGrading/colorGrading.fs
APPEND
)
Expand Down
2 changes: 1 addition & 1 deletion filament/backend/include/backend/DriverEnums.h
Original file line number Diff line number Diff line change
Expand Up @@ -1302,7 +1302,7 @@ enum class Workaround : uint16_t {
// for some uniform arrays, it's needed to do an initialization to avoid crash on adreno gpu
ADRENO_UNIFORM_ARRAY_CRASH,
// Workaround a Metal pipeline compilation error with the message:
// "Could not statically determine the target of a texture". See light_indirect.fs
// "Could not statically determine the target of a texture". See surface_light_indirect.fs
METAL_STATIC_TEXTURE_TARGET_ERROR,
// Adreno drivers sometimes aren't able to blit into a layer of a texture array.
DISABLE_BLIT_INTO_TEXTURE_ARRAY,
Expand Down
4 changes: 2 additions & 2 deletions filament/backend/src/metal/MetalDriver.mm
Original file line number Diff line number Diff line change
Expand Up @@ -1134,8 +1134,8 @@

math::float2 MetalDriver::getClipSpaceParams() {
// virtual and physical z-coordinate of clip-space is in [-w, 0]
// Note: this is actually never used (see: main.vs), but it's a backend API so we implement it
// properly.
// Note: this is actually never used (see: surface_main.vs), but it's a backend API so we
// implement it properly.
return math::float2{ 1.0f, 0.0f };
}

Expand Down
4 changes: 2 additions & 2 deletions filament/backend/src/vulkan/VulkanDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1091,8 +1091,8 @@ FeatureLevel VulkanDriver::getFeatureLevel() {

math::float2 VulkanDriver::getClipSpaceParams() {
// virtual and physical z-coordinate of clip-space is in [-w, 0]
// Note: this is actually never used (see: main.vs), but it's a backend API, so we implement it
// properly.
// Note: this is actually never used (see: surface_main.vs), but it's a backend API, so we
// implement it properly.
return math::float2{ 1.0f, 0.0f };
}

Expand Down
2 changes: 1 addition & 1 deletion filament/src/PostProcessManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2661,7 +2661,7 @@ void PostProcessManager::TaaJitterCamera(
// update projection matrix
inoutCameraInfo->projection[2].xy -= jitterInClipSpace;
// VERTEX_DOMAIN_DEVICE doesn't apply the projection, but it still needs this
// clip transform, so we apply it separately (see main.vs)
// clip transform, so we apply it separately (see surface_main.vs)
inoutCameraInfo->clipTransform.zw -= jitterInClipSpace;
}

Expand Down
6 changes: 3 additions & 3 deletions filament/src/ShadowMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ ShadowMap::ShaderParameters ShadowMap::updateDirectional(FEngine& engine,

// The model matrix below is in fact inverted to get the view matrix and passed to the
// shader as 'viewFromWorldMatrix', and is used in the VSM case to compute the depth metric.
// (see depth_main.fs). Note that in the case of VSM, 'b' below is identity.
// (see surface_depth_main.fs). Note that in the case of VSM, 'b' below is identity.
mCamera->setModelMatrix(FCamera::rigidTransformInverse(highPrecisionMultiplyd(Mv, b)));
mCamera->setCustomProjection(mat4(Mn * F * WLMp), znear, zfar);

Expand Down Expand Up @@ -315,7 +315,7 @@ ShadowMap::ShaderParameters ShadowMap::updatePunctual(

// The model matrix below is in fact inverted to get the view matrix and passed to the
// shader as 'viewFromWorldMatrix', and is used in the VSM case to compute the depth metric.
// (see depth_main.fs). Note that in the case of VSM, 'b' below is identity.
// (see surface_depth_main.fs). Note that in the case of VSM, 'b' below is identity.
mCamera->setModelMatrix(FCamera::rigidTransformInverse(highPrecisionMultiplyd(Mv, b)));
mCamera->setCustomProjection(highPrecisionMultiplyd(Mn, Mp), nearPlane, farPlane);

Expand Down Expand Up @@ -719,7 +719,7 @@ mat4f ShadowMap::computeVsmLightSpaceMatrix(const mat4f& lightSpacePcf,
// For VSM, we want to leave the z coordinate in linear light-space, normalized between [0, 1],
// i.e. remapping [near, far] to [0, 1].
// When sampling a VSM shadow map, the shader follows suit, and doesn't divide by w for the z
// coordinate. See shadowing.fs.
// coordinate. See surface_shadowing.fs.
// compute z' = -(Mv * position).z / (far - near) - (near / (far - near))
const float scale = 1.0f / (zfar - znear);
mat4f lightSpaceVsm{ lightSpacePcf };
Expand Down
2 changes: 1 addition & 1 deletion filament/src/details/MorphTargetBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ MorphTargetBuffer* MorphTargetBuffer::Builder::build(Engine& engine) {
// ------------------------------------------------------------------------------------------------

// This value is limited by ES3.0, ES3.0 only guarantees 2048.
// When you change this value, you must change MAX_MORPH_TARGET_BUFFER_WIDTH at getters.vs
// When you change this value, you must change MAX_MORPH_TARGET_BUFFER_WIDTH at surface_getters.vs
constexpr size_t MAX_MORPH_TARGET_BUFFER_WIDTH = 2048;

static inline size_t getWidth(size_t const vertexCount) noexcept {
Expand Down
2 changes: 1 addition & 1 deletion filament/src/details/Renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -781,7 +781,7 @@ void FRenderer::renderJob(RootArenaScope& rootArenaScope, FView& view) {
cameraInfo.projection = highPrecisionMultiply(ts, cameraInfo.projection);

// VERTEX_DOMAIN_DEVICE doesn't apply the projection, but it still needs this
// clip transform, so we apply it separately (see main.vs)
// clip transform, so we apply it separately (see surface_main.vs)
cameraInfo.clipTransform = { ts[0][0], ts[1][1], ts[3].x, ts[3].y };

// adjust svp to the new, larger, rendering dimensions
Expand Down
2 changes: 1 addition & 1 deletion filament/src/details/SkinningBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ void FSkinningBuffer::setBones(FEngine& engine, Handle<HwBufferObject> handle,
}

// This value is limited by ES3.0, ES3.0 only guarantees 2048.
// When you change this value, you must change MAX_SKINNING_BUFFER_WIDTH at getters.vs
// When you change this value, you must change MAX_SKINNING_BUFFER_WIDTH at surface_getters.vs
constexpr size_t MAX_SKINNING_BUFFER_WIDTH = 2048;

static inline size_t getSkinningBufferWidth(size_t const pairCount) noexcept {
Expand Down
4 changes: 2 additions & 2 deletions filament/src/materials/colorGrading/colorGrading.mat
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ vertex {

fragment {

#include "../../../../shaders/src/dithering.fs"
#include "../../../../shaders/src/vignette.fs"
#include "../../../../shaders/src/inline_dithering.fs"
#include "../../../../shaders/src/inline_vignette.fs"
#include "colorGrading.fs"

void dummy(){}
Expand Down
4 changes: 2 additions & 2 deletions filament/src/materials/colorGrading/colorGradingAsSubpass.mat
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ vertex {

fragment {

#include "../../../../shaders/src/dithering.fs"
#include "../../../../shaders/src/vignette.fs"
#include "../../../../shaders/src/inline_dithering.fs"
#include "../../../../shaders/src/inline_vignette.fs"
#include "colorGrading.fs"

void dummy(){}
Expand Down
2 changes: 1 addition & 1 deletion libs/filamat/include/filamat/MaterialBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -727,7 +727,7 @@ class UTILS_PUBLIC MaterialBuilder : public MaterialBuilderBase {
static constexpr size_t MAX_DEPTH_OUTPUT = 1;
static_assert(MAX_COLOR_OUTPUT == 8,
"When updating MRT::MAX_SUPPORTED_RENDER_TARGET_COUNT, manually update post_process_inputs.fs"
" and post_process.fs");
" and post_process_main.fs");

// Preview the first shader generated by the given CodeGenParams.
// This is used to run Static Code Analysis before generating a package.
Expand Down
12 changes: 6 additions & 6 deletions libs/filamat/src/MaterialBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -937,15 +937,15 @@ bool MaterialBuilder::generateShaders(JobSystem& jobSystem, const std::vector<Va
// explicitly remove them when using filamat lite.
std::string shader;
if (v.stage == backend::ShaderStage::VERTEX) {
shader = sg.createVertexProgram(
shader = sg.createSurfaceVertexProgram(
shaderModel, targetApi, targetLanguage, featureLevel,
info, v.variant, mInterpolation, mVertexDomain);
} else if (v.stage == backend::ShaderStage::FRAGMENT) {
shader = sg.createFragmentProgram(
shader = sg.createSurfaceFragmentProgram(
shaderModel, targetApi, targetLanguage, featureLevel,
info, v.variant, mInterpolation, mVariantFilter);
} else if (v.stage == backend::ShaderStage::COMPUTE) {
shader = sg.createComputeProgram(
shader = sg.createSurfaceComputeProgram(
shaderModel, targetApi, targetLanguage, featureLevel,
info);
}
Expand Down Expand Up @@ -1438,15 +1438,15 @@ std::string MaterialBuilder::peek(backend::ShaderStage stage,

switch (stage) {
case backend::ShaderStage::VERTEX:
return sg.createVertexProgram(
return sg.createSurfaceVertexProgram(
params.shaderModel, params.targetApi, params.targetLanguage,
params.featureLevel, info, {}, mInterpolation, mVertexDomain);
case backend::ShaderStage::FRAGMENT:
return sg.createFragmentProgram(
return sg.createSurfaceFragmentProgram(
params.shaderModel, params.targetApi, params.targetLanguage,
params.featureLevel, info, {}, mInterpolation, mVariantFilter);
case backend::ShaderStage::COMPUTE:
return sg.createComputeProgram(
return sg.createSurfaceComputeProgram(
params.shaderModel, params.targetApi, params.targetLanguage,
params.featureLevel, info);
}
Expand Down
Loading

0 comments on commit 87bdf96

Please sign in to comment.