Skip to content

Commit

Permalink
Replace skybox shader generator with a ShaderMaterial using few defin…
Browse files Browse the repository at this point in the history
…es (#7301)

Co-authored-by: Martin Valigursky <[email protected]>
  • Loading branch information
mvaligursky and Martin Valigursky authored Jan 20, 2025
1 parent 68db2b1 commit 0e58330
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 89 deletions.
3 changes: 0 additions & 3 deletions src/scene/shader-lib/chunks/skybox/frag/skybox.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
export default /* glsl */`
#include "decodePS"
#include "gammaPS"
#include "tonemappingPS"
#include "envMultiplyPS"
varying vec3 vViewDir;
Expand Down
55 changes: 0 additions & 55 deletions src/scene/shader-lib/programs/skybox.js

This file was deleted.

46 changes: 15 additions & 31 deletions src/scene/skybox/sky-mesh.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import { CULLFACE_FRONT } from '../../platform/graphics/constants.js';
import { ShaderProcessorOptions } from '../../platform/graphics/shader-processor-options.js';
import { LAYERID_SKYBOX } from '../constants.js';
import { CULLFACE_FRONT, SEMANTIC_POSITION } from '../../platform/graphics/constants.js';
import { LAYERID_SKYBOX, SKYTYPE_INFINITE } from '../constants.js';
import { ShaderMaterial } from '../materials/shader-material.js';
import { MeshInstance } from '../mesh-instance.js';
import { getProgramLibrary } from '../shader-lib/get-program-library.js';
import { skybox } from '../shader-lib/programs/skybox.js';
import { getCoreDefines } from '../shader-lib/utils.js';
import { ChunkUtils } from '../shader-lib/chunk-utils.js';
import { shaderChunks } from '../shader-lib/chunks/chunks.js';
import { SkyGeometry } from './sky-geometry.js';

/**
Expand Down Expand Up @@ -35,34 +33,20 @@ class SkyMesh {
*/
constructor(device, scene, node, texture, type) {

const material = new ShaderMaterial();
material.name = 'SkyMaterial';

material.getShaderVariant = function (params) {

const { scene, cameraShaderParams } = params;
const options = {
defines: getCoreDefines(this, params),
pass: params.pass,
encoding: texture.encoding,
gamma: cameraShaderParams.shaderOutputGamma,
toneMapping: cameraShaderParams.toneMapping,
skymesh: type
};

if (texture.cubemap) {
options.type = 'cubemap';
options.mip = scene.skyboxMip;
} else {
options.type = 'envAtlas';
const material = new ShaderMaterial({
uniqueName: 'SkyMaterial',
vertexCode: shaderChunks.skyboxVS,
fragmentCode: shaderChunks.skyboxPS,
attributes: {
aPosition: SEMANTIC_POSITION
}
});

const processingOptions = new ShaderProcessorOptions(params.viewUniformFormat, params.viewBindGroupFormat);
// defines
material.setDefine('SKYBOX_DECODE_FNC', ChunkUtils.decodeFunc(texture.encoding));
if (type !== SKYTYPE_INFINITE) material.setDefine('SKYMESH', '');
if (texture.cubemap) material.setDefine('SKY_CUBEMAP', '');

const library = getProgramLibrary(device);
library.register('skybox', skybox);
return library.getProgram('skybox', options, processingOptions);
};

material.setParameter('skyboxHighlightMultiplier', scene.skyboxHighlightMultiplier);

Expand Down

0 comments on commit 0e58330

Please sign in to comment.