Skip to content

Commit

Permalink
Merge pull request #895 from actnwit/feat/vector2
Browse files Browse the repository at this point in the history
  • Loading branch information
Yuki Shimada authored Oct 24, 2021
2 parents 70d0b24 + 68c4098 commit 4efd85c
Show file tree
Hide file tree
Showing 23 changed files with 227 additions and 187 deletions.
2 changes: 1 addition & 1 deletion samples/simple/GltfImporter-iOS/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ declare const Rn: typeof _Rn;
const fxaaMaterial = Rn.MaterialHelper.createFXAA3QualityMaterial();
fxaaMaterial.setParameter(
Rn.ShaderSemantics.ScreenInfo,
new Rn.Vector2(displayResolution, displayResolution)
Rn.Vector2.fromCopyArray2([displayResolution, displayResolution])
);
fxaaMaterial.setTextureParameter(
Rn.ShaderSemantics.BaseColorTexture,
Expand Down
8 changes: 4 additions & 4 deletions samples/simple/VRMImporterMToon/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ declare const Rn: typeof _Rn;
setParameterForMeshComponents(
fxaaRenderPass.meshComponents,
Rn.ShaderSemantics.ScreenInfo,
new Rn.Vector2(displayResolution, displayResolution)
Rn.Vector2.fromCopyArray2([displayResolution, displayResolution])
);
setTextureParameterForMeshComponents(
fxaaRenderPass.meshComponents,
Expand Down Expand Up @@ -234,7 +234,7 @@ function setAnisotropy(baseAnisotropy, clearcoatAnisotropy) {
for (const material of materials) {
material.setParameter(
Rn.ShaderSemantics.Anisotropy,
new Rn.Vector2(baseAnisotropy, clearcoatAnisotropy)
Rn.Vector2.fromCopyArray2([baseAnisotropy, clearcoatAnisotropy])
);
}
}
Expand All @@ -244,7 +244,7 @@ function setClearCoat(factor, roughness) {
for (const material of materials) {
material.setParameter(
Rn.ShaderSemantics.ClearCoatParameter,
new Rn.Vector2(factor, roughness)
Rn.Vector2.fromCopyArray2([factor, roughness])
);
}
}
Expand All @@ -254,7 +254,7 @@ function setSheen(sheenColor, sheenSubsurfaceColor) {
for (const material of materials) {
material.setParameter(
Rn.ShaderSemantics.SheenParameter,
new Rn.Vector2(sheenColor, sheenSubsurfaceColor)
Rn.Vector2.fromCopyArray2([sheenColor, sheenSubsurfaceColor])
);
}
}
Expand Down
2 changes: 1 addition & 1 deletion samples/test_e2e/FXAA/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ function setupRenderPassFxaa(
);
primitiveFxaa.material.setParameter(
Rn.ShaderSemantics.ScreenInfo,
new Rn.Vector2(width, height)
Rn.Vector2.fromCopyArray2([width, height])
);
const meshComponentFxaa = entityFxaa.getMesh() as MeshComponent;
const meshFxaa = new Rn.Mesh();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ declare global {
material.setParameter(Rn.FurnaceTestSingleMaterialNode.debugView, 1); // weakWhiteFurnaceResult
material.setParameter(
Rn.ShaderSemantics.ScreenInfo,
new Rn.Vector2(512, 512)
Rn.Vector2.fromCopyArray2([512, 512])
);
window.material = material;

Expand Down
2 changes: 1 addition & 1 deletion samples/test_e2e/FurnaceTest-whiteFurnace/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ declare global {
const material = Rn.MaterialHelper.createFurnaceTestMaterial();
material.setParameter(
Rn.ShaderSemantics.ScreenInfo,
new Rn.Vector2(512, 512)
Rn.Vector2.fromCopyArray2([512, 512])
);
window.material = material;

Expand Down
2 changes: 1 addition & 1 deletion samples/test_e2e/GltfImporter/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ declare const Rn: typeof _Rn;
const fxaaMaterial = Rn.MaterialHelper.createFXAA3QualityMaterial();
fxaaMaterial.setParameter(
Rn.ShaderSemantics.ScreenInfo,
new Rn.Vector2(displayResolution, displayResolution)
Rn.Vector2.fromCopyArray2([displayResolution, displayResolution])
);
fxaaMaterial.setTextureParameter(
Rn.ShaderSemantics.BaseColorTexture,
Expand Down
4 changes: 2 additions & 2 deletions samples/test_e2e/MultiPass/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ declare const Stats: any;
);
primitive_fxaa.material.setParameter(
Rn.ShaderSemantics.ScreenInfo,
new Rn.Vector2(600, 600)
Rn.Vector2.fromCopyArray2([600, 600])
);
primitive_fxaa.generate({
width: 2,
Expand All @@ -183,7 +183,7 @@ declare const Stats: any;
);
primitive_fxaa.material.setParameter(
Rn.ShaderSemantics.ScreenInfo,
new Rn.Vector2(600, 600)
Rn.Vector2.fromCopyArray2([600, 600])
);
const meshComponent_fxaa = entity_fxaa.getMesh();
const mesh_fxaa = new Rn.Mesh();
Expand Down
2 changes: 1 addition & 1 deletion samples/test_e2e/VRMAnimation/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ declare const Rn: typeof _Rn;
const fxaaMaterial = Rn.MaterialHelper.createFXAA3QualityMaterial();
fxaaMaterial.setParameter(
Rn.ShaderSemantics.ScreenInfo,
new Rn.Vector2(displayResolution, displayResolution)
Rn.Vector2.fromCopyArray2([displayResolution, displayResolution])
);
fxaaMaterial.setTextureParameter(
Rn.ShaderSemantics.BaseColorTexture,
Expand Down
2 changes: 1 addition & 1 deletion src/foundation/importer/ModelConverter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1253,7 +1253,7 @@ export default class ModelConverter {
roughnessFactor = roughnessFactor ?? 1;
material.setParameter(
ShaderSemantics.MetallicRoughnessFactor,
new Vector2(metallicFactor, roughnessFactor)
Vector2.fromCopyArray2([metallicFactor, roughnessFactor])
);

const metallicRoughnessTexture =
Expand Down
53 changes: 32 additions & 21 deletions src/foundation/materials/core/ShaderityUtility.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import Rn from '../../../../dist/esm';
import {ShaderityObject} from 'shaderity';
import MutableScalar from '../../math/MutableScalar';
import MutableVector2 from '../../math/MutableVector2';

test('ShaderityUtility parse rn_data correctly', async () => {
const shaderText = `
Expand Down Expand Up @@ -32,27 +30,40 @@ void main() {
const shaderityObject = {code: shaderText} as ShaderityObject;
const shaderityUtility = Rn.ShaderityUtility.getInstance();

const array = shaderityUtility.getShaderDataRefection(shaderityObject)
.shaderSemanticsInfoArray;
expect(array[0].semantic.str).toBe('worldMatrix');
expect(array[0].componentType).toBe(Rn.ComponentType.Float);
expect(array[0].compositionType).toBe(Rn.CompositionType.Scalar);
expect(array[0].soloDatum).toBe(false);
expect(array[0].none_u_prefix).toBe(false);
expect(array[1].semantic.str).toBe('shadingModel');
expect(array[1].soloDatum).toBe(false);
expect(array[1].initialValue.isStrictEqual(new MutableScalar(0))).toBe(true);
expect(array[1].none_u_prefix).toBe(true);
expect(array[2].semantic.str).toBe('screenInfo');
expect(array[2].soloDatum).toBe(true);
const array = shaderityUtility.getShaderDataRefection(shaderityObject);
expect(array.shaderSemanticsInfoArray[0].semantic.str).toBe('worldMatrix');
expect(array.shaderSemanticsInfoArray[0].componentType).toBe(
Rn.ComponentType.Float
);
expect(array.shaderSemanticsInfoArray[0].compositionType).toBe(
Rn.CompositionType.Scalar
);
expect(array.shaderSemanticsInfoArray[0].soloDatum).toBe(false);
expect(array.shaderSemanticsInfoArray[0].none_u_prefix).toBe(false);
expect(array.shaderSemanticsInfoArray[1].semantic.str).toBe('shadingModel');
expect(array.shaderSemanticsInfoArray[1].soloDatum).toBe(false);
expect(
array.shaderSemanticsInfoArray[1].initialValue.isStrictEqual(
new Rn.MutableScalar(0)
)
).toBe(true);
expect(array.shaderSemanticsInfoArray[1].none_u_prefix).toBe(true);
expect(array.shaderSemanticsInfoArray[2].semantic.str).toBe('screenInfo');
expect(array.shaderSemanticsInfoArray[2].soloDatum).toBe(true);
expect(
array[2].initialValue.isStrictEqual(new MutableVector2(100, 100))
array.shaderSemanticsInfoArray[2].initialValue.isStrictEqual(
Rn.MutableVector2.fromCopyArray2([100, 100])
)
).toBe(true);
expect(array[2].none_u_prefix).toBe(false);
expect(array[3].semantic.str).toBe('diffuseColorTexture');
expect(array[3].compositionType).toBe(Rn.CompositionType.Texture2D);
expect(array[3].initialValue[0]).toBe(7);
expect(array[3].initialValue[1]).toBe(
expect(array.shaderSemanticsInfoArray[2].none_u_prefix).toBe(false);
expect(array.shaderSemanticsInfoArray[3].semantic.str).toBe(
'diffuseColorTexture'
);
expect(array.shaderSemanticsInfoArray[3].compositionType).toBe(
Rn.CompositionType.Texture2D
);
expect(array.shaderSemanticsInfoArray[3].initialValue[0]).toBe(7);
expect(array.shaderSemanticsInfoArray[3].initialValue[1]).toBe(
Rn.AbstractMaterialNode.dummyWhiteTexture
);
});
9 changes: 5 additions & 4 deletions src/foundation/materials/core/ShaderityUtility.ts
Original file line number Diff line number Diff line change
Expand Up @@ -256,10 +256,11 @@ export default class ShaderityUtility {
];
} else {
checkCompositionNumber(CompositionType.Vec2);
shaderSemanticsInfo.initialValue = new MutableVector2(
parseFloat(split[0]),
parseFloat(split[1])
);
shaderSemanticsInfo.initialValue =
MutableVector2.fromCopyArray([
parseFloat(split[0]),
parseFloat(split[1]),
]);
}
break;
case 3:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export default class FXAA3QualitySingleMaterialNode extends AbstractMaterialNode
isSystem: false,
updateInterval: ShaderVariableUpdateInterval.FirstTimeOnly,
soloDatum: false,
initialValue: new Vector2(0, 0),
initialValue: Vector2.fromCopyArray2([0, 0]),
min: 0,
max: Number.MAX_SAFE_INTEGER,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ export default class FurnaceTestSingleMaterialNode extends AbstractMaterialNode
isSystem: false,
updateInterval: ShaderVariableUpdateInterval.FirstTimeOnly,
soloDatum: false,
initialValue: new Vector2(0, 0),
initialValue: Vector2.fromCopyArray2([0, 0]),
min: 0,
max: Number.MAX_SAFE_INTEGER,
},
Expand All @@ -113,7 +113,7 @@ export default class FurnaceTestSingleMaterialNode extends AbstractMaterialNode
isSystem: false,
updateInterval: ShaderVariableUpdateInterval.FirstTimeOnly,
soloDatum: false,
initialValue: new Vector2(1, 1),
initialValue: Vector2.fromCopyArray2([1, 1]),
min: 0,
max: 2,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ export default class PbrExtendedShadingSingleMaterialNode extends AbstractMateri
min: -1,
max: 1,
isSystem: false,
initialValue: new Vector2(0, 0),
initialValue: Vector2.fromCopyArray2([0, 0]),
},
{
semantic: ShaderSemantics.ClearCoatParameter,
Expand All @@ -159,7 +159,7 @@ export default class PbrExtendedShadingSingleMaterialNode extends AbstractMateri
min: 0,
max: 1,
isSystem: false,
initialValue: new Vector2(0.0, 0.5),
initialValue: Vector2.fromCopyArray2([0.0, 0.5]),
},
{
semantic: ShaderSemantics.SheenParameter,
Expand Down Expand Up @@ -305,7 +305,7 @@ export default class PbrExtendedShadingSingleMaterialNode extends AbstractMateri
max: 5,
isSystem: true,
updateInterval: ShaderVariableUpdateInterval.EveryTime,
initialValue: new Vector2(0, 0),
initialValue: Vector2.fromCopyArray2([0, 0]),
},
// {
// semantic: ShaderSemantics.BrdfLutTexture,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ export default class PbrShadingSingleMaterialNode extends AbstractMaterialNode {
max: 2,
isSystem: false,
updateInterval: ShaderVariableUpdateInterval.FirstTimeOnly,
initialValue: new Vector2(1, 1),
initialValue: Vector2.fromCopyArray2([1, 1]),
},
{
semantic: ShaderSemantics.MetallicRoughnessTexture,
Expand Down Expand Up @@ -220,7 +220,7 @@ export default class PbrShadingSingleMaterialNode extends AbstractMaterialNode {
max: 5,
isSystem: true,
updateInterval: ShaderVariableUpdateInterval.FirstTimeOnly,
initialValue: new Vector2(0, 0),
initialValue: Vector2.fromCopyArray2([0, 0]),
},
{
semantic: ShaderSemantics.DiffuseEnvTexture,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ export default class SkinPbrShadingSingleMaterialNode extends AbstractMaterialNo
max: 2,
isSystem: false,
updateInterval: ShaderVariableUpdateInterval.FirstTimeOnly,
initialValue: new Vector2(1, 1),
initialValue: Vector2.fromCopyArray2([1, 1]),
},
{
semantic: ShaderSemantics.MetallicRoughnessTexture,
Expand Down Expand Up @@ -227,7 +227,7 @@ export default class SkinPbrShadingSingleMaterialNode extends AbstractMaterialNo
max: 5,
isSystem: true,
updateInterval: ShaderVariableUpdateInterval.FirstTimeOnly,
initialValue: new Vector2(0, 0),
initialValue: Vector2.fromCopyArray2([0, 0]),
},
// {
// semantic: ShaderSemantics.LightNumber,
Expand Down
6 changes: 3 additions & 3 deletions src/foundation/math/ImageUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,9 @@ function decorrelateColorSpace(

// Compute ranges of the new color space
const colorSpaceRanges: MutableVector2[] = [
new MutableVector2(Number.MAX_VALUE, -Number.MAX_VALUE),
new MutableVector2(Number.MAX_VALUE, -Number.MAX_VALUE),
new MutableVector2(Number.MAX_VALUE, -Number.MAX_VALUE),
MutableVector2.fromCopyArray2([Number.MAX_VALUE, -Number.MAX_VALUE]),
MutableVector2.fromCopyArray2([Number.MAX_VALUE, -Number.MAX_VALUE]),
MutableVector2.fromCopyArray2([Number.MAX_VALUE, -Number.MAX_VALUE]),
];
for (let y = 0; y < input.height; y++) {
for (let x = 0; x < input.width; x++) {
Expand Down
6 changes: 3 additions & 3 deletions src/foundation/math/MathClassUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export default class MathClassUtil {
} else if (typeof element[2] !== 'undefined') {
return Vector3.fromCopyArray([element[0], element[1], element[2]]);
} else {
return new Vector2(element[0], element[1]);
return Vector2.fromCopyArray2([element[0], element[1]]);
}
} else {
return element;
Expand All @@ -58,7 +58,7 @@ export default class MathClassUtil {
} else if (typeof element[2] !== 'undefined') {
return Vector3.fromCopyArray([element[0], element[1], element[2]]);
} else {
return new Vector2(element[0], element[1]);
return Vector2.fromCopyArray2([element[0], element[1]]);
}
} else {
return element;
Expand Down Expand Up @@ -333,7 +333,7 @@ export default class MathClassUtil {
// number?
return val;
} else if (objForDetectType instanceof Vector2) {
return new Vector2(val, val);
return Vector2.fromCopyArray2([val, val]);
} else if (objForDetectType instanceof Vector3) {
return Vector3.fromCopyArray([val, val, val]);
} else if (objForDetectType instanceof Vector4) {
Expand Down
9 changes: 4 additions & 5 deletions src/foundation/math/Matrix22.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import Matrix33 from './Matrix33';
import Matrix44 from './Matrix44';
import {IMatrix, IMatrix22} from './IMatrix';
import {CompositionType} from '../definitions/CompositionType';
import {TypedArray} from '../../types/CommonTypes';
import Vector2 from './Vector2';
import MutableMatrix22 from './MutableMatrix22';
import {MathUtil} from './MathUtil';
Expand Down Expand Up @@ -319,7 +318,7 @@ export default class Matrix22 extends AbstractMatrix implements IMatrix22 {
multiplyVector(vec: Vector2) {
const x = this._v[0] * vec._v[0] + this._v[2] * vec._v[1];
const y = this._v[1] * vec._v[0] + this._v[3] * vec._v[1];
return new (vec.constructor as any)(x, y);
return Vector2.fromCopyArray2([x, y]);
}

multiplyVectorTo(vec: Vector2, outVec: MutableVector2) {
Expand All @@ -331,10 +330,10 @@ export default class Matrix22 extends AbstractMatrix implements IMatrix22 {
}

getScale() {
return new Vector2(
return Vector2.fromCopyArray2([
Math.hypot(this.m00, this.m01),
Math.hypot(this.m10, this.m11)
);
Math.hypot(this.m10, this.m11),
]);
}

getScaleTo(outVec: MutableVector2) {
Expand Down
Loading

0 comments on commit 4efd85c

Please sign in to comment.