Skip to content

Commit

Permalink
feat(cloud-picture): ISceneGraphRepoDp->bsdfMaterialRepo->getDiffuseC…
Browse files Browse the repository at this point in the history
…olor now return (r,g,b,a) instead of (r,g,b)

(fix(cloud-picture): get_hit_shading_data.glsl->alpha now = diffuseMap.a * diffuseColor.a)
  • Loading branch information
yyc-git committed Nov 12, 2020
1 parent b3ac205 commit a7ea7df
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ type normalMatrix = Js.Typed_array.Float32Array.t;

type color3 = (float, float, float);

type color4 = (float, float, float, float);

type intensity = float;

type direction = (float, float, float);
Expand All @@ -44,7 +46,7 @@ type viewWorldToCameraMatrix = Js.Typed_array.Float32Array.t;

type projectionMatrix = Js.Typed_array.Float32Array.t;

type diffuse = color3;
type diffuse = color4;

type specularColor = color3;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ let getDiffuseColor = material =>
DpContainer.unsafeGetBSDFMaterialRepoDp().getDiffuseColor(
material->BSDFMaterialEntity.value,
)
->Color3VO.create
->Color4VO.create
->DiffuseVO.create;

let getSpecular = material =>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
type t =
| Color4(SceneGraphRepoType.color4);

let create = value => Color4(value);

let value = color =>
switch (color) {
| Color4(value) => value
};
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
type t =
| Diffuse(Color3VO.t);
| Diffuse(Color4VO.t);

let create = value => Diffuse(value);

Expand All @@ -8,4 +8,4 @@ let value = color =>
| Diffuse(value) => value
};

let getPrimitiveValue = color => color->value->Color3VO.value;
let getPrimitiveValue = color => color->value->Color4VO.value;
Original file line number Diff line number Diff line change
Expand Up @@ -569,17 +569,17 @@ let _buildAndSetBSDFMaterialBufferData = (device, allRenderBSDFMaterials) => {
),
) => {
ListResult.mergeResults([
TypeArrayCPRepoUtils.setFloat3(offset + 0, diffuse, bufferData),
TypeArrayCPRepoUtils.setFloat1(
offset + 3,
alphaCutoff,
bufferData,
),
TypeArrayCPRepoUtils.setFloat4(offset + 0, diffuse, bufferData),
TypeArrayCPRepoUtils.setFloat3(
offset + 4,
specularColor,
bufferData,
),
TypeArrayCPRepoUtils.setFloat1(
offset + 7,
alphaCutoff,
bufferData,
),
TypeArrayCPRepoUtils.setFloat4(
offset + 8,
(metalness, roughness, specular, transmission),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ struct PointIndexData {
};

struct BSDFMaterial {
vec4 diffuseAndAlphaCutoff;
vec4 diffuse;

vec4 specularColor;
vec4 specularColorAndAlphaCutoff;

float metalness;
float roughness;
Expand Down Expand Up @@ -243,7 +243,7 @@ HitShadingData getHitShadingData(uint instanceIndex, uint primitiveIndex) {

HitShadingData data;

float alphaCutoff = mat.diffuseAndAlphaCutoff.w;
float alphaCutoff = mat.specularColorAndAlphaCutoff.w;
float alpha = 1.0;

if (_hasMap(diffuseMapLayerIndex)) {
Expand All @@ -254,13 +254,13 @@ HitShadingData getHitShadingData(uint instanceIndex, uint primitiveIndex) {
diffuseMapLayerIndex));

data.materialDiffuse =
convertSRGBToLinear(diffuseMapData.rgb) * mat.diffuseAndAlphaCutoff.xyz;
convertSRGBToLinear(diffuseMapData.rgb) * mat.diffuse.rgb;

alpha = diffuseMapData.a;
alpha = diffuseMapData.a * mat.diffuse.a;
} else {
data.materialDiffuse = mat.diffuseAndAlphaCutoff.xyz;
data.materialDiffuse = mat.diffuse.rgb;

alpha = 1.0;
alpha = mat.diffuse.a;
}

if (_hasMap(specularMapLayerIndex)) {
Expand All @@ -270,12 +270,12 @@ HitShadingData getHitShadingData(uint instanceIndex, uint primitiveIndex) {
mat.specularMapScale,
specularMapLayerIndex));

data.materialSpecularColor =
convertSRGBToLinear(specularMap.rgb) * vec3(mat.specularColor);
data.materialSpecularColor = convertSRGBToLinear(specularMap.rgb) *
mat.specularColorAndAlphaCutoff.xyz;

data.materialSpecular = specularMap.a * mat.specular;
} else {
data.materialSpecularColor = vec3(mat.specularColor);
data.materialSpecularColor = mat.specularColorAndAlphaCutoff.xyz;
data.materialSpecular = mat.specular;
}

Expand Down
5 changes: 2 additions & 3 deletions test/run/integration/updatePathTracingCPJob_test.re
Original file line number Diff line number Diff line change
Expand Up @@ -1281,7 +1281,6 @@ let _ =
((geometry1, geometry2), (material1, material2)),
) =
_prepare();
// let _ = BSDFMaterialCPTool.setMapData(material1, material2);
TextureArrayCPTool.setMapBetweenAllUsedImageIdToLayerIndex();
let (textureArrayLayerWidth, textureArrayLayerHeight) = (8, 8);
WebGPUDependencyTool.build(
Expand All @@ -1301,7 +1300,7 @@ let _ =
1.,
0.,
0.,
0.,
1.,
0.5,
0.,
0.,
Expand Down Expand Up @@ -1349,7 +1348,7 @@ let _ =
0.5,
1.,
0.,
0.,
0.5,
2.,
1.5,
1.,
Expand Down
4 changes: 2 additions & 2 deletions test/run/tool/BSDFMaterialCPTool.re
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ let buildRepoWithTwoMaterialsAndMapData = sandbox => {
let material1 = 2->Obj.magic;
let material2 = 3->Obj.magic;

let diffuseColor1 = (1., 0., 0.);
let diffuseColor2 = (0., 1., 0.);
let diffuseColor1 = (1., 0., 0., 1.);
let diffuseColor2 = (0., 1., 0., 0.5);
let alphaCutoff1 = 0.0;
let alphaCutoff2 = 0.5;
let specular1 = 0.5;
Expand Down

0 comments on commit a7ea7df

Please sign in to comment.