Skip to content

Commit

Permalink
feat(cloud-picture): fix "if has two render geometries, the second on…
Browse files Browse the repository at this point in the history
…e's tangents sended to vertex buffer is wrong"

solution
add get/set tangents api;
compute tangents when create sphere/plane/triangle geometries;
fix UpdatePathTracingCPJobEntity->_buildAndSetVertexBufferData: now get tangents from geometry po without compute;
  • Loading branch information
yyc-git committed Sep 27, 2020
1 parent 17ed877 commit f11d923
Show file tree
Hide file tree
Showing 20 changed files with 281 additions and 108 deletions.
12 changes: 12 additions & 0 deletions src/construct/application_layer/scene/GeometryApService.re
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,14 @@ let setNormals = (geometry, normals) => {
NormalsGeometryDoService.setNormals(geometry, normals);
};

let getTangents = geometry => {
TangentsGeometryDoService.getTangents(geometry);
};

let setTangents = (geometry, tangents) => {
TangentsGeometryDoService.setTangents(geometry, tangents);
};

let getIndices = geometry => {
IndicesGeometryDoService.getIndices(geometry);
};
Expand All @@ -63,6 +71,10 @@ let hasNormals = geometry => {
NormalsGeometryDoService.hasNormals(geometry);
};

let hasTangents = geometry => {
TangentsGeometryDoService.hasTangents(geometry);
};

let hasIndices = geometry => {
IndicesGeometryDoService.hasIndices(geometry);
};
Expand Down
6 changes: 5 additions & 1 deletion src/construct/domain_layer/dependency/interface/IRepoDp.re
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ type pbrMaterialRepo = {
setMetalness: (pbrMaterial, float) => Result.t2(unit),
getDiffuseMapImageId: pbrMaterial => option(ImagePOType.id),
setDiffuseMapImageId: (pbrMaterial, ImagePOType.id) => unit,
getChannelRoughnessMetallicMapImageId: pbrMaterial => option(ImagePOType.id),
getChannelRoughnessMetallicMapImageId:
pbrMaterial => option(ImagePOType.id),
setChannelRoughnessMetallicMapImageId: (pbrMaterial, ImagePOType.id) => unit,
getEmissionMapImageId: pbrMaterial => option(ImagePOType.id),
setEmissionMapImageId: (pbrMaterial, ImagePOType.id) => unit,
Expand All @@ -105,11 +106,14 @@ type geometryRepo = {
setNormals: (geometry, Js.Typed_array.Float32Array.t) => Result.t2(unit),
getTexCoords: geometry => Result.t2(Js.Typed_array.Float32Array.t),
setTexCoords: (geometry, Js.Typed_array.Float32Array.t) => Result.t2(unit),
getTangents: geometry => Result.t2(Js.Typed_array.Float32Array.t),
setTangents: (geometry, Js.Typed_array.Float32Array.t) => Result.t2(unit),
getIndices: geometry => Result.t2(Js.Typed_array.Uint32Array.t),
setIndices: (geometry, Js.Typed_array.Uint32Array.t) => Result.t2(unit),
hasVertices: geometry => Result.t2(bool),
hasNormals: geometry => Result.t2(bool),
hasTexCoords: geometry => Result.t2(bool),
hasTangents: geometry => Result.t2(bool),
hasIndices: geometry => Result.t2(bool),
getIndicesCount: geometry => Result.t2(int),
};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
open Js.Typed_array;

let addTangents = ((vertices, texCoords, normals, indices)) => {
let (vertices, texCoords, normals, indices) = (
Float32Array.make(vertices),
Float32Array.make(texCoords),
Float32Array.make(normals),
Uint32Array.make(indices),
);

(
vertices,
texCoords,
normals,
TangentsGeometryDoService.computeTangents(
vertices->VerticesVO.create,
texCoords->TexCoordsVO.create,
normals->NormalsVO.create,
indices->IndicesVO.create,
)
->TangentsVO.value,
indices,
);
};
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
open Js.Typed_array;

let compute = (radius, bands) => {
let latitudeBands = bands;
let longitudeBands = bands;
Expand Down Expand Up @@ -53,5 +55,6 @@ let compute = (radius, bands) => {
};
};

(vertices, texCoords, normals, indices);
(vertices, texCoords, normals, indices)
->ComputePointsGeometryDoService.addTangents;
};
Original file line number Diff line number Diff line change
@@ -1,29 +1,26 @@
open Js.Typed_array;

let create = ((vertices, texCoords, normals, indices)) => {
let create = ((vertices, texCoords, normals, tangents, indices)) => {
let vertices = vertices->VerticesVO.create;
let texCoords = texCoords->TexCoordsVO.create;
let normals = normals->NormalsVO.create;
let tangents = tangents->TangentsVO.create;
let indices = indices->IndicesVO.create;

CreateGeometryDoService.create()
->Result.bind(geometry => {
VerticesGeometryDoService.setVertices(
geometry,
Float32Array.make(vertices)->VerticesVO.create,
)
VerticesGeometryDoService.setVertices(geometry, vertices)
->Result.bind(() => {
TexCoordsGeometryDoService.setTexCoords(geometry, texCoords)
})
->Result.bind(() => {
TexCoordsGeometryDoService.setTexCoords(
geometry,
Float32Array.make(texCoords)->TexCoordsVO.create,
)
NormalsGeometryDoService.setNormals(geometry, normals)
})
->Result.bind(() => {
NormalsGeometryDoService.setNormals(
geometry,
Float32Array.make(normals)->NormalsVO.create,
)
TangentsGeometryDoService.setTangents(geometry, tangents)
})
->Result.bind(() => {
IndicesGeometryDoService.setIndices(
geometry,
Uint32Array.make(indices)->IndicesVO.create,
)
IndicesGeometryDoService.setIndices(geometry, indices)
})
->Result.mapSuccess(() => geometry)
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,50 +1,4 @@
// let create = () => {
// let vertices = [|
// 1.0,
// 0.0,
// (-1.0),
// 1.0,
// 0.0,
// 1.0,
// (-1.0),
// 0.0,
// 1.0,
// (-1.0),
// 0.0,
// (-1.0),
// |];
// let = [|
// 0.0,
// 1.0,
// 0.0,
// 0.0,
// 1.0,
// 0.0,
// 0.0,
// 1.0,
// 0.0,
// 0.0,
// 1.0,
// 0.0,
// |];
// let normals = [|
// 0.0,
// 1.0,
// 0.0,
// 0.0,
// 1.0,
// 0.0,
// 0.0,
// 1.0,
// 0.0,
// 0.0,
// 1.0,
// 0.0,
// |];
// let indices = [|2, 1, 0, 0, 3, 2|];

// CreateDefaultGeometryDoService.create((vertices, normals, indices));
// };
open Js.Typed_array;

let _generate = [%bs.raw
{|
Expand Down Expand Up @@ -121,6 +75,8 @@ let _generate = [%bs.raw
|}
];

let create = (width, height, widthSegments, heightSegments) =>
let create = (width, height, widthSegments, heightSegments) => {
_generate(width, height, widthSegments, heightSegments)
->ComputePointsGeometryDoService.addTangents
->CreateDefaultGeometryDoService.create;
};
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ let create = () => {
[|0., 0., 1., 0., 0., 1., 0., 0., 1.|],
[|0, 1, 2|],
)
->ComputePointsGeometryDoService.addTangents
->CreateDefaultGeometryDoService.create;
};
Original file line number Diff line number Diff line change
Expand Up @@ -211,3 +211,23 @@ let computeTangents = (vertices, texCoords, normals, indices) => {

tangents->TangentsVO.create;
};

let getTangents = geometry => {
DpContainer.unsafeGetGeometryRepoDp().getTangents(
geometry->GeometryEntity.value,
)
->Result.mapSuccess(TangentsVO.create);
};

let setTangents = (geometry, tangents) => {
DpContainer.unsafeGetGeometryRepoDp().setTangents(
geometry->GeometryEntity.value,
tangents->TangentsVO.value,
);
};

let hasTangents = geometry => {
DpContainer.unsafeGetGeometryRepoDp().hasTangents(
geometry->GeometryEntity.value,
);
};
12 changes: 12 additions & 0 deletions src/construct/external_layer/api/run/domain/GeometryRunAPI.re
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,14 @@ let setNormals = (geometry, normals) => {
GeometryApService.setNormals(geometry, normals);
};

let getTangents = geometry => {
GeometryApService.getTangents(geometry);
};

let setTangents = (geometry, tangents) => {
GeometryApService.setTangents(geometry, tangents);
};

let getIndices = geometry => {
GeometryApService.getIndices(geometry);
};
Expand All @@ -63,6 +71,10 @@ let hasNormals = geometry => {
GeometryApService.hasNormals(geometry);
};

let hasTangents = geometry => {
GeometryApService.hasTangents(geometry);
};

let hasIndices = geometry => {
GeometryApService.hasIndices(geometry);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,14 @@ let _injectDependencies = () => {
setTexCoords: GeometryCPRepoDp.setTexCoords,
getNormals: GeometryCPRepoDp.getNormals,
setNormals: GeometryCPRepoDp.setNormals,
getTangents: GeometryCPRepoDp.getTangents,
setTangents: GeometryCPRepoDp.setTangents,
getIndices: GeometryCPRepoDp.getIndices,
setIndices: GeometryCPRepoDp.setIndices,
hasVertices: GeometryCPRepoDp.hasVertices,
hasTexCoords: GeometryCPRepoDp.hasTexCoords,
hasNormals: GeometryCPRepoDp.hasNormals,
hasTangents: GeometryCPRepoDp.hasTangents,
hasIndices: GeometryCPRepoDp.hasIndices,
getIndicesCount: GeometryCPRepoDp.getIndicesCount,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,15 +211,7 @@ let _buildAndSetVertexBufferData = device => {
let vertices = PointsGeometryCPRepo.getSubUsedVerticesTypeArr();
let texCoords = PointsGeometryCPRepo.getSubUsedTexCoordsTypeArr();
let normals = PointsGeometryCPRepo.getSubUsedNormalsTypeArr();
let tangents =
GeometryRunAPI.computeTangents(
vertices->VerticesVO.create,
texCoords->TexCoordsVO.create,
normals->NormalsVO.create,
PointsGeometryCPRepo.getSubUsedIndicesTypeArr()
->IndicesVO.create,
)
->TangentsVO.value;
let tangents = PointsGeometryCPRepo.getSubUsedTangentsTypeArr();

let length = vertexCount * 3;

Expand Down Expand Up @@ -422,7 +414,9 @@ let _buildAndSetPBRMaterialBufferData = (device, allRenderPBRMaterials) => {
let diffuseMapImageId =
PBRMaterialRunAPI.getDiffuseMapImageId(pbrMaterial);
let channelRoughnessMetallicMapImageId =
PBRMaterialRunAPI.getChannelRoughnessMetallicMapImageId(pbrMaterial);
PBRMaterialRunAPI.getChannelRoughnessMetallicMapImageId(
pbrMaterial,
);
let emissionMapImageId =
PBRMaterialRunAPI.getEmissionMapImageId(pbrMaterial);
let normalMapImageId =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@ let createPO = () => {
vertices,
texCoords,
normals,
tangents,
indices,
verticesInfos,
texCoordsInfos,
normalsInfos,
tangentsInfos,
indicesInfos,
),
),
Expand All @@ -40,14 +42,17 @@ let createPO = () => {
vertices,
texCoords,
normals,
tangents,
indices,
verticesInfos,
texCoordsInfos,
normalsInfos,
tangentsInfos,
indicesInfos,
verticesOffset: 0,
texCoordsOffset: 0,
normalsOffset: 0,
tangentsOffset:0,
indicesOffset: 0,
gameObjectsMap:
CreateMapComponentCPRepoUtils.createEmptyMap(geometryCount),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ let _getNormalsTypeArr = () => {
CPRepo.getExnGeometry().normals;
};

let _getTangentsTypeArr = () => {
CPRepo.getExnGeometry().tangents;
};

let _getIndicesTypeArr = () => {
CPRepo.getExnGeometry().indices;
};
Expand Down Expand Up @@ -111,7 +115,11 @@ let getNormalsOffset = () => {
CPRepo.getExnGeometry().normalsOffset;
};

let getIndicesOffset = () => {
let _getTangentsOffset = () => {
CPRepo.getExnGeometry().tangentsOffset;
};

let _getIndicesOffset = () => {
CPRepo.getExnGeometry().indicesOffset;
};

Expand Down Expand Up @@ -139,18 +147,26 @@ let getSubUsedNormalsTypeArr = () => {
);
};

let getSubUsedTangentsTypeArr = () => {
Js.Typed_array.Float32Array.subarray(
~start=0,
~end_=_getTangentsOffset(),
_getTangentsTypeArr(),
);
};

let getSubUsedIndicesTypeArr = () => {
Js.Typed_array.Uint32Array.subarray(
~start=0,
~end_=getIndicesOffset(),
~end_=_getIndicesOffset(),
_getIndicesTypeArr(),
);
};

let getCopyUsedIndicesTypeArr = () => {
Js.Typed_array.Uint32Array.slice(
~start=0,
~end_=getIndicesOffset(),
~end_=_getIndicesOffset(),
_getIndicesTypeArr(),
);
};
Loading

0 comments on commit f11d923

Please sign in to comment.