Skip to content

Commit

Permalink
Source Engine: Fixes for func_monitor in background01
Browse files Browse the repository at this point in the history
  • Loading branch information
magcius committed Nov 23, 2024
1 parent 6d91be2 commit dddde49
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/Color.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export function colorScale(dst: Color, a: Color, v: number) {
dst.r = a.r * v;
dst.g = a.g * v;
dst.b = a.b * v;
dst.a = a.a * v;
dst.a = a.a;
}

export function colorMult(dst: Color, a: Color, b: Color): void {
Expand Down
2 changes: 1 addition & 1 deletion src/SourceEngine/EntitySystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3938,7 +3938,7 @@ export class point_camera extends BaseEntity {
super(entitySystem, renderContext, bspRenderer, entity);

this.fovY = Number(this.entity.fov);
this.useScreenAspectRatio = fallbackUndefined(this.entity.usescreenaspectratio, '1') !== '0';
this.useScreenAspectRatio = fallbackUndefined(this.entity.usescreenaspectratio, '0') !== '0';

this.viewRenderer.pvsFallback = false;
this.viewRenderer.renderObjectMask &= ~(RenderObjectKind.DetailProps);
Expand Down
19 changes: 18 additions & 1 deletion src/SourceEngine/Materials/MaterialBase.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

import { ReadonlyMat4, vec3, vec2, mat4 } from "gl-matrix";
import { Color, TransparentBlack, White, colorCopy, colorNewCopy, colorNewFromRGBA } from "../../Color.js";
import { Color, TransparentBlack, White, colorCopy, colorNewCopy, colorNewFromRGBA, colorScale } from "../../Color.js";
import { dfShow, dfRange } from "../../DebugFloaters.js";
import { AABB } from "../../Geometry.js";
import { scaleMatrix } from "../../MathHelpers.js";
Expand Down Expand Up @@ -543,6 +543,14 @@ export abstract class BaseMaterial {
return fillGammaColor(d, offs, MaterialUtil.scratchColor);
}

protected paramFillModulationColor(d: Float32Array, offs: number, gamma = true, scale = 1.0): number {
this.calcModulationColor(MaterialUtil.scratchColor, scale);
if (gamma)
return fillGammaColor(d, offs, MaterialUtil.scratchColor);
else
return fillColor(d, offs, MaterialUtil.scratchColor);
}

protected paramFillColor(d: Float32Array, offs: number, name: string, alpha: number = 1.0): number {
this.paramGetVector(name).fillColor(MaterialUtil.scratchColor, alpha);
return fillColor(d, offs, MaterialUtil.scratchColor);
Expand Down Expand Up @@ -683,6 +691,7 @@ export abstract class BaseMaterial {
p['$frame'] = new P.ParameterNumber(0);
p['$color'] = new P.ParameterColor(1, 1, 1);
p['$color2'] = new P.ParameterColor(1, 1, 1);
p['$srgbtint'] = new P.ParameterColor(1, 1, 1);
p['$alpha'] = new P.ParameterNumber(1);

// Data passed from entity system.
Expand Down Expand Up @@ -756,6 +765,14 @@ export abstract class BaseMaterial {
vec2.set(this.texCoord0Scale, 1 / w, 1 / h);
}

protected calcModulationColor(dst: Color, scale: number): void {
this.paramGetVector('$color').fillColor(dst, 1.0);
this.paramGetVector('$color2').mulColor(dst);
this.paramGetVector('$srgbtint').mulColor(dst);
dst.a = this.paramGetNumber('$alpha');
colorScale(dst, dst, scale)
}

protected initStatic(materialCache: MaterialCache) {
if (this.representativeTexture === null)
this.representativeTexture = this.calcRepresentativeTexture();
Expand Down
5 changes: 2 additions & 3 deletions src/SourceEngine/Materials/Material_Sky.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { MaterialShaderTemplateBase, BaseMaterial, AlphaBlendMode, MaterialUtil
import { UberShaderInstanceBasic } from "../UberShader.js";
import * as P from "./MaterialParameters.js";
import { MaterialCache } from "./MaterialCache.js";
import { colorScale } from "../../Color.js";

//#region Sky
export class ShaderTemplate_Sky extends MaterialShaderTemplateBase {
Expand Down Expand Up @@ -193,9 +194,7 @@ export class Material_Sky extends BaseMaterial {
offs += fillVec4v(d, offs, this.textureSizeInfo!);

this.paramGetVector('$color').fillColor(MaterialUtil.scratchColor, 1.0);
MaterialUtil.scratchColor.r *= 8.0;
MaterialUtil.scratchColor.g *= 8.0;
MaterialUtil.scratchColor.b *= 8.0;
colorScale(MaterialUtil.scratchColor, MaterialUtil.scratchColor, 8.0);

offs += fillColor(d, offs, MaterialUtil.scratchColor);
} else if (this.type === Material_Sky_Type.Sky) {
Expand Down
2 changes: 1 addition & 1 deletion src/SourceEngine/Materials/Material_SpriteCard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ export class Material_SpriteCard extends BaseMaterial {
offs += this.paramFillVector4(d, offs, '_b10');
offs += this.paramFillVector4(d, offs, '_b11');
offs += this.paramFillVector4(d, offs, '_b2');
offs += this.paramFillGammaColor(d, offs, '$color', this.paramGetNumber('$alpha'));
offs += this.paramFillModulationColor(d, offs);
offs += fillVec4(d, offs, this.paramGetNumber('_blend0'), this.paramGetNumber('_blend1'), this.paramGetNumber(`$addbasetexture2`));

renderInst.setSamplerBindingsFromTextureMappings(MaterialUtil.textureMappings);
Expand Down
2 changes: 1 addition & 1 deletion src/SourceEngine/Materials/Material_UnlitTwoTexture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export class Material_UnlitTwoTexture extends BaseMaterial {
const d = renderInst.mapUniformBufferF32(ShaderTemplate_UnlitTwoTexture.ub_ObjectParams);
offs += this.paramFillTextureMatrix(d, offs, '$basetexturetransform', this.paramGetFlipY(renderContext, '$basetexture'));
offs += this.paramFillTextureMatrix(d, offs, '$texture2transform');
offs += this.paramFillColor(d, offs, '$color', this.paramGetNumber('$alpha'));
offs += this.paramFillModulationColor(d, offs);

renderInst.setSamplerBindingsFromTextureMappings(MaterialUtil.textureMappings);
renderInst.setGfxProgram(this.gfxProgram);
Expand Down
5 changes: 1 addition & 4 deletions src/SourceEngine/ParticleSystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1363,10 +1363,7 @@ class Renderer_AnimatedSprites extends ModuleBase {
p[2].value = data[colorOffs + 2];
colorOffs += stride;
} else {
const p = (materialInstance.param['$color'] as any).internal;
p[0].value = system.constColor.r;
p[1].value = system.constColor.g;
p[2].value = system.constColor.b;
materialInstance.paramSetColor('$color', system.constColor);
}

if (alphaOffs !== null) {
Expand Down

0 comments on commit dddde49

Please sign in to comment.