Vertex/Fragment Tutorial for noobs

What it says on the tin: a place to discuss proposed new features.
Post Reply
User avatar
KungFooMasta
OGRE Contributor
OGRE Contributor
Posts: 2087
Joined: Thu Mar 03, 2005 7:11 am
Location: WA, USA
x 16
Contact:

Vertex/Fragment Tutorial for noobs

Post by KungFooMasta »

I've read bits and pieces of vertex/shader programming, but I don't see how it fits into the pipeline. For example programs will have input parameters and output parameters, but how does Ogre supply these parameters? It would be really helpful (to me at least) if there was a noob tutorial showing how vertex/fragment programs are applied to entities in Ogre via code.

For example, taking from RBGUI, we have some definitions:

Code: Select all

uniform sampler2D image;

void main( )
{
	gl_FragColor = texture2D( image, gl_TexCoord[0].st ) * gl_Color;
}

Code: Select all

// Pixel shader used for rendering Gui elements, GLSL
fragment_program GuiPixelShaderGLSL glsl
{
	source GuiPixel.glsl

	default_params
	{
		param_named image int 0
	}
}

Code: Select all

// Material for Gui rendering
material GuiMaterial
{
	technique
	{
		pass
		{
			cull_hardware none
			cull_software none

			depth_check off
			depth_write off

			lighting off

			vertex_program_ref GuiVertexShader
			{
				// ...
			}

			fragment_program_ref GuiPixelShader
			{
				// ...
			}

			texture_unit Image
			{
				tex_address_mode clamp
				filtering linear linear none
			}
		}
	}
}
Questions that could be adressed by a tutorial:

1. What are default_params, I thought programs requiring input parameters need to have parameters passed in? Maybe they aren't related?

2. param_named image int 0, the main function above uses a variable image, but it looks like the variable is defaulted to 0? Totally confused here, what data type is image and what is the following line trying to accomplish?

Code: Select all

gl_FragColor = texture2D( image, gl_TexCoord[0].st ) * gl_Color;
3. What kinds of operations can happen inside the following script?

Code: Select all

			vertex_program_ref GuiVertexShader
			{
				// ...
			}
Are we ablet o pass in parameters here? How can we do this in C++?

I know this might seem basic shader knowledge, and part of it is, but I also lack understanding of how shaders are used in the Ogre pipeline, I don't understand how Ogre uses them and how we can configure them. (Referring me to CG tutorials won't help me much, I need to be able to use these in Ogre)
Creator of QuickGUI!
User avatar
xavier
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 9481
Joined: Fri Feb 18, 2005 2:03 am
Location: Dublin, CA, US
x 22

Re: Vertex/Fragment Tutorial for noobs

Post by xavier »

No offense, but I have noticed a marked tendency in your development to do things like this -- to try to use code snippets without having the slightest clue what they are doing or why.

To be perfectly honest, you are going to have to learn how the graphics pipeline works. It's not difficult. Once you do so, every single question you raised above will answer itself.

Start here:

http://msdn.microsoft.com/en-us/library ... S.85).aspx

If you have questions about things introduced in that tutorial, feel free to ask them; I'll be happy to help out. But trying to explain what's going on to someone who lacks the background knowledge to understand the explanation, honestly is a waste of my time and yours.
Do you need help? What have you tried?

Image

Angels can fly because they take themselves lightly.
User avatar
KungFooMasta
OGRE Contributor
OGRE Contributor
Posts: 2087
Joined: Thu Mar 03, 2005 7:11 am
Location: WA, USA
x 16
Contact:

Re: Vertex/Fragment Tutorial for noobs

Post by KungFooMasta »

Hard not to take offense, I think you're exaggerating a little. I posted the code because its simple, and can be used to see where I lack understanding, in its use in Ogre. Whats the point of posting code I understand, that doesn't make sense to me. We have beginner tutorials that show step by step how to put a ninja into a scene, is asking for a tutorial to apply a vertex/fragment program to a ninja too much to ask for?

Will read the link, thanks
Creator of QuickGUI!
User avatar
spacegaier
OGRE Team Member
OGRE Team Member
Posts: 4308
Joined: Mon Feb 04, 2008 2:02 pm
Location: Germany
x 137
Contact:

Re: Vertex/Fragment Tutorial for noobs

Post by spacegaier »

Link works (take care that you hand-edit the .aspx at the end)!

EDIT: Did you have a look at the Oge manual. There are some parts that show how to use different types of shaders in Oge (CG, HLSL, GLSL).
Ogre Admin [Admin, Dev, PR, Finance, Wiki, etc.] | BasicOgreFramework | AdvancedOgreFramework
Don't know what to do in your spare time? Help the Ogre wiki grow! Or squash a bug...
User avatar
xavier
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 9481
Joined: Fri Feb 18, 2005 2:03 am
Location: Dublin, CA, US
x 22

Re: Vertex/Fragment Tutorial for noobs

Post by xavier »

The point is that you seem to want to come into the middle portion of the topic, and ignore all of that boring stuff about learning the "why" and skip right to the "how" -- to do the "intermediate" parts without first doing the "beginner" parts.

The problem is, without understanding the "why", the "how" will continue to be a mystery. However, once you know the "why", the "how" is almost self-evident.

The Cg Tutorial, contrary to its name, isn't teaching you Cg -- it's teaching you the "why" of the programmable graphics pipeline, in the context of the Cg language. The link I provided does the same thing, in the context of the HLSL language. Either of these will explain to you the implications of the programmable pipeline, and between that and the manual pages regarding GPU programs, your questions will answer themselves -- no "n00b" tutorial needed.
Do you need help? What have you tried?

Image

Angels can fly because they take themselves lightly.
User avatar
xavier
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 9481
Joined: Fri Feb 18, 2005 2:03 am
Location: Dublin, CA, US
x 22

Re: Vertex/Fragment Tutorial for noobs

Post by xavier »

spacegaier wrote:Link works (take care that you hand-edit the .aspx at the end)!
Yeah, MS doesn't seem to want to make it easy to link to their online MSDN pages... ;)
Do you need help? What have you tried?

Image

Angels can fly because they take themselves lightly.
User avatar
KungFooMasta
OGRE Contributor
OGRE Contributor
Posts: 2087
Joined: Thu Mar 03, 2005 7:11 am
Location: WA, USA
x 16
Contact:

Re: Vertex/Fragment Tutorial for noobs

Post by KungFooMasta »

The manual is helpful. I guess I was requesting a "teach by example" method of learning, but the manual gives me enough information to use shaders in Ogre. And for those who don't know, when I make posts in the feature requests board, its not just for self help, they are things I think Ogre would benefit from. No offense xavier, but despite you being right on a lot of things, and having a lot of knowledge and experience in general, you don't really have the patience or understanding to effectively help people in a good way.
Creator of QuickGUI!
User avatar
xavier
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 9481
Joined: Fri Feb 18, 2005 2:03 am
Location: Dublin, CA, US
x 22

Re: Vertex/Fragment Tutorial for noobs

Post by xavier »

To be honest, I hadn't even noticed what forum it was posted in -- I come to the forums via "view unread posts" filter and not from the main page. So in that respect, I was answering the wrong question it appears.

Your "teach-by-example" method is contained in the sample media -- but again it requires an understanding of "why" things are done the way they are. And on that I still stand -- the tutorial you request would not be understood by those who think they need it, and those who don't need it won't use it. As you point out, the manual suffices in this regard.
Do you need help? What have you tried?

Image

Angels can fly because they take themselves lightly.
User avatar
jacmoe
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 20570
Joined: Thu Jan 22, 2004 10:13 am
Location: Denmark
x 179
Contact:

Re: Vertex/Fragment Tutorial for noobs

Post by jacmoe »

KungFooMasta wrote:No offense xavier, but despite you being right on a lot of things, and having a lot of knowledge and experience in general, you don't really have the patience or understanding to effectively help people in a good way.
Xavier has his unique style, I have mine, and so on.
Which is fine. :)
I respect Xavier for being mercilessly frank, almost brutal.
His got his heart in the right place. And that makes all the difference. :wink:

A tutorial on how to hook up shaders and materials in Ogre is not a bad idea. Though. :)
/* Less noise. More signal. */
Ogitor Scenebuilder - powered by Ogre, presented by Qt, fueled by Passion.
OgreAddons - the Ogre code suppository.
Post Reply