-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathlmaterials.h
64 lines (45 loc) · 1.49 KB
/
lmaterials.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#pragma once
#include "scene/3d/mesh_instance.h"
#include "lvector.h"
namespace LM
{
struct LTexture
{
Vector<Color> colors;
int width;
int height;
void Sample(const Vector2 &uv, Color &col) const;
};
struct LMaterial
{
void Create() {pAlbedo = 0; pGodotMaterial = 0; m_bEmitter = false; m_Power_Emission = 0.0f; m_bTransparent = false;}
void Destroy();
const Material * pGodotMaterial;
LTexture * pAlbedo;
bool m_bTransparent;
bool m_bEmitter;
float m_Power_Emission;
Color m_Col_Emission; // color multiplied by emission power
};
class LMaterials
{
public:
LMaterials();
~LMaterials();
void Reset();
void Prepare(unsigned int max_material_size) {m_uiMaxMaterialSize = max_material_size;}
int FindOrCreateMaterial(const MeshInstance &mi, Ref<Mesh> rmesh, int surf_id);
bool FindColors(int mat_id, const Vector2 &uv, Color &albedo, bool &bTransparent);
const LMaterial &GetMaterial(int i) const {return m_Materials[i];}
// in order to account for emission density we need to reduce
// power to keep brightness the same
void AdjustMaterials(float emission_density);
private:
Variant FindCustom_AlbedoTex(Ref<Material> src_material);
void FindCustom_ShaderParams(Ref<Material> src_material, float &emission, Color &emission_color);
LTexture * _get_bake_texture(Ref<Image> p_image, const Color &p_color_mul, const Color &p_color_add);
LTexture * _make_dummy_texture(LTexture * pLTexture, Color col);
LVector<LMaterial> m_Materials;
unsigned int m_uiMaxMaterialSize;
};
} // namespace