public override void OnDestroy()
 {
     if (ps != null)
         ps.Dispose();
     ps = null;
     if (vs != null)
         vs.Dispose();
     vs = null;
 }
Example #2
0
 void IResource.Destroy()
 {
     if (ps != null)
         ps.Dispose();
     ps = null;
     if (vs != null)
         vs.Dispose();
     vs = null;
 }
        static ShaderCollection()
        {
            Stream shaderStream = Application.GetResourceStream(new Uri(@"Oct.Segmentation.Client;component/Shaders/Image.vs", UriKind.Relative)).Stream;
            DefaultVertexShader = VertexShader.FromStream(resourceDevice, shaderStream);

            shaderStream = Application.GetResourceStream(new Uri(@"Oct.Segmentation.Client;component/Shaders/Image.ps", UriKind.Relative)).Stream;
            TransparentSlicePixelShader = PixelShader.FromStream(resourceDevice, shaderStream);

            shaderStream = Application.GetResourceStream(new Uri(@"Oct.Segmentation.Client;component/Shaders/SelectedImage.ps", UriKind.Relative)).Stream;
            SelectedSlicePixelShader = PixelShader.FromStream(resourceDevice, shaderStream);
        }
Example #4
0
        public override void LoadContent()
        {
            // Load mesh
            mesh = new SpherePrimitive(1.0f, 50);

            // Load effects
            earthVertexShader           = VertexShader.FromStream(GraphicsDeviceManager.Current.GraphicsDevice, Application.GetResourceStream(new Uri(@"/SLARToolKit3DSample;component/Shaders/EarthVS.vs", UriKind.Relative)).Stream);
            earthPixelShader            = PixelShader.FromStream(GraphicsDeviceManager.Current.GraphicsDevice, Application.GetResourceStream(new Uri(@"/SLARToolKit3DSample;component/Shaders/EarthPS.ps", UriKind.Relative)).Stream);
            atmosphereVertexShader      = VertexShader.FromStream(GraphicsDeviceManager.Current.GraphicsDevice, Application.GetResourceStream(new Uri(@"/SLARToolKit3DSample;component/Shaders/AtmosphereVS.vs", UriKind.Relative)).Stream);
            cloudsPixelShader           = PixelShader.FromStream(GraphicsDeviceManager.Current.GraphicsDevice, Application.GetResourceStream(new Uri(@"/SLARToolKit3DSample;component/Shaders/CloudsPS.ps", UriKind.Relative)).Stream);
            lowerAtmospherePixelShader  = PixelShader.FromStream(GraphicsDeviceManager.Current.GraphicsDevice, Application.GetResourceStream(new Uri(@"/SLARToolKit3DSample;component/Shaders/AtmosphereLowerPS.ps", UriKind.Relative)).Stream);
            upperAtmospherePixelShader  = PixelShader.FromStream(GraphicsDeviceManager.Current.GraphicsDevice, Application.GetResourceStream(new Uri(@"/SLARToolKit3DSample;component/Shaders/AtmosphereUpperPS.ps", UriKind.Relative)).Stream);
            upperAtmosphereVertexShader = VertexShader.FromStream(GraphicsDeviceManager.Current.GraphicsDevice, Application.GetResourceStream(new Uri(@"/SLARToolKit3DSample;component/Shaders/AtmosphereUpperVS.vs", UriKind.Relative)).Stream);

            // Load textures
            atmosphereTexture  = ContentManager.LoadBitmapAndMipFromResource("Textures/Earth/EarthAtmosphere.png");
            cloudTexture       = ContentManager.LoadBitmapAndMipFromResource("Textures/Earth/EarthClouds.png");
            dayTexture         = ContentManager.LoadBitmapAndMipFromResource("Textures/Earth/EarthDay.jpg");
            maskTexture        = ContentManager.LoadBitmapAndMipFromResource("Textures/Earth/EarthMask.png");
            nightTexture       = ContentManager.LoadBitmapAndMipFromResource("Textures/Earth/EarthNight.png");
            nightLightsTexture = ContentManager.LoadBitmapAndMipFromResource("Textures/Earth/EarthNightLights.png");
            normalTexture      = ContentManager.LoadBitmapAndMipFromResource("Textures/Earth/EarthNormal.jpg");

            // Set initial state
            depthState = new DepthStencilState
            {
                DepthBufferEnable      = true,
                DepthBufferWriteEnable = true,
                DepthBufferFunction    = CompareFunction.LessEqual
            };

            cloudBlendState = new BlendState()
            {
                ColorSourceBlend      = Blend.SourceAlpha,
                AlphaSourceBlend      = Blend.SourceAlpha,
                ColorDestinationBlend = Blend.One,
                AlphaDestinationBlend = Blend.One
            };

            atmosphereBlendState = new BlendState()
            {
                ColorSourceBlend      = Blend.SourceAlpha,
                AlphaSourceBlend      = Blend.SourceAlpha,
                ColorDestinationBlend = Blend.One,
                AlphaDestinationBlend = Blend.One
            };

            // Load Moon data
            Moon.LoadContent();
        }
 public void CompileFromFiles(Canvas canvas, string psName, string vsName)
 {
     this.psFileName = psName;
     this.vsFileName = vsName;
     ShaderProfile psProf = ShaderProfile.PS_1_1;
     switch (PSTarget)
     {
         case 2:
             psProf = ShaderProfile.PS_2_0;
             break;
         case 3:
             psProf = ShaderProfile.PS_3_0;
             break;
     }
     ShaderProfile vsProf = ShaderProfile.VS_1_1;
     switch (VSTarget)
     {
         case 2:
             vsProf = ShaderProfile.VS_2_0;
             break;
         case 3:
             vsProf = ShaderProfile.VS_3_0;
             break;
     }
     CompiledShader psShader = ShaderCompiler.CompileFromFile(psFileName, null, null, CompilerOptions.PackMatrixRowMajor, "main", psProf, TargetPlatform.Windows);
     Log.GetInstance().WriteLine(psShader.ErrorsAndWarnings);
     CompiledShader vsShader = ShaderCompiler.CompileFromFile(vsFileName, null, null, CompilerOptions.PackMatrixRowMajor, "main", vsProf, TargetPlatform.Windows);
     Log.GetInstance().WriteLine(vsShader.ErrorsAndWarnings);
     errorMessage = null;
     if (vsShader.ErrorsAndWarnings.Length > 1)
         errorMessage = "Vertex Shader: " + vsShader.ErrorsAndWarnings;
     if (psShader.ErrorsAndWarnings.Length > 1)
     {
         if (errorMessage == null)
             errorMessage = "Pixel Shader: " + psShader.ErrorsAndWarnings;
         else
             errorMessage = errorMessage + "\n Pixel Shader: " + psShader.ErrorsAndWarnings;
     }
     if (psShader.Success && vsShader.Success)
     {
         ps = new PixelShader(canvas.GetDevice(), psShader.GetShaderCode());
         vs = new VertexShader(canvas.GetDevice(), vsShader.GetShaderCode());
         compiled = true;
     }
 }
        /// <summary>
        /// Creates a new effect pass.
        /// Marked as internal to prevent users from creating it.
        /// </summary>
        internal SilverlightEffectPass(string name, GraphicsDevice device, Stream vertexShaderCode, Stream pixelShaderCode, Stream vertexShaderParameters, Stream pixelShaderParameters)
        {
            this.device = device;
            Name = name;
            // Shaders
            vertexShader = VertexShader.FromStream(device, vertexShaderCode);
            pixelShader = PixelShader.FromStream(device, pixelShaderCode);

            // Assembly codes
            Dictionary<string, SilverlightEffectInternalParameter> tempParameters = new Dictionary<string, SilverlightEffectInternalParameter>();
            ExtractConstantsRegisters(vertexShaderParameters, false, tempParameters);
            ExtractConstantsRegisters(pixelShaderParameters, true, tempParameters);

            parameters = new List<SilverlightEffectInternalParameter>(tempParameters.Values);

            for (int index = 0; index < SamplerStatesCount; index++)
            {
                samplerStates[index] = new SilverlightEffectSamplerState(index);
            }
        }
Example #7
0
      public override void LoadContent()
      {
         // Load mesh
         mesh = new SpherePrimitive(0.2f, 50);

         // Load effects
         moonVertexShader = VertexShader.FromStream(GraphicsDeviceManager.Current.GraphicsDevice, Application.GetResourceStream(new Uri(@"/SLARToolKit3DSample;component/Shaders/MoonVS.vs", UriKind.Relative)).Stream);
         moonPixelShader = PixelShader.FromStream(GraphicsDeviceManager.Current.GraphicsDevice, Application.GetResourceStream(new Uri(@"/SLARToolKit3DSample;component/Shaders/MoonPS.ps", UriKind.Relative)).Stream);

         // Load textures
         moonTexture = ContentManager.LoadBitmapAndMipFromResource("Textures/Moon/moon.jpg");
         moonNormalTexture = ContentManager.LoadBitmapAndMipFromResource("Textures/Moon/moon_normal.jpg");

         // Set initial state
         depthState = new DepthStencilState
         {
            DepthBufferEnable = true,
            DepthBufferWriteEnable = true,
            DepthBufferFunction = CompareFunction.LessEqual
         };
      }
Example #8
0
      public override void LoadContent()
      {
         // Load mesh
         mesh = new SpherePrimitive(1.5f, 50);

         // Load effects
         sunVertexShader = VertexShader.FromStream(GraphicsDeviceManager.Current.GraphicsDevice, Application.GetResourceStream(new Uri(@"/SLARToolKit3DSample;component/Shaders/SunVS.vs", UriKind.Relative)).Stream);
         sunPixelShader = PixelShader.FromStream(GraphicsDeviceManager.Current.GraphicsDevice, Application.GetResourceStream(new Uri(@"/SLARToolKit3DSample;component/Shaders/SunPS.ps", UriKind.Relative)).Stream);
         refractionPixelShader = PixelShader.FromStream(GraphicsDeviceManager.Current.GraphicsDevice, Application.GetResourceStream(new Uri(@"/SLARToolKit3DSample;component/Shaders/RefractionPS.ps", UriKind.Relative)).Stream);

         // Load textures
         sunTexture = ContentManager.LoadBitmapAndMipFromResource("Textures/Sun/Sun.jpg");
         gradientTexture = ContentManager.LoadBitmapAndMipFromResource("Textures/Sun/FireGradient.png");
         turbulence1Texture = ContentManager.LoadBitmapAndMipFromResource("Textures/Sun/Turbulence1.png");
         turbulence2Texture = ContentManager.LoadBitmapAndMipFromResource("Textures/Sun/Turbulence2.png");

         depthState = new DepthStencilState
         {
            DepthBufferEnable = true,
            DepthBufferWriteEnable = true,
            DepthBufferFunction = CompareFunction.LessEqual
         };
      }
Example #9
0
 public void CompileFromFiles(string psFileName, string vsFileName)
 {
     ShaderProfile psProf = GFX.Device.GraphicsDeviceCapabilities.MaxPixelShaderProfile;
     ShaderProfile vsProf = GFX.Device.GraphicsDeviceCapabilities.MaxVertexShaderProfile;
     CompiledShader psShader = ShaderCompiler.CompileFromFile(psFileName, null, null, CompilerOptions.PackMatrixRowMajor, "main", psProf, TargetPlatform.Windows);
     CompiledShader vsShader = ShaderCompiler.CompileFromFile(vsFileName, null, null, CompilerOptions.PackMatrixRowMajor, "main", vsProf, TargetPlatform.Windows);
     errorMessage = null;
     if (vsShader.ErrorsAndWarnings.Length > 1)
         errorMessage = "Vertex Shader: " + vsShader.ErrorsAndWarnings;
     if (psShader.ErrorsAndWarnings.Length > 1)
     {
         if (errorMessage == null)
             errorMessage = "Pixel Shader: " + psShader.ErrorsAndWarnings;
         else
             errorMessage = errorMessage + "\n Pixel Shader: " + psShader.ErrorsAndWarnings;
         Console.WriteLine(errorMessage);
     }
     if (psShader.Success && vsShader.Success)
     {
         ps = new PixelShader(GFX.Device, psShader.GetShaderCode());
         vs = new VertexShader(GFX.Device, vsShader.GetShaderCode());
         compiled = true;
     }
 }
Example #10
0
		public static void PixelShader( this Effect effect, PixelShader value )
		{
			CustomEffect.PixelShaderSet(effect, value);
		}
Example #11
0
        private void init(string fileName, Stream stream, ShaderVersions shaderVersion, Loader.LoadedCallbackMethod loadedCallback)
        {
            try
            {
                #if SILVERLIGHT
                video = Parent.FindParentOrSelfWithException<Video>();

                getReflections(fileName);
                var code = getShaders(stream);
                vertex = new VertexShader(video.Device, code[0]);
                pixel = new PixelShader(video.Device, code[1]);
                #else
                effect = Parent.FindParentOrSelfWithException<RootDisposable>().Content.Load<Effect>(Streams.StripFileExt(fileName));
                loadedFromContentManager = true;
                pass = effect.CurrentTechnique.Passes[0];
                #endif

                variables = new List<ShaderVariable>();
                resources = new List<ShaderResource>();
            }
            catch (Exception e)
            {
                FailedToLoad = true;
                Loader.AddLoadableException(e);
                Dispose();
                if (loadedCallback != null) loadedCallback(this, false);
            }

            Loaded = true;
            if (loadedCallback != null) loadedCallback(this, true);
        }
Example #12
0
 public override void Dispose()
 {
     disposeChilderen();
     #if SILVERLIGHT
     if (vertex != null)
     {
         vertex.Dispose();
         vertex = null;
     }
     if (pixel != null)
     {
         pixel.Dispose();
         pixel = null;
     }
     #else
     if (effect != null && !loadedFromContentManager)
     {
         effect.Dispose();
         effect = null;
     }
     #endif
     base.Dispose();
 }
Example #13
0
        internal Shader(GraphicsDevice device, BinaryReader reader)
        {
            GraphicsDevice = device;

            var isVertexShader = reader.ReadBoolean();

            Stage = isVertexShader ? ShaderStage.Vertex : ShaderStage.Pixel;

            var shaderLength   = (int)reader.ReadUInt16();
            var shaderBytecode = reader.ReadBytes(shaderLength);

            var samplerCount = (int)reader.ReadByte();

            Samplers = new SamplerInfo[samplerCount];
            for (var s = 0; s < samplerCount; s++)
            {
                Samplers[s].type  = (SamplerType)reader.ReadByte();
                Samplers[s].index = reader.ReadByte();

                if (reader.ReadBoolean())
                {
                    Samplers[s].state                         = new SamplerState();
                    Samplers[s].state.AddressU                = (TextureAddressMode)reader.ReadByte();
                    Samplers[s].state.AddressV                = (TextureAddressMode)reader.ReadByte();
                    Samplers[s].state.AddressW                = (TextureAddressMode)reader.ReadByte();
                    Samplers[s].state.Filter                  = (TextureFilter)reader.ReadByte();
                    Samplers[s].state.MaxAnisotropy           = reader.ReadInt32();
                    Samplers[s].state.MaxMipLevel             = reader.ReadInt32();
                    Samplers[s].state.MipMapLevelOfDetailBias = reader.ReadSingle();
                }

#if OPENGL
                Samplers[s].name = reader.ReadString();
#endif
                Samplers[s].parameter = reader.ReadByte();
            }

            var cbufferCount = (int)reader.ReadByte();
            CBuffers = new int[cbufferCount];
            for (var c = 0; c < cbufferCount; c++)
            {
                CBuffers[c] = reader.ReadByte();
            }

#if DIRECTX
            var d3dDevice = device._d3dDevice;
            if (isVertexShader)
            {
                _vertexShader = new VertexShader(d3dDevice, shaderBytecode, null);

                // We need the bytecode later for allocating the
                // input layout from the vertex declaration.
                Bytecode = shaderBytecode;

                HashKey = MonoGame.Utilities.Hash.ComputeHash(Bytecode);
            }
            else
            {
                _pixelShader = new PixelShader(d3dDevice, shaderBytecode);
            }
#endif // DIRECTX

#if OPENGL
            _glslCode = System.Text.Encoding.ASCII.GetString(shaderBytecode);

            HashKey = MonoGame.Utilities.Hash.ComputeHash(shaderBytecode);

            var attributeCount = (int)reader.ReadByte();
            _attributes = new Attribute[attributeCount];
            for (var a = 0; a < attributeCount; a++)
            {
                _attributes[a].name   = reader.ReadString();
                _attributes[a].usage  = (VertexElementUsage)reader.ReadByte();
                _attributes[a].index  = reader.ReadByte();
                _attributes[a].format = reader.ReadInt16();
            }
#endif // OPENGL
        }
Example #14
0
 private void CreatePixelShader()
 {
     System.Diagnostics.Debug.Assert(Stage == ShaderStage.Pixel);
     _pixelShader = new PixelShader(GraphicsDevice._d3dDevice, _shaderBytecode);
 }
Example #15
0
      public override void LoadContent()
      {
         // Load mesh
         mesh = new SpherePrimitive(1.0f, 50);

         // Load effects
         earthVertexShader = VertexShader.FromStream(GraphicsDeviceManager.Current.GraphicsDevice, Application.GetResourceStream(new Uri(@"/SLARToolKit3DSample;component/Shaders/EarthVS.vs", UriKind.Relative)).Stream);
         earthPixelShader = PixelShader.FromStream(GraphicsDeviceManager.Current.GraphicsDevice, Application.GetResourceStream(new Uri(@"/SLARToolKit3DSample;component/Shaders/EarthPS.ps", UriKind.Relative)).Stream);
         atmosphereVertexShader = VertexShader.FromStream(GraphicsDeviceManager.Current.GraphicsDevice, Application.GetResourceStream(new Uri(@"/SLARToolKit3DSample;component/Shaders/AtmosphereVS.vs", UriKind.Relative)).Stream);
         cloudsPixelShader = PixelShader.FromStream(GraphicsDeviceManager.Current.GraphicsDevice, Application.GetResourceStream(new Uri(@"/SLARToolKit3DSample;component/Shaders/CloudsPS.ps", UriKind.Relative)).Stream);
         lowerAtmospherePixelShader = PixelShader.FromStream(GraphicsDeviceManager.Current.GraphicsDevice, Application.GetResourceStream(new Uri(@"/SLARToolKit3DSample;component/Shaders/AtmosphereLowerPS.ps", UriKind.Relative)).Stream);
         upperAtmospherePixelShader = PixelShader.FromStream(GraphicsDeviceManager.Current.GraphicsDevice, Application.GetResourceStream(new Uri(@"/SLARToolKit3DSample;component/Shaders/AtmosphereUpperPS.ps", UriKind.Relative)).Stream);
         upperAtmosphereVertexShader = VertexShader.FromStream(GraphicsDeviceManager.Current.GraphicsDevice, Application.GetResourceStream(new Uri(@"/SLARToolKit3DSample;component/Shaders/AtmosphereUpperVS.vs", UriKind.Relative)).Stream);

         // Load textures
         atmosphereTexture = ContentManager.LoadBitmapAndMipFromResource("Textures/Earth/EarthAtmosphere.png");
         cloudTexture = ContentManager.LoadBitmapAndMipFromResource("Textures/Earth/EarthClouds.png");
         dayTexture = ContentManager.LoadBitmapAndMipFromResource("Textures/Earth/EarthDay.jpg");
         maskTexture = ContentManager.LoadBitmapAndMipFromResource("Textures/Earth/EarthMask.png");
         nightTexture = ContentManager.LoadBitmapAndMipFromResource("Textures/Earth/EarthNight.png");
         nightLightsTexture = ContentManager.LoadBitmapAndMipFromResource("Textures/Earth/EarthNightLights.png");
         normalTexture = ContentManager.LoadBitmapAndMipFromResource("Textures/Earth/EarthNormal.jpg");

         // Set initial state
         depthState = new DepthStencilState
         {
            DepthBufferEnable = true,
            DepthBufferWriteEnable = true,
            DepthBufferFunction = CompareFunction.LessEqual
         };

         cloudBlendState = new BlendState()
         {
            ColorSourceBlend = Blend.SourceAlpha,
            AlphaSourceBlend = Blend.SourceAlpha,
            ColorDestinationBlend = Blend.One,
            AlphaDestinationBlend = Blend.One
         };

         atmosphereBlendState = new BlendState()
         {
            ColorSourceBlend = Blend.SourceAlpha,
            AlphaSourceBlend = Blend.SourceAlpha,
            ColorDestinationBlend = Blend.One,
            AlphaDestinationBlend = Blend.One
         };

         // Load Moon data 
         Moon.LoadContent();
      }
Example #16
0
 public Shader(CompiledShader vertex, CompiledShader fragment, VertexShader vshader, PixelShader pshader)
 {
     XnaCompiledVertexShader = vertex;
     XnaCompiledPixelShader = fragment;
     XnaVertexShader = vshader;
     XnaPixelShader = pshader;
 }