Commit Graph

81 Commits

Author SHA1 Message Date
bjorn 6a669bd967 rm var shader macro;
It is no longer necessary, and wasn't widely used/documented.
2024-02-21 10:28:30 -08:00
bjorn 64e253a8ef mv logo shader to nogame bundle; 2024-02-21 10:21:42 -08:00
bjorn 81ef58d032 Use push constant instead of BaseInstance for DrawID;
This is a little slower, but means indirect draws can use Transform and Color.

There are other solutions for this.  For example LÖVR could reserve
BaseInstance and use a compute shader to rewrite indirect buffers.

For now we choose to be correct and a little slower.
2024-02-21 10:21:42 -08:00
bjorn 875a7f8237 Shader rework;
- Undeprecate ShaderType (it's good actually, kinda like a pipeline bind
  point and more specific than having lovr trying to make sense of a
  random set of stages).
- Use a default uniform block instead of push constants.  The Constants
  macro now maps to a uniform block declaration.
- It is no longer possible to create a shader by giving a single
  DefaultShader string (you can still give a per-stage DefaultShader
  though).
- lovr.graphics.compileShader now takes all stages instead of a single
  stage.  In general we need all stages when compiling GLSL because
  default uniforms require linking across stages.
2024-02-21 10:21:41 -08:00
bjorn 40d85c6a16 Model uses sn10x3 normals and tangents;
This shaves 20 bytes off of each model vertex, or around 40% savings.
The vertex size is also a power of two which results in extreme amounts
of style points.
2024-01-20 17:39:36 -08:00
bjorn 1b1bc182bf Fix cubemap orientation;
+Z is the front face in a cubemap, not -Z.  Currently cubemap faces are
flipped in both the X and Z directions.

Some kind of flip is required because cubemaps use a left-handed
coordinate space instead of lovr's/vulkan's right-handed coordinate
space.

Equirect does not need any changes.
2024-01-06 13:58:14 -08:00
bjorn e0e1bc68f9 Add support for cubemap arrays;
- Cubemaps can have any layer count that is a multiple of 6.
- A cubemap with more than 6 layers will be a cubemap array image view.
  - This isn't perfect because it conflates regular cubemaps with
    6-layer cubemap arrays.
- Enable the vk feature, handle the spv feature, add getPixel helper.
2023-11-10 11:15:16 -08:00
bjorn eefc89909e Fix bitangent sign;
Really gotta compress ModelVertex at some point.
2023-11-09 16:50:52 -08:00
bjorn 7486108462 Add gammaToLinear and linearToGamma shader helpers; 2023-09-28 05:10:26 -07:00
bjorn 73b1b951f5 Model:clone has separate blend shape state; 2023-09-24 23:51:42 -07:00
bjorn 003d69ea94 Make Surface more flexible;
- Add newSurface, which returns a "blank" surface, allowing you to set
  your own properties.
- Add finalizeSurface, which sets computed surface properties and clamps
  values to prepare for lighting.
- Add applyMaterial, which takes all of the properties in the material
  and applies them to a surface
- Add helper functions for getting properties from the Material, which
  combine scalar factors and texture samples while respecting shader
  flags:
  - getMaterialBaseColor
  - getMaterialEmissive
  - getMaterialMetalness
  - getMaterialRoughness
  - getMaterialOcclusion
  - getMaterialClearcoat
  - getMaterialClearcoatRoughness
- Add getDefaultSurface, which returns what initSurface would result in
  today, deprecating initSurface.
2023-08-02 18:11:36 -07:00
bjorn 339e6cf94b Shrink DrawData from 128 to 64 bytes!;
- Last row of transform matrix is unused, make it 4x3
  - Requires funny row-major packing due to vec3 std140 padding.
  - Teach spirv parser to tolerate non-square matrix types, though
    they aren't supported anywhere else yet.
- Compute cofactor in shader for normal matrix, ALU is free,
  optimize out many terms, rm maf_cofactor.
- Take out complex UBO alignment logic since stuff is PO2 these days.

This was a common bottleneck for some workloads, so there are measurable
performance gains (up to 2x faster pass submission on CPU).  GPU time is
identical, at least on desktop.
2023-08-01 18:57:09 -07:00
bjorn 98729912a8 Add GL_EXT_samplerless_texture_functions; 2023-06-24 14:00:22 -07:00
bjorn 116d14cdf8 Details; 2023-06-24 11:26:09 -07:00
bjorn 97cc7d9137 Fix issue with blend shape compute shader;
It was only copying the raw vertex data for the first blend shape,
not the first blend shape in each group.
2023-06-20 21:42:44 -07:00
bjorn 4ec065757d Optimize blendshapes;
To initialize the vertices to their default state, it's way faster to
use a branch in the compute shader rather than using a copy.
2023-06-17 17:14:00 -07:00
bjorn 027dd0563b Fix seam in equirect shader; 2023-05-10 18:14:09 +01:00
bjorn 20a331cb93 Fix equirect shader orientation; 2023-05-10 18:14:09 +01:00
bjorn 452ee5c7c6 Pass rework;
Pass stores draw commands rather than sending them to Vulkan
immediately.

The main motivation is to allow more flexibility in the Lua API.  Passes
are now regular objects, aren't invalidated whenever submit is called,
and can cache their draws across multiple frames.  Draws can also be
internally culled, sorted, and batched.

Some API methods (tallies) are missing, and there are still some bugs to
fix, notably with background color.
2023-05-02 00:06:01 -07:00
bjorn f98306e786 rm transfer passes; rm Tally for now;
- Add Buffer:newReadback
- Add Buffer:getData
- Buffer:getPointer works with permanent buffers
- Buffer:setData works with permanent buffers
- Buffer:clear works with permanent buffers
- Add Texture:newReadback
- Add Texture:getPixels
- Add Texture:setPixels
- Add Texture:clear
- Add Texture:generateMipmaps
- Buffer readbacks can now return tables in addition to Blobs using Readback:getData

Tally is coming back soon with an improved API, it's temporarily removed
since it made the transfer rework a bit easier.

Note that synchronous readbacks (Buffer:getData, Texture:getPixels)
internally call lovr.graphics.submit, so they invalidate existing Pass
objects.  This will be improved soon.
2023-04-29 18:31:03 -07:00
bjorn 6862b8c970 Change cofactor/normal matrix to mat3;
This means per-draw uniform data is 128 bytes now!
2023-04-27 20:22:31 -07:00
bjorn 8f654ed408 Simplify fill shaders;
Now there's 2 instead of 3!  Behavior is the same, fill goes
layer-by-layer onto each view until either the texture or canvas run out
of layers.
2023-04-26 22:18:06 -07:00
bjorn 6c252a47b8 Don't declare builtin flags in compute shaders;
They aren't used, and increase file size and clutter up disassembly.
2023-04-05 21:53:39 -07:00
bjorn 747c7fdddf Optimize blend shape shader;
This is ~20% faster, I think it's because all the SSBO stores are
"batched" at the end.
2023-04-05 21:53:39 -07:00
bjorn a2b12c9e7c Vertex tangents don't require normalMap flag anymore; 2023-03-31 19:23:20 -07:00
bjorn ff10461e69 Reduce blend shape chunk size from 128 to 64; 2023-03-31 18:45:16 -07:00
bjorn f56b48b3a7 Blend shapes and skinning work at the same time; 2023-03-31 18:45:16 -07:00
bjorn 4a6de6caf5 Write blend shape compute shader; Bugfixes; 2023-03-31 18:45:16 -07:00
bjorn 530db8c7f8 WIP blend shape compute dispatch; 2023-03-31 18:45:16 -07:00
bjorn 6de1c624b4 Scope shader macros by the stage they're valid in;
Leads to better error messages if you try to use e.g. DefaultPosition in
a fragment shader.
2023-03-02 19:03:15 -08:00
bjorn 7027defe3c rm attachmentCount shader flag;
It doesn't work as intended (due to glslang issues?).  The current way
to write a shader that uses multiple attachments is to declare multiple
output variables, which is a little better because you can name them
however you want and customize the type.

It would be nice to be able to support a "void" entrypoint for multiple
attachments so you don't need to awkwardly return the first target's
color, but I can't find a way around this right now.
2023-02-05 16:04:17 -08:00
bjorn 5e2b44ad08 Fix stereo mirror window;
For some reason this was rendering both layers of a multi-layer
texture all squished.  I think it was supposed to just render the
first layer.
2022-11-07 17:14:27 -08:00
bjorn ee3cc30851 Animator renormalizes quantized weights;
It would be nice to do this in the importer, but it was 50+ lines and
was really tricky to write without reading from uncached GPU-mapped
memory.  Instead, it's 1 line here.

I hope zero-weight vertices aren't a thing?
2022-10-03 01:29:01 -07:00
bjorn cd04060467 Use correct roughness for indirect specular lighting; 2022-09-23 23:58:47 -07:00
bjorn d905b649a4 Lighting helper fixes; 2022-09-23 23:44:31 -07:00
bjorn ef407fd564 Add var shader helper;
Now you can write var(0) instead of layout(set = 2, binding = 0).
The advantage is less typing and resilience in the event that the
default set changes.
The disadvantage is that now you can't use var.
2022-09-22 20:44:06 -07:00
bjorn 72334cc1f2 Fix cubemaps being horizontally flipped; 2022-09-20 22:17:58 -07:00
bjorn 28869431fb Fix stereo mirror window; 2022-09-15 20:45:26 -07:00
bjorn 1dd737d8a4 Make the logo a default shader;
Improves build system, improves filesize, seemingly improves startup time
2022-09-13 17:36:10 -07:00
bjorn d8c6c47e00 Add normal DefaultShader;
It's a pretty normal shader.
2022-09-10 11:07:55 -07:00
bjorn 8697466009 Shader flag adjustments;
- glowTexture is on by default, but still requires the glow flag.
- occlusionTexture is named ambientOcclusion, and is on by default,
  but is still not used by any builtin shaders/helpers.
2022-09-02 15:33:18 -07:00
bjorn 0b0faf6dc6 DefaultColor respects flag_colorTexture; 2022-09-02 15:07:45 -07:00
bjorn d513b98ce2 Fix cubemap shader; 2022-08-26 22:22:37 -07:00
bjorn 085550da33 Tonemapping, I guess; 2022-08-26 10:34:32 -07:00
bjorn ad7c854571 Add evaluateSphericalHarmonics helper; 2022-08-26 10:28:43 -07:00
bjorn 70aff00a11 Rename shader flags; Add color flags; 2022-08-26 10:28:23 -07:00
bjorn 5a2fe54c04 Improve Pass:fill;
It can now fill an array texture to a multiview pass, copying to
the corresponding layers.
2022-08-26 09:57:51 -07:00
bjorn ede1036694 Temporary Passes;
Sigh, back to getPass.  I don't even know at this point.  Basically now
that we came up with a half-solution for temp buffers, it makes sense to
apply this to passes as well, since we aren't going with the workstream
idea and temp passes are more convenient than retained passes.
2022-08-25 21:57:15 -07:00
Josip Miskovic 11f2d052ef Skybox view matrix includes local transform 2022-08-18 09:04:42 -07:00
bjorn 51312f4704 Add attachmentCount/defaultPointSize specialization constants; 2022-08-14 09:43:00 -07:00