Skylicht Engine
Loading...
Searching...
No Matches
CRasterisation.h
1/*
2!@
3MIT License
4
5Copyright (c) 2020 Skylicht Technology CO., LTD
6
7Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files
8(the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify,
9merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
10subject to the following conditions:
11
12The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
13
14THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
15INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
16IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
17WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
19
20This file is part of the "Skylicht Engine".
21https://github.com/skylicht-lab/skylicht-engine
22!#
23*/
24
25#pragma once
26
27#include "Lightmapper/CSH9.h"
28
29#include "Utils/CMemoryStream.h"
30
31namespace Skylicht
32{
33 namespace Lightmapper
34 {
36 {
37 core::vector2di Pixel;
38 core::vector3df Position;
39 core::vector3df Normal;
40 core::vector3df Tangent;
41 core::vector3df Binormal;
42
43 CSH9 SH;
44 };
45
46 class CRasterisation
47 {
48 public:
49
50 /*
51 * ERasterPass
52 * http://web.archive.org/web/20160311085440/http://freespace.virgin.net/hugo.elias/radiosity/radiosity.htm
53 * Section: Increasing the accuracy of the solution
54 *
55 * Step 1: Space4A (All bake)
56 * A A
57 *
58 *
59 *
60 * A A
61 * Step 2,3: Space2BX, Space2BY (Interpolate + Bake if needed)
62 * A B A
63 *
64 * B B
65 *
66 * A B A
67 * Step 4: Space4C (Interpolate + Bake if needed)
68 * A B A
69 *
70 * B C B
71 *
72 * A B A
73 * Step 5: Space1D (Interpolate + Bake if needed)
74 * A D B D A
75 * D D D
76 * B D C D B
77 * D D D
78 * A D B D A
79 * Step 6: Space1E (Interpolate + Bake if needed)
80 * A D B D A
81 * D E D E D
82 * B D C D B
83 * D E D E D
84 * A D B D A
85 */
86 enum ERasterPass
87 {
88 Space4A = 0,
89 Space2BX,
90 Space2BY,
91 Space4C,
92 Space1DX,
93 Space1DY,
94 Space1E,
95 PassCount,
96 };
97
98 protected:
99 bool *m_bakedData;
100
101 int m_width;
102 int m_height;
103
104 core::vector2di m_uvMin;
105 core::vector2di m_uvMax;
106
107 core::vector2df m_uvf[3];
108
109 core::vector3df m_position[3];
110 core::vector2df m_uv[3];
111 core::vector3df m_normal[3];
112 core::vector3df m_tangent[3];
113
114 core::array<SBakePixel> m_bakePixels;
115
116 ERasterPass m_currentPass;
117
118 unsigned char *m_lightmapData;
119 unsigned char *m_testBakedData;
120
121 float m_interpolationThreshold;
122
123 private:
124 core::vector3df sampleVector3(const core::vector3df* p, const core::vector2df& uv);
125
126 public:
127 CRasterisation(int width, int height);
128
129 virtual ~CRasterisation();
130
131 void resetBake();
132
133 int getPixelStep(ERasterPass pass);
134
135 int getPassOffsetX(ERasterPass pass);
136
137 int getPassOffsetY(ERasterPass pass);
138
139 bool isInterpolateX(ERasterPass pass);
140
141 bool isInterpolateY(ERasterPass pass);
142
143 core::vector2di setTriangle(
144 const core::vector3df *position,
145 const core::vector2df *uv,
146 const core::vector3df *normal,
147 const core::vector3df *tangent,
148 ERasterPass pass);
149
150 bool samplingTrianglePosition(
151 core::vector3df& outPosition,
152 core::vector3df& outNormal,
153 core::vector3df& outTangent,
154 core::vector3df& outBinormal,
155 core::vector2di& lmPixel);
156
157 void imageDilate();
158
159 bool moveNextPixel(core::vector2di& lmPixel);
160
161 bool isFinished(const core::vector2di& lmPixel);
162
163 inline void setInterpolationThreshold(float f)
164 {
165 m_interpolationThreshold = f;
166 }
167
168 inline int getWidth()
169 {
170 return m_width;
171 }
172
173 inline int getHeight()
174 {
175 return m_height;
176 }
177
178 unsigned char* getTestBakeImage()
179 {
180 return m_testBakedData;
181 }
182
183 unsigned char* getLightmapData()
184 {
185 return m_lightmapData;
186 }
187
188 bool tryInterpolate(int x, int y);
189
190 void getLightmapPixel(int x, int y, float *color);
191
192 bool isBaked(int x, int y);
193
194 core::array<SBakePixel>& getBakePixelQueue()
195 {
196 return m_bakePixels;
197 }
198
199 void flushPixel(std::vector<CSH9>& bakeResults);
200
201 void save(CMemoryStream* stream);
202
203 void load(CMemoryStream* stream);
204 };
205 }
206}
In-memory byte stream for binary serialization and deserialization.
Definition CMemoryStream.h:37
Definition CSH9.h:32
Supports classes for baking lighting into Spherical Harmonics (SH) or Lightmap data.
Definition CBakeLightComponent.h:32
Everything in the Skylicht Engine. You can start by looking at the topics.
Definition AudioDebugLog.h:29
Definition CRasterisation.h:36