google / filament

Filament is a real-time physically based rendering engine for Android, iOS, Windows, Linux, macOS, and WebGL2
https://google.github.io/filament/
Apache License 2.0
17.35k stars 1.83k forks source link

material properties only work with direct assignment (`=`) but not with compound-assignment (e.g.: `*=`) #7914

Open gibssa opened 3 weeks ago

gibssa commented 3 weeks ago

Describe the bug clipSpaceTransform won't compile at all in matc for a vertexDomain:device shader (docs, previous discussion).

To Reproduce

  1. git clone git@github.com:google/filament.git
  2. ./build.sh release matc
  3. Minimal shader test_direct_pixels.mat:
    
    material {
    name: TestDirectPixels,
    parameters: [
    ],
    requires : [
        uv0
    ],
    blending : transparent,
    vertexDomain : device,
    shadingModel : unlit
    }

vertex { void materialVertex(inout MaterialVertexInputs material) { material.clipSpaceTransform *= 0.3; } }

fragment { void material(inout MaterialInputs material) { prepareMaterial(material); vec2 uv = getUV0(); material.baseColor = float4(0.0, 0.1, 0.4, 0.4); } }

5. ```./out/cmake-release/tools/matc/matc --api=metal --platform=mobile --output=./test_direct_pixels.filamat ./test_direct_pixels.mat```
6. `matc` compilation fails:

➜ filament git:(main) ✗ ./out/cmake-release/tools/matc/matc --api=metal --platform=mobile --output=./test_direct_pixels.filamat ./test_direct_pixels.mat ERROR: Unable to parse vertex shader ERROR: test_direct_pixels.mat:15: 'clipSpaceTransform' : no such field in structure 'material' ERROR: test_direct_pixels.mat:15: '' : compilation terminated ERROR: 2 compilation errors. No code generated.

Could not compile material ./test_direct_pixels.mat



**Expected behavior**
`matc` compilation should work, though it may have broken [here](https://github.com/google/filament/blob/af2ecf201f5b9116cba84d0c6ca0593fae1d52f1/RELEASE_NOTES.md?plain=1#L421)?

**Screenshots**
N/A

**Logs**
(see Step 6 above)

**Desktop (please complete the following information):**
 - OS: macOS
 - GPU: MacBook Pro Nov 2023
 - Backend: Metal

**Smartphone (please complete the following information):**
 - Device: N/A (offline `matc`)
 - OS: N/A (offline `matc`)

**Additional context**
I'm looking to create a 2D quad, with 256 instances, and do efficient vertex transforms on the GPU.

Thanks as always team!
pixelflinger commented 2 weeks ago

note that

test_filamat --gtest_filter=\*.StaticCodeAnalyzerDirectAssignVertex

passes

pixelflinger commented 2 weeks ago

ah this looks like a bug in how we detect when a property is used. Currently you can't use *= you have to use =. It shouldn't be a problem because it's set to identity by default.

gibssa commented 2 weeks ago

ah this looks like a bug in how we detect when a property is used. Currently you can't use *= you have to use =. It shouldn't be a problem because it's set to identity by default.

Works! Thank you for the triage.