1

I want to make object to become highlighted when selected in order to do this I need a custom shader that scales that renders the model outline - this part of the task I'm familiar with - XML3D provides a way to implement custom shader.

But the missing piece is having access to render pipeline: Its impossible to make nice highlighting without copying the model and painting it over old one or rendering the scene in two passes (postprocessing). Creating another model copy in the usual way (attaching new element to dom tree) won't solve the issue since I need also control scene blending.

How to I get it done with with xml3d? Is it possible without digging deep into the library?

gman
  • 100,619
  • 31
  • 269
  • 393
Xyz
  • 1,522
  • 17
  • 23

2 Answers2

1

In general there are four approaches to implement highlighting:

  1. you can exchange materials back and forth (not very efficient)
  2. you can use material overrides for highlighted objects, which will adapt one or more parameters of the current shading (e.g. emissive color)
  3. you can use a custom shader in combination with an arbitrary uniform attribute which indicates that the object should be highlighted. In the shader, you can adapt color and rendering based on the attribute. E.g. you could do a rim-highlighting or a wireframe rendering. Here is an example for a shader that colors an object if the uniform selected has a specific value. For instance:
    <mesh id="foo"> <data src="mesh-data.json"></data> <float name="selected">0</float> </mesh>
    To highlight this object: $("#foo float[name=selected]").text("1");
  4. you can adapt the rendering pipeline to render the highlighted object twice and blend it in various ways

If sufficient for your use-case, I would recommend approach 3, as it is not very intrusive. The interface for creating custom rendering pipeline is not yet very stable.

ksons
  • 183
  • 9
  • How can I set the "selected" value unifrom per model instance? So there would be no need for swapping shaders. – Xyz May 26 '15 at 14:21
  • I improved the answer, adding an example for this (3) – ksons May 27 '15 at 06:18
  • Thanks, but what about in case I use assets? In such case one must dig into hierarchy and put into the with proper name. There is a problem however - how one can now the assetdata name? If it is in extarnal file, and asset is instantianted using ? – Xyz Jun 22 '15 at 13:52
1

As ksons mentioned the render pipeline interface is undergoing some major changes right now, XML3D 4.8 is the last version that supports it in its current form. Version 5.0 will likely re-introduce it in a (hopefully) much improved form.

We use a custom render pipeline in one of our internal projects to draw a wireframe overlay onto selected models, I've posted a simplified version of this pipeline as a Gist for you to have a look at. Essentially it renders the scene using the standard internal render pass and then does a second pass to draw the highlighted objects in a crude wireframe mode without depth testing.

As I said this works in v4.8, if you need this functionality in v4.9 then please open an issue and I'll see about re-enabling it as a minor release.

csvurt
  • 236
  • 1
  • 2
  • How are things going with Custom render pipeline is it going to be the part of 5.0 release? – Xyz Oct 10 '15 at 17:22
  • 1
    Not officially, no. But I will work my way through the interface and make sure everything is available in the 5.0 release. So if you want to play around with it you can, and we'd love to get some feedback about what functionality is missing. The "improved form" had to be pushed back some but is still planned for a release in the near future. – csvurt Oct 12 '15 at 06:22
  • I need to implement SSAO shader and the higligthing i've mentioned, maybe more. I'm looking forward to any commits mentioning render pipeline modifications (as I understand it is supposed to don't work in 4.9). – Xyz Oct 13 '15 at 10:58
  • 1
    I've updated the section on custom render trees in the [Github wiki](https://github.com/xml3d/xml3d.js/wiki/Custom-RenderTrees-and-the-RenderInterface), you can also check out the develop branch as the necessary changes are now in there. If you find anything missing let us know! Just remember 5.0 is not backwards compatible with 4.9, you'll need to adapt your scenes [as described here](https://github.com/xml3d/xml3d.js/wiki/Migrate-to-XML3D-5.0) and/or using the [xml3d-4to5 script](https://github.com/xml3d/xml3d-4to5.js) with iojs. – csvurt Oct 13 '15 at 16:50
  • Thanks! I've got some problems using latest xml3d though. (The develop branch). I'm getting: "AssertionError: aspect cannot both be non-zero. at XML3D.extend.setFrustum (.../scripts/libs/xml3d-dev.js:19088:9) at Object.XML3D.createClass._updateFrustum (.../scripts/libs/xml3d-" I've cleaned view element to use default values (if any) for everything. – Xyz Oct 15 '15 at 19:08
  • 1
    Yeah sorry about that, we just caught this bug and a fix was pushed yesterday afternoon. Should be ok now. – csvurt Oct 16 '15 at 05:33