@@ -148,7 +148,8 @@ namespace osgVerse
148
148
rd->data ->setModelViewProjection (m.ptr ());
149
149
}
150
150
151
- void UserRasterizer::render (const osg::Vec3& cameraPos, std::vector<float >& depthData)
151
+ void UserRasterizer::render (const osg::Vec3& cameraPos, std::vector<float >* depthData,
152
+ std::vector<unsigned short >* hizData)
152
153
{
153
154
std::vector<BatchOccluder*> globalOccluders;
154
155
for (std::set<osg::ref_ptr<UserOccluder>>::iterator it = _occluders.begin ();
@@ -165,8 +166,8 @@ namespace osgVerse
165
166
__m128 camPos = convertFromVec3 (cameraPos);
166
167
std::sort (globalOccluders.begin (), globalOccluders.end (), [&](const BatchOccluder* o1, const BatchOccluder* o2)
167
168
{
168
- __m128 dist1 = _mm_sub_ps (convertFromVec3 ( o1->getCenter ()), camPos);
169
- __m128 dist2 = _mm_sub_ps (convertFromVec3 ( o2->getCenter ()), camPos);
169
+ __m128 dist1 = _mm_sub_ps (((BatchOccluderData*) o1->getOccluder ())-> data -> m_center , camPos);
170
+ __m128 dist2 = _mm_sub_ps (((BatchOccluderData*) o2->getOccluder ())-> data -> m_center , camPos);
170
171
return _mm_comilt_ss (_mm_dp_ps (dist1, dist1, 0x7f ), _mm_dp_ps (dist2, dist2, 0x7f ));
171
172
});
172
173
@@ -186,49 +187,60 @@ namespace osgVerse
186
187
it != _occluders.end (); ++it)
187
188
{
188
189
std::set<osg::ref_ptr<BatchOccluder>>& batches = (*it)->getBatches ();
189
- size_t count = 0 , maxCount = batches.size ();
190
+ size_t count = 0 , count2 = 0 , maxCount = batches.size ();
190
191
191
192
for (std::set<osg::ref_ptr<BatchOccluder>>::iterator it2 = batches.begin ();
192
193
it2 != batches.end (); ++it2)
193
194
{
194
195
BatchOccluder* bo = (*it2).get (); bool needsClipping = false ;
195
196
BatchOccluderData* od = (BatchOccluderData*)bo->getOccluder ();
196
197
if (rd->data ->queryVisibility (od->data ->m_boundsMin , od->data ->m_boundsMax , needsClipping))
197
- count ++;
198
+ { count++; if (needsClipping) count2 ++; }
198
199
}
199
- std::cout << (*it)->getName () << " ; " << count << " / " << maxCount << " \n " ;
200
+ std::cout << (*it)->getName () << " ; " << count << " ( " << count2 << " ) / " << maxCount << " \n " ;
200
201
}
201
202
202
203
// Get result depth image
203
204
std::vector<__m128i>& depthBuffer = rd->data ->getDepthBuffer ();
204
205
std::vector<uint16_t >& hizBuffer = rd->data ->getHiZ ();
205
- depthData.resize (_blockNumX * _blockNumY * 64 , 1 .0f );
206
-
207
- const float bias = 3 .9623753e+28f ; // 1.0f / floatCompressionBias
208
- for (uint32_t y = 0 ; y < _blockNumY; ++y)
206
+ if (depthData)
209
207
{
210
- for (uint32_t x = 0 ; x < _blockNumX; ++x)
208
+ const float bias = 3 .9623753e+28f ; // 1.0f / floatCompressionBias
209
+ depthData->resize (_blockNumX * _blockNumY * 64 );
210
+ for (uint32_t y = 0 ; y < _blockNumY; ++y)
211
211
{
212
- uint32_t index = y * _blockNumX + x;
213
- if (hizBuffer[index ] == 1 ) continue ;
214
-
215
- const __m128i* source = &depthBuffer[8 * index ];
216
- for (uint32_t subY = 0 ; subY < 8 ; ++subY)
212
+ for (uint32_t x = 0 ; x < _blockNumX; ++x)
217
213
{
218
- __m128i depthI = _mm_load_si128 (source++);
219
- __m256i depthI256 = _mm256_slli_epi32 (_mm256_cvtepu16_epi32 (depthI), 12 );
220
- __m256 depth = _mm256_mul_ps (_mm256_castsi256_ps (depthI256), _mm256_set1_ps (bias));
221
- __m256 linDepth = _mm256_div_ps (_mm256_set1_ps (2 * 0 .25f ),
222
- _mm256_sub_ps (_mm256_set1_ps (0 .25f + 1000 .0f ),
223
- _mm256_mul_ps (_mm256_sub_ps (_mm256_set1_ps (1 .0f ), depth),
224
- _mm256_set1_ps (1000 .0f - 0 .25f ))));
225
- float linDepthA[16 ]; _mm256_storeu_ps (linDepthA, linDepth);
226
-
227
- std::vector<float >::iterator it = depthData.begin () + ((8 * _blockNumX) * (8 * y + subY) + 8 * x);
228
- for (uint32_t subX = 0 ; subX < 8 ; ++subX, ++it) *it = linDepthA[subX];
214
+ uint32_t index = y * _blockNumX + x;
215
+ if (hizBuffer[index ] == 1 )
216
+ {
217
+ for (uint32_t subY = 0 ; subY < 8 ; ++subY)
218
+ {
219
+ std::vector<float >::iterator it = depthData->begin () + ((8 * _blockNumX) * (8 * y + subY) + 8 * x);
220
+ for (uint32_t subX = 0 ; subX < 8 ; ++subX, ++it) *it = -1 .0f ;
221
+ }
222
+ continue ;
223
+ }
224
+
225
+ const __m128i* source = &depthBuffer[8 * index ];
226
+ for (uint32_t subY = 0 ; subY < 8 ; ++subY)
227
+ {
228
+ __m128i depthI = _mm_load_si128 (source++);
229
+ __m256i depthI256 = _mm256_slli_epi32 (_mm256_cvtepu16_epi32 (depthI), 12 );
230
+ __m256 depth = _mm256_mul_ps (_mm256_castsi256_ps (depthI256), _mm256_set1_ps (bias));
231
+ __m256 linDepth = _mm256_div_ps (_mm256_set1_ps (2 * 0 .25f ),
232
+ _mm256_sub_ps (_mm256_set1_ps (0 .25f + 1000 .0f ),
233
+ _mm256_mul_ps (_mm256_sub_ps (_mm256_set1_ps (1 .0f ), depth),
234
+ _mm256_set1_ps (1000 .0f - 0 .25f ))));
235
+ float linDepthA[16 ]; _mm256_storeu_ps (linDepthA, linDepth);
236
+
237
+ std::vector<float >::iterator it = depthData->begin () + ((8 * _blockNumX) * (8 * y + subY) + 8 * x);
238
+ for (uint32_t subX = 0 ; subX < 8 ; ++subX, ++it) *it = linDepthA[subX];
239
+ }
229
240
}
230
241
}
231
242
}
243
+ if (hizData) hizData->assign (hizBuffer.begin (), hizBuffer.end ());
232
244
233
245
# if false
234
246
std::vector<char > rawData (_blockNumX * _blockNumY * 256 );
0 commit comments