载入中...
搜索中...
未找到
Graphics.cpp
浏览该文件的文档.
1#include "graphics/Graphics.h"
2#include "common/Capability.h"
3#include "common/config.h"
5#include "graphics/Grass.h"
7
8#ifdef EVENGINE_WEBGPU
10#else
12#endif
15#include "graphics/Font.h"
17#include "graphics/Light.h"
18#include "graphics/Material.h"
19#include "graphics/Mesh.h"
20#include "graphics/Outline.h"
21#include "graphics/Quad.h"
26#include "graphics/Texture.h"
27#include "graphics/Volumetric.h"
28#include "graphics/Water.h"
29#include "graphics/Waterfall.h"
30
31#ifndef EVENGINE_WEBGPU
32#include "font/FontData.h"
33#endif
34#include "common/Exception.h"
35#include "common/RenderTrace.h"
37#include "image/Image.h"
38#include "image/ImageData.h"
39
40
41#include <simplesquirrel/simplesquirrel.hpp>
42
43#include <cstdint>
44#include <filesystem>
45#include <fstream>
46#include <functional>
47#include <memory>
48
49namespace eve::graphics {
50
51namespace {
52
53bool copyArrayFloats(ssq::Array arr, std::vector<float> &out) {
54 const size_t n = arr.size();
55 out.resize(n);
56 for (size_t i = 0; i < n; ++i) out[i] = arr.get<float>(i);
57 return n > 0;
58}
59
60bool copyArrayUints(ssq::Array arr, std::vector<uint32_t> &out) {
61 const size_t n = arr.size();
62 out.resize(n);
63 for (size_t i = 0; i < n; ++i) out[i] = static_cast<uint32_t>(arr.get<int>(i));
64 return n > 0;
65}
66
67Mesh *newMeshFromArraysScript(Graphics *gfx, ssq::Array posArr, ssq::Array nrmArr,
68 ssq::Array uvArr, int vertexCount, ssq::Array idxArr,
69 int indexCount) {
70 std::vector<float> pos, nrm, uv;
71 std::vector<uint32_t> idx;
72 copyArrayFloats(posArr, pos);
73 copyArrayFloats(nrmArr, nrm);
74 copyArrayFloats(uvArr, uv);
75 copyArrayUints(idxArr, idx);
76 return gfx->newMeshFromArrays(pos.data(), nrm.empty() ? nullptr : nrm.data(),
77 uv.empty() ? nullptr : uv.data(), vertexCount,
78 idx.empty() ? nullptr : idx.data(), indexCount);
79}
80
81bool updateMeshVerticesScript(Graphics *gfx, Mesh *mesh, ssq::Array posArr, ssq::Array nrmArr,
82 ssq::Array uvArr, int vertexCount, ssq::Array idxArr,
83 int indexCount) {
84 std::vector<float> pos, nrm, uv;
85 std::vector<uint32_t> idx;
86 copyArrayFloats(posArr, pos);
87 copyArrayFloats(nrmArr, nrm);
88 copyArrayFloats(uvArr, uv);
89 copyArrayUints(idxArr, idx);
90 return gfx->updateMeshVertices(mesh, pos.data(), nrm.empty() ? nullptr : nrm.data(),
91 uv.empty() ? nullptr : uv.data(), vertexCount,
92 idx.empty() ? nullptr : idx.data(), indexCount);
93}
94
95} // namespace
96
98 // The window module owns the native window; we own the render surface.
99 // Register as its surface host so window never has to include graphics.
100 // The query happens after native window creation, so this pointer is valid
101 // by the time it is used; see common/WindowSurfaceHost.h.
104}
105
107 // Out-of-line so unique_ptr members of effect classes (Outline, AO, GI, …)
108 // are destroyed where the complete types are visible.
109}
110
111#ifdef EVENGINE_WEBGPU
113#else
115#endif
116
126
128 RenderSystem3D::renderToCanvas(*this, canvas, camera);
129}
130
132 if (!scene) return nullptr;
134 aa->setMode("fxaa");
135 const bool doAA = !renderControl_ || renderControl_->isEnabled("aa");
136 if (doAA) {
137 aa->setQuality("medium");
138 } else {
139 aa->setFloat("edgeThreshold", 1.f);
140 aa->setFloat("edgeThresholdMin", 1.f);
141 aa->setFloat("subpix", 0.f);
142 }
143 aa->prepareSource(scene);
144 return aa->getShader();
145}
146
147void Graphics::drawScene3DRGBA(float x, float y, float w, float h, float r, float g, float b, float a) {
148 Texture* scene = getSceneColorTexture();
149 if (!scene) return;
150 // Scene color A is linear view-depth, not opacity. The default textured
151 // blit multiplies that into SrcAlpha, so the planet composites against
152 // the dark clear color and looks dim. Use the same opaque FXAA resolve
153 // as the engine auto-composite path (aa shader writes alpha = 1).
154 if (Shader* sh = prepareSceneColorResolveShader(scene))
155 drawTexturedRectShader(scene, sh, x, y, w, h, Color(r, g, b, a));
156 else
157 drawTexturedRect(scene, x, y, w, h, Color(r, g, b, a));
158}
159
160void Graphics::drawCanvasRGBA(Canvas* canvas, float x, float y, float w, float h, float r, float g, float b, float a) {
161 if (!canvas) return;
162 Texture* tex = canvas->getTexture();
163 if (!tex) return;
164 drawTexturedRect(tex, x, y, w, h, Color(r, g, b, a));
165}
166
167void Graphics::setDirectionalLight(float dx, float dy, float dz, float r, float g, float b) {
168 RenderSystem3D::setDirectionalLight(dx, dy, dz, r, g, b);
169}
170
172
174 if (!renderControl_) {
175 renderControl_ = std::make_unique<RenderControl>();
176 renderControl_->attach(this);
177 renderControl_->compile();
178 }
179 return renderControl_.get();
180}
181
182void Graphics::expose(ssq::Table& table) {
183 auto cls = table.addClass(name, Graphics::create, false);
184 expose(cls);
185
186 auto canvasCls =
187 table.addClass<Canvas>("Canvas", std::function<Canvas*()>([]() -> Canvas* { return nullptr; }), true);
188 canvasCls.addFunc("getWidth", &Canvas::getWidth);
189 canvasCls.addFunc("getHeight", &Canvas::getHeight);
190 canvasCls.addFunc("getTexture", &Canvas::getTexture);
191
192 auto texCls =
193 table.addClass<Texture>("Texture", std::function<Texture*()>([]() -> Texture* { return nullptr; }), true);
194 texCls.addFunc("setCastOcclusion", &Texture::setCastOcclusion);
195 texCls.addFunc("getCastOcclusion", &Texture::getCastOcclusion);
196 texCls.addFunc("getWidth", &Texture::getWidth);
197 texCls.addFunc("getHeight", &Texture::getHeight);
198 texCls.addFunc("getMipmapCount", &Texture::getMipmapCount);
199
200 // Texture / Mesh expose occlusion flags used by volumetric light shafts.
201 // (create returns null — instances come from Graphics::newTexture / newMesh*)
202
203 auto meshCls = table.addClass<Mesh>("Mesh", std::function<Mesh*()>([]() -> Mesh* { return nullptr; }), true);
204 meshCls.addFunc("getVertexCount", &Mesh::getVertexCount);
205 meshCls.addFunc("getIndexCount",
206 std::function<int(Mesh *)>([](Mesh *mesh) { return mesh->indexCount; }));
207 meshCls.addFunc("getMorphCount", &Mesh::getMorphCount);
208 meshCls.addFunc("getMorphName", &Mesh::getMorphName);
209 meshCls.addFunc("hasMorph", &Mesh::hasMorph);
210 meshCls.addFunc("setMorphWeight", &Mesh::setMorphWeight);
211 meshCls.addFunc("getMorphWeight", &Mesh::getMorphWeight);
212 meshCls.addFunc("clearMorphWeights", &Mesh::clearMorphWeights);
213 meshCls.addFunc("hasMorphData", &Mesh::hasMorphData);
214 meshCls.addFunc("isMorphDirty", &Mesh::isMorphDirty);
215 meshCls.addFunc("setCastOcclusion", &Mesh::setCastOcclusion);
216 meshCls.addFunc("getCastOcclusion", &Mesh::getCastOcclusion);
217
218 auto quad = table.addClass<Quad>("Quad", std::function<Quad*()>([]() -> Quad* { return nullptr; }), true);
219 quad.addFunc("setViewport", &Quad::setViewport);
220 quad.addFunc("getX", &Quad::getX);
221 quad.addFunc("getY", &Quad::getY);
222 quad.addFunc("getWidth", &Quad::getWidth);
223 quad.addFunc("getHeight", &Quad::getHeight);
224
225 auto shader = table.addClass<Shader>("Shader", std::function<Shader*()>([]() -> Shader* { return nullptr; }), true);
226 shader.addFunc("declareFloat", &Shader::declareFloat);
227 shader.addFunc("declareVec2", &Shader::declareVec2);
228 shader.addFunc("declareVec3", &Shader::declareVec3);
229 shader.addFunc("declareVec4", &Shader::declareVec4);
230 shader.addFunc("declareMatrix", &Shader::declareMatrix);
231 shader.addFunc("sendFloat", &Shader::sendFloat);
232 shader.addFunc("sendVec2", &Shader::sendVec2);
233 shader.addFunc("sendVec3", &Shader::sendVec3);
234 shader.addFunc("sendVec4", &Shader::sendVec4);
235 shader.addFunc("hasUniform", &Shader::hasUniform);
236 shader.addFunc("getUniformIndex", &Shader::getUniformIndex);
237
238 // ECS entities live in the registry buffer (not standalone new/delete).
239 // Squirrel must not delete them on VM shutdown or close asserts
240 // _CrtIsValidHeapPointer.
241 auto cam2d = table.addClass<Camera2D>("Camera2D",
242 std::function<Camera2D*()>([]() { return Camera2D::createCamera(); }), false);
243 cam2d.addFunc("setAmbient", &Camera2D::setAmbient);
244 cam2d.addFunc("setPosition", &Camera2D::setPosition);
245 cam2d.addFunc("getX", &Camera2D::getX);
246 cam2d.addFunc("getY", &Camera2D::getY);
247 cam2d.addFunc("setZoom", &Camera2D::setZoom);
248 cam2d.addFunc("getZoom", &Camera2D::getZoom);
249 cam2d.addFunc("screenToWorldX", &Camera2D::screenToWorldX);
250 cam2d.addFunc("screenToWorldY", &Camera2D::screenToWorldY);
251 cam2d.addFunc("worldToScreenX", &Camera2D::worldToScreenX);
252 cam2d.addFunc("worldToScreenY", &Camera2D::worldToScreenY);
253
254 auto light = table.addClass<Light2D>(
255 "Light2D", std::function<Light2D*()>([]() { return Light2D::createLight("point"); }), false);
256 light.addFunc("setType", &Light2D::setType);
257 light.addFunc("getType", &Light2D::getType);
258 light.addFunc("setPosition", &Light2D::setPosition);
259 light.addFunc("getX", &Light2D::getX);
260 light.addFunc("getY", &Light2D::getY);
261 light.addFunc("setDirection", &Light2D::setDirection);
262 light.addFunc("getDirX", &Light2D::getDirX);
263 light.addFunc("getDirY", &Light2D::getDirY);
264 light.addFunc("setColor", &Light2D::setColor);
265 light.addFunc("setRadius", &Light2D::setRadius);
266 light.addFunc("getRadius", &Light2D::getRadius);
267 light.addFunc("setEnabled", &Light2D::setEnabled);
268 light.addFunc("isEnabled", &Light2D::isEnabled);
269 light.addFunc("setVolumetric", &Light2D::setVolumetric);
270 light.addFunc("getVolumetric", &Light2D::getVolumetric);
271 light.addFunc("setVolumetricIntensity", &Light2D::setVolumetricIntensity);
272 light.addFunc("getVolumetricIntensity", &Light2D::getVolumetricIntensity);
273 light.addFunc("setCanvas", &Light2D::setCanvas);
274
275 auto cam = table.addClass<Camera3D>("Camera3D",
276 std::function<Camera3D*()>([]() { return Camera3D::createCamera(); }), false);
277 cam.addFunc("setEye", &Camera3D::setEye);
278 cam.addFunc("setTarget", &Camera3D::setTarget);
279 cam.addFunc("setUp", &Camera3D::setUp);
280 cam.addFunc("setFov", &Camera3D::setFov);
281 cam.addFunc("setActive", &Camera3D::setActive);
282 cam.addFunc("setAmbient", &Camera3D::setAmbient);
283 cam.addFunc("setEnvMap", &Camera3D::setEnvMap);
284 cam.addFunc("setEnvIntensity", &Camera3D::setEnvIntensity);
285 cam.addFunc("screenToRay", &Camera3D::screenToRay);
286 cam.addFunc("getScreenRayOriginX", &Camera3D::getScreenRayOriginX);
287 cam.addFunc("getScreenRayOriginY", &Camera3D::getScreenRayOriginY);
288 cam.addFunc("getScreenRayOriginZ", &Camera3D::getScreenRayOriginZ);
289 cam.addFunc("getScreenRayDirX", &Camera3D::getScreenRayDirX);
290 cam.addFunc("getScreenRayDirY", &Camera3D::getScreenRayDirY);
291 cam.addFunc("getScreenRayDirZ", &Camera3D::getScreenRayDirZ);
292
293 auto light3d = table.addClass<Light3D>(
294 "Light3D", std::function<Light3D*()>([]() { return Light3D::createLight("point"); }), false);
295 light3d.addFunc("setType", &Light3D::setType);
296 light3d.addFunc("getType", &Light3D::getType);
297 light3d.addFunc("setPosition", &Light3D::setPosition);
298 light3d.addFunc("getX", &Light3D::getX);
299 light3d.addFunc("getY", &Light3D::getY);
300 light3d.addFunc("getZ", &Light3D::getZ);
301 light3d.addFunc("setDirection", &Light3D::setDirection);
302 light3d.addFunc("getDirX", &Light3D::getDirX);
303 light3d.addFunc("getDirY", &Light3D::getDirY);
304 light3d.addFunc("getDirZ", &Light3D::getDirZ);
305 light3d.addFunc("setColor", &Light3D::setColor);
306 light3d.addFunc("setRadius", &Light3D::setRadius);
307 light3d.addFunc("getRadius", &Light3D::getRadius);
308 light3d.addFunc("setEnabled", &Light3D::setEnabled);
309 light3d.addFunc("isEnabled", &Light3D::isEnabled);
310 light3d.addFunc("setCastShadow", &Light3D::setCastShadow);
311 light3d.addFunc("getCastShadow", &Light3D::getCastShadow);
312 light3d.addFunc("setShadowBias", &Light3D::setShadowBias);
313 light3d.addFunc("getShadowBias", &Light3D::getShadowBias);
314 light3d.addFunc("setShadowStrength", &Light3D::setShadowStrength);
315 light3d.addFunc("getShadowStrength", &Light3D::getShadowStrength);
316 light3d.addFunc("setVolumetric", &Light3D::setVolumetric);
317 light3d.addFunc("getVolumetric", &Light3D::getVolumetric);
318 light3d.addFunc("setVolumetricIntensity", &Light3D::setVolumetricIntensity);
319 light3d.addFunc("getVolumetricIntensity", &Light3D::getVolumetricIntensity);
320
321 auto ent = table.addClass<Renderable3D>(
322 "Renderable3D", std::function<Renderable3D*()>([]() { return Renderable3D::create(); }), false);
323 ent.addFunc("setPosition", &Renderable3D::setPosition);
324 ent.addFunc("setRotation", &Renderable3D::setRotation);
325 ent.addFunc("setYaw", &Renderable3D::setYaw);
326 ent.addFunc("getYaw", &Renderable3D::getYaw);
327 ent.addFunc("setScale", &Renderable3D::setScale);
328 ent.addFunc("setMesh", &Renderable3D::setMesh);
329 ent.addFunc("setTexture", &Renderable3D::setTexture);
330 ent.addFunc("setNormalTexture", &Renderable3D::setNormalTexture);
331 ent.addFunc("setHeightTexture", &Renderable3D::setHeightTexture);
332 ent.addFunc("setShader", &Renderable3D::setShader);
333 ent.addFunc("setMaterial", &Renderable3D::setMaterial);
334 ent.addFunc("getMaterial", &Renderable3D::getMaterial);
335 ent.addFunc("setPart", &Renderable3D::setPart);
336 ent.addFunc("clearParts", &Renderable3D::clearParts);
337 ent.addFunc("getPartCount", &Renderable3D::getPartCount);
338 ent.addFunc("getPartName", &Renderable3D::getPartName);
339 ent.addFunc("getPartMesh", &Renderable3D::getPartMesh);
340 ent.addFunc("getPartMaterial", &Renderable3D::getPartMaterial);
341 ent.addFunc("setHair", &Renderable3D::setHair);
342 ent.addFunc("getHair", &Renderable3D::getHair);
343 ent.addFunc("setTint", &Renderable3D::setTint);
344 ent.addFunc("setMetallic", &Renderable3D::setMetallic);
345 ent.addFunc("setRoughness", &Renderable3D::setRoughness);
346 ent.addFunc("setTexCellBomb", &Renderable3D::setTexCellBomb);
347 ent.addFunc("getTexCellBombScale", &Renderable3D::getTexCellBombScale);
348 ent.addFunc("getTexCellBombStrength", &Renderable3D::getTexCellBombStrength);
349 ent.addFunc("getTexCellBombRotation", &Renderable3D::getTexCellBombRotation);
350 ent.addFunc("setParallax", &Renderable3D::setParallax);
351 ent.addFunc("getParallaxScale", &Renderable3D::getParallaxScale);
352 ent.addFunc("getParallaxMinLayers", &Renderable3D::getParallaxMinLayers);
353 ent.addFunc("getParallaxMaxLayers", &Renderable3D::getParallaxMaxLayers);
354 ent.addFunc("setVisible", &Renderable3D::setVisible);
355 ent.addFunc("setReceiveLight", &Renderable3D::setReceiveLight);
356 ent.addFunc("setCastShadow", &Renderable3D::setCastShadow);
357 ent.addFunc("setReceiveShadow", &Renderable3D::setReceiveShadow);
358 ent.addFunc("setCastOcclusion", &Renderable3D::setCastOcclusion);
359 ent.addFunc("getCastOcclusion", &Renderable3D::getCastOcclusion);
360 ent.addFunc("setCamera", &Renderable3D::setCamera);
361 ent.addFunc("setMeshLod", &Renderable3D::setMeshLod);
362 ent.addFunc("clearMeshLod", &Renderable3D::clearMeshLod);
363 ent.addFunc("getMeshLodCount", &Renderable3D::getMeshLodCount);
364 ent.addFunc("getMeshLodLevelAtDistance", &Renderable3D::getMeshLodLevelAtDistance);
365
366 auto material =
367 table.addClass<Material>("Material", std::function<Material*()>([]() -> Material* { return nullptr; }), true);
368 material.addFunc("setShadingModel", &Material::setShadingModel);
369 material.addFunc("getShadingModel", &Material::getShadingModel);
370 material.addFunc("setAlbedoTexture", &Material::setAlbedoTexture);
371 material.addFunc("getAlbedoTexture", &Material::getAlbedoTexture);
372 material.addFunc("setNormalTexture", &Material::setNormalTexture);
373 material.addFunc("getNormalTexture", &Material::getNormalTexture);
374 material.addFunc("setHeightTexture", &Material::setHeightTexture);
375 material.addFunc("getHeightTexture", &Material::getHeightTexture);
376 material.addFunc("setShader", &Material::setShader);
377 material.addFunc("getShader", &Material::getShader);
378 material.addFunc("setTint", &Material::setTint);
379 material.addFunc("setMetallic", &Material::setMetallic);
380 material.addFunc("getMetallic", &Material::getMetallic);
381 material.addFunc("setRoughness", &Material::setRoughness);
382 material.addFunc("getRoughness", &Material::getRoughness);
383 material.addFunc("setTexCellBomb", &Material::setTexCellBomb);
384 material.addFunc("setParallax", &Material::setParallax);
385 material.addFunc("setReceiveLight", &Material::setReceiveLight);
386 material.addFunc("getReceiveLight", &Material::getReceiveLight);
387 material.addFunc("setCastShadow", &Material::setCastShadow);
388 material.addFunc("getCastShadow", &Material::getCastShadow);
389 material.addFunc("setReceiveShadow", &Material::setReceiveShadow);
390 material.addFunc("getReceiveShadow", &Material::getReceiveShadow);
391 material.addFunc("setCastOcclusion", &Material::setCastOcclusion);
392 material.addFunc("getCastOcclusion", &Material::getCastOcclusion);
393 material.addFunc("setHair", &Material::setHair);
394 material.addFunc("getHair", &Material::getHair);
395 material.addFunc("hasParam", &Material::hasParam);
396 material.addFunc("setFloat", &Material::setFloat);
397 material.addFunc("getFloat", &Material::getFloat);
398
399 auto gbuffer =
400 table.addClass<GBuffer>("GBuffer", std::function<GBuffer*()>([]() -> GBuffer* { return nullptr; }), true);
401 gbuffer.addFunc("isValid", &GBuffer::isValid);
402 gbuffer.addFunc("getWidth", &GBuffer::getWidth);
403 gbuffer.addFunc("getHeight", &GBuffer::getHeight);
404 gbuffer.addFunc("getDepthTexture", &GBuffer::getDepthTexture);
405 gbuffer.addFunc("getHwDepthTexture", &GBuffer::getHwDepthTexture);
406 gbuffer.addFunc("getNormalTexture", &GBuffer::getNormalTexture);
407 gbuffer.addFunc("getAlbedoTexture", &GBuffer::getAlbedoTexture);
408 gbuffer.addFunc("hasBuffer", &GBuffer::hasBuffer);
409 gbuffer.addFunc("getBuffer", &GBuffer::getBuffer);
410
411 auto rctrl = table.addClass<RenderControl>(
412 "RenderControl", std::function<RenderControl*()>([]() -> RenderControl* { return nullptr; }), true);
413 rctrl.addFunc("supports", &RenderControl::supports);
414 rctrl.addFunc("enable", &RenderControl::enable);
415 rctrl.addFunc("disable", &RenderControl::disable);
416 rctrl.addFunc("isEnabled", &RenderControl::isEnabled);
417 rctrl.addFunc("compile", &RenderControl::compile);
418 rctrl.addFunc("isCompiled", &RenderControl::isCompiled);
419 rctrl.addFunc("getPassCount", &RenderControl::getPassCount);
420 rctrl.addFunc("getPassName", &RenderControl::getPassName);
421 rctrl.addFunc("hasPass", &RenderControl::hasPass);
422 rctrl.addFunc("getGBuffer", static_cast<GBuffer* (RenderControl::*)()>(&RenderControl::getGBuffer));
423
424 auto vol = table.addClass<Volumetric>("Volumetric",
425 std::function<Volumetric*()>([]() -> Volumetric* { return nullptr; }), true);
426 vol.addFunc("setQuality", &Volumetric::setQuality);
427 vol.addFunc("getQuality", &Volumetric::getQuality);
428 vol.addFunc("setMode", &Volumetric::setMode);
429 vol.addFunc("getMode", &Volumetric::getMode);
430 vol.addFunc("setLightScreenUV", &Volumetric::setLightScreenUV);
431 vol.addFunc("getLightScreenU", &Volumetric::getLightScreenU);
432 vol.addFunc("getLightScreenV", &Volumetric::getLightScreenV);
433 vol.addFunc("setLightScreenPos", &Volumetric::setLightScreenPos);
434 vol.addFunc("setLightDirection", &Volumetric::setLightDirection);
435 vol.addFunc("setCamera", &Volumetric::setCamera);
436 vol.addFunc("setShaftColor", &Volumetric::setShaftColor);
437 vol.addFunc("setFogColor", &Volumetric::setFogColor);
438 vol.addFunc("setIntensity", &Volumetric::setIntensity);
439 vol.addFunc("setTime", &Volumetric::setTime);
440 vol.addFunc("setDensity", &Volumetric::setDensity);
441 vol.addFunc("hasParam", &Volumetric::hasParam);
442 vol.addFunc("setFloat", &Volumetric::setFloat);
443 vol.addFunc("getFloat", &Volumetric::getFloat);
444 vol.addFunc("getSampleCount", &Volumetric::getSampleCount);
445 vol.addFunc("getDownscale", &Volumetric::getDownscale);
446 vol.addFunc("resolutionFor", &Volumetric::resolutionFor);
447 vol.addFunc("beginOcclusionMap", &Volumetric::beginOcclusionMap);
448 vol.addFunc("drawOccluder", &Volumetric::drawOccluder);
449 vol.addFunc("drawOccluderSolid", &Volumetric::drawOccluderSolid);
450 vol.addFunc("drawOccluderTexture", &Volumetric::drawOccluderTexture);
451 vol.addFunc("drawOccluders2D", &Volumetric::drawOccluders2D);
452 vol.addFunc("scatter", &Volumetric::scatter);
453 vol.addFunc("scatterTo", &Volumetric::scatterTo);
454 vol.addFunc("applyFromScene", &Volumetric::applyFromScene);
455 vol.addFunc("applyFromSceneTo", &Volumetric::applyFromSceneTo);
456 vol.addFunc("rayMarch", &Volumetric::rayMarch);
457 vol.addFunc("rayMarchTo", &Volumetric::rayMarchTo);
458 vol.addFunc("setFogHeight", &Volumetric::setFogHeight);
459 vol.addFunc("setFogHeightFalloff", &Volumetric::setFogHeightFalloff);
460 vol.addFunc("setFogStart", &Volumetric::setFogStart);
461 vol.addFunc("setFogEnd", &Volumetric::setFogEnd);
462 vol.addFunc("setFogNoise", &Volumetric::setFogNoise);
463 vol.addFunc("applyFog", &Volumetric::applyFog);
464 vol.addFunc("applyFogTo", &Volumetric::applyFogTo);
465 vol.addFunc("getShader", &Volumetric::getShader);
466 vol.addFunc("getRayMarchShader", &Volumetric::getRayMarchShader);
467 vol.addFunc("getFogShader", &Volumetric::getFogShader);
468
469 auto grassField = table.addClass<GrassField>(
470 "GrassField", std::function<GrassField*()>([]() -> GrassField* { return nullptr; }), true);
471 grassField.addFunc("bakePlane", static_cast<void (GrassField::*)(float, float, int, int)>(&GrassField::bakePlane));
472 grassField.addFunc("update", &GrassField::update);
473 grassField.addFunc("setTime", &GrassField::setTime);
474 grassField.addFunc("getTime", &GrassField::getTime);
475 grassField.addFunc("setFrameDuration", &GrassField::setFrameDuration);
476 grassField.addFunc("getFrameDuration", &GrassField::getFrameDuration);
477 grassField.addFunc("draw", static_cast<void (GrassField::*)()>(&GrassField::draw));
478 grassField.addFunc("getDenseMesh", &GrassField::getDenseMesh);
479 grassField.addFunc("getSparseMesh", &GrassField::getSparseMesh);
480 grassField.addFunc("getShader", &GrassField::getShader);
481 grassField.addFunc("getAtlas", &GrassField::getAtlas);
482 grassField.addFunc("getDenseCount", &GrassField::getDenseCount);
483 grassField.addFunc("getSparseCount", &GrassField::getSparseCount);
484
485 auto waterfall = table.addClass<Waterfall>(
486 "Waterfall", std::function<Waterfall*()>([]() -> Waterfall* { return nullptr; }), true);
487 waterfall.addFunc("createSheet", &Waterfall::createSheet);
488 waterfall.addFunc("update", &Waterfall::update);
489 waterfall.addFunc("setTime", &Waterfall::setTime);
490 waterfall.addFunc("getTime", &Waterfall::getTime);
491 waterfall.addFunc("setFlowSpeed", &Waterfall::setFlowSpeed);
492 waterfall.addFunc("getFlowSpeed", &Waterfall::getFlowSpeed);
493 waterfall.addFunc("setTurbulence", &Waterfall::setTurbulence);
494 waterfall.addFunc("getTurbulence", &Waterfall::getTurbulence);
495 waterfall.addFunc("setStreakCount", &Waterfall::setStreakCount);
496 waterfall.addFunc("getStreakCount", &Waterfall::getStreakCount);
497 waterfall.addFunc("setStreakScale", &Waterfall::setStreakScale);
498 waterfall.addFunc("getStreakScale", &Waterfall::getStreakScale);
499 waterfall.addFunc("setTopFoam", &Waterfall::setTopFoam);
500 waterfall.addFunc("getTopFoam", &Waterfall::getTopFoam);
501 waterfall.addFunc("setBottomFoam", &Waterfall::setBottomFoam);
502 waterfall.addFunc("getBottomFoam", &Waterfall::getBottomFoam);
503 waterfall.addFunc("setFoamAmount", &Waterfall::setFoamAmount);
504 waterfall.addFunc("getFoamAmount", &Waterfall::getFoamAmount);
505 waterfall.addFunc("setWaterColor", &Waterfall::setWaterColor);
506 waterfall.addFunc("setReflectionIntensity", &Waterfall::setReflectionIntensity);
507 waterfall.addFunc("getReflectionIntensity", &Waterfall::getReflectionIntensity);
508 waterfall.addFunc("setSunIntensity", &Waterfall::setSunIntensity);
509 waterfall.addFunc("getSunIntensity", &Waterfall::getSunIntensity);
510 waterfall.addFunc("bindParams", &Waterfall::bindParams);
511 waterfall.addFunc("draw", &Waterfall::draw);
512 waterfall.addFunc("getShader", &Waterfall::getShader);
513 waterfall.addFunc("getMesh", &Waterfall::getMesh);
514 auto water = table.addClass<Water>("Water", std::function<Water*()>([]() -> Water* { return nullptr; }), true);
515 water.addFunc("createPlane", &Water::createPlane);
516 water.addFunc("update", &Water::update);
517 water.addFunc("setTime", &Water::setTime);
518 water.addFunc("getTime", &Water::getTime);
519 water.addFunc("setWaveSpeed", &Water::setWaveSpeed);
520 water.addFunc("getWaveSpeed", &Water::getWaveSpeed);
521 water.addFunc("setWaveAmplitude", &Water::setWaveAmplitude);
522 water.addFunc("getWaveAmplitude", &Water::getWaveAmplitude);
523 water.addFunc("setRippleAmplitude", &Water::setRippleAmplitude);
524 water.addFunc("getRippleAmplitude", &Water::getRippleAmplitude);
525 water.addFunc("setEdgeFalloff", &Water::setEdgeFalloff);
526 water.addFunc("getEdgeFalloff", &Water::getEdgeFalloff);
527 water.addFunc("setRippleCount", &Water::setRippleCount);
528 water.addFunc("getRippleCount", &Water::getRippleCount);
529 water.addFunc("setRippleInterval", &Water::setRippleInterval);
530 water.addFunc("getRippleInterval", &Water::getRippleInterval);
531 water.addFunc("setWaveScale", &Water::setWaveScale);
532 water.addFunc("getWaveScale", &Water::getWaveScale);
533 water.addFunc("setWaterColor", &Water::setWaterColor);
534 water.addFunc("setReflectionTint", &Water::setReflectionTint);
535 water.addFunc("setReflectionIntensity", &Water::setReflectionIntensity);
536 water.addFunc("getReflectionIntensity", &Water::getReflectionIntensity);
537 water.addFunc("setSunIntensity", &Water::setSunIntensity);
538 water.addFunc("getSunIntensity", &Water::getSunIntensity);
539 water.addFunc("setScreenSpaceReflection", &Water::setScreenSpaceReflection);
540 water.addFunc("getScreenSpaceReflection", &Water::getScreenSpaceReflection);
541 water.addFunc("getScreenSpaceReflectionStrength", &Water::getScreenSpaceReflectionStrength);
542 water.addFunc("setViewport", &Water::setViewport);
543 water.addFunc("getViewportWidth", &Water::getViewportWidth);
544 water.addFunc("getViewportHeight", &Water::getViewportHeight);
545 water.addFunc("bindParams", &Water::bindParams);
546 water.addFunc("draw", &Water::draw);
547 water.addFunc("getShader", &Water::getShader);
548 water.addFunc("getMesh", &Water::getMesh);
549
550 auto ao = table.addClass<AmbientOcclusion>(
551 "AmbientOcclusion", std::function<AmbientOcclusion*()>([]() -> AmbientOcclusion* { return nullptr; }), true);
552 ao.addFunc("setQuality", &AmbientOcclusion::setQuality);
553 ao.addFunc("getQuality", &AmbientOcclusion::getQuality);
554 ao.addFunc("setMode", &AmbientOcclusion::setMode);
555 ao.addFunc("getMode", &AmbientOcclusion::getMode);
556 ao.addFunc("setCamera", &AmbientOcclusion::setCamera);
557 ao.addFunc("setRadius", &AmbientOcclusion::setRadius);
558 ao.addFunc("setBias", &AmbientOcclusion::setBias);
559 ao.addFunc("setIntensity", &AmbientOcclusion::setIntensity);
560 ao.addFunc("setPower", &AmbientOcclusion::setPower);
561 ao.addFunc("setThickness", &AmbientOcclusion::setThickness);
562 ao.addFunc("getRadius", &AmbientOcclusion::getRadius);
563 ao.addFunc("getBias", &AmbientOcclusion::getBias);
564 ao.addFunc("getIntensity", &AmbientOcclusion::getIntensity);
565 ao.addFunc("getPower", &AmbientOcclusion::getPower);
566 ao.addFunc("hasParam", &AmbientOcclusion::hasParam);
567 ao.addFunc("setFloat", &AmbientOcclusion::setFloat);
568 ao.addFunc("getFloat", &AmbientOcclusion::getFloat);
569 ao.addFunc("getSampleCount", &AmbientOcclusion::getSampleCount);
570 ao.addFunc("getDownscale", &AmbientOcclusion::getDownscale);
571 ao.addFunc("resolutionFor", &AmbientOcclusion::resolutionFor);
572 ao.addFunc("compute", &AmbientOcclusion::compute);
573 ao.addFunc("computeTo", &AmbientOcclusion::computeTo);
574 ao.addFunc("blur", &AmbientOcclusion::blur);
575 ao.addFunc("blurTo", &AmbientOcclusion::blurTo);
576 ao.addFunc("applyOverlay", &AmbientOcclusion::applyOverlay);
577 ao.addFunc("applyOverlayTo", &AmbientOcclusion::applyOverlayTo);
578 ao.addFunc("applyFromDepth", &AmbientOcclusion::applyFromDepth);
579 ao.addFunc("applyFromDepthTo", &AmbientOcclusion::applyFromDepthTo);
580 ao.addFunc("applyFromGBuffer", &AmbientOcclusion::applyFromGBuffer);
581 ao.addFunc("getShader", &AmbientOcclusion::getShader);
582 ao.addFunc("getSsaoShader", &AmbientOcclusion::getSsaoShader);
583 ao.addFunc("getHbaoShader", &AmbientOcclusion::getHbaoShader);
584 ao.addFunc("getGtaoShader", &AmbientOcclusion::getGtaoShader);
585 ao.addFunc("getBlurShader", &AmbientOcclusion::getBlurShader);
586 ao.addFunc("getOverlayShader", &AmbientOcclusion::getOverlayShader);
587 ao.addFunc("getFromDepthShader", &AmbientOcclusion::getFromDepthShader);
588
589 auto outline =
590 table.addClass<Outline>("Outline", std::function<Outline*()>([]() -> Outline* { return nullptr; }), true);
591 outline.addFunc("setColor", &Outline::setColor);
592 outline.addFunc("getColorR", &Outline::getColorR);
593 outline.addFunc("getColorG", &Outline::getColorG);
594 outline.addFunc("getColorB", &Outline::getColorB);
595 outline.addFunc("setWidth", &Outline::setWidth);
596 outline.addFunc("getWidth", &Outline::getWidth);
597 outline.addFunc("setDepthThreshold", &Outline::setDepthThreshold);
598 outline.addFunc("getDepthThreshold", &Outline::getDepthThreshold);
599 outline.addFunc("setDepthSensitivity", &Outline::setDepthSensitivity);
600 outline.addFunc("getDepthSensitivity", &Outline::getDepthSensitivity);
601 outline.addFunc("setNormalThreshold", &Outline::setNormalThreshold);
602 outline.addFunc("getNormalThreshold", &Outline::getNormalThreshold);
603 outline.addFunc("setSoftness", &Outline::setSoftness);
604 outline.addFunc("getSoftness", &Outline::getSoftness);
605 outline.addFunc("setClip", &Outline::setClip);
606 outline.addFunc("hasParam", &Outline::hasParam);
607 outline.addFunc("setFloat", &Outline::setFloat);
608 outline.addFunc("getFloat", &Outline::getFloat);
609 outline.addFunc("apply", &Outline::apply);
610 outline.addFunc("applyTo", &Outline::applyTo);
611 outline.addFunc("getShader", &Outline::getShader);
612
613 auto gi = table.addClass<GlobalIllumination>(
614 "GlobalIllumination", std::function<GlobalIllumination*()>([]() -> GlobalIllumination* { return nullptr; }),
615 true);
616 gi.addFunc("setQuality", &GlobalIllumination::setQuality);
617 gi.addFunc("getQuality", &GlobalIllumination::getQuality);
618 gi.addFunc("setCamera", &GlobalIllumination::setCamera);
619 gi.addFunc("setRadius", &GlobalIllumination::setRadius);
620 gi.addFunc("setIntensity", &GlobalIllumination::setIntensity);
621 gi.addFunc("setLightDirection", &GlobalIllumination::setLightDirection);
622 gi.addFunc("setLightColor", &GlobalIllumination::setLightColor);
623 gi.addFunc("getRadius", &GlobalIllumination::getRadius);
624 gi.addFunc("getIntensity", &GlobalIllumination::getIntensity);
625 gi.addFunc("hasParam", &GlobalIllumination::hasParam);
626 gi.addFunc("setFloat", &GlobalIllumination::setFloat);
627 gi.addFunc("getFloat", &GlobalIllumination::getFloat);
628 gi.addFunc("getSampleCount", &GlobalIllumination::getSampleCount);
629 gi.addFunc("applyFromDepth", &GlobalIllumination::applyFromDepth);
630 gi.addFunc("applyFromDepthTo", &GlobalIllumination::applyFromDepthTo);
631 gi.addFunc("applyFromScene", &GlobalIllumination::applyFromScene);
632 gi.addFunc("getShader", &GlobalIllumination::getShader);
633
634 auto ssr = table.addClass<ScreenSpaceReflection>(
635 "ScreenSpaceReflection",
636 std::function<ScreenSpaceReflection*()>([]() -> ScreenSpaceReflection* { return nullptr; }), true);
637 ssr.addFunc("setCamera", &ScreenSpaceReflection::setCamera);
638 ssr.addFunc("setEnabled", &ScreenSpaceReflection::setEnabled);
639 ssr.addFunc("getEnabled", &ScreenSpaceReflection::getEnabled);
640 ssr.addFunc("setMaxDistance", &ScreenSpaceReflection::setMaxDistance);
641 ssr.addFunc("setStepLength", &ScreenSpaceReflection::setStepLength);
642 ssr.addFunc("setMaxSteps", &ScreenSpaceReflection::setMaxSteps);
643 ssr.addFunc("setThickness", &ScreenSpaceReflection::setThickness);
644 ssr.addFunc("setStrength", &ScreenSpaceReflection::setStrength);
645 ssr.addFunc("getStrength", &ScreenSpaceReflection::getStrength);
646 ssr.addFunc("hasParam", &ScreenSpaceReflection::hasParam);
647 ssr.addFunc("setFloat", &ScreenSpaceReflection::setFloat);
648 ssr.addFunc("getFloat", &ScreenSpaceReflection::getFloat);
649 ssr.addFunc("applyFromScene", &ScreenSpaceReflection::applyFromScene);
650 ssr.addFunc("applyFromSceneTo", &ScreenSpaceReflection::applyFromSceneTo);
651 ssr.addFunc("getShader", &ScreenSpaceReflection::getShader);
652
653 auto aa = table.addClass<AntiAliasing>(
654 "AntiAliasing", std::function<AntiAliasing*()>([]() -> AntiAliasing* { return nullptr; }), true);
655 aa.addFunc("setQuality", &AntiAliasing::setQuality);
656 aa.addFunc("getQuality", &AntiAliasing::getQuality);
657 aa.addFunc("setMode", &AntiAliasing::setMode);
658 aa.addFunc("getMode", &AntiAliasing::getMode);
659 aa.addFunc("hasParam", &AntiAliasing::hasParam);
660 aa.addFunc("setFloat", &AntiAliasing::setFloat);
661 aa.addFunc("getFloat", &AntiAliasing::getFloat);
662 aa.addFunc("suggestScale", &AntiAliasing::suggestScale);
663 aa.addFunc("resolutionFor", &AntiAliasing::resolutionFor);
664 aa.addFunc("apply", &AntiAliasing::apply);
665 aa.addFunc("applyTo", &AntiAliasing::applyTo);
666 aa.addFunc("applyCanvas", &AntiAliasing::applyCanvas);
667 aa.addFunc("applyCanvasTo", &AntiAliasing::applyCanvasTo);
668 aa.addFunc("getShader", &AntiAliasing::getShader);
669 aa.addFunc("getFxaaShader", &AntiAliasing::getFxaaShader);
670 aa.addFunc("getSmaaShader", &AntiAliasing::getSmaaShader);
671 aa.addFunc("getSsaaShader", &AntiAliasing::getSsaaShader);
672 aa.addFunc("getNfaaShader", &AntiAliasing::getNfaaShader);
673}
674
675void Graphics::expose(ssq::Class& cls) {
676 cls.addFunc("getName", &Graphics::getName);
677 cls.addFunc("reset", &Graphics::reset);
678 cls.addFunc("present", &Graphics::present);
679 cls.addFunc("clear", &Graphics::clearScreen);
680 cls.addFunc("setBackgroundColor", &Graphics::setBackgroundColorRGBA);
681 cls.addFunc("drawSolidRect", &Graphics::drawSolidRectRGBA);
682 cls.addFunc("drawTexturedRect", &Graphics::drawTexturedRectRGBA);
683 cls.addFunc("newTextureFromFile", &Graphics::newTextureFromFile);
684 cls.addFunc("newTexture",
685 static_cast<Texture* (Graphics::*)(image::ImageData*, bool, bool)>(&Graphics::newTextureFromImageData));
686 cls.addFunc("newTextureFromFile", &Graphics::newTextureFromFile);
687 cls.addFunc("newTextureFromFileRepeated", &Graphics::newTextureFromFileRepeated);
688 cls.addFunc("newTextureWithSampler", &Graphics::newTextureWithSampler);
689 cls.addFunc("setTextureSampler", &Graphics::setTextureSamplerParams);
690 cls.addFunc("getMaxAnisotropy", &Graphics::getMaxAnisotropy);
691 cls.addFunc("newMeshSphere", &Graphics::newMeshSphere);
692 cls.addFunc("newMeshCylinder", &Graphics::newMeshCylinder);
693 cls.addFunc("newMeshCube", &Graphics::newMeshCube);
694 cls.addFunc("newMeshFromArrays",
695 std::function<Mesh *(Graphics *, ssq::Array, ssq::Array, ssq::Array, int,
696 ssq::Array, int)>(newMeshFromArraysScript));
697 cls.addFunc("updateMeshVertices",
698 std::function<bool(Graphics *, Mesh *, ssq::Array, ssq::Array, ssq::Array,
699 int, ssq::Array, int)>(updateMeshVerticesScript));
700 cls.addFunc("bakeMeshMorph", &Graphics::bakeMeshMorph);
701 cls.addFunc("newShader", static_cast<Shader* (Graphics::*)(const std::string&)>(&Graphics::newShader));
702 cls.addFunc("newMeshShader", static_cast<Shader* (Graphics::*)(const std::string&)>(&Graphics::newMeshShader));
703 cls.addFunc("newHairShader", &Graphics::newHairShader);
704 cls.addFunc("newGrassShader", &Graphics::newGrassShader);
705 cls.addFunc("newGrassField", &Graphics::newGrassField);
706 cls.addFunc("newWaterfall", &Graphics::newWaterfall);
707 cls.addFunc("newWater", &Graphics::newWater);
708 cls.addFunc("newShaderFromSpvFile",
709 static_cast<Shader* (Graphics::*)(const std::string&)>(&Graphics::newShaderFromSpvFile));
710 cls.addFunc("setShader", static_cast<void (Graphics::*)(Shader*)>(&Graphics::setShader));
711 cls.addFunc("getShader", &Graphics::getShader);
712 cls.addFunc("render3D", &Graphics::render3D);
713 cls.addFunc("renderScene3DToCanvas", &Graphics::renderScene3DToCanvas);
714 cls.addFunc("saveFramePng", &Graphics::saveFramePng);
715 cls.addFunc("drawScene3D", &Graphics::drawScene3D);
716 cls.addFunc("drawCanvas", &Graphics::drawCanvas);
717 cls.addFunc("newCanvas", &Graphics::newCanvas);
718 cls.addFunc("setCanvas", static_cast<void (Graphics::*)(Canvas*)>(&Graphics::setCanvas));
719 cls.addFunc("getCanvas", &Graphics::getCanvas);
720 cls.addFunc("getWidth", &Graphics::getWidth);
721 cls.addFunc("getHeight", &Graphics::getHeight);
722 cls.addFunc("setDirectionalLight", &Graphics::setDirectionalLight);
723 cls.addFunc("newMaterial", &Graphics::newMaterial);
724 cls.addFunc("getRenderControl", &Graphics::getRenderControl);
725 cls.addFunc("setMsaaSamples", &Graphics::setMsaaSamples);
726 cls.addFunc("getMsaaSamples", &Graphics::getMsaaSamples);
727 cls.addFunc("getSceneColorTexture", &Graphics::getSceneColorTexture);
728 cls.addFunc("newQuad", &Graphics::newQuad);
729 cls.addFunc("newVolumetric", &Graphics::newVolumetric);
730 cls.addFunc("newAmbientOcclusion", &Graphics::newAmbientOcclusion);
731 cls.addFunc("newOutline", &Graphics::newOutline);
732 cls.addFunc("getOutline", &Graphics::pipelineOutline);
733 cls.addFunc("newGlobalIllumination", &Graphics::newGlobalIllumination);
734 cls.addFunc("newScreenSpaceReflection", &Graphics::newScreenSpaceReflection);
735 cls.addFunc("newAntiAliasing", &Graphics::newAntiAliasing);
736 cls.addFunc("drawOcclusionSolid", &Graphics::drawOcclusionSolid);
737 cls.addFunc("drawOcclusionTexture", &Graphics::drawOcclusionTexture);
738}
739
741 currentShader = nullptr;
742 currentFont = nullptr;
743}
744
746
748
750
752
753Outline* Graphics::newOutline() { return new Outline(this); }
754
756
758
760 if (!pipelineAO_) pipelineAO_ = std::make_unique<AmbientOcclusion>(this);
761 return pipelineAO_.get();
762}
763
765 if (!pipelineGI_) pipelineGI_ = std::make_unique<GlobalIllumination>(this);
766 return pipelineGI_.get();
767}
768
770 if (!pipelineAA_) pipelineAA_ = std::make_unique<AntiAliasing>(this);
771 return pipelineAA_.get();
772}
773
775 if (!pipelineOutline_) pipelineOutline_ = std::make_unique<Outline>(this);
776 return pipelineOutline_.get();
777}
778
780
782
784
786
788Water* Graphics::newWater() { return new Water(this); }
789
791 const float h = size * 0.5f;
792 // 6 faces x 4 corners (per-face normal + full 0..1 UV), outward CCW for RH Y-up.
793 const float kFaces[6][4][3] = {
794 {{-h, -h, h}, {h, -h, h}, {h, h, h}, {-h, h, h}}, // +Z
795 {{h, -h, -h}, {-h, -h, -h}, {-h, h, -h}, {h, h, -h}}, // -Z
796 {{h, -h, h}, {h, -h, -h}, {h, h, -h}, {h, h, h}}, // +X
797 {{-h, -h, -h}, {-h, -h, h}, {-h, h, h}, {-h, h, -h}}, // -X
798 {{-h, h, h}, {h, h, h}, {h, h, -h}, {-h, h, -h}}, // +Y
799 {{-h, -h, -h}, {h, -h, -h}, {h, -h, h}, {-h, -h, h}}, // -Y
800 };
801 const float kN[6][3] = {{0, 0, 1}, {0, 0, -1}, {1, 0, 0}, {-1, 0, 0}, {0, 1, 0}, {0, -1, 0}};
802 const float kUV[4][2] = {{0, 0}, {1, 0}, {1, 1}, {0, 1}};
803
804 std::vector<float> pos, nrm, uv;
805 pos.reserve(6 * 4 * 3);
806 nrm.reserve(6 * 4 * 3);
807 uv.reserve(6 * 4 * 2);
808 std::vector<uint32_t> indices;
809 indices.reserve(6 * 6);
810 for (int f = 0; f < 6; ++f) {
811 const uint32_t base = uint32_t(f * 4);
812 for (int c = 0; c < 4; ++c) {
813 pos.insert(pos.end(), kFaces[f][c], kFaces[f][c] + 3);
814 nrm.insert(nrm.end(), kN[f], kN[f] + 3);
815 uv.insert(uv.end(), kUV[c], kUV[c] + 2);
816 }
817 indices.push_back(base + 0);
818 indices.push_back(base + 1);
819 indices.push_back(base + 2);
820 indices.push_back(base + 0);
821 indices.push_back(base + 2);
822 indices.push_back(base + 3);
823 }
824 return newMeshFromArrays(pos.data(), nrm.data(), uv.data(), int(pos.size() / 3), indices.data(),
825 int(indices.size()));
826}
827
828bool Graphics::saveFramePng(const std::string& path) {
830 std::unique_ptr<eve::image::ImageData> frame;
831 try {
832 frame.reset(newImageData());
833 } catch (...) {
834 return false; // no presented frame yet
835 }
836 if (!frame) return false;
837 std::unique_ptr<eve::filesystem::FileData> png(
838 frame->encode(medialoader::FormatHandler::ENCODED_PNG, path.c_str(), false));
839 if (!png) return false;
840 std::error_code ec;
841 std::filesystem::create_directories(std::filesystem::path(path).parent_path(), ec);
842 std::ofstream out(path, std::ios::binary);
843 if (!out.good()) return false;
844 out.write(static_cast<const char*>(png->getData()), static_cast<std::streamsize>(png->getSize()));
845 return out.good();
846}
847
848void Graphics::draw(Drawable* drawable, const glm::mat4& m) {
849 if (drawable) drawable->draw(this, m);
850}
851
852void Graphics::drawOcclusion(Drawable* drawable, const glm::mat4& m) {
853 if (drawable && drawable->getCastOcclusion()) drawable->drawOcclusion(this, m);
854}
855
856void Graphics::drawOcclusionSolid(float x, float y, float w, float h) {
857 drawSolidRect(x, y, w, h, Color(0.f, 0.f, 0.f, 1.f));
858}
859
860void Graphics::drawOcclusionTexture(Texture* texture, float x, float y, float w, float h) {
861 // Black RGB keeps silhouette; texture alpha cuts soft edges (same idea as shadow masks).
862 drawTexturedRect(texture, x, y, w, h, Color(0.f, 0.f, 0.f, 1.f));
863}
864
865void Graphics::clearScreen() { clear(std::nullopt, std::nullopt, std::nullopt); }
866
867void Graphics::setBackgroundColorRGBA(float r, float g, float b, float a) { setBackgroundColor(Color(r, g, b, a)); }
868
869void Graphics::drawSolidRectRGBA(float x, float y, float w, float h, float r, float g, float b, float a) {
870 drawSolidRect(x, y, w, h, Color(r, g, b, a));
871}
872
873void Graphics::drawTexturedRectRGBA(Texture* texture, float x, float y, float w, float h, float r, float g, float b,
874 float a) {
875 drawTexturedRect(texture, x, y, w, h, Color(r, g, b, a));
876}
877
879 if (!data) throw eve::Exception("newTextureFromImageData: null ImageData");
880 if (data->getFormat() != "RGBA8") throw eve::Exception("newTextureFromImageData: only RGBA8 supported");
882 info.sampler.repeatU = repeatU;
883 info.sampler.repeatV = repeatV;
884 return newTexture(data->getWidth(), data->getHeight(), static_cast<const uint8_t*>(data->getData()), info);
885}
886
888 if (!data) throw eve::Exception("newTextureFromImageData: null ImageData");
889 if (data->getFormat() != "RGBA8") throw eve::Exception("newTextureFromImageData: only RGBA8 supported");
890 return newTexture(data->getWidth(), data->getHeight(), static_cast<const uint8_t*>(data->getData()), info);
891}
892
893Texture* Graphics::newTextureFromFileRepeated(const std::string& filename, bool repeatU, bool repeatV) {
894 if (filename.empty()) throw eve::Exception("newTextureFromFileRepeated: empty filename");
895 auto* fs = eve::filesystem::Filesystem::create();
896 std::unique_ptr<eve::filesystem::FileData> fileData(fs->read(filename));
897 if (!fileData) throw eve::Exception("newTextureFromFileRepeated: failed to read '%s'", filename.c_str());
898 auto* imgMod = eve::image::Image::create();
899 std::unique_ptr<eve::image::ImageData> data(imgMod->newImageData(fileData.get()));
901}
902
904 float maxAnisotropy, const std::string& filter, const std::string& mipmap,
905 float lodBias) {
907 info.generateMipmaps = generateMipmaps;
909 info.sampler.mag = info.sampler.min;
911 if (generateMipmaps && info.sampler.mipmap == MipmapMode::Disabled) info.sampler.mipmap = MipmapMode::Linear;
912 info.sampler.repeatU = repeatU;
913 info.sampler.repeatV = repeatV;
914 info.sampler.maxAnisotropy = maxAnisotropy;
915 info.sampler.lodBias = lodBias;
916 return newTextureFromImageData(data, info);
917}
918
919void Graphics::setTextureSamplerParams(Texture* texture, const std::string& filter, const std::string& mipmap,
920 float maxAnisotropy, float lodBias) {
921 if (!texture) return;
922 TextureSampler s = texture->getSampler();
924 s.mag = s.min;
926 s.maxAnisotropy = maxAnisotropy;
927 s.lodBias = lodBias;
928 setTextureSampler(texture, s);
929}
930
931Quad* Graphics::newQuad(int x, int y, int w, int h) { return new Quad(x, y, w, h); }
932
933#ifndef EVENGINE_WEBGPU
934Font* Graphics::newFont(font::FontData* data, std::string charset) { return new Font(this, data, std::move(charset)); }
935
936void Graphics::print(const std::string& text, float x, float y, const Color& color, float scale) {
937 if (currentFont == nullptr) {
938 eve::debug::rtDraw("print", "no-font");
939 throw eve::Exception("Graphics::print: no font set (call setFont first)");
940 }
941 eve::debug::rtBind("font", "current");
942 eve::debug::rtDraw("print", text.empty() ? "" : "text");
943
945 float penX = x;
946 float baseline = y + currentFont->getBaseline() * scale;
947 int prevCodepoint = -1;
948
949 size_t i = 0;
950 while (i < text.size()) {
951 uint32_t cp = nextCodepointUtf8(text, i);
952 if (cp == 0) continue;
953 int code = static_cast<int>(cp);
954
955 if (prevCodepoint >= 0) penX += data->getKerning(prevCodepoint, code) * scale;
956
957 if (const Font::Glyph* g = currentFont->findGlyph(code)) {
958 if (g->width > 0 && g->height > 0) {
959 float gx = penX + static_cast<float>(g->bearingX) * scale;
960 float gy = baseline - static_cast<float>(g->bearingY) * scale;
961 drawTexturedRectUV(currentFont->getTexture(), gx, gy, static_cast<float>(g->width) * scale,
962 static_cast<float>(g->height) * scale, g->u0, g->v0, g->u1, g->v1, color);
963 }
964 penX += static_cast<float>(g->advance) * scale;
965 } else {
966 // Not pre-rasterized into this Font's atlas — still advance the pen.
967 penX += static_cast<float>(data->getGlyphAdvance(code)) * scale;
968 }
969
970 prevCodepoint = code;
971 }
972}
973#endif // !EVENGINE_WEBGPU
974
975} // namespace eve::graphics
HSQOBJECT cls
Definition ECS.cpp:21
int y
Definition Grass.cpp:135
int x
Definition Grass.cpp:135
glm::vec3 n
Definition Grass.cpp:64
int h
int w
uint32_t a
uint32_t b
uint32_t c
#define Module_IMPL(ModuleName, newExpr)
Definition Module.h:24
int idx
float f
Mesh * mesh
Shader * shader
Material * material
Light2D::Data * data
const char * name
Definition RockMesh.cpp:21
bool repeatV
std::string filter
std::string mipmap
bool repeatU
image::ImageData::Colorf color
float scale
Definition TreeMesh.cpp:122
float m[16]
uint32_t s
Definition Weather.cpp:28
virtual std::string getName() const =0
CPU-side decoded font face (FreeType FT_Face + owned font bytes). Does not upload to GPU — rasterize ...
Definition FontData.h:23
Screen-space ambient occlusion.
void applyFromDepthTo(Graphics *gfx, Texture *linearDepth, Canvas *dest)
void applyFromDepth(Graphics *gfx, Texture *hwDepth)
One-pass SSAO overlay for the 3D swapchain path. Samples hardware D32 (Vulkan NDC z in ....
int resolutionFor(int fullSize) const
Downscale helper: returns floor(dim / downscale), at least 1. Callers create AO canvases at this size...
void setFloat(const std::string &name, float value)
void computeTo(Graphics *gfx, Texture *linearDepth, Canvas *dest)
void setCamera(float eyeX, float eyeY, float eyeZ, float targetX, float targetY, float targetZ, float upX, float upY, float upZ, float fovYDeg, float aspect, float nearZ, float farZ)
Camera for depth reconstruction (RH + ZO). Builds inv(viewProj) and near/far used by compute*.
void setMode(const std::string &mode)
"ssao" | "hbao" | "gtao".
void blurTo(Graphics *gfx, Texture *aoMap, Canvas *dest)
bool hasParam(const std::string &name) const
void applyFromGBuffer(Graphics *gfx, Texture *hwDepth, Texture *worldNormal)
float getFloat(const std::string &name) const
void setQuality(const std::string &quality)
"low" | "medium" | "high" (unknown → medium).
void compute(Graphics *gfx, Texture *linearDepth)
Compute AO into the currently bound canvas / screen. Output RGB = AO (1=open), A = depth01.
void blur(Graphics *gfx, Texture *aoMap)
Bilateral blur of an AO map (RGB=AO, A=depth).
void applyOverlayTo(Graphics *gfx, Texture *aoMap, Canvas *dest)
void applyOverlay(Graphics *gfx, Texture *aoMap)
Darken the current target with AO: black + alpha=(1-ao)*intensity. Draw over an already-rendered scen...
Classic image-space anti-aliasing.
bool hasParam(const std::string &name) const
void apply(Graphics *gfx, Texture *source)
Apply current mode to source, writing into the currently bound canvas / screen. Uploads texelW/texelH...
Shader * getSmaaShader() const
Shader * getNfaaShader() const
void setMode(const std::string &mode)
"fxaa" | "smaa" | "ssaa" | "nfaa" (unknown → fxaa).
Shader * getSsaaShader() const
void prepareSource(Texture *source)
Upload texel uniforms from source without drawing (3D scene-color resolve).
std::string getQuality() const
float suggestScale() const
Suggested supersample scale for the active quality when using "ssaa" (2 for low/medium,...
void applyTo(Graphics *gfx, Texture *source, Canvas *dest)
float getFloat(const std::string &name) const
Shader * getFxaaShader() const
void setFloat(const std::string &name, float value)
void applyCanvas(Graphics *gfx, Canvas *source)
int resolutionFor(int destSize) const
void applyCanvasTo(Graphics *gfx, Canvas *source, Canvas *dest)
void setQuality(const std::string &quality)
"low" | "medium" | "high" (unknown → medium).
std::string getMode() const
float screenToWorldY(float screenX, float screenY, float viewW, float viewH)
float worldToScreenY(float worldX, float worldY, float viewW, float viewH)
float worldToScreenX(float worldX, float worldY, float viewW, float viewH)
float screenToWorldX(float screenX, float screenY, float viewW, float viewH)
Convert screen pixel (origin top-left of viewport) to world coordinates. viewW/viewH are the current ...
void setZoom(float zoom)
void setAmbient(float r, float g, float b)
void setPosition(float x, float y)
World-space look-at center and zoom (1 = identity).
static Camera2D * createCamera()
void setUp(float x, float y, float z)
void setFov(float fovYDeg)
void screenToRay(float screenX, float screenY, float viewW, float viewH)
Build a world-space picking ray from a screen pixel. Stores origin (camera eye) and normalized direct...
void setEnvIntensity(float intensity)
static Camera3D * createCamera()
void setTarget(float x, float y, float z)
void setAmbient(float r, float g, float b)
void setActive(bool active)
void setEye(float x, float y, float z)
void setEnvMap(Texture *cube)
Specular IBL cubemap (Graphics::newCubemap). nullptr disables IBL.
virtual int getWidth() const =0
virtual image::ImageData * newImageData()=0
virtual void clear(std::optional< Color > color, std::optional< int > stencil, std::optional< double > depth)=0
virtual Texture * getTexture()=0
Sampleable color buffer; screen Canvas returns nullptr.
virtual int getHeight() const =0
Drawable base (textures, meshes, canvases).
Definition Drawable.h:17
virtual void drawOcclusion(Graphics *gfx, const glm::mat4 &matrix) const
Draw as an opaque black silhouette for volumetric occlusion maps (screen-space god rays / light shaft...
Definition Drawable.h:35
virtual void draw(Graphics *gfx, const glm::mat4 &matrix) const =0
Draws the object with the specified transformation matrix.
bool getCastOcclusion() const
When false, skipped by Graphics::drawOcclusion / volumetric occluder passes.
Definition Drawable.h:27
void setCastOcclusion(bool cast)
Definition Drawable.h:28
GPU-side font: wraps a decoded font::FontData and rasterizes a fixed set of codepoints into a single ...
Definition Font.h:32
font::FontData * getData() const
Definition Font.h:43
Texture * getTexture() const
Definition Font.h:44
float getBaseline() const
Distance from the top of a line to the baseline (== getAscent()).
Definition Font.cpp:174
const Glyph * findGlyph(int codepoint) const
Returns nullptr if codepoint isn't in this Font's atlas.
Definition Font.cpp:180
int getWidth() const
Definition GBuffer.h:36
Texture * getBuffer(const std::string &name) const
Definition GBuffer.cpp:17
int getHeight() const
Definition GBuffer.h:37
bool hasBuffer(const std::string &name) const
"depth" | "hwDepth" | "normal" | "albedo"
Definition GBuffer.cpp:9
Texture * getAlbedoTexture() const
Definition GBuffer.h:42
Texture * getNormalTexture() const
Definition GBuffer.h:41
Texture * getDepthTexture() const
Definition GBuffer.h:39
Texture * getHwDepthTexture() const
Definition GBuffer.h:40
bool isValid() const
Definition GBuffer.cpp:5
Screen-space single-bounce GI (SSGI).
void applyFromDepth(Graphics *gfx, Texture *packedAlbedo)
Overlay bounced light onto the currently bound canvas / screen. Packed path (tests): RGB=albedo/lit,...
void applyFromScene(Graphics *gfx, Texture *color, Texture *hwDepth)
bool hasParam(const std::string &name) const
void setLightDirection(float dx, float dy, float dz)
void setQuality(const std::string &quality)
"low" | "medium" | "high" (unknown → medium).
void setCamera(float eyeX, float eyeY, float eyeZ, float targetX, float targetY, float targetZ, float upX, float upY, float upZ, float fovYDeg, float aspect, float nearZ, float farZ)
Camera for depth reconstruction (RH + ZO). Builds inv(viewProj) and near/far used by applyFromDepth.
void setFloat(const std::string &name, float value)
void setLightColor(float r, float g, float b)
void applyFromDepthTo(Graphics *gfx, Texture *packedAlbedo, Canvas *dest)
float getFloat(const std::string &name) const
virtual void reset()
Resets the current color, background color, line style, and so forth.
Definition Graphics.cpp:740
virtual void setTextureSamplerParams(Texture *texture, const std::string &filter, const std::string &mipmap, float maxAnisotropy, float lodBias)
Update sampler state without re-uploading pixels (filter / mip / aniso / LOD bias).
Definition Graphics.cpp:919
virtual void draw(Drawable *drawable, const glm::mat4 &m)
Definition Graphics.cpp:848
Volumetric * newVolumetric()
Volumetric light + fog (screenspace / raymarch / fog). Caller owns Volumetric*; its Shaders are owned...
Definition Graphics.cpp:749
void drawCanvas(Canvas *canvas, float x, float y, float w, float h)
Definition Graphics.h:355
virtual void setDirectionalLight(float dx, float dy, float dz, float r=1.f, float g=1.f, float b=1.f)
Definition Graphics.cpp:167
std::unique_ptr< AntiAliasing > pipelineAA_
Definition Graphics.h:993
virtual void setShader()
Definition Graphics.cpp:747
void setBackgroundColor(const Color &c)
Definition Graphics.h:585
virtual Mesh * newMeshCylinder(int slices=32, int stacks=1, bool caps=true)=0
Procedural Y-up cylinder (radius 1, height 2 centered at origin). slices = longitude divisions; stack...
std::unique_ptr< Outline > pipelineOutline_
Definition Graphics.h:994
Shader * newHairShader()
Built-in hair shader with default anisotropic parameters.
Definition Graphics.cpp:781
Texture * newTextureWithSampler(image::ImageData *data, bool repeatU, bool repeatV, bool generateMipmaps, float maxAnisotropy, const std::string &filter, const std::string &mipmap, float lodBias=0.f)
Script-friendly texture create: filter = "linear"|"nearest", mipmap = "none"|"linear"|"nearest"....
Definition Graphics.cpp:903
virtual void drawOcclusionTexture(Texture *texture, float x, float y, float w, float h)
Definition Graphics.cpp:860
virtual void setBackgroundColorRGBA(float r, float g, float b, float a=1.f)
Definition Graphics.cpp:867
GrassField * newGrassField()
Dense + sparse stylized grass field. Caller owns GrassField*; its Mesh / Shader / Texture are owned b...
Definition Graphics.cpp:785
AmbientOcclusion * newAmbientOcclusion()
Screen-space ambient occlusion (ssao / hbao / gtao). Caller owns AmbientOcclusion*; its Shaders are o...
Definition Graphics.cpp:751
Quad * newQuad(int x, int y, int w, int h)
Pixel-space atlas rect. Caller owns Quad* (not tracked by Graphics).
Definition Graphics.cpp:931
virtual Shader * newMeshShader(const std::string &vertGlsl, const std::string &fragGlsl)=0
virtual void setMsaaSamples(int samples)
Hardware MSAA sample count for the 3D scene color pass (0 disables, then 2/4/8 are used when the devi...
Definition Graphics.h:612
bool recordingEngine3D_
True while RenderSystem3D is submitting (AO / engine overlays).
Definition Graphics.h:980
Waterfall * newWaterfall()
Flowing waterfall (falling water sheet) with sky reflection, downward velocity streaks and animated f...
Definition Graphics.cpp:787
GlobalIllumination * pipelineGlobalIllumination()
Definition Graphics.cpp:764
Shader * newGrassShader()
t3ssel8r-style grass billboard shader (alpha test + shadow two-tone). Owned by Graphics....
Definition Graphics.cpp:783
bool saveFramePng(const std::string &path)
Save the last presented frame to a PNG at path. Enables screen readback if needed....
Definition Graphics.cpp:828
Outline * newOutline()
Screen-space model outline (t3ssel8r-style) from GBuffer depth + normal. Caller owns Outline*; its Sh...
Definition Graphics.cpp:753
virtual void drawScene3DRGBA(float x, float y, float w, float h, float r=1.f, float g=1.f, float b=1.f, float a=1.f)
Composite this frame's 3D scene color into a rect (screen or active Canvas). virtual * Call after ren...
Definition Graphics.cpp:147
virtual void renderScene3DToCanvas(Canvas *canvas, Camera3D *camera)
Definition Graphics.cpp:127
virtual Canvas * getCanvas() const =0
Shader * prepareSceneColorResolveShader(Texture *scene)
FXAA resolve shader that writes opaque RGB (ignores scene-color depth alpha).
Definition Graphics.cpp:131
Mesh * newMeshCube(float size=1.f)
Procedural cube (edge length size, centered at origin, outward CCW for RH Y-up), with per-face normal...
Definition Graphics.cpp:790
virtual void popValidationScope()=0
virtual void drawTexturedRectRGBA(Texture *texture, float x, float y, float w, float h, float r, float g, float b, float a=1.f)
Definition Graphics.cpp:873
virtual void pushValidationScope()=0
Backend hooks so the platform-independent render3D() can wrap its work in a GPU validation error scop...
virtual Shader * newShader(const std::string &vertGlsl, const std::string &fragGlsl)=0
Compile GLSL source with glslc (must be on PATH). Empty vertGlsl → default textured vert....
virtual void drawCanvasRGBA(Canvas *canvas, float x, float y, float w, float h, float r=1.f, float g=1.f, float b=1.f, float a=1.f)
Draw a Canvas color buffer as a textured rect (same batch order as other 2D).
Definition Graphics.cpp:160
virtual Texture * newTexture(int width, int height, const uint8_t *rgba, bool repeatU=false, bool repeatV=false)=0
Outline * pipelineOutline()
Pipeline-owned Outline used by RenderSystem3D when the "outline" feature is on.
Definition Graphics.cpp:774
Font * newFont(font::FontData *data, std::string charset=Font::defaultCharset())
Build a GPU font (glyph atlas texture) from decoded font data. Rasterizes charset (UTF-8,...
Definition Graphics.cpp:934
Material * newMaterial()
Create a Material asset (shading model + textures + PBR knobs). Caller owns Material*; not tracked by...
Definition Graphics.cpp:171
AntiAliasing * newAntiAliasing()
Classic image-space AA (FXAA / SMAA / SSAA / NFAA). Caller owns AntiAliasing*; its Shaders are owned ...
Definition Graphics.cpp:779
Texture * newTextureFromImageData(image::ImageData *data, bool repeatU=false, bool repeatV=false)
Definition Graphics.cpp:878
virtual void print(const std::string &text, float x, float y, const Color &color=Color(1.f, 1.f, 1.f, 1.f), float scale=1.f)
Draws UTF-8 text with the current font (see setFont), baseline-aligned so that (x,...
Definition Graphics.cpp:936
virtual float getMaxAnisotropy() const =0
Device max supported anisotropy (1 if unsupported). Valid after initWithWindow.
std::unique_ptr< RenderControl > renderControl_
Definition Graphics.h:990
virtual Texture * newTextureFromFile(const std::string &filename)=0
virtual void drawTexturedRectUV(Texture *texture, float x, float y, float w, float h, float u0, float v0, float u1, float v1, const Color &color)=0
Draw a textured sub-rect (atlas / tile UVs). texture may be null → solid.
virtual int getMsaaSamples() const
Definition Graphics.h:613
virtual void present()=0
virtual void drawOcclusionSolid(float x, float y, float w, float h)
Definition Graphics.cpp:856
AntiAliasing * pipelineAntiAliasing()
Definition Graphics.cpp:769
AmbientOcclusion * pipelineAmbientOcclusion()
Pipeline-owned AO / GI / AA used by RenderSystem3D when features "ao" / "gi" / "aa" are enabled....
Definition Graphics.cpp:759
virtual void render3D()
Run RenderSystem3D (begin3DFrame + draw visible Renderable3D).
Definition Graphics.cpp:117
virtual bool bakeMeshMorph(Mesh *mesh)=0
If mesh morph weights are dirty, bake blended positions and upload to the GPU VBO....
Shader * getShader() const
Definition Graphics.h:703
Texture * newTextureFromFileRepeated(const std::string &filename, bool repeatU, bool repeatV)
Definition Graphics.cpp:893
ScreenSpaceReflection * newScreenSpaceReflection()
Screen-space reflections (ray-marched over scene color + hw depth). Caller owns ScreenSpaceReflection...
Definition Graphics.cpp:757
std::unique_ptr< GlobalIllumination > pipelineGI_
Definition Graphics.h:992
std::unique_ptr< AmbientOcclusion > pipelineAO_
Definition Graphics.h:991
virtual void setTextureSampler(Texture *texture, const TextureSampler &sampler)=0
Recreate the sampler for an existing texture (keeps image / mip chain). No-op when texture is null or...
virtual void drawTexturedRect(Texture *texture, float x, float y, float w, float h, const Color &color)=0
void drawScene3D(float x, float y, float w, float h)
Script-friendly 4-arg form (simplesquirrel does not apply C++ defaults).
Definition Graphics.h:348
virtual Texture * getSceneColorTexture()
Sampleable 3D color target for the current frame (RGB = lit, A = linear depth). Valid after begin3DFr...
Definition Graphics.h:432
virtual void drawSolidRectRGBA(float x, float y, float w, float h, float r, float g, float b, float a=1.f)
Definition Graphics.cpp:869
virtual void drawOcclusion(Drawable *drawable, const glm::mat4 &m)
Volumetric occlusion helpers (shadow-pass analogue for light shafts). drawOcclusion skips drawables w...
Definition Graphics.cpp:852
RenderControl * getRenderControl()
Shared compilable 3D render control (features → pass list + GBuffer). Owned by Graphics; valid for th...
Definition Graphics.cpp:173
virtual Mesh * newMeshFromArrays(const float *posXYZ, const float *nrmXYZ, const float *uvST, int vertexCount, const uint32_t *indices, int indexCount)=0
Upload a triangle mesh from packed CPU arrays. Owned by Graphics. posXYZ required (vertexCount*3)....
virtual void clearScreen()
Script-friendly wrappers (r,g,b[,a] floats — no Color type in Squirrel).
Definition Graphics.cpp:865
virtual void drawSolidRect(float x, float y, float w, float h, const Color &color, BlendMode blend=BlendMode::Alpha)=0
Internal immediate-mode helper used by RenderSystem / Batcher.
Water * newWater()
Dynamic water surface (sky reflection + animated edge waves + middle drop ripples)....
Definition Graphics.cpp:788
virtual Canvas * newCanvas(int width, int height)=0
Create an offscreen render target (sampleable). Owned by Graphics.
virtual void setScreenReadbackEnabled(bool enabled)
When true, each present copies the swapchain to a CPU buffer for getPixel/newImageData....
Definition Graphics.h:591
virtual Mesh * newMeshSphere(int slices=32, int stacks=16)=0
Procedural UV sphere (radius 1, Y-up). Owned by Graphics. slices = longitude divisions,...
GlobalIllumination * newGlobalIllumination()
Screen-space single-bounce GI. Caller owns GlobalIllumination*; its Shaders are owned by Graphics.
Definition Graphics.cpp:755
int getHeight() const
Definition Graphics.h:118
virtual Shader * newShaderFromSpvFile(const std::string &vertPath, const std::string &fragPath)=0
Load SPIR-V from files via Filesystem (empty vertPath → default textured vert).
virtual void drawTexturedRectShader(Texture *texture, Shader *shader, float x, float y, float w, float h, const Color &color)=0
Draw with an explicit Shader (nullptr = default textured pipeline).
Dense grass + sparse dark tufts on a mesh. Caller owns GrassField*; GPU Mesh / Shader / Texture are o...
Definition Grass.h:124
void setFrameDuration(float seconds)
Definition Grass.cpp:752
Shader * getShader() const
Definition Grass.h:166
Mesh * getDenseMesh() const
Definition Grass.h:164
Texture * getAtlas() const
Definition Grass.h:167
Mesh * getSparseMesh() const
Definition Grass.h:165
int getDenseCount() const
Definition Grass.h:169
void bakePlane(float sizeX, float sizeZ, int segX, int segZ)
Definition Grass.cpp:731
void setTime(float seconds)
Definition Grass.cpp:747
float getTime() const
Definition Grass.h:157
void update(float dt)
Definition Grass.cpp:742
int getSparseCount() const
Definition Grass.h:170
float getFrameDuration() const
Definition Grass.h:159
float getVolumetricIntensity()
Definition Light.cpp:59
void setDirection(float dx, float dy)
Definition Light.cpp:31
void setPosition(float x, float y)
Definition Light.cpp:23
void setColor(float r, float g, float b, float intensity=1.f)
Definition Light.cpp:39
void setVolumetric(bool enabled)
Definition Light.cpp:53
void setCanvas(Canvas *canvas)
Definition Light.cpp:61
void setVolumetricIntensity(float intensity)
Definition Light.cpp:56
void setType(const std::string &type)
Definition Light.cpp:13
void setEnabled(bool enabled)
Definition Light.cpp:50
std::string getType()
Definition Light.cpp:21
static Light2D * createLight(const std::string &type="point")
Definition Light.cpp:5
void setRadius(float radius)
Definition Light.cpp:47
void setEnabled(bool enabled)
Definition Light.cpp:114
void setCastShadow(bool cast)
Definition Light.cpp:117
void setDirection(float dx, float dy, float dz)
Definition Light.cpp:92
void setShadowBias(float bias)
Definition Light.cpp:120
float getVolumetricIntensity()
Definition Light.cpp:134
float getShadowStrength()
Definition Light.cpp:126
void setShadowStrength(float strength)
Definition Light.cpp:123
void setPosition(float x, float y, float z)
Definition Light.cpp:81
static Light3D * createLight(const std::string &type="point")
Definition Light.cpp:63
void setType(const std::string &type)
Definition Light.cpp:71
void setVolumetricIntensity(float intensity)
Definition Light.cpp:131
void setRadius(float radius)
Definition Light.cpp:111
void setColor(float r, float g, float b, float intensity=1.f)
Definition Light.cpp:103
void setVolumetric(bool enabled)
Definition Light.cpp:128
std::string getType()
Definition Light.cpp:79
Packages shading method + surface parameters into one attachable asset.
Definition Material.h:26
float getFloat(const std::string &name) const
Definition Material.cpp:58
void setNormalTexture(Texture *texture)
Definition Material.h:43
void setAlbedoTexture(Texture *texture)
Definition Material.h:40
bool hasParam(const std::string &name) const
Optional named float knobs (style / custom shader params).
Definition Material.cpp:54
bool getHair() const
Definition Material.h:88
void setCastShadow(bool cast)
Definition Material.h:78
void setCastOcclusion(bool cast)
Definition Material.h:84
void setHeightTexture(Texture *texture)
Definition Material.h:46
float getMetallic() const
Definition Material.h:60
Texture * getAlbedoTexture() const
Definition Material.h:41
void setMetallic(float metallic)
Definition Material.cpp:26
void setReceiveShadow(bool receive)
Definition Material.h:81
Texture * getNormalTexture() const
Definition Material.h:44
float getRoughness() const
Definition Material.h:63
bool getReceiveShadow() const
Definition Material.h:82
void setRoughness(float roughness)
Definition Material.cpp:30
bool getCastOcclusion() const
Definition Material.h:85
void setReceiveLight(bool receive)
Definition Material.h:75
void setShadingModel(const std::string &model)
"pbr" | "unlit" | "hair" | "custom" (unknown → pbr).
Definition Material.cpp:9
void setTexCellBomb(float cellScale, float strength, float rotAmount=1.f)
Definition Material.cpp:34
void setTint(float r, float g, float b, float a=1.f)
Definition Material.cpp:19
Shader * getShader() const
Definition Material.h:51
std::string getShadingModel() const
Definition Material.h:38
void setParallax(float scale, float minLayers=8.f, float maxLayers=32.f)
Definition Material.cpp:40
bool getCastShadow() const
Definition Material.h:79
bool getReceiveLight() const
Definition Material.h:76
void setFloat(const std::string &name, float value)
Definition Material.cpp:56
void setHair(bool hair)
Definition Material.cpp:49
Texture * getHeightTexture() const
Definition Material.h:47
void setShader(Shader *shader)
Optional Mesh3D / hair Shader. nullptr → built-in path for the shading model.
Definition Material.h:50
GPU mesh handle (+ optional CPU morph targets).
Definition Mesh.h:18
bool hasMorphData() const
Definition Mesh.h:67
bool isMorphDirty() const
Definition Mesh.h:65
bool setMorphWeight(const std::string &name, float weight)
Definition Mesh.cpp:116
bool hasMorph(const std::string &name) const
Definition Mesh.cpp:112
float getMorphWeight(const std::string &name) const
Definition Mesh.cpp:128
void clearMorphWeights()
Definition Mesh.cpp:133
int getMorphCount() const
Definition Mesh.cpp:105
std::string getMorphName(int index) const
Definition Mesh.cpp:107
int getVertexCount() const
Definition Mesh.cpp:103
Screen-space model outline (t3ssel8r-style), computed from the GBuffer hardware depth + world-normal ...
Definition Outline.h:31
float getColorG() const
Definition Outline.cpp:68
void setWidth(float width)
Outline thickness in screen pixels (>= 0.5).
Definition Outline.cpp:71
float getDepthSensitivity() const
Definition Outline.cpp:90
void setDepthThreshold(float threshold)
View-space depth discontinuity that starts a depth edge.
Definition Outline.cpp:78
float getDepthThreshold() const
Definition Outline.cpp:83
float getWidth() const
Definition Outline.cpp:76
float getSoftness() const
Definition Outline.cpp:104
void setFloat(const std::string &name, float value)
Definition Outline.cpp:119
void setNormalThreshold(float threshold)
Normal discontinuity (1 - dot(n, nN)) that starts a crease edge.
Definition Outline.cpp:92
void setColor(float r, float g, float b)
Definition Outline.cpp:56
void setSoftness(float softness)
Smoothstep band used to fade edges (0 = hard, 1 = soft).
Definition Outline.cpp:99
float getColorB() const
Definition Outline.cpp:69
bool hasParam(const std::string &name) const
Definition Outline.cpp:115
void setDepthSensitivity(float sensitivity)
Extra per-unit-distance depth tolerance (keeps outlines distance-consistent).
Definition Outline.cpp:85
float getFloat(const std::string &name) const
Definition Outline.cpp:124
void setClip(float nearZ, float farZ)
Near/far used to linearize the hardware depth.
Definition Outline.cpp:106
bool apply(Graphics *gfx, Texture *hwDepth, Texture *worldNormal)
Draw the outline over the currently bound canvas / screen. hwDepth is the D32 GBuffer (Vulkan NDC z),...
Definition Outline.cpp:143
Shader * getShader() const
Definition Outline.h:80
float getNormalThreshold() const
Definition Outline.cpp:97
float getColorR() const
Definition Outline.cpp:67
bool applyTo(Graphics *gfx, Texture *hwDepth, Texture *worldNormal, Canvas *dest)
Definition Outline.cpp:159
Pixel-space sub-rectangle of a Texture (atlas cell / sprite frame). UV conversion uses the texture's ...
Definition Quad.h:9
int getWidth() const
Definition Quad.h:18
int getX() const
Definition Quad.h:16
int getHeight() const
Definition Quad.h:19
int getY() const
Definition Quad.h:17
void setViewport(int x, int y, int w, int h)
Definition Quad.cpp:11
Declarative, compilable 3D render control.
void compile()
Rebuild the executable pass list from current feature flags.
void enable(const std::string &feature)
void disable(const std::string &feature)
bool isEnabled(const std::string &feature) const
bool hasPass(const std::string &name) const
std::string getPassName(int index) const
Pass names: "shadow" | "gbuffer" | "forward" | "hair"
bool supports(const std::string &feature) const
static void setDirectionalLight(float dx, float dy, float dz, float r, float g, float b)
Legacy single directional light used when no enabled Light3D exists.
static void renderToCanvas(Graphics &gfx, Canvas *target, Camera3D *camera)
static void render(Graphics &gfx)
void setNormalTexture(Texture *texture)
void setCamera(Camera3D *camera)
int getMeshLodLevelAtDistance(float distance)
std::string getPartName(int index)
Material * getPartMaterial(int index)
void setRotation(float yaw, float pitch, float roll)
void setHeightTexture(Texture *texture)
Height map for parallax (R channel; white = raised). nullptr disables sampling.
void setPart(int index, const std::string &name, Mesh *mesh, Material *material)
Bind a named mesh+material part (e.g. Assimp submesh / body region). index 0..kMaxParts-1....
void setTexCellBomb(float cellScale, float strength, float rotAmount=1.f)
Texture cell bombing — random per-cell UV offset/rotation blended across a 2×2 neighborhood to hide t...
void setTint(float r, float g, float b, float a=1.f)
void setMetallic(float metallic)
void setTexture(Texture *texture)
void setReceiveLight(bool receive)
void setShader(Shader *shader)
void setMaterial(Material *material)
Attach a Material that packages shading method + surface params.
void setParallax(float scale, float minLayers=8.f, float maxLayers=32.f)
Parallax occlusion mapping. scale 0 disables (default). Typical scale 0.02..0.08. Requires a height t...
void setPosition(float x, float y, float z)
void setMeshLod(int index, Mesh *mesh, float switchDistance=0.f)
Configure geometric LOD. index 0 = highest detail. For index > 0, switchDistance is the camera distan...
void setRoughness(float roughness)
void setScale(float sx, float sy, float sz)
void setReceiveShadow(bool receive)
Screen-space reflections (SSR) as a fullscreen post pass.
void applyFromSceneTo(Graphics *gfx, Texture *sceneColor, Texture *hwDepth, Texture *worldNormal, Canvas *dest)
Write the SSR result into the currently bound canvas / dest.
void setCamera(float eyeX, float eyeY, float eyeZ, float targetX, float targetY, float targetZ, float upX, float upY, float upZ, float fovYDeg, float aspect, float nearZ, float farZ)
Camera for depth reconstruction (RH + ZO). Builds inv(viewProj) + near/far.
void setEnabled(bool enabled)
Enable/disable the pass. When disabled it emits transparent (0 hit).
float getFloat(const std::string &name) const
void setFloat(const std::string &name, float value)
void applyFromScene(Graphics *gfx, Texture *sceneColor, Texture *hwDepth, Texture *worldNormal)
Write SSR into the currently bound canvas / screen.
bool hasParam(const std::string &name) const
Custom GPU program.
Definition Shader.h:30
bool hasUniform(const std::string &name) const
Definition Shader.cpp:46
void sendVec2(const std::string &name, float x, float y)
Definition Shader.cpp:84
int declareVec2(const std::string &name)
Definition Shader.cpp:31
void sendFloat(const std::string &name, float x)
Definition Shader.cpp:82
void sendVec3(const std::string &name, float x, float y, float z)
Definition Shader.cpp:89
int declareMatrix(const std::string &name)
Definition Shader.cpp:34
int getUniformIndex(const std::string &name) const
Definition Shader.cpp:48
int declareVec3(const std::string &name)
Definition Shader.cpp:32
int declareVec4(const std::string &name)
Definition Shader.cpp:33
int declareFloat(const std::string &name)
Reserve sequential float slots in the push-constant block. Returns start index.
Definition Shader.cpp:30
void sendVec4(const std::string &name, float x, float y, float z, float w)
Definition Shader.cpp:94
GPU texture created via Graphics::newTexture. Owns GPU resources through an opaque backend handle.
Definition Texture.h:17
int getMipmapCount() const
Definition Texture.h:30
const TextureSampler & getSampler() const
Definition Texture.h:31
int getWidth() const
Definition Texture.h:26
int getHeight() const
Definition Texture.h:27
Volumetric light + fog.
Definition Volumetric.h:27
void scatter(Graphics *gfx, Texture *occlusion)
Scatter-only: occlusion → shafts with alpha (draw over a prior scene). Writes to the currently bound ...
void scatterTo(Graphics *gfx, Texture *occlusion, Canvas *dest)
Same as scatter but into an explicit destination.
float getFloat(const std::string &name) const
void setFogNoise(float amount)
void drawOccluder(Graphics *gfx, Drawable *drawable, const glm::mat4 &matrix)
Drawable occlusion (respects Drawable::getCastOcclusion).
void setMode(const std::string &mode)
"screenspace" | "raymarch" | "fog" — selects which shader params quality tweaks.
void setLightScreenPos(float x, float y, float width, float height)
Pixel-space helper (converts with width/height).
void setFogEnd(float endDistance)
void beginOcclusionMap(Graphics *gfx, float lightPixelX, float lightPixelY, float lightRadiusPixels=24.f)
Clear the current canvas to black and draw a bright light disc (start of an occlusion map)....
void applyFromScene(Graphics *gfx, Texture *scene)
Single-pass: treat source as the scene (bright regions ≈ light), add shafts + dust/fog onto it....
void drawOccluders2D(Graphics *gfx)
Draw all visible Renderable2D with castOcclusion into the current canvas as black silhouettes (shadow...
void rayMarchTo(Graphics *gfx, Texture *linearDepth, Canvas *dest)
void setFogHeightFalloff(float falloff)
float getDownscale() const
Definition Volumetric.h:84
void setLightScreenUV(float u, float v)
Light position in UV (0..1), origin top-left to match 2D UVs.
void rayMarch(Graphics *gfx, Texture *linearDepth)
Ray march participating media using a linear-depth texture (R channel, 0=near .. 1=far)....
Shader * getShader() const
Definition Volumetric.h:152
void setCamera(float eyeX, float eyeY, float eyeZ, float targetX, float targetY, float targetZ, float upX, float upY, float upZ, float fovYDeg, float aspect, float nearZ, float farZ)
Camera for ray march reconstruction (RH + ZO). Builds inv(viewProj) and near/far used by rayMarch*.
std::string getMode() const
Definition Volumetric.h:41
void setIntensity(float intensity)
bool hasParam(const std::string &name) const
std::string getQuality() const
Definition Volumetric.h:37
float getLightScreenU() const
void setLightDirection(float dx, float dy, float dz)
World-space direction toward the lit surface (ray march / phase).
void setTime(float seconds)
void setFloat(const std::string &name, float value)
void setShaftColor(float r, float g, float b)
void setQuality(const std::string &quality)
"low" | "medium" | "high" (unknown → medium).
void setFogHeight(float worldY)
Height fog: denser near world Y = fogHeight; falloff is 1/meters scale.
void applyFromSceneTo(Graphics *gfx, Texture *scene, Canvas *dest)
float getLightScreenV() const
void applyFogTo(Graphics *gfx, Texture *linearDepth, Canvas *dest)
void setDensity(float density)
void drawOccluderTexture(Graphics *gfx, Texture *texture, float x, float y, float w, float h)
void setFogStart(float startDistance)
View-distance ramp where fog appears (world units along the ray).
void applyFog(Graphics *gfx, Texture *linearDepth)
Volumetric height/distance fog from a linear-depth texture. Writes fog RGB with alpha = 1-transmittan...
Shader * getRayMarchShader() const
Definition Volumetric.h:153
void drawOccluderSolid(Graphics *gfx, float x, float y, float w, float h)
Convenience 2D black silhouette (solid or textured alpha).
int resolutionFor(int fullSize) const
Downscale helper: returns floor(dim / downscale), at least 1. Callers create occlusion / scatter canv...
Shader * getFogShader() const
Definition Volumetric.h:154
void setFogColor(float r, float g, float b)
Dynamic water surface with sky reflection and animated ripples.
Definition Water.h:33
Mesh * getMesh() const
Definition Water.h:106
void setScreenSpaceReflection(bool enabled, float strength=0.85f)
Optional screen-space reflection overlay. When enabled, the shader samples the SSR pass result (bound...
Definition Water.cpp:250
float getViewportHeight() const
Definition Water.h:97
float getSunIntensity() const
Definition Water.h:82
float getTime() const
Definition Water.h:47
void setWaveAmplitude(float amp)
Amplitude of the shore-edge waves.
Definition Water.cpp:232
void setRippleAmplitude(float amp)
Amplitude of the occasional middle drop ripples.
Definition Water.cpp:233
void setWaveSpeed(float speed)
Definition Water.cpp:231
float getWaveAmplitude() const
Definition Water.h:55
void update(float dt)
Advance the animation clock by dt seconds.
Definition Water.cpp:221
float getRippleAmplitude() const
Definition Water.h:59
void draw()
Draw the water plane (uses default mesh3d camera / lighting state).
Definition Water.cpp:279
float getReflectionIntensity() const
Definition Water.h:79
void setEdgeFalloff(float edge)
Width (in UV, 0..1) of the edge wave band.
Definition Water.cpp:234
int getRippleCount() const
Definition Water.h:67
void createPlane(float sizeX, float sizeZ, int segX, int segZ)
Build a flat XZ plane (Y-up) sized sizeX × sizeZ with UVs in [0,1]².
Definition Water.cpp:186
void setSunIntensity(float intensity)
Definition Water.cpp:249
float getWaveSpeed() const
Definition Water.h:51
void setReflectionTint(float r, float g, float b)
Definition Water.cpp:243
void setTime(float seconds)
Definition Water.cpp:226
float getEdgeFalloff() const
Definition Water.h:63
void setReflectionIntensity(float intensity)
Definition Water.cpp:248
float getRippleInterval() const
Definition Water.h:71
float getViewportWidth() const
Definition Water.h:96
void setWaveScale(float scale)
Definition Water.cpp:237
float getScreenSpaceReflectionStrength() const
Definition Water.h:92
bool getScreenSpaceReflection() const
Definition Water.h:91
void setRippleInterval(float seconds)
Seconds between drop ripples.
Definition Water.cpp:236
Shader * getShader() const
Definition Water.h:105
void bindParams()
Upload current params to the shader push constants.
Definition Water.cpp:259
void setViewport(float width, float height)
Window / target size in pixels, used to compute screen-space UVs.
Definition Water.cpp:254
void setRippleCount(int count)
How many expanding drop ripples exist.
Definition Water.cpp:235
float getWaveScale() const
Definition Water.h:74
void setWaterColor(float r, float g, float b)
Definition Water.cpp:238
Flowing waterfall (falling water sheet) rendered on a vertical plane.
Definition Waterfall.h:34
float getStreakScale() const
Definition Waterfall.h:65
void setSunIntensity(float intensity)
void setReflectionIntensity(float intensity)
Shader * getShader() const
Definition Waterfall.h:87
void createSheet(float width, float height, int segX, int segY)
Build a vertical XY plane (facing +Z, Y-up world) sized w×h, UVs [0,1]².
Definition Waterfall.cpp:56
float getSunIntensity() const
Definition Waterfall.h:79
void setStreakCount(int count)
How many layered falling streaks are drawn.
void setFoamAmount(float v)
int getStreakCount() const
Definition Waterfall.h:61
float getFoamAmount() const
Definition Waterfall.h:73
float getTime() const
Definition Waterfall.h:48
void draw()
Draw the waterfall sheet (uses default mesh3d camera / lighting state).
void setWaterColor(float r, float g, float b)
Mesh * getMesh() const
Definition Waterfall.h:88
float getTurbulence() const
Definition Waterfall.h:57
float getBottomFoam() const
Definition Waterfall.h:71
void setTurbulence(float t)
Amount of turbulence / white-water streak in the body.
float getReflectionIntensity() const
Definition Waterfall.h:77
void bindParams()
Upload current params to the shader push constants.
void setBottomFoam(float v)
void setStreakScale(float scale)
Horizontal stretch of the falling streaks (1 = circular, >1 elongated).
float getTopFoam() const
Definition Waterfall.h:69
void update(float dt)
Advance the animation clock by dt seconds.
Definition Waterfall.cpp:91
void setTopFoam(float v)
Relative height (0..1) of the top foam lip and bottom splash bands.
void setFlowSpeed(float speed)
Fall speed of the water (scales the downward scroll).
void setTime(float seconds)
Definition Waterfall.cpp:96
float getFlowSpeed() const
Definition Waterfall.h:53
Represents raw pixel data.
Definition ImageData.h:26
I * query()
Definition Capability.h:77
void rtBind(const char *kind, const char *name)
Definition RenderTrace.h:45
void rtFrameBegin()
Definition RenderTrace.h:30
void rtFrameEnd()
Definition RenderTrace.h:33
void rtDraw(const char *api, const char *detail=nullptr)
Definition RenderTrace.h:48
Shader * createShader(Graphics *gfx)
Definition Grass.cpp:346
Shader * createShader(Graphics *gfx)
Create the default hair shader (alpha-blended, anisotropic specular). Owned by Graphics.
卡牌游戏 UI 工具模块:工厂 + 脚本绑定入口。 功能参考 ycarowr/UiCard:扇形手牌布局、抽牌/洗牌、悬浮放大、拖拽到落牌区、 敌方手牌(背面/偷看)、费用不足置灰,以及可实时调节的布局...
Definition AnimTrail.h:6
uint32_t nextCodepointUtf8(const std::string &text, size_t &i)
Decodes one UTF-8 codepoint from text starting at byte offset i, advancing i past it....
Definition Font.cpp:17
glm::vec4 Color
RGBA color used by every graphics draw call. Lives inside eve::graphics so including a graphics heade...
Definition Color.h:13
constexpr uint32_t Water
Definition Semantic.h:14
Options for Graphics::newTexture / newCubemap. When generateMipmaps is true and sampler....
Sampler state for a Texture (filter, wrap, mip LOD, anisotropy). Defaults match historical engine beh...
float maxAnisotropy
1 = off; values >1 enable anisotropic filtering when the device supports it.
static FilterMode parseFilter(const std::string &name)
static MipmapMode parseMipmap(const std::string &name)