Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disallow renderables with missing required attributes #1279

Closed
bejado opened this issue Jun 10, 2019 · 9 comments
Closed

Disallow renderables with missing required attributes #1279

bejado opened this issue Jun 10, 2019 · 9 comments
Assignees
Labels
enhancement New feature or request

Comments

@bejado
Copy link
Member

bejado commented Jun 10, 2019

All lit materials implicitly require the tangents attribute. Not including tangents for lit renderables causes undefined behavior in OpenGL and a crash in Metal.

RenderableManager permits renderables to be created with missing required attributes; however, missing attributes are logged in two places:

  • RenderableManager::Builder::build
  • FRenderableManager::setMaterialInstanceAt

A better solution would be to somehow disallow renderables with insufficient attributes. Ideally, renderables should be immutable. This way, the checks at build and setMaterialInstanceAt could be promoted to errors.

@romainguy romainguy added the enhancement New feature or request label Jun 11, 2019
@prideout
Copy link
Contributor

Related PR is #1290

@prideout
Copy link
Contributor

Some questions arise when thinking about this:

  • Why do our renderables allow users to change out the VertexBuffer? The VertexBuffer defines which attributes are present so this makes validation complex. If Sceneform does not need this ability then we should consider removing it. Note that renderables also allow users to swap out materials.
  • Do all our backends have the ability to supply dummy attributes? In OpenGL you can provide a default value that is spread across all vertices using glVertexAttrib4f. This feature seems unavailable with Vulkan / Metal, although in theory you can set the stride to 0.
  • Which attributes should trigger actual errors when missing? The presence of tangents should perhaps be a hard requirement for lit variants, but our skinning+morphing variant uses 10 attributes (8 for morphing, 2 for skinning) and we should definitely not require users to supply all of these.

@bejado
Copy link
Member Author

bejado commented Jul 24, 2019

On point 2, the Metal backend can create a small zero-ed out "dummy" buffer for missing vertex attributes and use the MTLVertexStepFunctionConstant step function.

In order to do that, the backend needs to know which attributes are "expected" for a given program. I propose we add an AttributeBitset field to Program that gets set up by Filament. The backend can use it to determine which attributes are read from in the shader, but aren't provided by the renderable.

@prideout
Copy link
Contributor

See also #1663

@prideout
Copy link
Contributor

Let me add yet another bullet to my list:

  • Why do our renderables allow users to change the MaterialInstance? This causes the same validation issue that swapping out the VertexBuffer has. For example, Filament lets you switch from an unlit material to a lit material.

@romainguy
Copy link
Collaborator

It can be extremely useful if you want to change the visual state of an object. You could create a different renderable but this is much easier.

@prideout
Copy link
Contributor

Creating a new renderable would be super easy if we exposed a clone method. Also, users can always call setParameter on the material instance, the problem arises only when they want a drastic change like the shading model or set of attributes.

prideout added a commit that referenced this issue Sep 18, 2019
To prevent an excess of variants, sometimes our vertex shaders declare
inputs that they never read from. For example, our skin-and-morph
variant might never read from the skinning attribute, but still declares
the input.

This PR is a sister to #1663, which is a fix for #1525.

See also #1279.
prideout added a commit that referenced this issue Sep 19, 2019
To prevent an excess of variants, sometimes our vertex shaders declare
inputs that they never read from. For example, our skin-and-morph
variant might never read from the skinning attribute, but still declares
the input.

This PR is a sister to #1663, which is a fix for #1525.

See also #1279.
@pixelflinger
Copy link
Collaborator

I agree with @prideout my original intent was for all these things to be immutable.

@prideout
Copy link
Contributor

prideout commented Jul 7, 2021

@pixelflinger I complained about mutability in 2019 but unfortunately the ship has already sailed. We now have several users who swap out materials nowadays. In fact we made VertexBuffer more mutable with the advent of BufferObject, in order to satisfy glTF morphing requirements.

Anyway: I feel this bug is obsolete and that we can close it.

@bejado bejado closed this as completed Jul 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants