AB4D Forum

Full Version: Apply PixelEffect to VertexColorMaterial
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello,
I need to apply PixelEffect to a VertexColorMaterial but this doesn't works.

Code:
// Create pixel effect
var _pixelEffect = dxViewportView.DXScene.DXDevice.EffectsManager.GetEffect<Ab3d.DirectX.Effects.PixelEffect>();
_pixelEffect.PixelSize = 2;

// Create vertex color material
var vertexColorMaterial = new Ab3d.DirectX.Materials.VertexColorMaterial()
{
 PositionColors = positionColors, // positions of my model
 Effect = _pixelEffect
};

System.Windows.Media.Media3D.Material myMaterial= new DiffuseMaterial(Brushes.Red);
myMaterial.SetUsedDXMaterial(vertexColorMaterial);

Is this a bug?
Thank you
Each Effect can "understand" only properties that it is designed for. For example, LineThickness property is ignored by StandardEffect. Also, properties defined by VertexColorMaterial are not read by PixelEffect.

Behind the scenes, the task of the Effect is to setup vertex, geometry and pixel shaders that will render the effect. Each used shader also have a fixed number of "input parameters" that are defined in constant buffers. Effect reads the properties from Material object and set the fields in the constant buffers.

Here is a code snippet from PixelEffect.ApplyMaterial method that shows part of this process:

Code:
float usedPixelSize;
Color4 usedPixelColor;

var pixelMaterial = material as IPixelMaterial;
if (pixelMaterial != null)
{
   usedPixelColor = pixelMaterial.PixelColor;
   usedPixelSize = pixelMaterial.PixelSize;
}
else
{
   var lineMaterial = material as ILineMaterial;

   if (lineMaterial != null)
   {
       usedPixelColor = lineMaterial.LineColor;

       usedPixelSize = lineMaterial.LineThickness;
   }
   else
   {
       var diffuseMaterial = material as IDiffuseMaterial;

       if (diffuseMaterial != null)
           usedPixelColor = new Color4(diffuseMaterial.DiffuseColor, diffuseMaterial.Alpha);
       else
           usedPixelColor = this.PixelColor;

       usedPixelSize = this.PixelSize;
   }
}

if (_pixelShaderConstantBufferData.LineColor != usedPixelColor)
{
   _pixelShaderConstantBufferData.LineColor = usedPixelColor;
   _deviceContext.UpdateSubresource(ref _pixelShaderConstantBufferData, _pixelShaderConstantBuffer);
}

As you can see the Effect is quite flexible and can get pixel color from IPixelMaterial, ILineMaterial or even IDiffuseMaterial.

But it cannot use PositionColors array because the shaders are not (yet) designed to support such property.


I guess that you would like to render many pixels where you will be able to define the color for each of the pixel.

This functionality is high on my todo list and will be provided in the future. In December 2017 I will not have time to implement that, but if you contact me in January 2018, I will try to find some time and prepare a pre-release version with this functionality for you.
Thank you for your answer.
Any news about this feature?

Thank you
Leonardo
Sorry, nothing new there.

I am currently working on some other feature (PBR materials). After this is complete I will try to implement PixelEffect with specified color for each pixel.
Thank you for your answer.
Could you give me some info about PBR materials? Maybe can be useful for my project.

Thank you
Leonardo
I am adding support for PBR (Physically-based rendering) materials - for metalness workflow.

This will allow you to use materials with:
- diffuse texture (base color / albedo) or color
- metalness texture or float value
- roughness texture or float value
- normal map (optional)
- environmental map (optional)
Hi.

I also would like to render point clouds with per-pixel colouring.

I'm thinking the updates to PixelEffect will allow me to do this?  When do you think this feature will roll out?

cheers

Simon
Leonardo, I have just sent a new pre-release version to you with per-pixel color support.

I also plan to add support for per-pixel size.