internal Effect(GraphicsDevice device) { graphicsDevice = device; Parameters = new EffectParameterCollection(); Techniques = new EffectTechniqueCollection(); CurrentTechnique = new EffectTechnique(this); }
//-------------------------------------------------------------- /// <summary> /// Initializes a new instance of the <see cref="ByNameTechniqueBinding"/> class. /// </summary> /// <param name="effect">The effect.</param> /// <exception cref="ArgumentNullException"> /// <paramref name="effect"/> is <see langword="null"/>. /// </exception> public ByNameTechniqueBinding(Effect effect) { if (effect == null) throw new ArgumentNullException("effect"); _techniques = effect.Techniques; }
/// <summary> /// Initializes a new instance of the <see cref="ByNameTechniqueBinding"/> class. /// </summary> /// <param name="techniques">The effect techniques.</param> /// <exception cref="ArgumentNullException"> /// <paramref name="techniques"/> is <see langword="null"/>. /// </exception> private ByNameTechniqueBinding(EffectTechniqueCollection techniques) { if (techniques == null) throw new ArgumentNullException("techniques"); _techniques = techniques; }
protected Effect(Effect cloneSource) : this(cloneSource.GraphicsDevice) { this.CurrentTechnique = cloneSource.CurrentTechnique; this.Name = cloneSource.Name; this.Parameters = cloneSource.Parameters; this.Tag = cloneSource.Tag; this.Techniques = cloneSource.Techniques; }
/// <summary> /// Initializes a new instance of the <see cref="ByNameTechniqueBinding"/> class. /// </summary> /// <param name="techniques">The effect techniques.</param> /// <exception cref="ArgumentNullException"> /// <paramref name="techniques"/> is <see langword="null"/>. /// </exception> private ByNameTechniqueBinding(EffectTechniqueCollection techniques) { if (techniques == null) { throw new ArgumentNullException("techniques"); } _techniques = techniques; }
/// <summary> /// Initializes a new instance of the <see cref="ByNameTechniqueBinding"/> class. /// </summary> /// <param name="effect">The effect.</param> /// <exception cref="ArgumentNullException"> /// <paramref name="effect"/> is <see langword="null"/>. /// </exception> public ByNameTechniqueBinding(Effect effect) { if (effect == null) { throw new ArgumentNullException("effect"); } _techniques = effect.Techniques; }
/// <summary> /// Initializes a new instance of the <see cref="ShadowRenderer"/> class. /// </summary> /// <param name="device">The device.</param> /// <param name="contentManager">The content.</param> public CascadeShadowRenderer(GraphicsDevice device, ContentManager contentManager) { // Load the Shadow Effect shadowEffect = contentManager.Load <Effect>("Shaders/Shadows/CascadeShadowMap"); // Instantiate the SpriteBatch spriteBatch = new SpriteBatch(device); // Create the ShadowMap RenderTarget shadowMap = new RenderTarget2D(device, SHADOWMAPSIZE * NUMBER_OF_SPLITS, SHADOWMAPSIZE, false, SurfaceFormat.Single, DepthFormat.Depth24Stencil8, 0, RenderTargetUsage.DiscardContents); // Create the Shadow Occlusion RenderTarget shadowOcclusion = new RenderTarget2D(device, device.PresentationParameters.BackBufferWidth, device.PresentationParameters.BackBufferHeight, false, SurfaceFormat.Color, DepthFormat.Depth24Stencil8); // Create the Disabled Shadow Occlusion RenderTarget disabledShadowOcclusion = new RenderTarget2D(device, 1, 1, false, SurfaceFormat.Color, DepthFormat.Depth24Stencil8); // Create the Fullscreen Quad fullscreenQuad = new FullScreenQuad(device); // Get the Techniques // 0 - GenerateShadowMap // 1 - CreateShadowTerm2x2PCF // 2 - CreateShadowTerm3x3PCF // 3 - CreateShadowTerm5x5PCF // 4 - CreateShadowTerm7x7PCF shadowOcclusionTechniques = this.shadowEffect.Techniques; // Create a default Directional light light = new Lights.DirectionalLight(); light.Direction = new Vector3(-1, -1, -1); light.Color = new Vector3(0.7f, 0.7f, 0.7f); }
internal Effect(GraphicsDevice aGraphicsDevice) { if (aGraphicsDevice == null) { throw new ArgumentNullException("Graphics Device Cannot Be Null"); } this.graphicsDevice = aGraphicsDevice; Parameters = new EffectParameterCollection(); Techniques = new EffectTechniqueCollection(); CurrentTechnique = new EffectTechnique(this); }
private unsafe void INTERNAL_parseEffectStruct() { MojoShader.MOJOSHADER_effect* effectPtr = (MojoShader.MOJOSHADER_effect*) glEffect.EffectData; // Set up Parameters MojoShader.MOJOSHADER_effectParam* paramPtr = (MojoShader.MOJOSHADER_effectParam*) effectPtr->parameters; List<EffectParameter> parameters = new List<EffectParameter>(); for (int i = 0; i < effectPtr->param_count; i += 1) { MojoShader.MOJOSHADER_effectParam param = paramPtr[i]; if ( param.value.value_type == MojoShader.MOJOSHADER_symbolType.MOJOSHADER_SYMTYPE_VERTEXSHADER || param.value.value_type == MojoShader.MOJOSHADER_symbolType.MOJOSHADER_SYMTYPE_PIXELSHADER ) { // Skip shader objects... continue; } else if ( param.value.value_type >= MojoShader.MOJOSHADER_symbolType.MOJOSHADER_SYMTYPE_SAMPLER && param.value.value_type <= MojoShader.MOJOSHADER_symbolType.MOJOSHADER_SYMTYPE_SAMPLERCUBE ) { string textureName = String.Empty; MojoShader.MOJOSHADER_effectSamplerState* states = (MojoShader.MOJOSHADER_effectSamplerState*) param.value.values; for (int j = 0; j < param.value.value_count; j += 1) { if ( states[j].value.value_type >= MojoShader.MOJOSHADER_symbolType.MOJOSHADER_SYMTYPE_TEXTURE && states[j].value.value_type <= MojoShader.MOJOSHADER_symbolType.MOJOSHADER_SYMTYPE_TEXTURECUBE ) { MojoShader.MOJOSHADER_effectObject *objectPtr = (MojoShader.MOJOSHADER_effectObject*) effectPtr->objects; int* index = (int*) states[j].value.values; textureName = Marshal.PtrToStringAnsi(objectPtr[*index].mapping.name); break; } } /* Because textures have to be declared before the sampler, * we can assume that it will always be in the list by the * time we get to this point. * -flibit */ for (int j = 0; j < parameters.Count; j += 1) { if (textureName.Equals(parameters[j].Name)) { samplerMap[Marshal.PtrToStringAnsi(param.value.name)] = parameters[j]; break; } } continue; } parameters.Add(new EffectParameter( Marshal.PtrToStringAnsi(param.value.name), Marshal.PtrToStringAnsi(param.value.semantic), (int) param.value.row_count, (int) param.value.column_count, (int) param.value.element_count, XNAClass[(int) param.value.value_class], XNAType[(int) param.value.value_type], null, // FIXME: See mojoshader_effects.c:readvalue -flibit INTERNAL_readAnnotations( param.annotations, param.annotation_count ), param.value.values )); } Parameters = new EffectParameterCollection(parameters); // Set up Techniques MojoShader.MOJOSHADER_effectTechnique* techPtr = (MojoShader.MOJOSHADER_effectTechnique*) effectPtr->techniques; List<EffectTechnique> techniques = new List<EffectTechnique>(effectPtr->technique_count); for (int i = 0; i < techniques.Capacity; i += 1) { MojoShader.MOJOSHADER_effectTechnique tech = techPtr[i]; // Set up Passes MojoShader.MOJOSHADER_effectPass* passPtr = (MojoShader.MOJOSHADER_effectPass*) tech.passes; List<EffectPass> passes = new List<EffectPass>((int) tech.pass_count); for (int j = 0; j < passes.Capacity; j += 1) { MojoShader.MOJOSHADER_effectPass pass = passPtr[j]; passes.Add(new EffectPass( Marshal.PtrToStringAnsi(pass.name), INTERNAL_readAnnotations( pass.annotations, pass.annotation_count ), this, (uint) j )); } techniques.Add(new EffectTechnique( Marshal.PtrToStringAnsi(tech.name), (IntPtr) (techPtr + i), new EffectPassCollection(passes), INTERNAL_readAnnotations( tech.annotations, tech.annotation_count ) )); } Techniques = new EffectTechniqueCollection(techniques); }
protected Effect(GraphicsDevice graphicsDevice) { if (graphicsDevice == null) { throw new ArgumentNullException("Graphics Device Cannot Be Null"); } this.graphicsDevice = graphicsDevice; Techniques = new EffectTechniqueCollection(); }
private void InitEffect() { effect = Editor.Content.Load<Effect>( @"Shaders\heightmap_multilayer" ); effectTechniques = effect.Techniques; worldViewProjParam = effect.Parameters[ "WorldViewProj" ]; worldParam = effect.Parameters[ "World" ]; viewParam = effect.Parameters[ "View" ]; textureParam = new EffectParameter[ 5 ]; textureScaleParam = new EffectParameter[ 5 ]; for( int i = 0; i < textureParam.Length; i++ ) { textureParam[ i ] = effect.Parameters[ "t" + i ]; textureScaleParam[ i ] = effect.Parameters[ "t" + i + "scale" ]; } DrawDetailParam = effect.Parameters[ "bDrawDetail" ]; colormapParam = effect.Parameters[ "colormap" ]; lightMapParam = effect.Parameters[ "lightMap" ]; normalMapParam = effect.Parameters[ "normalMap" ]; decalMapParam = effect.Parameters[ "decalMap" ]; cameraPositionParam = effect.Parameters[ "cameraPosition" ]; cameraDirectionParam = effect.Parameters[ "cameraDirection" ]; ambientLightParam = effect.Parameters[ "ambientLight" ]; lightPositionParam = effect.Parameters[ "lightPosition" ]; lightDirectionParam = effect.Parameters[ "lightDirection" ]; lightPowerParam = effect.Parameters[ "lightPower" ]; groundCursorPositionParam = effect.Parameters[ "groundCursorPosition" ]; groundCursorTextureParam = effect.Parameters[ "groundCursorTex" ]; groundCursorSizeParam = effect.Parameters[ "groundCursorSize" ]; showCursorParam = effect.Parameters[ "bShowCursor" ]; useSunParam = effect.Parameters[ "bUseSun" ]; sunColorParam = effect.Parameters[ "sunColor" ]; UpdateTextures(); UpdateEffect(); }
/// <summary> /// Clone the source into this existing object. /// </summary> /// <remarks> /// Note this is not overloaded in derived classes on purpose. This is /// only a reason this exists is for caching effects. /// </remarks> /// <param name="cloneSource">The source effect to clone from.</param> private void Clone(Effect cloneSource) { Debug.Assert(_isClone, "Cannot clone into non-cloned effect!"); // Copy the mutable members of the effect. Parameters = new EffectParameterCollection(cloneSource.Parameters); Techniques = new EffectTechniqueCollection(this, cloneSource.Techniques); // Make a copy of the immutable constant buffers. ConstantBuffers = new ConstantBuffer[cloneSource.ConstantBuffers.Length]; for (var i = 0; i < cloneSource.ConstantBuffers.Length; i++) ConstantBuffers[i] = new ConstantBuffer(cloneSource.ConstantBuffers[i]); // Find and set the current technique. for (var i = 0; i < cloneSource.Techniques.Count; i++) { if (cloneSource.Techniques[i] == cloneSource.CurrentTechnique) { CurrentTechnique = Techniques[i]; break; } } // Take a reference to the original shader list. _shaderList = cloneSource._shaderList; }
private void ReadEffect (BinaryReader reader) { // TODO: Maybe we should be reading in a string // table here to save some bytes in the file. // Read in all the constant buffers. var buffers = (int)reader.ReadByte (); ConstantBuffers = new ConstantBuffer[buffers]; for (var c = 0; c < buffers; c++) { #if OPENGL string name = reader.ReadString (); #else string name = null; #endif // Create the backing system memory buffer. var sizeInBytes = (int)reader.ReadInt16 (); // Read the parameter index values. var parameters = new int[reader.ReadByte ()]; var offsets = new int[parameters.Length]; for (var i = 0; i < parameters.Length; i++) { parameters [i] = (int)reader.ReadByte (); offsets [i] = (int)reader.ReadUInt16 (); } var buffer = new ConstantBuffer(GraphicsDevice, sizeInBytes, parameters, offsets, name); ConstantBuffers[c] = buffer; } // Read in all the shader objects. var shaders = (int)reader.ReadByte(); _shaders = new Shader[shaders]; for (var s = 0; s < shaders; s++) _shaders[s] = new Shader(GraphicsDevice, reader); // Read in the parameters. Parameters = ReadParameters(reader); // Read the techniques. var techniqueCount = (int)reader.ReadByte(); var techniques = new EffectTechnique[techniqueCount]; for (var t = 0; t < techniqueCount; t++) { var name = reader.ReadString(); var annotations = ReadAnnotations(reader); var passes = ReadPasses(reader, this, _shaders); techniques[t] = new EffectTechnique(this, name, passes, annotations); } Techniques = new EffectTechniqueCollection(techniques); CurrentTechnique = Techniques[0]; }
/// <summary> /// Initializes a new instance of the <see cref="Effect" /> class with the specified bytecode effect. See remarks. /// </summary> /// <param name="device">The device.</param> /// <param name="effectData">The bytecode to add to <see cref="GraphicsDevice.DefaultEffectPool"/>. This bytecode must contain only one effect.</param> /// <exception cref="ArgumentException">If the bytecode doesn't contain a single effect.</exception> /// <remarks> /// The effect bytecode must contain only a single effect and will be registered into the <see cref="GraphicsDevice.DefaultEffectPool"/>. /// </remarks> public Effect(GraphicsDevice device, EffectData effectData) : base(device) { if (effectData.Effects.Count != 1) throw new ArgumentException(string.Format("Expecting only one effect in the effect bytecode instead of [{0}]. Use GraphicsDevice.DefaultEffectPool.RegisterBytecode instead", Utilities.Join(",", effectData.Effects)), "bytecode"); ConstantBuffers = new EffectConstantBufferCollection(); Parameters = new EffectParameterCollection(); Techniques = new EffectTechniqueCollection(); ResourceLinker = ToDispose(new EffectResourceLinker()); Pool = device.DefaultEffectPool; // Sets the effect name Name = effectData.Effects[0].Name; // Register the bytecode to the pool Pool.RegisterBytecode(effectData); Initialize(); }
/// <summary> /// Initializes a new instance of the <see cref="Effect" /> class with the specified effect loaded from an effect pool. /// </summary> /// <param name="device">The device.</param> /// <param name="pool">The effect pool.</param> /// <param name="effectName">Name of the effect.</param> public Effect(GraphicsDevice device, EffectPool pool, string effectName) : base(device, effectName) { ConstantBuffers = new EffectConstantBufferCollection(); Parameters = new EffectParameterCollection(); Techniques = new EffectTechniqueCollection(); ResourceLinker = ToDispose(new EffectResourceLinker()); Pool = pool; Initialize(); }
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]; }
protected Effect(GraphicsDevice graphicsDevice, Effect cloneSource) { Parameters = new EffectParameterCollection(); Techniques = new EffectTechniqueCollection(); if (graphicsDevice == null) { throw new ArgumentNullException("Graphics Device Cannot Be Null"); } this.graphicsDevice = graphicsDevice; }
private void ReadEffect (BinaryReader reader) { // Check the header to make sure the file and version is correct! var header = new string (reader.ReadChars (MGFXHeader.Length)); var version = (int)reader.ReadByte (); if (header != MGFXHeader) throw new Exception ("The MGFX file is corrupt!"); if (version != MGFXVersion) throw new Exception("Wrong MGFX file version!"); var profile = reader.ReadByte (); #if DIRECTX if (profile != 1) #else if (profile != 0) #endif throw new Exception("The MGFX effect is the wrong profile for this platform!"); // TODO: Maybe we should be reading in a string // table here to save some bytes in the file. // Read in all the constant buffers. var buffers = (int)reader.ReadByte (); ConstantBuffers = new ConstantBuffer[buffers]; for (var c = 0; c < buffers; c++) { #if OPENGL string name = reader.ReadString (); #else string name = null; #endif // Create the backing system memory buffer. var sizeInBytes = (int)reader.ReadInt16 (); // Read the parameter index values. var parameters = new int[reader.ReadByte ()]; var offsets = new int[parameters.Length]; for (var i = 0; i < parameters.Length; i++) { parameters [i] = (int)reader.ReadByte (); offsets [i] = (int)reader.ReadUInt16 (); } var buffer = new ConstantBuffer(GraphicsDevice, sizeInBytes, parameters, offsets, name); ConstantBuffers[c] = buffer; } // Read in all the shader objects. var shaders = (int)reader.ReadByte(); _shaders = new Shader[shaders]; for (var s = 0; s < shaders; s++) _shaders[s] = new Shader(GraphicsDevice, reader); // Read in the parameters. Parameters = ReadParameters(reader); // Read the techniques. var techniqueCount = (int)reader.ReadByte(); var techniques = new EffectTechnique[techniqueCount]; for (var t = 0; t < techniqueCount; t++) { var name = reader.ReadString(); var annotations = ReadAnnotations(reader); var passes = ReadPasses(reader, this, _shaders); techniques[t] = new EffectTechnique(this, name, passes, annotations); } Techniques = new EffectTechniqueCollection(techniques); CurrentTechnique = Techniques[0]; }
/// <summary> /// Initializes a new instance of the <see cref="Effect" /> class with the specified bytecode effect. See remarks. /// </summary> /// <param name="device">The device.</param> /// <param name="effectData">The bytecode to add to the Effect Pool. This bytecode must contain only one effect.</param> /// <param name="effectPool">The effect pool used to register the bytecode. Default is <see cref="GraphicsDevice.DefaultEffectPool"/>.</param> /// <exception cref="ArgumentException">If the bytecode doesn't contain a single effect.</exception> /// <remarks>The effect bytecode must contain only a single effect and will be registered into the <see cref="GraphicsDevice.DefaultEffectPool"/>.</remarks> public Effect(GraphicsDevice device, EffectData effectData, EffectPool effectPool = null) : base(device) { if (effectData.Effects.Count != 1) throw new ArgumentException(string.Format("Expecting only one effect in the effect bytecode instead of [{0}].", Utilities.Join(",", effectData.Effects)), "effectData"); ConstantBuffers = new EffectConstantBufferCollection(); Parameters = new EffectParameterCollection(); Techniques = new EffectTechniqueCollection(); Pool = effectPool ?? device.DefaultEffectPool; // Sets the effect name Name = effectData.Effects[0].Name; // Register the bytecode to the pool Pool.RegisterBytecode(effectData); // Initialize from effect InitializeFrom(Pool.Find(Name)); // If everything was fine, then we can register it into the pool Pool.AddEffect(this); }
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]; }
internal void CreateInstanceFrom(GraphicsDevice device, EffectData effectData, EffectPool effectPool) { GraphicsDevice = device; ConstantBuffers = new EffectConstantBufferCollection(); Parameters = new EffectParameterCollection(); Techniques = new EffectTechniqueCollection(); Pool = effectPool ?? device.DefaultEffectPool; // Sets the effect name Name = effectData.Description.Name; // Register the bytecode to the pool var effect = Pool.RegisterBytecode(effectData); // Initialize from effect InitializeFrom(effect, null); // If everything was fine, then we can register it into the pool Pool.AddEffect(this); }