Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

shadertools: Remove getVersionDefines #2012

Merged
merged 2 commits into from
Mar 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import {glsl} from '../glsl-utils/highlight';
import {resolveModules} from './resolve-modules';
import {PlatformInfo} from './platform-info';
import {getPlatformShaderDefines, getVersionDefines} from './platform-defines';
import {getPlatformShaderDefines} from './platform-defines';
import {injectShader, DECLARATION_INJECT_MARKER} from './shader-injections';
import {transpileGLSLShader} from '../shader-transpiler/transpile-glsl-shader';
import {ShaderModuleInstance} from '../shader-module/shader-module-instance';
Expand Down Expand Up @@ -196,7 +196,6 @@ export function assembleWGSLShader(platformInfo: PlatformInfo, options: Assemble
// ${getShaderNameDefine({id, source, type})}
// ${getShaderType(type)}
// ${getPlatformShaderDefines(platformInfo)}
// ${getVersionDefines(platformInfo)}
// ${getApplicationDefines(allDefines)}
// ${isVertex ? '' : FRAGMENT_SHADER_PROLOGUE}
// `
Expand Down Expand Up @@ -342,7 +341,6 @@ ${sourceVersionDirective}
${getShaderNameDefine({id, source, stage})}
${`#define SHADER_TYPE_${stage.toUpperCase()}`}
${getPlatformShaderDefines(platformInfo)}
${getVersionDefines(platformInfo)}
${stage === 'fragment' ? FRAGMENT_SHADER_PROLOGUE : ''}
// ----- APPLICATION DEFINES -------------------------
Expand Down
60 changes: 0 additions & 60 deletions modules/shadertools/src/lib/shader-assembly/platform-defines.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,63 +57,3 @@ export function getPlatformShaderDefines(platformInfo: PlatformInfo): string {
`;
}
}

/** Adds defines to let shaders portably v1/v3 check for features */
export function getVersionDefines(platformInfo: PlatformInfo): string {
let versionDefines = '';

if (platformInfo.features.has('webgl2')) {
versionDefines += glsl`\
# define FEATURE_GLSL_DERIVATIVES
# define FEATURE_GLSL_DRAW_BUFFERS
# define FEATURE_GLSL_FRAG_DEPTH
# define FEATURE_GLSL_TEXTURE_LOD
`;
}

if (!platformInfo.features.has('webgl2')) {
if (platformInfo.features.has('glsl-frag-depth')) {
versionDefines += glsl`\
// FEATURE_GLSL_FRAG_DEPTH => gl_FragDepth is available
#ifdef GL_EXT_frag_depth
# extension GL_EXT_frag_depth : enable
# define FEATURE_GLSL_FRAG_DEPTH
# define FRAG_DEPTH
# define gl_FragDepth gl_FragDepthEXT
#endif
`;
}
if (platformInfo?.features.has('glsl-derivatives')) {
versionDefines += glsl`\
// FEATURE_GLSL_DERIVATIVES => dxdF, dxdY and fwidth are available
#if defined(GL_OES_standard_derivatives) || defined(FEATURE_GLSL_DERIVATIVES)
# extension GL_OES_standard_derivatives : enable
# define FEATURE_GLSL_DERIVATIVES
#endif
`;
}
if (platformInfo?.features.has('glsl-frag-data')) {
versionDefines += glsl`\
// FEATURE_GLSL_DRAW_BUFFERS => gl_FragData[] is available
#ifdef GL_EXT_draw_buffers
# extension GL_EXT_draw_buffers : require
# define FEATURE_GLSL_DRAW_BUFFERS
#endif
`;
}
if (platformInfo?.features.has('glsl-texture-lod')) {
versionDefines += glsl`\
// TEXTURE_LOD => texture2DLod etc are available
#ifdef GL_EXT_shader_texture_lod
# extension GL_EXT_shader_texture_lod : enable
# define FEATURE_GLSL_TEXTURE_LOD
# define TEXTURE_LOD
#endif
`;
}
}
return versionDefines;
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,6 @@
import {glsl} from '../../../lib/glsl-utils/highlight';

export const fs = glsl`\
#if defined(USE_TEX_LOD) && !defined(FEATURE_GLSL_TEXTURE_LOD)
# error PBR fragment shader: Texture LOD is not available
#endif
#if !defined(HAS_TANGENTS) && !defined(FEATURE_GLSL_DERIVATIVES)
# error PBR fragment shader: Derivatives are not available
#endif
precision highp float;
uniform bool pbr_uUnlit;
Expand Down Expand Up @@ -349,15 +341,15 @@ vec4 pbr_filterColor(vec4 colorUnused)
color += calculateFinalColor(pbrInputs, lighting_uAmbientLight.color);
// Apply directional light
for(int i = 0, i < lighting_uDirectionalLightCount, i++) {
for(int i = 0; i < lighting_uDirectionalLightCount; i++) {
if (i < lighting_uDirectionalLightCount) {
PBRInfo_setDirectionalLight(pbrInputs, lighting_uDirectionalLight[i].direction);
color += calculateFinalColor(pbrInputs, lighting_uDirectionalLight[i].color);
}
}
// Apply point light
for(int i = 0, i < lighting_uPointLightCount, i++) {
for(int i = 0; i < lighting_uPointLightCount; i++) {
if (i < lighting_uPointLightCount) {
PBRInfo_setPointLight(pbrInputs, lighting_uPointLight[i]);
float attenuation = getPointLightAttenuation(lighting_uPointLight[i], distance(lighting_uPointLight[i].position, pbr_vPosition));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,6 @@
import {glsl} from '../../../lib/glsl-utils/highlight';

export const fs = glsl`\
#if defined(USE_TEX_LOD) && !defined(FEATURE_GLSL_TEXTURE_LOD)
# error PBR fragment shader: Texture LOD is not available
#endif
#if !defined(HAS_TANGENTS) && !defined(FEATURE_GLSL_DERIVATIVES)
# error PBR fragment shader: Derivatives are not available
#endif
precision highp float;
uniform Projection {
Expand Down Expand Up @@ -366,15 +358,15 @@ vec4 pbr_filterColor(vec4 colorUnused)
color += calculateFinalColor(pbrInfo, lighting_uAmbientLight.color);
// Apply directional light
for(int i = 0, i < lighting_uDirectionalLightCount, i++) {
for(int i = 0; i < lighting_uDirectionalLightCount; i++) {
if (i < lighting_uDirectionalLightCount) {
PBRInfo_setDirectionalLight(pbrInfo, lighting_uDirectionalLight[i].direction);
color += calculateFinalColor(pbrInfo, lighting_uDirectionalLight[i].color);
}
}
// Apply point light
for(int i = 0, i < lighting_uPointLightCount, i++) {
for(int i = 0; i < lighting_uPointLightCount; i++) {
if (i < lighting_uPointLightCount) {
PBRInfo_setPointLight(pbrInfo, lighting_uPointLight[i]);
float attenuation = getPointLightAttenuation(lighting_uPointLight[i], distance(lighting_uPointLight[i].position, pbr_vPosition));
Expand Down