public override void LoadResources() { string base_path = (string)settings["Base.Path"]; // load effect string errors; effect = Effect.FromFile(device, base_path + "Media/Effects/Bloom-new.fx", null, null, ShaderFlags.None, null, out errors); if (errors.Length > 0) throw new Exception("HLSL compile error"); brightPass = effect.GetTechnique("std_BloomBrightPass"); blurPass = effect.GetTechnique("std_BlurPass"); finalPass = effect.GetTechnique("std_FinalPass"); bpQuad = new CustomVertex.TransformedTextured[4]; bpQuad[0].Tu = 0; bpQuad[0].Tv = 0; bpQuad[1].Tu = 1; bpQuad[1].Tv = 0; bpQuad[2].Tu = 0; bpQuad[2].Tv = 1; bpQuad[3].Tu = 1; bpQuad[3].Tv = 1; //testTexture = TextureLoader.FromFile(device, "c:/blurTest.bmp", 256, 128, 0, Usage.None, Format.X8R8G8B8, Pool.Managed, Filter.None, Filter.None, 0); }
public override void SetupForDevice(OutputSettings settings) { // pick techniques required string noiseType = "Turbulence"; string techStr = string.Format("noise{0}", noiseType); technique = effect.GetTechnique(techStr); }
public override void DoPostProcess() { base.DoPostProcess(); primaryNoiseMapTag = Open <bitmap>(shaderTransparentPlasmaValues.PrimaryNoiseMap.Value); secondaryNoiseMapTag = Open <bitmap>(shaderTransparentPlasmaValues.SecondaryNoiseMap.Value); if (MdxRender.Device.DeviceCaps.PixelShaderVersion.Major >= 2) { string shaderErrors = null; effect = Effect.FromStream(MdxRender.Device, System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("Games.Halo.Resources.Shaders.shader_transparent_plasma.fx"), null, null, ShaderFlags.None, null, out shaderErrors); if (!String.IsNullOrEmpty(shaderErrors)) { LogError("Failed to initialize shader_transparent_plasma effect: {0}", shaderErrors); } wvpHandle = effect.GetParameter(null, "worldViewProjection"); worldHandle = effect.GetParameter(null, "world"); cameraHandle = effect.GetParameter(null, "cameraPosition"); pIHandle = effect.GetParameter(null, "primaryI"); pJHandle = effect.GetParameter(null, "primaryJ"); pKHandle = effect.GetParameter(null, "primaryK"); sIHandle = effect.GetParameter(null, "secondaryI"); sJHandle = effect.GetParameter(null, "secondaryJ"); sKHandle = effect.GetParameter(null, "secondaryK"); offsetHandle = effect.GetParameter(null, "offset"); intensityHandle = effect.GetParameter(null, "intensity"); effect.SetValue(effect.GetParameter(null, "perpendicularBrightness"), shaderTransparentPlasmaValues.PerpendicularBrightness.Value); effect.SetValue(effect.GetParameter(null, "parallelBrightness"), shaderTransparentPlasmaValues.ParallelBrightness.Value); effect.SetValue(effect.GetParameter(null, "perpendicularColor"), new Vector4(shaderTransparentPlasmaValues.PerpendicularTintColor.R, shaderTransparentPlasmaValues.PerpendicularTintColor.G, shaderTransparentPlasmaValues.PerpendicularTintColor.B, 1.0f)); effect.SetValue(effect.GetParameter(null, "parallelColor"), new Vector4(shaderTransparentPlasmaValues.ParallelTintColor.R, shaderTransparentPlasmaValues.ParallelTintColor.G, shaderTransparentPlasmaValues.ParallelTintColor.B, 1.0f)); effect.SetValue(effect.GetParameter(null, "primaryScale"), shaderTransparentPlasmaValues.PrimaryNoiseMapScale.Value); effect.SetValue(effect.GetParameter(null, "secondaryScale"), shaderTransparentPlasmaValues.SecondaryNoiseMapScale.Value); if (primaryNoiseMapTag == null) { effect.SetValue(effect.GetParameter(null, "PrimaryMap"), default3d[Additive]); } else { effect.SetValue(effect.GetParameter(null, "PrimaryMap"), primaryNoiseMapTag[0]); } if (secondaryNoiseMapTag == null) { effect.SetValue(effect.GetParameter(null, "SecondaryMap"), default3d[Multiplicative]); } else { effect.SetValue(effect.GetParameter(null, "SecondaryMap"), secondaryNoiseMapTag[0]); } effect.Technique = technique = effect.GetTechnique("Plasma"); } }
internal ShaderTechnique(DeviceContext context, Shader shader, EffectHandle techniqueHandle) { TechniqueDescription desc = shader.Effect.GetTechniqueDescription(techniqueHandle); Handle = techniqueHandle; PassCount = desc.Passes; Name = desc.Name; Passes = new ShaderPassCollection(context, shader, this); }
public override void SetParameter(string name, Color parameter) { Math.Vector4 color = new Math.Vector4(parameter.R / 255.0f, parameter.G / 255.0f, parameter.B / 255.0f, parameter.A / 255.0f); EffectHandle param = getParameter(name); _effect.SetValue(param, color); }
public void Stop(EffectHandle handle) { var efx = GetEfx(handle); if (efx != null) { StopEffect(efx); } }
public MyEffectSolarMapGrid() : base("Effects2\\SolarSystemMap\\MySolarSystemMapGrid") { m_gridTexture = m_D3DEffect.GetParameter(null, "GridTexture"); m_colorA = m_D3DEffect.GetParameter(null, "ColorA"); m_alphaA = m_D3DEffect.GetParameter(null, "AlphaA"); m_worldMatrix = m_D3DEffect.GetParameter(null, "WorldMatrix"); m_viewProjectionMatrix = m_D3DEffect.GetParameter(null, "ViewProjectionMatrix"); }
public MyEffectAntiAlias() : base("Effects2\\Fullscreen\\MyEffectAntiAlias") { m_diffuse = m_D3DEffect.GetParameter(null, "DiffuseTexture"); m_fullPixel = m_D3DEffect.GetParameter(null, "FullPixel"); m_halfPixel = m_D3DEffect.GetParameter(null, "HalfPixel"); m_applyFxaa = m_D3DEffect.GetTechnique("ApplyFxaa"); m_noAntialiasing = m_D3DEffect.GetTechnique("NoAntialiasing"); }
public MyEffectVignetting() : base("Effects2\\Fullscreen\\MyEffectVignetting") { m_inputTexture = m_D3DEffect.GetParameter(null, "InputTexture"); m_halfPixel = m_D3DEffect.GetParameter(null, "HalfPixel"); m_vignettingPower = m_D3DEffect.GetParameter(null, "VignettingPower"); m_vignettingEnabled = m_D3DEffect.GetTechnique("VignettingEnabled"); m_vignettingDisabled = m_D3DEffect.GetTechnique("VignettingDisabled"); }
public MyEffectVoxelsDebris() : base("Effects2\\Voxels\\MyEffectVoxelsDebris") { m_worldMatrix = m_D3DEffect.GetParameter(null, "WorldMatrix"); m_viewWorldScaleMatrix = m_D3DEffect.GetParameter(null, "ViewWorldScaleMatrix"); m_textureCoordRandomPositionOffset = m_D3DEffect.GetParameter(null, "TextureCoordRandomPositionOffset"); m_textureCoordScale = m_D3DEffect.GetParameter(null, "TextureCoordScale"); m_diffuseTextureColorMultiplier = m_D3DEffect.GetParameter(null, "DiffuseTextureColorMultiplier"); }
private EffectHandle[] m_EffectHandle = new EffectHandle[EFFECT_MAX]; //!< エフェクト関連:エフェクトインスタンス管理 // MonoBehaviour 関連 #region <MonoBehaviour> protected override void Awake() { base.Awake(); for (int idx = 0; idx < m_EffectHandle.Length; idx++) { m_EffectHandle[idx] = new EffectHandle(); } }
public MyEffectSSAOBlur2() : base("Effects2\\SSAO\\MyEffectSSAOBlur2") { m_depthsRT = m_D3DEffect.GetParameter(null, "DepthsRT"); m_halfPixel = m_D3DEffect.GetParameter(null, "HalfPixel"); m_SSAOhalfPixel = m_D3DEffect.GetParameter(null, "SSAOHalfPixel"); m_ssaoRT = m_D3DEffect.GetParameter(null, "SsaoRT"); m_blurDirection = m_D3DEffect.GetParameter(null, "BlurDirection"); }
public void SetPaused(EffectHandle handle, bool paused) { var efx = GetEfx(handle); if (efx != null) { efx.SetPaused(paused); } }
public void Remove(EffectHandle handle) { var efx = GetEfx(handle); if (efx != null) { RemoveEffect(efx, wasDestroyed: false); } }
public MyEffectContrast() : base("Effects2\\Fullscreen\\MyEffectContrast") { m_diffuseTexture = m_D3DEffect.GetParameter(null, "DiffuseTexture"); m_contrast = m_D3DEffect.GetParameter(null, "Contrast"); m_hue = m_D3DEffect.GetParameter(null, "Hue"); m_saturation = m_D3DEffect.GetParameter(null, "Saturation"); m_halfPixel = m_D3DEffect.GetParameter(null, "HalfPixel"); }
public MyEffectVoxelsBase(string asset) : base(asset) { m_projectionMatrix = m_D3DEffect.GetParameter(null, "ProjectionMatrix"); m_textureDiffuseForAxisXZ = m_D3DEffect.GetParameter(null, "TextureDiffuseForAxisXZ"); m_textureDiffuseForAxisY = m_D3DEffect.GetParameter(null, "TextureDiffuseForAxisY"); m_textureNormalMapForAxisXZ = m_D3DEffect.GetParameter(null, "TextureNormalMapForAxisXZ"); m_textureNormalMapForAxisY = m_D3DEffect.GetParameter(null, "TextureNormalMapForAxisY"); m_textureDiffuseForAxisXZ2 = m_D3DEffect.GetParameter(null, "TextureDiffuseForAxisXZ2"); m_textureDiffuseForAxisY2 = m_D3DEffect.GetParameter(null, "TextureDiffuseForAxisY2"); m_textureNormalMapForAxisXZ2 = m_D3DEffect.GetParameter(null, "TextureNormalMapForAxisXZ2"); m_textureNormalMapForAxisY2 = m_D3DEffect.GetParameter(null, "TextureNormalMapForAxisY2"); m_textureDiffuseForAxisXZ3 = m_D3DEffect.GetParameter(null, "TextureDiffuseForAxisXZ3"); m_textureDiffuseForAxisY3 = m_D3DEffect.GetParameter(null, "TextureDiffuseForAxisY3"); m_textureNormalMapForAxisXZ3 = m_D3DEffect.GetParameter(null, "TextureNormalMapForAxisXZ3"); m_textureNormalMapForAxisY3 = m_D3DEffect.GetParameter(null, "TextureNormalMapForAxisY3"); m_specularIntensity = m_D3DEffect.GetParameter(null, "SpecularIntensity"); m_specularPower = m_D3DEffect.GetParameter(null, "SpecularPower"); m_specularIntensity2 = m_D3DEffect.GetParameter(null, "SpecularIntensity2"); m_specularPower2 = m_D3DEffect.GetParameter(null, "SpecularPower2"); m_specularIntensity3 = m_D3DEffect.GetParameter(null, "SpecularIntensity3"); m_specularPower3 = m_D3DEffect.GetParameter(null, "SpecularPower3"); m_lowTechnique = m_D3DEffect.GetTechnique("Technique_RenderQualityLow"); m_normalTechnique = m_D3DEffect.GetTechnique("Technique_RenderQualityNormal"); m_highTechnique = m_D3DEffect.GetTechnique("Technique_RenderQualityHigh"); m_extremeTechnique = m_D3DEffect.GetTechnique("Technique_RenderQualityExtreme"); m_normalMultimaterialTechnique = m_D3DEffect.GetTechnique("Technique_RenderQualityNormal_Multimaterial"); m_highMultimaterialTechnique = m_D3DEffect.GetTechnique("Technique_RenderQualityHigh_Multimaterial"); m_extremeMultimaterialTechnique = m_D3DEffect.GetTechnique("Technique_RenderQualityExtreme_Multimaterial"); m_normalFarTechnique = m_D3DEffect.GetTechnique("Technique_RenderQualityNormal_Far"); m_normalMultimaterialFarTechnique = D3DEffect.GetTechnique("Technique_RenderQualityNormal_Mulitmaterial_Far"); m_highFarTechnique = m_D3DEffect.GetTechnique("Technique_RenderQualityHigh_Far"); m_highMultimaterialFarTechnique = D3DEffect.GetTechnique("Technique_RenderQualityHigh_Mulitmaterial_Far"); m_extremeFarTechnique = m_D3DEffect.GetTechnique("Technique_RenderQualityExtreme_Far"); m_extremeMultimaterialFarTechnique = D3DEffect.GetTechnique("Technique_RenderQualityExtreme_Mulitmaterial_Far"); m_lowInstancedTechnique = m_D3DEffect.GetTechnique("Technique_RenderQualityLow_Instanced"); m_normalInstancedTechnique = m_D3DEffect.GetTechnique("Technique_RenderQualityNormal_Instanced"); m_highInstancedTechnique = m_D3DEffect.GetTechnique("Technique_RenderQualityHigh_Instanced"); m_extremeInstancedTechnique = m_D3DEffect.GetTechnique("Technique_RenderQualityExtreme_Instanced"); DynamicLights = new MyEffectDynamicLightingBase(m_D3DEffect); Reflector = new MyEffectReflectorBase(m_D3DEffect); }
public MyEffectHDRBase(string asset) : base(asset) { m_sourceMod = m_D3DEffect.GetParameter(null, "SourceTexture"); m_sourceDiv = m_D3DEffect.GetParameter(null, "SourceTextureDiv"); m_lumSource = m_D3DEffect.GetParameter(null, "LumTexture"); m_halfPixel = m_D3DEffect.GetParameter(null, "HalfPixel"); //m_middleGrey = m_xnaEffect.GetParameter(null, "MiddleGrey"); m_Exposure = m_D3DEffect.GetParameter(null, "Exposure"); }
public MyEffectComponentVoxelVertex(Effect effect) { m_effect = effect; m_cellOffset = effect.GetParameter(null, "VoxelVertex_CellOffset"); m_cellScale = effect.GetParameter(null, "VoxelVertex_CellScale"); m_cellRelativeCamera = effect.GetParameter(null, "VoxelVertex_CellRelativeCamera"); m_bounds = effect.GetParameter(null, "VoxelVertex_Bounds"); m_morphDebug = effect.GetParameter(null, "VoxelVertex_MorphDebug"); }
/// <summary> /// Primary Constructor. /// </summary> /// <param name="device">Copy of the device.</param> /// <param name="effect">Copy of the effect.</param> /// <param name="effectName">Name used for setting the texture in the shader.</param> /// <param name="effectBool">Name used for toggling the use of the texture in the shader.</param> public TextureClass(Device device, Effect effect, string effectName, string effectBool) { pathName = ""; this.device = device; this.effect = effect; textureEffectName = effectName; textureEffectBool = effectBool; enableTexture = false; technique = "PerPixel"; }
static EffectHandles() { foreach (FieldInfo field in typeof(EffectHandles).GetFields()) { if (field.IsStatic && field.FieldType == typeof(EffectHandle)) { field.SetValue(null, EffectHandle.FromString(field.Name)); } } }
private void Reset() { this.thread.Do(() => { ready.Reset(); Debug.WriteLine($"{GetHashCode()} getting write lock"); this.movieslock.LockWrite(); lock (this) { lock (this.videoframes) { this.videoframes.ForEach(_f => _f.OnLost()); } lock (this.renderframes) { this.renderframes.ForEach(_f => _f.OnLost()); } pp.BackBufferWidth = this.videosize.width; pp.BackBufferHeight = this.videosize.height; this.technique2.Dispose(); this.technique.Dispose(); this.effect3.Dispose(); this.effect2.Dispose(); this.presenteffect.Dispose(); this.device.DepthStencilSurface = this.olddepth; this.olddepth.Dispose(); this.depthtexture.Dispose(); this.depthsurface.Dispose(); device.Reset(pp); this.depthtexture = new Texture(this.device, 4096, 4096, 1, Usage.DepthStencil, Format.D24S8, Pool.Default); this.depthsurface = this.depthtexture.GetSurfaceLevel(0); this.olddepth = this.device.DepthStencilSurface; this.device.DepthStencilSurface = this.depthsurface; this.presenteffect = _LoadEffect("render"); this.effect2 = _LoadEffect("render2"); this.effect3 = _LoadEffect("render3"); // Compiles the effect // this.effect = Effect.FromFile(device, "render.fx", ShaderFlags.None); this.technique = presenteffect.GetTechnique(0); //this.effect2 = Effect.FromFile(device, "render2.fx", ShaderFlags.None); this.technique2 = effect2.GetTechnique(0); // Get the technique lock (this.videoframes) { this.videoframes.ForEach(_f => _f.OnReset()); } lock (this.renderframes) { this.renderframes.ForEach(_f => _f.OnReset()); } } this.movieslock.UnlockWrite(); ready.Set(); }); }
public MyEffectSpotShadowBase(string asset) : base(asset) { m_shadowBias = m_D3DEffect.GetParameter(null, "ShadowBias"); m_slopeBias = m_D3DEffect.GetParameter(null, "SlopeBias"); m_shadowMap = m_D3DEffect.GetParameter(null, "ShadowMap"); m_shadowMapSize = m_D3DEffect.GetParameter(null, "ShadowMapSize"); m_invViewMatrix = m_D3DEffect.GetParameter(null, "InvViewMatrix"); m_lightViewProjectionShadow = m_D3DEffect.GetParameter(null, "LightViewProjectionShadow"); }
public void SetShaderTexture(int stage, BaseTexture texture) { if (shaderEnabled && effect != null) { EffectHandle handle = stage == 0 ? EffectHandle.FromString("tex") : EffectHandle.FromString("lightmap"); effect.SetValue(handle, texture); } }
public void SetTechnique(string techniqueName) { if (effect != null) { EffectHandle techniqueHandle = effect.GetTechnique(techniqueName); if (techniqueHandle != null) { effect.Technique = techniqueHandle; } } }
public static float FindAnnotationFloat(Effect effect, EffectHandle handle, string name) { if (effect == null) { throw new ArgumentNullException(nameof(effect)); } if (handle == null) { throw new ArgumentNullException(nameof(handle)); } if (string.IsNullOrEmpty(name)) { throw new ArgumentNullException(nameof(name)); } ParameterDescription paramDesc = effect.GetParameterDescription(handle); for (int i = 0; i < paramDesc.Annotations; i++) { EffectHandle annotationHandle = effect.GetAnnotation(handle, i); if (annotationHandle != null) { ParameterDescription annotationDesc = effect.GetParameterDescription(annotationHandle); if (StringUtils.EqualsIgnoreCase(annotationDesc.Name, name)) { try { switch (annotationDesc.Type) { case ParameterType.String: return(float.Parse(effect.GetString(annotationHandle), CultureInfo.InvariantCulture)); case ParameterType.Int: return(effect.GetValue <int>(annotationHandle)); case ParameterType.Float: return(effect.GetValue <float>(annotationHandle)); case ParameterType.Bool: return(effect.GetValue <bool>(annotationHandle) ? 1.0f : 0.0f); default: return(0.0f); } } catch (Direct3D9Exception) { return(0.0f); } } } } return(0.0f); }
/// <summary> /// 全エフェクト停止 /// </summary> public void stopEffectAll() { for (int idx = 0; idx < m_EffectHandle.Length; idx++) { EffectHandle effect_handle = m_EffectHandle[idx]; if (effect_handle.m_PoolInfo != null) { unuseEffectHandle(effect_handle); } } }
public MyEffectVoxels() : base("Effects2\\Voxels\\MyEffectVoxels") { m_viewMatrix = m_D3DEffect.GetParameter(null, "ViewMatrix"); m_voxelMapPosition = m_D3DEffect.GetParameter(null, "VoxelMapPosition"); m_diffuseColor = m_D3DEffect.GetParameter(null, "DiffuseColor"); m_highlightColor = m_D3DEffect.GetParameter(null, "Highlight"); m_worldMatrix = m_D3DEffect.GetParameter(null, "WorldMatrix"); m_enablePerVertexAmbient = m_D3DEffect.GetParameter(null, "EnablePerVertexAmbient"); }
public MyEffectLuminance() : base("Effects2\\HDR\\MyEffectLuminance") { m_DT = m_D3DEffect.GetParameter(null, "DT"); m_Tau = m_D3DEffect.GetParameter(null, "Tau"); m_MipLevel = m_D3DEffect.GetParameter(null, "MipLevel"); m_SourceTexture2 = m_D3DEffect.GetParameter(null, "SourceTexture2"); m_luminance = m_D3DEffect.GetTechnique("Luminance"); m_calcAdaptedLuminance = m_D3DEffect.GetTechnique("CalcAdaptedLuminance"); m_luminanceMipmap = m_D3DEffect.GetTechnique("LuminanceMipmap"); }
public EffectHandle getEffectParam(string paramName) { EffectHandle eh = mShader.GetParameter(null, paramName); if (eh == null) { MessageBox.Show("EffectParam " + paramName + " not found in file " + mFilename); } return(eh); }
internal ShaderPass(DeviceContext context, Shader shader, EffectHandle passHandle, int index) { Shader = shader; Effect = shader.Effect; Handle = passHandle; // TODO: Correct assignment, or reserved for a different handle? Context = context; Index = index; PassDescription desc = shader.Effect.GetPassDescription(passHandle); Name = desc.Name; }
/// <summary> /// エフェクト停止 /// </summary> /// <param name="handle_name">エフェクトハンドリング用の識別名</param> public void stopEffect(string handle_name) { for (int idx = 0; idx < m_EffectHandle.Length; idx++) { EffectHandle effect_handle = m_EffectHandle[idx]; if (effect_handle.m_PoolInfo != null && effect_handle.m_HandleName == handle_name) { unuseEffectHandle(effect_handle); } } }
public MyEffectScale() : base("Effects2\\HDR\\MyEffectScale") { m_sourceDimensions = m_D3DEffect.GetParameter(null, "SourceDimensions"); m_scale = m_D3DEffect.GetParameter(null, "Scale"); //m_downscale = m_xnaEffect.GetTechnique("Downscale"]; //m_downscaleLuminance = m_xnaEffect.Technique = m_xnaEffect.GetTechnique("DownscaleLuminance"]; m_HWScale = m_D3DEffect.Technique = m_D3DEffect.GetTechnique("HWScale"); m_HWScalePrefabPreviews = m_D3DEffect.Technique = m_D3DEffect.GetTechnique("HWScalePrefabPreviews"); m_downscale8 = m_D3DEffect.Technique = m_D3DEffect.GetTechnique("Downscale8"); m_downscale4 = m_D3DEffect.Technique = m_D3DEffect.GetTechnique("Downscale4"); }
private void GenerateTexture(ref Texture texture, int width, int height, EffectHandle function) { texture = new Texture(device, width, height, 1, Usage.RenderTarget, Format.X8R8G8B8, Pool.Default); device.SetRenderTarget(0, texture.GetSurfaceLevel(0)); device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.Black, 1, 0); device.BeginScene(); device.EndScene(); device.Present(); }
/// <summary> /// Set the current technique, given a handle /// </summary> /// <param name="technique"></param> public static void SetTechnique(EffectHandle tech) { try { effect.ValidateTechnique(tech); } catch { tech = effect.FindNextValidTechnique(tech); //Debug.WriteLine("Using fallback technique: "+effect.GetTechniqueDescription(tech).Name); } effect.Technique = tech; }
public CellTexCreator(int Res) { texBanks = new System.Collections.Generic.List<TextureBank>(); //Create basic vertex buffer that can be used for all cells which has positions and texture coordinates vBuffer = new VertexBuffer(typeof(CellVertex), 4225, DXMain.device, Usage.WriteOnly, CellVertex.Format, Pool.Managed); CellVertex[] CellData = (CellVertex[])vBuffer.Lock(0, LockFlags.None); float mult = (float)(Res / 64); for(int y=0;y<=64;y++) { for(int x=0;x<=64;x++) { //Figure out which index to use int i = y * 65 + x; //Write values CellData[i].x = ((float)x / 64.0f) * 2.0f - 1.0f; CellData[i].y = ((float)y / 64.0f) * 2.0f - 1.0f; CellData[i].z = 0.5f; CellData[i].w = 1.0f; CellData[i].u = (float)x / 16.0f; CellData[i].v = (float)y / 16.0f; } } vBuffer.Unlock(); //Create triangle strip index buffer //Size is 2r + 2rc + 2(r-1) where r is rows and c is colums (squares, not vertices) iBuffer = new IndexBuffer(typeof(Int16), 8446, DXMain.device, Usage.WriteOnly, Pool.Managed); Int16[] iBuf = (Int16[])iBuffer.Lock(0, LockFlags.None); int idx = 0; for(int y=0;y<64;y++) { //If this is is a continuation strip, we need to add two extra vertices to create degenerat triangles //and get us back to the left side if ( y > 0 ) { iBuf[idx] = (Int16)(y * 65 + (63+1)); iBuf[idx + 1] = (Int16)(y * 65 + 0); idx += 2; } //Start the row off with a vertex in the lower left corner of the square iBuf[idx] = (Int16)(y * 65 + 0); ++idx; for(int x=0;x<64;x++) { //Add the top left and bottom right vertex of each square iBuf[idx] = (Int16)((y+1) * 65 + x); iBuf[idx + 1] = (Int16)(y * 65 + (x+1)); idx += 2; } //End the row with the top right vertex iBuf[idx] = (Int16)((y+1) * 65 + (63+1)); ++idx; } iBuffer.Unlock(); //Create the buffers that will contain different information during each render colorBuffer = new VertexBuffer(typeof(NormalColorVertex), 4225, DXMain.device, Usage.WriteOnly, NormalColorVertex.Format, Pool.Managed); ResetColorsAndNormals(); RenderTargetTex=new Texture(DXMain.device, Res, Res, 0, Usage.RenderTarget, Format.X8R8G8B8, Pool.Default); CompressedTex=new Texture(DXMain.device, Res, Res, 0, Usage.None, Format.Dxt1, Pool.SystemMemory); RenderTarget=RenderTargetTex.GetSurfaceLevel(0); effect=Effect.FromFile(DXMain.device, EffectPath, null, null, ShaderFlags.NotCloneable, null); m1h = effect.GetParameter(null, "transform"); t1h = effect.GetParameter(null, "t1"); t2h = effect.GetParameter(null, "t2"); t3h = effect.GetParameter(null, "t3"); t4h = effect.GetParameter(null, "t4"); }
public override void SetupForDevice(OutputSettings settings) { technique = effect.GetTechnique("outlinePerPixel"); }
/// <summary> /// Load the effect file & initialise everything /// </summary> public static void Load(Device device, ShaderFlags shaderFlags) { string err = ""; // shader compiler errors // Find and load the file try { string path = Utility.FindMediaFile("Simbiosis.fx"); effect = ResourceCache.GetGlobalInstance().CreateEffectFromFile(device, path, null, null, shaderFlags, null, out err); if (effect == null) throw new Exception("effect = null"); } catch (Exception e) { Debug.WriteLine("========================================================================================="); Debug.WriteLine("Unable to compile Effect file." + e.ToString()); Debug.WriteLine(err); Debug.WriteLine("========================================================================================="); throw e; } // Set up handles for the globals matDiffuse = effect.GetParameter(null, "matDiffuse"); matSpecular = effect.GetParameter(null, "matSpecular"); matEmissive = effect.GetParameter(null, "matEmissive"); matAmbient = effect.GetParameter(null, "matAmbient"); baseTexture = effect.GetParameter(null, "baseTexture"); bumpTexture = effect.GetParameter(null, "bumpTexture"); world = effect.GetParameter(null, "world"); worldViewProjection = effect.GetParameter(null, "worldViewProjection"); eyePosition = effect.GetParameter(null, "eyePosition"); isTextured = effect.GetParameter(null, "isTextured"); isBump = effect.GetParameter(null, "isBump"); isShadowed = effect.GetParameter(null, "isShadowed"); isSpotlit = effect.GetParameter(null, "isSpotlit"); spotVP = effect.GetParameter(null, "spotVP"); spotTexture = effect.GetParameter(null, "spotTexture"); spotPosition = effect.GetParameter(null, "spotPosition"); causticTexture = effect.GetParameter(null, "causticTexture"); envTexture = effect.GetParameter(null, "envTexture"); shadowTexture = effect.GetParameter(null, "shadowTexture"); shadowMatrix = effect.GetParameter(null, "shadowMatrix"); // and the techniques mainTechnique = effect.GetTechnique("Main"); sceneryTechnique = effect.GetTechnique("Scenery"); waterTechnique = effect.GetTechnique("Water"); skyboxTechnique = effect.GetTechnique("Skybox"); shadowTechnique = effect.GetTechnique("Shadow"); markerTechnique = effect.GetTechnique("Marker"); // Set once-only shader constants effect.SetValue("sunPosition",new Vector4(512,1000,512,0)); // sun's position (.W is ignored - float3 in shader) effect.SetValue("ambient", new ColorValue(255, 255, 255)); // amount/colour of ambient skylight effect.SetValue("sunlight", new ColorValue(255, 255, 255)); // colour/brightness of sunlight // Set up the projection matrix for shadows, based on sun position sunProj = Matrix.OrthoLH(100, 100, 0, 1000); // adjust width, height if necc effect.SetValue("sunProj", sunProj); SetCameraData(); // also set up the (variable) view matrix // Set up the projection matrix for caustics Matrix caustic = Matrix.Invert( // "view" matrix Matrix.Translation(new Vector3(0, Water.WATERLEVEL, 0)) // caustics start at water level * Matrix.RotationYawPitchRoll(0, (float)Math.PI/2, 0) // looking down ) // Proj matrix (orthogonal) * Matrix.OrthoLH(80, 80, 0, 1000); // adjust width, height effect.SetValue("causticMatrix", caustic); }
/// <summary> /// This event will be fired immediately after the Direct3D device has been /// created, which will happen during application initialization and windowed/full screen /// toggles. This is the best location to create Pool.Managed resources since these /// resources need to be reloaded whenever the device is destroyed. Resources created /// here should be released in the Disposing event. /// </summary> private void OnCreateDevice(object sender, DeviceEventArgs e) { // Setup direction widget DirectionWidget.OnCreateDevice(e.Device); // Initialize the stats font statsFont = ResourceCache.GetGlobalInstance().CreateFont(e.Device, 15, 0, FontWeight.Bold, 1, false, CharacterSet.Default, Precision.Default, FontQuality.Default, PitchAndFamily.FamilyDoNotCare | PitchAndFamily.DefaultPitch , "Arial"); // Read the D3DX effect file string path = "NifViewer.fx"; string errors; effect = ResourceCache.GetGlobalInstance().CreateEffectFromFile(e.Device, path, null, null, ShaderFlags.NotCloneable, null, out errors); if(effect==null) { MessageBox.Show("Effects.fx Shader compilation failed.\n"+errors, "Error"); } ehLightDir=effect.GetParameter(null, "g_LightDir"); ehLightCol=effect.GetParameter(null, "g_LightDiffuse"); egAmbCol=effect.GetParameter(null, "g_LightAmbient"); ehViewProj=effect.GetParameter(null, "viewProjection"); ehEyePos=effect.GetParameter(null, "eyePos"); ehEyeVec=effect.GetParameter(null, "eyeVec"); ehHalfVec=effect.GetParameter(null, "g_LightHalfVec"); NifFile.SetEffect(effect); // Setup the camera's view parameters camera.SetViewParameters(new Vector3(0.0f, 0.0f, -15.0f), Vector3.Empty); camera.IsPositionMovementEnabled=true; NifFile.SetCamera(camera); lightControl.Radius = 10; camera.SetRadius(30.0f, 0, 100.0f); }
public override void SetupForDevice(OutputSettings settings) { // pick techniques required bool texture = true; bool spec = true; string lightType = "Dir"; string techStr = string.Format("std_basic{0}Light{1}Spec{2}Texture", lightType, spec ? "" : "No", texture ? "" : "No"); if (lod == 0) { technique = effect1.GetTechnique(techStr); lineTechnique = effect1.GetTechnique(techStr + "Line"); alphaTechnique = effect1.GetTechnique("std_basicAlphaTexture"); } else if (lod == 1) { technique = effect2.GetTechnique(techStr); lineTechnique = effect2.GetTechnique(techStr + "Line"); alphaTechnique = effect2.GetTechnique("std_basicAlphaTexture"); } }
private void LoadSurfaceShaders() { shaders.Clear(); Libx42.Model m = model.Model; if( m == null ) return; Device device = pn3D.Device; string errs; shadedEffect = Effect.FromFile( device, Path.Combine( Application.StartupPath, "Media/ShadedPreview.fx" ), null, null, ShaderFlags.None, null, out errs ); ehMv = shadedEffect.GetParameterBySemantic( null, "MODELVIEW" ); ehMvp = shadedEffect.GetParameterBySemantic( null, "MODELVIEWPROJECTION" ); ehCamPos = shadedEffect.GetParameterBySemantic( null, "CAMERAPOSITION" ); ehAmbient = shadedEffect.GetParameterBySemantic( null, "LIGHTAMBIENT" ); shaderLights = ShaderLight.GetLights( shadedEffect ); ehBumpUnpack = shadedEffect.GetParameterBySemantic( null, "BUMPUNPACK" ); defaultDiffuse = TextureLoader.FromFile( device, Path.Combine( Application.StartupPath, "Media/DefaultDiffuse.bmp" ), 0, 0, 0, Usage.None, Format.Unknown, Pool.Managed, Filter.Box, Filter.Box, 0 ); defaultNormal = TextureLoader.FromFile( device, Path.Combine( Application.StartupPath, "Media/DefaultNormal.bmp" ), 0, 0, 0, Usage.None, Format.Unknown, Pool.Managed, Filter.Box, Filter.Box, 0 ); foreach( Libx42.Group g in m.Groups ) { if( shaders.ContainsKey( g.MaterialName ) ) continue; SurfaceShader shader = LoadSurfaceShader( g.MaterialName ); if( shader != null ) shaders.Add( g.MaterialName, shader ); } surfaceShadersLoaded = true; }
/// <summary> /// Primary Constructor. /// </summary> /// <param name="device">Copy of the device.</param> /// <param name="effect">Copy of the effect.</param> /// <param name="effectName">Name used for setting the texture in the shader.</param> /// <param name="effectBool">Name used for toggling the use of the texture in the shader.</param> public TextureClass(Device device, Effect effect, string effectName, string effectBool) { pathName = ""; this.device = device; this.effect = effect; textureEffectName = effectName; textureEffectBool = effectBool; enableTexture = false; technique = "PerPixel"; }
public override void LoadResources() { string base_path = (string)settings["Base.Path"]; string errors; pEffect = Effect.FromFile(device, base_path + "Media/Effects/Blobs.fx", null, null, ShaderFlags.NotCloneable, null, out errors); if (errors.Length > 0) throw new Exception("HLSL compile error"); // Initialize the technique for blending if (nPasses == 1) { // Multiple RT available hBlendTech = pEffect.GetTechnique("BlobBlend"); } else { // Single RT. Multiple passes. hBlendTech = pEffect.GetTechnique("BlobBlendTwoPasses"); } // Create the environment map pEnvMap = TextureLoader.FromCubeFile(device, base_path + "Media/Effects/LobbyCube.dds"); }
public override void Render() { using (var modelBBoxOffSet = new EffectHandle("ModelBBoxOffSet")) using (var modelBBoxScale = new EffectHandle("ModelBBoxScale")) { foreach (Mesh mesh in this.meshes) { if (this.RenderSettings.IsSkinning) { this.RenderSettings.Skeleton.LoadMatrices(mesh.BoneIds); } this.RenderSettings.ShaderManager.SetEffect(mesh.ShaderName, this.varEquip, mesh.MeshHeader.Unknown4); this.Device.VertexShader.Function.ConstantTable.SetValue(this.Device, modelBBoxOffSet, bboxOffset); this.Device.VertexShader.Function.ConstantTable.SetValue(this.Device, modelBBoxScale, bboxScale); mesh.Render(); } } }
private void InitializeGraphics() { Cursor.Hide(); PresentParameters presentParams = new PresentParameters(); presentParams.Windowed = ! FullScreen; presentParams.SwapEffect = SwapEffect.Discard; presentParams.AutoDepthStencilFormat = DepthFormat.D24X8; presentParams.EnableAutoDepthStencil = true; // If we want a Fullscreen device we need to set up a backbuffer if ( FullScreen) { presentParams.BackBufferCount = 1; presentParams.BackBufferFormat = Format.X8R8G8B8; presentParams.BackBufferWidth = 800; presentParams.BackBufferHeight = 600; } Caps hardware = Manager.GetDeviceCaps(0, DeviceType.Hardware); CreateFlags flags = CreateFlags.SoftwareVertexProcessing; if (hardware.DeviceCaps.SupportsHardwareTransformAndLight) flags = CreateFlags.HardwareVertexProcessing; if (hardware.DeviceCaps.SupportsPureDevice) flags |= CreateFlags.PureDevice; // Pixelshader 2.0 is required // If not available create a Reference device ( must have SDK installed ) if (hardware.PixelShaderVersion >= new Version(2,0) && hardware.VertexShaderVersion >= new Version(1,1)) device = new Device(0, DeviceType.Hardware, this, flags, presentParams); else device = new Device(0, DeviceType.Reference, this, flags, presentParams); String s = null; effect = Effect.FromFile(device, @"shader.fx", null,null,ShaderFlags.None, null, out s); //if ( s != null) //{ // // There are Compilation errors show them and then close app // Cursor.Show(); // device.Dispose(); // this.Visible = false; // MessageBox.Show(s); // return; //} effect.Technique = "TransformTexture"; projMatrix = Matrix.PerspectiveFovLH((float)Math.PI/4f, this.Width / this.Height, 1f, 250f); t1 = TextureLoader.FromFile(device,@"..\..\grass.bmp"); t2 = TextureLoader.FromFile(device,@"..\..\rock.bmp"); effect.SetValue("Texture1", t1); effect.SetValue("Texture2", t2); handle1 = effect.GetParameter(null,"ambient"); handle2 = effect.GetParameter(null,"WorldViewProj"); handle3 = effect.GetParameter(null,"light"); t = new Terrain(device,0,28); font = new Microsoft.DirectX.Direct3D.Font(device,new System.Drawing.Font("Arial",18)); }
public static void SetEffect(Effect _effect) { effect=_effect; if(effect!=null) { ehWorld=effect.GetParameter(null, "worldMatrix"); ehIWorld=effect.GetParameter(null, "iWorld"); ehNormalMatrix=effect.GetParameter(null, "normalMatrix"); ehWorldView=effect.GetParameter(null, "worldView"); ehWorldViewProj=effect.GetParameter(null, "worldViewProj"); ehTexture=effect.GetParameter(null, "colorMap"); ehGlowMap=effect.GetParameter(null, "glowMap"); ehNormalMap=effect.GetParameter(null, "normalMap"); ehMaterialAmb=effect.GetParameter(null, "g_MaterialAmbientColor"); ehMaterialDif=effect.GetParameter(null, "g_MaterialDiffuseColor"); ehMaterialSpec=effect.GetParameter(null, "g_MaterialSpecularColor"); ehMaterialEmm=effect.GetParameter(null, "g_MaterialEmissiveColor"); ehMaterialGloss=effect.GetParameter(null, "g_MaterialGloss"); ehMaterialAlpha=effect.GetParameter(null, "g_MaterialAlpha"); ehUseSpecular=effect.GetParameter(null, "use_specular"); ehUseGlow=effect.GetParameter(null, "use_glow"); ehUseDiffuseVColor=effect.GetParameter(null, "use_dvcolor"); ehUseEmissiveVColor=effect.GetParameter(null, "use_evcolor"); ehUseExplicitAlpha=effect.GetParameter(null, "use_alpha"); } }
public void SetEffectParameters(Effect effect,EffectHandle[] handles) { if(handles[0]!=null) effect.SetValue("CameraPosition", CameraPosition); if (handles[1] != null) effect.SetValue("CameraUp",CameraUp); if (handles[2] != null) effect.SetValue("CameraLook", CameraLook); if (handles[3] != null) effect.SetValue("CameraVelocity", CameraVelocity); if (handles[4] != null) effect.SetValue("CameraAcceleration", CameraAcceleration); if (handles[5] != null) effect.SetValue("World", World); if (handles[6] != null) effect.SetValue("View", View); if (handles[7] != null) effect.SetValue("Projection", Projection); if (handles[8] != null) effect.SetValue("WorldView", WorldView); if (handles[9] != null) effect.SetValue("WorldViewProjection", WorldViewProjection); if (handles[10] != null) effect.SetValue("WorldI", WorldI); if (handles[11] != null) effect.SetValue("WorldIT", WorldIT); if (handles[12] != null) effect.SetValue("LightDirection", LightDirection); if (handles[13] != null) effect.SetValue("LightColor", LightColor); }
public WrappedEffectHandle(EffectHandle effectHandle) { EffectHandle = effectHandle; }
protected void ProcessParamElement( ConstantTable constantTable, EffectHandle parent, string prefix, int index ) { var constant = constantTable.GetConstant( parent, index ); // Since D3D HLSL doesn't deal with naming of array and struct parameters // automatically, we have to do it by hand var desc = constantTable.GetConstantDescription( constant ); var paramName = desc.Name; // trim the odd '$' which appears at the start of the names in HLSL if ( paramName.StartsWith( "$" ) ) { paramName = paramName.Remove( 0, 1 ); } // Also trim the '[0]' suffix if it exists, we will add our own indexing later if (paramName.EndsWith("[0]")) { paramName.Remove( paramName.Length - 3 ); } if (desc.Class == ParameterClass.Struct) { // work out a new prefix for the nextest members if its an array, we need the index prefix = prefix + paramName + "."; // Cascade into struct for (var i = 0; i < desc.StructMembers; ++i) { ProcessParamElement(constantTable, constant, prefix, i); } } else { // process params if ( desc.Type == ParameterType.Float || desc.Type == ParameterType.Int || desc.Type == ParameterType.Bool ) { var paramIndex = desc.RegisterIndex; var name = prefix + paramName; var def = new GpuProgramParameters.GpuConstantDefinition(); def.LogicalIndex = paramIndex; // populate type, array size & element size PopulateDef( desc, def ); if ( def.IsFloat ) { def.PhysicalIndex = floatLogicalToPhysical.BufferSize; lock ( floatLogicalToPhysical.Mutex ) { floatLogicalToPhysical.Map.Add( paramIndex, new GpuProgramParameters.GpuLogicalIndexUse( def.PhysicalIndex, def.ArraySize*def.ElementSize, GpuProgramParameters.GpuParamVariability.Global ) ); floatLogicalToPhysical.BufferSize += def.ArraySize*def.ElementSize; } } else { def.PhysicalIndex = intLogicalToPhysical.BufferSize; lock ( intLogicalToPhysical.Mutex ) { intLogicalToPhysical.Map.Add( paramIndex, new GpuProgramParameters.GpuLogicalIndexUse( def.PhysicalIndex, def.ArraySize*def.ElementSize, GpuProgramParameters.GpuParamVariability.Global ) ); intLogicalToPhysical.BufferSize += def.ArraySize*def.ElementSize; } } if ( !parametersMap.ContainsKey( paramName ) ) { parametersMap.Add( paramName, def ); /* parametersMapSizeAsBuffer += sizeof ( int ); parametersMapSizeAsBuffer += paramName.Length; parametersMapSizeAsBuffer += Marshal.SizeOf( def ); */ } } } }
protected string textureEffectName; // String used for setting the texture in the shader. #endregion Fields #region Constructors /// <summary> /// Default constructor for use with child classes. /// </summary> public TextureClass() { enableTexture = false; technique = "PerPixel"; }
private void UnloadSurfaceShaders() { ehBumpUnpack = null; shaderLights = null; ehAmbient = null; ehCamPos = null; ehMv = null; ehMvp = null; Helpers.DisposeAndClear( ref defaultNormal ); Helpers.DisposeAndClear( ref defaultDiffuse ); Helpers.DisposeAndClear( ref shadedEffect ); foreach( SurfaceShader shd in shaders.Values ) shd.UnloadTextures(); shaders.Clear(); surfaceShadersLoaded = false; }
EffectHandle EH(SlimDX.Direct3D9.Effect effect, String name) { Dictionary<String, EffectHandle> d; if (!hanldes.TryGetValue(effect, out d)) hanldes[effect] = d = new Dictionary<string, EffectHandle>(); EffectHandle h; if (d.TryGetValue(name, out h)) return h; else return d[name] = new EffectHandle(name); }
public ShaderLight( Effect fx, EffectHandle elem ) { this.fx = fx; diffuse = fx.GetParameterBySemantic( elem, "DIFFUSE" ); ndlBias = fx.GetParameterBySemantic( elem, "NDLBIAS" ); specular = fx.GetParameterBySemantic( elem, "SPECULAR" ); specSharpness = fx.GetParameterBySemantic( elem, "SPECULARSHARPNESS" ); direction = fx.GetParameterBySemantic( elem, "DIRECTION" ); }
EffectHandle EH(String name) { EffectHandle h; if (hanldes.TryGetValue(name, out h)) return h; else return hanldes[name] = new EffectHandle(name); }
protected static bool FindAnnotationString(Effect effect, EffectHandle parameterHandle, string name, ref string ret) { ParameterDescription paramDesc = effect.GetParameterDescription(parameterHandle); for (int i = 0; i < paramDesc.Annotations; i++) { EffectHandle annotationHandle = effect.GetAnnotation(parameterHandle, i); if (annotationHandle != null) /* <-- Here, is this possible? */ { ParameterDescription annotationDesc = effect.GetParameterDescription(annotationHandle); if (annotationDesc.Type == ParameterType.String && string.Compare(annotationDesc.Name, name, true) == 0) { ret = effect.GetValueString(annotationHandle); return true; } } } return false; }
public void Free() { if (_handleTechnique != null) _handleTechnique.Dispose(); if (_handleTexture != null) _handleTexture.Dispose(); if (_handleWorldProjection != null) _handleWorldProjection.Dispose(); _handleTechnique = null; _handleWorldProjection = null; _handleTexture = null; if (_effect != null) { _effect.Dispose(); _effect = null; } }
public bool Allocate() { string[] files = _effectName.Split(';'); if (files.Length == 0) return false; StringBuilder effectShader = new StringBuilder(8196); Version vertexShaderVersion = GraphicsDevice.Device.Capabilities.VertexShaderVersion; Version pixelShaderVersion = GraphicsDevice.Device.Capabilities.PixelShaderVersion; for (int i = files.Length-1; i >= 0; --i) { string effectFilePath = SkinContext.SkinResources.GetResourceFilePath(string.Format(@"{0}\{1}.fx", SkinResources.SHADERS_DIRECTORY, files[i])); if (effectFilePath == null || !File.Exists(effectFilePath)) { if (!_fileMissing) ServiceRegistration.Get<ILogger>().Error("Effect file {0} does not exist", effectFilePath); _fileMissing = true; return false; } _fileMissing = false; using (StreamReader reader = new StreamReader(effectFilePath)) effectShader.Append(reader.ReadToEnd()); // Concatenate effectShader.Append(Environment.NewLine); } effectShader.Replace("vs_2_0", String.Format("vs_{0}_{1}", vertexShaderVersion.Major, vertexShaderVersion.Minor)); effectShader.Replace("ps_2_0", String.Format("ps_{0}_{1}", pixelShaderVersion.Major, pixelShaderVersion.Minor)); // We place the lock here to comply to the MP2 multithreading guideline - we are not allowed to request the // effect resources when holding our lock lock (_syncObj) { if (_effect != null) return true; string errors = string.Empty; try { const ShaderFlags shaderFlags = ShaderFlags.OptimizationLevel3 | ShaderFlags.EnableBackwardsCompatibility; //| ShaderFlags.NoPreshader; _effect = Effect.FromString(GraphicsDevice.Device, effectShader.ToString(), null, null, null, shaderFlags, null, out errors); _handleWorldProjection = _effect.GetParameter(null, PARAM_WORLDVIEWPROJ); _handleTexture = _effect.GetParameter(null, PARAM_TEXTURE); _handleTechnique = _effect.GetTechnique(0); return true; } catch { ServiceRegistration.Get<ILogger>().Error("EffectAsset: Unable to load '{0}'", _effectName); ServiceRegistration.Get<ILogger>().Error("EffectAsset: Errors: {0}", errors); return false; } } }
/// <summary> /// Renders the scene. /// </summary> public void RenderScene(Color background, List<LightObj> lights, Camera camera) { bool useGlow = false; // Sets the variables for the shader. SetVariables(lights, camera); //effect.Technique = "Test"; for (int i = 0; i < mesh.Count; i++) { if (mesh[i].Emissive.Enable && !mesh[i].Emissive.Path.Equals("")) { useGlow = true; break; } } // If/Else statement to control rendering with emissive glow or not. if (useGlow) RenderGlow(); else BeginRender(background); // If emissive glow is used, the base scene is rendered to a texture. if (useGlow) { surfRender.BeginScene(renderedScene.GetSurfaceLevel(0), device.Viewport); device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, background, 1.0f, 0); } if (groundPlane.Enabled) RenderModel((Model)groundPlane, lights[0].Shadows, 0); // Loops through all the models and renders each. for (int i = 0; i < mesh.Count; i++) { if (mesh[i].Enabled) RenderModel(mesh[i], lights[0].Shadows, 0); } if (showLights) { using (Sprite spriteobject = new Sprite(device)) { foreach (LightObj light in lights) { if (!light.Enabled) continue; spriteobject.SetWorldViewRH(device.Transform.World, device.Transform.View); spriteobject.Begin(SpriteFlags.AlphaBlend | SpriteFlags.Billboard | SpriteFlags.SortTexture | SpriteFlags.ObjectSpace); //spriteobject.Transform = Matrix.Scaling(0.25f, 0.25f, 0.25f); spriteobject.Draw(lightTexture, Rectangle.Empty, Vector3.Empty, light.Direction, Color.White); spriteobject.End(); } } } // If emissive glow is used, the textures are set to the shader and rendered to a sprite. if (useGlow) { surfRender.EndScene(Filter.None); effect.SetValue("renderedScene", renderedScene); BeginRender(background); using (Sprite spriteobject = new Sprite(device)) { prevTechnique = effect.Technique; effect.Technique = "Bloom"; effect.Begin(FX.None); spriteobject.Begin(SpriteFlags.None); effect.BeginPass(0); spriteobject.Draw(renderedGlow, Rectangle.Empty, new Vector3(0, 0, 0), new Vector3(0, 0, 0), Color.White); effect.EndPass(); spriteobject.End(); effect.End(); effect.Technique = prevTechnique; } } EndRender(); }
public EffectHandle[] GetParameters(Effect effect) { EffectHandle[] handles = new EffectHandle[14]; handles[0] = effect.GetParameter(null, "CameraPosition"); handles[1] = effect.GetParameter(null, "CameraUp"); handles[2] = effect.GetParameter(null, "CameraLook"); handles[3] = effect.GetParameter(null, "CameraVelocity"); handles[4] = effect.GetParameter(null, "CameraAcceleration"); handles[5] = effect.GetParameter(null, "World"); handles[6] = effect.GetParameter(null, "View"); handles[7] = effect.GetParameter(null, "Projection"); handles[8] = effect.GetParameter(null, "WorldView"); handles[9] = effect.GetParameter(null, "WorldViewProjection"); handles[10] = effect.GetParameter(null, "WorldI"); handles[11] = effect.GetParameter(null, "WorldIT"); handles[12] = effect.GetParameter(null, "LightDirection"); handles[13] = effect.GetParameter(null, "LightColor"); return handles; }