playcanvas / playcanvas/engine

Custom material assets support in Engine and Editor

Open
#4,536 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

area: graphics enhancement
Dominant language
JavaScript
Stars
16.8k
Forks
2k
Avg merge
4h 32m
Merged PRs (30d)
222

Description

Hey PlayCanvas team, I'd like to propose a feature that I think will greatly benefit everyone working with the PlayCanvas engine.
At the moment there is no straightforward way of setting up and using custom materials inside a project. One can inherit from pc.Material or pc.StandardMaterial and create pretty much whatever custom material one needs.
The only problem is that you cannot save them as assets and edit their parameters using the Editor like one does with the standard material, you have to create scripts, attach them to entitites inside the scene and use their attributes to be able to tweak the material parameters.
I think the ability to save your custom materials as assets/resources, tweak them inside the Editor and apply them to any renderable should be one of the top features of any game engine.
Most other known game engines like Unity, Unreal, Godot, Babylon.js offer this feature out of the box and it would be a really big win if PlayCanvas would offer this too. The standard material is amazing but in a lot of cases developers need to create their own to fit their needs and the artists should have an easy straightforward way of tweaking those.

I don't have a really good understanding of the engine but I believe this support can be achieved relatively easy (complexity wise, although I might be totally wrong) from a high level perspective:

  1. on the engine side treat materials somewhat like scripts, register them to a material registry so they can be instantiated using a unique name
  2. extend the pc.Material class with serializing and deserializing methods that can be overriden in child classes
  3. make JsonStandardMaterialParser more generic. Based on the raw json data it receives (could contain a materialType field with the unique name registered at step 1) it should determine the type of material and instantiate from material registry, it would then use the overriden deserialize method from the custom material to set the parameters from the raw json data.
  4. On the Editor side use the material asset raw json data to tweak the materials. Make the material inspector work with any custom material by treating all materials in a generic way (editing a list of material parameters) and don't assume it's going to be a StandardMaterial.

This may be a bit oversimplified, I know it's not a small feature and lot more thought should be put into designing the API and making sure the standard material is easily extendable and that at the same time one can start just as easily with a material from scratch.

I hope PlayCanvas team and the community can agree on the benefits of this feature. This is a feature that we sorely miss on our project and I'll gladly work closely with you guys to design, implement and add a PR on the engine side for this if you believe this would be a great addition to PC.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading pc.Material, pc.StandardMaterial, and JsonStandardMaterialParser to understand current material creation and serialization. Then inspect the Editor material asset and material inspector behavior described in the issue. Done means custom material assets can be saved, edited in the Editor, and applied to renderables without assuming StandardMaterial.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
game-dev, tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.