Skip to content

Commit

Permalink
shadertools: Remove getVersionDefines (#2012)
Browse files Browse the repository at this point in the history
  • Loading branch information
felixpalmer committed Mar 8, 2024
1 parent b4ba7f3 commit c801d59
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 83 deletions.
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

0 comments on commit c801d59

Please sign in to comment.