AB4D Forum
Apply PixelEffect to VertexColorMaterial - Printable Version

+- AB4D Forum (https://forum.ab4d.com)
+-- Forum: Products Forums (https://forum.ab4d.com/forumdisplay.php?fid=4)
+--- Forum: Ab3d.DXEngine (https://forum.ab4d.com/forumdisplay.php?fid=11)
+--- Thread: Apply PixelEffect to VertexColorMaterial (/showthread.php?tid=4064)



Apply PixelEffect to VertexColorMaterial - leonardo - 12-06-2017

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


RE: Apply PixelEffect to VertexColorMaterial - abenedik - 12-07-2017

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.


RE: Apply PixelEffect to VertexColorMaterial - leonardo - 12-07-2017

Thank you for your answer.


RE: Apply PixelEffect to VertexColorMaterial - leonardo - 01-26-2018

Any news about this feature?

Thank you
Leonardo


RE: Apply PixelEffect to VertexColorMaterial - abenedik - 01-29-2018

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.


RE: Apply PixelEffect to VertexColorMaterial - leonardo - 01-31-2018

Thank you for your answer.
Could you give me some info about PBR materials? Maybe can be useful for my project.

Thank you
Leonardo


RE: Apply PixelEffect to VertexColorMaterial - abenedik - 01-31-2018

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)


RE: Apply PixelEffect to VertexColorMaterial - SLH - 02-05-2018

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


RE: Apply PixelEffect to VertexColorMaterial - abenedik - 02-12-2018

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.