Why
•
Remeshing으로 (bake-to-texture 없이) 에셋을 사용하기 위해선 새로 생성한 UV가 반드시 필요 (UV 생성 = UV generation)
•
Bake-to-texture 하지 않고, 이미 있는 PBR 메테리얼 텍스처를 single texture로 사용하기 위해서
•
장점
◦
과정
▪
베이킹 X
▪
이미 있는 텍스처 그대로 사용
◦
결과물
▪
Draw call 감소
▪
UV 1개로 전체 모델
What
Simplygon SDK v8 설명
•
v8 기준으로 전체적인 그림과 각 프로세스의 개념을 잡고, v10에서 변화된 diff만 이후에서 추가하는 식으로 진행.
◦
최신과는 차이가 있으나, 설명 자체는 이 때 버전의 도큐먼트가 더 자세함
◦
이후 버전의 도큐먼트에서는 그림 예시는 오히려 삭제되고 설명 글도 훨씬 짧아짐;;
•
주의
◦
여기서 사용되는 용어는 심플리곤의 자체 용어로, 업계/학계 전체에서 통용되는 단어는 아닐 수 있음
The Material LOD is not a processor or tool by itself. In the Simplygon UI there is a Material LOD section but in the API it is not available as its own entity.
The Material LOD is rather a sequence of processors and tools to bake all the scene materials to the LOD.
When a LOD is generated by any of the processors from the Processors section - a mapping image can be generated along with it.
The mapping image can then be used to bake the original materials to the LOD.
Material LOD consists of the following components:
•
To generate texture coordinates.
•
To generate texture coordinates.
•
Generated from a processor to be able to cast materials.
•
To cast the materials.
Simplygon 자체 용어 정의 (학계/업계 용어와는 다름!!)
•
UV
◦
texture coordinate
•
Atlas
◦
1개의 UV map을 지칭
•
Chart
◦
UV map 내 face 덩어리 1개 (= 대륙 하나)
•
Baked
◦
고퀄리티 모델에서부터 변경된 저퀄리티 저용량 모델
◦
Bake-to-texure만 한정해서 쓰는 게 아니라, low-poly로 만드는 작업도 bake에 포함
•
Material table
◦
Parameterizer: 완전히 새 UV 만들기
All new UVs for the baked materials can be created by the parameterizer. Setting the maximum allowed stretch will determine the texture coordinate charts. A large stretch tolerance will create larger charts consisting of more triangles but a larger "UV to 3D" triangle area disparity. The distance between the charts in the atlas is determined by the gutter space. The parametrizer creates unique texture coordinates for all the triangles.
•
What
◦
모든 face마다 새로 UV 좌표 만들어줌
•
Param.
◦
Stretch tolerance
// The higher the number, the fewer texture-borders.
mappingSettings->SetParameterizerMaxStretch( 0.5f );
C++
복사
▪
높이면: 덩어리(=chart) 당 크기(=속한 face 개수)가 커짐
•
→ 텍스처 경계가 적어짐
◦
→ 노말이 경계에서 끊기는 경우가 적어짐
◦
→ 최대한 크면 클수록 좋음
▪
낮추면: chart가 잘게 쪼개짐
◦
Gutter space
mappingSettings->SetGutterSpace( 1 );
C++
복사
▪
키우면: 빈 여백이 늘고 비효율적
API examples
Chart aggregator: 이미 있는 UV들 하나의 atlas에 모으기
The UVs for the baked materials can be created by the chart aggregator. It reuses all the input UVs but re-packs them in a combined texture atlas. The charts will be the same as in the original scene but moved and rotated. The user can choose to have the the UV charts' size adjusted based on the size of the model that is being textured (the UV space of a shoe texture will be smaller than the texture of a car.), or have it adjusted so that the size of the input textures determine the size of the output textures. The distance between the UV charts is determined by the gutter space. If multiple objects in the scene have the same UVs and materials It is possible to either group the overlapping charts and only pack them once or to separate overlapping charts and pack every instance separately. For instance if a building has 100 instances of the same window (with the same texture coords and materials) either a single window's textures or all 100 instances will be packed into the unified atlas depending on the settings.
The chart aggregation modes will scale the output texture space differently based on the input scene's properties.
•
What
◦
이미 있는 UV들을 하나의 atlas에 잘 모으기
•
How
◦
Translation
◦
Rotation
•
Param.
◦
Destination atlas에서의 chart size 정하는 알고리즘
▪
3D 상에서의 크기에 비례
▪
입력 텍스처 크기에 비례
◦
Gutter space
◦
같은 UV && 같은 메테리얼이면 중복할 지 여부
▪
주의: 이미 같은 UV였어야 함!! 심플리곤이 알아서 해주지는 않음!!!!
// If multiple parts of the mesh have the same texcoords, you can either select to
// only generate one instance of the repeating texture or one instance for each
// time it is used. This is controlled with the SeparateOverlappingCharts flag.
// If charts are overlapping in the original texture coords, they will be separated if
// SeparateOverlappingCharts is set to true.
//
chartAggregator->SetSeparateOverlappingCharts(true);
C++
복사
API examples
Mapping image: 한 mesh 위의 점을 다른 mesh 위의 점으로 mapping 하기 위한 구조
The Mapping image is a structure that maps each point on a geometry to a point on another geometry. The LOD processors in Simplygon generate mapping images between the original models and their LODs to be able to cast all the original materials and properties to the corresponding point on the generated mesh.
The Surface Mapper can create mapping images between any two meshes.
The mapping image is a texture generated for the LOD during the processing. It uses the LOD's newly generated texture coordinates. Per pixel it contains the original triangle ID and the barycentric coordinate of the corresponding point on the original object's surface. The mapping image is needed to automatically cast materials with any of the material casters (color caster, normal caster etc.). But the user can also use it manually to retrieve any information from the original model for the current surface element on the LOD.
앞에서 메테리얼 LOD의 구성 요소로 Parameterizer, Chart aggregator, Mapping image, Material caster 4가지가 있다고 해놓고서, Mapping image의 구성 요소로 다시 Parameterizer, Chart aggregator, Material caster가 언급된다. 여기에 Vertex color baker가 하나 추가된다.
SDK v8 개념에서는 Mapping image가 사실상 메테리얼 LOD와 동치.
•
What
◦
Mapping image
1.
한 mesh 위의 점을 다른 mesh 위의 점으로 mapping 하기 위해 심플리곤이 쓰는 방법
•
픽셀 단위 변환
•
3D-3D 변환
◦
변환 함수를 만들기에는 너무 복잡
2.
Low-poly에서 원본 모델로의 변환
•
e.g
◦
Low-poly 모델1 → mapping image1 → 원본 모델
◦
Low-poly 모델2 → mapping image2 → 원본 모델
◦
Low-poly 모델3 → mapping image3 → 원본 모델
◦
Surface mapper
▪
두 mesh 간 mapping image를 만들어 주는 심플리곤 프로세서
•
1.
Reduction
a.
Settings
i.
Repair Settings
ii.
Reduction Settings
iii.
Normal Calculation Settings
iv.
…
v.
Image Mapping Settings
b.
Run
i.
RunProcessing();
2.
Mapping Image 를 이용해서 P’가 원래 모델의 픽셀 P로 매핑된다는 점을 이용한 알고리즘 짜기 (이 부분은 사용자가 코드로 직접 짜야함)
예제에서는 원래 모델의 텍스처 가져오기를 보여줌
•
Param.
//Setup the mapping image properties
uint texture_width = 512; // Should be a multiple of 256
uint texture_height = 512; // Should be a multiple of 256
uint multisampling = 4; // 256 should be divisible by this
// Set the Image Mapping Settings for the reducer
spMappingImageSettings mapping_settings = red->GetMappingImageSettings();
// generate diffuse, specular, normal maps and custom channel later.
mapping_settings->SetGenerateMappingImage( true );
// Set to generate new texture coordinates.
mapping_settings->SetGenerateTexCoords( true );
// The higher the number, the fewer texture-borders.
mapping_settings->SetParameterizerMaxStretch( 0.2f );
// Buffer space for when texture is mip-mapped, so color values don't blend over.
mapping_settings->SetGutterSpace( 4 );
mapping_settings->SetWidth( texture_width );
mapping_settings->SetHeight( texture_height );
mapping_settings->SetMultisamplingLevel( multisampling );
C++
복사
•
Questions
◦
Q. 해상도가 정해져 있나? → discrete / continous
▪
A. Discrete
//Setup the mapping image properties
uint texture_width = 512; // Should be a multiple of 256
uint texture_height = 512; // Should be a multiple of 256
uint multisampling = 4; // 256 should be divisible by this
C++
복사
Components
Mapping image consists of the following components:
•
To create the new and unique texture coordinates.
•
To create the texture coordinates based on the original texture coordinates.
•
Is given the mapping image to cast the materials.
•
Is given the mapping image to bake the vertex colors.
API examples
Material caster: 원본 메테리얼 → low-poly에 적용
There are a number of different casters that work similarly (color caster, normal caster, opacity caster etc). Given the original material table and the mapping image between the LOD and original scene it is able to cast the original materials to the LOD. To reduce mip-map artifacts it is possible to dilate the texture chart colors outwards onto the unused atlas space.
•
Color caster
Color casting (diffuse/specular/ambient etc.).
•
Normal caster
Normal map caster.
•
Opacity caster
Opacity map caster.
•
Ambient occlusion caster
This one is different as it won't be merely taking an original material and casting it to the LOD. It will compute ambient occlusion for the scene and create an ambient occlusion map.
•
What
◦
원본 메테리얼 → low-poly에 적용
◦
Input
▪
Material table (원본의)
▪
Mapping image (LOD → 원본)
◦
면 테두리 부분 아티펙트(=mip-map artifact) 방지
▪
하기 위해서 atlas의 남는 여백으로 색 dilate 하기
•
Param.
◦
The Material caster supports:
•
◦
Required input for material casting.
API examples
그 외
메테리얼 인덱스 단위로 threshold 값을 정할 수 있는 API 제공
// Setup the PerMaterialSizeThresholds array
spRealArray perMaterialSizeThresholds = partRem->GetPerMaterialSizeThresholds();
unsigned int matCount = materials->GetItemsCount();
perMaterialSizeThresholds->SetItemCount( matCount );
// If parts made up of material 1 have a diameter smaller than 10% of the scene's entire diameter,
// then remove the part. Material 2 parts get removed at 20%.
// The threshold for Material 0 is zero, meaning we never remove parts using it.
if( matCount >= 2 )
{
perMaterialSizeThresholds->SetItem( 0, 0.0f );
perMaterialSizeThresholds->SetItem( 1, 0.1f*diam );
perMaterialSizeThresholds->SetItem( 2, 0.2f*diam );
}
C++
복사
•
기본 API가 우리의 사용 용도와 같은가?
◦
우리는 작은 나사라도 앞에 보이는 거면 남기고, 커도 안 보이면 날려야 하는데?
•
UV만 visibility assisted로 할 수 도 있음
The Vertex color baker will bake a selected material channel as colors to the vertices. After baking the vertex colors the textures can be removed and replaced by just the vertex colors. However, the resolution of the baked materials will depend on the amount of vertices. The sampling quality for the vertices depend on the size of the mapping image.
•
Why
◦
조건을 만족하는 경우에는 텍스처를 사용하는 것보다 훨씬 효율적
▪
조건 (내 생각)
•
Face가 충분히 많고
•
하나의 face는 하나의 색 만을 가지고 있고
•
곡선보다는 직선 형태가 많을 때
•
예제 코드 분석
1.
Reducer
a.
Repair Settings
b.
Reduction Settings
c.
Image Mapping Settings
i.
기본 내용
// Set the Image Mapping Settings.
//
spMappingImageSettings mappingSettings = reducer->GetMappingImageSettings();
// Without this we cannot fetch data from the original geometry, and thus not
// populate the vertex color field
//
mappingSettings->SetGenerateMappingImage( true );
// The higher the number, the fewer texture-borders.
//
mappingSettings->SetParameterizerMaxStretch( 0.5f );
mappingSettings->SetGutterSpace( 1 );
C++
복사
ii.
해상도는 높게
// When only using the mapping image to bake to vert colors, the resolution and super-sampling
// effectively decides how many samples will be used for each vertex. Higher sizes means better quality.
//
mappingSettings->SetWidth( 1024 );
mappingSettings->SetHeight( 1024 );
mappingSettings->SetMultisamplingLevel( 1 );
C++
복사
iii.
Mapping Image를 만들기 전에 vertex 마다 유일한 UV를 가지고 있어야 함!!
// If the asset does not already have unique UVs per vertex, i.e. many textures or mirrored UVs,
// a new unique UV set will need to be generated for the mapping image.
//
mappingSettings->SetGenerateTexCoords( true );
mappingSettings->SetTexCoordLevel( (SG_NUM_SUPPORTED_TEXTURE_CHANNELS - 1) );
C++
복사
d.
RunProcessing();
2.
Baker
// Now, finally, bake the entire diffuse channel into color field 0
//
spVertexColorBaker baker = sg->CreateVertexColorBaker();
baker->SetScene( scene ); // The geometry in which you want to create the new vertex color field
baker->SetMappingImage( mappingImage ); // The mapping image mapping the original geometry to the geometry set above
baker->SetSourceMaterials( scene->GetMaterialTable() ); // The material table from which the sampling will be done
baker->SetSourceTextures( scene->GetTextureTable() );
baker->SetChannelName( SG_MATERIAL_CHANNEL_DIFFUSE ); // The channel that will be cast to the color field
baker->SetOutputColorLevelName( "0" ); // The output color level
baker->SetColorSpaceEdgeThreshold( 3.0 ); // This will determine how many "hard borders" will exist in the color field
// It is essentially a RGBA color space difference threshold, where smaller distances are merged.
// This means that the largest distance is sqrt(4) = 2, so 3.0 will produce all smooth borders.
baker->Bake();
C++
복사
3.
Binary로 저장 (.obj는 color 지원이 안 되니까 scene binary로 저장!!)
// Since .obj does not support colors, we export the result as a scene binary.
//
scene->SaveToFile( output_geometry_baked_filename.c_str() );
C++
복사
4.
API 예제: Aggregate Repeating UVs
Simplygon SDK v10 설명
Simplygon SDK v9부터 Material LOD라는 컨셉 버림. 아마도 사람들이 자꾸 이게 processor 종류 중 하나라고 헛갈려서인 듯