Cleanup some shader #defines
- create a new FILAMENT_HAS_FEATURE_TEXTURE_GATHER, which can be used in the shaders to use textureGather. - A new TARGET_GLES_ENVIRONMENT and TARGET_GL_ENVIRONMENT in addition to TARGET_METAL_ and TARGET_VULKAN_, for completeness. - Rename TARGET_LANGUAGE_SPIRV to FILAMENT_VULKAN_SEMANTICS and add FILAMENT_OPENGL_SEMANTICS for completeness. - expose the shader model to shaders as: FILAMENT_SHADER_MODEL_ES30 and FILAMENT_SHADER_MODEL_GL41 Use these new #define where appropriate. The main change here is that TARGET_MOBILE is now only used for dealing with the `mediump` default on mobile. This change also enables textureGather on Metal.
This commit is contained in:
committed by
Mathias Agopian
parent
6f948c101f
commit
2d9064d2bf
@@ -2,7 +2,7 @@
|
||||
#define gpu_shader5 1
|
||||
|
||||
// ES 3.0 does not have gather though
|
||||
#if defined(TARGET_VULKAN_ENVIRONMENT) || !defined(TARGET_MOBILE)
|
||||
#if defined(FILAMENT_HAS_FEATURE_TEXTURE_GATHER)
|
||||
#define FXAA_GATHER4_ALPHA 1
|
||||
#else
|
||||
#define FXAA_GATHER4_ALPHA 0
|
||||
|
||||
@@ -78,7 +78,7 @@ void postProcess(inout PostProcessInputs postProcess) {
|
||||
hdr[3] = 1.0 / (1.0 + max3(s00.rgb));
|
||||
|
||||
vec4 d;
|
||||
#if defined(TARGET_VULKAN_ENVIRONMENT) || !defined(TARGET_MOBILE)
|
||||
#if defined(FILAMENT_HAS_FEATURE_TEXTURE_GATHER)
|
||||
d = textureGather(materialParams_depth, uv, 0); // 01, 11, 10, 00
|
||||
#else
|
||||
d[0] = textureLodOffset(materialParams_depth, uv, 0.0, ivec2(0, 1)).r;
|
||||
|
||||
@@ -48,7 +48,7 @@ void postProcess(inout PostProcessInputs postProcess) {
|
||||
|
||||
// note: the first time, the source texture is swizzled -- so .r and .g are the same channel
|
||||
// if swizzling is not supported, we use dofTilesSwizzle instead.
|
||||
#if defined(TARGET_VULKAN_ENVIRONMENT) || !defined(TARGET_MOBILE)
|
||||
#if defined(FILAMENT_HAS_FEATURE_TEXTURE_GATHER)
|
||||
vec4 mi = textureGather(materialParams_cocMinMax, uv, 0); // 01, 11, 10, 00
|
||||
vec4 ma = textureGather(materialParams_cocMinMax, uv, 1); // 01, 11, 10, 00
|
||||
#else
|
||||
|
||||
@@ -46,7 +46,7 @@ void postProcess(inout PostProcessInputs postProcess) {
|
||||
|
||||
ivec2 i = ivec2(uv * size - 0.5);
|
||||
|
||||
#if defined(TARGET_VULKAN_ENVIRONMENT) || !defined(TARGET_MOBILE)
|
||||
#if defined(FILAMENT_HAS_FEATURE_TEXTURE_GATHER)
|
||||
vec4 mi = textureGather(materialParams_cocMinMax, uv, 0); // 01, 11, 10, 00
|
||||
#else
|
||||
vec4 mi;
|
||||
|
||||
@@ -68,8 +68,8 @@ public:
|
||||
};
|
||||
|
||||
enum class TargetLanguage {
|
||||
GLSL,
|
||||
SPIRV
|
||||
GLSL, // GLSL with OpenGL semantics
|
||||
SPIRV // GLSL with Vulkan semantics
|
||||
};
|
||||
|
||||
enum class Optimization {
|
||||
|
||||
@@ -18,9 +18,13 @@
|
||||
|
||||
#include "generated/shaders.h"
|
||||
|
||||
#include <utils/sstream.h>
|
||||
|
||||
#include <cctype>
|
||||
#include <iomanip>
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
namespace filamat {
|
||||
|
||||
// From driverEnum namespace
|
||||
@@ -74,8 +78,26 @@ io::sstream& CodeGenerator::generateProlog(io::sstream& out, ShaderType type,
|
||||
if (mTargetApi == TargetApi::METAL) {
|
||||
out << "#define TARGET_METAL_ENVIRONMENT\n";
|
||||
}
|
||||
if (mTargetApi == TargetApi::OPENGL && mShaderModel == ShaderModel::GL_ES_30) {
|
||||
out << "#define TARGET_GLES_ENVIRONMENT\n";
|
||||
}
|
||||
if (mTargetApi == TargetApi::OPENGL && mShaderModel == ShaderModel::GL_CORE_41) {
|
||||
out << "#define TARGET_GL_ENVIRONMENT\n";
|
||||
}
|
||||
|
||||
out << '\n';
|
||||
if (mTargetLanguage == TargetLanguage::SPIRV) {
|
||||
out << "#define TARGET_LANGUAGE_SPIRV\n";
|
||||
out << "#define FILAMENT_VULKAN_SEMANTICS\n";
|
||||
}
|
||||
if (mTargetLanguage == TargetLanguage::GLSL) {
|
||||
out << "#define FILAMENT_OPENGL_SEMANTICS\n";
|
||||
}
|
||||
|
||||
out << '\n';
|
||||
if (mTargetApi == TargetApi::VULKAN ||
|
||||
mTargetApi == TargetApi::METAL ||
|
||||
mTargetApi == TargetApi::OPENGL && mShaderModel == ShaderModel::GL_CORE_41) {
|
||||
out << "#define FILAMENT_HAS_FEATURE_TEXTURE_GATHER\n";
|
||||
}
|
||||
|
||||
out << '\n';
|
||||
|
||||
@@ -27,7 +27,11 @@ float evaluateSSAO() {
|
||||
highp vec2 size = vec2(textureSize(light_ssao, 0));
|
||||
|
||||
// Read four AO samples and their depths values
|
||||
#if defined(TARGET_MOBILE)
|
||||
#if defined(FILAMENT_HAS_FEATURE_TEXTURE_GATHER)
|
||||
vec4 ao = textureGather(light_ssao, uv, 0); // 01, 11, 10, 00
|
||||
vec4 dg = textureGather(light_ssao, uv, 1); // 01, 11, 10, 00
|
||||
vec4 db = textureGather(light_ssao, uv, 2); // 01, 11, 10, 00
|
||||
#else
|
||||
// on mobile we can't use textureGather() because we're limited to ES3.0,
|
||||
// so we emulate it with texelFetch(), on Pixel 4 this doesn't seem to have any
|
||||
// significant impact on performance.
|
||||
@@ -38,10 +42,6 @@ float evaluateSSAO() {
|
||||
vec4 ao = vec4(s01.r, s11.r, s10.r, s00.r);
|
||||
vec4 dg = vec4(s01.g, s11.g, s10.g, s00.g);
|
||||
vec4 db = vec4(s01.b, s11.b, s10.b, s00.b);
|
||||
#else
|
||||
vec4 ao = textureGather(light_ssao, uv, 0); // 01, 11, 10, 00
|
||||
vec4 dg = textureGather(light_ssao, uv, 1); // 01, 11, 10, 00
|
||||
vec4 db = textureGather(light_ssao, uv, 2); // 01, 11, 10, 00
|
||||
#endif
|
||||
// bilinear weights
|
||||
vec2 f = fract(uv * size - 0.5);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#if !defined(TARGET_MOBILE) || defined(TARGET_LANGUAGE_SPIRV)
|
||||
#if defined(FILAMENT_VULKAN_SEMANTICS)
|
||||
#define LAYOUT_LOCATION(x) layout(location = x)
|
||||
#else
|
||||
#define LAYOUT_LOCATION(x)
|
||||
|
||||
Reference in New Issue
Block a user