public override unsafe void Update(Vec3[] vectors, ShaderVariableMapping variable) { uint srcStride = (uint)ShaderBase.VariableTypeToSrcStride(ShaderVariableType.Float3); uint dstStride = (uint)ShaderBase.VariableTypeToDstStride(ShaderVariableType.Float3); fixed(Vec3 *ptr = vectors) Orbital_Video_D3D12_ConstantBuffer_UpdateArray(handle, ptr, (uint)Marshal.SizeOf <Vec3>(), (uint)vectors.Length, (uint)variable.offset, srcStride, dstStride, activeNodeIndex); }
public override unsafe void Update(Quat[] quaternions, ShaderVariableMapping variable) { uint srcStride = (uint)ShaderBase.VariableTypeToSrcStride(ShaderVariableType.Float4); uint dstStride = (uint)ShaderBase.VariableTypeToDstStride(ShaderVariableType.Float4); fixed(Quat *ptr = quaternions) Orbital_Video_D3D12_ConstantBuffer_UpdateArray(handle, ptr, (uint)Marshal.SizeOf <Quat>(), (uint)quaternions.Length, (uint)variable.offset, srcStride, dstStride, activeNodeIndex); }
public override unsafe void Update(Mat3x2[] matrices, ShaderVariableMapping variable) { uint srcStride = (uint)ShaderBase.VariableTypeToSrcStride(ShaderVariableType.Float3x2); uint dstStride = (uint)ShaderBase.VariableTypeToDstStride(ShaderVariableType.Float3x2); fixed(Mat3x2 *ptr = matrices) Orbital_Video_D3D12_ConstantBuffer_UpdateArray(handle, ptr, (uint)Marshal.SizeOf <Mat3x2>(), (uint)matrices.Length, (uint)variable.offset, srcStride, dstStride, activeNodeIndex); }
public void Render() { MdxRender.Dev.VertexFormat = CustomVertex.PositionTextured.Format; MdxRender.Dev.RenderState.CullMode = Cull.None; for (int i = 1; i < 5; i++) { MdxRender.Dev.TextureState[i].AlphaOperation = TextureOperation.Disable; MdxRender.Dev.TextureState[i].ColorOperation = TextureOperation.Disable; } MdxRender.SM.m_TextureManager.ActivateTexture(0, this.decalTextureIndex, 0); MdxRender.Dev.RenderState.SourceBlend = Blend.One; MdxRender.Dev.RenderState.DestinationBlend = Blend.One; MdxRender.Dev.RenderState.AlphaBlendEnable = true; MdxRender.Dev.TextureState[0].ColorArgument1 = TextureArgument.TextureColor; MdxRender.Dev.TextureState[0].ColorArgument2 = TextureArgument.TextureColor; MdxRender.Dev.TextureState[0].AlphaArgument1 = TextureArgument.TextureColor; MdxRender.Dev.TextureState[0].AlphaArgument2 = TextureArgument.TextureColor; MdxRender.Dev.TextureState[0].AlphaOperation = TextureOperation.SelectArg1; MdxRender.Dev.TextureState[0].ColorOperation = TextureOperation.SelectArg1;//.ModulateInvAlphaAddColor; MdxRender.Dev.TextureState[0].TextureTransform = TextureTransform.Disable; ShaderBase sb = new ShaderBase(); sb.DebugFixedFunctionShader(); MdxRender.Dev.SetStreamSource(0, m_VertexBuffer, 0); MdxRender.Dev.DrawPrimitives(PrimitiveType.TriangleStrip, 0, 2); }
public Flag(Vector3 position) { count++; pole = new GameObject(); flag = new GameObject(); if (meshPole == null) { meshPole = new XMesh("data/flagpole.x"); } if (meshFlag == null) { meshFlag = new XMesh("data/flag.x"); flagShader = new ShaderBase("FlagShader", "data/flag.fx"); flagShader.SetVariable("matWorldViewProj", ShaderBase.ShaderParameters.WorldProjection); flagShader.SetVariable("matWorld", ShaderBase.ShaderParameters.World); flagShader.SetVariable("vecLightDir", new Vector3(-0.3529871f, 0.8714578f, -0.3405313f)); flagShader.SetTechnique("TFlag"); } //this.Position = new Microsoft.DirectX.Vector3((count % 2 == 0)?5f:-5f, 0, (count % 2 == 0)?50f:20f); this.Position = position; pole.Mesh = meshPole; pole.Scale = new Vector3(2, 2, 2); flag.Mesh = meshFlag; flag.Position = new Vector3(0, 2.3f, 0); flag.Shader = flagShader; this.AddChild(pole); this.AddChild(flag); this.Scale = new Microsoft.DirectX.Vector3(2f, 2f, 2f); if (!string.IsNullOrEmpty(oldTexture) && !string.IsNullOrEmpty(newTexture)) { meshFlag.ReplaceTexture(oldTexture, newTexture, true); flagShader.SetVariable("Texture", meshFlag.GetTexture(0)); } }
protected virtual void BindBillboardTexture(DeviceContext context, ShaderBase shader) { var buffer = GeometryBuffer as IBillboardBufferModel; shader.BindTexture(context, shaderTextureSlot, buffer.TextureView); shader.BindSampler(context, textureSamplerSlot, textureSampler); }
/// <summary> /// Sets the shader. /// </summary> /// <param name="shader">The shader.</param> public void SetShader(ShaderBase shader) { switch (shader.ShaderType) { case ShaderStage.Vertex: RemoveAndDispose(ref vertexShader); vertexShader = shader as VertexShader ?? VertexShader.NullVertexShader; break; case ShaderStage.Pixel: RemoveAndDispose(ref pixelShader); pixelShader = shader as PixelShader ?? PixelShader.NullPixelShader; break; case ShaderStage.Compute: RemoveAndDispose(ref computeShader); computeShader = shader as ComputeShader ?? ComputeShader.NullComputeShader; break; case ShaderStage.Hull: RemoveAndDispose(ref hullShader); hullShader = shader as HullShader ?? HullShader.NullHullShader; break; case ShaderStage.Domain: RemoveAndDispose(ref domainShader); domainShader = shader as DomainShader ?? DomainShader.NullDomainShader; break; case ShaderStage.Geometry: RemoveAndDispose(ref geometryShader); geometryShader = shader as GeometryShader ?? GeometryShader.NullGeometryShader; break; } }
public override unsafe void Update(Mat4[] matrices, int offset) { uint srcStride = (uint)ShaderBase.VariableTypeToSrcStride(ShaderVariableType.Float4x4); uint dstStride = (uint)ShaderBase.VariableTypeToDstStride(ShaderVariableType.Float4x4); fixed(Mat4 *ptr = matrices) Orbital_Video_D3D12_ConstantBuffer_UpdateArray(handle, ptr, (uint)Marshal.SizeOf <Mat4>(), (uint)matrices.Length, (uint)offset, srcStride, dstStride, currentNodeIndex); }
public override unsafe void Update(Vec2[] vectors, int offset) { uint srcStride = (uint)ShaderBase.VariableTypeToSrcStride(ShaderVariableType.Float2); uint dstStride = (uint)ShaderBase.VariableTypeToDstStride(ShaderVariableType.Float2); fixed(Vec2 *ptr = vectors) Orbital_Video_D3D12_ConstantBuffer_UpdateArray(handle, ptr, (uint)Marshal.SizeOf <Vec2>(), (uint)vectors.Length, (uint)offset, srcStride, dstStride, currentNodeIndex); }
/// <summary> /// Sets the shader. /// </summary> /// <param name="shader">The shader.</param> public void SetShader(ShaderBase shader) { switch (shader.ShaderType) { case ShaderStage.Vertex: VertexShader = shader as VertexShader; break; case ShaderStage.Pixel: PixelShader = shader as PixelShader; break; case ShaderStage.Compute: ComputeShader = shader as ComputeShader; break; case ShaderStage.Hull: HullShader = shader as HullShader; break; case ShaderStage.Domain: DomainShader = shader as DomainShader; break; case ShaderStage.Geometry: GeometryShader = shader as GeometryShader; break; } }
public void Draw(GraphicsDevice Device, ShaderBase Shader) { foreach (var Mesh in Meshes_) { Mesh.Draw(Device, Shader); } }
public override unsafe void Update(float[] values, ShaderVariableMapping variable) { uint srcStride = (uint)ShaderBase.VariableTypeToSrcStride(ShaderVariableType.Float); uint dstStride = (uint)ShaderBase.VariableTypeToDstStride(ShaderVariableType.Float); fixed(float *ptr = values) Orbital_Video_D3D12_ConstantBuffer_UpdateArray(handle, ptr, sizeof(float), (uint)values.Length, (uint)variable.offset, srcStride, dstStride, activeNodeIndex); }
public override unsafe void Update(Color4[] colors, ShaderVariableMapping variable) { uint srcStride = (uint)ShaderBase.VariableTypeToSrcStride(ShaderVariableType.Float4) / sizeof(float); uint dstStride = (uint)ShaderBase.VariableTypeToDstStride(ShaderVariableType.Float4); fixed(Color4 *ptr = colors) Orbital_Video_D3D12_ConstantBuffer_UpdateColorArray(handle, ptr, (uint)Marshal.SizeOf <Color4>(), (uint)colors.Length, (uint)variable.offset, srcStride, dstStride, activeNodeIndex); }
public DrawCommand(Point[] vertexPositions, uint z, Color color, bool transparency, uint roundness, uint blurRadius, ShaderBase shader, Texture texture, Point[] texCoords, Rectangle?clipRect = null) { if (vertexPositions == null) { throw new ArgumentNullException("Vertex positions must not be null."); } if (shader == null) { throw new ArgumentNullException("Shader must not be null."); } if (roundness != 0u && roundness != 2u && roundness != 4u && roundness != 8u && roundness != 16u) { throw new ArgumentException("The given roundness must be one of: 0, 2, 4, 8, 16."); } if (texture != null) { if (vertexPositions.Length != 4) { throw new ArgumentException("Textures can only be used with rectangular polygons."); } if (texCoords == null) { throw new ArgumentNullException("Tex coords must not be null if the texture is set."); } if (texCoords.Length != vertexPositions.Length) { throw new ArgumentException("Tex coord amount must match the amount of vertices."); } if (blurRadius != 0u) { throw new ArgumentException("Blur is not available for textured sprites."); } } if (blurRadius != 0u && !transparency) { throw new ArgumentException("If blur is active, transparency must be set as well."); } VertexPositions = vertexPositions; Z = z; Color = color; Transparency = transparency; Roundness = roundness; BlurRadius = blurRadius; Shader = shader; Texture = texture; TexCoords = texCoords; ClipRect = clipRect; }
public Terrain(Program owner) { vegetation = new Vegetation(owner); ground = new GameObject(); heightMap = new Heightmap("data/text_height.png", 1000f, 100, 100); heightMap.MaxHeight = 100f; TerrainMesh sceneryMesh = new TerrainMesh(1.0f, heightMap); //sceneryMesh.Texture = new Bonsai.Objects.Textures.TextureBase("data\\grass.png"); ground.Mesh = sceneryMesh; //ground.RotateXAngle = (float)Math.PI / 2; splatShader = new ShaderBase("splatting", "splatting3.fx"); if (Framework.Instance.DeviceCaps.PixelShaderVersion.Major >= 3) { splatShader.SetTechnique("TextureSplatting_fx30"); } else { splatShader.SetTechnique("TextureSplatting"); } splatShader.SetVariable("matViewProj", ShaderBase.ShaderParameters.CameraProjection); splatShader.SetVariable("sunPosition", new Vector3(1, 1, 1)); splatShader.SetVariable("underwater", 0.0f); splatShader.SetVariable("matWorld", ShaderBase.ShaderParameters.World); splatShader.SetVariable("matInvertTransposeWorld", ShaderBase.ShaderParameters.WorldInvertTranspose); splatShader.SetVariable("cameraPos", ShaderBase.ShaderParameters.CameraPosition); splatShader.SetVariable("nearRepeat", 64.0f); splatShader.SetVariable("farRepeat", 20.0f); splatShader.SetVariable("nearFactor2", 3.0f); splatShader.SetVariable("farFactor2", 2.0f); splatShader.SetVariable("nearFactor3", 3.0f); splatShader.SetVariable("farFactor3", 2.0f); splatShader.SetVariable("nearFactor4", 3.0f); splatShader.SetVariable("farFactor4", 2.0f); splatShader.SetVariable("blendSqDistance", 50f * 50f); splatShader.SetVariable("blendSqWidth", 1.0f / (200f * 200f)); TextureBase normalMap = new TextureBase("data/text_norm.png"); TextureBase alphaMap = new TextureBase("data/text.dds"); TextureBase grassTexture = new TextureBase("data/grass.png"); TextureBase rockTexture = new TextureBase("data/rock.png"); TextureBase rockNormal = new TextureBase("data/splat_rock_normal.jpg"); TextureBase sandTexture = new TextureBase("data/sand.png"); TextureBase concreteTexture = new TextureBase("data/road.png"); splatShader.SetVariable("NormalMapTexture", normalMap); splatShader.SetVariable("AlphaTexture", alphaMap); splatShader.SetVariable("DetailTexture1", grassTexture); splatShader.SetVariable("DetailTexture2", rockTexture); splatShader.SetVariable("DetailTexture2NormalMap", rockNormal); splatShader.SetVariable("DetailTexture3", sandTexture); splatShader.SetVariable("DetailTexture4", concreteTexture); ground.Shader = splatShader; }
public void Draw(GraphicsDevice Device, ShaderBase Shader) { Shader.TexDiffuse = TexDiffuse_; Shader.TexSpecular = TexSpecular_; Device.UseShader(Shader); Device.BindVertexBuffer(VertexBuffer_); Device.BindIndexBuffer(IndexBuffer_); Device.DrawElements(PrimitiveType.Triangle, 0, 0, Indices.Length); }
public unsafe override void Update <T>(T[] data, ShaderVariableMapping variable) { uint srcStride = (uint)ShaderBase.VariableTypeToSrcStride(variable.type); uint dstStride = (uint)ShaderBase.VariableTypeToDstStride(variable.type); fixed(T *dataPtr = data) { Orbital_Video_D3D12_ConstantBuffer_UpdateArray(handle, dataPtr, (uint)Marshal.SizeOf <T>(), (uint)data.Length, (uint)variable.offset, srcStride, dstStride, activeNodeIndex); } }
public unsafe override void Update <T>(T[] data, ShaderVariableMapping variable) { uint srcStride = (uint)ShaderBase.VariableTypeToSrcStride(variable.type); uint dstStride = (uint)ShaderBase.VariableTypeToDstStride(variable.type); GCHandle gcHandle = GCHandle.Alloc(data, GCHandleType.Pinned); IntPtr dataPtr = gcHandle.AddrOfPinnedObject(); Orbital_Video_D3D12_ConstantBuffer_UpdateArray(handle, (void *)dataPtr, (uint)Marshal.SizeOf <T>(), (uint)data.Length, (uint)variable.offset, srcStride, dstStride, activeNodeIndex); gcHandle.Free(); }
public override ShaderEffectBase CreateShaderEffect(ShaderBase vs, ShaderBase ps, ShaderBase hs, ShaderBase ds, ShaderBase gs, ShaderEffectDesc desc, bool disposeShaders) { var abstraction = new ShaderEffect(this); if (!abstraction.Init((Shader)vs, (Shader)ps, (Shader)hs, (Shader)ds, (Shader)gs, desc, disposeShaders)) { abstraction.Dispose(); throw new Exception("Failed to create ShaderEffect"); } return(abstraction); }
/// <summary> /// Clean up. /// </summary> public override void Dispose() { count--; if (count == 0) { meshWindSock.Dispose(); meshWindSock = null; flagShader.Dispose(); flagShader = null; } }
private void WriteShader(ShaderBase shader) { WriteUShort(( ushort )shader.Type); WriteInt(shader.DataLength); WriteUShort(shader.Field06); WriteUInt(shader.Field08); WriteUInt(shader.Field0C); WriteUInt(shader.Field10); WriteUInt(shader.Field14); WriteUInt(shader.Field18); WriteBytes(shader.Data); }
public void Dispose() { GC.SuppressFinalize(this); if (DisposedShdaer) { if (Shader != null) { Shader.Dispose(); Shader = null; } } }
/// <summary> /// Clean up. /// </summary> public override void Dispose() { count--; if (count == 0) { meshPole.Dispose(); meshPole = null; meshFlag.Dispose(); meshFlag = null; flagShader.Dispose(); flagShader = null; } pole.Dispose(); flag.Dispose(); }
/// <summary> /// Actual bindings /// </summary> /// <param name="context"></param> /// <param name="shader"></param> private void OnBindMaterialTextures(DeviceContext context, ShaderBase shader) { int idx = shader.ShaderType.ToIndex(); for (int i = 0; i < NUMTEXTURES; ++i) { if (TextureResources[i] == null) { continue; } shader.BindTexture(context, TextureBindingMap[idx][i], TextureResources[i]); shader.BindSampler(context, SamplerBindingMap[idx][i], SamplerResources[i]); } if (RenderShadowMap) { shader.BindSampler(context, SamplerBindingMap[idx][NUMSAMPLERS - 1], SamplerResources[NUMSAMPLERS - 1]); } }
/// <summary> /// Actual bindings /// </summary> /// <param name="context"></param> /// <param name="shader"></param> private void OnBindMaterialTextures(DeviceContext context, ShaderBase shader) { if (shader.IsNULL) { return; } int idx = shader.ShaderType.ToIndex(); for (int i = 0; i < NUMTEXTURES; ++i) { if (TextureResources[i].TextureView == null) { continue; } shader.BindTexture(context, TextureBindingMap[idx][i], TextureResources[i]); shader.BindSampler(context, SamplerBindingMap[idx][i], SamplerResources[i]); } }
public WindSock() { count++; if (meshWindSock == null) { meshWindSock = new XMesh("flag.x"); flagShader = new ShaderBase("FlagShader", "flag.fx"); flagShader.SetVariable("matWorldViewProj", ShaderBase.ShaderParameters.WorldProjection); flagShader.SetVariable("matWorld", ShaderBase.ShaderParameters.World); flagShader.SetTechnique("TVertexShaderOnly"); //texture = new TextureBase("EuropeFlag.jpg"); //flagShader.SetVariable("Tex0", texture); } this.Mesh = meshWindSock; this.Shader = flagShader; this.Scale = new Microsoft.DirectX.Vector3(1f, 1f, 1f); this.Position = new Microsoft.DirectX.Vector3(1, 1, 0); }
public TestObject(GraphicsDevice Device) : base(Device) { Rand_ = new Random((int)DateTime.Now.Ticks); var Vertices = new[] { -1f, 1f, 0f, 0f, 0f, 0f, 0f, 1f, // 0 1f, 1f, 0f, 1f, 0f, 0f, 0f, 1f, // 1 1f, -1f, 0f, 1f, 1f, 0f, 0f, 1f, // 2 -1f, -1f, 0f, 0f, 1f, 0f, 0f, 1f // 3 }; var Indices = new[] { 0, 3, 1, // first triangle 1, 3, 2 // second triangle }; VertexBuffer_ = new VertexBufferObject(VertexBufferFormat.PositionUvNormal, Vertices); IndexBuffer_ = new IndexBufferObject(Indices); var DirLight = new Light(); DirLight.Type = LightType.Direction; DirLight.Direction = new Vector3(0.2f, 0.2f, -1f); DirLight.Ambient = new Colorf(0.05f, 0.05f, 0.05f); DirLight.Diffuse = new Colorf(0.4f, 0.4f, 0.4f); DirLight.Specular = new Colorf(0.5f, 0.5f, 0.5f); DirLight.Enabled = true; DirLight.UpdateSIMD(); Shader_ = new ShaderLight(); Shader_.Lights = new Light[1]; Shader_.Lights[0] = DirLight; Shader_.TexDiffuse = TextureHelper.Load("container2.png"); Shader_.TexSpecular = TextureHelper.Load("container2_specular.png"); Shader_.SpecularPower = 32; //Camera_ = new Camera(new Vector3(0, 0, 3), new Vector3(0, 0, -1), new Vector3(0, 1, 0), 60.0f, 800.0f / 600.0f, 0.3f, 100.0f); Camera_ = new Camera(800, 600); }
/// <summary> /// Clean up. /// </summary> public override void Dispose() { if (surfaceDefinition.Type == AircraftParameters.ControlSurfaceTypeEnum.PropHighRPM || surfaceDefinition.Type == AircraftParameters.ControlSurfaceTypeEnum.RotorHighRPM || surfaceDefinition.Type == AircraftParameters.ControlSurfaceTypeEnum.TailrotorHighRPM) { Program.Instance.TransparentObjectManager.Objects.Remove(this); } if (Mesh != null) { Mesh.Dispose(); Mesh = null; } if (reflectionShader != null) { reflectionShader.Dispose(); reflectionShader = null; } }
void IDisposable.Dispose() { DeleteShaderResources(); if (waterShader != null) { waterShader.Dispose(); waterShader = null; } if (waterNormalTexture != null) { waterNormalTexture.Dispose(); waterNormalTexture = null; } if (squareMesh.Texture != null) { squareMesh.Texture.Dispose(); squareMesh.Texture = null; } base.Dispose(); }
public GraphicsContext(GraphicsDevice Device, Box Viewport) { this.CoreNum = 6; this.Device = Device; this.Viewport = Viewport; this.FrameCount = 0; this.ColorBuffer = null; this.ZBuffer = new float[Viewport.Width * Viewport.Height]; this.Vertices = new ListCore <Vertex>(this.CoreNum); this.Fragments = new ListCore <Fragment>(this.CoreNum); this.Indices = null; this.ClearColor = Colorf.Black; this.FillModeState = FillMode.Solid; this.CullFaceModeState = CullFaceMode.Back; this.FrontFaceModeState = FrontFaceMode.CCW; this.Shader = null; this.VertexBuffer = null; this.IndexBuffer = null; }
void NewAdvanced(){ if (OpenShader!=null) OpenShader.CleanUp(); OpenShader = ShaderBase.CreateInstance<ShaderBase>(); OpenShader.DiffMode.On = true; ShaderSandwich.ShaderLayerTab = ShaderLayerTabs.Base; Goto(GUIType.Layers,ShaderTransition.TransDir.Forward); ChangeSaveTemp(null); CurrentFilePath = ""; }
void NewSimple(){ if (OpenShader!=null) OpenShader.CleanUp(); OpenShader = ShaderBase.CreateInstance<ShaderBase>(); ShaderSandwich.ShaderLayerTab = ShaderLayerTabs.Base; Goto(GUIType.Presets,ShaderTransition.TransDir.Forward); ChangeSaveTemp(null); CurrentFilePath = ""; }
void SimpleLoad(string path){ SetStatus("Loading File","Loading Shader...",0.1f); string line = ""; string FileString = ""; StreamReader theReader = new StreamReader(path); //using (theReader) //{ bool inParse = false; bool didParse = false; while(true==true) { line = theReader.ReadLine(); //Debug.Log(line); if (line != null) { line = line.Trim(); if (line.Contains("BeginShaderParse")) { inParse = true; didParse = true; } if (line.IndexOf("#?")>=0) line = line.Substring(0,line.IndexOf("#?")); if (inParse==true&&(line!="")) FileString+=line+"\n"; if (line.Contains("EndShaderParse")) inParse = false; } else{ break; } } //Debug.Log(FileString); theReader.Close(); if (didParse){ OpenShader = ShaderBase.Load(new StringReader(FileString)); RegenShaderPreview(); GUI.changed = true; ChangeSaveTemp(null); }else{ EditorUtility.DisplayDialog("Oh no!","Sorry, the shader you chose wasn't made with Shader Sandwich, so it can't be opened :(.","Ok"); } SetStatus("Loading File","Shader Loaded.",1f); }