Ejemplo n.º 1
0
        /// <summary>
        /// Creates a new instance of <see cref="D3D10EffectImplementation"/>.
        /// </summary>
        /// <param name="renderer">The D3D10 renderer.</param>
        /// <param name="shaderByteCode">The compiled shader byte code.</param>
        /// <param name="profileName">Name of the shader profile.</param>
        /// <param name="sFlags">The shader flags.</param>
        /// <param name="eFlags">The effect flags.</param>
        internal D3D10EffectImplementation(D3D10Renderer renderer, byte[] shaderByteCode, String profileName, D3DC.ShaderFlags sFlags, D3DC.EffectFlags eFlags)
        {
            _cachedByteCode = shaderByteCode;
            _renderer       = renderer;
            _graphicsDevice = _renderer.GraphicsDevice;
            _profileName    = profileName;
            _sFlags         = sFlags;
            _eFlags         = eFlags;
            _effect         = D3D.Effect.FromMemory(_graphicsDevice, _cachedByteCode, _profileName, _sFlags, _eFlags, null, null, null);

            //Add to resource tracker
            _renderer.Resources.AddTrackedObject(_effect.ComPointer, this);

            int techCount = _effect.Description.TechniqueCount;
            D3D10EffectTechniqueCollection techniques = new D3D10EffectTechniqueCollection();
            D3D10EffectParameterCollection parameters = new D3D10EffectParameterCollection();

            base.SetTechniques(techniques);
            base.SetParameters(parameters);

            for (int i = 0; i < techCount; i++)
            {
                D3D10EffectTechnique tech = new D3D10EffectTechnique(this, _effect, _effect.GetTechniqueByIndex(i));
                ((D3D10EffectTechniqueCollection)techniques).Add(tech);
            }

            //Set the current technique, the first one by default
            _currentTechnique = (D3D10EffectTechnique)techniques[0];
        }
        /// <summary>
        /// Clones the technique collection with the new effect instance
        /// and the new parent implementation.
        /// </summary>
        /// <param name="effect">The D3D10 effect.</param>
        /// <param name="parent">The D3D10 implementation.</param>
        /// <returns></returns>
        internal D3D10EffectTechniqueCollection Clone(D3D.Effect effect, D3D10EffectImplementation parent)
        {
            D3D10EffectTechniqueCollection clone = new D3D10EffectTechniqueCollection();

            for (int i = 0; i < Count; i++)
            {
                clone.Add(_techniques[i].Clone(effect.GetTechniqueByIndex(i), parent));
            }
            return(clone);
        }
Ejemplo n.º 3
0
        public virtual void Init(D3DDevice device)
        {
            SlimDX.D3DCompiler.ShaderFlags shaderflags = SlimDX.D3DCompiler.ShaderFlags.EnableStrictness;
            SlimDX.D3DCompiler.EffectFlags effectFlags = SlimDX.D3DCompiler.EffectFlags.None;
            effect = D3D.Effect.FromFile(device.Device, ShaderFilename, "fx_4_0", shaderflags, effectFlags, null, null, null);

            passes = new List<D3D.EffectPass>();
            for (int i = 0; i < MaxTechniques; i++)
            {
                D3D.EffectTechnique technique = effect.GetTechniqueByIndex(i);
                if (technique == null || !technique.IsValid) break;
                for (int p = 0; p < MaxPasses; p++)
                {
                    D3D.EffectPass pass = technique.GetPassByIndex(p);
                    if (pass == null || !pass.IsValid) break;
                    passes.Add(pass);
                }
            }

            World = effect.GetVariableByName("World").AsMatrix();
            View = effect.GetVariableByName("View").AsMatrix();
            Proj = effect.GetVariableByName("Proj").AsMatrix();
            InvProj = effect.GetVariableByName("InvProj").AsMatrix();
            CameraPos = effect.GetVariableByName("CameraPos").AsVector();
        }