• 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
LiziPizi

How shaders work in my program?

5 posts in this topic

Hey guys. 

I came across with difficult subject (for me) Shaders. I can understand why we need them but I dont know how to write them in my program. vertex shader and fragment shader.. do I need to write them in my program once and forget about them? I have looked at so many tutorials but its really hard for me to understand them.

Why people write their vertex shader and fragment shader in txt file? and why when I write #version 150 in my code it just mark it in red zigzag.

 

sorry for throwing on u guys those things but if someone could help me I will really appreciate it.

 

Thanks 

 

p.s.

If you need any information from me just ask me and I will answer in about 30 secs.

0

Share this post


Link to post
Share on other sites

do I need to write them in my program once and forget about them?

If your current shaders do what you expect them to do, you do not need to modify them. If you need new functionality, you need to modify them. Just like any other code.

I have looked at so many tutorials but its really hard for me to understand them.

Without specific questions it's a bit difficult to give any answers. What exactly is causing you troubles?

Why people write their vertex shader and fragment shader in txt file?

OpenGL shaders are handed as text to the driver. How you get that text is completely up to you. Having them as text files in the application's data directory can be convenient because you can modify them without having to recompile the executable.

and why when I write #version 150 in my code it just mark it in red zigzag.

You will have to clear that up with whatever text editor or IDE you are using. Possibly it's just the spellchecker.
0

Share this post


Link to post
Share on other sites

Hey LiziPizi,

 

Just regarding your post, From what i can see, you are unsure how to actually get the shader to run- And i think this is backed up by your red line mentioned above.

 

What i am assuming is that you are writing this is if it was normal code onto the screen - But the shader code itself is actually meant to be in a string, and this string is then compiled/whatever. People add them to txt files, as it keeps your source code from getting cluttered.

 

Im only looking at opengl3 now myself, so i cant really help anymore with this - but i found this site to be a great place to start : http://www.arcsynthesis.org/gltut/

 

TLDR; Wrap your shader code in quotes, and make it a string

Edited by McGrane
0

Share this post


Link to post
Share on other sites

Hi,

 

Shaders add enormous capability to improve the appearance of objects.  For example, water in a game typically depends heavily on shaders to look, well, like water. Procedural shaders can be used to create realistic rock appearance of things such as mountains with fewer polygons and little or no UV mapping of texture files, which is a gigantic boost in game performance usually. Shine on metal, artificial texture of fabrics, and many other things can be emulated by using shaders.  Most AAA popular 3D video games use shaders a lot and this is industry standard. Ever notice a realistic looking wood in a game?  That might have been created with procedural shading. Other shaders are for the look of soil, debris, leaves on trees and other plants, and much more.

 

Speaking of standards, eventually you will be using the folder and file formats and/ or procedural algorithms which is common in the industry and/or the game engine that you will use in the future. This things have been developed with literally millions of hours of work to sort the issues and implement them in games.

 

These wheels called shaders have been invented already, but you can make your own custom shaders.  There are SDKs which specialize in shader development. These can come as a plug-in for a 3D software such as 3ds Max or included in an SDK or IDE for creating the coding.  Game engines sometimes come with shader SDK for you.  Added to this, there are templates which can be taken and customized, which is a very time efficient way of creating shaders.

 

As a 3D graphics artist, I use a 3D modeling software to apply shaders to models in standard or game engine form.  With a 3D object, the shader work that is done will be saved in a file which is created by the 3D software when the model changes are "saved" or exported with the model. Usually the shader file is in the 3D model folder but can be external when the game engine needs it to be more accessible.  An example of this is when the 3D model folder is encrypted but the game designer needs to be able to make changes to the shader file later, in such case it might be an external file.

 

It is possible to reinvent the wheel and make all shading in your game from pure game source code, but this is much more work in the long term.  For a hobby, this is no problem because it is for fun!  If you want to work with shaders long term as something you need to do as a professional then you need to learn the industry or game engine standard methods of creating shaders.

0

Share this post


Link to post
Share on other sites

first thing you should get clear yourself with on your path to understand shaders is to (first) know what they ask from application to render right. And this is far from trivial, it is actualy thing that will get you knowing them very advanced.

 

So, the data for the pepilne of vertex/pixel shader is:

 

1-) uniform variables - it is data that stays constant during entire shader, wheather pixel or vertex (matrix that transforms constant verticies in stream during the draw and so on)

 

2-) attribute stream - this is volatile input to vertex shader , the actual verticies with attributes (position, texture coordinate..), it is a different data for every vertex function execution (unlike uniforms) , you should learn how to provide them. Do not confuse with the fact the stream is constant in GPU memory , provided once by CPU (preferably)

 

3-) varying variable - this is not computed by CPU (you) but by the vertex shader and it travels to pixel shader. Pixel shader computes the pixels on the triangle by the help of interpolating those vertex shader outputs. (do not think that result of vertex shader stays constant for pixel triangle, it varies acros its surface upon barycentric interpolation of fragment position in triangle).

 

4-) result of pixel shader is written to target, the 4 component vector (color usualy).

 

 

To summarize, vertex shader needs uniforms and stream, and pixel shader needs uniforms and varying input from vertex shader.

 

Since, this is quite restrictive model of pipeline, it is very native to GPUs. But this does not describe exactly geometry/vertex/pixel shader approach of newer dx and opengl libraries they brought offering.

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