Jump to content

  • Log In with Google      Sign In   
  • Create Account


How shaders work in my program?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
5 replies to this topic

#1 LiziPizi   Members   -  Reputation: 74

Like
0Likes
Like

Posted 19 May 2014 - 08:45 AM

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.



Sponsor:

#2 BitMaster   Crossbones+   -  Reputation: 3914

Like
0Likes
Like

Posted 19 May 2014 - 09:03 AM

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.

#3 McGrane   Members   -  Reputation: 1032

Like
0Likes
Like

Posted 19 May 2014 - 10:43 AM

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, 19 May 2014 - 10:44 AM.


#4 Kaptein   Prime Members   -  Reputation: 2075

Like
1Likes
Like

Posted 19 May 2014 - 01:12 PM

Yes, it looks like you have added it to your project somehow, as if it was C/C++ code.

Shader code is either loaded from a file, or a multiline string http://stackoverflow.com/questions/20508534/c-multiline-string-raw-literal



#5 3Ddreamer   Crossbones+   -  Reputation: 3134

Like
0Likes
Like

Posted 20 May 2014 - 08:48 PM

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.


Personal life and your private thoughts always effect your career. Research is the intellectual backbone of game development and the first order. Version Control is crucial for full management of applications and software.  The better the workflow pipeline, then the greater the potential output for a quality game.  Completing projects is the last but finest order.

 

by Clinton, 3Ddreamer


#6 JohnnyCode   Members   -  Reputation: 226

Like
0Likes
Like

Posted 21 May 2014 - 05:50 PM

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.






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS