Apply PixelEffect to VertexColorMaterial
I need to apply PixelEffect to a VertexColorMaterial but this doesn't works.

// 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);

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:

float usedPixelSize;
Color4 usedPixelColor;

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

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

       usedPixelSize = lineMaterial.LineThickness;
       var diffuseMaterial = material as IDiffuseMaterial;

       if (diffuseMaterial != null)
           usedPixelColor = new Color4(diffuseMaterial.DiffuseColor, diffuseMaterial.Alpha);
           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.
Andrej Benedik
Thank you for your answer.

Forum Jump:

Users browsing this thread:
1 Guest(s)