I’m using the Engine version, latest. Things work great, and what’s documented is very helpful. But it seems like there’s not much documentation for not using your Editor. Had to search for and figure out other code examples, which is slow and tedious.
I’m trying to add glow to a model. The basic cube.
var cube = new pc.Entity('cube');
cube.addComponent('model', {
type: 'box',
});
The Earth example is way too much stuff for me. The Halo uses a texture, which I’m not interested in. I figured out how to add the Bloom posteffect, but not how to apply it to one model. Would that be possible? Toggling that on and off. I couldn’t figure out how to just add some glow to the model’s material, just through tinkering in the console. Maybe like an Emissive color. Tinkering with that property of the material did nothing.
Am I learning PlayCanvas Engine the wrong way? Is there anywhere that explains how to achieve this very basic need? It’s not encouraging that all the Tutorials are for the Editor, without some tips for converting to Engine use.
EDIT: If this helps anyone, a very simple example of adding a simple shader to a model/material is in the github toon example.
The tutorials on the PlayCanvas website are for the editor as it’s there to support the PlayCanvas service (which generates revenue) rather than the engine directly. That said, most of them can be used with engine directly if you take into account what the scripting system is referencing through the attributes.
Fundamentally, that is all it’s really doing 90% of the time (there’s some more features such as baking lightmaps, building DDS skyboxes, converting FBX to it’s JSON format etc that is done by the service on the server).
The tricky bit is how to get the array of assets for textures without using the editor. If you are using the engine directly, I would assume there is a reference to those assets somewhere that you can use to create the array. Or use the asset registry to find them.
You can also get the attribute name if you hover over a field in the editor to bring up the tooltip which should contain the name of the attribute in the engine:
Thanks for responding so quickly. I understand the editor is the business part, and it’s great for what it does. But it’s not suitable for all cases, so it’s confusing to be directed to it.
I saw those scripts you linked, but I don’t want to apply a new material to my model. I just want to highlight it, keeping the previous material intact. I had the impression I can just apply a shader, not affecting the entire material (like Bloom does), but I guess that’s not the case.
I don’t see what textures has to do with it. I am not interested in applying a texture.
Interesting tip about the attributes for the engine in the editor!
TL;DR (Update first.)
I was lost at the pc.Material API page, but then after searching in the engine examples, realized I can stumble on the pc.StandardMaterial API page which does have a bit of code to help. I got Emissive to work!
For the sake of clarification, is there a way to apply the Bloom posteffect to only my cube model? That would look more awesome than just Emissive.
I still wish the API pages were clear on which parts relate to which; the latter says “Extends: pc.Material”, but the former says nothing. Would be awesome if it said “Extended by: pc.StandardMaterial and pc.BasicMaterial.” And a bit more code samples in the API to clarify actual usage in Engine. It would be my pleasure to add the @see tag on Github, so the API has those clarifications and a link to the relevant Engine file. If that the devs would be interested in such edits.
Where I randomly stumbled on a code sample (which is oddly different from API sample, so which is the recommended standard?):
So, you’re saying I should be able to highlight a model by adjusting its Emissive? Can you provide a basic example of this? My code example is in the OP, nothing more. As basic as it gets. In console I tried tweaking a variety of properties such as:
The API reference is generated from the engine code docs so you could create a pull request for a file or two and see what the response is like.
Here’s an example to get the emissive to only apply to a single model even if another uses the same material asset: PlayCanvas | HTML5 Game Engine
I’m not sure about the bloom effect (as the example seems to be broken at the moment).
The glow effect on the Earth in the Planet Earth example is possible to only apply to a single model. Not 100% how to turn it on/off though Perhaps an extra param can be added to the shader to change the intensity of the effect?
Thanks for the extra info. The Emissive option is clear now. To add Bloom to your camera I just use this code (notice I put the script file in my local directory):
app.assets.loadFromUrl('scripts/extras/posteffects/posteffect-bloom.js', 'script',
function (err, asset) {
var bloom = new pc.BloomEffect(app.graphicsDevice);
bloom.bloomThreshold = 0.1;
camera.camera.postEffects.addEffect(bloom);
});
Does anybody know how to apply Bloom to a single model??
That’s what I’m wondering. I’m too inexperienced to have enough clues about this. Does anybody know how to take the shader from Bloom and apply it for a specific model?
Specifically to you yaustar, any idea why I can change ‘material_emissive’, but when I try to change any other value, say ‘material_emissiveIntensity’, it doesn’t work? I made sure I got the name right from the github.
I’ve gained moderate success in applying a “Glow” shader to a model. Had to mix and match from forums, github, threejs + example project for Glow. It’s not working as expected - lacks the opacity effect and camera movement affects it oddly - but it’s something. I’d appreciate any tips! Now, can I add it to the StandardMaterial as a .glow property? It doesn’t make sense to lose all other material properties for one.
Following up on the shader question, I found some examples, but I’m failing at applying any of them. A rather simple one has some undefined variables that I can’t figure out how to define with playcanvas. normalMatrix, normal, and viewVector are all a mystery to me. How would I define them? Here’s the vertexshader that’s bugging:
I think a BASIC post processing glow shader should be taught in a demo and have it run withing minutes, the earth shader is too complicated and should be featured after basic glow… despite cg code floating for decades to do this…it requires setting up the chunks so that playcanvas could speak to these available shaders not to mention having to dust up the blue, orange and red gl books so one can relearn all the crinngey asm goodness, which could take hours, days or even weeks, if you are not properly guided
For the initial question, indeed a fullscreen post process effect will affect all rendered objects. Right now all post process effects created are being added to the PostEffectQueue.
That is automatically being added as layer after all layers, minus the UI, has finished rendering. So one way to have a pp effect affect only certain models is to change the order of when the effect is rendering. Most easiest way I think would be to reorder the PostEffectQueue layer to render after your custom layer rendering the models in question.
I’m trying to do this same thing… in that I’d like just one model to have a bloom effect, not the entire scene. Are you suggesting this change in the actual engine code itself?
I realize this is an old thread; is there anything new that has happened in the engine since then that might help handle this?