c# - Setting pixel shader uniform variable -
dummy question, guess. have custom shader looks this:
sampler2d inputtexture; float parameter1, parameter2 etc float4 main(float2 uv : texcoord) : color { float4 result = blah-blah-blah calculations using parameter1, parameter2 etc. return result; }
i'm trying use via wrapper looks this:
class myshadereffect : shadereffect { private pixelshader _pixelshader = new pixelshader(); public readonly dependencyproperty inputproperty = shadereffect.registerpixelshadersamplerproperty("input", typeof(myshadereffect), 0); public myshadereffect() { _pixelshader.urisource = new uri("myshader.ps", urikind.relative); this.pixelshader = _pixelshader; this.updateshadervalue(inputproperty); } public brush input { { return (brush)this.getvalue(inputproperty); } set { this.setvalue(inputproperty, value); } } }
so, question is: how set shader parameters c# program?
it's right there in documentation of shadereffect
class. need create dependency properties every parameter. example:
class myshadereffect { public myshadereffect() { pixelshader = _pixelshader; updateshadervalue(inputproperty); updateshadervalue(thresholdproperty); } public double threshold { { return (double)getvalue(thresholdproperty); } set { setvalue(thresholdproperty, value); } } public static readonly dependencyproperty thresholdproperty = dependencyproperty.register("threshold", typeof(double), typeof(myshadereffect), new uipropertymetadata(0.5, pixelshaderconstantcallback(0))); }
the 0
in pixelshaderconstantcallback
refers register use in hlsl:
float threshold : register(c0);
this way wpf knows update shader when property changes. it's important call updateshadervalue
in constructor pass value.
Comments
Post a Comment