MCPcopy Create free account
hub / github.com/davideberly/GeometricTools / CreateMesh

Method CreateMesh

GTE/Samples/Graphics/VolumeFog/VolumeFogWindow3.cpp:102–155  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

100}
101
102void VolumeFogWindow3::CreateMesh()
103{
104 std::default_random_engine dre{};
105 std::uniform_real_distribution<float> urd(0.0f, 1.0f);
106
107 VertexFormat vformat{};
108 vformat.Bind(VASemantic::POSITION, DF_R32G32B32_FLOAT, 0);
109 vformat.Bind(VASemantic::COLOR, DF_R32G32B32A32_FLOAT, 0);
110 vformat.Bind(VASemantic::TEXCOORD, DF_R32G32_FLOAT, 0);
111 MeshFactory mf{};
112 mf.SetVertexFormat(vformat);
113
114 mMesh = mf.CreateRectangle(64, 64, 8.0f, 8.0f);
115 auto const& vbuffer = mMesh->GetVertexBuffer();
116 vbuffer->SetUsage(Resource::DYNAMIC_UPDATE);
117 auto* vertices = vbuffer->Get<Vertex>();
118 uint32_t numVertices = vbuffer->GetNumElements();
119
120 // Set the heights based on a precomputed height field. Also create a
121 // texture image to go with the height field.
122 std::string path = mEnvironment.GetPath("HeightField.png");
123 auto texture = WICFileIO::Load(path, true);
124 texture->AutogenerateMipmaps();
125 auto* texels = texture->Get<uint8_t>();
126 Vector4<float> white{ 1.0f, 1.0f, 1.0f, 0.0f };
127 for (uint32_t i = 0; i < numVertices; ++i)
128 {
129 uint8_t value = *texels;
130 float height = 3.0f * value / 255.0f + 0.05f * (2.0f * urd(dre) - 1.0f);
131 vertices[i].position[2] = height;
132
133 // The fog color is white. The alpha channel is fillled in by the
134 // UpdateFog() function.
135 vertices[i].color = white;
136
137 // The texture has blends of red and green.
138 *texels++ = static_cast<uint8_t>(32.0f * (urd(dre) + 1.0f));
139 *texels++ = 3 * (128 - value / 2) / 4;
140 *texels++ = 0;
141 *texels++ = 255;
142 }
143
144 auto effect = std::make_shared<VolumeFogEffect>(mProgramFactory, texture,
145 SamplerState::Filter::MIN_L_MAG_L_MIP_L, SamplerState::Mode::CLAMP,
146 SamplerState::Mode::CLAMP);
147 mMesh->SetEffect(effect);
148
149 mPVWMatrices.Subscribe(mMesh);
150 mTrackBall.Attach(mMesh);
151 mTrackBall.Update();
152 mPVWMatrices.Update();
153
154 UpdateFog();
155}
156
157void VolumeFogWindow3::UpdateFog()
158{

Callers 1

CreateConeMeshMethod · 0.45

Calls 12

SetVertexFormatMethod · 0.80
CreateRectangleMethod · 0.80
SetUsageMethod · 0.80
GetPathMethod · 0.80
AutogenerateMipmapsMethod · 0.80
SetEffectMethod · 0.80
SubscribeMethod · 0.80
AttachMethod · 0.80
BindMethod · 0.45
GetVertexBufferMethod · 0.45
GetNumElementsMethod · 0.45
UpdateMethod · 0.45

Tested by

no test coverage detected