• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
JustJim

Effects.fx in Monogame

2 posts in this topic

Hey!

As I am programming my little space shooter and gone through many changes containing the planets (changing them from Models to Vertexbased Icospheres) I came across a problem I could not solve yet.

 

I want to have lighting on my Planets but as basicEffect.lightingenabled = true won't work (I guess it's due to the fact it's no model),

I need to make an own shader to make pixel-based-lighting.

 

As I am programming with Monogame which is like XNA I tried to read through tutorials which gives solutions to that.

I came across Riemers tutorials who uses a effects.fx-file.

According to the tutorial, I added the file to the Game1ContentContent (yes in Monogame there will be 2 Content Projects of which the latter one is the one to use for the files) and loaded it via Effect effect = Content.Load<Effect>("effects")

 

But this gives me huge problems.

First I encountered the problem that VS2013 told me that this is not a valid mgfx file.

I stumbled through the net and found that I need to change the version to ps_4_0 and vs_4_0 as well as POSITION and POSITION0 to SV_POSITION.

 

After that I got an error, telling me that I only could use version 3.X or earlier.

Changing them to ps/vs_3_0 it looked like it was working: Window popped up and seemed to load but after a couple of seconds it

crashes, telling me "Could not load effects asset as a non-content file!", which suprises me, as it is in the content folder.

 

What can I do about this?

0

Share this post


Link to post
Share on other sites


I want to have lighting on my Planets but as basicEffect.lightingenabled = true won't work (I guess it's due to the fact it's no model),

 

As long as you're using the effect to draw, it doesn't matter if it's a "Model" class or not. Just make sure your icosphere vertices have the necessary information - specifically, they need a normal component in order to have 3d lighting work.

1

Share this post


Link to post
Share on other sites

Well okay, I guess, I am not that into it.

 

I'll post my code, so you can see if it has the necessary information.

protected override void Initialize()
        {
            // TODO: Add your initialization logic here

            basicEffect = new BasicEffect(GraphicsDevice);
            List<VertexPositionColor> vertices = new List<VertexPositionColor>();

            float t = (float)(1.0 + Math.Sqrt(5.0f)) / 2.0f;
            
            vertices = AddNormalizedVertex(vertices, new Vector3(-1, 0, t), Color.Gray);
            vertices = AddNormalizedVertex(vertices, new Vector3(1, 0, t), Color.Gray);
            vertices = AddNormalizedVertex(vertices, new Vector3(-1, 0, -t), Color.Gray);
            vertices = AddNormalizedVertex(vertices, new Vector3(1, 0, -t), Color.Gray);


            vertices = AddNormalizedVertex(vertices, new Vector3(0, t, 1), Color.Gray);
            vertices = AddNormalizedVertex(vertices, new Vector3(0, t, -1), Color.Gray);
            vertices = AddNormalizedVertex(vertices, new Vector3(0, -t, 1), Color.Gray);
            vertices = AddNormalizedVertex(vertices, new Vector3(0, -t, -1), Color.Gray);


            vertices = AddNormalizedVertex(vertices, new Vector3(t, 1, 0), Color.Gray);
            vertices = AddNormalizedVertex(vertices, new Vector3(-t, 1, 0), Color.Gray);
            vertices = AddNormalizedVertex(vertices, new Vector3(t, -1, 0), Color.Gray);
            vertices = AddNormalizedVertex(vertices, new Vector3(-t, -1, 0), Color.Gray);

            List<int> indices = new List<int>();

            indices.Add(0); indices.Add(6); indices.Add(1);
            indices.Add(0); indices.Add(11); indices.Add(6);
            indices.Add(1); indices.Add(4); indices.Add(0);
            indices.Add(1); indices.Add(8); indices.Add(4);
            indices.Add(1); indices.Add(10); indices.Add(8);

            indices.Add(2); indices.Add(5); indices.Add(3);
            indices.Add(2); indices.Add(9); indices.Add(5);
            indices.Add(2); indices.Add(11); indices.Add(9);
            indices.Add(3); indices.Add(7); indices.Add(2);
            indices.Add(3); indices.Add(10); indices.Add(7);

            indices.Add(4); indices.Add(8); indices.Add(5);
            indices.Add(4); indices.Add(9); indices.Add(0);
            indices.Add(5); indices.Add(8); indices.Add(3);
            indices.Add(5); indices.Add(9); indices.Add(4);
            indices.Add(6); indices.Add(10); indices.Add(1);

            indices.Add(6); indices.Add(11); indices.Add(7);
            indices.Add(7); indices.Add(10); indices.Add(6);
            indices.Add(7); indices.Add(11); indices.Add(2);
            indices.Add(8); indices.Add(10); indices.Add(3);
            indices.Add(9); indices.Add(11); indices.Add(0);

            List<int> indices2 = new List<int>();
            for (int j = 0; j <4 ; j++)
            {
                
                for (int i = 0; i < indices.Count; i++)
                {
                    Vector3 p1 = vertices[indices[i]].Position;
                    int p1I = (int)i++;
                    Vector3 p2 = vertices[indices[i]].Position;
                    int p2I = (int)i++;
                    Vector3 p3 = vertices[indices[i]].Position;
                    int p3I = (int)i;

                    int a = (int)vertices.Count;
                    vertices = AddNormalizedVertex(vertices, new Vector3(((p1.X + p2.X) / 2), (p1.Y + p2.Y) / 2, (p1.Z + p2.Z) / 2), Color.Green);

                    int b = (int)vertices.Count;
                    vertices = AddNormalizedVertex(vertices, new Vector3((p2.X + p3.X) / 2, (p2.Y + p3.Y) / 2, (p2.Z + p3.Z) / 2), Color.Yellow);

                    int c = (int)vertices.Count;
                    vertices = AddNormalizedVertex(vertices, new Vector3((p3.X + p1.X) / 2, (p3.Y + p1.Y) / 2, (p3.Z + p1.Z) / 2), Color.Red);

                    indices2.Add(indices[p1I]); indices2.Add(c); indices2.Add(a);
                    indices2.Add(indices[p2I]); indices2.Add(a); indices2.Add(b);
                    indices2.Add(indices[p3I]); indices2.Add(b); indices2.Add(c);
                    indices2.Add(b); indices2.Add(a); indices2.Add(c);

                }
                indices.Clear();
                foreach (int index in indices2)
                {
                    indices.Add(index);
                }
            }
            vertexList = new VertexPositionColor[vertices.Count];
            for (int i = 0; i < vertices.Count; i++)
            {
                vertexList[i] = vertices[i];
            }

            indexList = new int[indices.Count];
            for (int i = 0; i < indices.Count; i++)
            {
                indexList[i] = indices[i];
            }

            vertexBuffer = new VertexBuffer(GraphicsDevice, typeof(VertexPositionColor), vertexList.Length, BufferUsage.WriteOnly);
            vertexBuffer.SetData<VertexPositionColor>(vertexList);
            indexBuffer = new IndexBuffer(graphics.GraphicsDevice, typeof(int), indexList.Length, BufferUsage.WriteOnly);
            indexBuffer.SetData(indexList);


            base.Initialize();
        }

Thats the Code for the Icosphere (building a Icosahedron and sudivide the vertices).

protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.DarkSlateBlue);

            DrawPrimitive(vertexList);

            base.Draw(gameTime);
        }
        protected void DrawPrimitive(VertexPositionColor[] vertices)
        {
            basicEffect.VertexColorEnabled = true;
            basicEffect.World = world;
            basicEffect.View = view;
            basicEffect.Projection = projection;
           
            GraphicsDevice.SetVertexBuffer(vertexBuffer);
            GraphicsDevice.Indices = indexBuffer;

            RasterizerState rasterizerState = new RasterizerState();
            rasterizerState.CullMode = CullMode.None;
            GraphicsDevice.RasterizerState = rasterizerState;
           
            foreach (EffectPass pass in basicEffect.CurrentTechnique.Passes)
            {
                pass.Apply();
                
                GraphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, vertexList.Length, 0, indexList.Length / 3);
            }
        }

And thats the draw Methodes. if I type in basicEffect.EnableLighting = true; It will crash.

Another thing just came to my mind, if I Enable Culling, there are some weird effects in the icosphere as some triangles won't be drawn correctly.

But either way, even with only 0 iteration (pure Icosahedron without subdividing) there is this crash :/

The error it gives me is this:

"SharpDX.SharpDXException" in SharpDX.dll

HRESULT: [0x80070057], Modules: [General], ApiCode: [E_INVALIDARG/Invalid Arguments], Message: Invalide Parameter.

Edited by JustJim
0

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  
Followers 0