• Advertisement
  • Popular Tags

  • Popular Now

  • Advertisement
  • Similar Content

    • By ThunderTwonk
      Hello everyone, I am working on a game idea and since I am still in the process of learning C# and the features available in unity I was hoping some of you might be able to offer me a little insight on things in general for getting started.
      I guess the basic components of what I'm wanting to create would be a Multi-levels management/city builder/rpg.
      The goal is to provide a framework for players to interact with, build in and affect the world both from a 3rd person action RPG as well as a zoomed out 4x style view (This would be something unlocked through gameplay)
       
      As for my questions go I was wondering if anyone had resources that could help me learn.  I've been on youtube as well as enrolled in an online course for basic unity and C# and will continue those but if anyone has any words of advice, a place that has good information and tutorials etc.
       
      Thanks for your time.
    • By Cahit Karahan

       
      Hi, I'm new in this forum. It is honorable to see such communities exist. I would like to share my new game. I did for android with unity. I know the game is a little awkward , but you have to know that this game is from the time when Unity's name is Unity3D  I have made my first game when I was 12. Now I am 22.  I have taken a lot of experience in this process and I can make better games nowadays. I have published this game nowadays but actually this game is very old but also it is very special for me :))
      I have just wanted to retouch and share this game, because it has a very important place for me.
       
      DESCRIPTION FROM GOOGLE PLAY STORE

      It's a special free 3D horror adventure action game for the halloween. Fun with scary sound effects and musics, 3D realistic graphics, you will feel the horror in the deep of your heart. Use your reflex. Totally free adventure. Totally scary horror game. 

      Tamarra, she is a beast from our world. She needs to consume souls from innocent people to stay alive. Story begins, the old Elaris tribe had lost their everything because of this beast who lived in the well. Araknas was the most powerful warrior of the tribe. One day, Araknas's mother was killed by the servant beasts of Tamarra. That's how Araknas's journey to the well begins. Tamara's well is guarded by horrible beasts. Araknas has to pass all servant beasts until he reaches Tamarra.

      Even death at the end is worth the revenge. 
      Are you brave enough to jump into Tamarra's well?

      Survive from witch attacks, clown attacks and many scary creature.

      - Realistic 3D graphics.
      - Scary sounds.
      - Scary musics.
      - Best experience with headphones.
      - A demon cage where you can imprison all the demons one by one
      - The witches do not like help, but they love blood stone. Witch store where you can develop your abilities and get new abilities.
      - Countless beasts.
      - At the end of the well there is a hidden surprise for you.

      *We do not recommend this game to people with clown phobia, spider phobia, or panic attacks.*

      **!!!**Note : This game is an early-access game, we are upgrading new features every day, new beasts, new improvements, as an example online 1vs1 fall on the list, so stay on connect and follow Halloween : Horror Well on Google Play.**!!!**

    • By INFRA
      SCAN. DRILL. SURVIVE.   ISOLATED Release in May 1st 2018   https://store.steampowered.com/app/805950/Isolated/   A game by Jérémie Bertrand Music & Sound Design by Pierrick Querolle *** Our solar system has been invaded by strangers. For the purpose of a possible negotiation, a team of astronauts is sent to the moon. Alas, they are shot before even arriving on the scene. Only one astronaut survives the crash and his only goal will be to go home...   GAMEPLAY   Shoot enemy ships to avoid being invaded. Be precise in your movements, because it's better to lose a bit of life at the top than to lose it all at the bottom. Take out your drill to destroy the stones in your path. Validate your identity to cross the different laboratories. Reach the flag before losing your three lives.   And all that... at the same time! Will you be able to go home? If the answer is yes, how long will it take?
    • By BigJiggly
      Hello! So, I've been the leader of BJP for a while now. I'm a bit bored of taking the role I always take, leader. I was hoping someone out there is looking to forge a team maybe and needs a programmer. 
      I have experience mainly in the Unity engine(C# intermediate) and I have a very small amount of knowledge on Shaders, as well as experience on developing games(usually end up stuck in dev hell) and leading experience from my last team which at one point reached 11 people. I personally love the Unity engine and prefer to use it as it's the development environment I'm comfortable with. 
      I have used Unity for over a year and a few months, I'd consider myself an intermediate at the Engine, but to this day Unity still surprises me. 
      I live in the United Kingdom, I find it a bit strange to work with other programmers as the ones I've worked with tend to leave their code heavily unoptimised and I'm a on the go optimise kind of guy, I also like to get things done quickly.
       
      If you're a new team and need a programmer that has high levels of ambition and strives to maintain the motivation throughout the team, then I'm your guy. I don't care if you're just beginning because I'm all for helping people learn!
       
      To finish this off: I like to get things done and I like to get them done right the first time, if I fail I will do it again and again, etc, until I loose all motivation. So if you're a modeller or an artist, please don't leave me to do all the modelling/art as well as the programming and sound. I do have experience in all those areas but my main power is in programming and I'd prefer to keep it that way.
       
      [If this was posted in the wrong forum, sorry, I don't really know the layout of this website yet]
    • By Alexia
      Hi all,
      A small team are currently undertaking a fairly large game project involving multi-playing, taming and other complex game mechanisms.
      We are looking for someone who is experienced in programming a wide range of mechanisms, more information is on our discord server. It is also a learning experience and we wouldn't expect you to know how to do everything we wanted, but just ask that you would be willing to learn how to.
      If you are interested in joining the (rather long term project) just message me and i'll add you on discord.
      Thanks for your time,
      Alexia 
  • Advertisement
  • Advertisement
Sign in to follow this  

Unity SharpDX how to set texture on polygon correctly ?

Recommended Posts

I am trying to display texture on mesh correctly but texture looks like crushed. I added references. I have texture on polygon I think there is UV problem.

 

Program.cs

// Copyright (c) 2010-2013 SharpDX - Alexandre Mutel
// 
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
// 
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
// 
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
using System;
using System.Diagnostics;
using System.Windows.Forms;


using SharpDX;
using SharpDX.D3DCompiler;
using SharpDX.Direct3D;
using SharpDX.Direct3D11;
using SharpDX.DXGI;
using SharpDX.Windows;
using Buffer = SharpDX.Direct3D11.Buffer;
using Device = SharpDX.Direct3D11.Device;
using SharpDX.RawInput;
using SharpDX.Multimedia;
using CubeApp.EngineTools;


using AlphaMode = SharpDX.Direct2D1.AlphaMode;
using Factory = SharpDX.DXGI.Factory;
using System.Threading;
using System.Collections.Generic;
using CubeApp.Configration;
using CubeApp.Windows;


namespace CubeApp
{
    /// <summary>
    /// SharpDX MiniCube Direct3D 11 Sample
    /// </summary>
    internal static class Program
    {
        [STAThread]
        private static void Main()
        {
            new Thread(new ThreadStart(() =>
            {
                DisposeCollector DC=new DisposeCollector();
                var form = new RenderForm(Globals.Window_Title) { Width = Globals.Window_Size.Width, Height = Globals.Window_Size.Height, AllowUserResizing = false, MinimizeBox = false };
                InputHandler IHandler = new InputHandler(form);
                SampleDescription SamplerDesc = new SampleDescription(8, 0);
                // SwapChain description
                var desc = new SwapChainDescription()
                {
                    BufferCount = 2,
                    ModeDescription = new ModeDescription(form.ClientSize.Width, form.ClientSize.Height, new Rational(60, 1), Format.R8G8B8A8_UNorm),
                    IsWindowed = true,
                    OutputHandle = form.Handle,
                    SampleDescription = SamplerDesc,
                    SwapEffect = SwapEffect.Discard,
                    Usage = Usage.RenderTargetOutput
                };


                var samplerStateDescription = new SamplerStateDescription
                {
                    AddressU = TextureAddressMode.Wrap,
                    AddressV = TextureAddressMode.Wrap,
                    AddressW = TextureAddressMode.Wrap,
                    Filter = Filter.MinMagMipLinear
                };
                var rasterizerStateDescription = RasterizerStateDescription.Default();
                rasterizerStateDescription.IsFrontCounterClockwise = true;


                // Used for debugging dispose object references
                Configuration.EnableObjectTracking = true;


                // Disable throws on shader compilation errors
                Configuration.ThrowOnShaderCompileError = false;


                SharpDX.DXGI.Factory factory = new SharpDX.DXGI.Factory1();
                SharpDX.DXGI.Adapter adapter = factory.GetAdapter(1);


                Adapter[] availableAdapters = factory.Adapters;
                foreach(Adapter _adapter in availableAdapters)
                {
                    Console.WriteLine(_adapter.Description.Description);
                }
                // Create Device and SwapChain
                Device device;
                SwapChain swapChain;
                Device.CreateWithSwapChain(adapter, DeviceCreationFlags.SingleThreaded, desc, out device, out swapChain);


                var context = device.ImmediateContext;


                //factory.MakeWindowAssociation(form.Handle, WindowAssociationFlags.IgnoreAll);


                // Compile Vertex and Pixel shaders
                var vertexShaderByteCode = ShaderBytecode.CompileFromFile("MiniCube.hlsl", "VS", "vs_5_0", ShaderFlags.Debug);
                var vertexShader = new VertexShader(device, vertexShaderByteCode);


                var pixelShaderByteCode = ShaderBytecode.CompileFromFile("MiniCube.hlsl", "PS", "ps_5_0", ShaderFlags.Debug);
                var pixelShader = new PixelShader(device, pixelShaderByteCode);


                var signature = ShaderSignature.GetInputSignature(vertexShaderByteCode);


                // Layout from VertexShader input signature
                var layout = new InputLayout(device, signature, new[]
                {
                new InputElement("POSITION", 0, Format.R32G32B32A32_Float, 0, 0),
                new InputElement("NORMAL", 0, Format.R32G32B32A32_Float, 0, 0),
                new InputElement("COLOR", 0, Format.R32G32B32A32_Float, 16, 0),
                new InputElement("TEXCOORD", 0, Format.R32G32_Float, InputElement.AppendAligned, 0)


                });


                var samplerState = new SamplerState(device, samplerStateDescription);


                Mesh mesh1 = new Mesh("mesh1", new[] { new Vector4(0, 0, 0, 1) }, "", device, "1_Purple.jpg") { IsSelected=true };
                Mesh mesh2 = new Mesh("mesh2", new[] { new Vector4(0, 0, 0, 1) }, "", device, "1_Purple.jpg");
                //MenuCreator menu1 = new MenuCreator(device,new[] {new Vector4(0, 0, 0, 0) });
                // Create Constant Buffer
                var contantBuffer = new Buffer(device, Utilities.SizeOf<Matrix>(), ResourceUsage.Default, BindFlags.ConstantBuffer, CpuAccessFlags.None, ResourceOptionFlags.None, 0);


                ShaderResourceView textureView;
                SharpDX.WIC.ImagingFactory2 ImagingFactory2 = new SharpDX.WIC.ImagingFactory2();


                // Prepare All the stages
                context.InputAssembler.InputLayout = layout;




                context.VertexShader.SetConstantBuffer(0, contantBuffer);
                context.VertexShader.Set(vertexShader);
                context.PixelShader.Set(pixelShader);
                context.PixelShader.SetSampler(0, samplerState);
                //context.PixelShader.SetShaderResource(0, textureView);


                Matrix proj = Matrix.Identity;


                // Use clock
                var clock = new Stopwatch();
                FPS fps = new FPS();
                clock.Start();


                // Declare texture for rendering
                bool userResized = true;
                Texture2D backBuffer = null;
                RenderTargetView renderView = null;
                Texture2D depthBuffer = null;
                DepthStencilView depthView = null;


                // Setup handler on resize form
                form.UserResized += (sender, args) => userResized = true;


                // Setup full screen mode change F5 (Full) F4 (Window)
                form.KeyUp += (sender, args) =>
                {
                    if (args.KeyCode == Keys.F5)
                    swapChain.SetFullscreenState(true, null);
                    else if (args.KeyCode == Keys.F4)
                        swapChain.SetFullscreenState(false, null);
                    else if (args.KeyCode == Keys.Escape)
                        form.Close();
                };


                //CREATE DEPTH STENCIL DESCRIPTION
                DepthStencilStateDescription depthSSD = new DepthStencilStateDescription();
                depthSSD.IsDepthEnabled = false;
                depthSSD.DepthComparison = Comparison.LessEqual;
                depthSSD.DepthWriteMask = DepthWriteMask.Zero;
                DepthStencilState DSState = new DepthStencilState(device, depthSSD);


                Camera camera = new Camera();
                camera.eye = new Vector3(0, 0, -5);
                camera.target = new Vector3(0, 0, 0);
                Globals.Render = true;
                /*void DrawEmptyCircle(Vector3 startPoint, Vector2 radius, Color color)
                {
                    List<VertexPositionColor> circle = new List<VertexPositionColor>();
                    float X, Y;


                    var stepDegree = 0.3f;
                    for (float angle = 0; angle <= 360; angle += stepDegree)
                    {
                        X = startPoint.X + radius.X * (float)Math.Cos((angle));
                        Y = startPoint.Y + radius.Y * (float)Math.Sin((angle));
                        Vector3 point = new Vector3(X, Y, 0);
                        circle.Add(new VertexPositionColor(point, color));
                    }
                }*/
                CubeApp.Windows.SystemInformation.Print(CubeApp.Windows.SystemInformation.GetSystemInformation());
                HardwareInformation.GetHardwareInformation("Win32_DisplayConfiguration", "Description");


                // Main loop
                RenderLoop.Run(form, () =>
                {


                    
                        fps.Count();fps.setFormHeader(form);
                    // Prepare matrices
                    if (Globals.Render)
                    {
                        var view = camera.getView();


                    // If Form resized
                    if (userResized)
                    {
                        // Dispose all previous allocated resources
                        Utilities.Dispose(ref backBuffer);
                        Utilities.Dispose(ref renderView);
                        Utilities.Dispose(ref depthBuffer);
                        Utilities.Dispose(ref depthView);


                            foreach (Mesh _mesh in Meshes.MeshCollection)
                        {
                            if (_mesh.IsDisposed == false)
                            {
                                Utilities.Dispose(ref _mesh.VerticesBuffer);
                            }
                        }


                            // Resize the backbuffer
                            swapChain.ResizeBuffers(desc.BufferCount, form.ClientSize.Width, form.ClientSize.Height, Format.Unknown, SwapChainFlags.None);
                            // Get the backbuffer from the swapchain
                            backBuffer = Texture2D.FromSwapChain<Texture2D>(swapChain, 0);
                            // Renderview on the backbuffer
                            renderView = new RenderTargetView(device, backBuffer);
                            // Create the depth buffer
                            depthBuffer = new Texture2D(device, new Texture2DDescription()
                            {
                                Format = Format.D32_Float_S8X24_UInt,
                                ArraySize = 1,
                                MipLevels = 1,
                                Width = form.ClientSize.Width,
                                Height = form.ClientSize.Height,
                                SampleDescription = SamplerDesc,
                                Usage = ResourceUsage.Default,
                                BindFlags = BindFlags.DepthStencil,
                                CpuAccessFlags = CpuAccessFlags.None,
                                OptionFlags = ResourceOptionFlags.None
                            });


                            // Create the depth buffer view
                            depthView = new DepthStencilView(device, depthBuffer);
                            // Setup targets and viewport for rendering
                            context.Rasterizer.SetViewport(new Viewport(0, 0, form.ClientSize.Width, form.ClientSize.Height, 0.0f, 1.0f));
                            //context.OutputMerger.SetDepthStencilState(DSState);
                            context.OutputMerger.SetTargets(depthView, renderView);
                            // Setup new projection matrix with correct aspect ratio
                            proj = Matrix.PerspectiveFovLH((float)Math.PI / 4.0f, form.ClientSize.Width / (float)form.ClientSize.Height, 0.1f, 100.0f);
                            // We are done resizing
                            userResized = false;
                        }
                        var time = clock.ElapsedMilliseconds / 1000.0f;
                        var viewProj = Matrix.Multiply(view, proj);


                // Clear views
                context.ClearDepthStencilView(depthView, DepthStencilClearFlags.Depth, 1.0f, 0);
                context.ClearRenderTargetView(renderView, Color.WhiteSmoke);


                // Update WorldViewProj Matrix
                var worldViewProj = Matrix.RotationX(45) * Matrix.RotationY(0 * 2) * Matrix.RotationZ(0 * .7f) * viewProj;
                worldViewProj.Transpose();
                context.UpdateSubresource(ref worldViewProj, contantBuffer);


                    //Update Camera Position
                    Vector3 _camEye = camera.eye;
                    Vector3 _camTarget = camera.target;


                    if (IHandler.KeyW)
                    {
                        _camEye.Z+= 0.050f; _camTarget.Z += 0.050f;
                    }
                    if (IHandler.KeyS)
                    {
                        _camEye.Z -= 0.050f; _camTarget.Z -= 0.050f;
                    }
                    if (IHandler.KeyA)
                    {
                            _camEye.X -= 0.050f; _camTarget.X -= 0.050f;


                    }
                    if (IHandler.KeyD)
                    {
                        _camTarget.X += 0.050f;
                        _camEye.X += 0.050f;


                    }
                    if (IHandler.KeyQ)
                    {


                    }
                    camera.eye = _camEye;
                    camera.target = _camTarget;
                    camera.updateView();


                    // Draw the cube
                    foreach (Mesh __mesh in Meshes.MeshCollection)
                    {
                        if ( __mesh.IsSelected )
                        {
                            for (int i = 0; i <= __mesh.VerticesCount - 1; i++)
                            {
                                if (IHandler.KeyRight) __mesh.Vertices[i].X += 0.050f;
                                if (IHandler.KeyLeft) __mesh.Vertices[i].X -= 0.050f;
                                if (IHandler.KeyUp) __mesh.Vertices[i].Y += 0.050f;
                                if (IHandler.KeyDown) __mesh.Vertices[i].Y -= 0.050f;
                            }
                    }
                            var texture = TextureLoader.CreateTexture2DFromBitmap(device, TextureLoader.LoadBitmap(ImagingFactory2, __mesh.Texture_DiffuseMap));
                            textureView = new ShaderResourceView(device, texture);


                            context.PixelShader.SetShaderResource(0, textureView);
                            texture.Dispose();
                            textureView.Dispose();
                            __mesh.VerticesBuffer = SharpDX.Direct3D11.Buffer.Create(device, BindFlags.VertexBuffer, __mesh.Vertices);
                        //EnvironmentDisplayModes.SetDisplayMode(device, __mesh, EnvironmentDisplayModes.DisplayMode.Standart);
                        __mesh.Render();
                }
                    /*context.ClearDepthStencilView(depthView, DepthStencilClearFlags.Depth, 1.0f, 0);


                    var view2 = Matrix.LookAtLH(new Vector3(0, 0, -10), new Vector3(0, 0, 0), Vector3.UnitY);
                    var viewProj2 = Matrix.Multiply(view2, proj);
                    var worldViewProj2 = Matrix.RotationX(0) * Matrix.RotationY(0) * Matrix.RotationZ(0) * viewProj2;
                    worldViewProj2.Transpose();
                    context.UpdateSubresource(ref worldViewProj2, contantBuffer);
                    */
                    /*for (int i = 0; i <= menu1.VerticesCount - 1; i++)
                    {
                        if (IHandler.KeyRight) menu1.Vertices[i].X -= 0.010f;
                        if (IHandler.KeyLeft) menu1.Vertices[i].X += 0.010f;
                        if (IHandler.KeyUp) menu1.Vertices[i].Y -= 0.010f;
                        if (IHandler.KeyDown) menu1.Vertices[i].Y += 0.010f;
                    }


                    menu1.VerticesBuffer = SharpDX.Direct3D11.Buffer.Create(device, BindFlags.VertexBuffer, menu1.Vertices);
                    menu1.Render();
                    context.Draw(menu1.VerticesCount, 0);*/


                // Present!
                swapChain.Present(0, PresentFlags.None);
                    }
                });
                // Release all resources
                foreach (Mesh msh in Meshes.MeshCollection)
                {
                    msh.d3dDevice.Dispose();
                    msh.VerticesBuffer.Dispose();
                }
            DC.DisposeAndClear();
            signature.Dispose();
            vertexShaderByteCode.Dispose();
            vertexShader.Dispose();
            pixelShaderByteCode.Dispose();
            pixelShader.Dispose();
            layout.Dispose();
            contantBuffer.Dispose();
            depthBuffer.Dispose();
            depthView.Dispose();
            renderView.Dispose();
            backBuffer.Dispose();
            ImagingFactory2.Dispose();
            //context.ClearState();
            //context.Flush();
                device.Dispose();
            context.Dispose();
            swapChain.Dispose();
            factory.Dispose();
            adapter.Dispose();
            DSState.Dispose();
            samplerState.Dispose();
            DC.Dispose();
            form.Dispose();
            })).Start();
            /*new Thread(new ThreadStart(() =>
            { ToolWindow tw = new ToolWindow(); })).Start();*/


    }
    }
}

Mesh.cs

using ChamberLib.Content;
using CubeApp.EngineTools;
using SharpDX;
using SharpDX.Direct3D;
using SharpDX.Direct3D11;
using SharpDX.DXGI;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using FBX = FbxSharp;
using FBXCL = ChamberLib;


namespace CubeApp
{
    public class Mesh : IDisposable
    {
        public string File;
        public string Name;
        public Vector4[] Vertices { get; set; }
        public int VerticesCount=0;
        public Vector3 Position; //BASED ON PIVOT
        public Vector3 PivotPosition; //MOVE MESH BASED ON THIS POSITION
        public Vector3 Rotation;
        public double Weight;
        public SharpDX.Direct3D11.Device d3dDevice;
        public SharpDX.Direct3D11.Buffer VerticesBuffer;


        public bool IsDisposed=false;
        public bool IsSelected = false;
        public int Triangles;
        public string Texture_DiffuseMap;
        public Vector2 [] UV=new Vector2[]
        {
           new Vector2(0f,0f),
           new Vector2(1f,0f),
           new Vector2(1f,1f),
           new Vector2(0f,1f)
            };


        public Mesh(string _name, Vector4[] _vertices, string _file, SharpDX.Direct3D11.Device _device, string _Texture_DiffuseMap = "")
        {
            Vertices = new[]
            {
                new Vector4(-1.0f, -1.0f, -1.0f, 1.0f), new Vector4(1.0f, 0.0f, 0.0f, 1.0f), // Front
                new Vector4(-1.0f,  1.0f, -1.0f, 1.0f), new Vector4(1.0f, 0.0f, 0.0f, 1.0f),
                new Vector4( 1.0f,  1.0f, -1.0f, 1.0f), new Vector4(1.0f, 0.0f, 0.0f, 1.0f),
                new Vector4(-1.0f, -1.0f, -1.0f, 1.0f), new Vector4(1.0f, 0.0f, 0.0f, 1.0f),
                new Vector4( 1.0f,  1.0f, -1.0f, 1.0f), new Vector4(1.0f, 0.0f, 0.0f, 1.0f),
                new Vector4( 1.0f, -1.0f, -1.0f, 1.0f), new Vector4(1.0f, 0.0f, 0.0f, 1.0f),
                new Vector4(-1.0f, -1.0f,  1.0f, 1.0f), new Vector4(0.0f, 1.0f, 0.0f, 1.0f), // BACK
                new Vector4( 1.0f,  1.0f,  1.0f, 1.0f), new Vector4(0.0f, 1.0f, 0.0f, 1.0f),
                new Vector4(-1.0f,  1.0f,  1.0f, 1.0f), new Vector4(0.0f, 1.0f, 0.0f, 1.0f),
                new Vector4(-1.0f, -1.0f,  1.0f, 1.0f), new Vector4(0.0f, 1.0f, 0.0f, 1.0f),
                new Vector4( 1.0f, -1.0f,  1.0f, 1.0f), new Vector4(0.0f, 1.0f, 0.0f, 1.0f),
                new Vector4( 1.0f,  1.0f,  1.0f, 1.0f), new Vector4(0.0f, 1.0f, 0.0f, 1.0f),
                new Vector4(-1.0f, 1.0f, -1.0f,  1.0f), new Vector4(0.0f, 0.0f, 1.0f, 1.0f), // Top
                new Vector4(-1.0f, 1.0f,  1.0f,  1.0f), new Vector4(0.0f, 0.0f, 1.0f, 1.0f),
                new Vector4( 1.0f, 1.0f,  1.0f,  1.0f), new Vector4(0.0f, 0.0f, 1.0f, 1.0f),
                new Vector4(-1.0f, 1.0f, -1.0f,  1.0f), new Vector4(0.0f, 0.0f, 1.0f, 1.0f),
                new Vector4( 1.0f, 1.0f,  1.0f,  1.0f), new Vector4(0.0f, 0.0f, 1.0f, 1.0f),
                new Vector4( 1.0f, 1.0f, -1.0f,  1.0f), new Vector4(0.0f, 0.0f, 1.0f, 1.0f),
                new Vector4(-1.0f,-1.0f, -1.0f,  1.0f), new Vector4(1.0f, 1.0f, 0.0f, 1.0f), // Bottom
                new Vector4( 1.0f,-1.0f,  1.0f,  1.0f), new Vector4(1.0f, 1.0f, 0.0f, 1.0f),
                new Vector4(-1.0f,-1.0f,  1.0f,  1.0f), new Vector4(1.0f, 1.0f, 0.0f, 1.0f),
                new Vector4(-1.0f,-1.0f, -1.0f,  1.0f), new Vector4(1.0f, 1.0f, 0.0f, 1.0f),
                new Vector4( 1.0f,-1.0f, -1.0f,  1.0f), new Vector4(1.0f, 1.0f, 0.0f, 1.0f),
                new Vector4( 1.0f,-1.0f,  1.0f,  1.0f), new Vector4(1.0f, 1.0f, 0.0f, 1.0f),
                new Vector4(-1.0f, -1.0f, -1.0f, 1.0f), new Vector4(1.0f, 0.0f, 1.0f, 1.0f), // Left
                new Vector4(-1.0f, -1.0f,  1.0f, 1.0f), new Vector4(1.0f, 0.0f, 1.0f, 1.0f),
                new Vector4(-1.0f,  1.0f,  1.0f, 1.0f), new Vector4(1.0f, 0.0f, 1.0f, 1.0f),
                new Vector4(-1.0f, -1.0f, -1.0f, 1.0f), new Vector4(1.0f, 0.0f, 1.0f, 1.0f),
                new Vector4(-1.0f,  1.0f,  1.0f, 1.0f), new Vector4(1.0f, 0.0f, 1.0f, 1.0f),
                new Vector4(-1.0f,  1.0f, -1.0f, 1.0f), new Vector4(1.0f, 0.0f, 1.0f, 1.0f),
                new Vector4( 1.0f, -1.0f, -1.0f, 1.0f), new Vector4(0.0f, 1.0f, 1.0f, 1.0f), // Right
                new Vector4( 1.0f,  1.0f,  1.0f, 1.0f), new Vector4(0.0f, 1.0f, 1.0f, 1.0f),
                new Vector4( 1.0f, -1.0f,  1.0f, 1.0f), new Vector4(0.0f, 1.0f, 1.0f, 1.0f),
                new Vector4( 1.0f, -1.0f, -1.0f, 1.0f), new Vector4(0.0f, 1.0f, 1.0f, 1.0f),
                new Vector4( 1.0f,  1.0f, -1.0f, 1.0f), new Vector4(0.0f, 1.0f, 1.0f, 1.0f),
                new Vector4( 1.0f,  1.0f,  1.0f, 1.0f), new Vector4(0.0f, 1.0f, 1.0f, 1.0f),
            };
            Texture_DiffuseMap = _Texture_DiffuseMap;
            _vertices = Vertices;
            d3dDevice = _device;
            VerticesCount = Vertices.Count();


            /* var _verticesBuffer = SharpDX.Direct3D11.Buffer.Create(_device, BindFlags.VertexBuffer, Vertices);
             VerticesBuffer = _verticesBuffer;*/


            Name = _name;
            File = _file;
            Meshes.Add(this);
        }


        // Other functions go here...


        public void Dispose()
        {
            Dispose(true);
            GC.SuppressFinalize(this);
            IsDisposed = true;


        }


        protected virtual void Dispose(bool disposing)
        {
            if (disposing)
            {
                Dispose();
            }
            // free native resources if there are any.
            VerticesBuffer.Dispose();
            IsDisposed = true;
        }


        public void Render()
        {


            d3dDevice.ImmediateContext.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleList;
            d3dDevice.ImmediateContext.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(VerticesBuffer, Utilities.SizeOf<Vector4>() * 2, 0));

            d3dDevice.ImmediateContext.Draw(VerticesCount,0);
            
            VerticesBuffer.Dispose();
        }
    }
}

Is that about IndexBuffer. If that is how can I correclty set it ? I use Draw instead should I use DrawIndexed but if I do that I see nothing is rendered.

Edited by gomidas

Share this post


Link to post
Share on other sites
Advertisement

I'm no SharpDX guru, but I do see one immediate issue with this provided code. You loop through presumably all the subsets of your mesh, creating a textureview for each subset. You than proceed to assign this textureview object to the same shader slot for each iteration.

And though it may be a managed language you're in, but than you proceed to throw your handle to that heap memory off the stack as soon as you exit that for loop. Does your object have multiple subsets? Each with it's own unique texture? You seem to be loading the same one for each iteration. And it seems the only mesh in question here is a cube.

Normally what you would want to do is load your texture once. Than when it comes time to draw, assign it to a shaderslot. (Though that's not set in stone, I just find that to be easy to track).

Another thing would be to include the UVs, and indices you're using. Those UVs could be buried in one of those Vector4's but i'm not seeing it.

Share this post


Link to post
Share on other sites

I'm no SharpDX guru, but I do see one immediate issue with this provided code. You loop through presumably all the subsets of your mesh, creating a textureview for each subset. You than proceed to assign this textureview object to the same shader slot for each iteration.

And though it may be a managed language you're in, but than you proceed to throw your handle to that heap memory off the stack as soon as you exit that for loop. Does your object have multiple subsets? Each with it's own unique texture? You seem to be loading the same one for each iteration. And it seems the only mesh in question here is a cube.

Normally what you would want to do is load your texture once. Than when it comes time to draw, assign it to a shaderslot. (Though that's not set in stone, I just find that to be easy to track).

Another thing would be to include the UVs, and indices you're using. Those UVs could be buried in one of those Vector4's but i'm not seeing it.

There I added only part of the code it is not full normally I will add it. Most probably problem is UV but I do not know how to add UV. After adding how can I get it work ? There is something called IndexBuffer is that about UV ?


I'm no SharpDX guru, but I do see one immediate issue with this provided code. You loop through presumably all the subsets of your mesh, creating a textureview for each subset. You than proceed to assign this textureview object to the same shader slot for each iteration.

And though it may be a managed language you're in, but than you proceed to throw your handle to that heap memory off the stack as soon as you exit that for loop. Does your object have multiple subsets? Each with it's own unique texture? You seem to be loading the same one for each iteration. And it seems the only mesh in question here is a cube.

Normally what you would want to do is load your texture once. Than when it comes time to draw, assign it to a shaderslot. (Though that's not set in stone, I just find that to be easy to track).

Another thing would be to include the UVs, and indices you're using. Those UVs could be buried in one of those Vector4's but i'm not seeing it.

How can I use UVs and get it work ?

Share this post


Link to post
Share on other sites

Naw, index buffers hold indices that tell the IA stage how to piece together your vertice positions. For large meshes with potentially thousands of redundant vertices, the memory savings add up.

So looking over your UVs, you only have four. Normally you're gonna want a UV for each vertice position (Think about it from the VertexShader point of view, and I think you'll understand why).

So by judging on the front face of your cube, your front face UVs should read like this:

new Vector2(0f,1f),
new Vector2(0f,0f),
new Vector2(1f,0f),
new Vector2(0f,1f),
new Vector2(1f,0f),
new Vector2(1f,1f),

If this doesn't work for whatever reason, you get the idea, play around with the values until it does.

Now, these WILL work for the other faces, BUT they will "rotated" (Not the correct terminology) at a different angle. So I'll leave this reference image for you to figure out the other faces UV positions

http://imgur.com/a/EzctC

Marcus Hansen

Share this post


Link to post
Share on other sites

Naw, index buffers hold indices that tell the IA stage how to piece together your vertice positions. For large meshes with potentially thousands of redundant vertices, the memory savings add up.

So looking over your UVs, you only have four. Normally you're gonna want a UV for each vertice position (Think about it from the VertexShader point of view, and I think you'll understand why).

So by judging on the front face of your cube, your front face UVs should read like this:

new Vector2(0f,1f),
new Vector2(0f,0f),
new Vector2(1f,0f),
new Vector2(0f,1f),
new Vector2(1f,0f),
new Vector2(1f,1f),

If this doesn't work for whatever reason, you get the idea, play around with the values until it does.

Now, these WILL work for the other faces, BUT they will "rotated" (Not the correct terminology) at a different angle. So I'll leave this reference image for you to figure out the other faces UV positions

http://imgur.com/a/EzctC

Marcus Hansen

Thank you I fixed it. I checked my TEXCOORD call and I saw something like :

 new InputElement("TEXCOORD", 0, Format.R32G32_Float, InputElement.AppendAligned, 0)

I changed InputElement.AppendAligned to 16 and it was fixed for my cube. I did not get what does it mean InputElement.AppendAligned. However, problem is fixed.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this  

  • Advertisement