@@ -24,17 +24,16 @@ Random generated asteroid model with mesh and texture ready for rendering
24
24
#include " Asteroid.h"
25
25
26
26
#include < Methane/Graphics/Noise.hpp>
27
- #include < Methane/Data/ Instrumentation.h>
27
+ #include < Methane/Instrumentation.h>
28
28
29
29
#include < cmath>
30
- #include < sstream>
31
30
32
31
namespace Methane ::Samples
33
32
{
34
33
35
34
using AsteroidColorSchema = std::array<gfx::Color3f, Asteroid::color_schema_size>;
36
35
37
- static gfx::Color3f TransformSRGBToLinear (const gfx::Color3f& srgb_color)
36
+ static gfx::Color3f TransformSrgbToLinear (const gfx::Color3f& srgb_color)
38
37
{
39
38
ITT_FUNCTION_TASK ();
40
39
@@ -46,20 +45,20 @@ static gfx::Color3f TransformSRGBToLinear(const gfx::Color3f& srgb_color)
46
45
return linear_color;
47
46
}
48
47
49
- static AsteroidColorSchema TransformSRGBToLinear (const AsteroidColorSchema& srgb_color_schema)
48
+ static AsteroidColorSchema TransformSrgbToLinear (const AsteroidColorSchema& srgb_color_schema)
50
49
{
51
50
ITT_FUNCTION_TASK ();
52
51
53
52
AsteroidColorSchema linear_color_schema = {};
54
53
for (size_t i = 0 ; i < srgb_color_schema.size (); ++i)
55
54
{
56
- linear_color_schema[i] = TransformSRGBToLinear (srgb_color_schema[i]);
55
+ linear_color_schema[i] = TransformSrgbToLinear (srgb_color_schema[i]);
57
56
}
58
57
return linear_color_schema;
59
58
}
60
59
61
60
Asteroid::Mesh::Mesh (uint32_t subdivisions_count, bool randomize)
62
- : gfx::IcosahedronMesh<Vertex>(VertexLayoutFromArray (Vertex::layout), 0 .5f , subdivisions_count, true )
61
+ : gfx::IcosahedronMesh<Vertex>(Mesh::VertexLayout (Vertex::layout), 0 .5f , subdivisions_count, true )
63
62
{
64
63
ITT_FUNCTION_TASK ();
65
64
@@ -100,21 +99,21 @@ void Asteroid::Mesh::Randomize(uint32_t random_seed)
100
99
ComputeAverageNormals ();
101
100
}
102
101
103
- Asteroid::Asteroid (gfx::Context & context)
102
+ Asteroid::Asteroid (gfx::RenderContext & context)
104
103
: BaseBuffers(context, Mesh(3 , true ), " Asteroid" )
105
104
{
106
105
ITT_FUNCTION_TASK ();
107
106
108
107
SetTexture (GenerateTextureArray (context, gfx::Dimensions (256 , 256 ), 1 , true , TextureNoiseParameters ()));
109
108
}
110
109
111
- gfx::Texture::Ptr Asteroid::GenerateTextureArray (gfx::Context & context, const gfx::Dimensions& dimensions, uint32_t array_size, bool mipmapped,
110
+ Ptr< gfx::Texture> Asteroid::GenerateTextureArray (gfx::RenderContext & context, const gfx::Dimensions& dimensions, uint32_t array_size, bool mipmapped,
112
111
const TextureNoiseParameters& noise_parameters)
113
112
{
114
113
ITT_FUNCTION_TASK ();
115
114
116
115
const gfx::Resource::SubResources sub_resources = GenerateTextureArraySubresources (dimensions, array_size, noise_parameters);
117
- gfx::Texture::Ptr sp_texture_array = gfx::Texture::CreateImage (context, dimensions, array_size, gfx::PixelFormat::RGBA8Unorm, mipmapped);
116
+ Ptr< gfx::Texture> sp_texture_array = gfx::Texture::CreateImage (context, dimensions, array_size, gfx::PixelFormat::RGBA8Unorm, mipmapped);
118
117
sp_texture_array->SetData (sub_resources);
119
118
return sp_texture_array;
120
119
}
@@ -124,9 +123,9 @@ gfx::Resource::SubResources Asteroid::GenerateTextureArraySubresources(const gfx
124
123
ITT_FUNCTION_TASK ();
125
124
126
125
const gfx::PixelFormat pixel_format = gfx::PixelFormat::RGBA8Unorm;
127
- const uint32_t pixel_size = gfx::GetPixelSize (pixel_format);
128
- const uint32_t pixels_count = dimensions.GetPixelsCount ();
129
- const uint32_t row_stide = pixel_size * dimensions.width ;
126
+ const uint32_t pixel_size = gfx::GetPixelSize (pixel_format);
127
+ const uint32_t pixels_count = dimensions.GetPixelsCount ();
128
+ const uint32_t row_stride = pixel_size * dimensions.width ;
130
129
131
130
gfx::Resource::SubResources sub_resources;
132
131
sub_resources.reserve (array_size);
@@ -137,13 +136,11 @@ gfx::Resource::SubResources Asteroid::GenerateTextureArraySubresources(const gfx
137
136
for (uint32_t array_index = 0 ; array_index < array_size; ++array_index)
138
137
{
139
138
Data::Bytes sub_resource_data (pixels_count * pixel_size, 255u );
140
- FillPerlinNoiseToTexture (sub_resource_data, dimensions,
141
- pixel_size, row_stide,
139
+ FillPerlinNoiseToTexture (sub_resource_data, dimensions, row_stride,
142
140
noise_seed_distribution (rng),
143
141
noise_parameters.persistence ,
144
142
noise_parameters.scale ,
145
- noise_parameters.strength ,
146
- array_index);
143
+ noise_parameters.strength );
147
144
148
145
sub_resources.emplace_back (std::move (sub_resource_data), gfx::Resource::SubResource::Index{ 0 , array_index });
149
146
}
@@ -163,7 +160,7 @@ Asteroid::Colors Asteroid::GetAsteroidRockColors(uint32_t deep_color_index, uint
163
160
{ 88 .f , 88 .f , 88 .f },
164
161
{ 148 .f , 108 .f , 102 .f },
165
162
} };
166
- static const AsteroidColorSchema s_linear_deep_rock_colors = TransformSRGBToLinear (s_srgb_deep_rock_colors);
163
+ static const AsteroidColorSchema s_linear_deep_rock_colors = TransformSrgbToLinear (s_srgb_deep_rock_colors);
167
164
168
165
static const AsteroidColorSchema s_srgb_shallow_rock_colors = { {
169
166
{ 156 .f , 139 .f , 113 .f },
@@ -173,7 +170,7 @@ Asteroid::Colors Asteroid::GetAsteroidRockColors(uint32_t deep_color_index, uint
173
170
{ 153 .f , 146 .f , 136 .f },
174
171
{ 189 .f , 181 .f , 164 .f },
175
172
} };
176
- static const AsteroidColorSchema s_linear_shallow_rock_colors = TransformSRGBToLinear (s_srgb_shallow_rock_colors);
173
+ static const AsteroidColorSchema s_linear_shallow_rock_colors = TransformSrgbToLinear (s_srgb_shallow_rock_colors);
177
174
178
175
if (deep_color_index >= s_linear_deep_rock_colors.size () || shallow_color_index >= s_linear_shallow_rock_colors.size ())
179
176
throw std::invalid_argument (" Deep or shallow color indices are out of boundaries for asteroids color schema." );
@@ -193,7 +190,7 @@ Asteroid::Colors Asteroid::GetAsteroidIceColors(uint32_t deep_color_index, uint3
193
190
{ 16 .f , 66 .f , 66 .f },
194
191
{ 48 .f , 103 .f , 147 .f }
195
192
} };
196
- static const AsteroidColorSchema s_linear_deep_ice_colors = TransformSRGBToLinear (s_srgb_deep_ice_colors);
193
+ static const AsteroidColorSchema s_linear_deep_ice_colors = TransformSrgbToLinear (s_srgb_deep_ice_colors);
197
194
198
195
static const AsteroidColorSchema s_srgb_shallow_ice_colors = { {
199
196
{ 199 .f , 212 .f , 244 .f },
@@ -203,7 +200,7 @@ Asteroid::Colors Asteroid::GetAsteroidIceColors(uint32_t deep_color_index, uint3
203
200
{ 167 .f , 212 .f , 239 .f },
204
201
{ 200 .f , 221 .f , 252 .f }
205
202
} };
206
- static const AsteroidColorSchema s_linear_shallow_ice_colors = TransformSRGBToLinear (s_srgb_shallow_ice_colors);
203
+ static const AsteroidColorSchema s_linear_shallow_ice_colors = TransformSrgbToLinear (s_srgb_shallow_ice_colors);
207
204
208
205
if (deep_color_index >= s_linear_deep_ice_colors.size () || shallow_color_index >= s_linear_shallow_ice_colors.size ())
209
206
throw std::invalid_argument (" Deep or shallow color indices are out of boundaries for asteroids color schema." );
@@ -222,7 +219,7 @@ Asteroid::Colors Asteroid::GetAsteroidLodColors(uint32_t lod_index)
222
219
{ 128 .f , 128 .f , 0 .f }, // LOD-4: yellow
223
220
{ 128 .f , 64 .f , 0 .f }, // LOD-5: orange
224
221
} };
225
- static const AsteroidColorSchema s_linear_lod_deep_colors = TransformSRGBToLinear (s_srgb_lod_deep_colors);
222
+ static const AsteroidColorSchema s_linear_lod_deep_colors = TransformSrgbToLinear (s_srgb_lod_deep_colors);
226
223
227
224
static const AsteroidColorSchema s_srgb_lod_shallow_colors = { {
228
225
{ 0 .f , 255 .f , 0 .f }, // LOD-0: green
@@ -232,16 +229,16 @@ Asteroid::Colors Asteroid::GetAsteroidLodColors(uint32_t lod_index)
232
229
{ 255 .f , 255 .f , 0 .f }, // LOD-4: yellow
233
230
{ 255 .f , 128 .f , 0 .f }, // LOD-5: orange
234
231
} };
235
- static const AsteroidColorSchema s_linear_lod_shallow_colors = TransformSRGBToLinear (s_srgb_lod_shallow_colors);
232
+ static const AsteroidColorSchema s_linear_lod_shallow_colors = TransformSrgbToLinear (s_srgb_lod_shallow_colors);
236
233
237
234
if (lod_index >= s_linear_lod_deep_colors.size () || lod_index >= s_linear_lod_shallow_colors.size ())
238
235
throw std::invalid_argument (" LOD index is out of boundaries for asteroids color schema." );
239
236
240
237
return Asteroid::Colors{ s_linear_lod_deep_colors[lod_index], s_linear_lod_shallow_colors[lod_index] };
241
238
}
242
239
243
- void Asteroid::FillPerlinNoiseToTexture (Data::Bytes& texture_data, const gfx::Dimensions& dimensions, uint32_t pixel_size, uint32_t row_stride,
244
- float random_seed, float persistence, float noise_scale, float noise_strength, uint32_t array_index )
240
+ void Asteroid::FillPerlinNoiseToTexture (Data::Bytes& texture_data, const gfx::Dimensions& dimensions, uint32_t row_stride,
241
+ float random_seed, float persistence, float noise_scale, float noise_strength)
245
242
{
246
243
ITT_FUNCTION_TASK ();
247
244
@@ -259,12 +256,7 @@ void Asteroid::FillPerlinNoiseToTexture(Data::Bytes& texture_data, const gfx::Di
259
256
uint8_t * texel_data = reinterpret_cast <uint8_t *>(&row_data[col]);
260
257
for (size_t channel = 0 ; channel < 3 ; ++channel)
261
258
{
262
- #if 1
263
- const float channel_value = 255 .f ;
264
- #else
265
- const float channel_value = array_index % 3 == channel ? 255.f : 125.f;
266
- #endif
267
- texel_data[channel] = static_cast <uint8_t >(channel_value * noise_intensity);
259
+ texel_data[channel] = static_cast <uint8_t >(255 .f * noise_intensity);
268
260
}
269
261
}
270
262
}
0 commit comments