diff --git a/PARITY.md b/PARITY.md index dcc7d75c..d71dc6ac 100644 --- a/PARITY.md +++ b/PARITY.md @@ -4458,10 +4458,6 @@ treated as before. A Move drag with Snap to Curve enabled follows the nearest point on the curve even when the cursor moves farther than 40 pixels away. This applies to the C shortcut and the Snap to Curves toggle. -filtered by language; Command Completion, Object Path Completion, Show Tooltip Help and Show quick help are greyed -because the editor has no completion, so the Quick Help side bar they would show is not built; the MEL tab icon is -drawn from the reference's file name, as the reference's `mel_tab.png` is not on disk. - ### mGear's menus, run item by item (25/11/2026) Every item of mGear 5.4.8's menus (136) was triggered in the running application, with nothing selected, with a rig @@ -4566,6 +4562,196 @@ reference greys them. `IKSplineHandleTool` starts it. The defaults are those ikS to root off is unverified. Not yet: Create IK Handle is still a command on two selected joints, not the IK Handle Tool; Auto simplify curve and Root twist mode are passed on but don't change the solve. +### What changed (25/11/2026, #302) + +The viewport reflects and refracts as the Render View does. Until now it shaded direct light and the sky dome only: a +red sphere standing on a grey floor lit a red patch into the floor through bounce light, but no image of the sphere +appeared in it. + +The Realtime renderer writes a material image beside its picture and surface colour: the fresnel-weighted reflection +colour and the roughness it is looked up with, then transmission, IOR and metalness. The material shader no longer adds +the sky's reflection itself; a post pass works out the reflection from that material before the picture is put +together. + +- Screen-space reflections march the view's own colour and depth, so objects reflect objects. Where a ray leaves the + view or meets nothing, the sky dome stands in. The march is jittered by a fixed per-pixel pattern, never by time, so + it does not flicker while the camera moves. +- The widest flat mesh at the ground plane is drawn a second time mirrored below the plane, without the reflector + itself, and the floor reads that image. A screen-space march cannot reflect the underside of a sphere standing on + the floor, which is most of what the floor sees; the mirrored draw can. Where the surface is the plane and near it, + the planar image replaces the screen-space one; a raised or sloped surface keeps the screen-space result. +- Reflections are blurred by the composite over the reflection image, with a radius that grows with the square of the + roughness: a mirror one ray, a rough metal gathers its neighbourhood, and neighbouring pixels on another surface are + left out so an edge stays an edge. Metals tint their reflection through the material's fresnel colour; dielectrics + keep the sky's. +- Glass is drawn solid so it has depth and a material, and the post pass takes it apart. The scene is drawn once more + without its transmissive surfaces; each glass pixel reads that image bent out towards the rim as a lens bends it and + tinted by its transmission colour, fading with the distance the lookup travels. Two glass spheres at different IOR + bend the wall behind them differently. +- The examples get a lighting suite for parity: `examples/rendering/reflections.ma`, + `metal_roughness_sweep.ma`, `dielectric_glass.ma`, `tinted_glass.ma`, `emissive_object.ma`, `area_lights.ma`, + `environment_hdri.ma` and `checker_sphere.ma`, built by `examples/tools/make_rendering_parity.py`. Each has a + reference render (the Render View's path) and a viewport capture under `examples/rendering/reference` and + `examples/rendering/viewport`, taken by `tools/render_parity/capture.sh`, which is documented in + `tools/render_parity/README.md`. +- `tools/render_parity/capture.sh` renders each scene through `shotCam` at 640 by 360 and captures the realtime + viewport through the same camera with `--viewport-screenshot`, cropping the taller panel to the render's 16:9 field. + The capture hides the grid, ViewCube, light and camera icons, handles and selection highlights and keeps textures and + the camera's depth of field on. +- Tests without a GPU in `crates/aztek_host/src/post.rs`: the reflection and refraction directions, the roughness + blur radius, the planar ground cover, the material and post bindings the shaders declare, and the eight example + scenes with their two pictures. The existing shader compile tests cover the new reflection shader for one sample and + for several. + +Not done: a reflection of what the view does not show anywhere falls back to the sky; only the widest flat mesh at the +world's ground is mirrored; Aztek has no transmission depth, so the lookup distance stands in for it and the glass is +bent as a lens rather than traced through its back surface; the viewport does not draw the sky dome as a background +(it lights and reflects from it); and at the same focal length the viewport frames about 12% tighter than the Render +View. Harold reflects a single large floor face onto itself, so the suite's floors are subdivided. The depth of field +of #300 still works: a camera with `depthOfField` on blurs the viewport after the reflections are added, and the +guides stay over the finished picture. + +### Reflection filtering and the two tiers (25/11/2026, #302) + +The reflection image is low-passed over three pixels and then copied down a six-level mip chain. The composite picks a +level from the surface's roughness and gathers a fixed 8-tap disc inside the ray's footprint, with an eight pixel +minimum, clamping each tap at 8 and hashing the pixel for its offset rather than the frame. The metal roughness +sweep's floor went from a grid of bright texels that shimmered while orbiting to soft blobs that are steady idle or +moving. + +The ground plane's planar image and the screen-space reflection now share one brightness scale and the same filtered +copy. The planar side gets a three by three sample so its silhouette hands over gradually; the weight is the surface's +planarity, its roughness and the planar image's own coverage, read from its alpha, and the two are mixed by one minus +that weight, so the weights sum to one. The reflections example's key is a directional light: a point light close to +the floor left a cube shadow face seam across it, which read as a second reflection. + +What still differs from the Render View: the HDRI scene's sky is still not drawn as the viewport's background, the +viewport frames about 12% tighter than the render at the same focal length, only the widest flat ground mesh is +mirrored, and a point light near a large floor can still show a cube shadow seam. The new captures are in +`examples/rendering/reference` and `examples/rendering/viewport`. + +### The mirrored pass and the floor's top (26/11/2026, #302) + +The planar pass used to mirror the camera and rewrite the light block for that view. The geometry drew, but the +fragment shader shaded it in the mirrored view's light space while its normal matrix and the main pass did not agree, +so a mirrored sphere came out black except for one lit crescent, and it sat away from the sphere at most angles. The +pass now keeps the main camera, projection and lights and mirrors the model instead: each item is drawn with the +reflection matrix about the reflector's actual top plane (`translate(point) * reflect(up) * translate(-point)`), not +about the world origin, so a floor slab whose top is not at zero works too. Normals are recomputed from the real +model, so the planar image is the real scene's shading mirrored about the floor; culling is off because the mirror +turns the winding. The planar pass has its own light buffer without the camera's shadow map, which would be sampled at +the mirrored point. + +The composite reads the planar image's alpha, not its lightness, as the weight. The planar pass clears to transparent +black, so alpha is exactly the mirrored scene's coverage: a sphere's own shadowed side is dark and still a reflection, +where reading lightness treated it as empty and let the sky stand in, which cut the mirror into a bright cap and a +separate lower disc. Measured at the persp camera before the fix, the lit planar image of the red mirrored sphere was +only rows 313 to 337 (a crescent); with a flat unlit colour it projects to rows 307 to 422, the real red sphere's 111 +rows mirrored about its contact row, and the white mirrored sphere to rows 314 to 435 for the real 110 rows. + +### The bounce light's filtering and the reflection's level (26/11/2026, #302) + +The viewport's Bounce Light (the indirect light) drew the spheres with scattered square texels. The bounce pass shoots +a dozen stochastic rays a pixel and stores their mean in the bounce image; a ray that met a specular highlight came +back as a bright texel, and the composite then spread each one over a hard 9x9 square. The old per-pixel hash also +left a diagonal weave, so the noise was spatially correlated. The pass now clamps each ray's radiance (the offline +renderer clamps its indirect samples for the same reason), uses a decorrelated integer hash for its sequences, and the +composite no longer filters the bounce at the sampling point. Instead the bounce image is low-passed by a separable +Gaussian quad pass along each axis (sigma 3.5 physical pixels, 19 taps a pass) and the composite reads that filtered +image with one linear sample. That is where the denoise belongs, after the rasterized passes and before the shading +uses it. The two passes reuse the occlusion and bounce images, so they add no render target and no VRAM; they replace +the old 81-tap spread and its 81 depth fetches, so the frame does slightly less work. The openness and contact shadow +share the buffer and are low-passed with the light, because a sharp alpha against the soft light made the contact +shadow's steps show on the sphere's dark side. + +The reflection gather's prefilter level was the blocky edge: the composite looked the gather up from an +eighth-resolution mip (level 3) for even a mirror, so every reflection edge stepped at about eight pixels. The gather +now starts two levels sharper (half resolution for a mirror, quarter and eighth only as the roughness grows), while +the gather's disc radius stays 8 to 32 pixels at a 720-line view and grows with the buffer, so a rough surface keeps +the same softness at any window size or pixel ratio; the planar image is read with linear filtering too. The reflection and planar targets were already at the viewport's full +resolution, so no target grew and no memory changed. Net cost is slightly lower: two 19-tap bounce passes replace the +9x9 (81-tap) composite spread, and the reflection reads a higher mip. `modelEditor -bounceLight` and +`-ambientOcclusion` now drive those two lighting toggles from scripts as well. + +Measured with the indirect debug view: before, the bounce was a sparse field of bright texels that the 9x9 box turned +into square blocks; now it is a smooth field. The four viewpoints, with the bounce on and off and reflections on and +off, show no square texels, and the mirrored edge against the floor is smooth and continuous. + +EEVEE is the reference for the shape of these two effects. Its planar probes (`eevee_lightprobe_planar.cc`, +`PlanarProbe::set_view`, and `shaders/eevee_lightprobe_plane.bsl.hh`) render one full-viewport mirrored image per flat +plane, with a depth image of its own and a world clip plane at the probe's plane (`world_clip_buf_.plane`), and its +`select_probe` scores a surface with `saturate(dot(N, probe_normal)) * inside_bounds`. Aztek's mirrored-model pass is +the same probe: full-viewport radiance and `planar_depth`, the main camera and lights, and the real model's normals. +Our `planar_cover` is the `saturate(dot(N, up))` score and the height fade is the `inside_bounds` test; the planar +alpha is the stand-in for EEVEE's `planar_depth_tx == reverse_z::read(1.0)` background rejection in +`eevee_forward_lib.bsl.hh`, and the composite blends the planar and screen-space tiers by roughness the way EEVEE +mixes its planar probe with the screen trace. Because the models are mirrored and the camera is not, the image is +right-side up at the same screen UV, so EEVEE's NDC flip for its upside-down probes does not apply, and the planar +tier is used only on the plane, where the `parallax()` term is the identity. The reflection gather reads a prefiltered +chain and chooses the level from the roughness, as `roughness_to_lod` does for the sphere probes +(`eevee_lightprobe_sphere.bsl.hh`). The one EEVEE detail not mirrored yet is the world clip plane: the suite's +geometry never crosses the probe plane and the reflector itself is skipped, so it is left for a scene that does. + +For the indirect term EEVEE never shades from a raw stochastic trace: `eevee_lightprobe_volume.cc` bakes irradiance +into a 3D grid of spherical harmonics and the forward pass samples it with a filtered lookup. Aztek keeps a +screen-space variant of that idea: the bounce rays are clamped and decorrelated, then the finished bounce image is +blurred along each axis in quad passes and read with a linear sample, so the shading sees a smooth irradiance field +rather than the sample points. Temporal reprojection would be the next step if the screen-space field is not enough; +the clamp, the low-discrepancy sequence and the filtered lookup are the parts that matter for the blocks today. + +### A moving check of the realtime viewport (26/11/2026, #302) + +`tools/render_parity/motion_capture.py` runs one session with lights, shadows, ambient occlusion, bounce light, +textures and depth of field on, and writes four keyframed playblasts: a full 360-degree orbit, a dolly from far to +close and back, a low sweep from the lit side to the dark side, and twelve frames of an unmoving camera to catch +temporal instability. The app's `playblast` sets each frame and renders the live viewport, so the motion is smooth and +one launch serves a whole pass. + +The moving capture found the bounce and reflection work stable: twelve still frames were bit-identical, and the +orbit, dolly and sweep had no frame-to-frame step above 1.6 times its neighbours' mean. There was no speckle, no tier +pop and no reflection offset at any angle. What did show was the shadow map's cast edge: at a close view one texel is +many pixels, so the sphere's shadow on the floor was a hard, chunky boundary that crawled as the camera moved. The +percentage-closer filter now gathers 5 by 5 texels and the shadow sampler is bilinear, so that edge is a soft +penumbra. The cost is 25 taps instead of 9 in the shadowed fragment; with this scene the capture still ran at about +20 frames a second at 734 by 708 including the PNG write, and the app's own draw timing stayed at about 0.2 ms. + +Two display-layer edges stay: a one-pixel dashed rim on a sphere is MSAA coverage quantisation, not shading, and the +grid's smooth lines can read over a sphere at grazing angles. The parity capture hides the grid, and the motion script +does too; both are guides rather than the shaded picture. The depth-of-field view is available to scripts through +`modelEditor -depthOfField`, which is how the capture turns it on. + +The second pass re-ran the same four captures from a fresh session. Every frame was bit-identical to the first pass's +frame at the same time, so the renderer has no cross-session variation and no temporal accumulation state to drift; +the twelve still frames were identical again, and the frame-to-frame steps kept the same smooth profile. The wider +shadow filter introduced no peter-panning: the contact shadow stays attached at the dolly's closest view, and the +sweep's shadow boundary is the smoother of the two passes. No further change was needed. + +### Point-light shadows and the glass that cast them (26/11/2026, #302) + +The dielectric_glass floor was covered in dark polygonal patches under the glass spheres. A point light is a cube +shadow map: six 2048-texel faces, all six rewritten every frame, with near and far from the scene's distance to the +light. The shader compared a single cube texel against a constant world-space slack. A floor seen at a grazing angle +from a light close to it needs the bias to follow the texel footprint over the cosine to the light, and one texel +gives a hard polygonal edge with a mottled fill wherever the comparison flips. The cube path now uses a depth slack +that grows with the texel footprint and the surface's slope to the light, and fixed bilinear cube taps at a +four-texel radius: a 4 by 4 grid for a point light, and a golden-angle disc of sixteen taps for an area light's wider +penumbra. Nothing is rotated per pixel or per frame. The directional and spot path +keeps its 5 by 5 bilinear PCF, and the cube faces stay at 2048, all six every frame. + +The deeper cause was that the glass spheres were drawn into the shadow map. A transmissive shape laid down an opaque +shadow, the floor under it went black, and the glass refracted that black floor, so it read black inside the shadow. +Transmissive casters are now left out of the shadow map, so the floor under the glass is lit and the behind-glass +image is not black; the glass also keeps a floor of its own transmission colour where the background behind it is +dark, so it never reads blacker than what it lets through. The debug view of the behind-glass image shows the glass +shadows gone. + +Verified at the dielectric scene's far, mid and close distances, two angles at each, and a grazing view. The far views +push the floor until it fills the frame, where the shadow-map footprint is worst: before, the far floor had the blocky +glass shadows with a mottled fill; after, they are gone, the remaining cast shadows are smooth, and the glass reads +red rather than black. The metal roughness sweep and area lights recapture without a regression; the area light's soft +shadow is smoother for the fixed tap pattern. The point-light shadow costs sixteen bilinear taps instead of one; the +area-light path is unchanged at twelve blocker plus sixteen taps, and the shadow map's memory is unchanged. + ### What changed (26/11/2026, emit) `emit`, as the reference's documentation describes it: particles added to a particle object that exists, one for diff --git a/TICKETS.md b/TICKETS.md index c2fd0b72..4678f4aa 100644 --- a/TICKETS.md +++ b/TICKETS.md @@ -16,6 +16,43 @@ Requests waiting or in progress, newest detail kept. Move to Done with the date - C++ plug-in kit (agent). ## Waiting +- Viewport reflections and refraction (#302, 25/11/2026): screen-space reflections for objects, a mirrored draw for the + widest flat ground mesh, roughness blur, and glass read from a behind-glass draw. Left: a reflection of something the + view does not show falls back to the sky; only the widest flat mesh at the world's ground is mirrored; no + transmission depth (the lookup distance stands in, and the glass is bent as a lens rather than traced through its + back faces); the sky dome is not drawn as the viewport's background; the viewport frames about 12% tighter than the + Render View at the same focal length; and Harold reflects one large single-face floor onto itself, so the parity + floors are subdivided. The suite and its capture steps are in `tools/render_parity/README.md`. 25/11/2026: the + reflection gather is a low-passed mip chain with a fixed disc and outlier clamp, and the planar and screen-space + tiers share a brightness and blur with weights that sum to one. 26/11/2026: the planar pass now mirrors the models + about the floor's top plane with the main camera and lights, shades them with the real model's normals, and the + composite uses the planar image's alpha rather than its lightness, so the mirror is a complete lit sphere anchored + under the real one at the shot, low, high and off-axis views instead of a black crescent away from the shot camera. + 26/11/2026: the bounce light clamps its ray radiance, decorrelates its sequence and is low-passed along each axis in + its own quad passes before the picture reads it, and the reflection gather starts from a half-resolution mip instead + of an eighth with linear planar sampling; the square texels are gone in every bounce/reflection combination and the + mirrored edge is smooth. `modelEditor -bounceLight` and `-ambientOcclusion` drive the two lighting toggles from + scripts. The shape follows EEVEE: a full-viewport planar probe with its own depth, a `select_probe`-style normal + score, planar/alpha coverage, a roughness-to-level prefiltered gather, and a filtered screen-space irradiance field + for the bounce instead of raw stochastic samples. Left of that design: EEVEE's world clip plane at the probe's plane + (the suite's geometry never crosses it) and temporal reprojection of the indirect term. +- Point-light shadows and glass (#302, 26/11/2026): the cube path now has a slope-scaled depth slack and fixed + bilinear taps instead of one texel (a 4 by 4 grid for a point light, a sixteen-tap disc for an area light), and + transmissive shapes no longer cast an opaque shadow, so the + dielectric_glass floor's blocky glass shadows and the black glass behind them are gone; the glass keeps a floor of + its own colour where the background is dark. Verified far, mid and close, two angles each, and grazing; the far + view is clean. Left: the glass refraction is still a lens-bend approximation, so its transparency is flatter than + the Render View's, and a point light's shadow is still small-penumbra because the light has no size. +- Realtime motion polish (#302, 26/11/2026): `tools/render_parity/motion_capture.py` checks one session with every + feature on over an orbit, a dolly, a low terminator sweep and twelve still frames. The bounce, reflection and AO + terms are temporally stable (still frames are bit-identical, no frame-diff spikes) and show no speckle or tier pop. + Pass one widened the shadow map's PCF to 5 by 5 with a bilinear sampler, which softens the cast edge that crawled + at close range. Pass two re-ran all four captures from a fresh session: every frame was bit-identical to pass one's + and the contact shadow stayed attached, so nothing remained to fix. Left: a one-pixel MSAA rim on a silhouette, the grid's smooth lines reading over a sphere at + grazing angles, and the reflection's sharp horizon on a smooth sphere, which is the scene's own image. + Left: the sky dome is still not drawn as the viewport's background, the viewport frames about 12% tighter than the + Render View, only the widest flat ground mesh is mirrored, and a point light close to a large floor can leave a cube + shadow seam. - Script Editor completion (25/11/2026): the feature is in (PARITY.md, docs/SCRIPT_EDITOR_COMPLETION.md). Left: object path completion; a Quick Help side bar; completion across a multi-line expression; type inference for an arbitrary expression before a dot; docstrings for the Python API's members, which the embedded modules do not carry; diff --git a/app/src/main.cpp b/app/src/main.cpp index 8cc953d8..1e468350 100644 --- a/app/src/main.cpp +++ b/app/src/main.cpp @@ -17,11 +17,14 @@ #include "widgets.h" #include #include +#include #include #include #include #include #include +#include +#include "viewport.h" #ifdef Q_OS_WIN #include #endif @@ -130,9 +133,11 @@ int main(int argc, char** argv) { args.addHelpOption(); QCommandLineOption script({"s", "script"}, "Run a MEL file at start.", "file"); QCommandLineOption shot("screenshot", "Save a screenshot of the window after start-up and quit.", "png"); + QCommandLineOption viewport("viewport-screenshot", "Save the first visible viewport after start-up and quit.", "png"); QCommandLineOption batch("batch", "No window: run the scene and scripts given, then exit with their status."); args.addOption(script); args.addOption(shot); + args.addOption(viewport); args.addOption(batch); args.addPositionalArgument("scene", "Scene to open."); args.process(app); @@ -156,11 +161,15 @@ int main(int argc, char** argv) { aztek_set_main_window(static_cast(&w)); // The saved size and panels before the window is shown. Restoring them after show resized the window under the splash, // and under XWayland on a scaled screen the parts drawn at the old size stayed on screen (#225). - if (!args.isSet(shot)) w.restore_saved_window(); + if (!args.isSet(shot) && !args.isSet(viewport)) w.restore_saved_window(); + // A viewport capture is compared with a render frame: a fixed window keeps its size the same every time. + if (args.isSet(viewport)) w.resize(1280, 800); // Keep the viewport hidden while the first-run dialog processes events. On macOS, presenting a frame here can // block the dialog while Metal waits for a drawable. Script and screenshot runs skip the prompt. - if (!args.isSet(script) && !args.isSet(shot)) az::ask_user_folder_at_first_start(&w, splash); + if (!args.isSet(script) && !args.isSet(shot) && !args.isSet(viewport)) az::ask_user_folder_at_first_start(&w, splash); w.show(); + // A parity capture is one view, made before the start-up script so the script's lookThru reaches it. + if (args.isSet(viewport)) w.panels()->set_layout(0); if (splash) { splash->finish(&w); delete splash; @@ -174,6 +183,32 @@ int main(int argc, char** argv) { aztek_startup_scripts(); if (!args.positionalArguments().isEmpty()) w.open_file(args.positionalArguments().first()); w.run_startup(args.value(script), args.value(shot)); + if (!args.value(viewport).isEmpty()) { + const QString path = args.value(viewport); + QTimer::singleShot(1500, &w, [&w, path] { + for (az::ViewportWidget* v : w.panels()->views()) { + if (!v->isVisible()) continue; + // A parity capture is the picture alone: the Realtime renderer, no grid over it. + v->set("renderer", "\"realtime\""); + v->set("grid", "false"); + v->set("viewCubeVisible", "false"); + // The picture alone: no light or camera icons, handles or selection highlights over it. Textures show, + // as the Render View draws them. + v->set("disp", "{\"lights\":false,\"cameras\":false,\"manipulators\":false,\"highlight\":false,\"filmGate\":false,\"resGate\":false,\"safeAction\":false,\"textured\":true,\"depthOfField\":true}"); + // The Render View clears to black; the viewport's own background is grey, so a parity capture clears to + // black too. + v->set("background", "0.0"); + // The host writes a PPM; the picture is kept as the format the path names. + QString tmp = path + ".ppm"; + if (v->capture(tmp)) { + QImage(tmp).save(path); + QFile::remove(tmp); + } + break; + } + qApp->quit(); + }); + } int rc = app.exec(); aztek_exiting(); return rc; diff --git a/crates/aztek_host/src/gpu.rs b/crates/aztek_host/src/gpu.rs index 9822ac6e..c1b41274 100644 --- a/crates/aztek_host/src/gpu.rs +++ b/crates/aztek_host/src/gpu.rs @@ -239,6 +239,30 @@ pub struct Gpu { pub albedo_msaa_image: vk::Image, pub albedo_msaa_view: vk::ImageView, pub albedo_msaa_alloc: Option, + /// The Realtime renderer's reflection for each pixel: the fresnel-weighted reflection colour in rgb, the roughness + /// used for its environment lookup in a (above zero wherever a material is drawn). The screen-space reflection pass + /// reads it (#302). + pub mat_image: vk::Image, + pub mat_view: vk::ImageView, + pub mat_alloc: Option, + pub mat_msaa_image: vk::Image, + pub mat_msaa_view: vk::ImageView, + pub mat_msaa_alloc: Option, + /// The rest of a material the reflection pass needs: transmission, IOR as (IOR - 1) / 2, metalness, and 1 where a + /// Realtime material was drawn. RGBA8 is enough for these (#302). + pub mat_aux_image: vk::Image, + pub mat_aux_view: vk::ImageView, + pub mat_aux_alloc: Option, + pub mat_aux_msaa_image: vk::Image, + pub mat_aux_msaa_view: vk::ImageView, + pub mat_aux_msaa_alloc: Option, + /// Where the guides' pass resolves the material attachments it doesn't draw, keeping the scene's (#302). + pub overlay_mat_spare_image: vk::Image, + pub overlay_mat_spare_view: vk::ImageView, + pub overlay_mat_spare_alloc: Option, + pub overlay_mat_aux_spare_image: vk::Image, + pub overlay_mat_aux_spare_view: vk::ImageView, + pub overlay_mat_aux_spare_alloc: Option, /// How open each pixel is to the light around it, worked out from the scene's depth before the picture is put together. pub ao_pass: vk::RenderPass, pub ao_image: vk::Image, @@ -251,6 +275,38 @@ pub struct Gpu { pub bounce_view: vk::ImageView, pub bounce_alloc: Option, pub bounce_framebuffer: vk::Framebuffer, + /// Screen-space reflections and refraction, worked out from the scene's colour, depth and material before the + /// picture is put together (#302). + pub refl_image: vk::Image, + pub refl_view: vk::ImageView, + pub refl_alloc: Option, + pub refl_framebuffer: vk::Framebuffer, + /// The reflection image low-passed over a few pixels, so one bright texel does not speckle a reflection (#302). + pub refl_soft_image: vk::Image, + pub refl_soft_view: vk::ImageView, + pub refl_soft_alloc: Option, + pub refl_soft_framebuffer: vk::Framebuffer, + /// A mip chain of the reflection image: each level a filtered copy, so a gather at any roughness is smooth (#302). + pub refl_chain_image: vk::Image, + pub refl_chain_view: vk::ImageView, + pub refl_chain_alloc: Option, + /// The scene drawn mirrored about the ground plane, for the floor's reflection (#302). + pub planar_pass: vk::RenderPass, + pub planar_image: vk::Image, + pub planar_view: vk::ImageView, + pub planar_alloc: Option, + pub planar_depth_image: vk::Image, + pub planar_depth_view: vk::ImageView, + pub planar_depth_alloc: Option, + pub planar_framebuffer: vk::Framebuffer, + /// The scene without its transmissive surfaces, for glass to see what it lets through (#302). + pub back_image: vk::Image, + pub back_view: vk::ImageView, + pub back_alloc: Option, + pub back_depth_image: vk::Image, + pub back_depth_view: vk::ImageView, + pub back_depth_alloc: Option, + pub back_framebuffer: vk::Framebuffer, /// The pass that puts the scene on the window, through the post effects. pub post_pass: vk::RenderPass, /// One per swapchain image, for the post pass. @@ -311,6 +367,7 @@ impl Gpu { .initial_layout(vk::ImageLayout::UNDEFINED) .final_layout(vk::ImageLayout::SHADER_READ_ONLY_OPTIMAL)]; let ao_pass = device.create_render_pass(&vk::RenderPassCreateInfo::default().attachments(&ao_att).subpasses(&post_sub).dependencies(&post_dep), None)?; + let planar_pass = planar_pass(&device)?; let pool = device.create_command_pool( &vk::CommandPoolCreateInfo::default().queue_family_index(shared.queue_family).flags(vk::CommandPoolCreateFlags::RESET_COMMAND_BUFFER), None, @@ -358,6 +415,24 @@ impl Gpu { albedo_msaa_image: vk::Image::null(), albedo_msaa_view: vk::ImageView::null(), albedo_msaa_alloc: None, + mat_image: vk::Image::null(), + mat_view: vk::ImageView::null(), + mat_alloc: None, + mat_msaa_image: vk::Image::null(), + mat_msaa_view: vk::ImageView::null(), + mat_msaa_alloc: None, + mat_aux_image: vk::Image::null(), + mat_aux_view: vk::ImageView::null(), + mat_aux_alloc: None, + mat_aux_msaa_image: vk::Image::null(), + mat_aux_msaa_view: vk::ImageView::null(), + mat_aux_msaa_alloc: None, + overlay_mat_spare_image: vk::Image::null(), + overlay_mat_spare_view: vk::ImageView::null(), + overlay_mat_spare_alloc: None, + overlay_mat_aux_spare_image: vk::Image::null(), + overlay_mat_aux_spare_view: vk::ImageView::null(), + overlay_mat_aux_spare_alloc: None, ao_pass, ao_image: vk::Image::null(), ao_view: vk::ImageView::null(), @@ -367,6 +442,32 @@ impl Gpu { bounce_view: vk::ImageView::null(), bounce_alloc: None, bounce_framebuffer: vk::Framebuffer::null(), + refl_image: vk::Image::null(), + refl_view: vk::ImageView::null(), + refl_alloc: None, + refl_framebuffer: vk::Framebuffer::null(), + refl_soft_image: vk::Image::null(), + refl_soft_view: vk::ImageView::null(), + refl_soft_alloc: None, + refl_soft_framebuffer: vk::Framebuffer::null(), + refl_chain_image: vk::Image::null(), + refl_chain_view: vk::ImageView::null(), + refl_chain_alloc: None, + planar_pass, + planar_image: vk::Image::null(), + planar_view: vk::ImageView::null(), + planar_alloc: None, + planar_depth_image: vk::Image::null(), + planar_depth_view: vk::ImageView::null(), + planar_depth_alloc: None, + planar_framebuffer: vk::Framebuffer::null(), + back_image: vk::Image::null(), + back_view: vk::ImageView::null(), + back_alloc: None, + back_depth_image: vk::Image::null(), + back_depth_view: vk::ImageView::null(), + back_depth_alloc: None, + back_framebuffer: vk::Framebuffer::null(), post_pass, framebuffers: Vec::new(), in_post: false, @@ -419,6 +520,51 @@ impl Gpu { } self.bounce_view = vk::ImageView::null(); } + if self.refl_framebuffer != vk::Framebuffer::null() { + self.device.destroy_framebuffer(self.refl_framebuffer, None); + self.refl_framebuffer = vk::Framebuffer::null(); + } + if self.refl_soft_framebuffer != vk::Framebuffer::null() { + self.device.destroy_framebuffer(self.refl_soft_framebuffer, None); + self.refl_soft_framebuffer = vk::Framebuffer::null(); + } + for (view, image, alloc) in [ + (&mut self.refl_view, self.refl_image, &mut self.refl_alloc), + (&mut self.refl_soft_view, self.refl_soft_image, &mut self.refl_soft_alloc), + (&mut self.refl_chain_view, self.refl_chain_image, &mut self.refl_chain_alloc), + ] { + if *view != vk::ImageView::null() { + self.device.destroy_image_view(*view, None); + self.device.destroy_image(image, None); + if let Some(a) = alloc.take() { + let _ = self.shared.allocator.lock().unwrap().free(a); + } + *view = vk::ImageView::null(); + } + } + if self.planar_framebuffer != vk::Framebuffer::null() { + self.device.destroy_framebuffer(self.planar_framebuffer, None); + self.planar_framebuffer = vk::Framebuffer::null(); + } + if self.back_framebuffer != vk::Framebuffer::null() { + self.device.destroy_framebuffer(self.back_framebuffer, None); + self.back_framebuffer = vk::Framebuffer::null(); + } + for (view, image, alloc) in [ + (&mut self.planar_view, self.planar_image, &mut self.planar_alloc), + (&mut self.planar_depth_view, self.planar_depth_image, &mut self.planar_depth_alloc), + (&mut self.back_view, self.back_image, &mut self.back_alloc), + (&mut self.back_depth_view, self.back_depth_image, &mut self.back_depth_alloc), + ] { + if *view != vk::ImageView::null() { + self.device.destroy_image_view(*view, None); + self.device.destroy_image(image, None); + if let Some(a) = alloc.take() { + let _ = self.shared.allocator.lock().unwrap().free(a); + } + *view = vk::ImageView::null(); + } + } if self.ao_framebuffer != vk::Framebuffer::null() { self.device.destroy_framebuffer(self.ao_framebuffer, None); self.ao_framebuffer = vk::Framebuffer::null(); @@ -434,6 +580,12 @@ impl Gpu { for (view, image, alloc) in [ (&mut self.albedo_view, self.albedo_image, &mut self.albedo_alloc), (&mut self.albedo_msaa_view, self.albedo_msaa_image, &mut self.albedo_msaa_alloc), + (&mut self.mat_view, self.mat_image, &mut self.mat_alloc), + (&mut self.mat_msaa_view, self.mat_msaa_image, &mut self.mat_msaa_alloc), + (&mut self.mat_aux_view, self.mat_aux_image, &mut self.mat_aux_alloc), + (&mut self.mat_aux_msaa_view, self.mat_aux_msaa_image, &mut self.mat_aux_msaa_alloc), + (&mut self.overlay_mat_spare_view, self.overlay_mat_spare_image, &mut self.overlay_mat_spare_alloc), + (&mut self.overlay_mat_aux_spare_view, self.overlay_mat_aux_spare_image, &mut self.overlay_mat_aux_spare_alloc), ] { if *view != vk::ImageView::null() { self.device.destroy_image_view(*view, None); @@ -628,10 +780,26 @@ impl Gpu { let (image, view, alloc) = self.color_image("msaa albedo", ALBEDO_FORMAT, self.samples, vk::ImageUsageFlags::COLOR_ATTACHMENT | vk::ImageUsageFlags::TRANSIENT_ATTACHMENT, extent)?; (self.albedo_msaa_image, self.albedo_msaa_view, self.albedo_msaa_alloc) = (image, view, Some(alloc)); } + // The Realtime renderer's material: the reflection colour and roughness, and the transmission, IOR and + // metalness the screen-space reflection pass reads (#302). + let (image, view, alloc) = self.color_image("material", MAT_FORMAT, vk::SampleCountFlags::TYPE_1, vk::ImageUsageFlags::COLOR_ATTACHMENT | vk::ImageUsageFlags::SAMPLED, extent)?; + (self.mat_image, self.mat_view, self.mat_alloc) = (image, view, Some(alloc)); + let (image, view, alloc) = self.color_image("material aux", MAT_AUX_FORMAT, vk::SampleCountFlags::TYPE_1, vk::ImageUsageFlags::COLOR_ATTACHMENT | vk::ImageUsageFlags::SAMPLED, extent)?; + (self.mat_aux_image, self.mat_aux_view, self.mat_aux_alloc) = (image, view, Some(alloc)); + if multi { + let (image, view, alloc) = self.color_image("msaa material", MAT_FORMAT, self.samples, vk::ImageUsageFlags::COLOR_ATTACHMENT | vk::ImageUsageFlags::TRANSIENT_ATTACHMENT, extent)?; + (self.mat_msaa_image, self.mat_msaa_view, self.mat_msaa_alloc) = (image, view, Some(alloc)); + let (image, view, alloc) = self.color_image("msaa material aux", MAT_AUX_FORMAT, self.samples, vk::ImageUsageFlags::COLOR_ATTACHMENT | vk::ImageUsageFlags::TRANSIENT_ATTACHMENT, extent)?; + (self.mat_aux_msaa_image, self.mat_aux_msaa_view, self.mat_aux_msaa_alloc) = (image, view, Some(alloc)); + let (image, view, alloc) = self.color_image("overlay material spare", MAT_FORMAT, vk::SampleCountFlags::TYPE_1, vk::ImageUsageFlags::COLOR_ATTACHMENT | vk::ImageUsageFlags::SAMPLED, extent)?; + (self.overlay_mat_spare_image, self.overlay_mat_spare_view, self.overlay_mat_spare_alloc) = (image, view, Some(alloc)); + let (image, view, alloc) = self.color_image("overlay material aux spare", MAT_AUX_FORMAT, vk::SampleCountFlags::TYPE_1, vk::ImageUsageFlags::COLOR_ATTACHMENT | vk::ImageUsageFlags::SAMPLED, extent)?; + (self.overlay_mat_aux_spare_image, self.overlay_mat_aux_spare_view, self.overlay_mat_aux_spare_alloc) = (image, view, Some(alloc)); + } let att: Vec = if multi { - vec![self.msaa_view, self.depth_view, self.scene_view, self.albedo_msaa_view, self.albedo_view] + vec![self.msaa_view, self.depth_view, self.scene_view, self.albedo_msaa_view, self.albedo_view, self.mat_msaa_view, self.mat_view, self.mat_aux_msaa_view, self.mat_aux_view] } else { - vec![self.scene_view, self.depth_view, self.albedo_view] + vec![self.scene_view, self.depth_view, self.albedo_view, self.mat_view, self.mat_aux_view] }; self.scene_framebuffer = self.device.create_framebuffer( &vk::FramebufferCreateInfo::default().render_pass(self.render_pass).attachments(&att).width(extent.width).height(extent.height).layers(1), @@ -643,10 +811,21 @@ impl Gpu { let att: Vec = if multi { let (image, view, alloc) = self.color_image("overlay spare", ALBEDO_FORMAT, vk::SampleCountFlags::TYPE_1, vk::ImageUsageFlags::COLOR_ATTACHMENT | vk::ImageUsageFlags::SAMPLED, extent)?; (self.overlay_spare_image, self.overlay_spare_view, self.overlay_spare_alloc) = (image, view, Some(alloc)); - // The scene's multisampled colour is done with once it is resolved: the guides draw into it afresh. - vec![self.msaa_view, self.depth_view, self.overlay_view, self.albedo_msaa_view, self.overlay_spare_view] + // The scene's multisampled colour is done with once it is resolved: the guides draw into it afresh. The + // material attachments resolve into spares, so the scene's own stay as the reflection pass reads them. + vec![ + self.msaa_view, + self.depth_view, + self.overlay_view, + self.albedo_msaa_view, + self.overlay_spare_view, + self.mat_msaa_view, + self.overlay_mat_spare_view, + self.mat_aux_msaa_view, + self.overlay_mat_aux_spare_view, + ] } else { - vec![self.overlay_view, self.depth_view, self.albedo_view] + vec![self.overlay_view, self.depth_view, self.albedo_view, self.mat_view, self.mat_aux_view] }; self.overlay_framebuffer = self.device.create_framebuffer( &vk::FramebufferCreateInfo::default().render_pass(self.overlay_pass).attachments(&att).width(extent.width).height(extent.height).layers(1), @@ -689,6 +868,96 @@ impl Gpu { &vk::FramebufferCreateInfo::default().render_pass(self.ao_pass).attachments(&bounce_att).width(extent.width).height(extent.height).layers(1), None, )?; + let (image, view, alloc) = self.color_image("reflection", AO_FORMAT, vk::SampleCountFlags::TYPE_1, vk::ImageUsageFlags::COLOR_ATTACHMENT | vk::ImageUsageFlags::SAMPLED, extent)?; + (self.refl_image, self.refl_view, self.refl_alloc) = (image, view, Some(alloc)); + let refl_att = [self.refl_view]; + self.refl_framebuffer = self.device.create_framebuffer( + &vk::FramebufferCreateInfo::default().render_pass(self.ao_pass).attachments(&refl_att).width(extent.width).height(extent.height).layers(1), + None, + )?; + let (image, view, alloc) = self.color_image("reflection soft", AO_FORMAT, vk::SampleCountFlags::TYPE_1, vk::ImageUsageFlags::COLOR_ATTACHMENT | vk::ImageUsageFlags::SAMPLED, extent)?; + (self.refl_soft_image, self.refl_soft_view, self.refl_soft_alloc) = (image, view, Some(alloc)); + let soft_att = [self.refl_soft_view]; + self.refl_soft_framebuffer = self.device.create_framebuffer( + &vk::FramebufferCreateInfo::default().render_pass(self.ao_pass).attachments(&soft_att).width(extent.width).height(extent.height).layers(1), + None, + )?; + let (image, view, alloc) = self.mip_image("reflection mips", AO_FORMAT, 6, vk::ImageUsageFlags::SAMPLED | vk::ImageUsageFlags::TRANSFER_SRC | vk::ImageUsageFlags::TRANSFER_DST, extent)?; + (self.refl_chain_image, self.refl_chain_view, self.refl_chain_alloc) = (image, view, Some(alloc)); + // The ground plane's reflection: the mirrored scene, at one sample a pixel. + let (image, view, alloc) = self.color_image("planar", AO_FORMAT, vk::SampleCountFlags::TYPE_1, vk::ImageUsageFlags::COLOR_ATTACHMENT | vk::ImageUsageFlags::SAMPLED, extent)?; + (self.planar_image, self.planar_view, self.planar_alloc) = (image, view, Some(alloc)); + self.planar_depth_image = self.device.create_image( + &vk::ImageCreateInfo::default() + .image_type(vk::ImageType::TYPE_2D) + .format(DEPTH_FORMAT) + .extent(vk::Extent3D { width: extent.width, height: extent.height, depth: 1 }) + .mip_levels(1) + .array_layers(1) + .samples(vk::SampleCountFlags::TYPE_1) + .usage(vk::ImageUsageFlags::DEPTH_STENCIL_ATTACHMENT), + None, + )?; + let req = self.device.get_image_memory_requirements(self.planar_depth_image); + let alloc = self.shared.allocator.lock().unwrap().allocate(&AllocationCreateDesc { + name: "planar depth", + requirements: req, + location: MemoryLocation::GpuOnly, + linear: false, + allocation_scheme: AllocationScheme::GpuAllocatorManaged, + })?; + self.device.bind_image_memory(self.planar_depth_image, alloc.memory(), alloc.offset())?; + self.planar_depth_alloc = Some(alloc); + self.planar_depth_view = self.device.create_image_view( + &vk::ImageViewCreateInfo::default() + .image(self.planar_depth_image) + .view_type(vk::ImageViewType::TYPE_2D) + .format(DEPTH_FORMAT) + .subresource_range(vk::ImageSubresourceRange::default().aspect_mask(vk::ImageAspectFlags::DEPTH).level_count(1).layer_count(1)), + None, + )?; + let planar_att = [self.planar_view, self.planar_depth_view]; + self.planar_framebuffer = self.device.create_framebuffer( + &vk::FramebufferCreateInfo::default().render_pass(self.planar_pass).attachments(&planar_att).width(extent.width).height(extent.height).layers(1), + None, + )?; + // What glass lets through: the scene without the transmissive surfaces (#302). + let (image, view, alloc) = self.color_image("behind glass", AO_FORMAT, vk::SampleCountFlags::TYPE_1, vk::ImageUsageFlags::COLOR_ATTACHMENT | vk::ImageUsageFlags::SAMPLED, extent)?; + (self.back_image, self.back_view, self.back_alloc) = (image, view, Some(alloc)); + self.back_depth_image = self.device.create_image( + &vk::ImageCreateInfo::default() + .image_type(vk::ImageType::TYPE_2D) + .format(DEPTH_FORMAT) + .extent(vk::Extent3D { width: extent.width, height: extent.height, depth: 1 }) + .mip_levels(1) + .array_layers(1) + .samples(vk::SampleCountFlags::TYPE_1) + .usage(vk::ImageUsageFlags::DEPTH_STENCIL_ATTACHMENT), + None, + )?; + let req = self.device.get_image_memory_requirements(self.back_depth_image); + let alloc = self.shared.allocator.lock().unwrap().allocate(&AllocationCreateDesc { + name: "behind depth", + requirements: req, + location: MemoryLocation::GpuOnly, + linear: false, + allocation_scheme: AllocationScheme::GpuAllocatorManaged, + })?; + self.device.bind_image_memory(self.back_depth_image, alloc.memory(), alloc.offset())?; + self.back_depth_alloc = Some(alloc); + self.back_depth_view = self.device.create_image_view( + &vk::ImageViewCreateInfo::default() + .image(self.back_depth_image) + .view_type(vk::ImageViewType::TYPE_2D) + .format(DEPTH_FORMAT) + .subresource_range(vk::ImageSubresourceRange::default().aspect_mask(vk::ImageAspectFlags::DEPTH).level_count(1).layer_count(1)), + None, + )?; + let back_att = [self.back_view, self.back_depth_view]; + self.back_framebuffer = self.device.create_framebuffer( + &vk::FramebufferCreateInfo::default().render_pass(self.planar_pass).attachments(&back_att).width(extent.width).height(extent.height).layers(1), + None, + )?; for &v in &self.views { let att = [v]; self.framebuffers.push(self.device.create_framebuffer( @@ -726,6 +995,33 @@ impl Gpu { Ok((image, view, alloc)) } + /// A colour image the view's size with a mip chain, its memory and a view of every level. + unsafe fn mip_image(&self, name: &str, format: vk::Format, levels: u32, usage: vk::ImageUsageFlags, extent: vk::Extent2D) -> Res<(vk::Image, vk::ImageView, Allocation)> { + let image = self.device.create_image( + &vk::ImageCreateInfo::default() + .image_type(vk::ImageType::TYPE_2D) + .format(format) + .extent(vk::Extent3D { width: extent.width, height: extent.height, depth: 1 }) + .mip_levels(levels) + .array_layers(1) + .samples(vk::SampleCountFlags::TYPE_1) + .usage(usage), + None, + )?; + let req = self.device.get_image_memory_requirements(image); + let alloc = self.shared.allocator.lock().unwrap().allocate(&AllocationCreateDesc { + name, + requirements: req, + location: MemoryLocation::GpuOnly, + linear: false, + allocation_scheme: AllocationScheme::GpuAllocatorManaged, + })?; + self.device.bind_image_memory(image, alloc.memory(), alloc.offset())?; + let range = vk::ImageSubresourceRange::default().aspect_mask(vk::ImageAspectFlags::COLOR).level_count(levels).layer_count(1); + let view = self.device.create_image_view(&vk::ImageViewCreateInfo::default().image(image).view_type(vk::ImageViewType::TYPE_2D).format(format).subresource_range(range), None)?; + Ok((image, view, alloc)) + } + /// A host-visible buffer holding data. pub fn buffer_with(&self, usage: vk::BufferUsageFlags, data: &[T]) -> Buffer { self.buffer_at(usage, data, MemoryLocation::CpuToGpu) @@ -803,8 +1099,13 @@ impl Gpu { // The albedo, none where nothing is drawn, and its resolve target. vk::ClearValue { color: vk::ClearColorValue { float32: [0.0; 4] } }, vk::ClearValue { color: vk::ClearColorValue { float32: [0.0; 4] } }, + // The material, none where nothing is drawn, and its resolve target. + vk::ClearValue { color: vk::ClearColorValue { float32: [0.0; 4] } }, + vk::ClearValue { color: vk::ClearColorValue { float32: [0.0; 4] } }, + vk::ClearValue { color: vk::ClearColorValue { float32: [0.0; 4] } }, + vk::ClearValue { color: vk::ClearColorValue { float32: [0.0; 4] } }, ]; - let one = [clears[0], clears[1], clears[3]]; + let one = [clears[0], clears[1], clears[3], clears[5], clears[7]]; let clears = if self.samples == vk::SampleCountFlags::TYPE_1 { &one[..] } else { &clears[..] }; self.device.cmd_begin_render_pass( self.cmd, @@ -833,8 +1134,8 @@ impl Gpu { self.device.cmd_end_render_pass(self.cmd); let none = vk::ClearValue { color: vk::ClearColorValue { float32: [0.0; 4] } }; let depth = vk::ClearValue { depth_stencil: vk::ClearDepthStencilValue { depth: 0.0, stencil: 0 } }; - let clears = [none, depth, none, none, none]; - let clears = if self.samples == vk::SampleCountFlags::TYPE_1 { &clears[..3] } else { &clears[..] }; + let clears = [none, depth, none, none, none, none, none, none, none]; + let clears = if self.samples == vk::SampleCountFlags::TYPE_1 { &clears[..5] } else { &clears[..] }; self.device.cmd_begin_render_pass( self.cmd, &vk::RenderPassBeginInfo::default() @@ -851,8 +1152,13 @@ impl Gpu { /// Ends the scene pass (or the overlay pass after it) and begins the one that works out the occlusion from its depth. pub fn begin_occlusion(&mut self) { + unsafe { self.device.cmd_end_render_pass(self.cmd) }; + self.begin_occlusion_after(); + } + + /// Begins the occlusion pass where the caller has already ended the pass before it. + pub fn begin_occlusion_after(&mut self) { unsafe { - self.device.cmd_end_render_pass(self.cmd); self.device.cmd_begin_render_pass( self.cmd, &vk::RenderPassBeginInfo::default() @@ -866,6 +1172,136 @@ impl Gpu { } } + /// Ends the reflection pass, so the image can be read and low-passed. + pub fn end_reflection(&mut self) { + unsafe { self.device.cmd_end_render_pass(self.cmd) }; + } + + /// Begins the low-pass of the reflection image, into `refl_soft_image`. + pub fn begin_refl_blur(&mut self) { + unsafe { + self.device.cmd_begin_render_pass( + self.cmd, + &vk::RenderPassBeginInfo::default() + .render_pass(self.ao_pass) + .framebuffer(self.refl_soft_framebuffer) + .render_area(vk::Rect2D { offset: vk::Offset2D::default(), extent: self.extent }), + vk::SubpassContents::INLINE, + ); + self.device.cmd_set_viewport(self.cmd, 0, &[vk::Viewport { x: 0.0, y: 0.0, width: self.extent.width as f32, height: self.extent.height as f32, min_depth: 0.0, max_depth: 1.0 }]); + self.device.cmd_set_scissor(self.cmd, 0, &[vk::Rect2D { offset: vk::Offset2D::default(), extent: self.extent }]); + } + } + + /// Ends the reflection low-pass. + pub fn end_refl_blur(&mut self) { + unsafe { self.device.cmd_end_render_pass(self.cmd) }; + } + + /// Builds the reflection mip chain from the reflection image just drawn (#302): level 1 is a bilinear half, level 2 + /// a quarter, and so on. The composite picks a level from the surface's roughness, so a gather is as smooth as the + /// blur it stands for. + pub fn build_reflection_mips(&mut self) { + unsafe { + let d = &self.device; + let cmd = self.cmd; + let range = |level: u32| vk::ImageSubresourceRange { + aspect_mask: vk::ImageAspectFlags::COLOR, + base_mip_level: level, + level_count: 1, + base_array_layer: 0, + layer_count: 1, + }; + let barrier = |image: vk::Image, level: u32, old: vk::ImageLayout, new: vk::ImageLayout, src: vk::PipelineStageFlags, dst: vk::PipelineStageFlags, src_access: vk::AccessFlags, dst_access: vk::AccessFlags| { + let b = vk::ImageMemoryBarrier::default() + .old_layout(old) + .new_layout(new) + .src_access_mask(src_access) + .dst_access_mask(dst_access) + .image(image) + .subresource_range(range(level)); + d.cmd_pipeline_barrier(cmd, src, dst, vk::DependencyFlags::empty(), &[], &[], &[b]); + }; + // What the low-pass wrote is a transfer source now. + barrier( + self.refl_soft_image, + 0, + vk::ImageLayout::SHADER_READ_ONLY_OPTIMAL, + vk::ImageLayout::TRANSFER_SRC_OPTIMAL, + vk::PipelineStageFlags::COLOR_ATTACHMENT_OUTPUT, + vk::PipelineStageFlags::TRANSFER, + vk::AccessFlags::COLOR_ATTACHMENT_WRITE, + vk::AccessFlags::TRANSFER_READ, + ); + let levels = 6u32; + for level in 0..levels { + let (src, src_image) = if level == 0 { (0, self.refl_soft_image) } else { (level - 1, self.refl_chain_image) }; + barrier( + self.refl_chain_image, + level, + vk::ImageLayout::UNDEFINED, + vk::ImageLayout::TRANSFER_DST_OPTIMAL, + vk::PipelineStageFlags::TRANSFER, + vk::PipelineStageFlags::TRANSFER, + vk::AccessFlags::empty(), + vk::AccessFlags::TRANSFER_WRITE, + ); + let (sw, sh) = (self.extent.width.max(1), self.extent.height.max(1)); + let src_extent = vk::Extent3D { width: (sw >> src).max(1), height: (sh >> src).max(1), depth: 1 }; + let dst_extent = vk::Extent3D { width: (sw >> level).max(1), height: (sh >> level).max(1), depth: 1 }; + let blit = vk::ImageBlit::default() + .src_subresource(vk::ImageSubresourceLayers::default().aspect_mask(vk::ImageAspectFlags::COLOR).mip_level(src).layer_count(1)) + .src_offsets([vk::Offset3D { x: 0, y: 0, z: 0 }, vk::Offset3D { x: src_extent.width as i32, y: src_extent.height as i32, z: 1 }]) + .dst_subresource(vk::ImageSubresourceLayers::default().aspect_mask(vk::ImageAspectFlags::COLOR).mip_level(level).layer_count(1)) + .dst_offsets([vk::Offset3D { x: 0, y: 0, z: 0 }, vk::Offset3D { x: dst_extent.width as i32, y: dst_extent.height as i32, z: 1 }]); + d.cmd_blit_image( + cmd, + src_image, + vk::ImageLayout::TRANSFER_SRC_OPTIMAL, + self.refl_chain_image, + vk::ImageLayout::TRANSFER_DST_OPTIMAL, + &[blit], + vk::Filter::LINEAR, + ); + // It is the next level's source, and in the end read by the post pass. + let next = if level + 1 < levels { vk::ImageLayout::TRANSFER_SRC_OPTIMAL } else { vk::ImageLayout::SHADER_READ_ONLY_OPTIMAL }; + barrier( + self.refl_chain_image, + level, + vk::ImageLayout::TRANSFER_DST_OPTIMAL, + next, + vk::PipelineStageFlags::TRANSFER, + if level + 1 < levels { vk::PipelineStageFlags::TRANSFER } else { vk::PipelineStageFlags::FRAGMENT_SHADER }, + vk::AccessFlags::TRANSFER_WRITE, + if level + 1 < levels { vk::AccessFlags::TRANSFER_READ } else { vk::AccessFlags::SHADER_READ }, + ); + } + // Levels 0 to 4 were left as sources; the post pass reads them. + for level in 0..levels - 1 { + barrier( + self.refl_chain_image, + level, + vk::ImageLayout::TRANSFER_SRC_OPTIMAL, + vk::ImageLayout::SHADER_READ_ONLY_OPTIMAL, + vk::PipelineStageFlags::TRANSFER, + vk::PipelineStageFlags::FRAGMENT_SHADER, + vk::AccessFlags::TRANSFER_READ, + vk::AccessFlags::SHADER_READ, + ); + } + barrier( + self.refl_soft_image, + 0, + vk::ImageLayout::TRANSFER_SRC_OPTIMAL, + vk::ImageLayout::SHADER_READ_ONLY_OPTIMAL, + vk::PipelineStageFlags::TRANSFER, + vk::PipelineStageFlags::FRAGMENT_SHADER, + vk::AccessFlags::TRANSFER_READ, + vk::AccessFlags::SHADER_READ, + ); + } + } + /// Ends the occlusion pass and begins the bounce light's second, into `bounce_image`. pub fn begin_bounce(&mut self) { unsafe { @@ -883,6 +1319,116 @@ impl Gpu { } } + /// Ends the bounce light's second pass and begins its low-pass along the view's rows, into `ao_image`, whose + /// first-pass light the second pass has already read. + pub fn begin_bounce_blur_h(&mut self) { + unsafe { + self.device.cmd_end_render_pass(self.cmd); + self.device.cmd_begin_render_pass( + self.cmd, + &vk::RenderPassBeginInfo::default() + .render_pass(self.ao_pass) + .framebuffer(self.ao_framebuffer) + .render_area(vk::Rect2D { offset: vk::Offset2D::default(), extent: self.extent }), + vk::SubpassContents::INLINE, + ); + self.device.cmd_set_viewport(self.cmd, 0, &[vk::Viewport { x: 0.0, y: 0.0, width: self.extent.width as f32, height: self.extent.height as f32, min_depth: 0.0, max_depth: 1.0 }]); + self.device.cmd_set_scissor(self.cmd, 0, &[vk::Rect2D { offset: vk::Offset2D::default(), extent: self.extent }]); + } + } + + /// Ends the row pass and begins the column pass, into `bounce_image` again. The column pass writes the image the + /// row pass read, so a barrier waits for that read before the attachment writes. + pub fn begin_bounce_blur_v(&mut self) { + unsafe { + self.device.cmd_end_render_pass(self.cmd); + self.device.cmd_pipeline_barrier( + self.cmd, + vk::PipelineStageFlags::FRAGMENT_SHADER, + vk::PipelineStageFlags::COLOR_ATTACHMENT_OUTPUT, + vk::DependencyFlags::empty(), + &[], + &[], + &[], + ); + self.device.cmd_begin_render_pass( + self.cmd, + &vk::RenderPassBeginInfo::default() + .render_pass(self.ao_pass) + .framebuffer(self.bounce_framebuffer) + .render_area(vk::Rect2D { offset: vk::Offset2D::default(), extent: self.extent }), + vk::SubpassContents::INLINE, + ); + self.device.cmd_set_viewport(self.cmd, 0, &[vk::Viewport { x: 0.0, y: 0.0, width: self.extent.width as f32, height: self.extent.height as f32, min_depth: 0.0, max_depth: 1.0 }]); + self.device.cmd_set_scissor(self.cmd, 0, &[vk::Rect2D { offset: vk::Offset2D::default(), extent: self.extent }]); + } + } + + /// Ends the scene pass (or the guides' after it) and begins the screen-space reflections, into `refl_image`. + pub fn begin_reflection(&mut self) { + unsafe { + self.device.cmd_end_render_pass(self.cmd); + self.device.cmd_begin_render_pass( + self.cmd, + &vk::RenderPassBeginInfo::default() + .render_pass(self.ao_pass) + .framebuffer(self.refl_framebuffer) + .render_area(vk::Rect2D { offset: vk::Offset2D::default(), extent: self.extent }), + vk::SubpassContents::INLINE, + ); + self.device.cmd_set_viewport(self.cmd, 0, &[vk::Viewport { x: 0.0, y: 0.0, width: self.extent.width as f32, height: self.extent.height as f32, min_depth: 0.0, max_depth: 1.0 }]); + self.device.cmd_set_scissor(self.cmd, 0, &[vk::Rect2D { offset: vk::Offset2D::default(), extent: self.extent }]); + } + } + + /// Begins the ground plane's reflection pass: the scene mirrored below the plane, into `planar_image` (#302). + pub fn begin_planar(&mut self) { + unsafe { + let clears = [ + vk::ClearValue { color: vk::ClearColorValue { float32: [0.0; 4] } }, + vk::ClearValue { depth_stencil: vk::ClearDepthStencilValue { depth: 0.0, stencil: 0 } }, + ]; + self.device.cmd_begin_render_pass( + self.cmd, + &vk::RenderPassBeginInfo::default() + .render_pass(self.planar_pass) + .framebuffer(self.planar_framebuffer) + .clear_values(&clears) + .render_area(vk::Rect2D { offset: vk::Offset2D::default(), extent: self.extent }), + vk::SubpassContents::INLINE, + ); + self.device.cmd_set_viewport(self.cmd, 0, &[vk::Viewport { x: 0.0, y: 0.0, width: self.extent.width as f32, height: self.extent.height as f32, min_depth: 0.0, max_depth: 1.0 }]); + self.device.cmd_set_scissor(self.cmd, 0, &[vk::Rect2D { offset: vk::Offset2D::default(), extent: self.extent }]); + } + } + + /// Ends the ground plane's reflection pass. + pub fn end_planar(&mut self) { + unsafe { self.device.cmd_end_render_pass(self.cmd) }; + } + + /// Begins the pass that draws the scene without its transmissive surfaces, for glass to see what it lets through + /// (#302). + pub fn begin_back(&mut self) { + unsafe { + self.device.cmd_begin_render_pass( + self.cmd, + &vk::RenderPassBeginInfo::default() + .render_pass(self.planar_pass) + .framebuffer(self.back_framebuffer) + .render_area(vk::Rect2D { offset: vk::Offset2D::default(), extent: self.extent }), + vk::SubpassContents::INLINE, + ); + self.device.cmd_set_viewport(self.cmd, 0, &[vk::Viewport { x: 0.0, y: 0.0, width: self.extent.width as f32, height: self.extent.height as f32, min_depth: 0.0, max_depth: 1.0 }]); + self.device.cmd_set_scissor(self.cmd, 0, &[vk::Rect2D { offset: vk::Offset2D::default(), extent: self.extent }]); + } + } + + /// Ends the behind-glass pass. + pub fn end_back(&mut self) { + unsafe { self.device.cmd_end_render_pass(self.cmd) }; + } + /// Ends the occlusion pass and begins the one that puts the picture on the window: it is drawn between this and /// `end_frame`. pub fn begin_post(&mut self, index: u32) { @@ -1035,6 +1581,7 @@ impl Drop for Gpu { } self.device.destroy_render_pass(self.post_pass, None); self.device.destroy_render_pass(self.ao_pass, None); + self.device.destroy_render_pass(self.planar_pass, None); self.shared.surface_fn.destroy_surface(self.surface, None); } } @@ -1046,6 +1593,10 @@ const SCENE_FORMAT: vk::Format = vk::Format::R16G16B16A16_SFLOAT; pub const AO_FORMAT: vk::Format = vk::Format::R16G16B16A16_SFLOAT; /// The surface colour the scene pass writes beside its picture. pub const ALBEDO_FORMAT: vk::Format = vk::Format::R8G8B8A8_UNORM; +/// The Realtime renderer's material: reflection colour in rgb, the roughness in a. +pub const MAT_FORMAT: vk::Format = vk::Format::R16G16B16A16_SFLOAT; +/// Transmission, IOR, metalness and whether a material is there, for the screen-space reflection pass (#302). +pub const MAT_AUX_FORMAT: vk::Format = vk::Format::R8G8B8A8_UNORM; pub fn color_range() -> vk::ImageSubresourceRange { vk::ImageSubresourceRange::default().aspect_mask(vk::ImageAspectFlags::COLOR).level_count(1).layer_count(1) @@ -1102,15 +1653,38 @@ unsafe fn scene_pass(device: &ash::Device, samples: vk::SampleCountFlags, overla if multi { attachments.push(resolved(ALBEDO_FORMAT)); } + // The material the screen-space reflection pass reads (#302). The overlay pass draws nothing into it: with one + // sample it is loaded and stored back as it was; with several it resolves into a spare of its own. + let keep_mat = overlay && !multi; + for format in [MAT_FORMAT, MAT_AUX_FORMAT] { + attachments.push( + vk::AttachmentDescription::default() + .format(format) + .samples(samples) + .load_op(if keep_mat { vk::AttachmentLoadOp::LOAD } else { vk::AttachmentLoadOp::CLEAR }) + .store_op(if multi { vk::AttachmentStoreOp::DONT_CARE } else { vk::AttachmentStoreOp::STORE }) + .initial_layout(if keep_mat { vk::ImageLayout::SHADER_READ_ONLY_OPTIMAL } else { vk::ImageLayout::UNDEFINED }) + .final_layout(if multi { vk::ImageLayout::COLOR_ATTACHMENT_OPTIMAL } else { vk::ImageLayout::SHADER_READ_ONLY_OPTIMAL }), + ); + if multi { + attachments.push(resolved(format)); + } + } let albedo = if multi { 3 } else { 2 }; + let mat = if multi { 5 } else { 3 }; + let mat_aux = if multi { 7 } else { 4 }; let color_ref = [ vk::AttachmentReference::default().attachment(0).layout(vk::ImageLayout::COLOR_ATTACHMENT_OPTIMAL), vk::AttachmentReference::default().attachment(albedo).layout(vk::ImageLayout::COLOR_ATTACHMENT_OPTIMAL), + vk::AttachmentReference::default().attachment(mat).layout(vk::ImageLayout::COLOR_ATTACHMENT_OPTIMAL), + vk::AttachmentReference::default().attachment(mat_aux).layout(vk::ImageLayout::COLOR_ATTACHMENT_OPTIMAL), ]; let depth_ref = vk::AttachmentReference::default().attachment(1).layout(vk::ImageLayout::DEPTH_STENCIL_ATTACHMENT_OPTIMAL); let resolve_ref = [ vk::AttachmentReference::default().attachment(2).layout(vk::ImageLayout::COLOR_ATTACHMENT_OPTIMAL), vk::AttachmentReference::default().attachment(4).layout(vk::ImageLayout::COLOR_ATTACHMENT_OPTIMAL), + vk::AttachmentReference::default().attachment(6).layout(vk::ImageLayout::COLOR_ATTACHMENT_OPTIMAL), + vk::AttachmentReference::default().attachment(8).layout(vk::ImageLayout::COLOR_ATTACHMENT_OPTIMAL), ]; let mut sp = vk::SubpassDescription::default() .pipeline_bind_point(vk::PipelineBindPoint::GRAPHICS) @@ -1134,6 +1708,38 @@ unsafe fn scene_pass(device: &ash::Device, samples: vk::SampleCountFlags, overla Ok(device.create_render_pass(&vk::RenderPassCreateInfo::default().attachments(&attachments).subpasses(&subpass).dependencies(&dep), None)?) } +/// The pass the ground plane's reflection is drawn in (#302): the scene mirrored below the plane, in the display's own +/// colour at one sample a pixel, with depth of its own. +unsafe fn planar_pass(device: &ash::Device) -> Res { + let attachments = [ + vk::AttachmentDescription::default() + .format(AO_FORMAT) + .samples(vk::SampleCountFlags::TYPE_1) + .load_op(vk::AttachmentLoadOp::CLEAR) + .store_op(vk::AttachmentStoreOp::STORE) + .initial_layout(vk::ImageLayout::UNDEFINED) + .final_layout(vk::ImageLayout::SHADER_READ_ONLY_OPTIMAL), + vk::AttachmentDescription::default() + .format(DEPTH_FORMAT) + .samples(vk::SampleCountFlags::TYPE_1) + .load_op(vk::AttachmentLoadOp::CLEAR) + .store_op(vk::AttachmentStoreOp::DONT_CARE) + .initial_layout(vk::ImageLayout::UNDEFINED) + .final_layout(vk::ImageLayout::DEPTH_STENCIL_ATTACHMENT_OPTIMAL), + ]; + let color_ref = [vk::AttachmentReference::default().attachment(0).layout(vk::ImageLayout::COLOR_ATTACHMENT_OPTIMAL)]; + let depth_ref = vk::AttachmentReference::default().attachment(1).layout(vk::ImageLayout::DEPTH_STENCIL_ATTACHMENT_OPTIMAL); + let subpass = [vk::SubpassDescription::default().pipeline_bind_point(vk::PipelineBindPoint::GRAPHICS).color_attachments(&color_ref).depth_stencil_attachment(&depth_ref)]; + let dep = [vk::SubpassDependency::default() + .src_subpass(vk::SUBPASS_EXTERNAL) + .dst_subpass(0) + .src_stage_mask(vk::PipelineStageFlags::COLOR_ATTACHMENT_OUTPUT | vk::PipelineStageFlags::EARLY_FRAGMENT_TESTS) + .dst_stage_mask(vk::PipelineStageFlags::COLOR_ATTACHMENT_OUTPUT | vk::PipelineStageFlags::EARLY_FRAGMENT_TESTS) + .src_access_mask(vk::AccessFlags::COLOR_ATTACHMENT_WRITE | vk::AccessFlags::SHADER_READ) + .dst_access_mask(vk::AccessFlags::COLOR_ATTACHMENT_WRITE | vk::AccessFlags::DEPTH_STENCIL_ATTACHMENT_WRITE)]; + Ok(device.create_render_pass(&vk::RenderPassCreateInfo::default().attachments(&attachments).subpasses(&subpass).dependencies(&dep), None)?) +} + /// What the environment asks for: AZTEK_MSAA=1, 2, 4 or 8. Four without it. fn wanted_samples() -> u32 { std::env::var("AZTEK_MSAA").ok().and_then(|v| v.parse().ok()).unwrap_or(4) diff --git a/crates/aztek_host/src/lighting.rs b/crates/aztek_host/src/lighting.rs index 5b4fcd0c..ed70046e 100644 --- a/crates/aztek_host/src/lighting.rs +++ b/crates/aztek_host/src/lighting.rs @@ -415,9 +415,11 @@ fn scene_bounds(items: &[crate::viewport::DrawItem]) -> (DVec3, DVec3) { /// A view's lighting buffers and descriptor set. pub struct ViewLights { block: Buffer, + planar_block: Buffer, speculars: Buffer, pool: vk::DescriptorPool, pub set: vk::DescriptorSet, + pub planar_set: vk::DescriptorSet, /// Indices into the highlight table, by shading group. 0 is no highlight. pub index: HashMap, /// The shapes whose mask isn't all lights. @@ -454,27 +456,34 @@ impl ViewLights { lights: [GpuLight::zeroed(); MAX_LIGHTS], }; let block = gpu.buffer_with(vk::BufferUsageFlags::UNIFORM_BUFFER, std::slice::from_ref(&start)); + let planar_block = gpu.buffer_with(vk::BufferUsageFlags::UNIFORM_BUFFER, std::slice::from_ref(&start)); let speculars = gpu.buffer_with(vk::BufferUsageFlags::UNIFORM_BUFFER, &vec![[[0.0f32; 4]; 2]; MAX_SPECULARS]); unsafe { let d = &gpu.device; - let sizes = [vk::DescriptorPoolSize::default().ty(vk::DescriptorType::UNIFORM_BUFFER).descriptor_count(2)]; - let pool = d.create_descriptor_pool(&vk::DescriptorPoolCreateInfo::default().max_sets(1).pool_sizes(&sizes), None).expect("light pool"); - let layouts = [r.light_layout]; - let set = d.allocate_descriptor_sets(&vk::DescriptorSetAllocateInfo::default().descriptor_pool(pool).set_layouts(&layouts)).expect("light set")[0]; + let sizes = [vk::DescriptorPoolSize::default().ty(vk::DescriptorType::UNIFORM_BUFFER).descriptor_count(4)]; + let pool = d.create_descriptor_pool(&vk::DescriptorPoolCreateInfo::default().max_sets(2).pool_sizes(&sizes), None).expect("light pool"); + let layouts = [r.light_layout, r.light_layout]; + let sets = d.allocate_descriptor_sets(&vk::DescriptorSetAllocateInfo::default().descriptor_pool(pool).set_layouts(&layouts)); + let (set, planar_set) = (sets.as_ref().expect("light sets")[0], sets.as_ref().expect("light sets")[1]); let infos = [ [vk::DescriptorBufferInfo::default().buffer(block.buffer).offset(0).range(std::mem::size_of::() as u64)], [vk::DescriptorBufferInfo::default().buffer(speculars.buffer).offset(0).range((MAX_SPECULARS * 32) as u64)], + [vk::DescriptorBufferInfo::default().buffer(planar_block.buffer).offset(0).range(std::mem::size_of::() as u64)], ]; let writes = [ vk::WriteDescriptorSet::default().dst_set(set).dst_binding(0).descriptor_type(vk::DescriptorType::UNIFORM_BUFFER).buffer_info(&infos[0]), vk::WriteDescriptorSet::default().dst_set(set).dst_binding(1).descriptor_type(vk::DescriptorType::UNIFORM_BUFFER).buffer_info(&infos[1]), + vk::WriteDescriptorSet::default().dst_set(planar_set).dst_binding(0).descriptor_type(vk::DescriptorType::UNIFORM_BUFFER).buffer_info(&infos[2]), + vk::WriteDescriptorSet::default().dst_set(planar_set).dst_binding(1).descriptor_type(vk::DescriptorType::UNIFORM_BUFFER).buffer_info(&infos[1]), ]; d.update_descriptor_sets(&writes, &[]); ViewLights { block, + planar_block, speculars, pool, set, + planar_set, index: HashMap::new(), masks: HashMap::new(), mask_key: None, @@ -536,27 +545,36 @@ impl ViewLights { /// This frame's block. `lights` are what the mode chose; `shadow` the light and its world-to-clip matrix when the /// Realtime renderer draws one. pub fn write_block(&mut self, mode: LightMode, lights: &[SceneLight], view: &DMat4, proj: &DMat4, two_sided: bool, ortho: bool, shadow: Option) { + self.write_block_at(false, mode, lights, view, proj, two_sided, ortho, shadow); + } + + /// The block the planar reflection draws with, in the planar buffer: the main view and lights, and no shadow map. + pub fn write_planar_block(&mut self, mode: LightMode, lights: &[SceneLight], view: &DMat4, proj: &DMat4, two_sided: bool, ortho: bool) { + self.write_block_at(true, mode, lights, view, proj, two_sided, ortho, None); + } + + fn write_block_at(&mut self, planar: bool, mode: LightMode, lights: &[SceneLight], view: &DMat4, proj: &DMat4, two_sided: bool, ortho: bool, shadow: Option) { + let target = if planar { &self.planar_block } else { &self.block }; let path = mode.shader_mode(); - // The default path reads nothing of the block but its head. + // The default path reads only its head and the inverse projection, which the view's position and size change + // every frame; writing it is cheap. if path == 0 { - if !self.written_default { - write( - &self.block, - std::slice::from_ref(&LightBlock { - inv_proj: DMat4::IDENTITY.as_mat4().to_cols_array(), - head: [0; 4], - shadow_matrix: DMat4::IDENTITY.as_mat4().to_cols_array(), - shadow: [-1.0; 4], - shadow_pos: [0.0; 4], - shadow_range: [0.0; 4], - env: [0.0; 4], - env_rot: [0.0, 0.0, 0.0, 1.0], - view_to_world: DMat4::IDENTITY.as_mat4().to_cols_array(), - lights: [GpuLight::zeroed(); MAX_LIGHTS], - }), - ); - self.written_default = true; - } + write( + target, + std::slice::from_ref(&LightBlock { + inv_proj: proj.inverse().as_mat4().to_cols_array(), + head: [0; 4], + shadow_matrix: DMat4::IDENTITY.as_mat4().to_cols_array(), + shadow: [-1.0; 4], + shadow_pos: [0.0; 4], + shadow_range: [0.0; 4], + env: [0.0; 4], + env_rot: [0.0, 0.0, 0.0, 1.0], + view_to_world: view.inverse().as_mat4().to_cols_array(), + lights: [GpuLight::zeroed(); MAX_LIGHTS], + }), + ); + self.written_default = true; return; } self.written_default = false; @@ -585,7 +603,7 @@ impl ViewLights { } block.lights[i] = g; } - write(&self.block, std::slice::from_ref(&block)); + write(target, std::slice::from_ref(&block)); } /// Which lights each drawn shape takes, when the scene or the lights have changed. Empty, and cheap, while every light @@ -613,9 +631,16 @@ impl ViewLights { self.masks.get(&shape).copied().unwrap_or(ALL_LIGHTS) } + /// The sky dome the frame's reflection pass falls back on: its colour and strength (w 1 with an image), its rotation, + /// and the descriptor set holding the image. + pub fn environment(&self) -> ([f32; 4], [f32; 4], Option) { + (self.env, self.env_rot, self.env_set) + } + pub fn release(self, gpu: &mut Gpu) { unsafe { gpu.device.destroy_descriptor_pool(self.pool, None) }; gpu.drop_buffer(self.block); + gpu.drop_buffer(self.planar_block); gpu.drop_buffer(self.speculars); } } diff --git a/crates/aztek_host/src/panel_cmds.rs b/crates/aztek_host/src/panel_cmds.rs index e36cb0bf..36973bca 100644 --- a/crates/aztek_host/src/panel_cmds.rs +++ b/crates/aztek_host/src/panel_cmds.rs @@ -164,6 +164,9 @@ const DISP: &[(&str, &str)] = &[ ("lights", "lights"), ("twoSided", "twoSidedLighting"), ("shadows", "shadows"), + ("bounceLight", "bounceLight"), + ("ambientOcclusion", "ambientOcclusion"), + ("depthOfField", "depthOfField"), ("manipulators", "manipulators"), ("xray", "xray"), ("xrayJoints", "jointXray"), @@ -249,7 +252,7 @@ fn get_panel(a: &Args) -> CmdResult { }) } -const EDITOR_FLAGS: &str = "activeOnly:ao:b activeView:av:b allObjects:alo:b backfaceCulling:bfc:b camera:cam:a cameras:ca:b clipGhosts:cg:b controlVertices:cv:b controllers:ctrl:b deformers:df:b dimensions:dim:b displayAppearance:da:a displayLights:dl:a displayTextures:dtx:b dynamicConstraints:dc:b dynamics:dy:b fluids:fl:b follicles:fo:b fogging:fg:b grid:gr:b hairSystems:hs:b handles:ha:b headsUpDisplay:hud:b hulls:hu:b ikHandles:ikh:b imagePlane:imp:b joints:j:b jointXray:jx:b lights:lt:b locators:lc:b lockMainConnection:lck:b lowQualityLighting:lql:b manipulators:m:b motionTrails:mt:b nCloths:ncl:b nParticles:npa:b nRigids:nr:b nurbsCurves:nc:b nurbsSurfaces:ns:b objectFilterShowInHUD:ofs:b panel:pnl:a parent:p:a pivots:pv:b planes:pl:b pluginObjects:po:a2 pluginShapes:ps:b polymeshes:pm:b rendererName:rnm:a selectionHiliteDisplay:sel:b shadows:sdw:b smoothWireframe:swf:b sortTransparent:st:b strokes:str:b subdivSurfaces:sds:b textures:tx:b twoSidedLighting:tsl:b useDefaultMaterial:udm:b viewObjects:vo:b viewSelected:vs:b wireframeBackingStore:wbs:b wireframeOnShaded:wos:b xray:xr:b activeComponentsXray:acx:b exists:ex:b query:q:b edit:e:b queried::a"; +const EDITOR_FLAGS: &str = "activeOnly:ao:b activeView:av:b allObjects:alo:b ambientOcclusion:aoc:b backfaceCulling:bfc:b bounceLight:bl:b depthOfField:dof:b camera:cam:a cameras:ca:b clipGhosts:cg:b controlVertices:cv:b controllers:ctrl:b deformers:df:b dimensions:dim:b displayAppearance:da:a displayLights:dl:a displayTextures:dtx:b dynamicConstraints:dc:b dynamics:dy:b fluids:fl:b follicles:fo:b fogging:fg:b grid:gr:b hairSystems:hs:b handles:ha:b headsUpDisplay:hud:b hulls:hu:b ikHandles:ikh:b imagePlane:imp:b joints:j:b jointXray:jx:b lights:lt:b locators:lc:b lockMainConnection:lck:b lowQualityLighting:lql:b manipulators:m:b motionTrails:mt:b nCloths:ncl:b nParticles:npa:b nRigids:nr:b nurbsCurves:nc:b nurbsSurfaces:ns:b objectFilterShowInHUD:ofs:b panel:pnl:a parent:p:a pivots:pv:b planes:pl:b pluginObjects:po:a2 pluginShapes:ps:b polymeshes:pm:b rendererName:rnm:a selectionHiliteDisplay:sel:b shadows:sdw:b smoothWireframe:swf:b sortTransparent:st:b strokes:str:b subdivSurfaces:sds:b textures:tx:b twoSidedLighting:tsl:b useDefaultMaterial:udm:b viewObjects:vo:b viewSelected:vs:b wireframeBackingStore:wbs:b wireframeOnShaded:wos:b xray:xr:b activeComponentsXray:acx:b exists:ex:b query:q:b edit:e:b queried::a"; fn add_spec(mut c: Cmd, spec: &str) -> Cmd { for t in spec.split_whitespace() { @@ -306,7 +309,8 @@ fn editor_default(flag: &str) -> Value { "displayAppearance" => json!("smoothShaded"), "displayLights" => json!("default"), "rendererName" => json!("vp2Renderer"), - "headsUpDisplay" | "selectionHiliteDisplay" | "twoSidedLighting" => json!(true), + "headsUpDisplay" | "selectionHiliteDisplay" | "twoSidedLighting" | "bounceLight" => json!(true), + "ambientOcclusion" | "depthOfField" => json!(false), "displayTextures" | "wireframeOnShaded" | "xray" | "jointXray" | "activeComponentsXray" | "backfaceCulling" | "useDefaultMaterial" | "activeOnly" | "viewSelected" | "shadows" => json!(false), k if OBJECT_FLAGS.contains(&k) => json!(true), _ => Value::Null, diff --git a/crates/aztek_host/src/post.rs b/crates/aztek_host/src/post.rs index cffdb75a..f49bcada 100644 --- a/crates/aztek_host/src/post.rs +++ b/crates/aztek_host/src/post.rs @@ -31,6 +31,21 @@ layout(set = 0, binding = 3) uniform texture2D t_open; layout(set = 0, binding = 5) uniform texture2D t_albedo; // The view's guides, drawn after the scene onto a clear layer, premultiplied by their alpha (#300). layout(set = 0, binding = 6) uniform texture2D t_overlay; +// The Realtime renderer's material (#302): reflection colour and roughness, then transmission, IOR and metalness. +layout(set = 0, binding = 7) uniform texture2D t_mat; +layout(set = 0, binding = 8) uniform texture2D t_mat_aux; +// The reflections and refraction the reflection pass worked out from these. +layout(set = 0, binding = 9) uniform texture2D t_refl; +// The scene mirrored below the ground plane, for the floor's reflection (#302). +layout(set = 0, binding = 10) uniform texture2D t_planar; +// The scene without its transmissive surfaces, for glass to see what it lets through (#302). +layout(set = 0, binding = 11) uniform texture2D t_back; +// The reflection image low-passed over a few pixels, so one bright texel does not speckle (#302). +layout(set = 0, binding = 12) uniform texture2D t_refl_soft; +layout(set = 0, binding = 13) uniform sampler s_refl; +// The view's sky dome, which reflections fall back on where the view shows nothing to reflect. +layout(set = 1, binding = 0) uniform texture2D t_env; +layout(set = 1, binding = 1) uniform sampler s_env; layout(push_constant) uniform P { // Clip space back to the camera's. mat4 inv_proj; @@ -51,12 +66,19 @@ layout(set = 0, binding = 4, std140) uniform Params { // Contact shadow strength, and whether it is on (0 off). vec4 contact; // x: 1 when the Realtime renderer asks for the finer occlusion (more taps, a wider blur). y: how strong the bounce - // light is, 0 with it off. + // light is, 0 with it off. z: 1 when the screen-space reflections are on. vec4 quality; // Depth of field. x: the lens's radius in pixels at unit distance (blur = x * |1/distance - y|); y: one over the // distance in focus; z: the widest blur in pixels, 0 with it off; w: 1 when only shaded surfaces blur (the // Realtime renderer marks them in the albedo's alpha). vec4 dof; + // View space back to world, for a reflection looked up in the environment. + mat4 view_to_world; + // The sky dome's colour and strength, w 1 when an image feeds it; and its world-to-dome rotation. + vec4 env; + vec4 env_rot; + // x: 1 with a ground plane's reflection, yzw: the world's up. + vec4 extra; } pp; float depth_at(vec2 px) { @@ -118,9 +140,12 @@ ivec2 covered_near(ivec2 q) { return best; } -// Noise that differs from pixel to pixel with no pattern the eye picks out. +// Noise that differs from pixel to pixel with no pattern the eye picks out. The integer hash spreads the low bits +// over both axes; the sine-free form avoids the diagonal bands a cheap dot-and-fract leaves on a screen grid. float noise(vec2 px) { - return fract(52.9829189 * fract(dot(px, vec2(0.06711056, 0.00583715)))); + vec3 p3 = fract(vec3(px.xyx) * 0.1031); + p3 += dot(p3, p3.yzx + 33.33); + return fract((p3.x + p3.y) * p3.z); } void main() { @@ -198,7 +223,10 @@ void main() { // weighted by the cosine, so the surface's colour times it is the light it bounces: rays that leave the view bring // none. Only what the view shows gives light, so it costs the same however the lights move. vec3 gi = vec3(0.0); - if (pp.quality.y > 0.0 && texelFetch(sampler2D(t_albedo, s_point), ivec2(c), 0).a > 0.0) { + // A metal has no diffuse bounce, and glass lets light through rather than bouncing it back. + vec4 aux_here = texelFetch(sampler2D(t_mat_aux, s_point), ivec2(c), 0); + bool diffuse_here = aux_here.b <= 0.5 && aux_here.r <= 0.5; + if (pp.quality.y > 0.0 && diffuse_here && texelFetch(sampler2D(t_albedo, s_point), ivec2(c), 0).a > 0.0) { vec3 tn = normalize(cross(n, abs(n.y) < 0.9 ? vec3(0.0, 1.0, 0.0) : vec3(1.0, 0.0, 0.0))); vec3 bn = cross(n, tn); // How far a ray goes: as far as the point is from the eye, which spans what the view shows. @@ -206,6 +234,7 @@ void main() { float jitter = noise(c.yx + vec2(17.0, 5.0)); // Rays leave a little off the surface, so those that skim along it don't meet it again in its own depth. vec3 from = p + n * (0.01 * reach); + // The bounce's grain is the few stochastic hits a pixel gets; the clamp and the filter carry the rest. const int RAYS = 12; vec3 hit_albedo = vec3(0.0); float hits = 0.0, gone = 0.0; @@ -236,7 +265,7 @@ void main() { // gap closes, the ray met that surface, however edge-on it is to the eye; when it stays open, the // ray only passed behind something standing in front, and goes on. float lo = t_last, hi = t; - for (int b = 0; b < 5; ++b) { + for (int b = 0; b < 8; ++b) { float mid = 0.5 * (lo + hi); if (behind_at(from + dir * mid) > 0.0) hi = mid; else lo = mid; } @@ -245,9 +274,12 @@ void main() { vec4 clip = pp.proj * vec4(at, 1.0); ivec2 q = covered_near(ivec2(clip.xy / clip.w * 0.5 * pc.size.xy + 0.5 * pc.size.xy)); vec3 hit_colour = texelFetch(sampler2D(t_albedo, s_point), q, 0).rgb; - gi += pow(texelFetch(sampler2D(t_scene, s_point), q, 0).rgb, vec3(2.2)); + // A ray that lands on a specular highlight must not carry it back as a bright texel: one such + // hit would light a whole square of the filter's footprint. The offline path clamps its + // indirect samples for the same reason. + gi += min(pow(max(texelFetch(sampler2D(t_scene, s_point), q, 0).rgb, vec3(0.0)), vec3(2.2)), vec3(4.0)); // The second time round, the surface met also sends back what the first bounce brought it. - if (second) gi += hit_colour * texelFetch(sampler2D(t_open, s_point), q, 0).rgb; + if (second) gi += min(hit_colour * texelFetch(sampler2D(t_open, s_point), q, 0).rgb, vec3(4.0)); hit_albedo += hit_colour; hits += 1.0; break; @@ -274,6 +306,245 @@ void main() { } "#; +/// The bounce light low-passed along one axis: the rays that found it are stochastic, and indirect light is not, so a +/// separable Gaussian turns the grain into a soft field before the picture reads it (#302). +const BOUNCE_BLUR_MAIN: &str = r#" +void main() { + vec2 c = floor(gl_FragCoord.xy) + 0.5; + vec2 dir = pc.bg_top.xy; + float sigma = max(pc.bg_top.z, 0.5); + int radius = int(clamp(ceil(sigma * 2.5), 1.0, 16.0)); + vec4 sum = vec4(0.0); + float total = 0.0; + for (int i = -16; i <= 16; ++i) { + if (i < -radius || i > radius) continue; + float f = float(i); + float w = exp(-f * f / (2.0 * sigma * sigma)); + ivec2 at = clamp(ivec2(c + dir * f), ivec2(0), ivec2(pc.size.xy) - 1); + sum += textureLod(sampler2D(t_open, s_refl), (vec2(at) + 0.5) / pc.size.xy, 0.0) * w; + total += w; + } + // The openness and contact shadow share the buffer and the rays' grain, so they are low-passed with them: a sharp + // alpha against the soft light made the contact shadow's steps show on the sphere's dark side. + o = sum / max(total, 1e-6); +} +"#; + +/// Screen-space reflections and refraction (#302): what a material's reflection sees of the scene, and what glass lets +/// through, in linear light. The environment stands in where the view shows nothing to reflect. +const REFLECT_MAIN: &str = r#" +const float PI = 3.141592653589793; + +float noise_at(vec2 px) { + return fract(52.9829189 * fract(dot(px, vec2(0.06711056, 0.00583715)))); +} +vec3 qrot(vec4 q, vec3 v) { + return v + 2.0 * cross(q.xyz, cross(q.xyz, v) + q.w * v); +} +// The sky dome a reflection sees, at the roughness's blur. +vec3 env_lookup(vec3 dir, float rough) { + if (pp.env.w < 0.5 && dot(pp.env.rgb, pp.env.rgb) <= 0.0) return vec3(0.0); + vec3 wd = normalize((pp.view_to_world * vec4(dir, 0.0)).xyz); + vec3 ld = normalize(qrot(pp.env_rot, wd)); + vec2 uv = vec2(atan(ld.z, ld.x) / (2.0 * PI) + 0.5, acos(clamp(ld.y, -1.0, 1.0)) / PI); + vec3 env = pp.env.w > 0.5 ? textureLod(sampler2D(t_env, s_env), uv, rough * 6.0).rgb : vec3(1.0); + return env * pp.env.rgb; +} +// The ground plane's reflection: the scene mirrored below the world's ground, read where the surface is that plane. +// cover comes back 1 there and 0 elsewhere; where the mirrored scene shows nothing the sky stands in. +vec3 planar_at(vec2 c, vec3 p, vec3 n, vec3 r, float rough, out float cover) { + vec3 wp = (pp.view_to_world * vec4(p, 1.0)).xyz; + vec3 wn = normalize((pp.view_to_world * vec4(n, 0.0)).xyz); + vec3 up = normalize(pp.extra.yzw); + cover = smoothstep(0.86, 0.98, dot(wn, up)) * (1.0 - smoothstep(0.04, 0.25, abs(dot(wp, up)))); + float planarity = cover; + if (pp.extra.x < 0.5 || cover <= 0.001) return vec3(0.0); + // A few pixels around the sample: the planar image's edge is a hard silhouette, and the weight that hands over to + // the screen-space reflection has to cross it gradually. + ivec2 at = ivec2(c); + ivec2 top = ivec2(pc.size.xy) - 1; + vec3 plane = vec3(0.0); + // How much of the sample is mirrored scene: the planar pass clears to transparent black, so its alpha is the + // coverage. Lightness is not coverage: a mirrored sphere's own shadowed side is dark and still a reflection. + float data = 0.0; + for (int y = -1; y <= 1; ++y) { + for (int x = -1; x <= 1; ++x) { + ivec2 q = clamp(at + ivec2(x, y), ivec2(0), top); + // Linear filtering, so the mirrored silhouette hands over to the floor without a stepped edge. + vec4 t = textureLod(sampler2D(t_planar, s_refl), (vec2(q) + 0.5) / pc.size.xy, 0.0); + plane += pow(max(t.rgb, vec3(0.0)), vec3(2.2)); + data += t.a; + } + } + plane /= 9.0; + // Where the planar image has nothing, the screen-space reflection stands in: the weight falls away at the image's + // edge and with roughness, and the two are mixed by one minus the other in the caller. + data = smoothstep(0.0, 0.5, data / 9.0); + float rough_w = 1.0 - 0.5 * smoothstep(0.15, 0.7, rough); + // The plane itself takes the planar image, fading to the sky where the image has nothing. The screen-space march + // fills in on surfaces that are not the mirror, and only partly here where the surface is rough. + cover = planarity * rough_w; + return mix(env_lookup(r, rough), plane, data); +} +// Where a view-space ray first goes behind what the view shows. Glass is passed through: a refracted ray starts behind +// it, and a reflected one sees what is behind glass too. colour comes back in linear light. +bool scene_hit(vec3 from, vec3 dir, float jitter, out vec3 colour, out float travelled) { + float scale = max(length(from), 1.0); + float span = clamp(scale * 12.0, 4.0, 240.0); + float thick = 0.01 * scale + 0.002; + float start = 0.05 * scale; + float prev = start; + bool was_in_front = false; + ivec2 top = ivec2(pc.size.xy) - 1; + for (int i = 0; i < 64; ++i) { + float f = (float(i) + jitter) / 64.0; + float t = start + span * f * f; + vec3 p = from + dir * t; + vec4 clip = pp.proj * vec4(p, 1.0); + if (clip.w <= 0.0) break; + vec2 ndc = clip.xy / clip.w; + if (abs(ndc.x) > 1.0 || abs(ndc.y) > 1.0) break; + ivec2 at = clamp(ivec2((ndc * 0.5 + 0.5) * pc.size.xy), ivec2(0), top); + vec2 c = vec2(at) + 0.5; + float dq = depth_at(c); + if (dq <= 0.0) { + prev = t; + was_in_front = true; + continue; + } + // Glass does not stop the ray: what is behind it is what a reflection or a refraction sees. + if (texelFetch(sampler2D(t_mat_aux, s_point), at, 0).r > 0.5) { + prev = t; + was_in_front = true; + continue; + } + vec3 q = point_at(c, dq); + bool behind = -p.z > -q.z + thick; + if (behind && was_in_front) { + float lo = prev; + float hi = t; + for (int b = 0; b < 8; ++b) { + float mid = 0.5 * (lo + hi); + vec3 mp = from + dir * mid; + vec4 mc = pp.proj * vec4(mp, 1.0); + if (mc.w <= 0.0) break; + vec2 ms = mc.xy / mc.w * 0.5 + 0.5; + float md = depth_at(ms * pc.size.xy); + if (md > 0.0 && -mp.z > -point_at(ms * pc.size.xy, md).z + thick) hi = mid; else lo = mid; + } + vec3 hp = from + dir * hi; + vec4 hc = pp.proj * vec4(hp, 1.0); + if (hc.w > 0.0) { + vec2 hs = hc.xy / hc.w * 0.5 + 0.5; + ivec2 hat = clamp(ivec2(hs * pc.size.xy), ivec2(0), top); + if (texelFetch(sampler2D(t_mat_aux, s_point), hat, 0).r <= 0.5) { + colour = pow(texelFetch(sampler2D(t_scene, s_point), hat, 0).rgb, vec3(2.2)); + travelled = hi; + return true; + } + } + } + prev = t; + was_in_front = !behind; + } + return false; +} + +void main() { + vec2 c = floor(gl_FragCoord.xy) + 0.5; + ivec2 at = ivec2(c); + vec4 m = texelFetch(sampler2D(t_mat, s_point), at, 0); + vec4 aux = texelFetch(sampler2D(t_mat_aux, s_point), at, 0); + float d = depth_at(c); + if (aux.a < 0.5 || d <= 0.0) { + o = vec4(0.0); + return; + } + vec3 p = point_at(c, d); + vec3 n = normal_at(c, d, p); + vec3 v = normalize(p); + float rough = clamp(m.a - 0.002, 0.02, 1.0); + float transmission = clamp(aux.r, 0.0, 1.0); + if (int(pp.quality.w) == 10) { + o = vec4(pp.extra.x > 0.5 ? vec3(0.0, 1.0, 0.0) : vec3(1.0, 0.0, 0.0), 1.0); + return; + } + float ior = 1.0 + clamp(aux.g, 0.0, 1.0) * 2.0; + vec3 coeff = max(m.rgb, vec3(0.0)); + vec3 sum = vec3(0.0); + float lift = 0.01 * length(p) + 0.002; + // Glass: the scene behind it, bent by the IOR and tinted by its transmission colour, falling off with the distance + // through it (#302). The view has no colour behind the glass itself, so the lookup moves out to what it shows round + // about: the background is seen through the glass, bent, as a lens does. Aztek has no transmission depth, so the + // distance the lookup travels stands in for it. + if (transmission > 0.5) { + vec3 dir = refract(v, n, 1.0 / ior); + if (dot(dir, dir) < 1e-6) dir = reflect(v, n); + // A lens: the image bends out towards the rim, where the surface turns away from the eye. + vec2 radial = vec2(n.x, -n.y); + float edge = 1.0 - clamp(abs(n.z), 0.0, 1.0); + vec2 offs = normalize(radial + vec2(0.0001)) * (edge * edge * 200.0); + vec2 q = clamp(c + offs, vec2(1.0), pc.size.xy - 2.0); + // The background behind the glass, drawn without it, seen through the bend and tinted. A few taps smooth the + // edge the bend crosses. + vec3 behind = vec3(0.0); + for (int y = -1; y <= 1; ++y) { + for (int x = -1; x <= 1; ++x) { + ivec2 qi = clamp(ivec2(q) + ivec2(x, y), ivec2(0), ivec2(pc.size.xy) - 1); + behind += pow(max(texelFetch(sampler2D(t_back, s_point), qi, 0).rgb, vec3(0.0)), vec3(2.2)); + } + } + behind /= 9.0; + float travelled = length(offs); + vec3 tint = texelFetch(sampler2D(t_albedo, s_point), at, 0).rgb; + // The tint the glass gives what it lets through; the bend's length shades it a little. A dark background + // behind the glass must not swallow it whole: keep its own transmission colour as a floor, so it never reads + // blacker than the background it lets through. + vec3 through = behind * tint * 1.4 * exp(-travelled * 0.005); + float through_lum = dot(through, vec3(0.2126, 0.7152, 0.0722)); + through = max(through, tint * (0.3 * (1.0 - smoothstep(0.04, 0.30, through_lum)))); + sum += through; + } + // The reflection: the scene where the view shows it, the sky where it doesn't. Glossy surfaces are smoothed over + // the reflection image in the composite, from their roughness. + vec3 r = reflect(v, n); + vec3 hit; + float travelled; + // A mirror marches at a fixed phase: the jitter that rougher surfaces need would only grain it. + float jitter = rough < 0.08 ? 0.5 : noise_at(c); + vec3 refl = scene_hit(p + n * lift, r, jitter, hit, travelled) ? hit : env_lookup(r, rough); + float planar_cover; + vec3 planar = planar_at(c, p, n, r, rough, planar_cover); + if (int(pp.quality.w) == 11) { + o = vec4(vec3(planar_cover), 1.0); + return; + } + // The two tiers are mixed by one weight, so their sum is the one reflection. Both take the same brightness scale + // and go through the same filtered copy by the surface's roughness. + refl = mix(refl, planar, planar_cover) * 1.3; + sum += refl * coeff; + o = vec4(sum, 1.0); +} +"#; + +/// A small low-pass of the reflection image: a bright texel from a mirrored specular highlight is spread over its +/// neighbours before a rough surface gathers it, so it does not come back as a speckle (#302). +const REFL_BLUR_MAIN: &str = r#" +void main() { + vec2 c = floor(gl_FragCoord.xy) + 0.5; + ivec2 at = ivec2(c); + ivec2 top = ivec2(pc.size.xy) - 1; + vec3 sum = vec3(0.0); + for (int y = -1; y <= 1; ++y) { + for (int x = -1; x <= 1; ++x) { + ivec2 q = clamp(at + ivec2(x, y), ivec2(0), top); + sum += clamp(texelFetch(sampler2D(t_refl, s_point), q, 0).rgb, vec3(0.0), vec3(8.0)); + } + } + o = vec4(sum / 9.0, 1.0); +} +"#; + /// The picture: the scene's colour, darkened by how closed in each pixel is, with the bounce light the surface's colour /// sends back. Both are smoothed over the pixels round about that lie on the same surface, which takes the sampling's /// grain out and keeps edges sharp. @@ -292,8 +563,48 @@ bool effects_off() { return pc.ao.z < 0.5 && pp.contact.x <= 0.0 && pp.quality.y <= 0.0; } -// The scene's colour with the occlusion and bounce light (`got`, rgb bounce and alpha openness) on it. -vec3 lit(vec3 color, vec4 got, ivec2 at) { +// The reflection image at a pixel, smoothed over the surface round about as the material's roughness asks: a mirror +// keeps one ray, a rough metal gathers its neighbourhood. Neighbouring pixels on another surface are left out, so an +// edge stays an edge. +vec3 reflection_at(ivec2 at, float d) { + float rough = texelFetch(sampler2D(t_mat, s_point), at, 0).a - 0.002; + vec2 uv = (vec2(at) + 0.5) / pc.size.xy; + if (d <= 0.0) return textureLod(sampler2D(t_refl_soft, s_refl), uv, 0.0).rgb; + // The mip chain is the filtered copy: one bright texel of a mirrored highlight is spread over the level the + // roughness asks for, so a rough gather is smooth and a mirror stays a mirror. + // The radius is a physical blur, so it is measured against a 720-line view and grows with this one: a rough + // surface keeps the same softness when the window or the display's pixel ratio changes. + float res = max(pc.size.y / 720.0, 1.0); + float radius = clamp(rough * rough * 120.0, 8.0, 32.0) * res; + // The disc below is the gather itself; the level it starts from is only a prefilter, so take it two steps sharper + // than the radius and let the disc reach the rest. Sampling the whole blur from the level made every reflection + // step at an eighth of the view (#302). + float lod = clamp(log2(radius) - 2.0, 1.0, 4.0); + float z = -point_at(vec2(at) + 0.5, d).z; + vec3 base = clamp(textureLod(sampler2D(t_refl_soft, s_refl), uv, lod).rgb, vec3(0.0), vec3(8.0)); + vec3 sum = base; + float total = 1.0; + ivec2 top = ivec2(pc.size.xy) - 1; + // A fixed disc inside the reflection ray's footprint: golden-angle taps, no per-frame or per-pixel noise. + for (int i = 0; i < 8; ++i) { + float t = (float(i) + 0.5) / 8.0; + float a = float(i) * 2.39996323; + vec2 q = vec2(at) + 0.5 + vec2(cos(a), sin(a)) * sqrt(t) * radius * 0.5; + ivec2 qa = clamp(ivec2(q), ivec2(0), top); + float dq = depth_at(vec2(qa) + 0.5); + if (dq <= 0.0) continue; + float zq = -point_at(vec2(qa) + 0.5, dq).z; + float w = exp(-abs(zq - z) / (0.02 * z + 0.1)); + vec2 quv = (vec2(qa) + 0.5) / pc.size.xy; + sum += clamp(textureLod(sampler2D(t_refl_soft, s_refl), quv, lod).rgb, vec3(0.0), vec3(8.0)) * w; + total += w; + } + return sum / total; +} + +// The scene's colour with the occlusion and bounce light (`got`, rgb bounce and alpha openness) on it, and the screen- +// space reflections and refraction added in linear light. +vec3 lit(vec3 color, vec4 got, ivec2 at, float d) { float open = got.a; vec3 shaded = color * open; if (pp.quality.y > 0.0) { @@ -301,6 +612,29 @@ vec3 lit(vec3 color, vec4 got, ivec2 at) { vec3 albedo = texelFetch(sampler2D(t_albedo, s_point), at, 0).rgb; shaded = pow(pow(shaded, vec3(2.2)) + albedo * got.rgb * open, vec3(1.0 / 2.2)); } + if (pp.quality.z > 0.5) { + vec3 refl = reflection_at(at, d); + int dbg = int(pp.quality.w); + if (dbg == 1) return pow(max(refl, vec3(0.0)), vec3(1.0 / 2.2)); + if (dbg == 2) return texelFetch(sampler2D(t_mat, s_point), at, 0).rgb; + if (dbg == 3) return vec3(texelFetch(sampler2D(t_mat, s_point), at, 0).a - 0.002); + if (dbg == 4) return vec3(texelFetch(sampler2D(t_mat_aux, s_point), at, 0).b); + if (dbg == 5) return vec3(texelFetch(sampler2D(t_mat_aux, s_point), at, 0).g); + if (dbg == 6) return texelFetch(sampler2D(t_planar, s_point), at, 0).rgb; + if (dbg == 7) return vec3(texelFetch(sampler2D(t_mat_aux, s_point), at, 0).r); + if (dbg == 8) return texelFetch(sampler2D(t_albedo, s_point), at, 0).rgb; + if (dbg == 13) return texelFetch(sampler2D(t_refl_soft, s_point), at, 0).rgb; + if (dbg == 14) return texelFetch(sampler2D(t_refl, s_point), at, 0).rgb; + if (dbg == 15) return reflection_at(at, d); + if (dbg == 16) return textureLod(sampler2D(t_refl_soft, s_refl), (vec2(at) + 0.5) / pc.size.xy, 3.0).rgb; + if (dbg == 20) return pow(max(got.rgb, vec3(0.0)), vec3(1.0 / 2.2)); + if (dbg == 21) return vec3(got.a); + if (dbg == 22) return pow(max(texelFetch(sampler2D(t_open, s_point), at, 0).rgb, vec3(0.0)), vec3(1.0 / 2.2)); + if (dbg == 23) return vec3(texelFetch(sampler2D(t_open, s_point), at, 0).a); + if (dbg == 24) return texelFetch(sampler2D(t_back, s_point), at, 0).rgb; + if (dbg == 25) return vec3(texelFetch(sampler2D(t_mat_aux, s_point), at, 0).r); + shaded = pow(pow(shaded, vec3(2.2)) + refl, vec3(1.0 / 2.2)); + } return shaded; } @@ -310,35 +644,20 @@ vec3 picture(vec2 c) { float d = depth_at(c); // Nothing drawn here: the gradient, top of the view to bottom. What was drawn without depth keeps its colour. if (pc.bg_top.w > 0.5 && cleared(color, d)) return mix(pc.bg_top.rgb, pc.bg_bottom.rgb, c.y * pc.size.w); - if (effects_off() || d <= 0.0) return color; - float z = point_at(c, d).z; - float per_px = length(point_at(c + vec2(1.0, 0.0), d) - point_at(c, d)); - vec4 sum = vec4(0.0); - float weight = 0.0; - // Realtime smooths over a wider square, which takes the finer sampling's remaining grain out. - int blur = pp.quality.x > 0.5 ? 4 : 3; - for (int y = -blur; y <= blur; ++y) { - for (int x = -blur; x <= blur; ++x) { - vec2 q = c + vec2(float(x), float(y)); - ivec2 at = clamp(ivec2(q), ivec2(0), ivec2(pc.size.xy) - 1); - float dq = depth_at(q); - if (dq <= 0.0) continue; - // Pixels much nearer or farther are another surface: a slope across the square is not. - float dz = abs(point_at(q, dq).z - z) / (per_px * float(blur * 2) + 1e-9); - float w = exp(-float(x * x + y * y) / float(blur * blur * 2)) * max(1.0 - dz, 0.0); - sum += texelFetch(sampler2D(t_open, s_point), at, 0) * w; - weight += w; - } - } - return lit(color, weight > 0.0 ? sum / weight : vec4(0.0, 0.0, 0.0, 1.0), ivec2(c)); + if (effects_off() || d <= 0.0) return lit(color, vec4(0.0, 0.0, 0.0, 1.0), ivec2(c), d); + // The bounce was low-passed along both axes before this pass, so one bilinear sample is already smooth: no + // stochastic grain and no square footprint, and no gather cost here. + ivec2 at = clamp(ivec2(c), ivec2(0), ivec2(pc.size.xy) - 1); + vec4 got = textureLod(sampler2D(t_open, s_refl), (vec2(at) + 0.5) / pc.size.xy, 0.0); + return lit(color, got, ivec2(c), d); } // The picture at a pixel the depth of field gathers from: the same, without the occlusion's smoothing, which the // gathering itself stands in for. vec3 picture_rough(ivec2 at, vec3 color, float d) { if (pc.bg_top.w > 0.5 && cleared(color, d)) return mix(pc.bg_top.rgb, pc.bg_bottom.rgb, (float(at.y) + 0.5) * pc.size.w); - if (effects_off() || d <= 0.0) return color; - return lit(color, texelFetch(sampler2D(t_open, s_point), at, 0), at); + if (effects_off() || d <= 0.0) return lit(color, vec4(0.0, 0.0, 0.0, 1.0), at, d); + return lit(color, textureLod(sampler2D(t_open, s_refl), (vec2(at) + 0.5) / pc.size.xy, 0.0), at, d); } // What depth of field blurs: the background, and what has depth (only shaded surfaces when the renderer marks them). @@ -428,11 +747,42 @@ pub struct PostSettings { pub bounce: f32, /// The camera's depth of field, as Harold renders it: the lens's radius in scene units and the distance in focus. pub dof: Option<(f32, f32)>, + /// Screen-space reflections and refraction (#302), only with the Realtime renderer's material buffer. + pub reflections: bool, + /// Show the reflection buffer itself (1), the material's reflection colour (2) or roughness (3), for checking the + /// pass. + pub debug_reflection: u32, + /// Whether a ground plane is being reflected, and which way the world's up is. + pub planar_reflection: bool, + pub up: [f32; 3], + /// The camera's world-to-view matrix, for looking a reflection up in the environment. + pub view: Mat4, + /// The sky dome the reflections fall back on: its colour and strength, w 1 when an image feeds it; and its + /// world-to-dome rotation. + pub env: [f32; 4], + pub env_rot: [f32; 4], } impl Default for PostSettings { fn default() -> Self { - PostSettings { ambient_occlusion: false, ao_radius: 2.0, ao_intensity: 1.5, gradient: None, clear_grey: 0.36, contact: None, high_quality: false, bounce: 0.0, dof: None } + PostSettings { + ambient_occlusion: false, + ao_radius: 2.0, + ao_intensity: 1.5, + gradient: None, + clear_grey: 0.36, + contact: None, + high_quality: false, + bounce: 0.0, + dof: None, + reflections: false, + debug_reflection: 0, + planar_reflection: false, + up: [0.0, 1.0, 0.0], + view: Mat4::IDENTITY, + env: [0.0; 4], + env_rot: [0.0, 0.0, 0.0, 1.0], + } } } @@ -455,20 +805,36 @@ struct PostParams { contact: [f32; 4], quality: [f32; 4], dof: [f32; 4], + /// View space back to world, for a reflection looked up in the environment. + view_to_world: [f32; 16], + /// The sky dome's colour and strength, w 1 when an image feeds it. + env: [f32; 4], + /// World to the dome's space. + env_rot: [f32; 4], + /// x: 1 with a ground plane's reflection, yzw: the world's up. + extra: [f32; 4], } pub struct Post { pipeline: vk::Pipeline, ao_pipeline: vk::Pipeline, + reflection_pipeline: vk::Pipeline, + reflection_blur_pipeline: vk::Pipeline, + bounce_blur_pipeline: vk::Pipeline, layout: vk::PipelineLayout, set_layout: vk::DescriptorSetLayout, + env_layout: vk::DescriptorSetLayout, pool: vk::DescriptorPool, set: vk::DescriptorSet, ao_set: vk::DescriptorSet, /// The bounce light's second pass, reading the first's; and the picture's, reading the second's. bounce_set: vk::DescriptorSet, bounced_set: vk::DescriptorSet, + reflection_set: vk::DescriptorSet, + /// The sky dome's textures, bound at set 1; white when the scene has none. + env_set: vk::DescriptorSet, sampler: vk::Sampler, + refl_sampler: vk::Sampler, params: crate::gpu::Buffer, } @@ -500,7 +866,10 @@ impl Post { let multisampled = gpu.samples != vk::SampleCountFlags::TYPE_1; let fs = module(&compile(&fragment_source(COMPOSITE_MAIN, multisampled), naga::ShaderStage::Fragment)); let ao_fs = module(&compile(&fragment_source(AO_MAIN, multisampled), naga::ShaderStage::Fragment)); - let bindings = [ + let reflect_fs = module(&compile(&fragment_source(REFLECT_MAIN, multisampled), naga::ShaderStage::Fragment)); + let blur_fs = module(&compile(&fragment_source(REFL_BLUR_MAIN, multisampled), naga::ShaderStage::Fragment)); + let bounce_blur_fs = module(&compile(&fragment_source(BOUNCE_BLUR_MAIN, multisampled), naga::ShaderStage::Fragment)); + let bindings = vec![ vk::DescriptorSetLayoutBinding::default().binding(0).descriptor_type(vk::DescriptorType::SAMPLED_IMAGE).descriptor_count(1).stage_flags(vk::ShaderStageFlags::FRAGMENT), vk::DescriptorSetLayoutBinding::default().binding(1).descriptor_type(vk::DescriptorType::SAMPLED_IMAGE).descriptor_count(1).stage_flags(vk::ShaderStageFlags::FRAGMENT), vk::DescriptorSetLayoutBinding::default().binding(2).descriptor_type(vk::DescriptorType::SAMPLER).descriptor_count(1).stage_flags(vk::ShaderStageFlags::FRAGMENT), @@ -508,14 +877,23 @@ impl Post { vk::DescriptorSetLayoutBinding::default().binding(4).descriptor_type(vk::DescriptorType::UNIFORM_BUFFER).descriptor_count(1).stage_flags(vk::ShaderStageFlags::FRAGMENT), vk::DescriptorSetLayoutBinding::default().binding(5).descriptor_type(vk::DescriptorType::SAMPLED_IMAGE).descriptor_count(1).stage_flags(vk::ShaderStageFlags::FRAGMENT), vk::DescriptorSetLayoutBinding::default().binding(6).descriptor_type(vk::DescriptorType::SAMPLED_IMAGE).descriptor_count(1).stage_flags(vk::ShaderStageFlags::FRAGMENT), + vk::DescriptorSetLayoutBinding::default().binding(7).descriptor_type(vk::DescriptorType::SAMPLED_IMAGE).descriptor_count(1).stage_flags(vk::ShaderStageFlags::FRAGMENT), + vk::DescriptorSetLayoutBinding::default().binding(8).descriptor_type(vk::DescriptorType::SAMPLED_IMAGE).descriptor_count(1).stage_flags(vk::ShaderStageFlags::FRAGMENT), + vk::DescriptorSetLayoutBinding::default().binding(9).descriptor_type(vk::DescriptorType::SAMPLED_IMAGE).descriptor_count(1).stage_flags(vk::ShaderStageFlags::FRAGMENT), + vk::DescriptorSetLayoutBinding::default().binding(10).descriptor_type(vk::DescriptorType::SAMPLED_IMAGE).descriptor_count(1).stage_flags(vk::ShaderStageFlags::FRAGMENT), + vk::DescriptorSetLayoutBinding::default().binding(11).descriptor_type(vk::DescriptorType::SAMPLED_IMAGE).descriptor_count(1).stage_flags(vk::ShaderStageFlags::FRAGMENT), + vk::DescriptorSetLayoutBinding::default().binding(12).descriptor_type(vk::DescriptorType::SAMPLED_IMAGE).descriptor_count(1).stage_flags(vk::ShaderStageFlags::FRAGMENT), + vk::DescriptorSetLayoutBinding::default().binding(13).descriptor_type(vk::DescriptorType::SAMPLER).descriptor_count(1).stage_flags(vk::ShaderStageFlags::FRAGMENT), ]; let set_layout = d.create_descriptor_set_layout(&vk::DescriptorSetLayoutCreateInfo::default().bindings(&bindings), None).unwrap(); + // The sky dome is a texture set of its own, bound at set 1, as the material pipelines bind it. + let env_layout = crate::textures::set_layout(gpu); let sizes = [ - vk::DescriptorPoolSize::default().ty(vk::DescriptorType::SAMPLED_IMAGE).descriptor_count(24), - vk::DescriptorPoolSize::default().ty(vk::DescriptorType::SAMPLER).descriptor_count(4), - vk::DescriptorPoolSize::default().ty(vk::DescriptorType::UNIFORM_BUFFER).descriptor_count(4), + vk::DescriptorPoolSize::default().ty(vk::DescriptorType::SAMPLED_IMAGE).descriptor_count(56), + vk::DescriptorPoolSize::default().ty(vk::DescriptorType::SAMPLER).descriptor_count(10), + vk::DescriptorPoolSize::default().ty(vk::DescriptorType::UNIFORM_BUFFER).descriptor_count(5), ]; - let pool = d.create_descriptor_pool(&vk::DescriptorPoolCreateInfo::default().max_sets(4).pool_sizes(&sizes), None).unwrap(); + let pool = d.create_descriptor_pool(&vk::DescriptorPoolCreateInfo::default().max_sets(5).pool_sizes(&sizes), None).unwrap(); let layouts = [set_layout]; let set = d.allocate_descriptor_sets(&vk::DescriptorSetAllocateInfo::default().descriptor_pool(pool).set_layouts(&layouts)).unwrap()[0]; let sampler = d @@ -529,9 +907,37 @@ impl Post { None, ) .unwrap(); - let params = gpu.buffer_with(vk::BufferUsageFlags::UNIFORM_BUFFER, &[PostParams { proj: glam::Mat4::IDENTITY.to_cols_array(), contact_dir: [0.0; 4], contact: [0.0; 4], quality: [0.0; 4], dof: [0.0; 4] }]); + let refl_sampler = d + .create_sampler( + &vk::SamplerCreateInfo::default() + .mag_filter(vk::Filter::LINEAR) + .min_filter(vk::Filter::LINEAR) + .mipmap_mode(vk::SamplerMipmapMode::LINEAR) + .min_lod(0.0) + .max_lod(5.0) + .address_mode_u(vk::SamplerAddressMode::CLAMP_TO_EDGE) + .address_mode_v(vk::SamplerAddressMode::CLAMP_TO_EDGE) + .address_mode_w(vk::SamplerAddressMode::CLAMP_TO_EDGE), + None, + ) + .unwrap(); + let params = gpu.buffer_with( + vk::BufferUsageFlags::UNIFORM_BUFFER, + &[PostParams { + proj: glam::Mat4::IDENTITY.to_cols_array(), + contact_dir: [0.0; 4], + contact: [0.0; 4], + quality: [0.0; 4], + dof: [0.0; 4], + view_to_world: glam::Mat4::IDENTITY.to_cols_array(), + env: [0.0; 4], + env_rot: [0.0, 0.0, 0.0, 1.0], + extra: [0.0; 4], + }], + ); let push = [vk::PushConstantRange::default().stage_flags(vk::ShaderStageFlags::FRAGMENT).offset(0).size(std::mem::size_of::() as u32)]; - let layout = d.create_pipeline_layout(&vk::PipelineLayoutCreateInfo::default().set_layouts(&layouts).push_constant_ranges(&push), None).unwrap(); + let sets = [set_layout, env_layout]; + let layout = d.create_pipeline_layout(&vk::PipelineLayoutCreateInfo::default().set_layouts(&sets).push_constant_ranges(&push), None).unwrap(); let stages = [ vk::PipelineShaderStageCreateInfo::default().stage(vk::ShaderStageFlags::VERTEX).module(vs).name(c"main"), vk::PipelineShaderStageCreateInfo::default().stage(vk::ShaderStageFlags::FRAGMENT).module(fs).name(c"main"), @@ -565,22 +971,51 @@ impl Post { ]; let ao_info = info.stages(&ao_stages).render_pass(gpu.ao_pass); let ao_pipeline = d.create_graphics_pipelines(vk::PipelineCache::null(), &[ao_info], None).map_err(|e| e.1).unwrap()[0]; - // The occlusion pass can't read the image it writes: its set has the scene's colour in that place. - let ao_set = d.allocate_descriptor_sets(&vk::DescriptorSetAllocateInfo::default().descriptor_pool(pool).set_layouts(&layouts)).unwrap()[0]; - let bounce_set = d.allocate_descriptor_sets(&vk::DescriptorSetAllocateInfo::default().descriptor_pool(pool).set_layouts(&layouts)).unwrap()[0]; - let bounced_set = d.allocate_descriptor_sets(&vk::DescriptorSetAllocateInfo::default().descriptor_pool(pool).set_layouts(&layouts)).unwrap()[0]; + // The reflection pass: the same triangle, its own shader, into the reflection image. + let reflect_stages = [ + vk::PipelineShaderStageCreateInfo::default().stage(vk::ShaderStageFlags::VERTEX).module(vs).name(c"main"), + vk::PipelineShaderStageCreateInfo::default().stage(vk::ShaderStageFlags::FRAGMENT).module(reflect_fs).name(c"main"), + ]; + let reflect_info = info.stages(&reflect_stages).render_pass(gpu.ao_pass); + let reflection_pipeline = d.create_graphics_pipelines(vk::PipelineCache::null(), &[reflect_info], None).map_err(|e| e.1).unwrap()[0]; + // The low-pass of that image: the same triangle, its own shader. + let blur_stages = [ + vk::PipelineShaderStageCreateInfo::default().stage(vk::ShaderStageFlags::VERTEX).module(vs).name(c"main"), + vk::PipelineShaderStageCreateInfo::default().stage(vk::ShaderStageFlags::FRAGMENT).module(blur_fs).name(c"main"), + ]; + let blur_info = info.stages(&blur_stages).render_pass(gpu.ao_pass); + let reflection_blur_pipeline = d.create_graphics_pipelines(vk::PipelineCache::null(), &[blur_info], None).map_err(|e| e.1).unwrap()[0]; + // The bounce light's low-pass, along one axis at a time. + let bounce_blur_stages = [ + vk::PipelineShaderStageCreateInfo::default().stage(vk::ShaderStageFlags::VERTEX).module(vs).name(c"main"), + vk::PipelineShaderStageCreateInfo::default().stage(vk::ShaderStageFlags::FRAGMENT).module(bounce_blur_fs).name(c"main"), + ]; + let bounce_blur_info = info.stages(&bounce_blur_stages).render_pass(gpu.ao_pass); + let bounce_blur_pipeline = d.create_graphics_pipelines(vk::PipelineCache::null(), &[bounce_blur_info], None).map_err(|e| e.1).unwrap()[0]; + // The occlusion and reflection passes can't read the image they write: their sets have another image there. + let allocate = || d.allocate_descriptor_sets(&vk::DescriptorSetAllocateInfo::default().descriptor_pool(pool).set_layouts(&layouts)).unwrap()[0]; + let ao_set = allocate(); + let bounce_set = allocate(); + let bounced_set = allocate(); + let reflection_set = allocate(); + let env_set = crate::textures::with_cache(gpu, |c| c.white(gpu)); d.destroy_shader_module(vs, None); d.destroy_shader_module(fs, None); d.destroy_shader_module(ao_fs, None); - Post { pipeline, ao_pipeline, layout, set_layout, pool, set, ao_set, bounce_set, bounced_set, sampler, params } + d.destroy_shader_module(reflect_fs, None); + d.destroy_shader_module(blur_fs, None); + d.destroy_shader_module(bounce_blur_fs, None); + Post { pipeline, ao_pipeline, reflection_pipeline, reflection_blur_pipeline, bounce_blur_pipeline, layout, set_layout, env_layout, pool, set, ao_set, bounce_set, bounced_set, reflection_set, env_set, sampler, refl_sampler, params } } } - /// Points the sets at the scene's images. Call with no frame in flight (before the frame draws). - pub fn bind_images(&self, gpu: &Gpu) { + /// Points the sets at the scene's images, and at the sky dome the reflections fall back on. Call with no frame in + /// flight (before the frame draws). + pub fn bind_images(&mut self, gpu: &Gpu, env: Option) { if gpu.scene_view == vk::ImageView::null() || gpu.overlay_view == vk::ImageView::null() { return; } + self.env_set = env.unwrap_or_else(|| crate::textures::with_cache(gpu, |c| c.white(gpu))); // Written each frame: a view remade at another size can come back under the handle the old one had. let color = [vk::DescriptorImageInfo::default().image_view(gpu.scene_view).image_layout(vk::ImageLayout::SHADER_READ_ONLY_OPTIMAL)]; let depth = [vk::DescriptorImageInfo::default().image_view(gpu.depth_view).image_layout(vk::ImageLayout::DEPTH_STENCIL_READ_ONLY_OPTIMAL)]; @@ -589,9 +1024,23 @@ impl Post { let bounced = [vk::DescriptorImageInfo::default().image_view(gpu.bounce_view).image_layout(vk::ImageLayout::SHADER_READ_ONLY_OPTIMAL)]; let albedo = [vk::DescriptorImageInfo::default().image_view(gpu.albedo_view).image_layout(vk::ImageLayout::SHADER_READ_ONLY_OPTIMAL)]; let overlay = [vk::DescriptorImageInfo::default().image_view(gpu.overlay_view).image_layout(vk::ImageLayout::SHADER_READ_ONLY_OPTIMAL)]; + let mat = [vk::DescriptorImageInfo::default().image_view(gpu.mat_view).image_layout(vk::ImageLayout::SHADER_READ_ONLY_OPTIMAL)]; + let mat_aux = [vk::DescriptorImageInfo::default().image_view(gpu.mat_aux_view).image_layout(vk::ImageLayout::SHADER_READ_ONLY_OPTIMAL)]; + let reflection = [vk::DescriptorImageInfo::default().image_view(gpu.refl_view).image_layout(vk::ImageLayout::SHADER_READ_ONLY_OPTIMAL)]; + let planar = [vk::DescriptorImageInfo::default().image_view(gpu.planar_view).image_layout(vk::ImageLayout::SHADER_READ_ONLY_OPTIMAL)]; + let back = [vk::DescriptorImageInfo::default().image_view(gpu.back_view).image_layout(vk::ImageLayout::SHADER_READ_ONLY_OPTIMAL)]; + let refl_soft = [vk::DescriptorImageInfo::default().image_view(gpu.refl_chain_view).image_layout(vk::ImageLayout::SHADER_READ_ONLY_OPTIMAL)]; + let refl_sampler = [vk::DescriptorImageInfo::default().sampler(self.refl_sampler)]; let params = [vk::DescriptorBufferInfo::default().buffer(self.params.buffer).offset(0).range(std::mem::size_of::() as u64)]; let mut writes = Vec::new(); - for (set, last) in [(self.set, &open), (self.ao_set, &color), (self.bounce_set, &open), (self.bounced_set, &bounced)] { + for (set, last, refl) in [ + (self.set, &open, &reflection), + (self.ao_set, &color, &reflection), + (self.bounce_set, &open, &reflection), + (self.bounced_set, &bounced, &reflection), + // The reflection pass can't read the image it writes: its binding has the bounce image, which it never reads. + (self.reflection_set, &open, &bounced), + ] { writes.push(vk::WriteDescriptorSet::default().dst_set(set).dst_binding(0).descriptor_type(vk::DescriptorType::SAMPLED_IMAGE).image_info(&color)); writes.push(vk::WriteDescriptorSet::default().dst_set(set).dst_binding(1).descriptor_type(vk::DescriptorType::SAMPLED_IMAGE).image_info(&depth)); writes.push(vk::WriteDescriptorSet::default().dst_set(set).dst_binding(2).descriptor_type(vk::DescriptorType::SAMPLER).image_info(&point)); @@ -599,6 +1048,13 @@ impl Post { writes.push(vk::WriteDescriptorSet::default().dst_set(set).dst_binding(4).descriptor_type(vk::DescriptorType::UNIFORM_BUFFER).buffer_info(¶ms)); writes.push(vk::WriteDescriptorSet::default().dst_set(set).dst_binding(5).descriptor_type(vk::DescriptorType::SAMPLED_IMAGE).image_info(&albedo)); writes.push(vk::WriteDescriptorSet::default().dst_set(set).dst_binding(6).descriptor_type(vk::DescriptorType::SAMPLED_IMAGE).image_info(&overlay)); + writes.push(vk::WriteDescriptorSet::default().dst_set(set).dst_binding(7).descriptor_type(vk::DescriptorType::SAMPLED_IMAGE).image_info(&mat)); + writes.push(vk::WriteDescriptorSet::default().dst_set(set).dst_binding(8).descriptor_type(vk::DescriptorType::SAMPLED_IMAGE).image_info(&mat_aux)); + writes.push(vk::WriteDescriptorSet::default().dst_set(set).dst_binding(9).descriptor_type(vk::DescriptorType::SAMPLED_IMAGE).image_info(refl)); + writes.push(vk::WriteDescriptorSet::default().dst_set(set).dst_binding(10).descriptor_type(vk::DescriptorType::SAMPLED_IMAGE).image_info(&planar)); + writes.push(vk::WriteDescriptorSet::default().dst_set(set).dst_binding(11).descriptor_type(vk::DescriptorType::SAMPLED_IMAGE).image_info(&back)); + writes.push(vk::WriteDescriptorSet::default().dst_set(set).dst_binding(12).descriptor_type(vk::DescriptorType::SAMPLED_IMAGE).image_info(&refl_soft)); + writes.push(vk::WriteDescriptorSet::default().dst_set(set).dst_binding(13).descriptor_type(vk::DescriptorType::SAMPLER).image_info(&refl_sampler)); } unsafe { gpu.device.update_descriptor_sets(&writes, &[]) }; } @@ -633,8 +1089,12 @@ impl Post { proj: proj.to_cols_array(), contact_dir: match s.contact { Some((d, reach, _)) => [d[0], d[1], d[2], reach.max(0.0)], None => [0.0; 4] }, contact: match s.contact { Some((_, _, strength)) => [strength.max(0.0), 0.0, 0.0, 0.0], None => [0.0; 4] }, - quality: [if s.high_quality { 1.0 } else { 0.0 }, s.bounce.max(0.0), 0.0, 0.0], + quality: [if s.high_quality { 1.0 } else { 0.0 }, s.bounce.max(0.0), if s.reflections { 1.0 } else { 0.0 }, s.debug_reflection as f32], dof: dof_params(proj, s, w, h), + view_to_world: s.view.inverse().to_cols_array(), + env: s.env, + env_rot: s.env_rot, + extra: [if s.planar_reflection { 1.0 } else { 0.0 }, s.up[0], s.up[1], s.up[2]], }; let bytes: &[u8] = bytemuck::bytes_of(&data); if let Some(p) = self.params.alloc.as_ref().and_then(|a| a.mapped_ptr()) { @@ -646,7 +1106,7 @@ impl Post { unsafe { let d = &gpu.device; d.cmd_bind_pipeline(gpu.cmd, vk::PipelineBindPoint::GRAPHICS, pipeline); - d.cmd_bind_descriptor_sets(gpu.cmd, vk::PipelineBindPoint::GRAPHICS, self.layout, 0, &[set], &[]); + d.cmd_bind_descriptor_sets(gpu.cmd, vk::PipelineBindPoint::GRAPHICS, self.layout, 0, &[set, self.env_set], &[]); d.cmd_push_constants(gpu.cmd, self.layout, vk::ShaderStageFlags::FRAGMENT, 0, bytemuck::bytes_of(push)); d.cmd_draw(gpu.cmd, 3, 1, 0, 0); } @@ -666,6 +1126,33 @@ impl Post { self.pass(gpu, self.ao_pipeline, self.bounce_set, &push); } + /// One axis of the bounce light's low-pass, between the two passes the view begins for it. + pub fn draw_bounce_blur(&self, gpu: &Gpu, proj: Mat4, orthographic: bool, s: &PostSettings, horizontal: bool) { + if s.bounce <= 0.0 { + return; + } + let mut push = self.push(gpu, proj, orthographic, s); + // bg_top is unused by this pass otherwise: the axis, then the Gaussian's sigma in pixels. + push.bg_top = [if horizontal { 1.0 } else { 0.0 }, if horizontal { 0.0 } else { 1.0 }, 3.5, 0.0]; + let set = if horizontal { self.bounced_set } else { self.bounce_set }; + self.pass(gpu, self.bounce_blur_pipeline, set, &push); + } + + /// The screen-space reflections and refraction. Between `Gpu::begin_reflection` and `Gpu::begin_occlusion`, with + /// the Realtime renderer's material buffer. + pub fn draw_reflection(&self, gpu: &Gpu, proj: Mat4, orthographic: bool, s: &PostSettings) { + if s.reflections { + self.pass(gpu, self.reflection_pipeline, self.reflection_set, &self.push(gpu, proj, orthographic, s)); + } + } + + /// The low-pass of the reflection image. Between `Gpu::begin_refl_blur` and `Gpu::end_refl_blur`. + pub fn draw_reflection_blur(&self, gpu: &Gpu, proj: Mat4, orthographic: bool, s: &PostSettings) { + if s.reflections { + self.pass(gpu, self.reflection_blur_pipeline, self.set, &self.push(gpu, proj, orthographic, s)); + } + } + /// Draws the scene's picture onto the window's image. Between `Gpu::begin_post` and `Gpu::end_frame`. pub fn draw(&self, gpu: &Gpu, proj: Mat4, orthographic: bool, s: &PostSettings) { let set = if s.bounce > 0.0 { self.bounced_set } else { self.set }; @@ -677,10 +1164,15 @@ impl Post { let d = &gpu.device; d.destroy_pipeline(self.pipeline, None); d.destroy_pipeline(self.ao_pipeline, None); + d.destroy_pipeline(self.reflection_pipeline, None); + d.destroy_pipeline(self.reflection_blur_pipeline, None); + d.destroy_pipeline(self.bounce_blur_pipeline, None); d.destroy_pipeline_layout(self.layout, None); d.destroy_descriptor_pool(self.pool, None); d.destroy_descriptor_set_layout(self.set_layout, None); + d.destroy_descriptor_set_layout(self.env_layout, None); d.destroy_sampler(self.sampler, None); + d.destroy_sampler(self.refl_sampler, None); d.destroy_buffer(self.params.buffer, None); if let Some(a) = self.params.alloc.take() { let _ = gpu.shared.allocator.lock().unwrap().free(a); @@ -689,6 +1181,47 @@ impl Post { } } +/// The reflection of `i` about `n`, as the shader's `reflect`: i and n unit vectors, i towards the surface. +#[cfg(test)] +fn reflected(i: [f32; 3], n: [f32; 3]) -> [f32; 3] { + let d = i[0] * n[0] + i[1] * n[1] + i[2] * n[2]; + [i[0] - 2.0 * d * n[0], i[1] - 2.0 * d * n[1], i[2] - 2.0 * d * n[2]] +} + +/// The refracted direction into a medium of `eta = n1 / n2`, or None at total internal reflection, as GLSL `refract`. +#[cfg(test)] +fn refracted(i: [f32; 3], n: [f32; 3], eta: f32) -> Option<[f32; 3]> { + let d = i[0] * n[0] + i[1] * n[1] + i[2] * n[2]; + let k = 1.0 - eta * eta * (1.0 - d * d); + if k < 0.0 { + return None; + } + let s = eta * d + k.sqrt(); + Some([eta * i[0] - s * n[0], eta * i[1] - s * n[1], eta * i[2] - s * n[2]]) +} + +/// The radius in pixels a roughness blurs a reflection over, as `reflection_at` gathers it. +#[cfg(test)] +fn roughness_pixels(rough: f32) -> f32 { + (rough * rough * 120.0).clamp(8.0, 32.0) +} + +/// How much a surface is the ground plane's reflection, as `planar_at`: 1 flat on the ground, 0 upright or off it. +/// The mip level the reflection gather samples for a roughness, as `reflection_at`. +#[cfg(test)] +fn reflection_lod(rough: f32) -> f32 { + (roughness_pixels(rough).log2() - 2.0).clamp(1.0, 4.0) +} + +#[cfg(test)] +fn planar_cover(up: f32, height: f32) -> f32 { + fn smoothstep(a: f32, b: f32, x: f32) -> f32 { + let t = ((x - a) / (b - a)).clamp(0.0, 1.0); + t * t * (3.0 - 2.0 * t) + } + smoothstep(0.86, 0.98, up) * (1.0 - smoothstep(0.04, 0.25, height.abs())) +} + #[cfg(test)] mod tests { use super::*; @@ -697,7 +1230,7 @@ mod tests { fn the_post_shaders_compile_for_one_sample_and_for_several() { assert!(!compile(POST_VS, naga::ShaderStage::Vertex).is_empty()); for multisampled in [false, true] { - for main in [AO_MAIN, COMPOSITE_MAIN] { + for main in [AO_MAIN, REFLECT_MAIN, REFL_BLUR_MAIN, COMPOSITE_MAIN] { assert!(!compile(&fragment_source(main, multisampled), naga::ShaderStage::Fragment).is_empty(), "multisampled {multisampled}"); } } @@ -747,5 +1280,92 @@ mod tests { // In reverse projection, the occlusion, the size and the two background colours: the 128 bytes every device gives. // The projection and contact shadow ride in a uniform buffer, so this stays at that minimum. assert_eq!(std::mem::size_of::(), 128); + // The reflection pass reads the material, the planar image and the behind-glass image: they are what the shader + // declares, and what the post sets bind. + for b in [7, 8, 9, 10, 11, 12, 13] { + assert!(POST_HEAD.contains(&format!("binding = {b}")), "binding {b}"); + } + assert!(REFLECT_MAIN.contains("t_mat_aux")); + assert!(REFLECT_MAIN.contains("t_planar")); + assert!(REFLECT_MAIN.contains("t_back")); + assert!(REFL_BLUR_MAIN.contains("t_refl")); + assert!(COMPOSITE_MAIN.contains("t_refl_soft")); + } + + #[test] + fn a_reflection_goes_where_the_mirror_says() { + // Straight down onto a floor whose normal is +y reflects straight up. + let r = reflected([0.0, -1.0, 0.0], [0.0, 1.0, 0.0]); + assert!((r[0]).abs() < 1e-6 && (r[1] - 1.0).abs() < 1e-6 && r[2].abs() < 1e-6, "{r:?}"); + // At 45 degrees it keeps the sideways part and turns the normal part over, the same angle. + let i = [0.7071068, -0.7071068, 0.0]; + let r = reflected(i, [0.0, 1.0, 0.0]); + assert!((r[0] - 0.7071068).abs() < 1e-5 && (r[1] - 0.7071068).abs() < 1e-5 && r[2].abs() < 1e-5, "{r:?}"); + // The shader's own line is this one. + assert!(REFLECT_MAIN.contains("vec3 r = reflect(v, n);")); + } + + #[test] + fn glass_bends_a_ray_towards_its_normal() { + // 45 degrees into glass of IOR 1.5: sin(t) = sin(i) / 1.5, so the ray turns towards the normal. + let i = [0.7071068, 0.0, -0.7071068]; + let r = refracted(i, [0.0, 0.0, 1.0], 1.0 / 1.5).unwrap(); + let angle = r[0].atan2(-r[2]).abs(); + assert!(angle < std::f32::consts::FRAC_PI_4 - 0.1, "{angle}"); + assert!((r[0] * r[0] + r[1] * r[1] + r[2] * r[2] - 1.0).abs() < 1e-5); + assert!(REFLECT_MAIN.contains("vec3 dir = refract(v, n, 1.0 / ior);")); + } + + #[test] + fn a_rougher_metal_blurs_its_reflection_more() { + assert_eq!(roughness_pixels(0.02), 8.0); + assert!(roughness_pixels(0.3) < roughness_pixels(0.5)); + assert!(roughness_pixels(0.2) < roughness_pixels(0.5)); + assert_eq!(roughness_pixels(1.0), 32.0); + // The composite's gather is the same radius, scaled to the view's height, with a pixel and a half at least at + // any roughness. + assert!(COMPOSITE_MAIN.contains("float res = max(pc.size.y / 720.0, 1.0);")); + assert!(COMPOSITE_MAIN.contains("clamp(rough * rough * 120.0, 8.0, 32.0) * res;")); + // The gather reads the filtered copy at a level that follows the roughness, and clamps bright taps. + assert!(COMPOSITE_MAIN.contains("textureLod(sampler2D(t_refl_soft, s_refl)")); + assert!(COMPOSITE_MAIN.contains("vec3(0.0), vec3(8.0)")); + // The prefilter starts two levels sharper than the gather's radius: a mirror reads the half-resolution mip, + // not an eighth. + assert_eq!(reflection_lod(0.02), 1.0); + assert!(reflection_lod(0.2) < reflection_lod(0.5)); + assert_eq!(reflection_lod(1.0), 3.0); + } + + #[test] + fn the_ground_plane_takes_the_planar_reflection() { + assert_eq!(planar_cover(1.0, 0.0), 1.0); + assert_eq!(planar_cover(0.0, 0.0), 0.0); + assert_eq!(planar_cover(1.0, 1.0), 0.0); + // Rounding a sphere's side off the plane, the planar image fades to the screen-space one. + assert!(planar_cover(0.9, 0.0) > 0.0 && planar_cover(0.9, 0.0) < 1.0); + assert!(REFLECT_MAIN.contains("smoothstep(0.86, 0.98, dot(wn, up))")); + } + + #[test] + fn the_examples_have_the_parity_suite() { + // Each lighting scene opens through shotCam and has a reference render and a viewport capture beside it. + let root = std::path::Path::new(env!("CARGO_MANIFEST_DIR")).join("../.."); + for name in [ + "reflections", + "metal_roughness_sweep", + "dielectric_glass", + "tinted_glass", + "emissive_object", + "area_lights", + "environment_hdri", + "checker_sphere", + ] { + let ma = root.join(format!("examples/rendering/{name}.ma")); + assert!(ma.is_file(), "{}", ma.display()); + let text = std::fs::read_to_string(&ma).unwrap(); + assert!(text.contains("shotCam"), "{name} has a shot camera"); + assert!(root.join(format!("examples/rendering/reference/{name}.png")).is_file(), "{name} reference"); + assert!(root.join(format!("examples/rendering/viewport/{name}.png")).is_file(), "{name} viewport"); + } } } diff --git a/crates/aztek_host/src/realtime.rs b/crates/aztek_host/src/realtime.rs index 519e1a62..94a152d3 100644 --- a/crates/aztek_host/src/realtime.rs +++ b/crates/aztek_host/src/realtime.rs @@ -1,7 +1,7 @@ //! The Realtime viewport's shadow map: one depth image drawn from the first light that casts shadows, and the meshes it //! needs. The shading itself is in `render.rs`; this is what the shader reads. -use std::collections::HashMap; +use std::collections::{HashMap, HashSet}; use std::sync::Arc; use ash::vk; @@ -250,8 +250,10 @@ impl Realtime { let sampler = d .create_sampler( &vk::SamplerCreateInfo::default() - .mag_filter(vk::Filter::NEAREST) - .min_filter(vk::Filter::NEAREST) + // Bilinear, so the percentage-closer comparison reads a filtered depth and the shadow edge is + // smooth instead of a stair-step of texels. + .mag_filter(vk::Filter::LINEAR) + .min_filter(vk::Filter::LINEAR) .address_mode_u(vk::SamplerAddressMode::CLAMP_TO_EDGE) .address_mode_v(vk::SamplerAddressMode::CLAMP_TO_EDGE) .address_mode_w(vk::SamplerAddressMode::CLAMP_TO_EDGE), @@ -294,8 +296,9 @@ impl Realtime { Some(self.set) } - /// Draws this frame's shadow map, before the scene's pass. Nothing when the frame plans none. - pub fn render(&mut self, gpu: &mut Gpu, items: &[DrawItem], plan: Option) { + /// Draws this frame's shadow map, before the scene's pass. Nothing when the frame plans none. `skip` holds the + /// transmissive shapes: a glass object lets the light through, so it must not lay down an opaque shadow. + pub fn render(&mut self, gpu: &mut Gpu, items: &[DrawItem], plan: Option, skip: &HashSet) { let Some(plan) = plan else { return }; self.keep(gpu, items); let d = gpu.device.clone(); @@ -315,6 +318,9 @@ impl Realtime { d.cmd_set_scissor(cmd, 0, &[vk::Rect2D { offset: vk::Offset2D::default(), extent }]); d.cmd_bind_pipeline(cmd, vk::PipelineBindPoint::GRAPHICS, self.pipeline); for it in items { + if skip.contains(&it.shape) { + continue; + } let Some(cast) = self.meshes.get(&it.shape) else { continue }; if cast.count == 0 { continue; diff --git a/crates/aztek_host/src/render.rs b/crates/aztek_host/src/render.rs index c90fc2c8..ca253005 100644 --- a/crates/aztek_host/src/render.rs +++ b/crates/aztek_host/src/render.rs @@ -378,9 +378,10 @@ void main() { // The OpenPBR surface as the Realtime renderer draws it: GGX specular and coat, Lambert base, an image or a sky dome // for image-based lighting, and the scene's one shadow map. The light block, all six light types and the falloffs are the // same as the legacy material shader's, so a light lights the same in either renderer. -/// The two colour attachments' blending for a pipeline in the scene pass: the picture, and the surface colour bounce -/// light reads, which only the Realtime renderer's materials write. -pub(crate) fn scene_blend(albedo: bool) -> [vk::PipelineColorBlendAttachmentState; 2] { +/// The colour attachments' blending for a pipeline in the scene pass: the picture, the surface colour bounce light reads, +/// which only the Realtime renderer's materials write, and the two material images the screen-space reflection pass reads +/// (#302). +pub(crate) fn scene_blend(albedo: bool, mat: bool) -> [vk::PipelineColorBlendAttachmentState; 4] { let blend = vk::PipelineColorBlendAttachmentState::default() .blend_enable(true) .src_color_blend_factor(vk::BlendFactor::SRC_ALPHA) @@ -390,7 +391,9 @@ pub(crate) fn scene_blend(albedo: bool) -> [vk::PipelineColorBlendAttachmentStat .dst_alpha_blend_factor(vk::BlendFactor::ONE_MINUS_SRC_ALPHA) .alpha_blend_op(vk::BlendOp::ADD) .color_write_mask(vk::ColorComponentFlags::RGBA); - [blend, if albedo { blend } else { blend.color_write_mask(vk::ColorComponentFlags::empty()) }] + let none = blend.color_write_mask(vk::ColorComponentFlags::empty()); + let material = vk::PipelineColorBlendAttachmentState::default().blend_enable(false).color_write_mask(vk::ColorComponentFlags::RGBA); + [blend, if albedo { blend } else { none }, if mat { material } else { none }, if mat { material } else { none }] } const REALTIME_FS: &str = r#"#version 450 @@ -414,6 +417,11 @@ layout(set = 4, binding = 3) uniform sampler s_shadow_cube; layout(location = 0) out vec4 out_color; // The surface's diffuse colour, linear: what bounce light arriving here is tinted by. layout(location = 1) out vec4 out_albedo; +// The screen-space reflection pass's material (#302): the fresnel-weighted reflection colour in rgb, the roughness it +// looks the environment up with in a. Zero where nothing is drawn. +layout(location = 2) out vec4 out_mat; +// Transmission, IOR as (IOR - 1) / 2, metalness, and 1 where this shader drew a material. +layout(location = 3) out vec4 out_aux; const float PI = 3.141592653589793; const float INV_PI = 0.3183098861837907; @@ -473,39 +481,61 @@ float shadow_at(vec3 p, vec3 n) { float far = max(lt.shadow_range.y, near + 0.02); // Each face looks a quarter turn from the light: its depth turns back into the distance along the face's axis. float axis = max(abs(to.x), max(abs(to.y), abs(to.z))); - float slack = lt.shadow.x + 0.02; - // An area light's shadows soften with its size, as Harold's do: look round the direction for what stands between - // (percentage-closer soft shadows), then take the share of the light's spread that gets past it. A point light - // has no size and a hard edge. int li = int(lt.shadow.z); float size = lt.lights[li].pos.w > 3.5 && lt.lights[li].pos.w < 4.5 ? 0.5 * (length(lt.lights[li].a.xyz) + length(lt.lights[li].b.xyz)) : 0.0; - if (size <= 0.0) { - float stored = cube_distance(d, near, far); - return axis <= stored + slack ? 1.0 : 0.0; - } + // A cube texel covers this much of the face at the receiver's distance, and it stretches along the surface as + // the cosine to the light falls. The slack has to follow that stretch: a constant one either acnes on a floor + // seen at a grazing angle or detaches the shadow where the surface faces the light. + vec3 l = lt.lights[li].pos.xyz - p; + float nl = max(dot(n, normalize(l + vec3(1e-6))), 0.0); + float texel = 2.0 * lt.shadow.y; + float slope = sqrt(max(1.0 - nl * nl, 0.0)) / max(nl, 0.2); + float slack = 0.02 + axis * texel * (0.5 + 1.5 * slope); vec3 t1 = normalize(cross(d, abs(d.y) < 0.9 ? vec3(0.0, 1.0, 0.0) : vec3(1.0, 0.0, 0.0))); vec3 t2 = cross(d, t1); - float turn = fract(52.9829189 * fract(dot(gl_FragCoord.xy, vec2(0.06711056, 0.00583715)))) * 6.2831853; - float search = clamp(size / max(axis, 0.001), 0.0, 0.5); - float blockers = 0.0, found = 0.0; - for (int i = 0; i < 12; ++i) { - float r = sqrt((float(i) + 0.5) / 12.0) * search; - float a = turn + float(i) * 2.39996323; - float stored = cube_distance(normalize(d + (t1 * cos(a) + t2 * sin(a)) * r), near, far); - if (stored + slack < axis) { - blockers += stored; - found += 1.0; + // A point light gets a stable 4 by 4 grid of bilinear cube taps, at least a texel and a half across. An area + // light widens the same grid to its penumbra. Nothing is rotated per pixel or per frame: that is what made + // the floor mottled like a dither. + float spread = texel * 4.0; + if (size > 0.0) { + float search = clamp(size / max(axis, 0.001), 0.0, 0.5); + float blockers = 0.0, found = 0.0; + for (int i = 0; i < 12; ++i) { + float r = sqrt((float(i) + 0.5) / 12.0) * search; + float a = float(i) * 2.39996323; + float stored = cube_distance(normalize(d + (t1 * cos(a) + t2 * sin(a)) * r), near, far); + if (stored + slack < axis) { + blockers += stored; + found += 1.0; + } + } + if (found > 0.5) { + float b = blockers / found; + spread = clamp(size * (axis - b) / max(b * axis, 0.0001), texel * 2.0, 0.5); } } - if (found < 0.5) return 1.0; - float b = blockers / found; - float spread = clamp(size * (axis - b) / max(b * axis, 0.0001), 0.0005, 0.5); + // The taps are fixed, never rotated per pixel or per frame. A point light gets a 4 by 4 grid of bilinear cube + // taps over a few texels: a regular grid has no spiral pattern on a smooth sphere. An area light's penumbra is + // wider, so it keeps the smoother golden-angle disc. float lit = 0.0; - for (int i = 0; i < 16; ++i) { - float r = sqrt((float(i) + 0.5) / 16.0) * spread; - float a = turn + 1.3 + float(i) * 2.39996323; - float stored = cube_distance(normalize(d + (t1 * cos(a) + t2 * sin(a)) * r), near, far); - lit += axis <= stored + slack ? 1.0 : 0.0; + if (size <= 0.0) { + for (int y = 0; y < 4; ++y) { + for (int x = 0; x < 4; ++x) { + vec2 o = (vec2(float(x), float(y)) + 0.5) * 0.25 - 0.5; + vec3 dir = normalize(d + (t1 * o.x + t2 * o.y) * spread); + float stored = cube_distance(dir, near, far); + lit += axis <= stored + slack ? 1.0 : 0.0; + } + } + } else { + for (int i = 0; i < 16; ++i) { + float t = (float(i) + 0.5) / 16.0; + float a = float(i) * 2.39996323; + float r = sqrt(t) * spread; + vec3 dir = normalize(d + (t1 * cos(a) + t2 * sin(a)) * r); + float stored = cube_distance(dir, near, far); + lit += axis <= stored + slack ? 1.0 : 0.0; + } } return lit / 16.0; } @@ -515,13 +545,15 @@ float shadow_at(vec3 p, vec3 n) { if (q.x < 0.0 || q.x > 1.0 || q.y < 0.0 || q.y > 1.0 || q.z > 1.0 || q.z < 0.0) return 1.0; float texel = lt.shadow.y; float sum = 0.0; - for (int y = -1; y <= 1; y += 1) { - for (int x = -1; x <= 1; x += 1) { - float d = texture(sampler2D(t_shadow, s_shadow), q.xy + vec2(float(x), float(y)) * texel * 1.5).r; + // A 5 by 5 gather, bilinearly read: the map's edge is chunky at a close view where one texel is many pixels, and + // it crawls as the camera moves. The wider filtered kernel turns that into a soft penumbra. + for (int y = -2; y <= 2; y += 1) { + for (int x = -2; x <= 2; x += 1) { + float d = texture(sampler2D(t_shadow, s_shadow), q.xy + vec2(float(x), float(y)) * texel).r; sum += q.z - 0.0015 <= d ? 1.0 : 0.0; } } - return sum / 9.0; + return sum / 25.0; } // What a rectangle of light sends to a matte surface at x facing n, as its radiance times this: the exact integral of // the cosines over the distance squared across it (Lambert's polygon formula). Corners p0..p3 go round it so that @@ -710,6 +742,8 @@ void main() { if (pc.gain.w < 0.5) { out_color = vec4(pow(max(base + emission, vec3(0.0)), vec3(1.0 / 2.2)), alpha); out_albedo = vec4(0.0, 0.0, 0.0, alpha); + out_mat = vec4(0.0); + out_aux = vec4(0.0); return; } vec3 v = lt.head.w != 0 ? vec3(0.0, 0.0, 1.0) : normalize(-v_view); @@ -720,7 +754,8 @@ void main() { if (pc.n2.w > 0.5) n = facet; else if (back) n = -n; float transmission = clamp(pc.coat.w, 0.0, 1.0); - if (transmission > 0.5) base = mix(base, base * 0.12 + pc.ambient.rgb * 0.5, transmission); + // A transmissive surface's colour is its transmission colour, which the material already carries (#302): the + // refraction pass tints what it lets through with it, so it is kept as it is. // A mapped colour comes from the image; an unmapped one already carries the base weight in the material's colour. bool mapped = (flags & 16) != 0 && !outside; vec3 layer = mapped ? base * clamp(pc.offs.w, 0.0, 1.0) : base; @@ -729,7 +764,8 @@ void main() { float metal = clamp(pc.frame.x, 0.0, 1.0); vec3 diffuse_color = layer * (1.0 - metal) * (1.0 - transmission); vec3 lin = emission + diff * diffuse_color * INV_PI + spec; - out_albedo = vec4(clamp(diffuse_color, 0.0, 1.0), alpha); + // Glass keeps its transmission colour for the refraction pass; a metal's own colour is already in its reflection. + out_albedo = vec4(clamp(transmission > 0.5 ? layer : diffuse_color, 0.0, 1.0), alpha); // Use Default Lighting: the viewport's key and fill, when no real light is in use. if (lt.head.x == 0) { vec3 k = normalize(vec3(-0.45, 0.6, 0.65)); @@ -737,32 +773,32 @@ void main() { float d = 0.75 * abs(dot(n, k)) + 0.3 * abs(dot(n, f)); lin += layer * (1.0 - metal) * (0.12 + 0.95 * d); } - // Image-based lighting: the sky dome, or nothing when the scene has none. + // Image-based lighting's diffuse half: the sky's irradiance, a few blurred samples around the normal, so a bright + // horizon reaches the surface as it does through Harold's path tracing. float rough = clamp(pc.frame.y, 0.02, 1.0); - vec3 r = reflect(-v, n); - vec3 wd = normalize((lt.view_to_world * vec4(r, 0.0)).xyz); - vec3 ld = normalize(qrot(lt.env_rot, wd)); - vec2 euv = vec2(atan(ld.z, ld.x) / (2.0 * PI) + 0.5, acos(clamp(ld.y, -1.0, 1.0)) / PI); - vec3 env = lt.env.w > 0.5 ? textureLod(sampler2D(t_env, s_env), euv, rough * 6.0).rgb : vec3(1.0); - env *= lt.env.rgb; - // The diffuse half is the sky's irradiance: a few blurred samples around the normal, so a bright horizon reaches the - // surface as it does through Harold's path tracing. vec3 wn = normalize((lt.view_to_world * vec4(n, 0.0)).xyz); vec3 env_d = lt.env.w > 0.5 ? env_irradiance(wn) : vec3(1.0); env_d *= lt.env.rgb; if (lt.env.w > 0.5 || dot(lt.env.rgb, lt.env.rgb) > 0.0) { - float nv = max(dot(n, v), 0.001); - float f0d = f_ior(max(pc.incandescence.w, 1.0)); - vec3 f0 = mix(vec3(f0d) * pc.ambient.rgb * pc.frame.w, layer, metal); - vec3 fres = f0 + (max(vec3(1.0 - rough), f0) - f0) * pow(1.0 - nv, 5.0); lin += env_d * diffuse_color; - lin += env * fres * (1.0 - 0.7 * rough); - if (pc.coat.x > 0.0) { - vec3 cf0 = vec3(f_ior(max(pc.coat.z, 1.0))); - vec3 cfres = cf0 + (max(vec3(1.0 - max(pc.coat.y, 0.02)), cf0) - cf0) * pow(1.0 - nv, 5.0); - lin += env * pc.coat.x * cfres; - } } + // The reflection is drawn by the screen-space pass from this material (#302): the environment feeds it where the + // view has no scene to reflect, and the scene where it has. + float nv = max(dot(n, v), 0.001); + float ior = max(pc.incandescence.w, 1.0); + vec3 f0 = mix(vec3(f_ior(ior)) * pc.ambient.rgb * pc.frame.w, layer, metal); + vec3 fres = f0 + (max(vec3(1.0 - rough), f0) - f0) * pow(1.0 - nv, 5.0); + vec3 coeff = fres * (1.0 - 0.7 * rough); + float look_rough = rough; + if (pc.coat.x > 0.0) { + float cr = max(pc.coat.y, 0.02); + vec3 cf0 = vec3(f_ior(max(pc.coat.z, 1.0))); + vec3 cfres = cf0 + (max(vec3(1.0 - cr), cf0) - cf0) * pow(1.0 - nv, 5.0); + coeff += cfres * pc.coat.x; + look_rough = min(look_rough, cr); + } + out_mat = vec4(coeff, look_rough + 0.002); + out_aux = vec4(transmission, clamp((ior - 1.0) * 0.5, 0.0, 1.0), metal, 1.0); out_color = vec4(pow(max(lin, vec3(0.0)), vec3(1.0 / 2.2)), alpha); } "#; @@ -895,6 +931,8 @@ pub struct Renderer { pub realtime: bool, rt_layout: vk::PipelineLayout, rt_pipelines: Vec<(Kind, vk::Pipeline)>, + /// The Realtime renderer's pipelines for the ground plane's reflection pass: the picture alone (#302). + rt_planar_pipelines: Vec<(Kind, vk::Pipeline)>, /// The Realtime shadow set: a 2D map, a cube map, and a sampler for each. pub rt_shadow_layout: vk::DescriptorSetLayout, } @@ -973,7 +1011,7 @@ impl Renderer { .depth_test_enable(!on_top) .depth_write_enable(matches!(kind, Kind::Shaded | Kind::ShadedCull | Kind::Lines | Kind::ColorTris)) .depth_compare_op(vk::CompareOp::GREATER_OR_EQUAL); - let blend = scene_blend(false); + let blend = scene_blend(false, false); let cb = vk::PipelineColorBlendStateCreateInfo::default().attachments(&blend); let mut dyns = vec![vk::DynamicState::VIEWPORT, vk::DynamicState::SCISSOR]; if feats.wide_lines != 0 && !shaded { @@ -1045,7 +1083,7 @@ impl Renderer { .depth_test_enable(true) .depth_write_enable(matches!(kind, Kind::Material | Kind::MaterialCull)) .depth_compare_op(vk::CompareOp::GREATER_OR_EQUAL); - let blend = scene_blend(false); + let blend = scene_blend(false, false); let cb = vk::PipelineColorBlendStateCreateInfo::default().attachments(&blend); let dyns = [vk::DynamicState::VIEWPORT, vk::DynamicState::SCISSOR]; let dy = vk::PipelineDynamicStateCreateInfo::default().dynamic_states(&dyns); @@ -1071,6 +1109,7 @@ impl Renderer { let rt_realtime = materials && limits.max_push_constants_size as usize >= std::mem::size_of::(); let mut rt_layout = vk::PipelineLayout::null(); let mut rt_pipelines = Vec::new(); + let mut rt_planar_pipelines = Vec::new(); let mut rt_shadow_layout = vk::DescriptorSetLayout::null(); if rt_realtime { let tex = crate::textures::set_layout(gpu); @@ -1116,7 +1155,7 @@ impl Renderer { .depth_test_enable(true) .depth_write_enable(matches!(kind, Kind::Material | Kind::MaterialCull)) .depth_compare_op(vk::CompareOp::GREATER_OR_EQUAL); - let blend = scene_blend(true); + let blend = scene_blend(true, true); let cb = vk::PipelineColorBlendStateCreateInfo::default().attachments(&blend); let dyns = [vk::DynamicState::VIEWPORT, vk::DynamicState::SCISSOR]; let dy = vk::PipelineDynamicStateCreateInfo::default().dynamic_states(&dyns); @@ -1135,6 +1174,29 @@ impl Renderer { .subpass(0); let p = d.create_graphics_pipelines(vk::PipelineCache::null(), &[info], None).map_err(|e| e.1).unwrap()[0]; rt_pipelines.push((kind, p)); + // The same draw for the ground plane's reflection pass: the picture alone, no material targets. + if matches!(kind, Kind::Material | Kind::MaterialCull) { + let blend = [vk::PipelineColorBlendAttachmentState::default() + .blend_enable(true) + .src_color_blend_factor(vk::BlendFactor::SRC_ALPHA) + .dst_color_blend_factor(vk::BlendFactor::ONE_MINUS_SRC_ALPHA) + .color_blend_op(vk::BlendOp::ADD) + .src_alpha_blend_factor(vk::BlendFactor::ONE) + .dst_alpha_blend_factor(vk::BlendFactor::ONE_MINUS_SRC_ALPHA) + .alpha_blend_op(vk::BlendOp::ADD) + .color_write_mask(vk::ColorComponentFlags::RGBA)]; + let cb = vk::PipelineColorBlendStateCreateInfo::default().attachments(&blend); + let ms = vk::PipelineMultisampleStateCreateInfo::default().rasterization_samples(vk::SampleCountFlags::TYPE_1); + // The mirror flips the winding: both sides are drawn, the shader turns the normal to the eye. + let rs = vk::PipelineRasterizationStateCreateInfo::default() + .polygon_mode(vk::PolygonMode::FILL) + .cull_mode(vk::CullModeFlags::NONE) + .front_face(vk::FrontFace::CLOCKWISE) + .line_width(1.0); + let info = info.color_blend_state(&cb).multisample_state(&ms).rasterization_state(&rs).render_pass(gpu.planar_pass); + let p = d.create_graphics_pipelines(vk::PipelineCache::null(), &[info], None).map_err(|e| e.1).unwrap()[0]; + rt_planar_pipelines.push((kind, p)); + } } d.destroy_shader_module(vs, None); d.destroy_shader_module(fs, None); @@ -1167,7 +1229,7 @@ impl Renderer { .depth_test_enable(true) .depth_write_enable(false) .depth_compare_op(vk::CompareOp::GREATER_OR_EQUAL); - let blend = scene_blend(false); + let blend = scene_blend(false, false); let cb = vk::PipelineColorBlendStateCreateInfo::default().attachments(&blend); let dyns = [vk::DynamicState::VIEWPORT, vk::DynamicState::SCISSOR]; let dy = vk::PipelineDynamicStateCreateInfo::default().dynamic_states(&dyns); @@ -1189,7 +1251,7 @@ impl Renderer { d.destroy_shader_module(vs, None); d.destroy_shader_module(fs, None); } - Renderer { layout, pipelines, line_width: feats.wide_lines != 0, materials, material_layout, light_layout, realtime: rt_realtime, rt_layout, rt_pipelines, rt_shadow_layout } + Renderer { layout, pipelines, line_width: feats.wide_lines != 0, materials, material_layout, light_layout, realtime: rt_realtime, rt_layout, rt_pipelines, rt_planar_pipelines, rt_shadow_layout } } } @@ -1226,6 +1288,15 @@ impl Renderer { } } + /// Binds a Realtime material for the ground plane's reflection pass (#302). + pub fn bind_realtime_planar(&self, gpu: &Gpu, kind: Kind, color: vk::DescriptorSet, alpha: vk::DescriptorSet, lights: vk::DescriptorSet, env: vk::DescriptorSet, shadow: vk::DescriptorSet) { + let p = self.rt_planar_pipelines.iter().find(|(k, _)| *k == kind).unwrap().1; + unsafe { + gpu.device.cmd_bind_pipeline(gpu.cmd, vk::PipelineBindPoint::GRAPHICS, p); + gpu.device.cmd_bind_descriptor_sets(gpu.cmd, vk::PipelineBindPoint::GRAPHICS, self.rt_layout, 0, &[color, alpha, lights, env, shadow], &[]); + } + } + pub fn push_realtime(&self, gpu: &Gpu, p: &RtPush) { unsafe { gpu.device.cmd_push_constants(gpu.cmd, self.rt_layout, vk::ShaderStageFlags::VERTEX | vk::ShaderStageFlags::FRAGMENT, 0, bytemuck::bytes_of(p)); diff --git a/crates/aztek_host/src/usd_view.rs b/crates/aztek_host/src/usd_view.rs index de97d5bd..cc26ae8d 100644 --- a/crates/aztek_host/src/usd_view.rs +++ b/crates/aztek_host/src/usd_view.rs @@ -130,7 +130,7 @@ fn make_pipes(gpu: &Gpu) -> Pipes { let rs = vk::PipelineRasterizationStateCreateInfo::default().polygon_mode(vk::PolygonMode::FILL).cull_mode(vk::CullModeFlags::NONE).front_face(vk::FrontFace::CLOCKWISE).line_width(1.0); let ms = vk::PipelineMultisampleStateCreateInfo::default().rasterization_samples(gpu.samples); let ds = vk::PipelineDepthStencilStateCreateInfo::default().depth_test_enable(true).depth_write_enable(!blending).depth_compare_op(vk::CompareOp::GREATER_OR_EQUAL); - let blend = crate::render::scene_blend(false); + let blend = crate::render::scene_blend(false, false); let cb = vk::PipelineColorBlendStateCreateInfo::default().attachments(&blend); let dyns = [vk::DynamicState::VIEWPORT, vk::DynamicState::SCISSOR]; let dy = vk::PipelineDynamicStateCreateInfo::default().dynamic_states(&dyns); diff --git a/crates/aztek_host/src/view.rs b/crates/aztek_host/src/view.rs index 075dca72..384d1ee8 100644 --- a/crates/aztek_host/src/view.rs +++ b/crates/aztek_host/src/view.rs @@ -307,7 +307,7 @@ impl View { return; }; // The last frame is done with them: the post pass reads this size's images. - self.post.bind_images(&self.gpu); + // (Bound after the lights are read: the reflections fall back on this frame's sky dome.) // The camera it looked through is gone (a new scene, a delete): back to the perspective camera. if !matches!(self.cam_node.as_str(), "persp" | "top" | "front" | "side") && !matches!(core.s.graph.find(&self.cam_node), Ok(Some(_))) { self.cam_node = "persp".to_string(); @@ -348,13 +348,54 @@ impl View { core.push("// Warning: the Default renderer needs a graphics device with 256 bytes of push constants: drawing with Legacy //".to_string(), crate::core::LineKind::Warning); } self.vp.prepare_lights(&self.gpu, &self.r, &mut core.s, &items, realtime); + // The post pass reads the scene's images, its material and the sky dome the reflections fall back on. + let (env, env_rot, env_set) = self.vp.lit.as_ref().map(|l| l.environment()).unwrap_or(([0.0; 4], [0.0, 0.0, 0.0, 1.0], None)); + self.post.bind_images(&self.gpu, env_set); + let (reflector, reflector_up, reflector_point) = ground_reflector(&items); + let planar_on = realtime && reflector != aztek_scene::plug::NO_NODE; + self.vp.planar_debug_color = std::env::var("AZTEK_PLANAR_DEBUG_COLOR").ok().map(|_| [0.0, 1.0, 0.0]); + // What glass lets through: the scene without its transmissive surfaces, drawn from the camera's own view + // and lights (#302). Nothing is drawn when no material transmits. + if realtime && self.vp.needs_back() { + self.vp.back = true; + self.gpu.begin_back(); + self.vp.draw(&mut self.gpu, &self.r, &mut core.s, &items, self.dpr, realtime); + self.gpu.end_back(); + self.vp.back = false; + } + // The ground plane's reflection: the scene mirrored below the world's ground, drawn before the camera's own view + // so the floor can read what it reflects (#302). + if planar_on { + let up = DVec3::new(reflector_up[0] as f64, reflector_up[1] as f64, reflector_up[2] as f64); + let point = DVec3::new(reflector_point[0], reflector_point[1], reflector_point[2]); + let mut r = DMat4::IDENTITY; + for i in 0..3 { + for j in 0..3 { + r.col_mut(i)[j] = if i == j { 1.0 } else { 0.0 } - 2.0 * up[i] * up[j]; + } + } + let mirror = DMat4::from_translation(point) * r * DMat4::from_translation(-point); + self.vp.planar_skip = reflector; + self.vp.planar = Some(mirror); + // The mirrored side facing the floor is the real underside, which the main light does not reach: a plain + // fill stands in for the floor's bounce. The view stays the main one. + let proj_main = self.vp.cam.proj(self.vp.aspect()); + self.vp.write_lights_for(&mut core.s, &items, self.vp.cam.view(), proj_main, self.vp.disp.light_mode); + self.gpu.begin_planar(); + self.vp.draw(&mut self.gpu, &self.r, &mut core.s, &items, self.dpr, realtime); + self.gpu.end_planar(); + self.vp.planar = None; + } // The shadow map is drawn before the scene's pass, with the lights read. if realtime { if self.realtime.is_none() { self.realtime = Some(crate::realtime::Realtime::new(&self.gpu, self.r.rt_shadow_layout)); } + // A transmissive shape passes light instead of blocking it: drawing it into the shadow map would put an + // opaque shadow under the glass and the glass would refract that black floor. Leave it out of the casters. + let glass = self.vp.transmissive_shapes(&items); if let Some(rt) = self.realtime.as_mut() { - rt.render(&mut self.gpu, &items, self.vp.shadow); + rt.render(&mut self.gpu, &items, self.vp.shadow, &glass); } // The material pipelines' set 4 has this renderer's four bindings: it is bound whether or not a shadow map // is drawn this frame, and the shader skips the sampling when no light casts one (#228 review). @@ -397,12 +438,38 @@ impl View { high_quality: realtime, bounce: if realtime && d.bounce_light && !d.xray { 1.0 } else { 0.0 }, dof, + reflections: realtime && !d.xray && std::env::var("AZTEK_REFLECTIONS").map_or(true, |v| v != "0"), + debug_reflection: std::env::var("AZTEK_REFLECTION_DEBUG").ok().and_then(|v| v.parse().ok()).unwrap_or(0), + planar_reflection: planar_on, + up: reflector_up, + view: self.vp.cam.view().as_mat4(), + env, + env_rot, }; - self.gpu.begin_occlusion(); + // Reflections and refraction, from the scene's colour, depth and material, before the picture is put together. + self.gpu.begin_reflection(); + self.post.draw_reflection(&self.gpu, proj, ortho, &settings); + self.gpu.end_reflection(); + // A small low-pass of the reflection image, so one bright texel does not come back as a speckle (#302), and + // the filtered copies the gather picks a level from by the surface's roughness. + if settings.reflections { + self.gpu.begin_refl_blur(); + self.post.draw_reflection_blur(&self.gpu, proj, ortho, &settings); + self.gpu.end_refl_blur(); + self.gpu.build_reflection_mips(); + } + self.gpu.begin_occlusion_after(); self.post.draw_occlusion(&self.gpu, proj, ortho, &settings); if settings.bounce > 0.0 { self.gpu.begin_bounce(); self.post.draw_bounce(&self.gpu, proj, ortho, &settings); + // The bounce's rays are stochastic: low-pass it along each axis into a soft, continuous field before the + // picture reads it, so no single hit comes back as a bright texel (#302). + self.gpu.begin_bounce_blur_h(); + self.post.draw_bounce_blur(&self.gpu, proj, ortho, &settings, true); + self.gpu.begin_bounce_blur_v(); + self.post.draw_bounce_blur(&self.gpu, proj, ortho, &settings, false); + // The pass stays open: begin_post ends whichever pass is current. } self.gpu.begin_post(index); self.post.draw(&self.gpu, proj, ortho, &settings); @@ -2555,6 +2622,7 @@ impl View { self.vp.grid_extent = v.as_f64().unwrap_or(12.0).max(1.0); self.vp.reset_grid(&mut self.gpu); } + "viewCubeVisible" => crate::view_cube::set_hidden(!v.as_bool().unwrap_or(true)), "viewCube" => { let action = v.get("action").and_then(Value::as_str).unwrap_or("redraw").to_string(); self.cube_action(core, &action); @@ -2751,6 +2819,31 @@ pub fn finish_joint_chain(core: &mut Core) { } /// Component names with their mirror images, on meshes whose symmetry is on. +/// The mesh a ground plane's reflection is for: the widest flat one at the world's ground, along either up axis, and +/// that axis. Its own image would hide everything the mirrored scene puts below it (#302). +fn ground_reflector(items: &[crate::viewport::DrawItem]) -> (aztek_scene::plug::NodeId, [f32; 3], [f64; 3]) { + let mut best = (aztek_scene::plug::NO_NODE, [0.0, 1.0, 0.0], 0.0, [0.0; 3]); + for it in items { + let b = it.mesh.bounds(); + let (lo, hi) = (it.world.transform_point3(b.min), it.world.transform_point3(b.max)); + // Y up and Z up are both tried: a scene keeps its own geometry whatever the preferences' up axis is. + for (axis, up) in [(1usize, [0.0, 1.0, 0.0]), (2usize, [0.0, 0.0, 1.0])] { + let height = (hi[axis] - lo[axis]).abs(); + if height > 0.05 || lo[axis].abs() > 0.05 || hi[axis].abs() > 0.05 { + continue; + } + let (a, c) = if axis == 1 { (0, 2) } else { (0, 1) }; + let area = ((hi[a] - lo[a]) * (hi[c] - lo[c])).abs(); + if area > best.2 { + let mut point = [(lo.x + hi.x) * 0.5, (lo.y + hi.y) * 0.5, (lo.z + hi.z) * 0.5]; + point[axis] = hi[axis]; + best = (it.shape, up, area, point); + } + } + } + (best.0, best.1, best.3) +} + fn with_mirror_images(core: &mut Core, picked: Vec) -> Vec { let mut out = Vec::new(); for name in picked { @@ -2880,3 +2973,18 @@ mod renderer_tests { assert_eq!(RendererKind::default(), RendererKind::Realtime); } } + +#[cfg(test)] +mod reflector_tests { + use super::ground_reflector; + use aztek_scene::plug::NO_NODE; + + #[test] + fn the_reflections_example_has_a_ground_reflector() { + let mut s = aztek_scene::Session::new(); + let path = concat!(env!("CARGO_MANIFEST_DIR"), "/../../examples/rendering/reflections.ma"); + aztek_scene::ma_file::open_scene(&mut s, path).expect("open the reflections example"); + let items = crate::viewport::gather(&mut s.graph); + assert_ne!(ground_reflector(&items).0, NO_NODE); + } +} diff --git a/crates/aztek_host/src/view_cube.rs b/crates/aztek_host/src/view_cube.rs index 021633c2..6706eb4b 100644 --- a/crates/aztek_host/src/view_cube.rs +++ b/crates/aztek_host/src/view_cube.rs @@ -36,6 +36,8 @@ thread_local! { static HOMES: RefCell> = RefCell::new(HashMap::new()); /// Set Current View as Front's turn, degrees. static FRONT: RefCell = const { RefCell::new(0.0) }; + /// Hidden for a capture of the scene alone; a capture run has one view. + static HIDDEN: std::cell::Cell = const { std::cell::Cell::new(false) }; } fn setting(key: &str) -> Value { @@ -68,7 +70,12 @@ pub fn flag(key: &str) -> bool { } pub fn visible() -> bool { - setting("visible").as_bool().unwrap_or(true) + setting("visible").as_bool().unwrap_or(true) && !HIDDEN.with(|h| h.get()) +} + +/// Hides the cube for a capture of the scene alone. +pub fn set_hidden(hidden: bool) { + HIDDEN.with(|h| h.set(hidden)); } pub fn front() -> f64 { diff --git a/crates/aztek_host/src/viewport.rs b/crates/aztek_host/src/viewport.rs index 51566928..92608730 100644 --- a/crates/aztek_host/src/viewport.rs +++ b/crates/aztek_host/src/viewport.rs @@ -355,8 +355,14 @@ fn material_push(base: Push, m: &DrawMaterial, sets: Option<&MatSets>) -> (MatPu /// parameters: `frame` the roughness and weights, `offs.w` the base weight, `ambient` the specular colour, and `coat` /// the coat and transmission. fn realtime_push(mp: &MatPush, m: &DrawMaterial, highlight: f32) -> crate::render::RtPush { + let mut base = mp.base; + // A transmissive surface is drawn solid and taken apart by the screen-space refraction pass (#302): blending it + // against the background here would show that background twice. + if m.pbr.transmission_weight > 0.5 { + base.color[3] = 1.0; + } crate::render::RtPush { - base: mp.base, + base, uv: mp.uv, frame: [m.pbr.metalness, m.pbr.specular_roughness, m.pbr.diffuse_roughness, m.pbr.specular_weight], misc: mp.misc, @@ -735,6 +741,14 @@ pub struct Viewport { pub disp: Display, /// The light the Realtime renderer's shadow map is drawn from, and its camera: read by `View` before the frame. pub shadow: Option, + /// The ground plane's reflection pass draws with this view instead of the camera's (#302). + pub planar: Option, + /// The mesh that is the reflector, left out of the mirrored draw. + pub planar_skip: NodeId, + /// A flat colour for the mirrored pass instead of the material, for measuring its image (#302). + pub planar_debug_color: Option<[f32; 3]>, + /// Drawing the scene without its transmissive surfaces, for glass to see what it lets through (#302). + pub back: bool, /// The sky dome the Realtime renderer lights from. pub environment: Option, /// The Realtime renderer's shadow map, bound as set 4 of its material pipelines. @@ -839,6 +853,10 @@ impl Viewport { lit: None, shadow: None, environment: None, + planar: None, + planar_skip: NO_NODE, + planar_debug_color: None, + back: false, rt_shadow_set: None, contact: None, look_camera: NO_NODE, @@ -1170,6 +1188,48 @@ impl Viewport { } } + /// Whether any material in the scene lets light through, so the behind-glass draw is worth making (#302). + pub fn needs_back(&self) -> bool { + self.mats.materials.values().any(|m| m.pbr.transmission_weight > 0.5) + } + + + /// Whether any material in the scene is glossy enough to reflect, so the ground plane's mirrored draw is worth + /// making (#302). + /// The shapes whose shading group lets light through, for the shadow map to leave out: glass passes light, so an + /// opaque shadow under it would be wrong, and the glass would refract that black floor. + pub fn transmissive_shapes(&self, items: &[DrawItem]) -> std::collections::HashSet { + let groups: Vec = self + .mats + .materials + .iter() + .filter(|(_, m)| m.pbr.transmission_weight > 0.5) + .map(|(&sg, _)| sg) + .collect(); + if groups.is_empty() { + return Default::default(); + } + let member = |node: NodeId| { + groups.iter().any(|sg| { + self.mats + .members + .get(sg) + .is_some_and(|ms| ms.iter().any(|(m, _)| *m == node)) + }) + }; + items + .iter() + .filter(|it| member(it.shape) || member(it.xf)) + .map(|it| it.shape) + .collect() + } + + pub fn needs_planar(&self) -> bool { + self.mats.materials.values().any(|m| { + m.pbr.metalness > 0.05 || (m.pbr.specular_weight > 0.0 && m.pbr.specular_roughness < 0.45) + }) + } + /// This frame's lights, highlights and links, as the view's Lighting menu asks. Runs before the frame's command /// buffer, so the shadow map it plans can be drawn first. pub fn prepare_lights(&mut self, gpu: &Gpu, r: &Renderer, s: &mut Session, items: &[DrawItem], realtime: bool) { @@ -1202,6 +1262,16 @@ impl Viewport { lit.write_block(mode, &chosen, &view, &proj, self.disp.two_sided, self.cam.orthographic, shadow_plan.map(|p| p.block(&view))); } + /// This frame's lights again, in the planar reflection's own buffer: the same view and lights as the camera's, with + /// no shadow map, since the mirrored geometry would sample it at the wrong place (#302). + pub fn write_lights_for(&mut self, s: &mut Session, _items: &[DrawItem], view: DMat4, proj: DMat4, mode: crate::lighting::LightMode) { + let Some(lit) = self.lit.as_mut() else { return }; + // The same lights as the camera's own pass, re-selected so they can go in the planar buffer without the shadow + // map. The per-shape masks are already the ones prepare_lights worked out for those same lights. + let chosen = crate::lighting::chosen(&mut s.graph, mode, visible); + lit.write_planar_block(mode, &chosen, &view, &proj, self.disp.two_sided, self.cam.orthographic); + } + pub fn draw(&mut self, gpu: &mut Gpu, r: &Renderer, s: &mut Session, items: &[DrawItem], scale: f64, realtime: bool) { self.prune(gpu, items); let [x, y, w, h] = self.rect; @@ -1209,8 +1279,10 @@ impl Viewport { return; } r.set_viewport(gpu, x as f32, y as f32, w as f32, h as f32); - let vp = self.view_proj(); + let planar = self.planar.is_some(); + // The planar pass keeps the main camera: the models are mirrored instead. let view = self.cam.view(); + let vp = self.cam.proj((w / h.max(1.0)).max(1e-6)) * view; let colors = GridStyle::colors(); // An orthographic view's grid follows what it shows. if self.grid.is_some() && (self.cam.orthographic || self.grid_up_z != aztek_scene::world::up_z() || self.grid_colors != colors) { @@ -1234,6 +1306,13 @@ impl Viewport { let mut transparent: Vec = Vec::new(); let smooth_cage = self.smooth_cage || (self.force_cage && self.tool == Tool::MultiCut); for it in items { + // The ground plane's own mesh is the reflector, not part of what it reflects (#302). + if planar && it.shape == self.planar_skip { + continue; + } + // The planar pass mirrors the model, not the camera: positions and normals follow, the view and lights + // stay the main pass's (#302). + let world = self.planar.map_or(it.world, |m| m * it.world); let entry = self.meshes.entry(it.shape).or_insert_with(|| GpuMesh { drawn: None, mesh_gen: 0, @@ -1440,7 +1519,7 @@ impl Viewport { // Soft selection's falloff in false colour, by softSelect's colour ramp: yellow at the selection // through red to black, to begin with. let pts = components::convert(&it.mesh, mode, comps, ComponentMode::Vertex, false); - let w = aztek_scene::mesh_edit::transform::soft_weights(g, &it.mesh, &it.world, &pts); + let w = aztek_scene::mesh_edit::transform::soft_weights(g, &it.mesh, &world, &pts); let ramp = aztek_scene::soft_select::FalseColors::current(); let mut pv = Vec::new(); for p in 0..it.mesh.point_capacity() { @@ -1566,7 +1645,7 @@ impl Viewport { entry.batch_faces = faces; entry.batches = batches; } - let mvp = vp * it.world; + let mvp = vp * world; // Paint skin weights: the painted influence's weight in grey, white for 1, as the reference's colour feedback. let mut painted = false; // The values in grey, white for 1, as the reference's colour feedback; a held influence reads blue. @@ -1637,7 +1716,7 @@ impl Viewport { } if let Some((vb, ib, n)) = &entry.weight_tris { r.bind(gpu, Kind::ColorTris); - r.push(gpu, &push(mvp, it.world, view, [1.0; 4], 0.0, 1.0)); + r.push(gpu, &push(mvp, world, view, [1.0; 4], 0.0, 1.0)); r.draw(gpu, vb, Some((ib, *n)), 0); painted = true; } @@ -1671,7 +1750,7 @@ impl Viewport { let b = gpu.buffer_with(vk::BufferUsageFlags::VERTEX_BUFFER, &v); r.bind(gpu, Kind::Lines); r.set_line_width(gpu, 1.0); - r.push(gpu, &push(mvp, it.world, view, [1.0; 4], 1e-3, 1.0)); + r.push(gpu, &push(mvp, world, view, [1.0; 4], 1e-3, 1.0)); r.draw(gpu, &b, None, v.len() as u32); gpu.drop_buffer(b); continue; @@ -1713,7 +1792,7 @@ impl Viewport { if on_live && self.disp.highlight && self.live.color.is_some() { r.bind(gpu, Kind::Tint); let c = self.live.color.unwrap_or([0.2, 0.42, 0.95]); - let mut pc = push(mvp, it.world, view, [c[0], c[1], c[2], self.live.alpha.unwrap_or(1.0)], retopo, 1.0); + let mut pc = push(mvp, world, view, [c[0], c[1], c[2], self.live.alpha.unwrap_or(1.0)], retopo, 1.0); pc.n2[3] = self.disp.flat as i32 as f32; flip(&mut pc); r.push(gpu, &pc); @@ -1721,14 +1800,14 @@ impl Viewport { } else if self.disp.xray || obj_xray { // X-Ray: see-through, no sorting. r.bind(gpu, Kind::Tint); - let mut pc = push(mvp, it.world, view, [0.55, 0.55, 0.55, 0.45], retopo, 1.0); + let mut pc = push(mvp, world, view, [0.55, 0.55, 0.55, 0.45], retopo, 1.0); pc.n2[3] = self.disp.flat as i32 as f32; flip(&mut pc); r.push(gpu, &pc); r.draw(gpu, vb, Some((ib, *n)), 0); } else if self.disp.default_material && (self.disp.light_mode == crate::lighting::LightMode::Default || !r.materials) && !(checker_set.is_some() && checkered) { r.bind(gpu, if self.disp.backface || obj_cull { Kind::ShadedCull } else { Kind::Shaded }); - let mut pc = push(mvp, it.world, view, [0.5, 0.5, 0.5, 1.0], retopo, 1.0); + let mut pc = push(mvp, world, view, [0.5, 0.5, 0.5, 1.0], retopo, 1.0); pc.n2[3] = self.disp.flat as i32 as f32; flip(&mut pc); r.push(gpu, &pc); @@ -1760,7 +1839,7 @@ impl Viewport { None if partial.is_some() => (None, &[]), None => (entry.batch_ib.as_ref(), &batches), }; - let depth = (view * it.world.w_axis).z; + let depth = (view * world.w_axis).z; for (bi, b) in draw_list.iter().enumerate() { let green = no_material(); let grey = default_grey(); @@ -1776,32 +1855,50 @@ impl Viewport { } else { self.mats.materials.get(&b.group).or(self.mats.fallback.as_ref()).unwrap_or(&green) }; - let mut pc = push(mvp, it.world, view, [m.color[0], m.color[1], m.color[2], 1.0], retopo, 1.0); + // A flat colour for measuring the mirrored pass; not used for the normal picture. + let flat = if planar { self.planar_debug_color.map(|c| DrawMaterial { unlit: true, color: c, ..no_material() }) } else { None }; + let m = flat.as_ref().unwrap_or(m); + if self.back && m.pbr.transmission_weight > 0.5 { + continue; + } + // The mirrored vertex keeps the real model's normal: the planar image is the real scene's + // shading, mirrored about the floor, which is what the floor shows (#302). + let shade = if planar { it.world } else { world }; + let mut pc = push(mvp, shade, view, [m.color[0], m.color[1], m.color[2], 1.0], retopo, 1.0); pc.n2[3] = self.disp.flat as i32 as f32; flip(&mut pc); let (mut mp, clear) = material_push(pc, m, if checker_sets.is_some() { checker_sets.as_ref() } else if plain { None } else { self.mats.sets.get(&b.group).filter(|_| style.textured) }); stamp_lights(&self.lit, &mut mp, it.shape, if plain { NO_NODE } else { b.group }); + // Glass is drawn with the solid surfaces when the Realtime renderer's screen-space refraction + // pass takes it apart (#302); the legacy renderer still blends it. + let refractive = realtime && r.realtime && m.pbr.transmission_weight > 0.5; // The isolated draws are for this frame only, so see-through ones go now rather than later. - if clear && shown_batches.is_none() && r.materials { - transparent.push(Clear { shape: it.shape, world: it.world, batch: bi, depth, retopo }); + if clear && !refractive && shown_batches.is_none() && r.materials { + transparent.push(Clear { shape: it.shape, world, batch: bi, depth, retopo }); continue; } let (Some(ib), Some(uvs)) = (draw_ib, entry.uvs.as_ref()) else { continue }; if r.materials { let sets = if checker_sets.is_some() { checker_sets.as_ref() } else if plain { None } else { self.mats.sets.get(&b.group).filter(|_| style.textured) }; let white = crate::textures::with_cache(gpu, |c| c.white(gpu)); - let kind = match (clear, self.disp.backface || obj_cull) { - (false, false) => Kind::Material, - (false, true) => Kind::MaterialCull, - (true, false) => Kind::MaterialBlend, - (true, true) => Kind::MaterialBlendCull, + let solid = !clear || refractive; + let kind = match (solid, self.disp.backface || obj_cull) { + (true, false) => Kind::Material, + (true, true) => Kind::MaterialCull, + (false, false) => Kind::MaterialBlend, + (false, true) => Kind::MaterialBlendCull, }; - let lights = self.lit.as_ref().map_or(vk::DescriptorSet::null(), |l| l.set); + // The planar draw has no shadow map: its shadow would be sampled at the mirrored point. + let lights = self.lit.as_ref().map_or(vk::DescriptorSet::null(), |l| if planar { l.planar_set } else { l.set }); if realtime && r.realtime { let env = self.lit.as_ref().and_then(|l| l.env_set).unwrap_or(white); let shadow = self.rt_shadow_set.unwrap_or(white); let rp = realtime_push(&mp, m, self.lit.as_ref().map_or(0.0, |l| l.index.get(&b.group).copied().unwrap_or(0) as f32)); - r.bind_realtime(gpu, kind, sets.and_then(|x| x.color).unwrap_or(white), sets.and_then(|x| x.alpha).unwrap_or(white), lights, env, shadow); + if planar || self.back { + r.bind_realtime_planar(gpu, kind, sets.and_then(|x| x.color).unwrap_or(white), sets.and_then(|x| x.alpha).unwrap_or(white), lights, env, shadow); + } else { + r.bind_realtime(gpu, kind, sets.and_then(|x| x.color).unwrap_or(white), sets.and_then(|x| x.alpha).unwrap_or(white), lights, env, shadow); + } r.push_realtime(gpu, &rp); } else { r.bind_material(gpu, kind, sets.and_then(|x| x.color).unwrap_or(white), sets.and_then(|x| x.alpha).unwrap_or(white), lights); @@ -1821,16 +1918,18 @@ impl Viewport { gpu.drop_buffer(b); } } + if !planar && !self.back { if let Some((ti, tn)) = &entry.mirror_tint { r.bind(gpu, Kind::Tint); - r.push(gpu, &push(mvp, it.world, view, [0.2, 0.6, 1.0, 0.45], 2e-4, 1.0)); + r.push(gpu, &push(mvp, world, view, [0.2, 0.6, 1.0, 0.45], 2e-4, 1.0)); r.draw(gpu, vb, Some((ti, *tn)), 0); } if let Some((ti, tn)) = &entry.tint { r.bind(gpu, Kind::Tint); - r.push(gpu, &push(mvp, it.world, view, [1.0, 0.45, 0.05, 0.45], 2e-4, 1.0)); + r.push(gpu, &push(mvp, world, view, [1.0, 0.45, 0.05, 0.45], 2e-4, 1.0)); r.draw(gpu, vb, Some((ti, *tn)), 0); } + } } } if let Some((b, _)) = partial { @@ -1838,7 +1937,7 @@ impl Viewport { } // Wireframe Overlay: a mesh built on the live surface draws its wire in the overlay's colour, unless its // components are showing. - let overlay = if on_live && !hilited { self.live.wire } else { None }; + let overlay = if on_live && !hilited && !planar && !self.back { self.live.wire } else { None }; if let Some(c) = overlay { let col = [c[0], c[1], c[2], 1.0]; let m = &it.mesh; @@ -1852,25 +1951,27 @@ impl Viewport { let b = gpu.buffer_with(vk::BufferUsageFlags::VERTEX_BUFFER, &lv); r.bind(gpu, Kind::Lines); r.set_line_width(gpu, 1.0); - r.push(gpu, &push(mvp, it.world, view, [1.0; 4], 1.5e-3 + retopo, 1.0)); + r.push(gpu, &push(mvp, world, view, [1.0; 4], 1.5e-3 + retopo, 1.0)); r.draw(gpu, &b, None, lv.len() as u32); gpu.drop_buffer(b); } } - if let Some((lb, ln)) = entry.lines.as_ref().filter(|_| overlay.is_none()) { + if let Some((lb, ln)) = entry.lines.as_ref().filter(|_| overlay.is_none() && !planar && !self.back) { r.bind(gpu, if self.disp.xray_active && hilited { Kind::LinesOnTop } else { Kind::Lines }); r.set_line_width(gpu, if selected && mode == ComponentMode::Object { 1.5 } else { 1.0 }); - r.push(gpu, &push(mvp, it.world, view, [1.0; 4], 1.5e-3 + retopo, 1.0)); + r.push(gpu, &push(mvp, world, view, [1.0; 4], 1.5e-3 + retopo, 1.0)); r.draw(gpu, lb, None, *ln); } - if let Some((pb, pn)) = &entry.points { - r.bind(gpu, if self.disp.xray_active && hilited { Kind::PointsOnTop } else { Kind::Points }); - r.push(gpu, &push(mvp, it.world, view, [1.0; 4], 2e-3, (5.0 * scale) as f32)); - r.draw(gpu, pb, None, *pn); + if !planar && !self.back { + if let Some((pb, pn)) = &entry.points { + r.bind(gpu, if self.disp.xray_active && hilited { Kind::PointsOnTop } else { Kind::Points }); + r.push(gpu, &push(mvp, world, view, [1.0; 4], 2e-3, (5.0 * scale) as f32)); + r.draw(gpu, pb, None, *pn); + } } } // The grid reads the depth of solid geometry so it can cross through a surface. - if self.show_grid { + if self.show_grid && !planar && !self.back { r.bind(gpu, Kind::SmoothLines); let mut p = push(vp, DMat4::IDENTITY, view, [1.0; 4], 0.0, 1.0); p.n2 = [w as f32, h as f32, 0.5, 0.0]; @@ -1887,7 +1988,7 @@ impl Viewport { } // See-through materials last, the furthest first, reading the depth the solid ones wrote. transparent.sort_by(|a, b| a.depth.total_cmp(&b.depth)); - for c in &transparent { + for c in transparent.iter().filter(|_| !planar && !self.back) { let Some(entry) = self.meshes.get(&c.shape) else { continue }; let (Some((vb, _, _)), Some(ib), Some(uvs)) = (&entry.tris, entry.batch_ib.as_ref(), entry.uvs.as_ref()) else { continue }; let Some(b) = entry.batches.get(c.batch).copied() else { continue }; @@ -1913,6 +2014,9 @@ impl Viewport { } r.draw_material(gpu, vb, uvs, ib, b.first, b.count); } + if planar || self.back { + return; + } crate::usd_view::draw(gpu, r, s, vp, view); self.draw_image_planes(gpu, r, s); self.draw_ghosts(gpu, r, s); diff --git a/examples/rendering/area_lights.ma b/examples/rendering/area_lights.ma new file mode 100644 index 00000000..b7939626 --- /dev/null +++ b/examples/rendering/area_lights.ma @@ -0,0 +1,209 @@ +//Maya ASCII 2024 scene +//Name: .area_lights.ma.tmp +//Codeset: UTF-8 +requires maya "2024"; +currentUnit -l centimeter -a degree -t film; +fileInfo "application" "aztek"; +fileInfo "version" "1.0.0"; +createNode transform -s -n "persp"; + setAttr ".v" no; + setAttr ".t" -type "double3" 0 3.6 11 ; + setAttr ".r" -type "double3" -12.308015817427929 0 0 ; +createNode camera -s -n "perspShape" -p "persp"; + setAttr ".fl" 50; + setAttr ".coi" 11.258774356030056; + setAttr ".imn" -type "string" "persp"; + setAttr ".den" -type "string" "persp_depth"; + setAttr ".man" -type "string" "persp_mask"; + setAttr ".hc" -type "string" "viewSet -p %camera"; +createNode transform -s -n "top"; + setAttr ".v" no; + setAttr ".t" -type "double3" 0 1000.1 0 ; + setAttr ".r" -type "double3" -90 0 0 ; +createNode camera -s -n "topShape" -p "top"; + setAttr ".coi" 1000.1; + setAttr ".o" yes; + setAttr ".rnd" no; + setAttr ".imn" -type "string" "top"; + setAttr ".den" -type "string" "top_depth"; + setAttr ".man" -type "string" "top_mask"; + setAttr ".hc" -type "string" "viewSet -t %camera"; +createNode transform -s -n "front"; + setAttr ".v" no; + setAttr ".t" -type "double3" 0 0 1000.1 ; +createNode camera -s -n "frontShape" -p "front"; + setAttr ".coi" 1000.1; + setAttr ".o" yes; + setAttr ".rnd" no; + setAttr ".imn" -type "string" "front"; + setAttr ".den" -type "string" "front_depth"; + setAttr ".man" -type "string" "front_mask"; + setAttr ".hc" -type "string" "viewSet -f %camera"; +createNode transform -s -n "side"; + setAttr ".v" no; + setAttr ".t" -type "double3" 1000.1 0 0 ; + setAttr ".r" -type "double3" 0 90 0 ; +createNode camera -s -n "sideShape" -p "side"; + setAttr ".coi" 1000.1; + setAttr ".o" yes; + setAttr ".rnd" no; + setAttr ".imn" -type "string" "side"; + setAttr ".den" -type "string" "side_depth"; + setAttr ".man" -type "string" "side_mask"; + setAttr ".hc" -type "string" "viewSet -s %camera"; +createNode transform -n "floor"; + setAttr ".t" -type "double3" 0 -0.01 0 ; +createNode mesh -n "floorShape" -p "floor"; + setAttr -k off ".v"; +createNode transform -n "redBall"; + setAttr ".t" -type "double3" -2.2 1.3 0 ; +createNode mesh -n "redBallShape" -p "redBall"; + setAttr -k off ".v"; +createNode transform -n "blueBall"; + setAttr ".t" -type "double3" 2.2 1.3 0 ; +createNode mesh -n "blueBallShape" -p "blueBall"; + setAttr -k off ".v"; +createNode transform -n "keyArea"; + setAttr ".t" -type "double3" -3.2 5.5 4 ; + setAttr ".r" -type "double3" -45 35 0 ; + setAttr ".s" -type "double3" 2.5 2.5 1 ; +createNode aiAreaLight -n "keyAreaShape" -p "keyArea"; + setAttr -k off ".v"; + setAttr ".in" 250; +createNode transform -n "fillArea"; + setAttr ".t" -type "double3" 4 4.5 3 ; + setAttr ".r" -type "double3" -45 35 0 ; + setAttr ".s" -type "double3" 2 2 1 ; +createNode aiAreaLight -n "fillAreaShape" -p "fillArea"; + setAttr -k off ".v"; + setAttr ".in" 90; +createNode transform -n "shotCam"; + setAttr ".t" -type "double3" 0 3.6 11 ; + setAttr ".r" -type "double3" -8 0 0 ; +createNode camera -n "shotCamShape" -p "shotCam"; + setAttr -k off ".v"; + setAttr ".fl" 50; + setAttr ".coi" 10; +createNode lightLinker -s -n "lightLinker1"; +createNode displayLayerManager -n "layerManager"; +createNode displayLayer -n "defaultLayer"; + setAttr ".ufem" -type "stringArray" 0 ; +createNode renderLayerManager -n "renderLayerManager"; +createNode renderLayer -n "defaultRenderLayer"; + setAttr ".g" yes; +createNode standardSurface -n "floorMat"; + setAttr ".bc" -type "float3" 0.38 0.39 0.41 ; +createNode shadingEngine -n "floorMatSG"; + setAttr ".ihi" 0; + setAttr ".ro" yes; +createNode standardSurface -n "redBallMat"; + setAttr ".bc" -type "float3" 0.8 0.1 0.08 ; + setAttr ".sr" 0.15; +createNode shadingEngine -n "redBallMatSG"; + setAttr ".ihi" 0; + setAttr ".ro" yes; +createNode standardSurface -n "blueBallMat"; + setAttr ".bc" -type "float3" 0.08 0.25 0.75 ; + setAttr ".sr" 0.15; +createNode shadingEngine -n "blueBallMatSG"; + setAttr ".ihi" 0; + setAttr ".ro" yes; +createNode polyCube -n "polyCube1"; + setAttr ".w" 30; + setAttr ".h" 0.02; + setAttr ".d" 30; + setAttr ".sw" 20; + setAttr ".sh" 1; + setAttr ".sd" 20; +createNode polySphere -n "polySphere1"; + setAttr ".r" 1.3; + setAttr ".sa" 48; + setAttr ".sh" 32; +createNode polySphere -n "polySphere2"; + setAttr ".r" 1.3; + setAttr ".sa" 48; + setAttr ".sh" 32; +createNode aiOptions -s -n "defaultArnoldRenderOptions"; +createNode aiAOVFilter -s -n "defaultArnoldFilter"; +createNode aiAOVDriver -s -n "defaultArnoldDriver"; +createNode aiAOVDriver -s -n "defaultArnoldDisplayDriver"; +select -ne :lightList1; + setAttr -s 2 ".l"; +select -ne :defaultLightSet; + setAttr -s 2 ".dsm"; +createNode script -n "sceneConfigurationScriptNode"; + setAttr ".b" -type "string" "playbackOptions -min 1 -max 120 -ast 1 -aet 200 "; + setAttr ".st" 6; +select -ne :time1; + setAttr ".o" 1; + setAttr ".unw" 1; +select -ne :hardwareRenderingGlobals; + setAttr ".fprt" yes; + setAttr ".rtfm" 1; + setAttr ".otfna" -type "stringArray" 22 "NURBS Curves" "NURBS Surfaces" "Polygons" "Subdiv Surface" "Particles" "Particle Instance" "Fluids" "Strokes" "Image Planes" "UI" "Lights" "Cameras" "Locators" "Joints" "IK Handles" "Deformers" "Motion Trails" "Components" "Hair Systems" "Follicles" "Misc. UI" "Ornaments"; + setAttr ".otfva" -type "Int32Array" 22 0 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0; +select -ne :renderPartition; + setAttr -s 5 ".st"; +select -ne :renderGlobalsList1; +select -ne :defaultShaderList1; + setAttr -s 9 ".s"; +select -ne :postProcessList1; + setAttr -s 2 ".p"; +select -ne :defaultRenderingList1; +select -ne :standardSurface1; + setAttr ".bc" -type "float3" 0.4 0.4 0.4 ; + setAttr ".sr" 0.5; +select -ne :openPBR_shader1; + setAttr ".bc" -type "float3" 0.4 0.4 0.4 ; + setAttr ".sr" 0.5; +select -ne :initialShadingGroup; + setAttr ".ro" yes; +select -ne :initialParticleSE; + setAttr ".ro" yes; +select -ne :defaultRenderGlobals; +select -ne :defaultResolution; +select -ne :defaultColorMgtGlobals; + setAttr ".cfe" yes; + setAttr ".cfp" -type "string" "/OCIO-configs/Maya2022-default/config.ocio"; + setAttr ".dn" -type "string" "sRGB"; + setAttr ".otn" -type "string" "ACES 1.0 SDR-video (sRGB)"; + setAttr ".potn" -type "string" "ACES 1.0 SDR-video (sRGB)"; + setAttr ".vn" -type "string" "ACES 1.0 SDR-video"; + setAttr ".vtn" -type "string" "ACES 1.0 SDR-video (sRGB)"; + setAttr ".wsn" -type "string" "ACEScg"; +select -ne :hardwareRenderGlobals; + setAttr ".ctrs" 256; + setAttr ".btrs" 512; +relationship "link" ":lightLinker1" ":initialShadingGroup.message" ":defaultLightSet.message"; +relationship "link" ":lightLinker1" ":initialParticleSE.message" ":defaultLightSet.message"; +relationship "link" ":lightLinker1" "floorMatSG.message" ":defaultLightSet.message"; +relationship "link" ":lightLinker1" "redBallMatSG.message" ":defaultLightSet.message"; +relationship "link" ":lightLinker1" "blueBallMatSG.message" ":defaultLightSet.message"; +relationship "shadowLink" ":lightLinker1" ":initialShadingGroup.message" ":defaultLightSet.message"; +relationship "shadowLink" ":lightLinker1" ":initialParticleSE.message" ":defaultLightSet.message"; +relationship "shadowLink" ":lightLinker1" "floorMatSG.message" ":defaultLightSet.message"; +relationship "shadowLink" ":lightLinker1" "redBallMatSG.message" ":defaultLightSet.message"; +relationship "shadowLink" ":lightLinker1" "blueBallMatSG.message" ":defaultLightSet.message"; +connectAttr "blueBallMat.oc" "blueBallMatSG.ss"; +connectAttr "floorMat.oc" "floorMatSG.ss"; +connectAttr "layerManager.dli[0]" "defaultLayer.id"; +connectAttr "polyCube1.out" "floorShape.i"; +connectAttr "polySphere1.out" "redBallShape.i"; +connectAttr "polySphere2.out" "blueBallShape.i"; +connectAttr "redBallMat.oc" "redBallMatSG.ss"; +connectAttr "renderLayerManager.rlmi[0]" "defaultRenderLayer.rlid"; +connectAttr "blueBallMat.msg" ":defaultShaderList1.s" -na; +connectAttr "blueBallMatSG.pa" ":renderPartition.st" -na; +connectAttr "blueBallShape.iog" "blueBallMatSG.dsm" -na; +connectAttr "defaultRenderLayer.msg" ":defaultRenderingList1.r" -na; +connectAttr "fillArea.iog" ":defaultLightSet.dsm" -na; +connectAttr "fillAreaShape.ltd" ":lightList1.l" -na; +connectAttr "floorMat.msg" ":defaultShaderList1.s" -na; +connectAttr "floorMatSG.pa" ":renderPartition.st" -na; +connectAttr "floorShape.iog" "floorMatSG.dsm" -na; +connectAttr "keyArea.iog" ":defaultLightSet.dsm" -na; +connectAttr "keyAreaShape.ltd" ":lightList1.l" -na; +connectAttr "redBallMat.msg" ":defaultShaderList1.s" -na; +connectAttr "redBallMatSG.pa" ":renderPartition.st" -na; +connectAttr "redBallShape.iog" "redBallMatSG.dsm" -na; +// End of .area_lights.ma.tmp diff --git a/examples/rendering/checker_sphere.ma b/examples/rendering/checker_sphere.ma new file mode 100644 index 00000000..66f7747e --- /dev/null +++ b/examples/rendering/checker_sphere.ma @@ -0,0 +1,234 @@ +//Maya ASCII 2024 scene +//Name: .checker_sphere.ma.tmp +//Codeset: UTF-8 +requires maya "2024"; +currentUnit -l centimeter -a degree -t film; +fileInfo "application" "aztek"; +fileInfo "version" "1.0.0"; +createNode transform -s -n "persp"; + setAttr ".v" no; + setAttr ".t" -type "double3" 0 3.5 12 ; + setAttr ".r" -type "double3" -10.850104629797375 0 0 ; +createNode camera -s -n "perspShape" -p "persp"; + setAttr ".fl" 50; + setAttr ".coi" 12.218428704215611; + setAttr ".imn" -type "string" "persp"; + setAttr ".den" -type "string" "persp_depth"; + setAttr ".man" -type "string" "persp_mask"; + setAttr ".hc" -type "string" "viewSet -p %camera"; +createNode transform -s -n "top"; + setAttr ".v" no; + setAttr ".t" -type "double3" 0 1000.1 0 ; + setAttr ".r" -type "double3" -90 0 0 ; +createNode camera -s -n "topShape" -p "top"; + setAttr ".coi" 1000.1; + setAttr ".o" yes; + setAttr ".rnd" no; + setAttr ".imn" -type "string" "top"; + setAttr ".den" -type "string" "top_depth"; + setAttr ".man" -type "string" "top_mask"; + setAttr ".hc" -type "string" "viewSet -t %camera"; +createNode transform -s -n "front"; + setAttr ".v" no; + setAttr ".t" -type "double3" 0 0 1000.1 ; +createNode camera -s -n "frontShape" -p "front"; + setAttr ".coi" 1000.1; + setAttr ".o" yes; + setAttr ".rnd" no; + setAttr ".imn" -type "string" "front"; + setAttr ".den" -type "string" "front_depth"; + setAttr ".man" -type "string" "front_mask"; + setAttr ".hc" -type "string" "viewSet -f %camera"; +createNode transform -s -n "side"; + setAttr ".v" no; + setAttr ".t" -type "double3" 1000.1 0 0 ; + setAttr ".r" -type "double3" 0 90 0 ; +createNode camera -s -n "sideShape" -p "side"; + setAttr ".coi" 1000.1; + setAttr ".o" yes; + setAttr ".rnd" no; + setAttr ".imn" -type "string" "side"; + setAttr ".den" -type "string" "side_depth"; + setAttr ".man" -type "string" "side_mask"; + setAttr ".hc" -type "string" "viewSet -s %camera"; +createNode transform -n "floor"; + setAttr ".t" -type "double3" 0 -0.01 0 ; +createNode mesh -n "floorShape" -p "floor"; + setAttr -k off ".v"; +createNode transform -n "checkerBall"; + setAttr ".t" -type "double3" 0 1.5 0 ; +createNode mesh -n "checkerBallShape" -p "checkerBall"; + setAttr -k off ".v"; +createNode transform -n "plain0"; + setAttr ".t" -type "double3" -3.4 1.2 -1 ; +createNode mesh -n "plainShape0" -p "plain0"; + setAttr -k off ".v"; +createNode transform -n "plain1"; + setAttr ".t" -type "double3" 3.4 1.2 -1 ; +createNode mesh -n "plainShape1" -p "plain1"; + setAttr -k off ".v"; +createNode transform -n "keyPoint"; + setAttr ".t" -type "double3" -4.5 7 4.5 ; +createNode pointLight -n "keyPointShape" -p "keyPoint"; + setAttr -k off ".v"; + setAttr ".in" 45; + setAttr ".de" 2; +createNode transform -n "shotCam"; + setAttr ".t" -type "double3" 0 3.5 12 ; + setAttr ".r" -type "double3" -10 0 0 ; +createNode camera -n "shotCamShape" -p "shotCam"; + setAttr -k off ".v"; + setAttr ".fl" 50; + setAttr ".coi" 10; +createNode lightLinker -s -n "lightLinker1"; +createNode displayLayerManager -n "layerManager"; +createNode displayLayer -n "defaultLayer"; + setAttr ".ufem" -type "stringArray" 0 ; +createNode renderLayerManager -n "renderLayerManager"; +createNode renderLayer -n "defaultRenderLayer"; + setAttr ".g" yes; +createNode standardSurface -n "floorMat"; + setAttr ".bc" -type "float3" 0.35 0.36 0.38 ; +createNode shadingEngine -n "floorMatSG"; + setAttr ".ihi" 0; + setAttr ".ro" yes; +createNode standardSurface -n "checkerBallMat"; + setAttr ".bc" -type "float3" 1 1 1 ; + setAttr ".sr" 0.25; +createNode shadingEngine -n "checkerBallMatSG"; + setAttr ".ihi" 0; + setAttr ".ro" yes; +createNode standardSurface -n "plain0Mat"; +createNode shadingEngine -n "plain0MatSG"; + setAttr ".ihi" 0; + setAttr ".ro" yes; +createNode standardSurface -n "plain1Mat"; +createNode shadingEngine -n "plain1MatSG"; + setAttr ".ihi" 0; + setAttr ".ro" yes; +createNode lambert -n "checkerMat"; +createNode file -n "checkerFile"; + setAttr ".ftn" -type "string" "../textures/checker.png"; +createNode place2dTexture -n "checkerPlace"; + setAttr ".re" -type "float2" 6 3 ; +createNode shadingEngine -n "checkerMatSG"; + setAttr ".ihi" 0; + setAttr ".ro" yes; +createNode polyCube -n "polyCube1"; + setAttr ".w" 30; + setAttr ".h" 0.02; + setAttr ".d" 30; + setAttr ".sw" 20; + setAttr ".sh" 1; + setAttr ".sd" 20; +createNode polySphere -n "polySphere1"; + setAttr ".r" 1.5; + setAttr ".sa" 48; + setAttr ".sh" 32; +createNode polySphere -n "polySphere2"; + setAttr ".r" 1.2; + setAttr ".sa" 48; + setAttr ".sh" 32; +createNode polySphere -n "polySphere3"; + setAttr ".r" 1.2; + setAttr ".sa" 48; + setAttr ".sh" 32; +createNode aiOptions -s -n "defaultArnoldRenderOptions"; +createNode aiAOVFilter -s -n "defaultArnoldFilter"; +createNode aiAOVDriver -s -n "defaultArnoldDriver"; +createNode aiAOVDriver -s -n "defaultArnoldDisplayDriver"; +select -ne :lightList1; + setAttr -s 1 ".l"; +select -ne :defaultLightSet; + setAttr -s 1 ".dsm"; +createNode script -n "sceneConfigurationScriptNode"; + setAttr ".b" -type "string" "playbackOptions -min 1 -max 120 -ast 1 -aet 200 "; + setAttr ".st" 6; +select -ne :time1; + setAttr ".o" 1; + setAttr ".unw" 1; +select -ne :hardwareRenderingGlobals; + setAttr ".fprt" yes; + setAttr ".rtfm" 1; + setAttr ".otfna" -type "stringArray" 22 "NURBS Curves" "NURBS Surfaces" "Polygons" "Subdiv Surface" "Particles" "Particle Instance" "Fluids" "Strokes" "Image Planes" "UI" "Lights" "Cameras" "Locators" "Joints" "IK Handles" "Deformers" "Motion Trails" "Components" "Hair Systems" "Follicles" "Misc. UI" "Ornaments"; + setAttr ".otfva" -type "Int32Array" 22 0 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0; +select -ne :renderPartition; + setAttr -s 7 ".st"; +select -ne :renderGlobalsList1; +select -ne :defaultShaderList1; + setAttr -s 11 ".s"; +select -ne :postProcessList1; + setAttr -s 2 ".p"; +select -ne :defaultRenderingList1; +select -ne :standardSurface1; + setAttr ".bc" -type "float3" 0.4 0.4 0.4 ; + setAttr ".sr" 0.5; +select -ne :openPBR_shader1; + setAttr ".bc" -type "float3" 0.4 0.4 0.4 ; + setAttr ".sr" 0.5; +select -ne :initialShadingGroup; + setAttr ".ro" yes; +select -ne :initialParticleSE; + setAttr ".ro" yes; +select -ne :defaultRenderGlobals; +select -ne :defaultResolution; +select -ne :defaultColorMgtGlobals; + setAttr ".cfe" yes; + setAttr ".cfp" -type "string" "/OCIO-configs/Maya2022-default/config.ocio"; + setAttr ".dn" -type "string" "sRGB"; + setAttr ".otn" -type "string" "ACES 1.0 SDR-video (sRGB)"; + setAttr ".potn" -type "string" "ACES 1.0 SDR-video (sRGB)"; + setAttr ".vn" -type "string" "ACES 1.0 SDR-video"; + setAttr ".vtn" -type "string" "ACES 1.0 SDR-video (sRGB)"; + setAttr ".wsn" -type "string" "ACEScg"; +select -ne :hardwareRenderGlobals; + setAttr ".ctrs" 256; + setAttr ".btrs" 512; +relationship "link" ":lightLinker1" ":initialShadingGroup.message" ":defaultLightSet.message"; +relationship "link" ":lightLinker1" ":initialParticleSE.message" ":defaultLightSet.message"; +relationship "link" ":lightLinker1" "floorMatSG.message" ":defaultLightSet.message"; +relationship "link" ":lightLinker1" "checkerBallMatSG.message" ":defaultLightSet.message"; +relationship "link" ":lightLinker1" "plain0MatSG.message" ":defaultLightSet.message"; +relationship "link" ":lightLinker1" "plain1MatSG.message" ":defaultLightSet.message"; +relationship "link" ":lightLinker1" "checkerMatSG.message" ":defaultLightSet.message"; +relationship "shadowLink" ":lightLinker1" ":initialShadingGroup.message" ":defaultLightSet.message"; +relationship "shadowLink" ":lightLinker1" ":initialParticleSE.message" ":defaultLightSet.message"; +relationship "shadowLink" ":lightLinker1" "floorMatSG.message" ":defaultLightSet.message"; +relationship "shadowLink" ":lightLinker1" "checkerBallMatSG.message" ":defaultLightSet.message"; +relationship "shadowLink" ":lightLinker1" "plain0MatSG.message" ":defaultLightSet.message"; +relationship "shadowLink" ":lightLinker1" "plain1MatSG.message" ":defaultLightSet.message"; +relationship "shadowLink" ":lightLinker1" "checkerMatSG.message" ":defaultLightSet.message"; +connectAttr "checkerBallMat.oc" "checkerBallMatSG.ss"; +connectAttr "checkerFile.oc" "checkerMat.c"; +connectAttr "checkerMat.oc" "checkerMatSG.ss"; +connectAttr "checkerPlace.o" "checkerFile.uv"; +connectAttr "checkerPlace.ofs" "checkerFile.fs"; +connectAttr "floorMat.oc" "floorMatSG.ss"; +connectAttr "layerManager.dli[0]" "defaultLayer.id"; +connectAttr "plain0Mat.oc" "plain0MatSG.ss"; +connectAttr "plain1Mat.oc" "plain1MatSG.ss"; +connectAttr "polyCube1.out" "floorShape.i"; +connectAttr "polySphere1.out" "checkerBallShape.i"; +connectAttr "polySphere2.out" "plainShape0.i"; +connectAttr "polySphere3.out" "plainShape1.i"; +connectAttr "renderLayerManager.rlmi[0]" "defaultRenderLayer.rlid"; +connectAttr "checkerBallMat.msg" ":defaultShaderList1.s" -na; +connectAttr "checkerBallMatSG.pa" ":renderPartition.st" -na; +connectAttr "checkerBallShape.iog" "checkerMatSG.dsm" -na; +connectAttr "checkerFile.msg" ":defaultTextureList1.tx" -na; +connectAttr "checkerMat.msg" ":defaultShaderList1.s" -na; +connectAttr "checkerMatSG.pa" ":renderPartition.st" -na; +connectAttr "checkerPlace.msg" ":defaultRenderUtilityList1.u" -na; +connectAttr "defaultRenderLayer.msg" ":defaultRenderingList1.r" -na; +connectAttr "floorMat.msg" ":defaultShaderList1.s" -na; +connectAttr "floorMatSG.pa" ":renderPartition.st" -na; +connectAttr "floorShape.iog" "floorMatSG.dsm" -na; +connectAttr "keyPoint.iog" ":defaultLightSet.dsm" -na; +connectAttr "keyPointShape.ltd" ":lightList1.l" -na; +connectAttr "plain0Mat.msg" ":defaultShaderList1.s" -na; +connectAttr "plain0MatSG.pa" ":renderPartition.st" -na; +connectAttr "plain1Mat.msg" ":defaultShaderList1.s" -na; +connectAttr "plain1MatSG.pa" ":renderPartition.st" -na; +connectAttr "plainShape0.iog" "plain0MatSG.dsm" -na; +connectAttr "plainShape1.iog" "plain1MatSG.dsm" -na; +// End of .checker_sphere.ma.tmp diff --git a/examples/rendering/dielectric_glass.ma b/examples/rendering/dielectric_glass.ma new file mode 100644 index 00000000..d0e7afcb --- /dev/null +++ b/examples/rendering/dielectric_glass.ma @@ -0,0 +1,308 @@ +//Maya ASCII 2024 scene +//Name: .dielectric_glass.ma.tmp +//Codeset: UTF-8 +requires maya "2024"; +currentUnit -l centimeter -a degree -t film; +fileInfo "application" "aztek"; +fileInfo "version" "1.0.0"; +createNode transform -s -n "persp"; + setAttr ".v" no; + setAttr ".t" -type "double3" 0 3.6 11 ; + setAttr ".r" -type "double3" -12.308015817427929 0 0 ; +createNode camera -s -n "perspShape" -p "persp"; + setAttr ".fl" 50; + setAttr ".coi" 11.258774356030056; + setAttr ".imn" -type "string" "persp"; + setAttr ".den" -type "string" "persp_depth"; + setAttr ".man" -type "string" "persp_mask"; + setAttr ".hc" -type "string" "viewSet -p %camera"; +createNode transform -s -n "top"; + setAttr ".v" no; + setAttr ".t" -type "double3" 0 1000.1 0 ; + setAttr ".r" -type "double3" -90 0 0 ; +createNode camera -s -n "topShape" -p "top"; + setAttr ".coi" 1000.1; + setAttr ".o" yes; + setAttr ".rnd" no; + setAttr ".imn" -type "string" "top"; + setAttr ".den" -type "string" "top_depth"; + setAttr ".man" -type "string" "top_mask"; + setAttr ".hc" -type "string" "viewSet -t %camera"; +createNode transform -s -n "front"; + setAttr ".v" no; + setAttr ".t" -type "double3" 0 0 1000.1 ; +createNode camera -s -n "frontShape" -p "front"; + setAttr ".coi" 1000.1; + setAttr ".o" yes; + setAttr ".rnd" no; + setAttr ".imn" -type "string" "front"; + setAttr ".den" -type "string" "front_depth"; + setAttr ".man" -type "string" "front_mask"; + setAttr ".hc" -type "string" "viewSet -f %camera"; +createNode transform -s -n "side"; + setAttr ".v" no; + setAttr ".t" -type "double3" 1000.1 0 0 ; + setAttr ".r" -type "double3" 0 90 0 ; +createNode camera -s -n "sideShape" -p "side"; + setAttr ".coi" 1000.1; + setAttr ".o" yes; + setAttr ".rnd" no; + setAttr ".imn" -type "string" "side"; + setAttr ".den" -type "string" "side_depth"; + setAttr ".man" -type "string" "side_mask"; + setAttr ".hc" -type "string" "viewSet -s %camera"; +createNode transform -n "floor"; + setAttr ".t" -type "double3" 0 -0.01 0 ; +createNode mesh -n "floorShape" -p "floor"; + setAttr -k off ".v"; +createNode transform -n "wall"; + setAttr ".t" -type "double3" 0 5 -8 ; +createNode mesh -n "wallShape" -p "wall"; + setAttr -k off ".v"; +createNode transform -n "leftBlock"; + setAttr ".t" -type "double3" -3.6 2 -5 ; +createNode mesh -n "leftBlockShape" -p "leftBlock"; + setAttr -k off ".v"; +createNode transform -n "rightBlock"; + setAttr ".t" -type "double3" 3.6 2 -5 ; +createNode mesh -n "rightBlockShape" -p "rightBlock"; + setAttr -k off ".v"; +createNode transform -n "glass0"; + setAttr ".t" -type "double3" -3 1.5 0 ; +createNode mesh -n "glassShape0" -p "glass0"; + setAttr -k off ".v"; +createNode transform -n "glass1"; + setAttr ".t" -type "double3" 0 1.5 0 ; +createNode mesh -n "glassShape1" -p "glass1"; + setAttr -k off ".v"; +createNode transform -n "glass2"; + setAttr ".t" -type "double3" 3 1.5 0 ; +createNode mesh -n "glassShape2" -p "glass2"; + setAttr -k off ".v"; +createNode transform -n "keyPoint"; + setAttr ".t" -type "double3" -4 7 5 ; +createNode pointLight -n "keyPointShape" -p "keyPoint"; + setAttr -k off ".v"; + setAttr ".in" 12; + setAttr ".de" 2; +createNode transform -n "shotCam"; + setAttr ".t" -type "double3" 0 3.6 11 ; + setAttr ".r" -type "double3" -8 0 0 ; +createNode camera -n "shotCamShape" -p "shotCam"; + setAttr -k off ".v"; + setAttr ".fl" 50; + setAttr ".coi" 10; +createNode lightLinker -s -n "lightLinker1"; +createNode displayLayerManager -n "layerManager"; +createNode displayLayer -n "defaultLayer"; + setAttr ".ufem" -type "stringArray" 0 ; +createNode renderLayerManager -n "renderLayerManager"; +createNode renderLayer -n "defaultRenderLayer"; + setAttr ".g" yes; +createNode standardSurface -n "floorMat"; + setAttr ".bc" -type "float3" 0.3 0.32 0.35 ; + setAttr ".m" 0.2; + setAttr ".sr" 0.15; +createNode shadingEngine -n "floorMatSG"; + setAttr ".ihi" 0; + setAttr ".ro" yes; +createNode standardSurface -n "wallMat"; + setAttr ".bc" -type "float3" 0 0 0 ; + setAttr ".sr" 0.5; + setAttr ".e" 1; + setAttr ".ec" -type "float3" 0.55 0.55 0.55 ; +createNode shadingEngine -n "wallMatSG"; + setAttr ".ihi" 0; + setAttr ".ro" yes; +createNode standardSurface -n "leftMat"; + setAttr ".bc" -type "float3" 0.95 0.65 0.08 ; + setAttr ".sr" 0.5; + setAttr ".e" 0.35; + setAttr ".ec" -type "float3" 0.8 0.5 0.05 ; +createNode shadingEngine -n "leftMatSG"; + setAttr ".ihi" 0; + setAttr ".ro" yes; +createNode standardSurface -n "rightMat"; + setAttr ".bc" -type "float3" 0.08 0.55 0.95 ; + setAttr ".sr" 0.5; + setAttr ".e" 0.35; + setAttr ".ec" -type "float3" 0.05 0.4 0.8 ; +createNode shadingEngine -n "rightMatSG"; + setAttr ".ihi" 0; + setAttr ".ro" yes; +createNode standardSurface -n "glass0Mat"; + setAttr ".bc" -type "float3" 1 1 1 ; + setAttr ".sr" 0.02; + setAttr ".sior" 1.33; + setAttr ".t" 1; + setAttr ".trc" -type "float3" 0.85 0.25 0.2 ; +createNode shadingEngine -n "glass0MatSG"; + setAttr ".ihi" 0; + setAttr ".ro" yes; +createNode standardSurface -n "glass1Mat"; + setAttr ".bc" -type "float3" 1 1 1 ; + setAttr ".sr" 0.02; + setAttr ".t" 1; + setAttr ".trc" -type "float3" 0.85 0.25 0.2 ; +createNode shadingEngine -n "glass1MatSG"; + setAttr ".ihi" 0; + setAttr ".ro" yes; +createNode standardSurface -n "glass2Mat"; + setAttr ".bc" -type "float3" 1 1 1 ; + setAttr ".sr" 0.02; + setAttr ".sior" 1.7; + setAttr ".t" 1; + setAttr ".trc" -type "float3" 0.85 0.25 0.2 ; +createNode shadingEngine -n "glass2MatSG"; + setAttr ".ihi" 0; + setAttr ".ro" yes; +createNode polyCube -n "polyCube1"; + setAttr ".w" 30; + setAttr ".h" 0.02; + setAttr ".d" 30; + setAttr ".sw" 20; + setAttr ".sh" 1; + setAttr ".sd" 20; +createNode polyCube -n "polyCube2"; + setAttr ".w" 24; + setAttr ".h" 10; + setAttr ".d" 0.2; + setAttr ".sw" 1; + setAttr ".sh" 1; + setAttr ".sd" 1; +createNode polyCube -n "polyCube3"; + setAttr ".w" 2; + setAttr ".h" 4; + setAttr ".d" 2; + setAttr ".sw" 1; + setAttr ".sh" 1; + setAttr ".sd" 1; +createNode polyCube -n "polyCube4"; + setAttr ".w" 2; + setAttr ".h" 4; + setAttr ".d" 2; + setAttr ".sw" 1; + setAttr ".sh" 1; + setAttr ".sd" 1; +createNode polySphere -n "polySphere1"; + setAttr ".r" 1.4; + setAttr ".sa" 48; + setAttr ".sh" 32; +createNode polySphere -n "polySphere2"; + setAttr ".r" 1.4; + setAttr ".sa" 48; + setAttr ".sh" 32; +createNode polySphere -n "polySphere3"; + setAttr ".r" 1.4; + setAttr ".sa" 48; + setAttr ".sh" 32; +createNode aiOptions -s -n "defaultArnoldRenderOptions"; +createNode aiAOVFilter -s -n "defaultArnoldFilter"; +createNode aiAOVDriver -s -n "defaultArnoldDriver"; +createNode aiAOVDriver -s -n "defaultArnoldDisplayDriver"; +select -ne :lightList1; + setAttr -s 1 ".l"; +select -ne :defaultLightSet; + setAttr -s 1 ".dsm"; +createNode script -n "sceneConfigurationScriptNode"; + setAttr ".b" -type "string" "playbackOptions -min 1 -max 120 -ast 1 -aet 200 "; + setAttr ".st" 6; +select -ne :time1; + setAttr ".o" 1; + setAttr ".unw" 1; +select -ne :hardwareRenderingGlobals; + setAttr ".fprt" yes; + setAttr ".rtfm" 1; + setAttr ".otfna" -type "stringArray" 22 "NURBS Curves" "NURBS Surfaces" "Polygons" "Subdiv Surface" "Particles" "Particle Instance" "Fluids" "Strokes" "Image Planes" "UI" "Lights" "Cameras" "Locators" "Joints" "IK Handles" "Deformers" "Motion Trails" "Components" "Hair Systems" "Follicles" "Misc. UI" "Ornaments"; + setAttr ".otfva" -type "Int32Array" 22 0 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0; +select -ne :renderPartition; + setAttr -s 9 ".st"; +select -ne :renderGlobalsList1; +select -ne :defaultShaderList1; + setAttr -s 13 ".s"; +select -ne :postProcessList1; + setAttr -s 2 ".p"; +select -ne :defaultRenderingList1; +select -ne :standardSurface1; + setAttr ".bc" -type "float3" 0.4 0.4 0.4 ; + setAttr ".sr" 0.5; +select -ne :openPBR_shader1; + setAttr ".bc" -type "float3" 0.4 0.4 0.4 ; + setAttr ".sr" 0.5; +select -ne :initialShadingGroup; + setAttr ".ro" yes; +select -ne :initialParticleSE; + setAttr ".ro" yes; +select -ne :defaultRenderGlobals; +select -ne :defaultResolution; +select -ne :defaultColorMgtGlobals; + setAttr ".cfe" yes; + setAttr ".cfp" -type "string" "/OCIO-configs/Maya2022-default/config.ocio"; + setAttr ".dn" -type "string" "sRGB"; + setAttr ".otn" -type "string" "ACES 1.0 SDR-video (sRGB)"; + setAttr ".potn" -type "string" "ACES 1.0 SDR-video (sRGB)"; + setAttr ".vn" -type "string" "ACES 1.0 SDR-video"; + setAttr ".vtn" -type "string" "ACES 1.0 SDR-video (sRGB)"; + setAttr ".wsn" -type "string" "ACEScg"; +select -ne :hardwareRenderGlobals; + setAttr ".ctrs" 256; + setAttr ".btrs" 512; +relationship "link" ":lightLinker1" ":initialShadingGroup.message" ":defaultLightSet.message"; +relationship "link" ":lightLinker1" ":initialParticleSE.message" ":defaultLightSet.message"; +relationship "link" ":lightLinker1" "floorMatSG.message" ":defaultLightSet.message"; +relationship "link" ":lightLinker1" "wallMatSG.message" ":defaultLightSet.message"; +relationship "link" ":lightLinker1" "leftMatSG.message" ":defaultLightSet.message"; +relationship "link" ":lightLinker1" "rightMatSG.message" ":defaultLightSet.message"; +relationship "link" ":lightLinker1" "glass0MatSG.message" ":defaultLightSet.message"; +relationship "link" ":lightLinker1" "glass1MatSG.message" ":defaultLightSet.message"; +relationship "link" ":lightLinker1" "glass2MatSG.message" ":defaultLightSet.message"; +relationship "shadowLink" ":lightLinker1" ":initialShadingGroup.message" ":defaultLightSet.message"; +relationship "shadowLink" ":lightLinker1" ":initialParticleSE.message" ":defaultLightSet.message"; +relationship "shadowLink" ":lightLinker1" "floorMatSG.message" ":defaultLightSet.message"; +relationship "shadowLink" ":lightLinker1" "wallMatSG.message" ":defaultLightSet.message"; +relationship "shadowLink" ":lightLinker1" "leftMatSG.message" ":defaultLightSet.message"; +relationship "shadowLink" ":lightLinker1" "rightMatSG.message" ":defaultLightSet.message"; +relationship "shadowLink" ":lightLinker1" "glass0MatSG.message" ":defaultLightSet.message"; +relationship "shadowLink" ":lightLinker1" "glass1MatSG.message" ":defaultLightSet.message"; +relationship "shadowLink" ":lightLinker1" "glass2MatSG.message" ":defaultLightSet.message"; +connectAttr "floorMat.oc" "floorMatSG.ss"; +connectAttr "glass0Mat.oc" "glass0MatSG.ss"; +connectAttr "glass1Mat.oc" "glass1MatSG.ss"; +connectAttr "glass2Mat.oc" "glass2MatSG.ss"; +connectAttr "layerManager.dli[0]" "defaultLayer.id"; +connectAttr "leftMat.oc" "leftMatSG.ss"; +connectAttr "polyCube1.out" "floorShape.i"; +connectAttr "polyCube2.out" "wallShape.i"; +connectAttr "polyCube3.out" "leftBlockShape.i"; +connectAttr "polyCube4.out" "rightBlockShape.i"; +connectAttr "polySphere1.out" "glassShape0.i"; +connectAttr "polySphere2.out" "glassShape1.i"; +connectAttr "polySphere3.out" "glassShape2.i"; +connectAttr "renderLayerManager.rlmi[0]" "defaultRenderLayer.rlid"; +connectAttr "rightMat.oc" "rightMatSG.ss"; +connectAttr "wallMat.oc" "wallMatSG.ss"; +connectAttr "defaultRenderLayer.msg" ":defaultRenderingList1.r" -na; +connectAttr "floorMat.msg" ":defaultShaderList1.s" -na; +connectAttr "floorMatSG.pa" ":renderPartition.st" -na; +connectAttr "floorShape.iog" "floorMatSG.dsm" -na; +connectAttr "glass0Mat.msg" ":defaultShaderList1.s" -na; +connectAttr "glass0MatSG.pa" ":renderPartition.st" -na; +connectAttr "glass1Mat.msg" ":defaultShaderList1.s" -na; +connectAttr "glass1MatSG.pa" ":renderPartition.st" -na; +connectAttr "glass2Mat.msg" ":defaultShaderList1.s" -na; +connectAttr "glass2MatSG.pa" ":renderPartition.st" -na; +connectAttr "glassShape0.iog" "glass0MatSG.dsm" -na; +connectAttr "glassShape1.iog" "glass1MatSG.dsm" -na; +connectAttr "glassShape2.iog" "glass2MatSG.dsm" -na; +connectAttr "keyPoint.iog" ":defaultLightSet.dsm" -na; +connectAttr "keyPointShape.ltd" ":lightList1.l" -na; +connectAttr "leftBlockShape.iog" "leftMatSG.dsm" -na; +connectAttr "leftMat.msg" ":defaultShaderList1.s" -na; +connectAttr "leftMatSG.pa" ":renderPartition.st" -na; +connectAttr "rightBlockShape.iog" "rightMatSG.dsm" -na; +connectAttr "rightMat.msg" ":defaultShaderList1.s" -na; +connectAttr "rightMatSG.pa" ":renderPartition.st" -na; +connectAttr "wallMat.msg" ":defaultShaderList1.s" -na; +connectAttr "wallMatSG.pa" ":renderPartition.st" -na; +connectAttr "wallShape.iog" "wallMatSG.dsm" -na; +// End of .dielectric_glass.ma.tmp diff --git a/examples/rendering/emissive_object.ma b/examples/rendering/emissive_object.ma new file mode 100644 index 00000000..d5561d80 --- /dev/null +++ b/examples/rendering/emissive_object.ma @@ -0,0 +1,227 @@ +//Maya ASCII 2024 scene +//Name: .emissive_object.ma.tmp +//Codeset: UTF-8 +requires maya "2024"; +currentUnit -l centimeter -a degree -t film; +fileInfo "application" "aztek"; +fileInfo "version" "1.0.0"; +createNode transform -s -n "persp"; + setAttr ".v" no; + setAttr ".t" -type "double3" 0 3.5 11 ; + setAttr ".r" -type "double3" -11.809882957028256 0 0 ; +createNode camera -s -n "perspShape" -p "persp"; + setAttr ".fl" 50; + setAttr ".coi" 11.237882362794158; + setAttr ".imn" -type "string" "persp"; + setAttr ".den" -type "string" "persp_depth"; + setAttr ".man" -type "string" "persp_mask"; + setAttr ".hc" -type "string" "viewSet -p %camera"; +createNode transform -s -n "top"; + setAttr ".v" no; + setAttr ".t" -type "double3" 0 1000.1 0 ; + setAttr ".r" -type "double3" -90 0 0 ; +createNode camera -s -n "topShape" -p "top"; + setAttr ".coi" 1000.1; + setAttr ".o" yes; + setAttr ".rnd" no; + setAttr ".imn" -type "string" "top"; + setAttr ".den" -type "string" "top_depth"; + setAttr ".man" -type "string" "top_mask"; + setAttr ".hc" -type "string" "viewSet -t %camera"; +createNode transform -s -n "front"; + setAttr ".v" no; + setAttr ".t" -type "double3" 0 0 1000.1 ; +createNode camera -s -n "frontShape" -p "front"; + setAttr ".coi" 1000.1; + setAttr ".o" yes; + setAttr ".rnd" no; + setAttr ".imn" -type "string" "front"; + setAttr ".den" -type "string" "front_depth"; + setAttr ".man" -type "string" "front_mask"; + setAttr ".hc" -type "string" "viewSet -f %camera"; +createNode transform -s -n "side"; + setAttr ".v" no; + setAttr ".t" -type "double3" 1000.1 0 0 ; + setAttr ".r" -type "double3" 0 90 0 ; +createNode camera -s -n "sideShape" -p "side"; + setAttr ".coi" 1000.1; + setAttr ".o" yes; + setAttr ".rnd" no; + setAttr ".imn" -type "string" "side"; + setAttr ".den" -type "string" "side_depth"; + setAttr ".man" -type "string" "side_mask"; + setAttr ".hc" -type "string" "viewSet -s %camera"; +createNode transform -n "floor"; + setAttr ".t" -type "double3" 0 -0.01 0 ; +createNode mesh -n "floorShape" -p "floor"; + setAttr -k off ".v"; +createNode transform -n "backWall"; + setAttr ".t" -type "double3" 0 5 -7 ; +createNode mesh -n "backWallShape" -p "backWall"; + setAttr -k off ".v"; +createNode transform -n "litSphere"; + setAttr ".t" -type "double3" 0 1.4 0 ; +createNode mesh -n "litSphereShape" -p "litSphere"; + setAttr -k off ".v"; +createNode transform -n "emitter"; + setAttr ".t" -type "double3" -3.5 3 3 ; +createNode mesh -n "emitterShape" -p "emitter"; + setAttr -k off ".v"; +createNode transform -n "fill"; + setAttr ".t" -type "double3" 4 5 4 ; +createNode pointLight -n "fillShape" -p "fill"; + setAttr -k off ".v"; + setAttr ".in" 8; + setAttr ".de" 2; +createNode transform -n "shotCam"; + setAttr ".t" -type "double3" 0 3.5 11 ; + setAttr ".r" -type "double3" -8 0 0 ; +createNode camera -n "shotCamShape" -p "shotCam"; + setAttr -k off ".v"; + setAttr ".fl" 50; + setAttr ".coi" 10; +createNode lightLinker -s -n "lightLinker1"; +createNode displayLayerManager -n "layerManager"; +createNode displayLayer -n "defaultLayer"; + setAttr ".ufem" -type "stringArray" 0 ; +createNode renderLayerManager -n "renderLayerManager"; +createNode renderLayer -n "defaultRenderLayer"; + setAttr ".g" yes; +createNode standardSurface -n "floorMat"; + setAttr ".bc" -type "float3" 0.45 0.45 0.45 ; + setAttr ".sr" 0.3; +createNode shadingEngine -n "floorMatSG"; + setAttr ".ihi" 0; + setAttr ".ro" yes; +createNode standardSurface -n "backMat"; + setAttr ".bc" -type "float3" 0.5 0.5 0.5 ; + setAttr ".sr" 0.4; +createNode shadingEngine -n "backMatSG"; + setAttr ".ihi" 0; + setAttr ".ro" yes; +createNode standardSurface -n "litSphereMat"; +createNode shadingEngine -n "litSphereMatSG"; + setAttr ".ihi" 0; + setAttr ".ro" yes; +createNode standardSurface -n "emitterMat"; + setAttr ".bc" -type "float3" 0 0 0 ; + setAttr ".sr" 0.5; + setAttr ".e" 8; + setAttr ".ec" -type "float3" 1 0.35 0.05 ; +createNode shadingEngine -n "emitterMatSG"; + setAttr ".ihi" 0; + setAttr ".ro" yes; +createNode polyCube -n "polyCube1"; + setAttr ".w" 30; + setAttr ".h" 0.02; + setAttr ".d" 30; + setAttr ".sw" 20; + setAttr ".sh" 1; + setAttr ".sd" 20; +createNode polyCube -n "polyCube2"; + setAttr ".w" 24; + setAttr ".h" 10; + setAttr ".d" 0.2; + setAttr ".sw" 1; + setAttr ".sh" 1; + setAttr ".sd" 1; +createNode polySphere -n "polySphere1"; + setAttr ".r" 1.4; + setAttr ".sa" 48; + setAttr ".sh" 32; +createNode polyCube -n "polyCube3"; + setAttr ".w" 5; + setAttr ".h" 3; + setAttr ".d" 0.2; + setAttr ".sw" 1; + setAttr ".sh" 1; + setAttr ".sd" 1; +createNode aiOptions -s -n "defaultArnoldRenderOptions"; +createNode aiAOVFilter -s -n "defaultArnoldFilter"; +createNode aiAOVDriver -s -n "defaultArnoldDriver"; +createNode aiAOVDriver -s -n "defaultArnoldDisplayDriver"; +select -ne :lightList1; + setAttr -s 1 ".l"; +select -ne :defaultLightSet; + setAttr -s 1 ".dsm"; +createNode script -n "sceneConfigurationScriptNode"; + setAttr ".b" -type "string" "playbackOptions -min 1 -max 120 -ast 1 -aet 200 "; + setAttr ".st" 6; +select -ne :time1; + setAttr ".o" 1; + setAttr ".unw" 1; +select -ne :hardwareRenderingGlobals; + setAttr ".fprt" yes; + setAttr ".rtfm" 1; + setAttr ".otfna" -type "stringArray" 22 "NURBS Curves" "NURBS Surfaces" "Polygons" "Subdiv Surface" "Particles" "Particle Instance" "Fluids" "Strokes" "Image Planes" "UI" "Lights" "Cameras" "Locators" "Joints" "IK Handles" "Deformers" "Motion Trails" "Components" "Hair Systems" "Follicles" "Misc. UI" "Ornaments"; + setAttr ".otfva" -type "Int32Array" 22 0 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0; +select -ne :renderPartition; + setAttr -s 6 ".st"; +select -ne :renderGlobalsList1; +select -ne :defaultShaderList1; + setAttr -s 10 ".s"; +select -ne :postProcessList1; + setAttr -s 2 ".p"; +select -ne :defaultRenderingList1; +select -ne :standardSurface1; + setAttr ".bc" -type "float3" 0.4 0.4 0.4 ; + setAttr ".sr" 0.5; +select -ne :openPBR_shader1; + setAttr ".bc" -type "float3" 0.4 0.4 0.4 ; + setAttr ".sr" 0.5; +select -ne :initialShadingGroup; + setAttr ".ro" yes; +select -ne :initialParticleSE; + setAttr ".ro" yes; +select -ne :defaultRenderGlobals; +select -ne :defaultResolution; +select -ne :defaultColorMgtGlobals; + setAttr ".cfe" yes; + setAttr ".cfp" -type "string" "/OCIO-configs/Maya2022-default/config.ocio"; + setAttr ".dn" -type "string" "sRGB"; + setAttr ".otn" -type "string" "ACES 1.0 SDR-video (sRGB)"; + setAttr ".potn" -type "string" "ACES 1.0 SDR-video (sRGB)"; + setAttr ".vn" -type "string" "ACES 1.0 SDR-video"; + setAttr ".vtn" -type "string" "ACES 1.0 SDR-video (sRGB)"; + setAttr ".wsn" -type "string" "ACEScg"; +select -ne :hardwareRenderGlobals; + setAttr ".ctrs" 256; + setAttr ".btrs" 512; +relationship "link" ":lightLinker1" ":initialShadingGroup.message" ":defaultLightSet.message"; +relationship "link" ":lightLinker1" ":initialParticleSE.message" ":defaultLightSet.message"; +relationship "link" ":lightLinker1" "floorMatSG.message" ":defaultLightSet.message"; +relationship "link" ":lightLinker1" "backMatSG.message" ":defaultLightSet.message"; +relationship "link" ":lightLinker1" "litSphereMatSG.message" ":defaultLightSet.message"; +relationship "link" ":lightLinker1" "emitterMatSG.message" ":defaultLightSet.message"; +relationship "shadowLink" ":lightLinker1" ":initialShadingGroup.message" ":defaultLightSet.message"; +relationship "shadowLink" ":lightLinker1" ":initialParticleSE.message" ":defaultLightSet.message"; +relationship "shadowLink" ":lightLinker1" "floorMatSG.message" ":defaultLightSet.message"; +relationship "shadowLink" ":lightLinker1" "backMatSG.message" ":defaultLightSet.message"; +relationship "shadowLink" ":lightLinker1" "litSphereMatSG.message" ":defaultLightSet.message"; +relationship "shadowLink" ":lightLinker1" "emitterMatSG.message" ":defaultLightSet.message"; +connectAttr "backMat.oc" "backMatSG.ss"; +connectAttr "emitterMat.oc" "emitterMatSG.ss"; +connectAttr "floorMat.oc" "floorMatSG.ss"; +connectAttr "layerManager.dli[0]" "defaultLayer.id"; +connectAttr "litSphereMat.oc" "litSphereMatSG.ss"; +connectAttr "polyCube1.out" "floorShape.i"; +connectAttr "polyCube2.out" "backWallShape.i"; +connectAttr "polyCube3.out" "emitterShape.i"; +connectAttr "polySphere1.out" "litSphereShape.i"; +connectAttr "renderLayerManager.rlmi[0]" "defaultRenderLayer.rlid"; +connectAttr "backMat.msg" ":defaultShaderList1.s" -na; +connectAttr "backMatSG.pa" ":renderPartition.st" -na; +connectAttr "backWallShape.iog" "backMatSG.dsm" -na; +connectAttr "defaultRenderLayer.msg" ":defaultRenderingList1.r" -na; +connectAttr "emitterMat.msg" ":defaultShaderList1.s" -na; +connectAttr "emitterMatSG.pa" ":renderPartition.st" -na; +connectAttr "emitterShape.iog" "emitterMatSG.dsm" -na; +connectAttr "fill.iog" ":defaultLightSet.dsm" -na; +connectAttr "fillShape.ltd" ":lightList1.l" -na; +connectAttr "floorMat.msg" ":defaultShaderList1.s" -na; +connectAttr "floorMatSG.pa" ":renderPartition.st" -na; +connectAttr "floorShape.iog" "floorMatSG.dsm" -na; +connectAttr "litSphereMat.msg" ":defaultShaderList1.s" -na; +connectAttr "litSphereMatSG.pa" ":renderPartition.st" -na; +connectAttr "litSphereShape.iog" "litSphereMatSG.dsm" -na; +// End of .emissive_object.ma.tmp diff --git a/examples/rendering/environment_hdri.ma b/examples/rendering/environment_hdri.ma new file mode 100644 index 00000000..17ac8eaf --- /dev/null +++ b/examples/rendering/environment_hdri.ma @@ -0,0 +1,224 @@ +//Maya ASCII 2024 scene +//Name: .environment_hdri.ma.tmp +//Codeset: UTF-8 +requires maya "2024"; +currentUnit -l centimeter -a degree -t film; +fileInfo "application" "aztek"; +fileInfo "version" "1.0.0"; +createNode transform -s -n "persp"; + setAttr ".v" no; + setAttr ".t" -type "double3" 0 4 12 ; + setAttr ".r" -type "double3" -13.13402230639632 0 0 ; +createNode camera -s -n "perspShape" -p "persp"; + setAttr ".fl" 50; + setAttr ".coi" 12.32233744059949; + setAttr ".imn" -type "string" "persp"; + setAttr ".den" -type "string" "persp_depth"; + setAttr ".man" -type "string" "persp_mask"; + setAttr ".hc" -type "string" "viewSet -p %camera"; +createNode transform -s -n "top"; + setAttr ".v" no; + setAttr ".t" -type "double3" 0 1000.1 0 ; + setAttr ".r" -type "double3" -90 0 0 ; +createNode camera -s -n "topShape" -p "top"; + setAttr ".coi" 1000.1; + setAttr ".o" yes; + setAttr ".rnd" no; + setAttr ".imn" -type "string" "top"; + setAttr ".den" -type "string" "top_depth"; + setAttr ".man" -type "string" "top_mask"; + setAttr ".hc" -type "string" "viewSet -t %camera"; +createNode transform -s -n "front"; + setAttr ".v" no; + setAttr ".t" -type "double3" 0 0 1000.1 ; +createNode camera -s -n "frontShape" -p "front"; + setAttr ".coi" 1000.1; + setAttr ".o" yes; + setAttr ".rnd" no; + setAttr ".imn" -type "string" "front"; + setAttr ".den" -type "string" "front_depth"; + setAttr ".man" -type "string" "front_mask"; + setAttr ".hc" -type "string" "viewSet -f %camera"; +createNode transform -s -n "side"; + setAttr ".v" no; + setAttr ".t" -type "double3" 1000.1 0 0 ; + setAttr ".r" -type "double3" 0 90 0 ; +createNode camera -s -n "sideShape" -p "side"; + setAttr ".coi" 1000.1; + setAttr ".o" yes; + setAttr ".rnd" no; + setAttr ".imn" -type "string" "side"; + setAttr ".den" -type "string" "side_depth"; + setAttr ".man" -type "string" "side_mask"; + setAttr ".hc" -type "string" "viewSet -s %camera"; +createNode transform -n "floor"; + setAttr ".t" -type "double3" 0 -0.01 0 ; +createNode mesh -n "floorShape" -p "floor"; + setAttr -k off ".v"; +createNode transform -n "goldBall"; + setAttr ".t" -type "double3" -2 1.5 0 ; +createNode mesh -n "goldBallShape" -p "goldBall"; + setAttr -k off ".v"; +createNode transform -n "chromeBall"; + setAttr ".t" -type "double3" 2.2 1.5 0 ; +createNode mesh -n "chromeBallShape" -p "chromeBall"; + setAttr -k off ".v"; +createNode transform -n "redBall"; + setAttr ".t" -type "double3" 0.2 1 -3.2 ; +createNode mesh -n "redBallShape" -p "redBall"; + setAttr -k off ".v"; +createNode transform -n "sky"; + setAttr ".r" -type "double3" 0 30 0 ; +createNode aiSkyDomeLight -n "skyShape" -p "sky"; + setAttr -k off ".v"; + setAttr ".in" 0.12; +createNode transform -n "shotCam"; + setAttr ".t" -type "double3" 0 4 12 ; + setAttr ".r" -type "double3" -10 0 0 ; +createNode camera -n "shotCamShape" -p "shotCam"; + setAttr -k off ".v"; + setAttr ".fl" 50; + setAttr ".coi" 10; +createNode lightLinker -s -n "lightLinker1"; +createNode displayLayerManager -n "layerManager"; +createNode displayLayer -n "defaultLayer"; + setAttr ".ufem" -type "stringArray" 0 ; +createNode renderLayerManager -n "renderLayerManager"; +createNode renderLayer -n "defaultRenderLayer"; + setAttr ".g" yes; +createNode standardSurface -n "floorMat"; + setAttr ".bc" -type "float3" 0.22 0.23 0.25 ; + setAttr ".m" 0.7; + setAttr ".sr" 0.08; +createNode shadingEngine -n "floorMatSG"; + setAttr ".ihi" 0; + setAttr ".ro" yes; +createNode standardSurface -n "goldBallMat"; + setAttr ".bc" -type "float3" 0.95 0.72 0.35 ; + setAttr ".m" 1; + setAttr ".sr" 0.05; +createNode shadingEngine -n "goldBallMatSG"; + setAttr ".ihi" 0; + setAttr ".ro" yes; +createNode standardSurface -n "chromeBallMat"; + setAttr ".bc" -type "float3" 0.85 0.85 0.85 ; + setAttr ".m" 1; + setAttr ".sr" 0.05; +createNode shadingEngine -n "chromeBallMatSG"; + setAttr ".ihi" 0; + setAttr ".ro" yes; +createNode standardSurface -n "redBallMat"; + setAttr ".bc" -type "float3" 0.8 0.03 0.02 ; + setAttr ".sr" 0.15; +createNode shadingEngine -n "redBallMatSG"; + setAttr ".ihi" 0; + setAttr ".ro" yes; +createNode file -n "skyImage"; + setAttr ".ftn" -type "string" "../textures/sky.hdr"; +createNode polyCube -n "polyCube1"; + setAttr ".w" 50; + setAttr ".h" 0.02; + setAttr ".d" 50; + setAttr ".sw" 20; + setAttr ".sh" 1; + setAttr ".sd" 20; +createNode polySphere -n "polySphere1"; + setAttr ".r" 1.5; + setAttr ".sa" 48; + setAttr ".sh" 32; +createNode polySphere -n "polySphere2"; + setAttr ".r" 1.5; + setAttr ".sa" 48; + setAttr ".sh" 32; +createNode polySphere -n "polySphere3"; + setAttr ".r" 1; + setAttr ".sa" 48; + setAttr ".sh" 32; +createNode aiOptions -s -n "defaultArnoldRenderOptions"; +createNode aiAOVFilter -s -n "defaultArnoldFilter"; +createNode aiAOVDriver -s -n "defaultArnoldDriver"; +createNode aiAOVDriver -s -n "defaultArnoldDisplayDriver"; +select -ne :lightList1; + setAttr -s 1 ".l"; +createNode script -n "sceneConfigurationScriptNode"; + setAttr ".b" -type "string" "playbackOptions -min 1 -max 120 -ast 1 -aet 200 "; + setAttr ".st" 6; +select -ne :time1; + setAttr ".o" 1; + setAttr ".unw" 1; +select -ne :hardwareRenderingGlobals; + setAttr ".fprt" yes; + setAttr ".rtfm" 1; + setAttr ".otfna" -type "stringArray" 22 "NURBS Curves" "NURBS Surfaces" "Polygons" "Subdiv Surface" "Particles" "Particle Instance" "Fluids" "Strokes" "Image Planes" "UI" "Lights" "Cameras" "Locators" "Joints" "IK Handles" "Deformers" "Motion Trails" "Components" "Hair Systems" "Follicles" "Misc. UI" "Ornaments"; + setAttr ".otfva" -type "Int32Array" 22 0 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0; +select -ne :renderPartition; + setAttr -s 6 ".st"; +select -ne :renderGlobalsList1; +select -ne :defaultShaderList1; + setAttr -s 10 ".s"; +select -ne :postProcessList1; + setAttr -s 2 ".p"; +select -ne :defaultRenderingList1; +select -ne :standardSurface1; + setAttr ".bc" -type "float3" 0.4 0.4 0.4 ; + setAttr ".sr" 0.5; +select -ne :openPBR_shader1; + setAttr ".bc" -type "float3" 0.4 0.4 0.4 ; + setAttr ".sr" 0.5; +select -ne :initialShadingGroup; + setAttr ".ro" yes; +select -ne :initialParticleSE; + setAttr ".ro" yes; +select -ne :defaultRenderGlobals; +select -ne :defaultResolution; +select -ne :defaultColorMgtGlobals; + setAttr ".cfe" yes; + setAttr ".cfp" -type "string" "/OCIO-configs/Maya2022-default/config.ocio"; + setAttr ".dn" -type "string" "sRGB"; + setAttr ".otn" -type "string" "ACES 1.0 SDR-video (sRGB)"; + setAttr ".potn" -type "string" "ACES 1.0 SDR-video (sRGB)"; + setAttr ".vn" -type "string" "ACES 1.0 SDR-video"; + setAttr ".vtn" -type "string" "ACES 1.0 SDR-video (sRGB)"; + setAttr ".wsn" -type "string" "ACEScg"; +select -ne :hardwareRenderGlobals; + setAttr ".ctrs" 256; + setAttr ".btrs" 512; +relationship "link" ":lightLinker1" ":initialShadingGroup.message" ":defaultLightSet.message"; +relationship "link" ":lightLinker1" ":initialParticleSE.message" ":defaultLightSet.message"; +relationship "link" ":lightLinker1" "floorMatSG.message" ":defaultLightSet.message"; +relationship "link" ":lightLinker1" "goldBallMatSG.message" ":defaultLightSet.message"; +relationship "link" ":lightLinker1" "chromeBallMatSG.message" ":defaultLightSet.message"; +relationship "link" ":lightLinker1" "redBallMatSG.message" ":defaultLightSet.message"; +relationship "shadowLink" ":lightLinker1" ":initialShadingGroup.message" ":defaultLightSet.message"; +relationship "shadowLink" ":lightLinker1" ":initialParticleSE.message" ":defaultLightSet.message"; +relationship "shadowLink" ":lightLinker1" "floorMatSG.message" ":defaultLightSet.message"; +relationship "shadowLink" ":lightLinker1" "goldBallMatSG.message" ":defaultLightSet.message"; +relationship "shadowLink" ":lightLinker1" "chromeBallMatSG.message" ":defaultLightSet.message"; +relationship "shadowLink" ":lightLinker1" "redBallMatSG.message" ":defaultLightSet.message"; +connectAttr "chromeBallMat.oc" "chromeBallMatSG.ss"; +connectAttr "floorMat.oc" "floorMatSG.ss"; +connectAttr "goldBallMat.oc" "goldBallMatSG.ss"; +connectAttr "layerManager.dli[0]" "defaultLayer.id"; +connectAttr "polyCube1.out" "floorShape.i"; +connectAttr "polySphere1.out" "goldBallShape.i"; +connectAttr "polySphere2.out" "chromeBallShape.i"; +connectAttr "polySphere3.out" "redBallShape.i"; +connectAttr "redBallMat.oc" "redBallMatSG.ss"; +connectAttr "renderLayerManager.rlmi[0]" "defaultRenderLayer.rlid"; +connectAttr "skyImage.oc" "skyShape.cl"; +connectAttr "chromeBallMat.msg" ":defaultShaderList1.s" -na; +connectAttr "chromeBallMatSG.pa" ":renderPartition.st" -na; +connectAttr "chromeBallShape.iog" "chromeBallMatSG.dsm" -na; +connectAttr "defaultRenderLayer.msg" ":defaultRenderingList1.r" -na; +connectAttr "floorMat.msg" ":defaultShaderList1.s" -na; +connectAttr "floorMatSG.pa" ":renderPartition.st" -na; +connectAttr "floorShape.iog" "floorMatSG.dsm" -na; +connectAttr "goldBallMat.msg" ":defaultShaderList1.s" -na; +connectAttr "goldBallMatSG.pa" ":renderPartition.st" -na; +connectAttr "goldBallShape.iog" "goldBallMatSG.dsm" -na; +connectAttr "redBallMat.msg" ":defaultShaderList1.s" -na; +connectAttr "redBallMatSG.pa" ":renderPartition.st" -na; +connectAttr "redBallShape.iog" "redBallMatSG.dsm" -na; +connectAttr "skyImage.msg" ":defaultTextureList1.tx" -na; +connectAttr "skyShape.ltd" ":lightList1.l" -na; +// End of .environment_hdri.ma.tmp diff --git a/examples/rendering/metal_roughness_sweep.ma b/examples/rendering/metal_roughness_sweep.ma new file mode 100644 index 00000000..1410e2e8 --- /dev/null +++ b/examples/rendering/metal_roughness_sweep.ma @@ -0,0 +1,343 @@ +//Maya ASCII 2024 scene +//Name: .metal_roughness_sweep.ma.tmp +//Codeset: UTF-8 +requires maya "2024"; +currentUnit -l centimeter -a degree -t film; +fileInfo "application" "aztek"; +fileInfo "version" "1.0.0"; +createNode transform -s -n "persp"; + setAttr ".v" no; + setAttr ".t" -type "double3" 0 5 16 ; + setAttr ".r" -type "double3" -13.360218444764483 0 0 ; +createNode camera -s -n "perspShape" -p "persp"; + setAttr ".fl" 50; + setAttr ".coi" 16.44506004853737; + setAttr ".imn" -type "string" "persp"; + setAttr ".den" -type "string" "persp_depth"; + setAttr ".man" -type "string" "persp_mask"; + setAttr ".hc" -type "string" "viewSet -p %camera"; +createNode transform -s -n "top"; + setAttr ".v" no; + setAttr ".t" -type "double3" 0 1000.1 0 ; + setAttr ".r" -type "double3" -90 0 0 ; +createNode camera -s -n "topShape" -p "top"; + setAttr ".coi" 1000.1; + setAttr ".o" yes; + setAttr ".rnd" no; + setAttr ".imn" -type "string" "top"; + setAttr ".den" -type "string" "top_depth"; + setAttr ".man" -type "string" "top_mask"; + setAttr ".hc" -type "string" "viewSet -t %camera"; +createNode transform -s -n "front"; + setAttr ".v" no; + setAttr ".t" -type "double3" 0 0 1000.1 ; +createNode camera -s -n "frontShape" -p "front"; + setAttr ".coi" 1000.1; + setAttr ".o" yes; + setAttr ".rnd" no; + setAttr ".imn" -type "string" "front"; + setAttr ".den" -type "string" "front_depth"; + setAttr ".man" -type "string" "front_mask"; + setAttr ".hc" -type "string" "viewSet -f %camera"; +createNode transform -s -n "side"; + setAttr ".v" no; + setAttr ".t" -type "double3" 1000.1 0 0 ; + setAttr ".r" -type "double3" 0 90 0 ; +createNode camera -s -n "sideShape" -p "side"; + setAttr ".coi" 1000.1; + setAttr ".o" yes; + setAttr ".rnd" no; + setAttr ".imn" -type "string" "side"; + setAttr ".den" -type "string" "side_depth"; + setAttr ".man" -type "string" "side_mask"; + setAttr ".hc" -type "string" "viewSet -s %camera"; +createNode transform -n "floor"; + setAttr ".t" -type "double3" 0 -0.01 0 ; +createNode mesh -n "floorShape" -p "floor"; + setAttr -k off ".v"; +createNode transform -n "metal0"; + setAttr ".t" -type "double3" -6 1 0 ; +createNode mesh -n "metalShape0" -p "metal0"; + setAttr -k off ".v"; +createNode transform -n "metal1"; + setAttr ".t" -type "double3" -4 1 0 ; +createNode mesh -n "metalShape1" -p "metal1"; + setAttr -k off ".v"; +createNode transform -n "metal2"; + setAttr ".t" -type "double3" -2 1 0 ; +createNode mesh -n "metalShape2" -p "metal2"; + setAttr -k off ".v"; +createNode transform -n "metal3"; + setAttr ".t" -type "double3" 0 1 0 ; +createNode mesh -n "metalShape3" -p "metal3"; + setAttr -k off ".v"; +createNode transform -n "metal4"; + setAttr ".t" -type "double3" 2 1 0 ; +createNode mesh -n "metalShape4" -p "metal4"; + setAttr -k off ".v"; +createNode transform -n "metal5"; + setAttr ".t" -type "double3" 4 1 0 ; +createNode mesh -n "metalShape5" -p "metal5"; + setAttr -k off ".v"; +createNode transform -n "metal6"; + setAttr ".t" -type "double3" 6 1 0 ; +createNode mesh -n "metalShape6" -p "metal6"; + setAttr -k off ".v"; +createNode transform -n "whiteBall"; + setAttr ".t" -type "double3" 0 1.2 -3 ; +createNode mesh -n "whiteBallShape" -p "whiteBall"; + setAttr -k off ".v"; +createNode transform -n "keyPoint"; + setAttr ".t" -type "double3" -4 7 5 ; +createNode pointLight -n "keyPointShape" -p "keyPoint"; + setAttr -k off ".v"; + setAttr ".in" 60; + setAttr ".de" 2; +createNode transform -n "sky"; + setAttr ".r" -type "double3" 0 45 0 ; +createNode aiSkyDomeLight -n "skyShape" -p "sky"; + setAttr -k off ".v"; + setAttr ".in" 0.15; +createNode transform -n "shotCam"; + setAttr ".t" -type "double3" 0 5 16 ; + setAttr ".r" -type "double3" -13 0 0 ; +createNode camera -n "shotCamShape" -p "shotCam"; + setAttr -k off ".v"; + setAttr ".fl" 50; + setAttr ".coi" 14; +createNode lightLinker -s -n "lightLinker1"; +createNode displayLayerManager -n "layerManager"; +createNode displayLayer -n "defaultLayer"; + setAttr ".ufem" -type "stringArray" 0 ; +createNode renderLayerManager -n "renderLayerManager"; +createNode renderLayer -n "defaultRenderLayer"; + setAttr ".g" yes; +createNode standardSurface -n "floorMat"; + setAttr ".bc" -type "float3" 0.2 0.21 0.23 ; + setAttr ".m" 0.6; + setAttr ".sr" 0.3; +createNode shadingEngine -n "floorMatSG"; + setAttr ".ihi" 0; + setAttr ".ro" yes; +createNode standardSurface -n "metal0Mat"; + setAttr ".bc" -type "float3" 0.95 0.72 0.35 ; + setAttr ".m" 1; + setAttr ".sr" 0.02; +createNode shadingEngine -n "metal0MatSG"; + setAttr ".ihi" 0; + setAttr ".ro" yes; +createNode standardSurface -n "metal1Mat"; + setAttr ".bc" -type "float3" 0.95 0.72 0.35 ; + setAttr ".m" 1; + setAttr ".sr" 0.08; +createNode shadingEngine -n "metal1MatSG"; + setAttr ".ihi" 0; + setAttr ".ro" yes; +createNode standardSurface -n "metal2Mat"; + setAttr ".bc" -type "float3" 0.95 0.72 0.35 ; + setAttr ".m" 1; + setAttr ".sr" 0.15; +createNode shadingEngine -n "metal2MatSG"; + setAttr ".ihi" 0; + setAttr ".ro" yes; +createNode standardSurface -n "metal3Mat"; + setAttr ".bc" -type "float3" 0.95 0.72 0.35 ; + setAttr ".m" 1; + setAttr ".sr" 0.25; +createNode shadingEngine -n "metal3MatSG"; + setAttr ".ihi" 0; + setAttr ".ro" yes; +createNode standardSurface -n "metal4Mat"; + setAttr ".bc" -type "float3" 0.95 0.72 0.35 ; + setAttr ".m" 1; + setAttr ".sr" 0.4; +createNode shadingEngine -n "metal4MatSG"; + setAttr ".ihi" 0; + setAttr ".ro" yes; +createNode standardSurface -n "metal5Mat"; + setAttr ".bc" -type "float3" 0.95 0.72 0.35 ; + setAttr ".m" 1; + setAttr ".sr" 0.6; +createNode shadingEngine -n "metal5MatSG"; + setAttr ".ihi" 0; + setAttr ".ro" yes; +createNode standardSurface -n "metal6Mat"; + setAttr ".bc" -type "float3" 0.95 0.72 0.35 ; + setAttr ".m" 1; + setAttr ".sr" 0.85; +createNode shadingEngine -n "metal6MatSG"; + setAttr ".ihi" 0; + setAttr ".ro" yes; +createNode standardSurface -n "whiteBallMat"; + setAttr ".bc" -type "float3" 0.9 0.9 0.9 ; +createNode shadingEngine -n "whiteBallMatSG"; + setAttr ".ihi" 0; + setAttr ".ro" yes; +createNode file -n "skyImage"; + setAttr ".ftn" -type "string" "../textures/sky.hdr"; +createNode polyCube -n "polyCube1"; + setAttr ".w" 40; + setAttr ".h" 0.02; + setAttr ".d" 40; + setAttr ".sw" 20; + setAttr ".sh" 1; + setAttr ".sd" 20; +createNode polySphere -n "polySphere1"; + setAttr ".r" 1; + setAttr ".sa" 48; + setAttr ".sh" 32; +createNode polySphere -n "polySphere2"; + setAttr ".r" 1; + setAttr ".sa" 48; + setAttr ".sh" 32; +createNode polySphere -n "polySphere3"; + setAttr ".r" 1; + setAttr ".sa" 48; + setAttr ".sh" 32; +createNode polySphere -n "polySphere4"; + setAttr ".r" 1; + setAttr ".sa" 48; + setAttr ".sh" 32; +createNode polySphere -n "polySphere5"; + setAttr ".r" 1; + setAttr ".sa" 48; + setAttr ".sh" 32; +createNode polySphere -n "polySphere6"; + setAttr ".r" 1; + setAttr ".sa" 48; + setAttr ".sh" 32; +createNode polySphere -n "polySphere7"; + setAttr ".r" 1; + setAttr ".sa" 48; + setAttr ".sh" 32; +createNode polySphere -n "polySphere8"; + setAttr ".r" 1.2; + setAttr ".sa" 48; + setAttr ".sh" 32; +createNode aiOptions -s -n "defaultArnoldRenderOptions"; +createNode aiAOVFilter -s -n "defaultArnoldFilter"; +createNode aiAOVDriver -s -n "defaultArnoldDriver"; +createNode aiAOVDriver -s -n "defaultArnoldDisplayDriver"; +select -ne :lightList1; + setAttr -s 2 ".l"; +select -ne :defaultLightSet; + setAttr -s 1 ".dsm"; +createNode script -n "sceneConfigurationScriptNode"; + setAttr ".b" -type "string" "playbackOptions -min 1 -max 120 -ast 1 -aet 200 "; + setAttr ".st" 6; +select -ne :time1; + setAttr ".o" 1; + setAttr ".unw" 1; +select -ne :hardwareRenderingGlobals; + setAttr ".fprt" yes; + setAttr ".rtfm" 1; + setAttr ".otfna" -type "stringArray" 22 "NURBS Curves" "NURBS Surfaces" "Polygons" "Subdiv Surface" "Particles" "Particle Instance" "Fluids" "Strokes" "Image Planes" "UI" "Lights" "Cameras" "Locators" "Joints" "IK Handles" "Deformers" "Motion Trails" "Components" "Hair Systems" "Follicles" "Misc. UI" "Ornaments"; + setAttr ".otfva" -type "Int32Array" 22 0 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0; +select -ne :renderPartition; + setAttr -s 11 ".st"; +select -ne :renderGlobalsList1; +select -ne :defaultShaderList1; + setAttr -s 15 ".s"; +select -ne :postProcessList1; + setAttr -s 2 ".p"; +select -ne :defaultRenderingList1; +select -ne :standardSurface1; + setAttr ".bc" -type "float3" 0.4 0.4 0.4 ; + setAttr ".sr" 0.5; +select -ne :openPBR_shader1; + setAttr ".bc" -type "float3" 0.4 0.4 0.4 ; + setAttr ".sr" 0.5; +select -ne :initialShadingGroup; + setAttr ".ro" yes; +select -ne :initialParticleSE; + setAttr ".ro" yes; +select -ne :defaultRenderGlobals; +select -ne :defaultResolution; +select -ne :defaultColorMgtGlobals; + setAttr ".cfe" yes; + setAttr ".cfp" -type "string" "/OCIO-configs/Maya2022-default/config.ocio"; + setAttr ".dn" -type "string" "sRGB"; + setAttr ".otn" -type "string" "ACES 1.0 SDR-video (sRGB)"; + setAttr ".potn" -type "string" "ACES 1.0 SDR-video (sRGB)"; + setAttr ".vn" -type "string" "ACES 1.0 SDR-video"; + setAttr ".vtn" -type "string" "ACES 1.0 SDR-video (sRGB)"; + setAttr ".wsn" -type "string" "ACEScg"; +select -ne :hardwareRenderGlobals; + setAttr ".ctrs" 256; + setAttr ".btrs" 512; +relationship "link" ":lightLinker1" ":initialShadingGroup.message" ":defaultLightSet.message"; +relationship "link" ":lightLinker1" ":initialParticleSE.message" ":defaultLightSet.message"; +relationship "link" ":lightLinker1" "floorMatSG.message" ":defaultLightSet.message"; +relationship "link" ":lightLinker1" "metal0MatSG.message" ":defaultLightSet.message"; +relationship "link" ":lightLinker1" "metal1MatSG.message" ":defaultLightSet.message"; +relationship "link" ":lightLinker1" "metal2MatSG.message" ":defaultLightSet.message"; +relationship "link" ":lightLinker1" "metal3MatSG.message" ":defaultLightSet.message"; +relationship "link" ":lightLinker1" "metal4MatSG.message" ":defaultLightSet.message"; +relationship "link" ":lightLinker1" "metal5MatSG.message" ":defaultLightSet.message"; +relationship "link" ":lightLinker1" "metal6MatSG.message" ":defaultLightSet.message"; +relationship "link" ":lightLinker1" "whiteBallMatSG.message" ":defaultLightSet.message"; +relationship "shadowLink" ":lightLinker1" ":initialShadingGroup.message" ":defaultLightSet.message"; +relationship "shadowLink" ":lightLinker1" ":initialParticleSE.message" ":defaultLightSet.message"; +relationship "shadowLink" ":lightLinker1" "floorMatSG.message" ":defaultLightSet.message"; +relationship "shadowLink" ":lightLinker1" "metal0MatSG.message" ":defaultLightSet.message"; +relationship "shadowLink" ":lightLinker1" "metal1MatSG.message" ":defaultLightSet.message"; +relationship "shadowLink" ":lightLinker1" "metal2MatSG.message" ":defaultLightSet.message"; +relationship "shadowLink" ":lightLinker1" "metal3MatSG.message" ":defaultLightSet.message"; +relationship "shadowLink" ":lightLinker1" "metal4MatSG.message" ":defaultLightSet.message"; +relationship "shadowLink" ":lightLinker1" "metal5MatSG.message" ":defaultLightSet.message"; +relationship "shadowLink" ":lightLinker1" "metal6MatSG.message" ":defaultLightSet.message"; +relationship "shadowLink" ":lightLinker1" "whiteBallMatSG.message" ":defaultLightSet.message"; +connectAttr "floorMat.oc" "floorMatSG.ss"; +connectAttr "layerManager.dli[0]" "defaultLayer.id"; +connectAttr "metal0Mat.oc" "metal0MatSG.ss"; +connectAttr "metal1Mat.oc" "metal1MatSG.ss"; +connectAttr "metal2Mat.oc" "metal2MatSG.ss"; +connectAttr "metal3Mat.oc" "metal3MatSG.ss"; +connectAttr "metal4Mat.oc" "metal4MatSG.ss"; +connectAttr "metal5Mat.oc" "metal5MatSG.ss"; +connectAttr "metal6Mat.oc" "metal6MatSG.ss"; +connectAttr "polyCube1.out" "floorShape.i"; +connectAttr "polySphere1.out" "metalShape0.i"; +connectAttr "polySphere2.out" "metalShape1.i"; +connectAttr "polySphere3.out" "metalShape2.i"; +connectAttr "polySphere4.out" "metalShape3.i"; +connectAttr "polySphere5.out" "metalShape4.i"; +connectAttr "polySphere6.out" "metalShape5.i"; +connectAttr "polySphere7.out" "metalShape6.i"; +connectAttr "polySphere8.out" "whiteBallShape.i"; +connectAttr "renderLayerManager.rlmi[0]" "defaultRenderLayer.rlid"; +connectAttr "skyImage.oc" "skyShape.cl"; +connectAttr "whiteBallMat.oc" "whiteBallMatSG.ss"; +connectAttr "defaultRenderLayer.msg" ":defaultRenderingList1.r" -na; +connectAttr "floorMat.msg" ":defaultShaderList1.s" -na; +connectAttr "floorMatSG.pa" ":renderPartition.st" -na; +connectAttr "floorShape.iog" "floorMatSG.dsm" -na; +connectAttr "keyPoint.iog" ":defaultLightSet.dsm" -na; +connectAttr "keyPointShape.ltd" ":lightList1.l" -na; +connectAttr "metal0Mat.msg" ":defaultShaderList1.s" -na; +connectAttr "metal0MatSG.pa" ":renderPartition.st" -na; +connectAttr "metal1Mat.msg" ":defaultShaderList1.s" -na; +connectAttr "metal1MatSG.pa" ":renderPartition.st" -na; +connectAttr "metal2Mat.msg" ":defaultShaderList1.s" -na; +connectAttr "metal2MatSG.pa" ":renderPartition.st" -na; +connectAttr "metal3Mat.msg" ":defaultShaderList1.s" -na; +connectAttr "metal3MatSG.pa" ":renderPartition.st" -na; +connectAttr "metal4Mat.msg" ":defaultShaderList1.s" -na; +connectAttr "metal4MatSG.pa" ":renderPartition.st" -na; +connectAttr "metal5Mat.msg" ":defaultShaderList1.s" -na; +connectAttr "metal5MatSG.pa" ":renderPartition.st" -na; +connectAttr "metal6Mat.msg" ":defaultShaderList1.s" -na; +connectAttr "metal6MatSG.pa" ":renderPartition.st" -na; +connectAttr "metalShape0.iog" "metal0MatSG.dsm" -na; +connectAttr "metalShape1.iog" "metal1MatSG.dsm" -na; +connectAttr "metalShape2.iog" "metal2MatSG.dsm" -na; +connectAttr "metalShape3.iog" "metal3MatSG.dsm" -na; +connectAttr "metalShape4.iog" "metal4MatSG.dsm" -na; +connectAttr "metalShape5.iog" "metal5MatSG.dsm" -na; +connectAttr "metalShape6.iog" "metal6MatSG.dsm" -na; +connectAttr "skyImage.msg" ":defaultTextureList1.tx" -na; +connectAttr "skyShape.ltd" ":lightList1.l" -na; +connectAttr "whiteBallMat.msg" ":defaultShaderList1.s" -na; +connectAttr "whiteBallMatSG.pa" ":renderPartition.st" -na; +connectAttr "whiteBallShape.iog" "whiteBallMatSG.dsm" -na; +// End of .metal_roughness_sweep.ma.tmp diff --git a/examples/rendering/reference/area_lights.png b/examples/rendering/reference/area_lights.png new file mode 100644 index 00000000..967fc7bb Binary files /dev/null and b/examples/rendering/reference/area_lights.png differ diff --git a/examples/rendering/reference/checker_sphere.png b/examples/rendering/reference/checker_sphere.png new file mode 100644 index 00000000..4e576e4a Binary files /dev/null and b/examples/rendering/reference/checker_sphere.png differ diff --git a/examples/rendering/reference/dielectric_glass.png b/examples/rendering/reference/dielectric_glass.png new file mode 100644 index 00000000..4ae8bdeb Binary files /dev/null and b/examples/rendering/reference/dielectric_glass.png differ diff --git a/examples/rendering/reference/emissive_object.png b/examples/rendering/reference/emissive_object.png new file mode 100644 index 00000000..28edb887 Binary files /dev/null and b/examples/rendering/reference/emissive_object.png differ diff --git a/examples/rendering/reference/environment_hdri.png b/examples/rendering/reference/environment_hdri.png new file mode 100644 index 00000000..829e66fa Binary files /dev/null and b/examples/rendering/reference/environment_hdri.png differ diff --git a/examples/rendering/reference/metal_roughness_sweep.png b/examples/rendering/reference/metal_roughness_sweep.png new file mode 100644 index 00000000..ab037333 Binary files /dev/null and b/examples/rendering/reference/metal_roughness_sweep.png differ diff --git a/examples/rendering/reference/reflections.png b/examples/rendering/reference/reflections.png new file mode 100644 index 00000000..8e18a3ea Binary files /dev/null and b/examples/rendering/reference/reflections.png differ diff --git a/examples/rendering/reference/tinted_glass.png b/examples/rendering/reference/tinted_glass.png new file mode 100644 index 00000000..8f4f5cd8 Binary files /dev/null and b/examples/rendering/reference/tinted_glass.png differ diff --git a/examples/rendering/reflections.ma b/examples/rendering/reflections.ma new file mode 100644 index 00000000..14f05991 --- /dev/null +++ b/examples/rendering/reflections.ma @@ -0,0 +1,200 @@ +//Maya ASCII 2024 scene +//Name: .reflections.ma.tmp +//Codeset: UTF-8 +requires maya "2024"; +currentUnit -l centimeter -a degree -t film; +fileInfo "application" "aztek"; +fileInfo "version" "1.0.0"; +createNode transform -s -n "persp"; + setAttr ".v" no; + setAttr ".t" -type "double3" 0 3.7 12 ; + setAttr ".r" -type "double3" -11.768288932020642 0 0 ; +createNode camera -s -n "perspShape" -p "persp"; + setAttr ".fl" 42; + setAttr ".coi" 12.257650672131263; + setAttr ".imn" -type "string" "persp"; + setAttr ".den" -type "string" "persp_depth"; + setAttr ".man" -type "string" "persp_mask"; + setAttr ".hc" -type "string" "viewSet -p %camera"; +createNode transform -s -n "top"; + setAttr ".v" no; + setAttr ".t" -type "double3" 0 1000.1 0 ; + setAttr ".r" -type "double3" -90 0 0 ; +createNode camera -s -n "topShape" -p "top"; + setAttr ".coi" 1000.1; + setAttr ".o" yes; + setAttr ".rnd" no; + setAttr ".imn" -type "string" "top"; + setAttr ".den" -type "string" "top_depth"; + setAttr ".man" -type "string" "top_mask"; + setAttr ".hc" -type "string" "viewSet -t %camera"; +createNode transform -s -n "front"; + setAttr ".v" no; + setAttr ".t" -type "double3" 0 0 1000.1 ; +createNode camera -s -n "frontShape" -p "front"; + setAttr ".coi" 1000.1; + setAttr ".o" yes; + setAttr ".rnd" no; + setAttr ".imn" -type "string" "front"; + setAttr ".den" -type "string" "front_depth"; + setAttr ".man" -type "string" "front_mask"; + setAttr ".hc" -type "string" "viewSet -f %camera"; +createNode transform -s -n "side"; + setAttr ".v" no; + setAttr ".t" -type "double3" 1000.1 0 0 ; + setAttr ".r" -type "double3" 0 90 0 ; +createNode camera -s -n "sideShape" -p "side"; + setAttr ".coi" 1000.1; + setAttr ".o" yes; + setAttr ".rnd" no; + setAttr ".imn" -type "string" "side"; + setAttr ".den" -type "string" "side_depth"; + setAttr ".man" -type "string" "side_mask"; + setAttr ".hc" -type "string" "viewSet -s %camera"; +createNode transform -n "floor"; + setAttr ".t" -type "double3" 0 -0.01 0 ; +createNode mesh -n "floorShape" -p "floor"; + setAttr -k off ".v"; +createNode transform -n "redSphere"; + setAttr ".t" -type "double3" -2 1.5 0 ; +createNode mesh -n "redSphereShape" -p "redSphere"; + setAttr -k off ".v"; +createNode transform -n "whiteSphere"; + setAttr ".t" -type "double3" 2.4 1.5 0.6 ; +createNode mesh -n "whiteSphereShape" -p "whiteSphere"; + setAttr -k off ".v"; +createNode transform -n "keyLight"; + setAttr ".r" -type "double3" -45 35 0 ; +createNode directionalLight -n "keyLightShape" -p "keyLight"; + setAttr -k off ".v"; + setAttr ".in" 2.5; +createNode transform -n "shotCam"; + setAttr ".t" -type "double3" 0 3.7 12 ; + setAttr ".r" -type "double3" -15 0 0 ; +createNode camera -n "shotCamShape" -p "shotCam"; + setAttr -k off ".v"; + setAttr ".fl" 42; + setAttr ".coi" 10; +createNode lightLinker -s -n "lightLinker1"; +createNode displayLayerManager -n "layerManager"; +createNode displayLayer -n "defaultLayer"; + setAttr ".ufem" -type "stringArray" 0 ; +createNode renderLayerManager -n "renderLayerManager"; +createNode renderLayer -n "defaultRenderLayer"; + setAttr ".g" yes; +createNode standardSurface -n "floorMat"; + setAttr ".bc" -type "float3" 0.55 0.57 0.6 ; + setAttr ".m" 0.75; + setAttr ".sr" 0.04; +createNode shadingEngine -n "floorMatSG"; + setAttr ".ihi" 0; + setAttr ".ro" yes; +createNode standardSurface -n "redSphereMat"; + setAttr ".bc" -type "float3" 0.8 0.03 0.02 ; + setAttr ".sr" 0.1; +createNode shadingEngine -n "redSphereMatSG"; + setAttr ".ihi" 0; + setAttr ".ro" yes; +createNode standardSurface -n "whiteSphereMat"; + setAttr ".bc" -type "float3" 0.8 0.8 0.78 ; + setAttr ".sr" 0.1; +createNode shadingEngine -n "whiteSphereMatSG"; + setAttr ".ihi" 0; + setAttr ".ro" yes; +createNode polyCube -n "polyCube1"; + setAttr ".w" 30; + setAttr ".h" 0.02; + setAttr ".d" 30; + setAttr ".sw" 20; + setAttr ".sh" 1; + setAttr ".sd" 20; +createNode polySphere -n "polySphere1"; + setAttr ".r" 1.5; + setAttr ".sa" 48; + setAttr ".sh" 32; +createNode polySphere -n "polySphere2"; + setAttr ".r" 1.5; + setAttr ".sa" 48; + setAttr ".sh" 32; +createNode aiOptions -s -n "defaultArnoldRenderOptions"; +createNode aiAOVFilter -s -n "defaultArnoldFilter"; +createNode aiAOVDriver -s -n "defaultArnoldDriver"; +createNode aiAOVDriver -s -n "defaultArnoldDisplayDriver"; +select -ne :lightList1; + setAttr -s 1 ".l"; +select -ne :defaultLightSet; + setAttr -s 1 ".dsm"; +createNode script -n "sceneConfigurationScriptNode"; + setAttr ".b" -type "string" "playbackOptions -min 1 -max 120 -ast 1 -aet 200 "; + setAttr ".st" 6; +select -ne :time1; + setAttr ".o" 1; + setAttr ".unw" 1; +select -ne :hardwareRenderingGlobals; + setAttr ".fprt" yes; + setAttr ".rtfm" 1; + setAttr ".otfna" -type "stringArray" 22 "NURBS Curves" "NURBS Surfaces" "Polygons" "Subdiv Surface" "Particles" "Particle Instance" "Fluids" "Strokes" "Image Planes" "UI" "Lights" "Cameras" "Locators" "Joints" "IK Handles" "Deformers" "Motion Trails" "Components" "Hair Systems" "Follicles" "Misc. UI" "Ornaments"; + setAttr ".otfva" -type "Int32Array" 22 0 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0; +select -ne :renderPartition; + setAttr -s 5 ".st"; +select -ne :renderGlobalsList1; +select -ne :defaultShaderList1; + setAttr -s 9 ".s"; +select -ne :postProcessList1; + setAttr -s 2 ".p"; +select -ne :defaultRenderingList1; +select -ne :standardSurface1; + setAttr ".bc" -type "float3" 0.4 0.4 0.4 ; + setAttr ".sr" 0.5; +select -ne :openPBR_shader1; + setAttr ".bc" -type "float3" 0.4 0.4 0.4 ; + setAttr ".sr" 0.5; +select -ne :initialShadingGroup; + setAttr ".ro" yes; +select -ne :initialParticleSE; + setAttr ".ro" yes; +select -ne :defaultRenderGlobals; +select -ne :defaultResolution; +select -ne :defaultColorMgtGlobals; + setAttr ".cfe" yes; + setAttr ".cfp" -type "string" "/OCIO-configs/Maya2022-default/config.ocio"; + setAttr ".dn" -type "string" "sRGB"; + setAttr ".otn" -type "string" "ACES 1.0 SDR-video (sRGB)"; + setAttr ".potn" -type "string" "ACES 1.0 SDR-video (sRGB)"; + setAttr ".vn" -type "string" "ACES 1.0 SDR-video"; + setAttr ".vtn" -type "string" "ACES 1.0 SDR-video (sRGB)"; + setAttr ".wsn" -type "string" "ACEScg"; +select -ne :hardwareRenderGlobals; + setAttr ".ctrs" 256; + setAttr ".btrs" 512; +relationship "link" ":lightLinker1" ":initialShadingGroup.message" ":defaultLightSet.message"; +relationship "link" ":lightLinker1" ":initialParticleSE.message" ":defaultLightSet.message"; +relationship "link" ":lightLinker1" "floorMatSG.message" ":defaultLightSet.message"; +relationship "link" ":lightLinker1" "redSphereMatSG.message" ":defaultLightSet.message"; +relationship "link" ":lightLinker1" "whiteSphereMatSG.message" ":defaultLightSet.message"; +relationship "shadowLink" ":lightLinker1" ":initialShadingGroup.message" ":defaultLightSet.message"; +relationship "shadowLink" ":lightLinker1" ":initialParticleSE.message" ":defaultLightSet.message"; +relationship "shadowLink" ":lightLinker1" "floorMatSG.message" ":defaultLightSet.message"; +relationship "shadowLink" ":lightLinker1" "redSphereMatSG.message" ":defaultLightSet.message"; +relationship "shadowLink" ":lightLinker1" "whiteSphereMatSG.message" ":defaultLightSet.message"; +connectAttr "floorMat.oc" "floorMatSG.ss"; +connectAttr "layerManager.dli[0]" "defaultLayer.id"; +connectAttr "polyCube1.out" "floorShape.i"; +connectAttr "polySphere1.out" "redSphereShape.i"; +connectAttr "polySphere2.out" "whiteSphereShape.i"; +connectAttr "redSphereMat.oc" "redSphereMatSG.ss"; +connectAttr "renderLayerManager.rlmi[0]" "defaultRenderLayer.rlid"; +connectAttr "whiteSphereMat.oc" "whiteSphereMatSG.ss"; +connectAttr "defaultRenderLayer.msg" ":defaultRenderingList1.r" -na; +connectAttr "floorMat.msg" ":defaultShaderList1.s" -na; +connectAttr "floorMatSG.pa" ":renderPartition.st" -na; +connectAttr "floorShape.iog" "floorMatSG.dsm" -na; +connectAttr "keyLight.iog" ":defaultLightSet.dsm" -na; +connectAttr "keyLightShape.ltd" ":lightList1.l" -na; +connectAttr "redSphereMat.msg" ":defaultShaderList1.s" -na; +connectAttr "redSphereMatSG.pa" ":renderPartition.st" -na; +connectAttr "redSphereShape.iog" "redSphereMatSG.dsm" -na; +connectAttr "whiteSphereMat.msg" ":defaultShaderList1.s" -na; +connectAttr "whiteSphereMatSG.pa" ":renderPartition.st" -na; +connectAttr "whiteSphereShape.iog" "whiteSphereMatSG.dsm" -na; +// End of .reflections.ma.tmp diff --git a/examples/rendering/tinted_glass.ma b/examples/rendering/tinted_glass.ma new file mode 100644 index 00000000..34a3d4f8 --- /dev/null +++ b/examples/rendering/tinted_glass.ma @@ -0,0 +1,277 @@ +//Maya ASCII 2024 scene +//Name: .tinted_glass.ma.tmp +//Codeset: UTF-8 +requires maya "2024"; +currentUnit -l centimeter -a degree -t film; +fileInfo "application" "aztek"; +fileInfo "version" "1.0.0"; +createNode transform -s -n "persp"; + setAttr ".v" no; + setAttr ".t" -type "double3" 0 3.6 13 ; + setAttr ".r" -type "double3" -10.459909092929129 0 0 ; +createNode camera -s -n "perspShape" -p "persp"; + setAttr ".fl" 50; + setAttr ".coi" 13.219682295728592; + setAttr ".imn" -type "string" "persp"; + setAttr ".den" -type "string" "persp_depth"; + setAttr ".man" -type "string" "persp_mask"; + setAttr ".hc" -type "string" "viewSet -p %camera"; +createNode transform -s -n "top"; + setAttr ".v" no; + setAttr ".t" -type "double3" 0 1000.1 0 ; + setAttr ".r" -type "double3" -90 0 0 ; +createNode camera -s -n "topShape" -p "top"; + setAttr ".coi" 1000.1; + setAttr ".o" yes; + setAttr ".rnd" no; + setAttr ".imn" -type "string" "top"; + setAttr ".den" -type "string" "top_depth"; + setAttr ".man" -type "string" "top_mask"; + setAttr ".hc" -type "string" "viewSet -t %camera"; +createNode transform -s -n "front"; + setAttr ".v" no; + setAttr ".t" -type "double3" 0 0 1000.1 ; +createNode camera -s -n "frontShape" -p "front"; + setAttr ".coi" 1000.1; + setAttr ".o" yes; + setAttr ".rnd" no; + setAttr ".imn" -type "string" "front"; + setAttr ".den" -type "string" "front_depth"; + setAttr ".man" -type "string" "front_mask"; + setAttr ".hc" -type "string" "viewSet -f %camera"; +createNode transform -s -n "side"; + setAttr ".v" no; + setAttr ".t" -type "double3" 1000.1 0 0 ; + setAttr ".r" -type "double3" 0 90 0 ; +createNode camera -s -n "sideShape" -p "side"; + setAttr ".coi" 1000.1; + setAttr ".o" yes; + setAttr ".rnd" no; + setAttr ".imn" -type "string" "side"; + setAttr ".den" -type "string" "side_depth"; + setAttr ".man" -type "string" "side_mask"; + setAttr ".hc" -type "string" "viewSet -s %camera"; +createNode transform -n "floor"; + setAttr ".t" -type "double3" 0 -0.01 0 ; +createNode mesh -n "floorShape" -p "floor"; + setAttr -k off ".v"; +createNode transform -n "wall"; + setAttr ".t" -type "double3" 0 5 -8 ; +createNode mesh -n "wallShape" -p "wall"; + setAttr -k off ".v"; +createNode transform -n "tint0"; + setAttr ".t" -type "double3" -4.5 1.4 0 ; +createNode mesh -n "tintShape0" -p "tint0"; + setAttr -k off ".v"; +createNode transform -n "tint1"; + setAttr ".t" -type "double3" -1.5 1.4 0 ; +createNode mesh -n "tintShape1" -p "tint1"; + setAttr -k off ".v"; +createNode transform -n "tint2"; + setAttr ".t" -type "double3" 1.5 1.4 0 ; +createNode mesh -n "tintShape2" -p "tint2"; + setAttr -k off ".v"; +createNode transform -n "tint3"; + setAttr ".t" -type "double3" 4.5 1.4 0 ; +createNode mesh -n "tintShape3" -p "tint3"; + setAttr -k off ".v"; +createNode transform -n "keyPoint"; + setAttr ".t" -type "double3" -4 7 5 ; +createNode pointLight -n "keyPointShape" -p "keyPoint"; + setAttr -k off ".v"; + setAttr ".in" 12; + setAttr ".de" 2; +createNode transform -n "shotCam"; + setAttr ".t" -type "double3" 0 3.6 13 ; + setAttr ".r" -type "double3" -8 0 0 ; +createNode camera -n "shotCamShape" -p "shotCam"; + setAttr -k off ".v"; + setAttr ".fl" 50; + setAttr ".coi" 10; +createNode lightLinker -s -n "lightLinker1"; +createNode displayLayerManager -n "layerManager"; +createNode displayLayer -n "defaultLayer"; + setAttr ".ufem" -type "stringArray" 0 ; +createNode renderLayerManager -n "renderLayerManager"; +createNode renderLayer -n "defaultRenderLayer"; + setAttr ".g" yes; +createNode standardSurface -n "floorMat"; + setAttr ".bc" -type "float3" 0.3 0.32 0.35 ; + setAttr ".m" 0.2; + setAttr ".sr" 0.15; +createNode shadingEngine -n "floorMatSG"; + setAttr ".ihi" 0; + setAttr ".ro" yes; +createNode standardSurface -n "wallMat"; + setAttr ".bc" -type "float3" 0 0 0 ; + setAttr ".sr" 0.5; + setAttr ".e" 1; + setAttr ".ec" -type "float3" 0.6 0.6 0.6 ; +createNode shadingEngine -n "wallMatSG"; + setAttr ".ihi" 0; + setAttr ".ro" yes; +createNode standardSurface -n "tint0Mat"; + setAttr ".bc" -type "float3" 1 1 1 ; + setAttr ".sr" 0.03; + setAttr ".t" 1; + setAttr ".trc" -type "float3" 0.85 0.1 0.08 ; +createNode shadingEngine -n "tint0MatSG"; + setAttr ".ihi" 0; + setAttr ".ro" yes; +createNode standardSurface -n "tint1Mat"; + setAttr ".bc" -type "float3" 1 1 1 ; + setAttr ".sr" 0.03; + setAttr ".t" 1; + setAttr ".trc" -type "float3" 0.1 0.7 0.25 ; +createNode shadingEngine -n "tint1MatSG"; + setAttr ".ihi" 0; + setAttr ".ro" yes; +createNode standardSurface -n "tint2Mat"; + setAttr ".bc" -type "float3" 1 1 1 ; + setAttr ".sr" 0.03; + setAttr ".t" 1; + setAttr ".trc" -type "float3" 0.1 0.35 0.85 ; +createNode shadingEngine -n "tint2MatSG"; + setAttr ".ihi" 0; + setAttr ".ro" yes; +createNode standardSurface -n "tint3Mat"; + setAttr ".bc" -type "float3" 1 1 1 ; + setAttr ".sr" 0.03; + setAttr ".t" 1; + setAttr ".trc" -type "float3" 0.85 0.65 0.1 ; +createNode shadingEngine -n "tint3MatSG"; + setAttr ".ihi" 0; + setAttr ".ro" yes; +createNode polyCube -n "polyCube1"; + setAttr ".w" 30; + setAttr ".h" 0.02; + setAttr ".d" 30; + setAttr ".sw" 20; + setAttr ".sh" 1; + setAttr ".sd" 20; +createNode polyCube -n "polyCube2"; + setAttr ".w" 24; + setAttr ".h" 10; + setAttr ".d" 0.2; + setAttr ".sw" 1; + setAttr ".sh" 1; + setAttr ".sd" 1; +createNode polySphere -n "polySphere1"; + setAttr ".r" 1.3; + setAttr ".sa" 48; + setAttr ".sh" 32; +createNode polySphere -n "polySphere2"; + setAttr ".r" 1.3; + setAttr ".sa" 48; + setAttr ".sh" 32; +createNode polySphere -n "polySphere3"; + setAttr ".r" 1.3; + setAttr ".sa" 48; + setAttr ".sh" 32; +createNode polySphere -n "polySphere4"; + setAttr ".r" 1.3; + setAttr ".sa" 48; + setAttr ".sh" 32; +createNode aiOptions -s -n "defaultArnoldRenderOptions"; +createNode aiAOVFilter -s -n "defaultArnoldFilter"; +createNode aiAOVDriver -s -n "defaultArnoldDriver"; +createNode aiAOVDriver -s -n "defaultArnoldDisplayDriver"; +select -ne :lightList1; + setAttr -s 1 ".l"; +select -ne :defaultLightSet; + setAttr -s 1 ".dsm"; +createNode script -n "sceneConfigurationScriptNode"; + setAttr ".b" -type "string" "playbackOptions -min 1 -max 120 -ast 1 -aet 200 "; + setAttr ".st" 6; +select -ne :time1; + setAttr ".o" 1; + setAttr ".unw" 1; +select -ne :hardwareRenderingGlobals; + setAttr ".fprt" yes; + setAttr ".rtfm" 1; + setAttr ".otfna" -type "stringArray" 22 "NURBS Curves" "NURBS Surfaces" "Polygons" "Subdiv Surface" "Particles" "Particle Instance" "Fluids" "Strokes" "Image Planes" "UI" "Lights" "Cameras" "Locators" "Joints" "IK Handles" "Deformers" "Motion Trails" "Components" "Hair Systems" "Follicles" "Misc. UI" "Ornaments"; + setAttr ".otfva" -type "Int32Array" 22 0 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0; +select -ne :renderPartition; + setAttr -s 8 ".st"; +select -ne :renderGlobalsList1; +select -ne :defaultShaderList1; + setAttr -s 12 ".s"; +select -ne :postProcessList1; + setAttr -s 2 ".p"; +select -ne :defaultRenderingList1; +select -ne :standardSurface1; + setAttr ".bc" -type "float3" 0.4 0.4 0.4 ; + setAttr ".sr" 0.5; +select -ne :openPBR_shader1; + setAttr ".bc" -type "float3" 0.4 0.4 0.4 ; + setAttr ".sr" 0.5; +select -ne :initialShadingGroup; + setAttr ".ro" yes; +select -ne :initialParticleSE; + setAttr ".ro" yes; +select -ne :defaultRenderGlobals; +select -ne :defaultResolution; +select -ne :defaultColorMgtGlobals; + setAttr ".cfe" yes; + setAttr ".cfp" -type "string" "/OCIO-configs/Maya2022-default/config.ocio"; + setAttr ".dn" -type "string" "sRGB"; + setAttr ".otn" -type "string" "ACES 1.0 SDR-video (sRGB)"; + setAttr ".potn" -type "string" "ACES 1.0 SDR-video (sRGB)"; + setAttr ".vn" -type "string" "ACES 1.0 SDR-video"; + setAttr ".vtn" -type "string" "ACES 1.0 SDR-video (sRGB)"; + setAttr ".wsn" -type "string" "ACEScg"; +select -ne :hardwareRenderGlobals; + setAttr ".ctrs" 256; + setAttr ".btrs" 512; +relationship "link" ":lightLinker1" ":initialShadingGroup.message" ":defaultLightSet.message"; +relationship "link" ":lightLinker1" ":initialParticleSE.message" ":defaultLightSet.message"; +relationship "link" ":lightLinker1" "floorMatSG.message" ":defaultLightSet.message"; +relationship "link" ":lightLinker1" "wallMatSG.message" ":defaultLightSet.message"; +relationship "link" ":lightLinker1" "tint0MatSG.message" ":defaultLightSet.message"; +relationship "link" ":lightLinker1" "tint1MatSG.message" ":defaultLightSet.message"; +relationship "link" ":lightLinker1" "tint2MatSG.message" ":defaultLightSet.message"; +relationship "link" ":lightLinker1" "tint3MatSG.message" ":defaultLightSet.message"; +relationship "shadowLink" ":lightLinker1" ":initialShadingGroup.message" ":defaultLightSet.message"; +relationship "shadowLink" ":lightLinker1" ":initialParticleSE.message" ":defaultLightSet.message"; +relationship "shadowLink" ":lightLinker1" "floorMatSG.message" ":defaultLightSet.message"; +relationship "shadowLink" ":lightLinker1" "wallMatSG.message" ":defaultLightSet.message"; +relationship "shadowLink" ":lightLinker1" "tint0MatSG.message" ":defaultLightSet.message"; +relationship "shadowLink" ":lightLinker1" "tint1MatSG.message" ":defaultLightSet.message"; +relationship "shadowLink" ":lightLinker1" "tint2MatSG.message" ":defaultLightSet.message"; +relationship "shadowLink" ":lightLinker1" "tint3MatSG.message" ":defaultLightSet.message"; +connectAttr "floorMat.oc" "floorMatSG.ss"; +connectAttr "layerManager.dli[0]" "defaultLayer.id"; +connectAttr "polyCube1.out" "floorShape.i"; +connectAttr "polyCube2.out" "wallShape.i"; +connectAttr "polySphere1.out" "tintShape0.i"; +connectAttr "polySphere2.out" "tintShape1.i"; +connectAttr "polySphere3.out" "tintShape2.i"; +connectAttr "polySphere4.out" "tintShape3.i"; +connectAttr "renderLayerManager.rlmi[0]" "defaultRenderLayer.rlid"; +connectAttr "tint0Mat.oc" "tint0MatSG.ss"; +connectAttr "tint1Mat.oc" "tint1MatSG.ss"; +connectAttr "tint2Mat.oc" "tint2MatSG.ss"; +connectAttr "tint3Mat.oc" "tint3MatSG.ss"; +connectAttr "wallMat.oc" "wallMatSG.ss"; +connectAttr "defaultRenderLayer.msg" ":defaultRenderingList1.r" -na; +connectAttr "floorMat.msg" ":defaultShaderList1.s" -na; +connectAttr "floorMatSG.pa" ":renderPartition.st" -na; +connectAttr "floorShape.iog" "floorMatSG.dsm" -na; +connectAttr "keyPoint.iog" ":defaultLightSet.dsm" -na; +connectAttr "keyPointShape.ltd" ":lightList1.l" -na; +connectAttr "tint0Mat.msg" ":defaultShaderList1.s" -na; +connectAttr "tint0MatSG.pa" ":renderPartition.st" -na; +connectAttr "tint1Mat.msg" ":defaultShaderList1.s" -na; +connectAttr "tint1MatSG.pa" ":renderPartition.st" -na; +connectAttr "tint2Mat.msg" ":defaultShaderList1.s" -na; +connectAttr "tint2MatSG.pa" ":renderPartition.st" -na; +connectAttr "tint3Mat.msg" ":defaultShaderList1.s" -na; +connectAttr "tint3MatSG.pa" ":renderPartition.st" -na; +connectAttr "tintShape0.iog" "tint0MatSG.dsm" -na; +connectAttr "tintShape1.iog" "tint1MatSG.dsm" -na; +connectAttr "tintShape2.iog" "tint2MatSG.dsm" -na; +connectAttr "tintShape3.iog" "tint3MatSG.dsm" -na; +connectAttr "wallMat.msg" ":defaultShaderList1.s" -na; +connectAttr "wallMatSG.pa" ":renderPartition.st" -na; +connectAttr "wallShape.iog" "wallMatSG.dsm" -na; +// End of .tinted_glass.ma.tmp diff --git a/examples/rendering/viewport/area_lights.png b/examples/rendering/viewport/area_lights.png new file mode 100644 index 00000000..7bc184b6 Binary files /dev/null and b/examples/rendering/viewport/area_lights.png differ diff --git a/examples/rendering/viewport/checker_sphere.png b/examples/rendering/viewport/checker_sphere.png new file mode 100644 index 00000000..83ba85ad Binary files /dev/null and b/examples/rendering/viewport/checker_sphere.png differ diff --git a/examples/rendering/viewport/dielectric_glass.png b/examples/rendering/viewport/dielectric_glass.png new file mode 100644 index 00000000..174b2f35 Binary files /dev/null and b/examples/rendering/viewport/dielectric_glass.png differ diff --git a/examples/rendering/viewport/emissive_object.png b/examples/rendering/viewport/emissive_object.png new file mode 100644 index 00000000..5751ff29 Binary files /dev/null and b/examples/rendering/viewport/emissive_object.png differ diff --git a/examples/rendering/viewport/environment_hdri.png b/examples/rendering/viewport/environment_hdri.png new file mode 100644 index 00000000..6c22b2a7 Binary files /dev/null and b/examples/rendering/viewport/environment_hdri.png differ diff --git a/examples/rendering/viewport/metal_roughness_sweep.png b/examples/rendering/viewport/metal_roughness_sweep.png new file mode 100644 index 00000000..b7ef2279 Binary files /dev/null and b/examples/rendering/viewport/metal_roughness_sweep.png differ diff --git a/examples/rendering/viewport/reflections.png b/examples/rendering/viewport/reflections.png new file mode 100644 index 00000000..9ce33b48 Binary files /dev/null and b/examples/rendering/viewport/reflections.png differ diff --git a/examples/rendering/viewport/tinted_glass.png b/examples/rendering/viewport/tinted_glass.png new file mode 100644 index 00000000..f602575a Binary files /dev/null and b/examples/rendering/viewport/tinted_glass.png differ diff --git a/examples/tools/make_rendering_parity.py b/examples/tools/make_rendering_parity.py new file mode 100644 index 00000000..b96ba975 --- /dev/null +++ b/examples/tools/make_rendering_parity.py @@ -0,0 +1,241 @@ +"""Builds the lighting parity scenes in examples/rendering/. +Run from the repository root: + ./build/Aztek/AppRun --batch --script examples/tools/make_rendering_parity.py +Each scene is opened by Aztek, saved by Aztek, and rendered through its shotCam by the Render View's path. +""" +import math +import os +import traceback + +import maya.cmds as mc + +ROOT = os.environ.get("AZTEK_EXAMPLES", os.path.join(os.getcwd(), "examples")) +OUT = os.path.join(ROOT, "rendering") +LOG = [] + + +def scene(name): + def wrap(fn): + try: + mc.file(new=True, force=True) + mc.currentUnit(l="cm", a="deg", t="film") + fn() + mc.select(clear=True) + mc.currentTime(mc.playbackOptions(q=True, min=True)) + mc.file(rename=os.path.join(OUT, name + ".ma")) + mc.file(save=True, type="mayaAscii", force=True) + LOG.append("ok " + name) + except Exception: + LOG.append("FAIL " + name + "\n" + traceback.format_exc()) + return fn + return wrap + + +def material(name, kind="standardSurface", color=(0.5, 0.5, 0.5), **attrs): + s = mc.shadingNode(kind, asShader=True, n=name) + attr = "baseColor" if kind in ("standardSurface", "openPBRSurface") else "color" + mc.setAttr(s + "." + attr, *color, type="double3") + for a, v in attrs.items(): + if isinstance(v, (tuple, list)): + mc.setAttr(s + "." + a, *v, type="double3") + else: + mc.setAttr(s + "." + a, v) + sg = mc.sets(renderable=True, noSurfaceShader=True, empty=True, n=name + "SG") + mc.connectAttr(s + ".outColor", sg + ".surfaceShader") + return s, sg + + +def assign(obj, sg): + mc.sets(obj, e=True, forceElement=sg) + + +def floor(size=30, name="floor", color=(0.42, 0.44, 0.47), rough=0.2, metal=0.0): + f = mc.polyCube(n=name, w=size, h=0.02, d=size, sx=20, sy=1, sz=20)[0] + mc.move(0, -0.01, 0, f) + m, sg = material(name + "Mat", color=color, specularRoughness=rough, metalness=metal) + assign(f, sg) + return f + + +def sphere(name, pos, radius=1.2, color=(0.5, 0.5, 0.5), **attrs): + s = mc.polySphere(n=name, r=radius, sx=48, sy=32)[0] + mc.move(pos[0], pos[1], pos[2], s) + m, sg = material(name + "Mat", color=color, **attrs) + assign(s, sg) + return s + + +def camera(pos=(0, 4.0, 12.0), rot=(-12, 0, 0), fl=50, coi=10.0): + c = mc.camera(n="shotCam")[0] + mc.setAttr(c + ".translateX", pos[0]) + mc.setAttr(c + ".translateY", pos[1]) + mc.setAttr(c + ".translateZ", pos[2]) + mc.setAttr(c + ".rotateX", rot[0]) + mc.setAttr(c + ".rotateY", rot[1]) + mc.setAttr(c + ".rotateZ", rot[2]) + mc.setAttr(c + ".focalLength", fl) + mc.setAttr(c + ".centerOfInterest", coi) + mc.setAttr("perspShape.focalLength", fl) + mc.viewPlace("persp", eye=pos, la=(0, 1.2, 0)) + return c + + +def point(name, pos=(-4.5, 7.5, 4.5), intensity=40.0, decay=2): + p = mc.pointLight(n=name, position=pos, intensity=intensity) + mc.setAttr(p + ".decayRate", decay) + mc.setAttr(p + ".useRayTraceShadows", 1) + return p + + +def area(name, pos=(-3.0, 6.5, 4.0), intensity=200.0, size=5.0): + p = mc.shadingNode("aiAreaLight", asLight=True, n=name) + mc.setAttr(p + ".intensity", intensity) + mc.setAttr(p + ".aiTranslator", 0) + mc.setAttr(p + ".useRayTraceShadows", 1) + mc.move(pos[0], pos[1], pos[2], p) + mc.setAttr(p + ".scaleX", size * 0.5) + mc.setAttr(p + ".scaleY", size * 0.5) + mc.rotate(-45, 35, 0, p) + return p + + +def sky(image=None, intensity=0.8, rotation=0.0): + t = mc.createNode("transform", n="sky") + s = mc.createNode("aiSkyDomeLight", n="skyShape", p=t) + mc.setAttr(s + ".intensity", intensity) + mc.setAttr(t + ".rotateY", rotation) + if image: + f = mc.shadingNode("file", asTexture=True, n="skyImage") + mc.setAttr(f + ".fileTextureName", image, type="string") + mc.connectAttr(f + ".outColor", s + ".cl") + return s + + +# ===================================================================================================== the issue +@scene("reflections") +def _(): + floor(30, color=(0.55, 0.57, 0.60), rough=0.04, metal=0.75) + sphere("redSphere", (-2.0, 1.5, 0.0), 1.5, (0.8, 0.03, 0.02), specularRoughness=0.10) + sphere("whiteSphere", (2.4, 1.5, 0.6), 1.5, (0.8, 0.8, 0.78), specularRoughness=0.10) + key = mc.directionalLight(n="keyLight", rotation=(-45, 35, 0), intensity=2.5) + mc.setAttr(key + ".useRayTraceShadows", 1) + camera((0, 3.7, 12.0), (-15, 0, 0), 42, 10.0) + + +# ===================================================================================================== metals +@scene("metal_roughness_sweep") +def _(): + floor(40, color=(0.20, 0.21, 0.23), rough=0.3, metal=0.6) + roughs = [0.02, 0.08, 0.15, 0.25, 0.40, 0.60, 0.85] + for i, r in enumerate(roughs): + x = -6.0 + i * 2.0 + sphere("metal%d" % i, (x, 1.0, 0.0), 1.0, (0.95, 0.72, 0.35), specularRoughness=r, metalness=1.0) + sphere("whiteBall", (0.0, 1.2, -3.0), 1.2, (0.9, 0.9, 0.9), specularRoughness=0.2) + point("keyPoint", (-4.0, 7.0, 5.0), 60.0) + sky("../textures/sky.hdr", 0.15, 45.0) + camera((0, 5.0, 16.0), (-13, 0, 0), 50, 14.0) + + +# ===================================================================================================== glass +@scene("dielectric_glass") +def _(): + floor(30, color=(0.30, 0.32, 0.35), rough=0.15, metal=0.2) + wall = mc.polyCube(n="wall", w=24, h=10, d=0.2)[0] + mc.move(0, 5, -8, wall) + wm, wsg = material("wallMat", color=(0.0, 0.0, 0.0), specularRoughness=0.5, emission=1.0, emissionColor=(0.55, 0.55, 0.55)) + assign(wall, wsg) + left = mc.polyCube(n="leftBlock", w=2, h=4, d=2)[0] + mc.move(-3.6, 2, -5, left) + m, sg = material("leftMat", color=(0.95, 0.65, 0.08), specularRoughness=0.5, emission=0.35, emissionColor=(0.8, 0.5, 0.05)) + assign(left, sg) + right = mc.polyCube(n="rightBlock", w=2, h=4, d=2)[0] + mc.move(3.6, 2, -5, right) + m, sg = material("rightMat", color=(0.08, 0.55, 0.95), specularRoughness=0.5, emission=0.35, emissionColor=(0.05, 0.4, 0.8)) + assign(right, sg) + for i, ior in enumerate([1.33, 1.5, 1.7]): + sphere("glass%d" % i, (-3.0 + i * 3.0, 1.5, 0.0), 1.4, (1.0, 1.0, 1.0), + specularRoughness=0.02, transmission=1.0, transmissionColor=(0.85, 0.25, 0.2), specularIOR=ior) + point("keyPoint", (-4.0, 7.0, 5.0), 12.0) + camera((0, 3.6, 11.0), (-8, 0, 0), 50) + + +# ===================================================================================================== tinted glass +@scene("tinted_glass") +def _(): + floor(30, color=(0.30, 0.32, 0.35), rough=0.15, metal=0.2) + wall = mc.polyCube(n="wall", w=24, h=10, d=0.2)[0] + mc.move(0, 5, -8, wall) + wm, wsg = material("wallMat", color=(0.0, 0.0, 0.0), specularRoughness=0.5, emission=1.0, emissionColor=(0.6, 0.6, 0.6)) + assign(wall, wsg) + cols = [(0.85, 0.10, 0.08), (0.10, 0.70, 0.25), (0.10, 0.35, 0.85), (0.85, 0.65, 0.10)] + for i, c in enumerate(cols): + x = -4.5 + i * 3.0 + sphere("tint%d" % i, (x, 1.4, 0.0), 1.3, (1.0, 1.0, 1.0), specularRoughness=0.03, + transmission=1.0, transmissionColor=c, specularIOR=1.5) + point("keyPoint", (-4.0, 7.0, 5.0), 12.0) + camera((0, 3.6, 13.0), (-8, 0, 0), 50) + + +# ===================================================================================================== emission +@scene("emissive_object") +def _(): + floor(30, color=(0.45, 0.45, 0.45), rough=0.3) + wall = mc.polyCube(n="backWall", w=24, h=10, d=0.2)[0] + mc.move(0, 5, -7, wall) + m, sg = material("backMat", color=(0.5, 0.5, 0.5), specularRoughness=0.4) + assign(wall, sg) + sphere("litSphere", (0.0, 1.4, 0.0), 1.4, (0.8, 0.8, 0.8), specularRoughness=0.2) + panel = mc.polyCube(n="emitter", w=5, h=3, d=0.2)[0] + mc.move(-3.5, 3.0, 3.0, panel) + em, esg = material("emitterMat", color=(0.0, 0.0, 0.0), specularRoughness=0.5, emission=8.0, emissionColor=(1.0, 0.35, 0.05)) + assign(panel, esg) + point("fill", (4.0, 5.0, 4.0), 8.0) + camera((0, 3.5, 11.0), (-8, 0, 0), 50) + + +# ===================================================================================================== area lights +@scene("area_lights") +def _(): + floor(30, color=(0.38, 0.39, 0.41), rough=0.2) + sphere("redBall", (-2.2, 1.3, 0.0), 1.3, (0.8, 0.10, 0.08), specularRoughness=0.15) + sphere("blueBall", (2.2, 1.3, 0.0), 1.3, (0.08, 0.25, 0.75), specularRoughness=0.15) + area("keyArea", (-3.2, 5.5, 4.0), 250.0, 5.0) + area("fillArea", (4.0, 4.5, 3.0), 90.0, 4.0) + camera((0, 3.6, 11.0), (-8, 0, 0), 50) + + +# ===================================================================================================== environment +@scene("environment_hdri") +def _(): + floor(50, color=(0.22, 0.23, 0.25), rough=0.08, metal=0.7) + sphere("goldBall", (-2.0, 1.5, 0.0), 1.5, (0.95, 0.72, 0.35), specularRoughness=0.05, metalness=1.0) + sphere("chromeBall", (2.2, 1.5, 0.0), 1.5, (0.85, 0.85, 0.85), specularRoughness=0.05, metalness=1.0) + sphere("redBall", (0.2, 1.0, -3.2), 1.0, (0.8, 0.03, 0.02), specularRoughness=0.15) + sky("../textures/sky.hdr", 0.12, 30.0) + camera((0, 4.0, 12.0), (-10, 0, 0), 50) + + +# ===================================================================================================== checker +@scene("checker_sphere") +def _(): + floor(30, color=(0.35, 0.36, 0.38), rough=0.2) + ball = sphere("checkerBall", (0.0, 1.5, 0.0), 1.5, (1.0, 1.0, 1.0), specularRoughness=0.25) + for i, x in enumerate([-3.4, 3.4]): + sphere("plain%d" % i, (x, 1.2, -1.0), 1.2, (0.8, 0.8, 0.8), specularRoughness=0.2) + s = mc.shadingNode("lambert", asShader=True, n="checkerMat") + f = mc.shadingNode("file", asTexture=True, n="checkerFile") + p = mc.shadingNode("place2dTexture", asUtility=True, n="checkerPlace") + mc.connectAttr(p + ".outUV", f + ".uvCoord") + mc.connectAttr(p + ".outUvFilterSize", f + ".uvFilterSize") + mc.setAttr(p + ".repeatU", 6) + mc.setAttr(p + ".repeatV", 3) + mc.setAttr(f + ".fileTextureName", "../textures/checker.png", type="string") + mc.connectAttr(f + ".outColor", s + ".color") + sg = mc.sets(renderable=True, noSurfaceShader=True, empty=True, n="checkerMatSG") + mc.connectAttr(s + ".outColor", sg + ".surfaceShader") + mc.sets(ball, e=True, forceElement=sg) + point("keyPoint", (-4.5, 7.0, 4.5), 45.0) + camera((0, 3.5, 12.0), (-10, 0, 0), 50) + + +print("\n".join(LOG)) diff --git a/tools/render_parity/README.md b/tools/render_parity/README.md new file mode 100644 index 00000000..dc0392c3 --- /dev/null +++ b/tools/render_parity/README.md @@ -0,0 +1,89 @@ +# Lighting parity suite + +Eight scenes in `examples/rendering/` compare the realtime viewport with the Render View's path (Harold): + +| Scene | What it shows | +| --- | --- | +| `reflections` | The issue's scene: a grey floor and a red and a white sphere lit by one light. Both spheres reflect in the floor. | +| `metal_roughness_sweep` | Seven gold spheres, roughness 0.02 to 0.85, under an HDRI sky: sharp reflections at low roughness, blurred at high, the sky in both. | +| `dielectric_glass` | Three glass spheres at IOR 1.33, 1.5 and 1.7 over a wall and two coloured blocks. | +| `tinted_glass` | Four transmission colours over a light wall; the glass is tinted and what is behind it bends. | +| `emissive_object` | An emissive panel lighting a wall and a sphere. | +| `area_lights` | Two area lights on red and blue spheres. | +| `environment_hdri` | Metal spheres and a red ball under `examples/textures/sky.hdr`. | +| `checker_sphere` | A checker texture on a sphere, with two plain spheres beside it. | + +Each scene has a `shotCam`; the reference render and the viewport capture both look through it. The pictures are kept +as `reference/.png` (640 by 360, the Render View) and `viewport/.png` (the realtime viewport, cropped to +the same 16:9 field and resized to 640 by 360). + +## Taking the pictures again + +From the repository root, with a build and a display (Xvfb is enough): + +``` +tools/render_parity/capture.sh build/Aztek/AppRun +``` + +Name scenes to redo only those: + +``` +tools/render_parity/capture.sh build/Aztek/AppRun reflections dielectric_glass +``` + +The reference render is Harold's batch path through `shotCam`: + +``` +build/Aztek/AppRun -render -s 1 -cam shotCam -x 640 -y 360 -rd examples/rendering/reference -im reflections -of png examples/rendering/reflections.ma +``` + +The viewport capture is `--viewport-screenshot`: the window is fixed, the view is set to a single panel, the ViewCube, +grid, light and camera icons, handles and selection highlights are hidden, textures and the camera's depth of field +are on, and the viewport looks through `shotCam` with the scene's lights and shadows. The host writes a PPM, the shell +saves the PNG. `tools/render_parity/viewport.py` sets the camera and the lighting before the capture's 1500 ms timer. + +At another viewport size the crop is taken from the picture's own width, so the field stays the same: the camera's +horizontal field is fixed by its focal length, and cropping to 16:9 removes only the extra height a taller panel adds. + +## Comparing + +The pictures are the same size, so a difference is the two renderers, not the crop: + +``` +magick compare -metric RMSE examples/rendering/reference/reflections.png examples/rendering/viewport/reflections.png null: +magick examples/rendering/reference/reflections.png examples/rendering/viewport/reflections.png +append side-by-side.png +``` + +The scenes are built by `examples/tools/make_rendering_parity.py`, run the same way: + +``` +build/Aztek/AppRun --batch --script examples/tools/make_rendering_parity.py +``` + +## What the viewport does + +- Screen-space reflections march the view's own colour and depth for objects; the sky dome stands in where the view + shows nothing to reflect. +- The widest flat mesh at the ground plane is drawn a second time mirrored below it; the floor reads that image, so + it reflects the underside of what stands on it, which a screen-space march cannot see. +- Metals and dielectrics blur their reflection with their roughness. +- Glass is drawn solid and taken apart in the post pass: the scene is drawn once more without its transmissive + surfaces, and each glass pixel reads that image bent out towards the rim and tinted by its transmission colour. + +## Known gaps + +- A reflection of something the view does not show anywhere falls back to the sky; the Render View sees it. +- The reflection image is low-passed and copied down a mip chain; the gather samples a level from the roughness, so a + speckle is spread rather than shown. The planar and screen-space tiers share one brightness and the same filtered + copy, and their weights sum to one. +- The viewport's planar reflection of a standing sphere is smaller and sharper than the Render View's soft full one. +- Only the widest flat mesh at the world's ground is mirrored. Sloped or raised reflecting planes use the + screen-space march. +- Aztek's standard surface has no transmission depth. The distance the refraction lookup travels stands in for it, and + the glass is bent as a lens rather than traced through its back surface. +- The viewport does not draw the sky dome as a background; it lights and reflects from it, so the HDRI scene's sky is + black behind the objects where the Render View shows it. +- Harold's reflection off one large single-face floor reflects the floor itself; the scenes give their floors + subdivisions so the reference shows the reflection it should. +- At the same focal length the viewport frames about 12% tighter than the Render View, seen when the two pictures are + overlaid. diff --git a/tools/render_parity/capture.sh b/tools/render_parity/capture.sh new file mode 100755 index 00000000..11a5a924 --- /dev/null +++ b/tools/render_parity/capture.sh @@ -0,0 +1,36 @@ +#!/usr/bin/env bash +# Renders every lighting parity scene both ways and keeps the pictures for comparison: +# examples/rendering/reference/.png the Render View's path (Harold) +# examples/rendering/viewport/.png the realtime viewport, cropped to the same aspect +# Usage: tools/render_parity/capture.sh [build/Aztek/AppRun] [scene ...] +# Needs a display (Xvfb is enough) and ImageMagick. Runs from anywhere; paths are taken from the repository root. +set -euo pipefail +cd "$(dirname "$0")/../.." +root=$(pwd) +app=${1:-build/Aztek/AppRun} +case "$app" in /*) ;; *) app="$root/$app" ;; esac +[ -x "$app" ] || { echo "no application at $app (build it first)"; exit 1; } +shift || true +command -v magick >/dev/null && im=magick || im=convert + +scenes=("$@") +if [ ${#scenes[@]} -eq 0 ]; then + scenes=(reflections metal_roughness_sweep dielectric_glass tinted_glass emissive_object area_lights environment_hdri checker_sphere) +fi + +mkdir -p examples/rendering/reference examples/rendering/viewport +work=$(mktemp -d "${TMPDIR:-/tmp}/aztek_parity.XXXXXX") +trap 'rm -rf "$work"' EXIT +export XDG_CONFIG_HOME="$work/config" XDG_DATA_HOME="$work/data" + +for name in "${scenes[@]}"; do + scene="examples/rendering/$name.ma" + echo "== $name" + "$app" -render -s 1 -cam shotCam -x 640 -y 360 -rd "$root/examples/rendering/reference" -im "$name" -of png "$root/$scene" >/dev/null + "$app" --script "$root/tools/render_parity/viewport.py" --viewport-screenshot "$work/$name.raw.png" "$root/$scene" >/dev/null + read -r w h < <("$im" identify -format '%w %h\n' "$work/$name.raw.png") + ch=$(( w * 9 / 16 )) + "$im" "$work/$name.raw.png" -gravity center -crop "${w}x${ch}+0+0" +repage -resize 640x360\! "examples/rendering/viewport/$name.png" + echo " reference/$name.png viewport/$name.png" +done +echo "done" diff --git a/tools/render_parity/motion_capture.py b/tools/render_parity/motion_capture.py new file mode 100644 index 00000000..b82c8958 --- /dev/null +++ b/tools/render_parity/motion_capture.py @@ -0,0 +1,99 @@ +"""A moving check of the realtime viewport: one session, every feature on, four camera passes. + +Run it with the app: + + MOTION_OUT=/tmp/aztek_motion build/Aztek/AppRun --script tools/render_parity/motion_capture.py \ + examples/rendering/reflections.ma + +It turns on Realtime's lights, shadows, ambient occlusion, bounce light, textures and depth of field, then writes: + + orbit.####.png a full 360-degree turntable at constant speed + dolly.####.png a dolly from far away to close and back, with the focus tracking the subject + sweep.####.png a low sweep from the lit side to the dark side, so the terminator crosses the spheres + still.####.png twelve frames of an unmoving camera; any difference between them is temporal instability + +All but the last use keyframed cameras and the app's own playblast, so the motion is smooth and one launch serves the +whole pass. The frames are the viewport size at 100 percent. Hide the grid and the ornaments: they are guides, and at +grazing angles the grid's smooth lines can read over a sphere, which is a display layer and not the shaded picture. +""" +import os +import maya.cmds as cmds + +OUT = os.environ.get("MOTION_OUT", "/tmp/aztek_motion") +os.makedirs(OUT, exist_ok=True) + +panel = cmds.playblast(q=True, activeEditor=True) +cmds.modelEditor(panel, edit=True, displayLights="all", shadows=True, ambientOcclusion=True, + bounceLight=True, depthOfField=True, displayTextures=True, grid=False) +state = { + "displayLights": cmds.modelEditor(panel, q=True, displayLights=True), + "shadows": cmds.modelEditor(panel, q=True, shadows=True), + "ambientOcclusion": cmds.modelEditor(panel, q=True, ambientOcclusion=True), + "bounceLight": cmds.modelEditor(panel, q=True, bounceLight=True), + "depthOfField": cmds.modelEditor(panel, q=True, depthOfField=True), + "displayTextures": cmds.modelEditor(panel, q=True, displayTextures=True), + "grid": cmds.modelEditor(panel, q=True, grid=True), +} +print("MOTION FEATURES", state) + + +def make(name, pos, focus): + made = cmds.camera(n=name, focalLength=42) + tr = made[0] if isinstance(made, (list, tuple)) else made + sh = made[1] if isinstance(made, (list, tuple)) and len(made) > 1 else tr + "Shape" + pivot = cmds.group(em=True, n=name + "Pivot") + cmds.move(0, 1.5, 0, pivot) + cmds.parent(tr, pivot, r=True) + cmds.move(pos[0], pos[1], pos[2], tr, os=True, r=True) + cmds.aimConstraint(pivot, tr, aim=(0, 0, -1), u=(0, 1, 0)) + cmds.setAttr(sh + ".depthOfField", 1) + cmds.setAttr(sh + ".fStop", 1.4) + cmds.setAttr(sh + ".focusDistance", focus) + cmds.lookThru(tr) + return tr, sh, pivot + + +def play(stem, last): + cmds.playbackOptions(min=1, max=last) + path = os.path.join(OUT, stem) + cmds.playblast(st=1, et=last, f=path, fmt="image", c="png", v=False, fo=True, p=100, showOrnaments=False) + print("MOTION WRITTEN", path) + + +# (a) Full 360 orbit at constant speed. +N = 90 +tr, sh, pivot = make("orbitCam", (0, 2.2, 12), 12.0) +cmds.setKeyframe(pivot, at="ry", t=1, v=0) +cmds.setKeyframe(pivot, at="ry", t=N + 1, v=360) +cmds.keyTangent(pivot, at="ry", itt="linear", ott="linear") +play("orbit", N) + +# (b) Dolly from very distant to close and back, focus tracking the subject. +N = 90 +tr, sh, pivot = make("dollyCam", (0, 2.2, 60), 60.0) +cmds.setKeyframe(tr, at="tz", t=1, v=60) +cmds.setKeyframe(tr, at="tz", t=45, v=8) +cmds.setKeyframe(tr, at="tz", t=N + 1, v=60) +cmds.keyTangent(tr, at="tz", itt="linear", ott="linear") +cmds.setKeyframe(sh, at="focusDistance", t=1, v=60) +cmds.setKeyframe(sh, at="focusDistance", t=45, v=8.3) +cmds.setKeyframe(sh, at="focusDistance", t=N + 1, v=60) +cmds.keyTangent(sh, at="focusDistance", itt="linear", ott="linear") +play("dolly", N) + +# (c) Low sweep from the lit side to the dark side, so the terminator crosses the spheres. +N = 90 +tr, sh, pivot = make("sweepCam", (0, 0.1, 11), 11.0) +cmds.setKeyframe(pivot, at="ry", t=1, v=0) +cmds.setKeyframe(pivot, at="ry", t=N + 1, v=180) +cmds.keyTangent(pivot, at="ry", itt="linear", ott="linear") +play("sweep", N) + +# (d) A still camera for twelve frames: any change here is temporal instability, not motion. +tr, sh, pivot = make("stillCam", (0, 2.2, 12), 12.0) +last = 12 +cmds.playbackOptions(min=1, max=last) +cmds.playblast(st=1, et=last, f=os.path.join(OUT, "still"), fmt="image", c="png", v=False, fo=True, p=100, showOrnaments=False) +print("MOTION WRITTEN", os.path.join(OUT, "still")) + +print("MOTION DONE") diff --git a/tools/render_parity/viewport.py b/tools/render_parity/viewport.py new file mode 100644 index 00000000..6ee2813e --- /dev/null +++ b/tools/render_parity/viewport.py @@ -0,0 +1,8 @@ +"""Sets the view the parity capture takes: through the scene's shotCam, with the scene's lights and shadows. +Run by tools/render_parity/capture.sh with --viewport-screenshot, which takes the picture 1500 ms after start-up. +""" +import maya.cmds as mc + +mc.lookThru("shotCam") +panel = mc.playblast(q=True, activeEditor=True) +mc.modelEditor(panel, edit=True, displayLights="all", shadows=True)