本文整理汇总了C#中Material.GetBestTechnique方法的典型用法代码示例。如果您正苦于以下问题:C# Material.GetBestTechnique方法的具体用法?C# Material.GetBestTechnique怎么用?C# Material.GetBestTechnique使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Material
的用法示例。
在下文中一共展示了Material.GetBestTechnique方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OnMaterialRender
protected override void OnMaterialRender( uint passId, Material material, ref bool skipPass )
{
base.OnMaterialRender( passId, material, ref skipPass );
//update material scheme
{
string materialScheme = RendererWorld.Instance.DefaultViewport.MaterialScheme;
foreach( CompositionTechnique technique in Compositor.Techniques )
{
foreach( CompositionTargetPass pass in technique.TargetPasses )
pass.MaterialScheme = materialScheme;
if( technique.OutputTargetPass != null )
technique.OutputTargetPass.MaterialScheme = materialScheme;
}
}
const int rt_brightPass = 800;
const int rt_bloomBlur = 700;
const int rt_bloomHorizontal = 701;
const int rt_bloomVertical = 702;
const int rt_targetOutput = 600;
//Skip bloom passes if bloom switched off
if( BloomScale == 0 )
{
if( passId == rt_brightPass || passId == rt_bloomBlur || passId == rt_bloomHorizontal ||
passId == rt_bloomVertical )
{
skipPass = true;
return;
}
}
// Prepare the fragment params offsets
switch( passId )
{
//BrightPass
case rt_brightPass:
{
Vec2[] sampleOffsets = new Vec2[ 16 ];
Vec2i textureSize = Owner.DimensionsInPixels.Size;
CalculateDownScale4x4SampleOffsets( textureSize, sampleOffsets );
//convert to Vec4 array
Vec4[] vec4Offsets = new Vec4[ 16 ];
for( int n = 0; n < 16; n++ )
{
Vec2 offset = sampleOffsets[ n ];
vec4Offsets[ n ] = new Vec4( offset[ 0 ], offset[ 1 ], 0, 0 );
}
GpuProgramParameters parameters = material.GetBestTechnique().
Passes[ 0 ].FragmentProgramParameters;
parameters.SetNamedConstant( "brightThreshold", BloomBrightThreshold );
parameters.SetNamedConstant( "sampleOffsets", vec4Offsets );
}
break;
case rt_bloomBlur:
{
Vec2[] sampleOffsets = new Vec2[ 13 ];
Vec4[] sampleWeights = new Vec4[ 13 ];
Vec2i textureSize = brightPassTextureSize;
CalculateGaussianBlur5x5SampleOffsets( textureSize, sampleOffsets, sampleWeights, 1 );
//convert to Vec4 array
Vec4[] vec4Offsets = new Vec4[ 13 ];
for( int n = 0; n < 13; n++ )
{
Vec2 offset = sampleOffsets[ n ];
vec4Offsets[ n ] = new Vec4( offset.X, offset.Y, 0, 0 );
}
GpuProgramParameters parameters = material.GetBestTechnique().
Passes[ 0 ].FragmentProgramParameters;
parameters.SetNamedConstant( "sampleOffsets", vec4Offsets );
parameters.SetNamedConstant( "sampleWeights", sampleWeights );
}
break;
case rt_bloomHorizontal:
case rt_bloomVertical:
{
// horizontal and vertical bloom
bool horizontal = passId == rt_bloomHorizontal;
float[] sampleOffsets = new float[ 15 ];
Vec4[] sampleWeights = new Vec4[ 15 ];
Vec2i textureSize = bloomTextureSize;
CalculateBloomSampleOffsets( horizontal ? textureSize.X : textureSize.Y,
sampleOffsets, sampleWeights, 3, 2 );
//convert to Vec4 array
Vec4[] vec4Offsets = new Vec4[ 15 ];
for( int n = 0; n < 15; n++ )
{
//.........这里部分代码省略.........
示例2: OnMaterialRender
protected override void OnMaterialRender( uint passId, Material material, ref bool skipPass )
{
base.OnMaterialRender( passId, material, ref skipPass );
const int rt_depthDownsample1x1 = 100;
const int rt_depthDownsample2x2 = 101;
const int rt_depthDownsample3x3 = 102;
const int rt_occlusion = 200;
const int rt_blurHorizontal = 300;
const int rt_blurVertical = 400;
const int rt_targetOutput = 500;
switch( passId )
{
case rt_depthDownsample1x1:
case rt_depthDownsample2x2:
case rt_depthDownsample3x3:
{
if( downsampling == 1 && passId != rt_depthDownsample1x1 )
{
skipPass = true;
return;
}
if( downsampling == 2 && passId != rt_depthDownsample2x2 )
{
skipPass = true;
return;
}
if( downsampling == 3 && passId != rt_depthDownsample3x3 )
{
skipPass = true;
return;
}
GpuProgramParameters parameters = material.Techniques[ 0 ].Passes[ 0 ].FragmentProgramParameters;
if( parameters != null )
{
parameters.SetNamedAutoConstant( "viewportSize", GpuProgramParameters.AutoConstantType.ViewportSize );
Vec4 v = new Vec4( EngineApp.Instance.IsKeyPressed( EKeys.Z ) ? 1 : -1, 0, 0, 0 );
parameters.SetNamedConstant( "temp", v );
}
}
break;
case rt_occlusion:
{
GpuProgramParameters parameters = material.Techniques[ 0 ].Passes[ 0 ].FragmentProgramParameters;
if( parameters != null )
{
parameters.SetNamedAutoConstant( "farClipDistance",
GpuProgramParameters.AutoConstantType.FarClipDistance );
parameters.SetNamedAutoConstant( "viewportSize",
GpuProgramParameters.AutoConstantType.ViewportSize );
parameters.SetNamedAutoConstant( "fov",
GpuProgramParameters.AutoConstantType.FOV );
parameters.SetNamedConstant( "downscaleTextureSize",
new Vec4( downscaleTextureSize.X, downscaleTextureSize.Y,
1.0f / (float)downscaleTextureSize.X, 1.0f / (float)downscaleTextureSize.Y ) );
parameters.SetNamedConstant( "sampleLength", sampleLength );
parameters.SetNamedConstant( "offsetScale", offsetScale );
parameters.SetNamedConstant( "defaultAccessibility", defaultAccessibility );
//parameters.SetNamedConstant( "parameters",
// new Vec4( sampleLength, offsetScale, defaultAccessibility, 0 ) );
Range range = new Range( maxDistance, maxDistance * 1.2f );
parameters.SetNamedConstant( "fadingByDistanceRange",
new Vec4( range.Minimum, 1.0f / ( range.Maximum - range.Minimum ), 0, 0 ) );
}
}
break;
case rt_blurHorizontal:
case rt_blurVertical:
{
// horizontal and vertical blur
bool horizontal = passId == rt_blurHorizontal;
float[] sampleOffsets = new float[ 15 ];
Vec4[] sampleWeights = new Vec4[ 15 ];
Vec2I textureSize = Owner.DimensionsInPixels.Size;
CalculateBlurSampleOffsets( horizontal ? textureSize.X : textureSize.Y, sampleOffsets, sampleWeights, 3, 1 );
//convert to Vec4 array
Vec4[] vec4Offsets = new Vec4[ 15 ];
for( int n = 0; n < 15; n++ )
{
float offset = sampleOffsets[ n ] * blurSpread;
if( horizontal )
vec4Offsets[ n ] = new Vec4( offset, 0, 0, 0 );
else
vec4Offsets[ n ] = new Vec4( 0, offset, 0, 0 );
}
GpuProgramParameters parameters = material.GetBestTechnique().
//.........这里部分代码省略.........
示例3: OnMaterialRender
protected override void OnMaterialRender( uint passId, Material material, ref bool skipPass )
{
base.OnMaterialRender( passId, material, ref skipPass );
if( passId == 700 || passId == 701 )
{
bool horizontal = passId == 700;
Vec2[] sampleOffsets = new Vec2[ 15 ];
Vec4[] sampleWeights = new Vec4[ 15 ];
// calculate gaussian texture offsets & weights
Vec2I textureSize = Owner.DimensionsInPixels.Size;
float texelSize = 1.0f / (float)( horizontal ? textureSize.X : textureSize.Y );
texelSize *= fuzziness;
// central sample, no offset
sampleOffsets[ 0 ] = Vec2.Zero;
{
float distribution = GaussianDistribution( 0, 0, 3 );
sampleWeights[ 0 ] = new Vec4( distribution, distribution, distribution, 0 );
}
// 'pre' samples
for( int n = 1; n < 8; n++ )
{
float distribution = GaussianDistribution( n, 0, 3 );
sampleWeights[ n ] = new Vec4( distribution, distribution, distribution, 1 );
if( horizontal )
sampleOffsets[ n ] = new Vec2( (float)n * texelSize, 0 );
else
sampleOffsets[ n ] = new Vec2( 0, (float)n * texelSize );
}
// 'post' samples
for( int n = 8; n < 15; n++ )
{
sampleWeights[ n ] = sampleWeights[ n - 7 ];
sampleOffsets[ n ] = -sampleOffsets[ n - 7 ];
}
//convert to Vec4 array
Vec4[] vec4Offsets = new Vec4[ 15 ];
for( int n = 0; n < 15; n++ )
{
Vec2 offset = sampleOffsets[ n ];
vec4Offsets[ n ] = new Vec4( offset.X, offset.Y, 0, 0 );
}
GpuProgramParameters parameters = material.GetBestTechnique().
Passes[ 0 ].FragmentProgramParameters;
parameters.SetNamedConstant( "sampleOffsets", vec4Offsets );
parameters.SetNamedConstant( "sampleWeights", sampleWeights );
}
}
示例4: OnMaterialRender
protected override void OnMaterialRender( uint passId, Material material, ref bool skipPass )
{
base.OnMaterialRender( passId, material, ref skipPass );
const int rt_downscale = 100;
const int rt_blurHorizontal = 200;
const int rt_blurVertical = 300;
const int rt_autoFocus1 = 400;
const int rt_autoFocus2 = 401;
const int rt_autoFocus3 = 402;
const int rt_autoFocusFinal = 403;
const int rt_autoFocusCurrent = 404;
//const int rt_blurFactors = 500;
const int rt_targetOutput = 600;
//Skip auto focus passes if no auto focus is enabled
if( !autoFocus )
{
if( passId == rt_autoFocus1 || passId == rt_autoFocus2 || passId == rt_autoFocus3 ||
passId == rt_autoFocusFinal || passId == rt_autoFocusCurrent )
{
skipPass = true;
return;
}
}
// Prepare the fragment params offsets
switch( passId )
{
case rt_downscale:
{
Vec2[] sampleOffsets = new Vec2[ 16 ];
CalculateDownScale4x4SampleOffsets( Owner.DimensionsInPixels.Size, sampleOffsets );
//convert to Vec4 array
Vec4[] vec4Offsets = new Vec4[ 16 ];
for( int n = 0; n < 16; n++ )
{
Vec2 offset = sampleOffsets[ n ];
vec4Offsets[ n ] = new Vec4( offset[ 0 ], offset[ 1 ], 0, 0 );
}
GpuProgramParameters parameters = material.GetBestTechnique().
Passes[ 0 ].FragmentProgramParameters;
parameters.SetNamedConstant( "sampleOffsets", vec4Offsets );
}
break;
case rt_blurHorizontal:
case rt_blurVertical:
{
// horizontal and vertical blur
bool horizontal = passId == rt_blurHorizontal;
float[] sampleOffsets = new float[ 15 ];
Vec4[] sampleWeights = new Vec4[ 15 ];
CalculateBlurSampleOffsets( horizontal ? downscaleTextureSize.X : downscaleTextureSize.Y,
sampleOffsets, sampleWeights, 3, 1 );
//convert to Vec4 array
Vec4[] vec4Offsets = new Vec4[ 15 ];
for( int n = 0; n < 15; n++ )
{
float offset = sampleOffsets[ n ] * blurSpread;
if( horizontal )
vec4Offsets[ n ] = new Vec4( offset, 0, 0, 0 );
else
vec4Offsets[ n ] = new Vec4( 0, offset, 0, 0 );
}
GpuProgramParameters parameters = material.GetBestTechnique().
Passes[ 0 ].FragmentProgramParameters;
parameters.SetNamedConstant( "sampleOffsets", vec4Offsets );
parameters.SetNamedConstant( "sampleWeights", sampleWeights );
}
break;
case rt_autoFocus1:
{
GpuProgramParameters parameters = material.GetBestTechnique().
Passes[ 0 ].FragmentProgramParameters;
parameters.SetNamedAutoConstant( "farClipDistance",
GpuProgramParameters.AutoConstantType.FarClipDistance );
}
break;
case rt_autoFocus2:
case rt_autoFocus3:
{
Vec2[] sampleOffsets = new Vec2[ 16 ];
string textureSizeFrom = null;
switch( passId )
{
case rt_autoFocus2: textureSizeFrom = "rt_autoFocus1"; break;
case rt_autoFocus3: textureSizeFrom = "rt_autoFocus2"; break;
default: Trace.Assert( false ); break;
//.........这里部分代码省略.........
示例5: OnMaterialRender
protected override void OnMaterialRender(uint passId, Material material, ref bool skipPass)
{
base.OnMaterialRender(passId, material, ref skipPass);
//update material scheme
{
string materialScheme = RendererWorld.Instance.DefaultViewport.MaterialScheme;
foreach (CompositionTechnique technique in Compositor.Techniques)
{
foreach (CompositionTargetPass pass in technique.TargetPasses)
pass.MaterialScheme = materialScheme;
if (technique.OutputTargetPass != null)
technique.OutputTargetPass.MaterialScheme = materialScheme;
}
}
const int rt_luminance0 = 994;
const int rt_luminance1 = 993;
const int rt_luminance2 = 992;
const int rt_luminance3 = 991;
const int rt_luminance4 = 990;
const int rt_brightPass = 800;
const int rt_bloomBlur = 700;
const int rt_bloomHorizontal = 701;
const int rt_bloomVertical = 702;
const int rt_adaptedLuminance = 500;
const int rt_targetOutput = 600;
//Skip adaptation passes if adaptation switched off.
if (!Adaptation)
{
if (passId == rt_luminance0 || passId == rt_luminance1 || passId == rt_luminance2
|| passId == rt_luminance3 || passId == rt_luminance4)
{
skipPass = true;
return;
}
}
//Skip bloom passes if bloom switched off
if (BloomScale == 0)
{
if (passId == rt_brightPass || passId == rt_bloomBlur || passId == rt_bloomHorizontal ||
passId == rt_bloomVertical)
{
skipPass = true;
return;
}
}
// Prepare the fragment params offsets
switch (passId)
{
case rt_luminance0:
{
Vec2[] sampleOffsets = new Vec2[9];
// Initialize the sample offsets for the initial luminance pass.
int textureSize = Technique.GetTextureDefinition("rt_luminance0").Size.X;
float tu = 1.0f / (3.0f * textureSize);
int index = 0;
for (int x = -1; x <= 1; x++)
{
for (int y = -1; y <= 1; y++)
{
sampleOffsets[index] = new Vec2(x, y) * tu;
index++;
}
}
GpuProgramParameters parameters = material.GetBestTechnique().
Passes[0].FragmentProgramParameters;
//convert to Vec4 array
Vec4[] vec4Offsets = new Vec4[9];
for (int n = 0; n < 9; n++)
{
Vec2 offset = sampleOffsets[n];
vec4Offsets[n] = new Vec4(offset[0], offset[1], 0, 0);
}
parameters.SetNamedConstant("sampleOffsets", vec4Offsets);
}
break;
case rt_luminance1:
case rt_luminance2:
case rt_luminance3:
case rt_luminance4:
{
Vec2[] sampleOffsets = new Vec2[16];
string textureSizeFrom = null;
switch (passId)
{
case rt_luminance1: textureSizeFrom = "rt_luminance0"; break;
case rt_luminance2: textureSizeFrom = "rt_luminance1"; break;
//.........这里部分代码省略.........