private void BuildFX() { var shaderFlags = ShaderFlags.None; #if DEBUG shaderFlags |= ShaderFlags.Debug; shaderFlags |= ShaderFlags.SkipOptimization; #endif string errors = null; ShaderBytecode compiledShader = null; try { //compiledShader = new ShaderBytecode(new DataStream(File.ReadAllBytes("fx/color.fxo"), false, false)); //_fx = new Effect(Device, compiledShader); Core.FX.IncludeFX includeFX = new Core.FX.IncludeFX(); compiledShader = ShaderBytecode.CompileFromFile("FX/color.fx", null, "fx_5_0", shaderFlags, EffectFlags.None, null, includeFX, out errors); _fx = new Effect(Device, compiledShader); } catch (Exception ex) { MessageBox.Show(ex.Message); return; } finally { Util.ReleaseCom(ref compiledShader); } _tech = _fx.GetTechniqueByName("ColorTech"); _fxWVP = _fx.GetVariableByName("gWorldViewProj").AsMatrix(); }
public void Load() { try { string path = Path.Combine(ShaderManager.ShadaresFolder, "transformEffectWireframe.fx"); using (ShaderBytecode effectByteCode = ShaderBytecode.CompileFromFile( path, "Render", "fx_5_0", ShaderFlags.EnableStrictness, EffectFlags.None)) { effect = new Effect(DeviceManager.Instance.device, effectByteCode); technique = effect.GetTechniqueByIndex(0); pass = technique.GetPassByIndex(0); inputSignature = pass.Description.Signature; } } catch (Exception ex) { Console.WriteLine(ex.ToString()); } var elements = new[] { new InputElement("POSITION", 0, Format.R32G32B32_Float, 0), }; layout = new InputLayout(DeviceManager.Instance.device, inputSignature, elements); tmat = effect.GetVariableByName("gWVP").AsMatrix(); wfCol = effect.GetVariableByName("colorWireframe").AsVector(); mCol = effect.GetVariableByName("colorSolid").AsVector(); }
public FowardLightingEffect(Device device, string filename) : base(device, filename) { Ambient = FX.GetTechniqueByName("Ambient"); DepthPrePass = FX.GetTechniqueByName("DepthPrePass"); Directional = FX.GetTechniqueByName("Directional"); PointLight = FX.GetTechniqueByName("Point"); _worldViewProj = FX.GetVariableByName("WorldViewProjection").AsMatrix(); _world = FX.GetVariableByName("World").AsMatrix(); _worldInvTranspose = FX.GetVariableByName("gWorldInvTranspose").AsMatrix(); _ambientDown = FX.GetVariableByName("AmbientDown").AsVector(); _ambientRange = FX.GetVariableByName("AmbientRange").AsVector(); _dirToLight = FX.GetVariableByName("DirToLight").AsVector(); _dirLightColor = FX.GetVariableByName("DirLightColor").AsVector(); _eyePosition = FX.GetVariableByName("EyePosition").AsVector(); _specularExponent = FX.GetVariableByName("specExp").AsScalar(); _specularIntensity = FX.GetVariableByName("specIntensity").AsScalar(); _pointLightPosition = FX.GetVariableByName("PointLightPosition").AsVector(); _pointLightRangeRcp = FX.GetVariableByName("PointLightRangeRcp").AsScalar(); _pointLightColor = FX.GetVariableByName("PointLightColor").AsVector(); _diffuseMap = FX.GetVariableByName("DiffuseTexture").AsResource(); }
private void Initialize3DTransformations(uint nWidth, uint nHeight) { worldVariable = shader.GetVariableByName("World").AsMatrix; viewVariable = shader.GetVariableByName("View").AsMatrix; projectionVariable = shader.GetVariableByName("Projection").AsMatrix; diffuseVariable = shader.GetVariableByName("txDiffuse").AsShaderResource; worldMatrix = Matrix4x4F.Identity; // Initialize the view matrix. Vector3F eye = new Vector3F(0.0f, 2.0f, -6.0f); Vector3F at = new Vector3F(0.0f, 0.0f, 0.0f); Vector3F up = new Vector3F(0.0f, 1.0f, 0.0f); viewMatrix = Camera.MatrixLookAtLH(eye, at, up); viewVariable.Matrix = viewMatrix; // Initialize the projection matrix projectionMatrix = Camera.MatrixPerspectiveFovLH( (float)Math.PI * 0.24f, // fovy nWidth / (float)nHeight, // aspect 0.1f, // zn 100.0f // zf ); projectionVariable.Matrix = projectionMatrix; }
public void Load() { try { string path = Path.Combine(ShaderManager.ShadaresFolder, "EffectShaded.fx"); using (ShaderBytecode effectByteCode = ShaderBytecode.CompileFromFile( path, "Render", "fx_5_0", ShaderFlags.EnableStrictness, EffectFlags.None)) { effect = new Effect(DeviceManager.Instance.device, effectByteCode); technique = effect.GetTechniqueByIndex(0); pass = technique.GetPassByIndex(0); inputSignature = pass.Description.Signature; } layout = new InputLayout(DeviceManager.Instance.device, inputSignature, elements); tmat = effect.GetVariableByName("gWVP").AsMatrix(); invW = effect.GetVariableByName("inv_world_matrix").AsMatrix(); lightPos = effect.GetVariableByName("LightPosition").AsVector(); color = effect.GetVariableByName("color").AsVector(); } catch (Exception ex) { Console.WriteLine(ex.ToString()); } }
private void BuildFX() { var shaderFlags = ShaderFlags.None; #if DEBUG shaderFlags |= ShaderFlags.Debug; shaderFlags |= ShaderFlags.SkipOptimization; #endif string errors = null; ShaderBytecode compiledShader = null; try { compiledShader = ShaderBytecode.CompileFromFile( "FX/color.fx", null, "fx_5_0", shaderFlags, EffectFlags.None, null, null, out errors); _fx = new Effect(Device, compiledShader); } catch (Exception ex) { if (!string.IsNullOrEmpty(errors)) { MessageBox.Show(errors); } MessageBox.Show(ex.Message); return; } finally { Util.ReleaseCom(ref compiledShader); } _tech = _fx.GetTechniqueByName("ColorTech"); _fxWVP = _fx.GetVariableByName("gWorldViewProj").AsMatrix(); }
protected override void OnLoadShaders(string shaderFileNeme) { base.OnLoadShaders("textureOnly.fx"); _CameraMatrix = Effect.GetVariableByName("ViewProjection").AsMatrix(); _DiffuseTexture = Effect.GetVariableByName("DiffuseTexture").AsResource(); }
public override void LoadResources() { if (m_Disposed == true) { m_Effect = m_Effect = new Effect(GameEnvironment.Device, Bytecode); // Effect.FromFile(GameEnvironment.Device, Helper.ResolvePath(m_ShaderLocation), "fx_4_0", ShaderFlags.None, EffectFlags.None, null, null); m_Technique = m_Effect.GetTechniqueByName("RenderParticles"); m_ParticlePass_Add = m_Technique.GetPassByName("Add"); m_Layout = new InputLayout(GameEnvironment.Device, m_ParticlePass_Add.Description.Signature, new[] { new InputElement("POSITION", 0, Format.R32G32B32A32_Float, 0, 0), new InputElement("TEXCOORD", 0, Format.R32G32_Float, 16, 0), new InputElement("INST_POSITION", 0, Format.R32G32B32_Float, 0, 1, InputClassification.PerInstanceData, 1), new InputElement("INST_COLOR", 0, Format.R32G32B32A32_Float, 12, 1, InputClassification.PerInstanceData, 1), }); m_WorldViewProj = m_Effect.GetVariableByName("worldViewProj").AsMatrix(); m_ParticleTexture = m_Effect.GetVariableByName("particle_texture").AsResource(); m_AmpScale = m_Effect.GetVariableByName("ampScale").AsScalar(); m_PartScaleX = m_Effect.GetVariableByName("partScaleX").AsScalar(); m_PartScaleY = m_Effect.GetVariableByName("partScaleY").AsScalar(); m_MaxDistance = m_Effect.GetVariableByName("maxDistance").AsScalar(); m_MinDistance = m_Effect.GetVariableByName("minDistance").AsScalar(); m_ScaleDistance = m_Effect.GetVariableByName("scaleDistance").AsScalar(); m_Disposed = false; } }
public void Load() { try { string path = Path.Combine(ShaderManager.ShadaresFolder, "texture3DEffect.fx"); using (ShaderBytecode effectByteCode = ShaderBytecode.CompileFromFile( path, "Render", "fx_5_0", ShaderFlags.EnableStrictness, EffectFlags.None)) { effect = new Effect(DeviceManager.Instance.device, effectByteCode); technique = effect.GetTechniqueByIndex(0); pass = technique.GetPassByIndex(0); inputSignature = pass.Description.Signature; } tmat = effect.GetVariableByName("gWVP").AsMatrix(); WVInvmat = effect.GetVariableByName("gWVInv").AsMatrix(); WVmat = effect.GetVariableByName("gWV").AsMatrix(); textureResourceVariable = effect.GetVariableByName("Texture").AsShaderResource(); layout = new InputLayout(DeviceManager.Instance.device, inputSignature, elements); } catch (Exception ex) { Console.WriteLine(ex.ToString()); } }
public DxEffect(SlimDX.Direct3D10.Device device, string shaderFileName = "scene.fx") { // using (var bytecode = ShaderBytecode.CompileFromFile(shaderFileName, "VShader", vs)) _dxDevice = device; _effect = Effect.FromFile(_dxDevice, shaderFileName, "fx_4_0", ShaderFlags.None, EffectFlags.None, null, null); _technique = _effect.GetTechniqueByName("Render"); //C++ Comparaison// technique = effect->GetTechniqueByName( "Render" ); _effectPass = _technique.GetPassByIndex(0); _worldVariable = _effect.GetVariableByName("World").AsMatrix(); //C++ Comparaison// worldVariable = effect->GetVariableByName( "World" )->AsMatrix(); _viewVariable = _effect.GetVariableByName("View").AsMatrix(); _projectionVariable = _effect.GetVariableByName("Projection").AsMatrix(); ShaderSignature signature = _effectPass.Description.Signature; _inputLayout = new InputLayout(_dxDevice, signature, new[] { //C++...// { "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0 }, new InputElement("POSITION", 0, SlimDX.DXGI.Format.R32G32B32A32_Float, 0, 0), // 8bits = 1 bytes, so 32bits = 4 bytes, then R32+G32+B32+A32 = 4+4+4+4 = 16 bytes new InputElement("COLOR", 0, SlimDX.DXGI.Format.R32G32B32A32_Float, 16, 0) // 16 = total bytes from the element before, here it's "POSITION" }); _effect.Optimize(); }
private void CompileShaders(string texturePath, string shaderPath) { _shaderEffect = new Effect(_device, ShaderBytecode.CompileFromFile(shaderPath, "fx_5_0", ShaderFlags.None, EffectFlags.None)); _shaderEffectPass = _shaderEffect.GetTechniqueByIndex((int)RenderParameters.ShaderMode).GetPassByIndex(0); _device.ImmediateContext.InputAssembler.InputLayout = new InputLayout(_device, _shaderEffectPass.Description.Signature, VertexShaderInput.InputLayout); // Setup Global Variables _world = _shaderEffect.GetVariableByName("World").AsMatrix(); _worldViewProjection = _shaderEffect.GetVariableByName("WorldViewProj").AsMatrix(); _tessFactor = _shaderEffect.GetVariableByName("TessFactor").AsScalar(); _textureMap = _shaderEffect.GetVariableByName("Texture").AsResource(); _enableTexture = _shaderEffect.GetVariableByName("EnableTexture").AsScalar(); _enableNormals = _shaderEffect.GetVariableByName("Normals").AsScalar(); _textureView = new ShaderResourceView(_device, Texture2D.FromFile(_device, texturePath)); // Setup Lighting Variables _phongParameters = _shaderEffect.GetVariableByName("AmbSpecDiffShini").AsVector(); _lightColor = _shaderEffect.GetVariableByName("LightColor").AsVector(); _lightDirection = _shaderEffect.GetVariableByName("LightDirection").AsVector(); _light2Color = _shaderEffect.GetVariableByName("Light2Color").AsVector(); _light2Direction = _shaderEffect.GetVariableByName("Light2Direction").AsVector(); _ambientLightColor = _shaderEffect.GetVariableByName("AmbientLight").AsVector(); _cameraPosition = _shaderEffect.GetVariableByName("Eye").AsVector(); _flatShading = _shaderEffect.GetVariableByName("FlatShading").AsScalar(); // Valences and Prefixes for ACC _valencePrefixResource = _shaderEffect.GetVariableByName("ValencePrefixBuffer").AsResource(); }
protected override void OnLoadShaders(string shaderFileNeme) { base.OnLoadShaders("singleColor.fx"); _CameraMatrix = Effect.GetVariableByName("ViewProjection").AsMatrix(); color = Effect.GetVariableByName("Color").AsVector(); }
public ShapesDemo(IntPtr hInstance) : base(hInstance) { _vb = null; _ib = null; _fx = null; _tech = null; _fxWVP = null; _inputLayout = null; _wireframeRS = null; _theta = 1.5f * MathF.PI; _phi = 0.1f * MathF.PI; _radius = 15.0f; MainWindowCaption = "Shapes Demo"; _lastMousePos = new Point(0, 0); _gridWorld = Matrix.Identity; _view = Matrix.Identity; _proj = Matrix.Identity; _boxWorld = Matrix.Scaling(2.0f, 1.0f, 2.0f) * Matrix.Translation(0, 0.5f, 0); _centerSphere = Matrix.Scaling(2.0f, 2.0f, 2.0f) * Matrix.Translation(0, 2, 0); for (int i = 0; i < 5; ++i) { _cylWorld[i * 2] = Matrix.Translation(-5.0f, 1.5f, -10.0f + i * 5.0f); _cylWorld[i * 2 + 1] = Matrix.Translation(5.0f, 1.5f, -10.0f + i * 5.0f); _sphereWorld[i * 2] = Matrix.Translation(-5.0f, 3.5f, -10.0f + i * 5.0f); _sphereWorld[i * 2 + 1] = Matrix.Translation(5.0f, 3.5f, -10.0f + i * 5.0f); } }
/// <summary> /// Creates the mesh manager /// </summary> /// <param name="device"></param> public XMeshManager(D3DDevice device) { this.device = device; // Create the effect //XMesh.fxo was compiled from XMesh.fx using: // "$(DXSDK_DIR)utilities\bin\x86\fxc" "$(ProjectDir)Mesh\MeshLoaders\XMesh.fx" /T fx_4_0 /Fo"$(ProjectDir)Mesh\MeshLoaders\XMesh.fxo" using (Stream effectStream = Assembly.GetExecutingAssembly().GetManifestResourceStream( "Microsoft.WindowsAPICodePack.DirectX.DirectXUtilities.XMesh.fxo")) { effect = device.CreateEffectFromCompiledBinary(new BinaryReader(effectStream)); } // Obtain the techniques techniqueRenderTexture = effect.GetTechniqueByName("RenderTextured"); techniqueRenderVertexColor = effect.GetTechniqueByName("RenderVertexColor"); techniqueRenderMaterialColor = effect.GetTechniqueByName("RenderMaterialColor"); // Obtain the variables brightnessVariable = effect.GetVariableByName("Brightness").AsScalar; materialColorVariable = effect.GetVariableByName("MaterialColor").AsVector; worldVariable = effect.GetVariableByName("World").AsMatrix; viewVariable = effect.GetVariableByName("View").AsMatrix; projectionVariable = effect.GetVariableByName("Projection").AsMatrix; diffuseVariable = effect.GetVariableByName("tex2D").AsShaderResource; }
public override void Initialize() { base.Initialize(); try { using (ShaderBytecode effectByteCode = ShaderBytecode.CompileFromFile( "Shaders/transformEffectWireframe.fx", "Render", "fx_5_0", ShaderFlags.EnableStrictness, EffectFlags.None)) { effect = new SlimDX.Direct3D11.Effect(DeviceManager.Instance.device, effectByteCode); technique = effect.GetTechniqueByIndex(0); pass = technique.GetPassByIndex(0); inputSignature = pass.Description.Signature; } var elements = new[] { new InputElement("POSITION", 0, Format.R32G32B32_Float, 0), }; layout = new InputLayout(DeviceManager.Instance.device, inputSignature, elements); tmat = effect.GetVariableByName("gWVP").AsMatrix(); wfCol = effect.GetVariableByName("colorWireframe").AsVector(); mCol = effect.GetVariableByName("colorSolid").AsVector(); } catch (Exception ex) { Console.WriteLine(ex.ToString()); } }
private void LoadEffect(string shaderFileName) { _effect = Effect.FromFile(_dxDevice, shaderFileName, "fx_4_0", ShaderFlags.None, EffectFlags.None, null, null); _renderTech = _effect.GetTechniqueByName("Render"); //C++ Comparaison// technique = effect->GetTechniqueByName( "Render" ); _eyePosWVar = _effect.GetVariableByName("gEyePosW").AsVector(); _viewProjVar = _effect.GetVariableByName("gViewProj").AsMatrix(); _worldVar = _effect.GetVariableByName("gWorld").AsMatrix(); _fillColorVar = _effect.GetVariableByName("gFillColor").AsVector(); _lightVariable = _effect.GetVariableByName("gLight"); _imageMapVar = _effect.GetVariableByName("gImageMap").AsResource(); _depthMapVar = _effect.GetVariableByName("gDepthMap").AsResource(); _resVar = _effect.GetVariableByName("gRes").AsVector(); _depthToRgbVar = _effect.GetVariableByName("gDepthToRgb").AsMatrix(); _focalLengthDepthVar = _effect.GetVariableByName("gFocalLengthDepth").AsScalar(); _focalLengthImageVar = _effect.GetVariableByName("gFocalLengthImage").AsScalar(); ShaderSignature signature = _renderTech.GetPassByIndex(0).Description.Signature; _inputLayout = new InputLayout(_dxDevice, signature, new[] { new InputElement("POSITION", 0, SlimDX.DXGI.Format.R16G16_SInt, 0, 0) }); }
private void LoadEffect(string fileName) { _effect = Effect.FromFile(_dxDevice, fileName, "fx_4_0", ShaderFlags.None, EffectFlags.None, null, null); _streamOutTech = _effect.GetTechniqueByName("StreamOutTech"); _drawTech = _effect.GetTechniqueByName("DrawTech"); _viewProjVar = _effect.GetVariableByName("gViewProj").AsMatrix(); _gameTimeVar = _effect.GetVariableByName("gGameTime").AsScalar(); _timeStepVar = _effect.GetVariableByName("gTimeStep").AsScalar(); _eyePosVar = _effect.GetVariableByName("gEyePosW").AsVector(); _emitPosVar = _effect.GetVariableByName("gEmitPosW").AsVector(); _emitDirVar = _effect.GetVariableByName("gEmitDirW").AsVector(); _texArrayVar = _effect.GetVariableByName("gTexArray").AsResource(); _randomTexVar = _effect.GetVariableByName("gRandomTex").AsResource(); ShaderSignature signature = _streamOutTech.GetPassByIndex(0).Description.Signature; _vertexLayout = new InputLayout(_dxDevice, signature, new[] { new InputElement("POSITION", 0, Format.R32G32B32_Float, 0, 0), new InputElement("VELOCITY", 0, Format.R32G32B32_Float, 12, 0), new InputElement("SIZE", 0, Format.R32G32_Float, 24, 0), new InputElement("AGE", 0, Format.R32_Float, 32, 0), new InputElement("TYPE", 0, Format.R32_UInt, 36, 0) }); }
/// <summary> /// Create Direct3D device and swap chain /// </summary> protected void InitDevice() { device = D3DDevice.CreateDeviceAndSwapChain(directControl.Handle); swapChain = device.SwapChain; SetViews(); // Create the effect using (FileStream effectStream = File.OpenRead("Tutorial04.fxo")) { effect = device.CreateEffectFromCompiledBinary(new BinaryReader(effectStream)); } // Obtain the technique technique = effect.GetTechniqueByName("Render"); // Obtain the variables worldVariable = effect.GetVariableByName("World").AsMatrix; viewVariable = effect.GetVariableByName("View").AsMatrix; projectionVariable = effect.GetVariableByName("Projection").AsMatrix; InitVertexLayout(); InitVertexBuffer(); InitIndexBuffer(); // Set primitive topology device.IA.PrimitiveTopology = PrimitiveTopology.TriangleList; InitMatrices(); needsResizing = false; }
public void Load() { try { using (ShaderBytecode effectByteCode = ShaderBytecode.CompileFromFile( Path.Combine(ShaderManager.ShadaresFolder, "ColorEffectInstanced.fx"), "Render", "fx_5_0", ShaderFlags.EnableStrictness, EffectFlags.None)) { effect = new Effect(DeviceManager.Instance.device, effectByteCode); technique = effect.GetTechniqueByIndex(0); pass = technique.GetPassByIndex(0); inputSignature = pass.Description.Signature; } layout = new InputLayout(DeviceManager.Instance.device, inputSignature, elements); tmat = effect.GetVariableByName("gWVP").AsMatrix(); Vector4 col = new Vector4(0, 0, 0, 1); } catch (Exception ex) { Console.WriteLine(ex.ToString()); } }
protected override void OnAttached() { base.OnAttached(); OnBoneParameterChanged(); OnBoneMatricesChanged(); hasBonesVar = effect.GetVariableByName("bHasBones").AsScalar(); boneMatricesVar = effect.GetVariableByName("SkinMatrices").AsMatrix(); }
public DisplacementMapEffect(Device device, string filename) : base(device, filename) { _heightScale = FX.GetVariableByName("gHeightScale").AsScalar(); _maxTessDistance = FX.GetVariableByName("gMaxTessDistance").AsScalar(); _minTessDistance = FX.GetVariableByName("gMinTessDistance").AsScalar(); _minTessFactor = FX.GetVariableByName("gMinTessFactor").AsScalar(); _maxTessFactor = FX.GetVariableByName("gMaxTessFactor").AsScalar(); _viewProj = FX.GetVariableByName("gViewProj").AsMatrix(); }
public TerrainEffect(Device device, string filename) : base(device, filename) { Light1Tech = FX.GetTechniqueByName("Light1"); Light2Tech = FX.GetTechniqueByName("Light2"); Light3Tech = FX.GetTechniqueByName("Light3"); Light1FogTech = FX.GetTechniqueByName("Light1Fog"); Light2FogTech = FX.GetTechniqueByName("Light2Fog"); Light3FogTech = FX.GetTechniqueByName("Light3Fog"); Light1ShadowTech = FX.GetTechniqueByName("Light1Shadow"); Light2ShadowTech = FX.GetTechniqueByName("Light2Shadow"); Light3ShadowTech = FX.GetTechniqueByName("Light3Shadow"); Light1FogShadowTech = FX.GetTechniqueByName("Light1FogShadow"); Light2FogShadowTech = FX.GetTechniqueByName("Light2FogShadow"); Light3FogShadowTech = FX.GetTechniqueByName("Light3FogShadow"); Light1TechNT = FX.GetTechniqueByName("Light1NT"); Light2TechNT = FX.GetTechniqueByName("Light2NT"); Light3TechNT = FX.GetTechniqueByName("Light3NT"); Light1FogTechNT = FX.GetTechniqueByName("Light1FogNT"); Light2FogTechNT = FX.GetTechniqueByName("Light2FogNT"); Light3FogTechNT = FX.GetTechniqueByName("Light3FogNT"); NormalDepthTech = FX.GetTechniqueByName("NormalDepth"); TessBuildShadowMapTech = FX.GetTechniqueByName("TessBuildShadowMapTech"); _viewProj = FX.GetVariableByName("gViewProj").AsMatrix(); _eyePosW = FX.GetVariableByName("gEyePosW").AsVector(); _fogColor = FX.GetVariableByName("gFogColor").AsVector(); _fogStart = FX.GetVariableByName("gFogStart").AsScalar(); _fogRange = FX.GetVariableByName("gFogRange").AsScalar(); _dirLights = FX.GetVariableByName("gDirLights"); _mat = FX.GetVariableByName("gMaterial"); _minDist = FX.GetVariableByName("gMinDist").AsScalar(); _maxDist = FX.GetVariableByName("gMaxDist").AsScalar(); _minTess = FX.GetVariableByName("gMinTess").AsScalar(); _maxTess = FX.GetVariableByName("gMaxTess").AsScalar(); _texelCellSpaceU = FX.GetVariableByName("gTexelCellSpaceU").AsScalar(); _texelCellSpaceV = FX.GetVariableByName("gTexelCellSpaceV").AsScalar(); _worldCellSpace = FX.GetVariableByName("gWorldCellSpace").AsScalar(); _worldFrustumPlanes = FX.GetVariableByName("gWorldFrustumPlanes").AsVector(); _layerMapArray = FX.GetVariableByName("gLayerMapArray").AsResource(); _blendMap = FX.GetVariableByName("gBlendMap").AsResource(); _heightMap = FX.GetVariableByName("gHeightMap").AsResource(); _view = FX.GetVariableByName("gView").AsMatrix(); _ambientMap = FX.GetVariableByName("gSsaoMap").AsResource(); _viewProjTex = FX.GetVariableByName("gViewProjTex").AsMatrix(); _shadowTransform = FX.GetVariableByName("gShadowTransform").AsMatrix(); _shadowMap = FX.GetVariableByName("gShadowMap").AsResource(); _walkMap = FX.GetVariableByName("gWalkMap").AsResource(); _unwalkableSRV = FX.GetVariableByName("gUnwalkable").AsResource(); }
protected override void LoadShaderVariables() { _useDiffuseTextureVar = Effect.GetVariableByName("gUseDiffuseTexture").AsScalar(); _diffuseTextureVar = Effect.GetVariableByName("gDiffuseTexture").AsShaderResource(); _useNormalTextureVar = Effect.GetVariableByName("gUseNormalTexture").AsScalar(); _normalTextureVar = Effect.GetVariableByName("gNormalTexture").AsShaderResource(); _wvpMatrixVar = Effect.GetVariableBySemantic("WORLDVIEWPROJECTION").AsMatrix(); _worldMatrixVar = Effect.GetVariableBySemantic("WORLD").AsMatrix(); }
/// <summary> /// /// </summary> /// <param name="name"></param> protected void GetVariableMatrix(out EffectMatrixVariable val, string name) { val = m_coreEffect.GetVariableByName(name).AsMatrix(); if (!val.IsValid) { throw new Exception("変数が存在しません。エフェクトファイル[common.hlsl]内に" + name + "が存在しません。"); } }
public SsaoNormalDepthEffect(Device device, string filename) : base(device, filename) { NormalDepthTech = FX.GetTechniqueByName("NormalDepth"); NormalDepthAlphaClipTech = FX.GetTechniqueByName("NormalDepthAlphaClip"); _worldView = FX.GetVariableByName("gWorldView").AsMatrix(); _worldInvTransposeView = FX.GetVariableByName("gWorldInvTransposeView").AsMatrix(); _worldViewProj = FX.GetVariableByName("gWorldViewProj").AsMatrix(); _texTransform = FX.GetVariableByName("gTexTransform").AsMatrix(); _diffuseMap = FX.GetVariableByName("gDiffuseMap").AsResource(); }
public DebugTexEffect(Device device, string filename) : base(device, filename) { ViewArgbTech = FX.GetTechniqueByName("ViewArgbTech"); ViewRedTech = FX.GetTechniqueByName("ViewRedTech"); ViewGreenTech = FX.GetTechniqueByName("ViewGreenTech"); ViewBlueTech = FX.GetTechniqueByName("ViewBlueTech"); ViewAlphaTech = FX.GetTechniqueByName("ViewAlphaTech"); _texture = FX.GetVariableByName("gTexture").AsResource(); _wvp = FX.GetVariableByName("gWorldViewProj").AsMatrix(); }
/// <summary> /// The OnAttached /// </summary> protected override void OnAttached() { base.OnAttached(); planeParamsVar = effect.GetVariableByName("CrossPlaneParams").AsMatrix(); planeEnabledVar = effect.GetVariableByName("EnableCrossPlane").AsVector(); crossSectionColorVar = effect.GetVariableByName("CrossSectionColor").AsVector(); sectionFillTextureVar = effect.GetVariableByName("SectionFillTexture").AsShaderResource(); CreateStates(); }
public WavesEffect(Device device, string filename) : base(device, filename) { _waveDispTexTransform0 = FX.GetVariableByName("gWaveDispTexTransform0").AsMatrix(); _waveDispTexTransform1 = FX.GetVariableByName("gWaveDispTexTransform1").AsMatrix(); _waveNormalTexTransform0 = FX.GetVariableByName("gWaveNormalTexTransform0").AsMatrix(); _waveNormalTexTransform1 = FX.GetVariableByName("gWaveNormalTexTransform1").AsMatrix(); _heightScale0 = FX.GetVariableByName("gHeightScale0").AsScalar(); _heightScale1 = FX.GetVariableByName("gHeightScale1").AsScalar(); _normalMap0 = FX.GetVariableByName("gNormalMap0").AsResource(); _normalMap1 = FX.GetVariableByName("gNormalMap1").AsResource(); }
public RenderContext(IRenderHost canvas, Effect effect) { this.Canvas = canvas; this.IsShadowPass = false; this.IsDeferredPass = false; this.mView = effect.GetVariableByName("mView").AsMatrix(); this.mProjection = effect.GetVariableByName("mProjection").AsMatrix(); this.vViewport = effect.GetVariableByName("vViewport").AsVector(); this.vFrustum = effect.GetVariableByName("vFrustum").AsVector(); this.vEyePos = effect.GetVariableByName("vEyePos").AsVector(); }
public InstancedNormalMapEffect(Device device, string filename) : base(device, filename) { Light1Tech = FX.GetTechniqueByName("Light1"); Light3TexTech = FX.GetTechniqueByName("Light3Tex"); _viewProj = FX.GetVariableByName("gViewProj").AsMatrix(); _texTransform = FX.GetVariableByName("gTexTransform").AsMatrix(); _eyePosW = FX.GetVariableByName("gEyePosW").AsVector(); _dirLights = FX.GetVariableByName("gDirLights"); _mat = FX.GetVariableByName("gMaterial"); _diffuseMap = FX.GetVariableByName("gDiffuseMap").AsResource(); _normalMap = FX.GetVariableByName("gNormalMap").AsResource(); }
private static void LoadShaders() { ShaderBytecode bytecode = null; bytecode = ShaderBytecode.CompileFromFile("Shaders.fx", null, "fx_5_0", ShaderFlags.None, EffectFlags.None, null, null); fx = new Effect(device, bytecode); bytecode.Dispose(); techniqueTextured = fx.GetTechniqueByName("Textured"); techniqueSelected = fx.GetTechniqueByName("Selected"); techniqueColor = fx.GetTechniqueByName("Color"); WVP = fx.GetVariableByName("WVP").AsMatrix(); fxTex = fx.GetVariableByName("tex").AsResource(); }
public TreeSpriteEffect(Device device, string filename) : base(device, filename) { Light3Tech = FX.GetTechniqueByName("Light3"); Light3TexAlphaClipTech = FX.GetTechniqueByName("Light3TexAlphaClip"); Light3TexAlphaClipFogTech = FX.GetTechniqueByName("Light3TexAlphaClipFog"); _viewProj = FX.GetVariableByName("gViewProj").AsMatrix(); _eyePosW = FX.GetVariableByName("gEyePosW").AsVector(); _fogColor = FX.GetVariableByName("gFogColor").AsVector(); _fogStart = FX.GetVariableByName("gFogStart").AsScalar(); _fogRange = FX.GetVariableByName("gFogRange").AsScalar(); _dirLights = FX.GetVariableByName("gDirLights"); _mat = FX.GetVariableByName("gMaterial"); _treeTextureMapArray = FX.GetVariableByName("gTreeMapArray").AsResource(); }
public ForwardLightingEffect(Device device, string filename) : base(device, filename) { Ambient = FX.GetTechniqueByName("Ambient"); _worldViewProj = FX.GetVariableByName("WorldViewProjection").AsMatrix(); _world = FX.GetVariableByName("World").AsMatrix(); _worldInvTranspose = FX.GetVariableByName("gWorldInvTranspose").AsMatrix(); _ambientDown = FX.GetVariableByName("AmbientDown").AsVector(); _ambientRange = FX.GetVariableByName("AmbientRange").AsVector(); _diffuseMap = FX.GetVariableByName("DiffuseTexture").AsResource(); }
public SsaoEffect(Device device, string filename) : base(device, filename) { SsaoTech = FX.GetTechniqueByName("Ssao"); _viewToTexSpace = FX.GetVariableByName("gViewToTexSpace").AsMatrix(); _offsetVectors = FX.GetVariableByName("gOffsetVectors").AsVector(); _frustumCorners = FX.GetVariableByName("gFrustumCorners").AsVector(); _occlusionRadius = FX.GetVariableByName("gOcclusionRadius").AsScalar(); _occlusionFadeStart = FX.GetVariableByName("gOcclusionFadeStart").AsScalar(); _occlusionFadeEnd = FX.GetVariableByName("gOcclusionFadeEnd").AsScalar(); _surfaceEpsilon = FX.GetVariableByName("gSurfaceEpsilon").AsScalar(); _normalDepthMap = FX.GetVariableByName("gNormalDepthMap").AsResource(); _randomVecMap = FX.GetVariableByName("gRandomVecMap").AsResource(); }
public ParticleEffect(Device device, string filename) : base(device, filename) { StreamOutTech = FX.GetTechniqueByName("StreamOutTech"); DrawTech = FX.GetTechniqueByName("DrawTech"); _viewProj = FX.GetVariableByName("gViewProj").AsMatrix(); _gameTime = FX.GetVariableByName("gGameTime").AsScalar(); _timeStep = FX.GetVariableByName("gTimeStep").AsScalar(); _eyePosW = FX.GetVariableByName("gEyePosW").AsVector(); _emitPosW = FX.GetVariableByName("gEmitPosW").AsVector(); _emitDirW = FX.GetVariableByName("gEmitDirW").AsVector(); _texArray = FX.GetVariableByName("gTexArray").AsResource(); _randomTex = FX.GetVariableByName("gRandomTex").AsResource(); }
protected override bool OnAttach(IRenderHost host) { if (base.OnAttach(host)) { viewMatrixVar = effect.GetVariableByName("mView").AsMatrix(); projectionMatrixVar = effect.GetVariableByName("mProjection").AsMatrix(); Disposer.RemoveAndDispose(ref depthStencil); depthStencil = CreateDepthStencilState(this.Device); return(true); } else { return(false); } }
public BoxApp(IntPtr hInstance) : base(hInstance) { _boxIB = null; _boxVB = null; _fx = null; _tech = null; _fxWVP = null; _inputLayout = null; _theta = 1.5f * MathF.PI; _phi = 0.25f * MathF.PI; _radius = 5.0f; MainWindowCaption = "Box Demo"; _lastMousePos = new Point(0, 0); _world = Matrix.Identity; _view = Matrix.Identity; _proj = Matrix.Identity; }
public InstancedBasicEffect(Device device, string filename) : base(device, filename) { Light1Tech = FX.GetTechniqueByName("Light1"); Light2Tech = FX.GetTechniqueByName("Light2"); Light3Tech = FX.GetTechniqueByName("Light3"); Light0TexTech = FX.GetTechniqueByName("Light0Tex"); Light1TexTech = FX.GetTechniqueByName("Light1Tex"); Light2TexTech = FX.GetTechniqueByName("Light2Tex"); Light3TexTech = FX.GetTechniqueByName("Light3Tex"); Light0TexAlphaClipTech = FX.GetTechniqueByName("Light0TexAlphaClip"); Light1TexAlphaClipTech = FX.GetTechniqueByName("Light1TexAlphaClip"); Light2TexAlphaClipTech = FX.GetTechniqueByName("Light2TexAlphaClip"); Light3TexAlphaClipTech = FX.GetTechniqueByName("Light3TexAlphaClip"); Light1FogTech = FX.GetTechniqueByName("Light1Fog"); Light2FogTech = FX.GetTechniqueByName("Light2Fog"); Light3FogTech = FX.GetTechniqueByName("Light3Fog"); Light0TexFogTech = FX.GetTechniqueByName("Light0TexFog"); Light1TexFogTech = FX.GetTechniqueByName("Light1TexFog"); Light2TexFogTech = FX.GetTechniqueByName("Light2TexFog"); Light3TexFogTech = FX.GetTechniqueByName("Light3TexFog"); Light0TexAlphaClipFogTech = FX.GetTechniqueByName("Light0TexAlphaClipFog"); Light1TexAlphaClipFogTech = FX.GetTechniqueByName("Light1TexAlphaClipFog"); Light2TexAlphaClipFogTech = FX.GetTechniqueByName("Light2TexAlphaClipFog"); Light3TexAlphaClipFogTech = FX.GetTechniqueByName("Light3TexAlphaClipFog"); _viewProj = FX.GetVariableByName("gViewProj").AsMatrix(); _texTransform = FX.GetVariableByName("gTexTransform").AsMatrix(); _eyePosW = FX.GetVariableByName("gEyePosW").AsVector(); _fogColor = FX.GetVariableByName("gFogColor").AsVector(); _fogStart = FX.GetVariableByName("gFogStart").AsScalar(); _fogRange = FX.GetVariableByName("gFogRange").AsScalar(); _dirLights = FX.GetVariableByName("gDirLights"); _mat = FX.GetVariableByName("gMaterial"); _diffuseMap = FX.GetVariableByName("gDiffuseMap").AsResource(); }
public BoxApp(IntPtr hInstance) : base(hInstance) { _ib = null; _vb = null; _fx = null; _tech = null; _fxWVP = null; _inputLayout = null; _theta = 1.5f * MathF.PI; _phi = 0.1f * MathF.PI; _radius = 200.0f; MainWindowCaption = "Hills Demo"; _lastMousePos = new Point(0, 0); _world = Matrix.Identity; _view = Matrix.Identity; _proj = Matrix.Identity; _gridIndexCount = 0; }
public override void LoadResources() { if (m_Disposed == true) { m_Effect = m_Effect = new Effect(GameEnvironment.Device, Bytecode); // Effect.FromFile(GameEnvironment.Device, Helper.ResolvePath(m_ShaderLocation), "fx_4_0", ShaderFlags.Debug | ShaderFlags.EnableStrictness, EffectFlags.None, null, null); m_Technique = m_Effect.GetTechniqueByName("Render"); m_Pass0 = m_Technique.GetPassByName("P0"); /*m_Layout = new InputLayout(GameEnvironment.Device, m_Pass0.Description.Signature, new[] { new InputElement( "POSITION", 0, Format.R32G32B32_Float, 0, 0, InputClassification.PerVertexData, 0), new InputElement( "NORMAL", 0, Format.R32G32B32_Float, 0, 12, InputClassification.PerVertexData, 0), new InputElement( "TEXCOORD", 0, Format.R32G32_Float, 0, 24, InputClassification.PerVertexData, 0), });*/ m_Layout = new InputLayout(GameEnvironment.Device, m_Pass0.Description.Signature, new[] { new InputElement("POSITION", 0, Format.R32G32B32_Float, 0, 0), new InputElement("NORMAL", 0, Format.R32G32B32_Float, 12, 0), new InputElement("TEXCOORD", 0, Format.R32G32_Float, 24, 0) }); //texColorMap //texNormalMap //texDiffuseMap //texSpecularMap //m_DiffuseVariable = m_Effect.GetVariableByName("g_txDiffuse").AsResource(); m_DiffuseVariable = m_Effect.GetVariableByName("texColorMap").AsResource(); m_NormalMapVariable = m_Effect.GetVariableByName("texNormalMap").AsResource(); m_WorldVariable = m_Effect.GetVariableByName("World").AsMatrix(); m_ViewVariable = m_Effect.GetVariableByName("View").AsMatrix(); m_InvViewVariable = m_Effect.GetVariableByName("InvView").AsMatrix(); m_ProjectionVariable = m_Effect.GetVariableByName("Projection").AsMatrix(); //m_SpecularMapVariable = m_Effect.GetVariableByName("g_txEnvMap").AsResource(); m_SpecularMapVariable = m_Effect.GetVariableByName("texSpecularMap").AsResource(); m_DiffuseMapVariable = m_Effect.GetVariableByName("texDiffuseMap").AsResource(); m_EyeVariable = m_Effect.GetVariableByName("Eye").AsVector(); m_Disposed = false; } }
/// <summary> /// Create our test RenderEffect. /// </summary> /// <param name="Device"></param> public TestEffect(Device Device) { this.Device = Device; ImmediateContext = Device.ImmediateContext; // Compile our shader... string compileErrors; var compiledShader = SlimDX.D3DCompiler.ShaderBytecode.CompileFromFile ( "../../Effects/TestEffect/TestEffect.fx", null, "fx_5_0", SlimDX.D3DCompiler.ShaderFlags.None, SlimDX.D3DCompiler.EffectFlags.None, null, null, out compileErrors ); if (compileErrors != null && compileErrors != "") { throw new EffectBuildException(compileErrors); } Effect = new Effect(Device, compiledShader); EffectTechnique = Effect.GetTechniqueByName("TestTechnique"); var vertexDesc = new[] { new InputElement("POSITION", 0, SlimDX.DXGI.Format.R32G32B32_Float, 0, 0, InputClassification.PerVertexData, 0), new InputElement("COLOR", 0, SlimDX.DXGI.Format.R32G32B32A32_Float, 12, 0, InputClassification.PerVertexData, 0) }; WorldViewProj = SlimDX.Matrix.Identity; CPO_WorldViewProj = Effect.GetVariableByName("gWorldViewProj").AsMatrix(); InputLayout = new InputLayout(Device, EffectTechnique.GetPassByIndex(0).Description.Signature, vertexDesc); Util.ReleaseCom(ref compiledShader); }
public SkullDemo(IntPtr hInstance) : base(hInstance) { _vb = null; _ib = null; _fx = null; _tech = null; _fxWVP = null; _inputLayout = null; _wireframeRS = null; _skullIndexCount = 0; _theta = 1.5f*MathF.PI; _phi = 0.1f*MathF.PI; _radius = 20.0f; MainWindowCaption = "Skull Demo"; _lastMousePos = new Point(0,0); _view = Matrix.Identity; _proj = Matrix.Identity; _skullWorld = Matrix.Translation(0.0f, -2.0f, 0.0f); }
public BuildShadowMapEffect(Device device, string filename) : base(device, filename) { BuildShadowMapTech = FX.GetTechniqueByName("BuildShadowMapTech"); BuildShadowMapAlphaClipTech = FX.GetTechniqueByName("BuildShadowMapAlphaClipTech"); TessBuildShadowMapTech = FX.GetTechniqueByName("TessBuildShadowMapTech"); TessBuildShadowMapAlphaClipTech = FX.GetTechniqueByName("TessBuildShadowMapAlphaClipTech"); _heightScale = FX.GetVariableByName("gHeightScale").AsScalar(); _maxTessDistance = FX.GetVariableByName("gMaxTessDistance").AsScalar(); _minTessDistance = FX.GetVariableByName("gMinTessDistance").AsScalar(); _minTessFactor = FX.GetVariableByName("gMinTessFactor").AsScalar(); _maxTessFactor = FX.GetVariableByName("gMaxTessFactor").AsScalar(); _viewProj = FX.GetVariableByName("gViewProj").AsMatrix(); _normalMap = FX.GetVariableByName("gNormalMap").AsResource(); _diffuseMap = FX.GetVariableByName("gDiffuseMap").AsResource(); _worldViewProj = FX.GetVariableByName("gWorldViewProj").AsMatrix(); _world = FX.GetVariableByName("gWorld").AsMatrix(); _worldInvTranspose = FX.GetVariableByName("gWorldInvTranspose").AsMatrix(); _texTransform = FX.GetVariableByName("gTexTransform").AsMatrix(); _eyePosW = FX.GetVariableByName("gEyePosW").AsVector(); }
public LightingDemo(IntPtr hInstance) : base(hInstance) { _landVB = null; _landIB = null; _waveVB = null; _waveIB = null; _fx = null; _tech = null; _fxWorld = null; _fxWIT = null; _fxEyePosW = null; _fxDirLight = null; _fxPointLight = null; _fxSpotLight = null; _fxMaterial = null; _fxWVP = null; _inputLayout = null; _eyePosW = new Vector3(); _theta = 1.5f*MathF.PI; _phi = 0.1f*MathF.PI; _radius = 80.0f; MainWindowCaption = "Lighting Demo"; _lastMousePos = new Point(); _landWorld = Matrix.Identity; _wavesWorld = Matrix.Translation(0, -3.0f, 0); _view = Matrix.Identity; _proj = Matrix.Identity; _dirLight = new DirectionalLight { Ambient = new Color4(0.2f, 0.2f, 0.2f), Diffuse = new Color4(0.5f, 0.5f, 0.5f), Specular = new Color4(0.5f, 0.5f, 0.5f), Direction = new Vector3(0.57735f, -0.57735f, 0.57735f) }; _pointLight = new PointLight { Ambient = new Color4(0.3f, 0.3f, 0.3f), Diffuse = new Color4(0.7f, 0.7f, 0.7f), Specular = new Color4(0.7f, 0.7f, 0.7f), Attenuation = new Vector3(0.0f, 0.1f, 0.0f), Range = 25.0f }; _spotLight = new SpotLight { Ambient = new Color4(0,0,0), Diffuse = new Color4(1.0f, 1.0f, 0.0f), Specular = Color.White, Attenuation = new Vector3(1.0f, 0.0f, 0.0f), Spot = 96.0f, Range = 10000.0f }; // NOTE: must put alpha (spec power) first, rather than last as in book code _landMaterial = new Material { Ambient = new Color4(1.0f, 0.48f, 0.77f, 0.46f), Diffuse = new Color4(1.0f, 0.48f, 0.77f, 0.46f), Specular = new Color4(16.0f, 0.2f, 0.2f, 0.2f) }; _wavesMaterial = new Material { Ambient = new Color4(0.137f, 0.42f, 0.556f), Diffuse = new Color4(0.137f, 0.42f, 0.556f), Specular = new Color4(96.0f, 0.8f, 0.8f, 0.8f) }; }
private void BuildFX() { ShaderBytecode compiledShader = null; try { compiledShader = new ShaderBytecode(new DataStream(File.ReadAllBytes("fx/Lighting.fxo"), false, false)); _fx = new Effect(Device, compiledShader); } catch (Exception ex) { MessageBox.Show(ex.Message); return; } finally { Util.ReleaseCom(ref compiledShader); } _tech = _fx.GetTechniqueByName("LightTech"); _fxWVP = _fx.GetVariableByName("gWorldViewProj").AsMatrix(); _fxWorld = _fx.GetVariableByName("gWorld").AsMatrix(); _fxWIT = _fx.GetVariableByName("gWorldInvTranspose").AsMatrix(); _fxEyePosW = _fx.GetVariableByName("gEyePosW").AsVector(); _fxDirLight = _fx.GetVariableByName("gDirLight"); _fxPointLight = _fx.GetVariableByName("gPointLight"); _fxSpotLight = _fx.GetVariableByName("gSpotLight"); _fxMaterial = _fx.GetVariableByName("gMaterial"); }
protected override void OnLoadShaders(string shaderFileNeme) { base.OnLoadShaders("default.fx"); _CameraMatrix = Effect.GetVariableByName("ViewProjection").AsMatrix(); world = Effect.GetVariableByName("World").AsMatrix(); color = Effect.GetVariableByName("Color").AsVector(); _DiffuseTexture = Effect.GetVariableByName("DiffuseTexture").AsResource(); }
public ColorEffect(Device device, string filename) : base(device, filename) { ColorTech = FX.GetTechniqueByName("ColorTech"); _wvp = FX.GetVariableByName("gWorldViewProj").AsMatrix(); }
void CreateDeviceResources() { uint width = (uint) host.ActualWidth; uint height = (uint) host.ActualHeight; // If we don't have a device, need to create one now and all // accompanying D3D resources. CreateDevice(); DXGIFactory dxgiFactory = DXGIFactory.CreateFactory(); SwapChainDescription swapDesc = new SwapChainDescription(); swapDesc.BufferDescription.Width = width; swapDesc.BufferDescription.Height = height; swapDesc.BufferDescription.Format = Format.R8G8B8A8_UNORM; swapDesc.BufferDescription.RefreshRate.Numerator = 60; swapDesc.BufferDescription.RefreshRate.Denominator = 1; swapDesc.SampleDescription.Count = 1; swapDesc.SampleDescription.Quality = 0; swapDesc.BufferUsage = UsageOption.RenderTargetOutput; swapDesc.BufferCount = 1; swapDesc.OutputWindowHandle = host.Handle; swapDesc.Windowed = true; swapChain = dxgiFactory.CreateSwapChain( device, swapDesc); // Create rasterizer state object RasterizerDescription rsDesc = new RasterizerDescription(); rsDesc.AntialiasedLineEnable = false; rsDesc.CullMode = CullMode.None; rsDesc.DepthBias = 0; rsDesc.DepthBiasClamp = 0; rsDesc.DepthClipEnable = true; rsDesc.FillMode = D3D10.FillMode.Solid; rsDesc.FrontCounterClockwise = false; // Must be FALSE for 10on9 rsDesc.MultisampleEnable = false; rsDesc.ScissorEnable = false; rsDesc.SlopeScaledDepthBias = 0; rasterizerState = device.CreateRasterizerState( rsDesc); device.RS.SetState( rasterizerState ); // If we don't have a D2D render target, need to create all of the resources // required to render to one here. // Ensure that nobody is holding onto one of the old resources device.OM.SetRenderTargets(new RenderTargetView[] {null}); InitializeDepthStencil(width, height); // Create views on the RT buffers and set them on the device RenderTargetViewDescription renderDesc = new RenderTargetViewDescription(); renderDesc.Format = Format.R8G8B8A8_UNORM; renderDesc.ViewDimension = RenderTargetViewDimension.Texture2D; renderDesc.Texture2D.MipSlice = 0; using (D3DResource spBackBufferResource = swapChain.GetBuffer<D3DResource>(0)) { renderTargetView = device.CreateRenderTargetView( spBackBufferResource, renderDesc); } device.OM.SetRenderTargets(new RenderTargetView[] {renderTargetView}, depthStencilView); SetViewport(width, height); // Create a D2D render target which can draw into the surface in the swap chain RenderTargetProperties props = new RenderTargetProperties( RenderTargetType.Default, new PixelFormat(Format.Unknown, AlphaMode.Premultiplied), 96, 96, RenderTargetUsage.None, FeatureLevel.Default); // Allocate a offscreen D3D surface for D2D to render our 2D content into Texture2DDescription tex2DDescription; tex2DDescription.ArraySize = 1; tex2DDescription.BindFlags = BindFlag.RenderTarget | BindFlag.ShaderResource; tex2DDescription.CpuAccessFlags = CpuAccessFlag.Unspecified; tex2DDescription.Format = Format.R8G8B8A8_UNORM; tex2DDescription.Height = 4096; tex2DDescription.Width = 512; tex2DDescription.MipLevels = 1; tex2DDescription.MiscFlags = 0; tex2DDescription.SampleDescription.Count = 1; tex2DDescription.SampleDescription.Quality = 0; tex2DDescription.Usage = Usage.Default; offscreenTexture = device.CreateTexture2D(tex2DDescription); using (Surface dxgiSurface = offscreenTexture.GetDXGISurface()) { // Create a D2D render target which can draw into our offscreen D3D surface renderTarget = d2DFactory.CreateDxgiSurfaceRenderTarget( dxgiSurface, props); } PixelFormat alphaOnlyFormat = new PixelFormat(Format.A8_UNORM, AlphaMode.Premultiplied); opacityRenderTarget = renderTarget.CreateCompatibleRenderTarget(CompatibleRenderTargetOptions.None, alphaOnlyFormat); // Load pixel shader // Open precompiled vertex shader // This file was compiled using DirectX's SDK Shader compilation tool: // fxc.exe /T fx_4_0 /Fo SciFiText.fxo SciFiText.fx shader = LoadResourceShader(device, "SciFiTextDemo.SciFiText.fxo"); // Obtain the technique technique = shader.GetTechniqueByName("Render"); // Obtain the variables worldMatrixVariable = shader.GetVariableByName("World").AsMatrix(); viewMatrixVariable = shader.GetVariableByName("View").AsMatrix(); projectionMarixVariable = shader.GetVariableByName("Projection").AsMatrix(); diffuseVariable = shader.GetVariableByName("txDiffuse").AsShaderResource(); // Create the input layout PassDescription passDesc = new PassDescription(); passDesc = technique.GetPassByIndex(0).Description; vertexLayout = device.CreateInputLayout( inputLayoutDescriptions, passDesc.InputAssemblerInputSignature, passDesc.InputAssemblerInputSignatureSize ); // Set the input layout device.IA.SetInputLayout( vertexLayout ); IntPtr verticesDataPtr = Marshal.AllocHGlobal(Marshal.SizeOf(VertexArray.VerticesInstance)); Marshal.StructureToPtr(VertexArray.VerticesInstance, verticesDataPtr, true); BufferDescription bd = new BufferDescription(); bd.Usage = Usage.Default; bd.ByteWidth = (uint) Marshal.SizeOf(VertexArray.VerticesInstance); bd.BindFlags = BindFlag.VertexBuffer; bd.CpuAccessFlags = CpuAccessFlag.Unspecified; bd.MiscFlags = ResourceMiscFlag.Undefined; SubresourceData InitData = new SubresourceData() { SysMem = verticesDataPtr }; vertexBuffer = device.CreateBuffer( bd, InitData ); Marshal.FreeHGlobal(verticesDataPtr); // Set vertex buffer uint stride = (uint) Marshal.SizeOf(typeof (SimpleVertex)); uint offset = 0; device.IA.SetVertexBuffers( 0, new D3DBuffer[] {vertexBuffer}, new uint[] {stride}, new uint[] {offset} ); IntPtr indicesDataPtr = Marshal.AllocHGlobal(Marshal.SizeOf(VertexArray.IndicesInstance)); Marshal.StructureToPtr(VertexArray.IndicesInstance, indicesDataPtr, true); bd.Usage = Usage.Default; bd.ByteWidth = (uint) Marshal.SizeOf(VertexArray.IndicesInstance); bd.BindFlags = BindFlag.IndexBuffer; bd.CpuAccessFlags = 0; bd.MiscFlags = 0; InitData.SysMem = indicesDataPtr; facesIndexBuffer = device.CreateBuffer( bd, InitData ); Marshal.FreeHGlobal(indicesDataPtr); // Set primitive topology device.IA.SetPrimitiveTopology(PrimitiveTopology.TriangleList); // Convert the D2D texture into a Shader Resource View textureResourceView = device.CreateShaderResourceView( offscreenTexture); // Initialize the world matrices worldMatrix = Matrix4x4F.Identity; // Initialize the view matrix Vector3F Eye = new Vector3F(0.0f, 0.0f, 13.0f); Vector3F At = new Vector3F(0.0f, -3.5f, 45.0f); Vector3F Up = new Vector3F(0.0f, 1.0f, 0.0f); viewMatrix = Camera.MatrixLookAtLH(Eye, At, Up); // Initialize the projection matrix projectionMatrix = Camera.MatrixPerspectiveFovLH( (float) Math.PI*0.1f, width/(float) height, 0.1f, 100.0f); // Update Variables that never change viewMatrixVariable.Matrix = viewMatrix; projectionMarixVariable.Matrix = projectionMatrix; GradientStop[] gradientStops = { new GradientStop(0.0f, new ColorF(Colors.Yellow)), new GradientStop(1.0f, new ColorF(Colors.Black)) }; GradientStopCollection spGradientStopCollection = renderTarget.CreateGradientStopCollection( gradientStops, Gamma.Gamma_22, ExtendMode.Clamp); // Create a linear gradient brush for text textBrush = renderTarget.CreateLinearGradientBrush( new LinearGradientBrushProperties(new Point2F(0, 0), new Point2F(0, -2048)), spGradientStopCollection ); }
public void SetSourceCode(string extendedSourceCode) { string shaderCode = File.ReadAllText(renderer.Directory + "\\Resources\\Teapot.fx"); try { using (ShaderBytecode bytecode = ShaderBytecode.Compile(extendedSourceCode + shaderCode, null, "fx_5_0", ShaderFlags.None, EffectFlags.None)) { effect = new Effect(renderingDevice, bytecode); } } catch (CompilationException ex) { System.Diagnostics.Debug.Write(ex.Message); return; } effectViewProjection = effect.GetVariableByName("matViewProjection").AsMatrix(); effectCameraPositionWorld = effect.GetVariableByName("cameraPositionWorld").AsVector(); technique = effect.GetTechniqueByIndex(0); pass = technique.GetPassByIndex(0); ShaderSignature signature = pass.Description.Signature; inputLayout = new InputLayout(renderingDevice, signature, new[] { new InputElement("POSITION", 0, SlimDX.DXGI.Format.R32G32B32_Float, 0, 0), new InputElement("NORMAL", 0, SlimDX.DXGI.Format.R32G32B32_Float, 12, 0) }); }
/// <summary> /// Create Direct3D device and swap chain /// </summary> protected void InitDevice() { device = D3DDevice.CreateDeviceAndSwapChain(this.Handle, out swapChain); SetViews(); // Create the effect using (FileStream effectStream = File.OpenRead("Tutorial07.fxo")) { effect = device.CreateEffectFromCompiledBinary(new BinaryReader(effectStream)); } // Obtain the technique technique = effect.GetTechniqueByName( "Render" ); // Obtain the variables worldVariable = effect.GetVariableByName( "World" ).AsMatrix(); viewVariable = effect.GetVariableByName( "View" ).AsMatrix(); projectionVariable = effect.GetVariableByName( "Projection" ).AsMatrix(); meshColorVariable = effect.GetVariableByName( "vMeshColor" ).AsVector(); diffuseVariable = effect.GetVariableByName( "txDiffuse" ).AsShaderResource(); InitVertexLayout(); InitVertexBuffer(); InitIndexBuffer(); // Set primitive topology device.IA.SetPrimitiveTopology(PrimitiveTopology.TriangleList); // Load the Texture using (FileStream stream = File.OpenRead("seafloor.png")) { textureRV = TextureLoader.LoadTexture(device, stream); } InitMatrices(); diffuseVariable.SetResource(textureRV); active = true; }