playcanvas
Version:
Open-source WebGL/WebGPU 3D engine for the web
100 lines (99 loc) • 2.54 kB
JavaScript
import { hashCode } from "../core/hash.js";
import { FOG_NONE, GAMMA_NONE, GAMMA_SRGB, gammaNames, TONEMAP_LINEAR, tonemapNames } from "./constants.js";
class CameraShaderParams {
_gammaCorrection = GAMMA_SRGB;
_toneMapping = TONEMAP_LINEAR;
_srgbRenderTarget = false;
_ssaoEnabled = false;
_fog = FOG_NONE;
_sceneDepthMapLinear = false;
_hash;
_defines = /* @__PURE__ */ new Map();
_definesDirty = true;
get hash() {
if (this._hash === void 0) {
const key = `${this.gammaCorrection}_${this.toneMapping}_${this.srgbRenderTarget}_${this.fog}_${this.ssaoEnabled}_${this.sceneDepthMapLinear}`;
this._hash = hashCode(key);
}
return this._hash;
}
get defines() {
const defines = this._defines;
if (this._definesDirty) {
this._definesDirty = false;
defines.clear();
if (this._sceneDepthMapLinear) defines.set("SCENE_DEPTHMAP_LINEAR", "");
if (this.shaderOutputGamma === GAMMA_SRGB) defines.set("SCENE_COLORMAP_GAMMA", "");
defines.set("FOG", this._fog.toUpperCase());
defines.set("TONEMAP", tonemapNames[this._toneMapping]);
defines.set("GAMMA", gammaNames[this.shaderOutputGamma]);
}
return defines;
}
markDirty() {
this._hash = void 0;
this._definesDirty = true;
}
set fog(type) {
if (this._fog !== type) {
this._fog = type;
this.markDirty();
}
}
get fog() {
return this._fog;
}
set ssaoEnabled(value) {
if (this._ssaoEnabled !== value) {
this._ssaoEnabled = value;
this.markDirty();
}
}
get ssaoEnabled() {
return this._ssaoEnabled;
}
set gammaCorrection(value) {
this._gammaCorrectionAssigned = true;
if (this._gammaCorrection !== value) {
this._gammaCorrection = value;
this.markDirty();
}
}
get gammaCorrection() {
return this._gammaCorrection;
}
set toneMapping(value) {
if (this._toneMapping !== value) {
this._toneMapping = value;
this.markDirty();
}
}
get toneMapping() {
return this._toneMapping;
}
set srgbRenderTarget(value) {
if (this._srgbRenderTarget !== value) {
this._srgbRenderTarget = value;
this.markDirty();
}
}
get srgbRenderTarget() {
return this._srgbRenderTarget;
}
set sceneDepthMapLinear(value) {
if (this._sceneDepthMapLinear !== value) {
this._sceneDepthMapLinear = value;
this.markDirty();
}
}
get sceneDepthMapLinear() {
return this._sceneDepthMapLinear;
}
get shaderOutputGamma() {
const gammaOutput = this._gammaCorrection === GAMMA_SRGB && !this._srgbRenderTarget;
return gammaOutput ? GAMMA_SRGB : GAMMA_NONE;
}
}
export {
CameraShaderParams
};