protected override void Load(ResourceDesc resourceDescription) { ShaderResourceDesc desc = (ShaderResourceDesc)resourceDescription; string file = System.IO.File.ReadAllText(resourceDescription.FileName); InputElements = Rendering.ShaderPreprocessor.Preprocess(file); // Creates a string with specified Defines string defines = ""; if (desc.Defines != null) { foreach (string str in desc.Defines) { defines += String.Format("#define {0}\n", str); } file = defines + file; } ShaderInclude shaderInclude = new ShaderInclude("data/shaders/"); ShaderBytecode vsShaderByteCode = ShaderBytecode.Compile(file, "vs_main", "vs_5_0", ShaderFlags.Debug, EffectFlags.None, null, shaderInclude); ShaderBytecode psShaderByteCode = ShaderBytecode.Compile(file, "ps_main", "ps_5_0", ShaderFlags.Debug, EffectFlags.None, null, shaderInclude); shaderInclude.Dispose(); InputSignature = ShaderSignature.GetInputSignature(vsShaderByteCode); VertexShader = new D3D11.VertexShader(desc.Device, vsShaderByteCode); PixelShader = new D3D11.PixelShader(desc.Device, psShaderByteCode); Shader = new Rendering.Shader(desc.Device, VertexShader, PixelShader, InputSignature, InputElements, resourceDescription.Alias); }
public void onEnter() { this.camera = new PerspecitveCamera(MathHelper.PiOver4, Game.shared.width, Game.shared.height); this.shader = Game.assets.shader("test"); VertexAttributes attrs = new VertexAttributes(VertexAttribute.Position(), VertexAttribute.Color()); this.rawMesh = new VertexBufferObject(true, 3, 7, attrs); this.rawIndicies = new IndexBufferObject(true); float[] data = new float[] { -0.8f, -0.8f, 0f, 1f, 0f, 0f, 1.0f, 0.8f, -0.8f, 0f, 0f, 1f, 0f, 1.0f, 0f, 0.8f, 0f, 0f, 0f, 1f, 1.0f, 0.8f, 0.8f, 0f, 1f, 0f, 1f, 1.0f }; uint[] indicies = new uint[] { 0, 1, 2, 1, 2, 3 }; this.rawIndicies.setIndicies(ref indicies); this.rawMesh.setVerticies(ref data); this.mviewdata = Matrix4.Translation(0f, 0f, 0f); Vector3 cameraPosition = new Vector3(5f, 5f, 5f); this.camera.translate(ref cameraPosition); Vector3 target = new Vector3(0f, 0f, 0f); this.camera.lookAt(ref target); }