public override void Render(GraphicsDevice myDevice, EffectPass pass) { pass.Apply(); myDevice.Textures[0] = Texture; myDevice.DrawUserIndexedPrimitives(PrimitiveType.TriangleList, Vertices, 0, 4, Indexes, 0, 2); }
public GdxSpriteBatch(GraphicsDevice graphicsDevice) { if (graphicsDevice == null) throw new ArgumentNullException("graphicsDevice"); _device = graphicsDevice; _spriteEffect = new LocalSpriteEffect(graphicsDevice); _matrixTransform = _spriteEffect.Parameters["MatrixTransform"]; _spritePass = _spriteEffect.CurrentTechnique.Passes[0]; _transformMatrix = Matrix.Identity; //_projectionMatrix = Matrix.CreateOrthographicOffCenter(0, graphicsDevice.Viewport.Width, graphicsDevice.Viewport.Height, 0, 0, 1); _projectionMatrix = XnaExt.Matrix.CreateOrthographic2D(0, 0, graphicsDevice.Viewport.Width, graphicsDevice.Viewport.Height, -1, 0); Color = Color.White; CalculateIndexBuffer(); _rasterizerScissorState = new RasterizerState() { CullMode = CullMode.None, ScissorTestEnable = true, }; // projection uses CreateOrthographicOffCenter to create 2d projection // matrix with 0,0 in the upper left. /*_basicEffect.Projection = Matrix.CreateOrthographicOffCenter (0, graphicsDevice.Viewport.Width, graphicsDevice.Viewport.Height, 0, 0, 1); this._basicEffect.World = Matrix.Identity; this._basicEffect.View = Matrix.CreateLookAt(Vector3.Zero, Vector3.Forward, Vector3.Up);*/ }
public StencilSolidEffect(Effect effect) { _effect = effect; _pass = _effect.CurrentTechnique.Passes[0]; _projection = effect.Parameters["Projection"]; _transformation = effect.Parameters["Transformation"]; }
//-------------------------------------------------------------- /// <summary> /// Initializes a new instance of the <see cref="LuminanceFilter"/> class. /// </summary> /// <param name="graphicsService">The graphics service.</param> /// <exception cref="ArgumentNullException"> /// <paramref name="graphicsService"/> is <see langword="null"/>. /// </exception> public LuminanceFilter(IGraphicsService graphicsService) : base(graphicsService) { _effect = GraphicsService.Content.Load<Effect>("DigitalRune/PostProcessing/LuminanceFilter"); _useGeometricMeanParameter = _effect.Parameters["UseGeometricMean"]; _useAdaptionParameter = _effect.Parameters["UseAdaption"]; _deltaTimeParameter = _effect.Parameters["DeltaTime"]; _adaptionSpeedParameter = _effect.Parameters["AdaptionSpeed"]; _lastLuminanceTextureParameter = _effect.Parameters["LastLuminanceTexture"]; _textureParameter = _effect.Parameters["SourceTexture"]; _sourceSizeParameter = _effect.Parameters["SourceSize"]; _targetSizeParameter = _effect.Parameters["TargetSize"]; _createPass = _effect.CurrentTechnique.Passes["Create"]; _downsamplePass = _effect.CurrentTechnique.Passes["Downsample"]; _finalPass = _effect.CurrentTechnique.Passes["Final"]; _downsampleFilter = PostProcessHelper.GetDownsampleFilter(graphicsService); _copyFilter = PostProcessHelper.GetCopyFilter(graphicsService); UseGeometricMean = true; UseAdaption = true; AdaptionSpeed = 0.02f; DefaultTargetFormat = new RenderTargetFormat(1, 1, false, SurfaceFormat.HalfVector4, DepthFormat.None); }
//-------------------------------------------------------------- /// <summary> /// Initializes a new instance of the <see cref="SsaoFilter"/> class. /// </summary> /// <param name="graphicsService">The graphics service.</param> /// <exception cref="ArgumentNullException"> /// <paramref name="graphicsService"/> is <see langword="null"/>. /// </exception> public SaoFilter(IGraphicsService graphicsService) : base(graphicsService) { Effect effect = GraphicsService.Content.Load<Effect>("DigitalRune/PostProcessing/SaoFilter"); _frustumInfoParameter = effect.Parameters["FrustumInfo"]; _numberOfAOSamplesParameter = effect.Parameters["NumberOfAOSamples"]; _aoParameters0 = effect.Parameters["AOParameters0"]; _aoParameters1 = effect.Parameters["AOParameters1"]; _aoParameters2 = effect.Parameters["AOParameters2"]; _sourceTextureParameter = effect.Parameters["SourceTexture"]; _occlusionTextureParameter = effect.Parameters["OcclusionTexture"]; _gBuffer0Parameter = effect.Parameters["GBuffer0"]; //_viewParameter = _effect.Parameters["View"]; //_gBuffer1Parameter = _effect.Parameters["GBuffer1"]; _createAOPass = effect.CurrentTechnique.Passes["CreateAO"]; _blurHorizontalPass = effect.CurrentTechnique.Passes["BlurHorizontal"]; _blurVerticalPass = effect.CurrentTechnique.Passes["BlurVertical"]; _blurVerticalAndCombinePass = effect.CurrentTechnique.Passes["BlurVerticalAndCombine"]; Strength = 1; MaxOcclusion = 1; Radius = 0.5f; MinBias = 0.02f; Bias = 0.0004f; NumberOfSamples = 11; SampleDistribution = 7; BlurScale = 2; EdgeSoftness = 0.5f; CombineWithSource = true; }
public GradientTextureSkyRenderer(IGraphicsService graphicsService) { if (graphicsService == null) throw new ArgumentNullException("graphicsService"); if (graphicsService.GraphicsDevice.GraphicsProfile == GraphicsProfile.Reach) throw new NotSupportedException("The GradientTextureSkyRenderer does not support the Reach profile."); _effect = graphicsService.Content.Load<Effect>("DigitalRune/Sky/GradientTextureSky"); _parameterView = _effect.Parameters["View"]; _parameterProjection = _effect.Parameters["Projection"]; _parameterSunDirection = _effect.Parameters["SunDirection"]; _parameterTime = _effect.Parameters["Time"]; _parameterColor = _effect.Parameters["Color"]; _parameterFrontTexture = _effect.Parameters["FrontTexture"]; _parameterBackTexture = _effect.Parameters["BackTexture"]; _parameterAbcd = _effect.Parameters["Abcd"]; _parameterEAndStrength = _effect.Parameters["EAndStrength"]; _passLinear = _effect.Techniques[0].Passes["Linear"]; _passGamma = _effect.Techniques[0].Passes["Gamma"]; _passCieLinear = _effect.Techniques[0].Passes["CieLinear"]; _passCieGamma = _effect.Techniques[0].Passes["CieGamma"]; _submesh = MeshHelper.GetBox(graphicsService); }
//-------------------------------------------------------------- /// <summary> /// Initializes a new instance of the <see cref="ObjectMotionBlur"/> class. /// </summary> /// <param name="graphicsService">The graphics service.</param> /// <exception cref="ArgumentNullException"> /// <paramref name="graphicsService"/> is <see langword="null"/>. /// </exception> public ObjectMotionBlur(IGraphicsService graphicsService) : base(graphicsService) { _effect = GraphicsService.Content.Load<Effect>("DigitalRune/PostProcessing/ObjectMotionBlur"); _viewportSizeParameter = _effect.Parameters["ViewportSize"]; _sourceTextureParameter = _effect.Parameters["SourceTexture"]; _numberOfSamplesParameter = _effect.Parameters["NumberOfSamples"]; _velocityTextureParameter = _effect.Parameters["VelocityTexture"]; _velocityTexture2Parameter = _effect.Parameters["VelocityTexture2"]; _maxBlurRadiusParameter = _effect.Parameters["MaxBlurRadius"]; _sourceSizeParameter = _effect.Parameters["SourceSize"]; _gBuffer0Parameter = _effect.Parameters["GBuffer0"]; _jitterTextureParameter = _effect.Parameters["JitterTexture"]; _softZExtentParameter = _effect.Parameters["SoftZExtent"]; _singlePass = _effect.CurrentTechnique.Passes["Single"]; _dualPass = _effect.CurrentTechnique.Passes["Dual"]; _downsampleMaxParameter = _effect.CurrentTechnique.Passes["DownsampleMax"]; _downsampleMaxFromFloatBufferParameter = _effect.CurrentTechnique.Passes["DownsampleMaxFromFloatBuffer"]; _neighborMaxPass = _effect.CurrentTechnique.Passes["NeighborMax"]; _softEdgePass = _effect.CurrentTechnique.Passes["SoftEdge"]; _jitterTexture = NoiseHelper.GetGrainTexture(GraphicsService, 128); NumberOfSamples = 9; MaxBlurRadius = 20; }
public void DrawDebugWorld(DynamicsWorld world) { world.DebugDrawWorld(); if (lines.Count == 0) return; if (effect == null) { effect = new BasicEffect(graphics.Device); effect.World = Microsoft.Xna.Framework.Matrix.Identity; effect.VertexColorEnabled = true; pass = effect.CurrentTechnique.Passes[0]; } effect.Projection = graphics.GetEffect().Projection; effect.View = graphics.GetEffect().View; pass.Apply(); int pointCount = lines.Count; int linesCount = pointCount / 2; VertexPositionColor[] linesArray = new VertexPositionColor[pointCount]; for (int i = 0; i < pointCount; i++) { int color = lines[i].Color; linesArray[i].Color = new Color(color & 0xff, (color & 0xff00) >> 8, (color & 0xff0000) >> 16, 1); linesArray[i].Position = MathHelper.Convert(lines[i].Position); } graphics.Device.DrawUserPrimitives(PrimitiveType.LineList, linesArray, 0, linesCount); lines.Clear(); }
//-------------------------------------------------------------- /// <summary> /// Initializes a new instance of the <see cref="DepthOfFieldFilter"/> class. /// </summary> /// <param name="graphicsService">The graphics service.</param> /// <exception cref="ArgumentNullException"> /// <paramref name="graphicsService"/> is <see langword="null"/>. /// </exception> public DepthOfFieldFilter(IGraphicsService graphicsService) : base(graphicsService) { _effect = GraphicsService.Content.Load<Effect>("DigitalRune/PostProcessing/DepthOfFieldFilter"); _screenSizeParameter = _effect.Parameters["ScreenSize"]; _depthTextureParameter = _effect.Parameters["DepthTexture"]; _nearBlurDistanceParameter = _effect.Parameters["NearBlurDistance"]; _nearFocusDistanceParameter = _effect.Parameters["NearFocusDistance"]; _farFocusDistanceParameter = _effect.Parameters["FarFocusDistance"]; _farBlurDistanceParameter = _effect.Parameters["FarBlurDistance"]; _farParameter = _effect.Parameters["Far"]; _blurTextureParameter = _effect.Parameters["BlurTexture"]; _downsampledDepthTextureParameter = _effect.Parameters["DownsampledDepthTexture"]; _downsampledCocTextureParameter = _effect.Parameters["DownsampledCocTexture"]; _offsetsParameter = _effect.Parameters["Offsets"]; _weightsParameter = _effect.Parameters["Weights"]; _sceneTextureParameter = _effect.Parameters["SceneTexture"]; _circleOfConfusionPass = _effect.CurrentTechnique.Passes["CircleOfConfusion"]; _blurPass = _effect.CurrentTechnique.Passes["Blur"]; _depthOfFieldPass = _effect.CurrentTechnique.Passes["DepthOfField"]; _downsampleFilter = PostProcessHelper.GetDownsampleFilter(graphicsService); _cocBlur = new Blur(graphicsService); _cocBlur.InitializeBoxBlur(5, false); NearBlurDistance = 2; NearFocusDistance = 5; FarFocusDistance = 6; FarBlurDistance = 10; _downsampleFactor = 2; BlurStrength = 1; }
//-------------------------------------------------------------- /// <summary> /// Initializes a new instance of the <see cref="GodRayFilter"/> class. /// </summary> /// <param name="graphicsService">The graphics service.</param> /// <exception cref="ArgumentNullException"> /// <paramref name="graphicsService"/> is <see langword="null"/>. /// </exception> public GodRayFilter(IGraphicsService graphicsService) : base(graphicsService) { Effect effect = GraphicsService.Content.Load<Effect>("DigitalRune/PostProcessing/GodRayFilter"); _viewportSizeParameter = effect.Parameters["ViewportSize"]; _parameters0Parameter = effect.Parameters["Parameters0"]; _parameters1Parameter = effect.Parameters["Parameters1"]; _intensityParameter = effect.Parameters["Intensity"]; _numberOfSamplesParameter = effect.Parameters["NumberOfSamples"]; _sourceTextureParameter = effect.Parameters["SourceTexture"]; _gBuffer0Parameter = effect.Parameters["GBuffer0"]; _rayTextureParameter = effect.Parameters["RayTexture"]; _createMaskPass = effect.CurrentTechnique.Passes["CreateMask"]; _blurPass = effect.CurrentTechnique.Passes["Blur"]; _combinePass = effect.CurrentTechnique.Passes["Combine"]; _downsampleFilter = graphicsService.GetDownsampleFilter(); Scale = 1; LightDirection = new Vector3F(0, -1, 0); LightRadius = 0.2f; Intensity = new Vector3F(1, 1, 1); DownsampleFactor = 4; NumberOfSamples = 8; NumberOfPasses = 2; Softness = 1; }
//-------------------------------------------------------------- /// <summary> /// Initializes a new instance of the <see cref="ProjectorLightRenderer"/> class. /// </summary> /// <param name="graphicsService">The graphics service.</param> /// <exception cref="ArgumentNullException"> /// <paramref name="graphicsService"/> is <see langword="null"/>. /// </exception> public ProjectorLightRenderer(IGraphicsService graphicsService) { if (graphicsService == null) throw new ArgumentNullException("graphicsService"); _effect = graphicsService.Content.Load<Effect>("DigitalRune/Deferred/ProjectorLight"); _parameterWorldViewProjection = _effect.Parameters["WorldViewProjection"]; _parameterViewportSize = _effect.Parameters["ViewportSize"]; _parameterFrustumCorners = _effect.Parameters["FrustumCorners"]; _parameterDiffuseColor = _effect.Parameters["ProjectorLightDiffuse"]; _parameterSpecularColor = _effect.Parameters["ProjectorLightSpecular"]; _parameterPosition = _effect.Parameters["ProjectorLightPosition"]; _parameterRange = _effect.Parameters["ProjectorLightRange"]; _parameterAttenuation = _effect.Parameters["ProjectorLightAttenuation"]; _parameterTexture = _effect.Parameters["ProjectorLightTexture"]; _parameterTextureMatrix = _effect.Parameters["ProjectorLightTextureMatrix"]; _parameterGBuffer0 = _effect.Parameters["GBuffer0"]; _parameterGBuffer1 = _effect.Parameters["GBuffer1"]; _parameterShadowMaskChannel = _effect.Parameters["ShadowMaskChannel"]; _parameterShadowMask = _effect.Parameters["ShadowMask"]; _passClip = _effect.CurrentTechnique.Passes["Clip"]; _passDefaultRgb = _effect.CurrentTechnique.Passes["DefaultRgb"]; _passDefaultAlpha = _effect.CurrentTechnique.Passes["DefaultAlpha"]; _passShadowedRgb = _effect.CurrentTechnique.Passes["ShadowedRgb"]; _passShadowedAlpha = _effect.CurrentTechnique.Passes["ShadowedAlpha"]; }
public ParticleEffect(Effect _fx, ParticleEffectConfig conf) { fx = _fx; fx.CurrentTechnique = fx.Techniques[0]; fxPassSimple = fx.CurrentTechnique.Passes[conf.PassSimple]; fxpVP = fx.Parameters[conf.ParamVP]; fxpTime = fx.Parameters[conf.ParamTime]; fxpMapSize = fx.Parameters[conf.ParamMapSize]; fxPassLightning = fx.CurrentTechnique.Passes[conf.PassLightning]; fxpLSplits = fx.Parameters[conf.ParamSplits]; fxPassFire = fx.CurrentTechnique.Passes[conf.PassFire]; fxpFRates = fx.Parameters[conf.ParamRates]; fxpFScales = fx.Parameters[conf.ParamScales]; fxpFOff1 = fx.Parameters[conf.ParamOffset1]; fxpFOff2 = fx.Parameters[conf.ParamOffset2]; fxpFOff3 = fx.Parameters[conf.ParamOffset3]; fxpFDistortScale = fx.Parameters[conf.ParamDistortScale]; fxpFDistortBias = fx.Parameters[conf.ParamDistortBias]; fxPassAlert = fx.CurrentTechnique.Passes[conf.PassAlert]; // Set Default Values LightningSplits = DEFAULT_SPLITS; FireDistortScale = DEFAULT_DISTORT_SCALE; FireDistortBias = DEFAULT_DISTORT_BIAS; FireOffset1 = DEFAULT_OFFSET; FireOffset2 = DEFAULT_OFFSET; FireOffset3 = DEFAULT_OFFSET; FireRates = DEFAULT_RATES; FireScales = DEFAULT_SCALES; }
//-------------------------------------------------------------- /// <summary> /// Initializes a new instance of the <see cref="EdgeFilter"/> class. /// </summary> /// <param name="graphicsService">The graphics service.</param> /// <exception cref="ArgumentNullException"> /// <paramref name="graphicsService"/> is <see langword="null"/>. /// </exception> public EdgeFilter(IGraphicsService graphicsService) : base(graphicsService) { _effect = GraphicsService.Content.Load<Effect>("DigitalRune/PostProcessing/EdgeFilter"); _parameterViewportSize = _effect.Parameters["ViewportSize"]; _parameterHalfEdgeWidth = _effect.Parameters["HalfEdgeWidth"]; _parameterDepthThreshold = _effect.Parameters["DepthThreshold"]; _parameterDepthSensitivity = _effect.Parameters["DepthSensitivity"]; _parameterNormalThreshold = _effect.Parameters["NormalThreshold"]; _parameterNormalSensitivity = _effect.Parameters["NormalSensitivity"]; _parameterCameraBackward = _effect.Parameters["CameraBackward"]; _parameterSourceTexture = _effect.Parameters["SourceTexture"]; _parameterSilhouetteColor = _effect.Parameters["SilhouetteColor"]; _parameterCreaseColor = _effect.Parameters["CreaseColor"]; _parameterGBuffer0 = _effect.Parameters["GBuffer0"]; _parameterGBuffer1 = _effect.Parameters["GBuffer1"]; _passEdge = _effect.Techniques[0].Passes["Edge"]; _passOnePixelEdge = _effect.Techniques[0].Passes["OnePixelEdge"]; EdgeWidth = 2.0f; DepthThreshold = 0.001f; // = minDistance / farPlaneDistance DepthSensitivity = 1000; // = farPlaneDistance / (maxDistance - minDistance) NormalThreshold = 0.1f; NormalSensitivity = 2f; SilhouetteColor = new Vector4F(0, 0, 0, 1); CreaseColor = new Vector4F(0, 0, 0, 1); }
public ScatteringSkyRenderer(IGraphicsService graphicsService) { if (graphicsService == null) throw new ArgumentNullException("graphicsService"); if (graphicsService.GraphicsDevice.GraphicsProfile == GraphicsProfile.Reach) throw new NotSupportedException("The ScatteringSkyRenderer does not support the Reach profile."); _effect = graphicsService.Content.Load<Effect>("DigitalRune/Sky/ScatteringSky"); _parameterView = _effect.Parameters["View"]; _parameterProjection = _effect.Parameters["Projection"]; _parameterSunDirection = _effect.Parameters["SunDirection"]; _parameterRadii = _effect.Parameters["Radii"]; _parameterNumberOfSamples = _effect.Parameters["NumberOfSamples"]; _parameterBetaRayleigh = _effect.Parameters["BetaRayleigh"]; _parameterBetaMie = _effect.Parameters["BetaMie"]; _parameterGMie = _effect.Parameters["GMie"]; _parameterSunIntensity = _effect.Parameters["SunIntensity"]; _parameterTransmittance = _effect.Parameters["Transmittance"]; _parameterBaseHorizonColor = _effect.Parameters["BaseHorizonColor"]; _parameterBaseZenithColor = _effect.Parameters["BaseZenithColor"]; _passLinear = _effect.Techniques[0].Passes["Linear"]; _passGamma = _effect.Techniques[0].Passes["Gamma"]; _passLinearWithBaseColor = _effect.Techniques[0].Passes["LinearWithBaseColor"]; _passGammaWithBaseColor = _effect.Techniques[0].Passes["GammaWithBaseColor"]; _submesh = MeshHelper.GetBox(graphicsService); }
public void SwapProgram(string passName) { _passName = passName; if (passName == null) return; _effectPass = _shader.CurrentTechnique.Passes[passName]; }
public void SwapProgram(string passName) { this._passName = passName; if (passName != null) { this._effectPass = this._shader.CurrentTechnique.Passes[passName]; } }
public ShaderData(Effect shader, string passName) { this._passName = passName; this._shader = shader; if (shader != null && passName != null) { this._effectPass = shader.CurrentTechnique.Passes[passName]; } }
public StencilFillEffect(Effect effect) { _effect = effect; _pass = _effect.CurrentTechnique.Passes[0]; _projection = effect.Parameters["Projection"]; _transformation = effect.Parameters["Transformation"]; _offset = effect.Parameters["Offset"]; _offsetValue = Vector4.Zero; }
public ShaderData(Effect shader, string passName) { _passName = passName; _shader = shader; if (shader == null || passName == null) return; _effectPass = shader.CurrentTechnique.Passes[passName]; }
public Sssm(SpriteBatch spriteBatch, ShadowMap.Settings shadowMapSettings, Settings sssmSettings, Effect shadowSceneEffect, Effect sssmEffect, Effect blurEffect) : base(spriteBatch) { if (shadowMapSettings == null) throw new ArgumentNullException("shadowMapSettings"); if (sssmSettings == null) throw new ArgumentNullException("sssmSettings"); if (shadowSceneEffect == null) throw new ArgumentNullException("shadowSceneEffect"); if (sssmEffect == null) throw new ArgumentNullException("sssmEffect"); if (blurEffect == null) throw new ArgumentNullException("blurEffect"); this.shadowMapSettings = shadowMapSettings; this.sssmSettings = sssmSettings; this.sssmEffect = sssmEffect; //================================================================ // シャドウ シーン //---------------------------------------------------------------- // エフェクト this.shadowSceneEffect = new ShadowSceneEffect(shadowSceneEffect); this.shadowSceneEffect.DepthBias = shadowMapSettings.DepthBias; this.shadowSceneEffect.SplitCount = shadowMapSettings.SplitCount; this.shadowSceneEffect.ShadowMapSize = shadowMapSettings.Size; this.shadowSceneEffect.ShadowMapTechnique = shadowMapSettings.Technique; //---------------------------------------------------------------- // レンダ ターゲット var pp = GraphicsDevice.PresentationParameters; var width = (int) (pp.BackBufferWidth * sssmSettings.MapScale); var height = (int) (pp.BackBufferHeight * sssmSettings.MapScale); // メモ: ブラーをかける場合があるので RenderTargetUsage.PreserveContents で作成。 shadowSceneMap = new RenderTarget2D(GraphicsDevice, width, height, false, SurfaceFormat.Color, DepthFormat.Depth24, 0, RenderTargetUsage.PreserveContents); //================================================================ // スクリーン スペース シャドウ マッピング //---------------------------------------------------------------- // エフェクト shadowColorParameter = sssmEffect.Parameters["ShadowColor"]; shadowSceneMapParameter = sssmEffect.Parameters["ShadowSceneMap"]; currentPass = sssmEffect.CurrentTechnique.Passes[0]; //---------------------------------------------------------------- // ブラー if (sssmSettings.BlurEnabled) { var blurSettings = sssmSettings.Blur; blur = new GaussianBlur(blurEffect, spriteBatch, width, height, SurfaceFormat.Vector2, blurSettings.Radius, blurSettings.Amount); } }
internal void Draw(Texture2D[] textures, GraphicsDevice device, BasicEffect effect, EffectPass pass) { effect.World = displayObject.WorldTransform; effect.Texture = textures[displayObject.TextureIndex]; device.SetVertexBuffer(vertexBuffer); device.Indices = indexBuffer; pass.Apply(); device.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, vertices.Length, 0, indices.Length / 3); }
protected void UpdateTechnique(string techniqueName, string passName, int vertexIndex, int fragmentIndex) { EffectTechnique tech = Techniques[techniqueName]; EffectPass pass = tech.Passes[passName]; //pass.VertexIndex = vertexIndex; //pass.FragmentIndex = fragmentIndex; pass.UpdatePass(vertexIndex, fragmentIndex); LogShaderParameters(String.Format("Technique {0} - Pass {1} :", tech.Name, pass.Name), pass.shaderProgram); }
private void createBasicEffect() { var et = new EffectTechnique(this); Techniques["Wtf"] = et; CurrentTechnique = et; var pass = new EffectPass(et); pass.Name = "Wtf2"; et.Passes[pass.Name] = pass; }
public DeferredLightEffect() : base( Core.graphicsDevice, EffectResource.deferredLightBytes ) { clearGBufferPass = Techniques["ClearGBuffer"].Passes[0]; pointLightPass = Techniques["DeferredPointLight"].Passes[0]; spotLightPass = Techniques["DeferredSpotLight"].Passes[0]; areaLightPass = Techniques["DeferredAreaLight"].Passes[0]; directionalLightPass = Techniques["DeferredDirectionalLight"].Passes[0]; finalCombinePass = Techniques["FinalCombine"].Passes[0]; cacheEffectParameters(); }
//-------------------------------------------------------------- /// <summary> /// Initializes a new instance of the <see cref="FxaaFilter"/> class. /// </summary> /// <param name="graphicsService">The graphics service.</param> /// <exception cref="ArgumentNullException"> /// <paramref name="graphicsService"/> is <see langword="null"/>. /// </exception> public FxaaFilter(IGraphicsService graphicsService) : base(graphicsService) { _effect = GraphicsService.Content.Load<Effect>("DigitalRune/PostProcessing/FxaaFilter"); _viewportSizeParameter = _effect.Parameters["ViewportSize"]; _sourceTextureParameter = _effect.Parameters["SourceTexture"]; _luminanceToAlphaPass = _effect.CurrentTechnique.Passes["LuminanceToAlpha"]; _fxaaPass = _effect.CurrentTechnique.Passes["Fxaa"]; ComputeLuminance = true; }
/// <summary> /// Initializes a new instance of the <see cref="SepiaFilter"/> class. /// </summary> /// <param name="graphicsService">The graphics service.</param> /// <exception cref="ArgumentNullException"> /// <paramref name="graphicsService"/> is <see langword="null"/>. /// </exception> public SepiaFilter(IGraphicsService graphicsService) : base(graphicsService) { _effect = GraphicsService.Content.Load<Effect>("DigitalRune/PostProcessing/SepiaFilter"); _sourceTextureParameter = _effect.Parameters["SourceTexture"]; _strengthParameter = _effect.Parameters["Strength"]; _viewportSizeParameter = _effect.Parameters["ViewportSize"]; _fullSepiaPass = _effect.CurrentTechnique.Passes["Full"]; _partialSepiaPass = _effect.CurrentTechnique.Passes["Partial"]; Strength = 1; }
public override void Render(GraphicsDevice myDevice, EffectPass pass) { myDevice.DepthStencilState = DepthStencilState.None; for (int i = 0; i < 6; i++) { mySides[i].Position = HMCameraManager.ActiveCamera.Position + myOffsets[i]; HMEffectManager.ActiveShader.SetParameters(mySides[i]); mySides[i].Render(myDevice, pass); } myDevice.DepthStencilState = DepthStencilState.Default; }
public StencilTextEffect(Effect effect) { _effect = effect; _pass = _effect.CurrentTechnique.Passes[0]; _projection = effect.Parameters["Projection"]; _transformation = effect.Parameters["Transformation"]; _offset = effect.Parameters["Offset"]; _offsets = effect.Parameters["GlyphOffsets"]; _vertices = effect.Parameters["FontVertices"]; _numVertices = effect.Parameters["VertexCount"]; _numOffsets = effect.Parameters["GlyphCount"]; }
public StencilStrokeEffect(Effect effect) { _effect = effect; _scalingTechnique = effect.Techniques["StencilStroke_Scaling"]; _nonscalingTechnique = effect.Techniques["StencilStroke_Nonscaling"]; _passSolid = _scalingTechnique.Passes["Solid"]; _passRadial = _scalingTechnique.Passes["Radial"]; _passSolidNS = _nonscalingTechnique.Passes["Solid"]; _passRadialNS = _nonscalingTechnique.Passes["Radial"]; _projection = effect.Parameters["Projection"]; _transformation = effect.Parameters["Transformation"]; _offset = effect.Parameters["Offset"]; _thickness = effect.Parameters["Thickness"]; }
private void RenderSky(EffectWrapper pEffect, EffectPass pEffectPass) { ModelMeshPart meshPart = m_pSkyDomeModel.Meshes[0].MeshParts[0]; pEffect.GraphicsDevice.Indices = meshPart.IndexBuffer; pEffect.GraphicsDevice.SetVertexBuffer(meshPart.VertexBuffer, meshPart.VertexOffset); pEffect.GraphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, meshPart.VertexOffset, 0, meshPart.NumVertices, meshPart.StartIndex, meshPart.PrimitiveCount); }
public SpriteBatch (GraphicsDevice graphicsDevice) { if (graphicsDevice == null) { throw new ArgumentException ("graphicsDevice"); } this.GraphicsDevice = graphicsDevice; // Use a custom SpriteEffect so we can control the transformation matrix _spriteEffect = new Effect(graphicsDevice, SpriteEffect.Bytecode); _matrixTransform = _spriteEffect.Parameters["MatrixTransform"]; _spritePass = _spriteEffect.CurrentTechnique.Passes[0]; _batcher = new SpriteBatcher(graphicsDevice); _beginCalled = false; }
protected void DefineTechnique(string techniqueName, string passName, int vertexIndex, int fragmentIndex) { EffectTechnique tech = new EffectTechnique(this); tech.Name = techniqueName; EffectPass pass = new EffectPass(tech); pass.Name = passName; pass.VertexIndex = vertexIndex; pass.FragmentIndex = fragmentIndex; pass.ApplyPass(); tech.Passes._passes.Add(pass); Techniques._techniques.Add(tech); LogShaderParameters(String.Format("Technique {0} - Pass {1} :", tech.Name, pass.Name), pass.shaderProgram); }
protected override bool OnNextPass(EffectTechnique technique, RenderContext context, ref int index, out EffectPass pass) { int numberOfPasses = technique.Passes.Count; // Progress to next pass when the desired number of repetitions were performed. // (Note: We use a while statement and not an if statement, because the desired // number of repetitions returned by GetPassRepetitionCount() could theoretically // be 0.) while (_actualPassCount >= _desiredPassCount) { // Finished with current pass. Progress to next pass. _passIndex++; if (_passIndex >= numberOfPasses) { // Finished: All effect passes have been applied. context.PassIndex = -1; pass = null; return false; } _actualPassCount = 0; _desiredPassCount = GetPassRepetitionCount(context, _passIndex); } pass = technique.Passes[_passIndex]; // In the parameter index and context.PassIndex, we store the total number // of executed passes. context.PassIndex = index; index++; _actualPassCount++; if (index == numberOfPasses - 1 && string.Equals(pass.Name, "Restore", StringComparison.OrdinalIgnoreCase)) { // A last effect pass may be used to restore the default render states without // drawing anything. The effect pass needs to be called "Restore". pass.Apply(); // Finished: All effect passes have been applied. context.PassIndex = -1; pass = null; return false; } return true; }
internal EffectPass(Effect effect, EffectPass cloneSource) { Debug.Assert(effect != null, "Got a null effect!"); Debug.Assert(cloneSource != null, "Got a null cloneSource!"); _effect = effect; // Share all the immutable types. Name = cloneSource.Name; _blendState = cloneSource._blendState; _depthStencilState = cloneSource._depthStencilState; _rasterizerState = cloneSource._rasterizerState; Annotations = cloneSource.Annotations; _vertexShader = cloneSource._vertexShader; _pixelShader = cloneSource._pixelShader; }
private static void SetShaderSamplers(this EffectPass pass, EffectPassProperties props, Shader shader, TextureCollection textures, SamplerStateCollection samplerStates) { foreach (var sampler in shader.Samplers) { var param = props.Effect.Parameters[sampler.parameter]; var texture = param.Data as Texture; textures[sampler.textureSlot] = texture; // If there is a sampler state set it. if (sampler.state != null) { samplerStates[sampler.samplerSlot] = sampler.state; } } }
/// <summary> /// Constructs a <see cref="SpriteBatch"/>. /// </summary> /// <param name="graphicsDevice">The <see cref="GraphicsDevice"/>, which will be used for sprite rendering.</param> /// <param name="capacity">The initial capacity of the internal array holding batch items (the value will be rounded to the next multiple of 64).</param> /// <exception cref="ArgumentNullException">Thrown when <paramref name="graphicsDevice"/> is null.</exception> public SpriteBatch(GraphicsDevice graphicsDevice, int capacity) { if (graphicsDevice == null) { throw new ArgumentNullException("graphicsDevice", FrameworkResources.ResourceCreationWhenDeviceIsNull); } this.GraphicsDevice = graphicsDevice; _spriteEffect = new SpriteEffect(graphicsDevice); _spritePass = _spriteEffect.CurrentTechnique.Passes[0]; _batcher = new SpriteBatcher(graphicsDevice, capacity); _beginCalled = false; }
public StarfieldRenderer(IGraphicsService graphicsService) { if (graphicsService == null) throw new ArgumentNullException("graphicsService"); if (graphicsService.GraphicsDevice.GraphicsProfile == GraphicsProfile.Reach) throw new NotSupportedException("The StarfieldRenderer does not support the Reach profile."); // Load effect. _effect = graphicsService.Content.Load<Effect>("DigitalRune/Sky/Starfield"); _effectParameterViewportSize = _effect.Parameters["ViewportSize"]; _effectParameterWorldViewProjection = _effect.Parameters["WorldViewProjection"]; _effectParameterIntensity = _effect.Parameters["Intensity"]; _effectPassLinear = _effect.Techniques[0].Passes["Linear"]; _effectPassGamma = _effect.Techniques[0].Passes["Gamma"]; }
private static EffectPassCollection ReadPasses(BinaryReader reader, Effect effect, List <Shader> shaders) { Shader vertexShader = null; Shader pixelShader = null; var collection = new EffectPassCollection(); var count = (int)reader.ReadByte(); for (var i = 0; i < count; i++) { var name = reader.ReadString(); var annotations = ReadAnnotations(reader); // Assign these to the default shaders at this point? or do that in the effect pass. // Get the vertex shader. var shaderIndex = (int)reader.ReadByte(); if (shaderIndex != 255) { vertexShader = shaders[shaderIndex]; } // Get the pixel shader. shaderIndex = (int)reader.ReadByte(); if (shaderIndex != 255) { pixelShader = shaders[shaderIndex]; } // TODO: Add the state objects to the format! var pass = new EffectPass(effect, name, vertexShader, pixelShader, null, null, null, annotations); collection.Add(pass); // need to fix up the } return(collection); }
internal void ReadEffect(BinaryReader reader) { var effectPass = new EffectPass(this, "Pass", null, null, BlendState.AlphaBlend, DepthStencilState.Default, RasterizerState.CullNone, new EffectAnnotationCollection()); effectPass._shaderProgram = new ShaderProgram(reader.ReadBytes((int)reader.BaseStream.Length)); var shaderProgram = effectPass._shaderProgram; Parameters = new EffectParameterCollection(); for (int i = 0; i < shaderProgram.UniformCount; i++) { Parameters.Add(EffectParameterForUniform(shaderProgram, i)); } #warning Hacks for BasicEffect as we don't have these parameters yet Parameters.Add(new EffectParameter( EffectParameterClass.Vector, EffectParameterType.Single, "SpecularColor", 3, 1, "float3", new EffectAnnotationCollection(), new EffectParameterCollection(), new EffectParameterCollection(), new float[3])); Parameters.Add(new EffectParameter( EffectParameterClass.Scalar, EffectParameterType.Single, "SpecularPower", 1, 1, "float", new EffectAnnotationCollection(), new EffectParameterCollection(), new EffectParameterCollection(), 0.0f)); Parameters.Add(new EffectParameter( EffectParameterClass.Vector, EffectParameterType.Single, "FogVector", 4, 1, "float4", new EffectAnnotationCollection(), new EffectParameterCollection(), new EffectParameterCollection(), new float[4])); Parameters.Add(new EffectParameter( EffectParameterClass.Vector, EffectParameterType.Single, "DiffuseColor", 4, 1, "float4", new EffectAnnotationCollection(), new EffectParameterCollection(), new EffectParameterCollection(), new float[4])); Techniques = new EffectTechniqueCollection(); var effectPassCollection = new EffectPassCollection(); effectPassCollection.Add(effectPass); Techniques.Add(new EffectTechnique(this, "Name", effectPassCollection, new EffectAnnotationCollection())); ConstantBuffers = new ConstantBuffer[0]; CurrentTechnique = Techniques[0]; }
internal void ReadEffect(BinaryReader reader) { var effectPass = new EffectPass(this, "Pass", null, null, null, DepthStencilState.Default, RasterizerState.CullNone, EffectAnnotationCollection.Empty); effectPass._shaderProgram = new ShaderProgram(reader.ReadBytes((int)reader.BaseStream.Length)); var shaderProgram = effectPass._shaderProgram; EffectParameter[] parametersArray = new EffectParameter[shaderProgram.UniformCount + 4]; for (int i = 0; i < shaderProgram.UniformCount; i++) { parametersArray[i] = EffectParameterForUniform(shaderProgram, i); } #warning Hacks for BasicEffect as we don't have these parameters yet parametersArray[shaderProgram.UniformCount] = new EffectParameter( EffectParameterClass.Vector, EffectParameterType.Single, "SpecularColor", 3, 1, "float3", EffectAnnotationCollection.Empty, EffectParameterCollection.Empty, EffectParameterCollection.Empty, new float[3]); parametersArray[shaderProgram.UniformCount + 1] = new EffectParameter( EffectParameterClass.Scalar, EffectParameterType.Single, "SpecularPower", 1, 1, "float", EffectAnnotationCollection.Empty, EffectParameterCollection.Empty, EffectParameterCollection.Empty, 0.0f); parametersArray[shaderProgram.UniformCount + 2] = new EffectParameter( EffectParameterClass.Vector, EffectParameterType.Single, "FogVector", 4, 1, "float4", EffectAnnotationCollection.Empty, EffectParameterCollection.Empty, EffectParameterCollection.Empty, new float[4]); parametersArray[shaderProgram.UniformCount + 3] = new EffectParameter( EffectParameterClass.Vector, EffectParameterType.Single, "DiffuseColor", 4, 1, "float4", EffectAnnotationCollection.Empty, EffectParameterCollection.Empty, EffectParameterCollection.Empty, new float[4]); Parameters = new EffectParameterCollection(parametersArray); EffectPass [] effectsPassArray = new EffectPass[1]; effectsPassArray[0] = effectPass; var effectPassCollection = new EffectPassCollection(effectsPassArray); EffectTechnique [] effectTechniqueArray = new EffectTechnique[1]; effectTechniqueArray[0] = new EffectTechnique(this, "Name", effectPassCollection, EffectAnnotationCollection.Empty); Techniques = new EffectTechniqueCollection(effectTechniqueArray); ConstantBuffers = new ConstantBuffer[0]; CurrentTechnique = Techniques[0]; }
public static void ApplyGL(this EffectPass pass) { // Set/get the correct shader handle/cleanups. // // TODO: This "reapply" if the shader index changes // trick is sort of ugly. We should probably rework // this to use some sort of "technique/pass redirect". // EffectPassProperties props = PropertyTable.GetValue(pass, x => { return(new EffectPassProperties(pass)); }); if (props.Effect.OnApply()) { props.Effect.CurrentTechnique.Passes[0].ApplyGL(); return; } var device = props.GraphicsDevice; ShaderProgram program = props.ShaderCache.GetProgram(props.VertexShader, props.PixelShader); GL.UseProgram(program.Program); if (props.VertexShader != null) { device.VertexShader = props.VertexShader; // Update the texture parameters. pass.SetShaderSamplers(props, props.VertexShader, device.VertexTextures, device.VertexSamplerStates); foreach (int paramIndex in props.VertexShaderParams) { EffectParameter param = props.Effect.Parameters[paramIndex]; SetEffectParameter(program, param); } // Update the constant buffers. foreach (int c in props.VertexShader.CBuffers) { device.SetConstantBuffer(ShaderStage.Vertex, c, null); } } if (props.PixelShader != null) { device.PixelShader = props.PixelShader; // Update the texture parameters. pass.SetShaderSamplers(props, props.PixelShader, device.Textures, device.SamplerStates); foreach (int paramIndex in props.PixelShaderParams) { EffectParameter param = props.Effect.Parameters[paramIndex]; SetEffectParameter(program, param); } // Update the constant buffers. foreach (int c in props.PixelShader.CBuffers) { device.SetConstantBuffer(ShaderStage.Pixel, c, null); } } // Set the render states if we have some. if (props.RasterizerState != null) { device.RasterizerState = props.RasterizerState; } if (props.BlendState != null) { device.BlendState = props.BlendState; } if (props.DepthStencilState != null) { device.DepthStencilState = props.DepthStencilState; } }
public EffectPassProperties(EffectPass pass) { Pass = pass; GetEffect(); }
private static EffectTechnique[] CreateTechniques(BinaryReader input) { int techniquesCount = input.ReadInt32(); if (techniquesCount < 0 || techniquesCount > 128) { throw new System.InvalidOperationException( "Invalid silverlight effect. Have you forgot to process the effect using SilverlightEffectProcessor?"); } EffectTechnique[] techniques = new EffectTechnique[techniquesCount]; for (int techniqueIndex = 0; techniqueIndex < techniquesCount; techniqueIndex++) { int passesCount = input.ReadInt32(); EffectPass[] passes = new EffectPass[passesCount]; for (int passIndex = 0; passIndex < passesCount; passIndex++) { string passName = input.ReadString(); MemoryStream vertexShaderCodeStream = null; MemoryStream vertexShaderParametersStream = null; MemoryStream pixelShaderCodeStream = null; MemoryStream pixelShaderParametersStream = null; // Vertex shader int vertexShaderByteCodeLength = input.ReadInt32(); if (vertexShaderByteCodeLength > 0) { byte[] vertexShaderByteCode = input.ReadBytes(vertexShaderByteCodeLength); int vertexShaderParametersLength = input.ReadInt32(); byte[] vertexShaderParameters = input.ReadBytes(vertexShaderParametersLength); vertexShaderCodeStream = new MemoryStream(vertexShaderByteCode); vertexShaderParametersStream = new MemoryStream(vertexShaderParameters); } // Pixel shader int pixelShaderByteCodeLength = input.ReadInt32(); if (pixelShaderByteCodeLength > 0) { byte[] pixelShaderByteCode = input.ReadBytes(pixelShaderByteCodeLength); int pixelShaderParametersLength = input.ReadInt32(); byte[] pixelShaderParameters = input.ReadBytes(pixelShaderParametersLength); pixelShaderCodeStream = new MemoryStream(pixelShaderByteCode); pixelShaderParametersStream = new MemoryStream(pixelShaderParameters); } // Instanciate pass SilverlightEffectPass currentPass = new SilverlightEffectPass(passName, GraphicsDeviceManager.Current.GraphicsDevice, vertexShaderCodeStream, pixelShaderCodeStream, vertexShaderParametersStream, pixelShaderParametersStream); passes[passIndex] = currentPass; if (vertexShaderCodeStream != null) { vertexShaderCodeStream.Dispose(); vertexShaderParametersStream.Dispose(); } if (pixelShaderCodeStream != null) { pixelShaderCodeStream.Dispose(); pixelShaderParametersStream.Dispose(); } // Render states int renderStatesCount = input.ReadInt32(); for (int renderStateIndex = 0; renderStateIndex < renderStatesCount; renderStateIndex++) { currentPass.AppendState(input.ReadString(), input.ReadString()); } } // Instanciate technique techniques[techniqueIndex] = new EffectTechnique(passes); } return(techniques); }
/// <summary> /// Creates a new instance of <see cref="XNAEffectPass"/>. /// </summary> /// <param name="pass">The underlying XNA pass.</param> internal XNAEffectPass(XFG.EffectPass pass) { _pass = pass; _annotations = new XNAEffectAnnotationCollection(pass.Annotations); }
/// <summary> /// Sorts the batch items and then groups batch drawing into maximal allowed batch sets that do not /// overflow the 16 bit array indices for vertices. /// </summary> /// <param name="sortMode">The type of depth sorting desired for the rendering.</param> public unsafe void DrawBatch(SpriteSortMode sortMode, EffectPass defaultSpritePass) { // nothing to do if (_batchItemCount == 0) { return; } // sort the batch items switch (sortMode) { case SpriteSortMode.Texture: case SpriteSortMode.FrontToBack: case SpriteSortMode.BackToFront: Array.Sort(_batchItemList, 0, _batchItemCount); break; } // Determine how many iterations through the drawing code we need to make int batchIndex = 0; int batchCount = _batchItemCount; unchecked { _device._graphicsMetrics._spriteCount += batchCount; } // Iterate through the batches, doing short.MaxValue sets of vertices only. while (batchCount > 0) { // setup the vertexArray array var startIndex = 0; var index = 0; Texture2D tex = null; SpriteBatch.EffectWithParams effect = default; int numBatchesToProcess = batchCount; if (numBatchesToProcess > MaxBatchSize) { numBatchesToProcess = MaxBatchSize; } // Avoid the array checking overhead by using pointer indexing! fixed(VertexPositionColorTexture *vertexArrayFixedPtr = _vertexArray) { var vertexArrayPtr = vertexArrayFixedPtr; // Draw the batches for (int i = 0; i < numBatchesToProcess; i++, batchIndex++, index += 4, vertexArrayPtr += 4) { SpriteBatchItem item = _batchItemList[batchIndex]; // if the texture changed, we need to flush and bind the new texture var shouldFlush = !ReferenceEquals(item.Texture, tex) || !ReferenceEquals(item.Effect.Effect, effect.Effect) || !ReferenceEquals(item.Effect.Params, effect.Params); if (shouldFlush) { FlushVertexArray(startIndex, index, effect.Effect, tex); tex = item.Texture; effect = item.Effect; if (effect.Effect is null || effect.Params is null) { defaultSpritePass.Apply(); } else { effect.Apply(); } startIndex = index = 0; vertexArrayPtr = vertexArrayFixedPtr; _device.Textures[0] = tex; } // store the SpriteBatchItem data in our vertexArray *(vertexArrayPtr + 0) = item.vertexTL; *(vertexArrayPtr + 1) = item.vertexTR; *(vertexArrayPtr + 2) = item.vertexBL; *(vertexArrayPtr + 3) = item.vertexBR; // Release the texture. item.Texture = null; item.Effect = default; } } // flush the remaining vertexArray data FlushVertexArray(startIndex, index, effect.Effect, tex); // Update our batch count to continue the process of culling down // large batches batchCount -= numBatchesToProcess; }
private static EffectPassCollection ReadPasses(BinaryReader reader, Effect effect, Shader[] shaders) { var count = (int)reader.ReadByte(); var passes = new EffectPass[count]; for (var i = 0; i < count; i++) { var name = reader.ReadString(); var annotations = ReadAnnotations(reader); // Get the vertex shader. Shader vertexShader = null; var shaderIndex = (int)reader.ReadByte(); if (shaderIndex != 255) { vertexShader = shaders[shaderIndex]; } // Get the pixel shader. Shader pixelShader = null; shaderIndex = (int)reader.ReadByte(); if (shaderIndex != 255) { pixelShader = shaders[shaderIndex]; } BlendState blend = null; DepthStencilState depth = null; RasterizerState raster = null; if (reader.ReadBoolean()) { blend = new BlendState { AlphaBlendFunction = (BlendFunction)reader.ReadByte(), AlphaDestinationBlend = (Blend)reader.ReadByte(), AlphaSourceBlend = (Blend)reader.ReadByte(), BlendFactor = new Color(reader.ReadByte(), reader.ReadByte(), reader.ReadByte(), reader.ReadByte()), ColorBlendFunction = (BlendFunction)reader.ReadByte(), ColorDestinationBlend = (Blend)reader.ReadByte(), ColorSourceBlend = (Blend)reader.ReadByte(), ColorWriteChannels = (ColorWriteChannels)reader.ReadByte(), ColorWriteChannels1 = (ColorWriteChannels)reader.ReadByte(), ColorWriteChannels2 = (ColorWriteChannels)reader.ReadByte(), ColorWriteChannels3 = (ColorWriteChannels)reader.ReadByte(), MultiSampleMask = reader.ReadInt32(), }; } if (reader.ReadBoolean()) { depth = new DepthStencilState { CounterClockwiseStencilDepthBufferFail = (StencilOperation)reader.ReadByte(), CounterClockwiseStencilFail = (StencilOperation)reader.ReadByte(), CounterClockwiseStencilFunction = (CompareFunction)reader.ReadByte(), CounterClockwiseStencilPass = (StencilOperation)reader.ReadByte(), DepthBufferEnable = reader.ReadBoolean(), DepthBufferFunction = (CompareFunction)reader.ReadByte(), DepthBufferWriteEnable = reader.ReadBoolean(), ReferenceStencil = reader.ReadInt32(), StencilDepthBufferFail = (StencilOperation)reader.ReadByte(), StencilEnable = reader.ReadBoolean(), StencilFail = (StencilOperation)reader.ReadByte(), StencilFunction = (CompareFunction)reader.ReadByte(), StencilMask = reader.ReadInt32(), StencilPass = (StencilOperation)reader.ReadByte(), StencilWriteMask = reader.ReadInt32(), TwoSidedStencilMode = reader.ReadBoolean(), }; } if (reader.ReadBoolean()) { raster = new RasterizerState { CullMode = (CullMode)reader.ReadByte(), DepthBias = reader.ReadSingle(), FillMode = (FillMode)reader.ReadByte(), MultiSampleAntiAlias = reader.ReadBoolean(), ScissorTestEnable = reader.ReadBoolean(), SlopeScaleDepthBias = reader.ReadSingle(), }; } passes[i] = new EffectPass(effect, name, vertexShader, pixelShader, blend, depth, raster, annotations); } return(new EffectPassCollection(passes)); }
private static EffectPassCollection ReadPasses(BinaryReader reader, Effect effect, List <Shader> shaders) { Shader vertexShader = (Shader)null; Shader pixelShader = (Shader)null; EffectPassCollection effectPassCollection = new EffectPassCollection(); int num = (int)reader.ReadByte(); for (int index1 = 0; index1 < num; ++index1) { string name = reader.ReadString(); EffectAnnotationCollection annotations = Effect.ReadAnnotations(reader); int index2 = (int)reader.ReadByte(); if (index2 != (int)byte.MaxValue) { vertexShader = shaders[index2]; } int index3 = (int)reader.ReadByte(); if (index3 != (int)byte.MaxValue) { pixelShader = shaders[index3]; } BlendState blendState = (BlendState)null; DepthStencilState depthStencilState = (DepthStencilState)null; RasterizerState rasterizerState = (RasterizerState)null; if (reader.ReadBoolean()) { blendState = new BlendState() { AlphaBlendFunction = (BlendFunction)reader.ReadByte(), AlphaDestinationBlend = (Blend)reader.ReadByte(), AlphaSourceBlend = (Blend)reader.ReadByte(), BlendFactor = new Color((int)reader.ReadByte(), (int)reader.ReadByte(), (int)reader.ReadByte(), (int)reader.ReadByte()), ColorBlendFunction = (BlendFunction)reader.ReadByte(), ColorDestinationBlend = (Blend)reader.ReadByte(), ColorSourceBlend = (Blend)reader.ReadByte(), ColorWriteChannels = (ColorWriteChannels)reader.ReadByte(), ColorWriteChannels1 = (ColorWriteChannels)reader.ReadByte(), ColorWriteChannels2 = (ColorWriteChannels)reader.ReadByte(), ColorWriteChannels3 = (ColorWriteChannels)reader.ReadByte(), MultiSampleMask = reader.ReadInt32() } } ; if (reader.ReadBoolean()) { depthStencilState = new DepthStencilState() { CounterClockwiseStencilDepthBufferFail = (StencilOperation)reader.ReadByte(), CounterClockwiseStencilFail = (StencilOperation)reader.ReadByte(), CounterClockwiseStencilFunction = (CompareFunction)reader.ReadByte(), CounterClockwiseStencilPass = (StencilOperation)reader.ReadByte(), DepthBufferEnable = reader.ReadBoolean(), DepthBufferFunction = (CompareFunction)reader.ReadByte(), DepthBufferWriteEnable = reader.ReadBoolean(), ReferenceStencil = reader.ReadInt32(), StencilDepthBufferFail = (StencilOperation)reader.ReadByte(), StencilEnable = reader.ReadBoolean(), StencilFail = (StencilOperation)reader.ReadByte(), StencilFunction = (CompareFunction)reader.ReadByte(), StencilMask = reader.ReadInt32(), StencilPass = (StencilOperation)reader.ReadByte(), StencilWriteMask = reader.ReadInt32(), TwoSidedStencilMode = reader.ReadBoolean() } } ; if (reader.ReadBoolean()) { rasterizerState = new RasterizerState() { CullMode = (CullMode)reader.ReadByte(), DepthBias = reader.ReadSingle(), FillMode = (FillMode)reader.ReadByte(), MultiSampleAntiAlias = reader.ReadBoolean(), ScissorTestEnable = reader.ReadBoolean(), SlopeScaleDepthBias = reader.ReadSingle() } } ; EffectPass pass = new EffectPass(effect, name, vertexShader, pixelShader, blendState, depthStencilState, rasterizerState, annotations); effectPassCollection.Add(pass); } return(effectPassCollection); }