PDA

View Full Version : Shader Creation thread


mpc823_99
08-28-2003, 03:54 AM
Just wanted to start the shader creation thread mentioned by Lyle on the Yahoo boards.

Previously ....
****************************
FX_SHADERINITINPUTS & FX_SHADEREVALUATE are macros you'd use to define your
shader callbacks. When you call:

fxShaderCallback(shader,FX_SHADERFUNC_INITINPUTS,shader_init);

you're registering the shader_init callback that will be used to initialize
data for your plugin. Then you have to define the function. You'd do it
like so:

FX_SHADERINITINPUTS(shader_init)
{
//initialize your shader inputs...
return;
}

I'll try to give more info over on CGTalk later tonight. It will be a
perfect opportunity to provide the FogBasic shader along with other info.

-lyle

*****************************
Yep, knew all that! :thumbsup: Rather than ask more questions now, I'll wait for the FogBasic shader to be posted. That should clear up most of my questions.

Thanks Lyle!

Daniel

lmilton
08-28-2003, 07:22 AM
I'm putting the FogBasic shader together right now. I'll post it on the yahoo group when I'm done, and we can discuss it here.

Stay tuned...

markpassion
08-28-2003, 09:59 AM
I got the shader. Just don't know how to use it. :rolleyes: :)

Thanks for the source :thumbsup:

lmilton
08-28-2003, 10:04 AM
I just uploaded the FogBasic shader and sample code to the messiah yahoo group: http://groups.yahoo.com/group/pmGmessiah/files/pmG_Files/

The FogBasic shader is just that: a basic fog shader. Here is a simple example of its output:

http://groups.yahoo.com/group/pmGmessiah/files/pmG_Files/fogbasic.JPG

This should be a good starting point in understanding how to write shaders. I'll try to make myself available to participate in this thread... should it blossom, so feel free to ask questions.

-lyle

lmilton
08-28-2003, 10:17 AM
I got the shader. Just don't know how to use it.

Red, Green, Blue = color of fog
Fog Min Depth = minimum fog depth (how close to camera)
Fog Max Depth = maximum fog depth (how far from camera)
Fog Density = the "thinkness" of fog
Fog Function = fog falloff type... try it out;)
Ground Fog = fog "eminates" from ground

You'd connect this shader (fog_radiance) to the Atmosphere "material" (color) if you want global fog. You can, however, apply it to any material to affect specific surfaces/objects.

Let me know if this makes sense.

markpassion
08-28-2003, 10:31 AM
cool. I can't get it to effect the backround or Environment when its used with Atmosphere.

Why are some of the outputs connectable and some not? What I mean is, to get it to work, you just hook up the Radiance to the colour channel, so why are the Opacity and Depth available also yet not the colour.

Is this just a decision you have made or is there particular qualities about this data that means it automatically gets included.

Mark
PS. I can't see the image you posted. :hmm:

lmilton
08-28-2003, 10:40 AM
Originally posted by markpassion
cool. I can't get it to effect the backround or Environment when its used with Atmosphere.

Why are some of the outputs connectable and some not? What I mean is, to get it to work, you just hook up the Radiance to the colour channel, so why are the Opacity and Depth available also yet not the colour.

Is this just a decision you have made or is there particular qualities about this data that means it automatically gets included.

Mark
PS. I can't see the image you posted. :hmm:

Not quite sure I understand the problem. You can connect any outputs you like to anything input you like. This goes for any shader.

I'm seeing the image fine right here on CGTalk. Did you try getting it from yahoo?

-lyle

markpassion
08-28-2003, 10:47 AM
The first is a problem ie the background and environment not being affected.

My second point wasn't a problem, I'm just curious what governs what data is presented where on the node, but looks like the coder has full control over that which is cool. So ignore me.;)

Mark

ThomasHelzle
08-28-2003, 12:01 PM
Hi,
I've put the .mp file in the shaders directory of the messiah installation but it didn't show up in the shader list - how do I install it?

Thanks,

Thomas Helzle

markpassion
08-28-2003, 12:14 PM
I have sent a reply to the yahoo groups as well, but basically the file is a .mp which is Messiah Plugin, which means it should live in the plugins folder.

Mark:thumbsup:

lmilton
08-28-2003, 03:48 PM
Originally posted by markpassion
The first is a problem ie the background and environment not being affected.

My second point wasn't a problem, I'm just curious what governs what data is presented where on the node, but looks like the coder has full control over that which is cool. So ignore me.;)

Mark

The first problem isn't a problem, either;) Fog should never affect the background or environment.

-lyle

lmilton
08-28-2003, 04:18 PM
Originally posted by markpassion
The first is a problem ie the background and environment not being affected.

My second point wasn't a problem, I'm just curious what governs what data is presented where on the node, but looks like the coder has full control over that which is cool. So ignore me.;)

Mark

For those of you that are still wondering about Mark's second "problem", yes it's true that the developer has full control over inputs/outputs that appear on the shader node.

When you receive the (requested) O_CREATE entry, it's up to you to create the inputs & outputs. Here's a snippet of the code from FogBasic:

//#4. Create Inputs------------------------------------------------------------
IN_FOG_COLOR = fxShaderCreateInput(shader, "Color", FX_IOTYPE_COLOR, 0);
IN_FOG_MIN_DEPTH = fxShaderCreateInput(shader, "Min_Depth", FX_IOTYPE_FLOAT, 0);
IN_FOG_MAX_DEPTH = fxShaderCreateInput(shader, "Max_Depth", FX_IOTYPE_FLOAT, 0);
IN_FOG_DENSITY = fxShaderCreateInput(shader, "Density", FX_IOTYPE_FLOAT, 0);
//```````````````````````````````````````````

//#5. Create Outputs-----------------------------------------------------------
OUT_FOG_RADIANCE = fxShaderCreateOutput(shader, "Fog_Radiance", FX_IOTYPE_COLOR, 0);
OUT_FOG_DEPTH = fxShaderCreateOutput(shader, "Fog_Depth", FX_IOTYPE_FLOAT, 0);
//```````````````````````````````````````````

So, you'd use fxShaderCreateInput to create inputs & fxShaderCreateOutput to create outputs;)

You should consult messiah_shader.h for the relevant i/o types.

-lyle

ThomasHelzle
08-28-2003, 04:54 PM
The first problem isn't a problem, either Fog should never affect the background or environment.

May I ask why you think so? Often exactly that is needed, at least as an option - or am I misunderstanding something? (wouldn't be the first time :-)

Regards,

Thomas Helzle

lmilton
08-28-2003, 05:04 PM
Originally posted by Thomas_Helzle
May I ask why you think so? Often exactly that is needed, at least as an option - or am I misunderstanding something (wouldn't be the first time :-)

Regards,

Thomas Helzle

While it would be cool to mimic the behavior of LW, there are going to be some trade offs for the added power.

Keeping this all in context, remember that the fog shader is a surface shader; it can only shade what it "hits". Since there can be no background or environment hit, they can't be shaded by fog.

The Atmosphere, Enviroment, & Background camera surface [read: layers] are separate to allow you to maximum control. They function as surfaces in that you can apply any number of shaders to them, but are really special render layers.

However, you should be able to apply the Atmosphere "material" to the Background & Environment camera surfaces. I haven't tried this myself, but it shoud work.

-lyle

ThomasHelzle
08-28-2003, 05:24 PM
However, you should be able to apply the Atmosphere "material" to the Background & Environment camera surfaces. I haven't tried this myself, but it shoud work.

I just tried it and it doesn't work for me. The background renders black instead of fog-white...

If it would work the way you said, I would be a happy camper ;-)

Thank you also for the "Depth" output of the Shader - connected to Atmosphere-Color it is perfect for creating a depth-buffer to use for DOF in AfterEffects!

As soon as I have time I will dive into shader coding...

Thanks a lot!

markpassion
08-29-2003, 12:05 PM
So, is there such a thing as a volume shader yet? If so how does that work? If not, how do you think it will work?;-)

Mark:)

lmilton
08-29-2003, 05:22 PM
Originally posted by markpassion
So, is there such a thing as a volume shader yet? If so how does that work? If not, how do you think it will work?;-)

Mark:)

The best way to do a volume shader, at present, it to create a shader to be attatched to the Atmosphere surface. For example, it's possible to do volumetric fog, not just the simple fog that I've posted. The one thing you'll need to be aware of in this version is that you may need to create a "background hemisphere" (instead of using the background surface) to generate a hit for the background.

We're currently working on functions that will allow you to cast rays and to compute lighting for a spot.

What did you have in mind?

-lyle

lmilton
08-29-2003, 06:00 PM
Originally posted by Thomas_Helzle
I just tried it and it doesn't work for me. The background renders black instead of fog-white...

If it would work the way you said, I would be a happy camper ;-)

Thank you also for the "Depth" output of the Shader - connected to Atmosphere-Color it is perfect for creating a depth-buffer to use for DOF in AfterEffects!

As soon as I have time I will dive into shader coding...

Thanks a lot!

Hmmm... it is supposed to work... I think I know what's causing the problem. Not so simple. I'll see if we can get it to work this way. I think it's a good deal more flexible & "readable" than just putting another button on the interface.

I'll let you know how it goes.

In the meantime, you could set the background color to be that of the fog. Or you could create an background hemispere object.

-lyle

ps: glad the depth output worked for you:) I did it also to demonstrate that it's a good idea to create output for "computational values". Others may find them quite useful. This is why the standard shaders all have multiple outputs. So, keep "the other guy" in mind when writing your own shaders;)

ThomasHelzle
08-29-2003, 07:09 PM
Yes, that "depth" output is very cool... A lot of stuff can be done with it. I hope I find some time soon to dive more into rendering. Thank you!

lmilton
08-31-2003, 03:38 AM
Originally posted by Thomas_Helzle
Yes, that "depth" output is very cool... A lot of stuff can be done with it. I hope I find some time soon to dive more into rendering. Thank you!

We figured out a way to get the background to be affected by the Atmosphere layer [read:fog]. Essentially, it now produces a "hit". Unfortunately, this means that we'll now have the opposite problem: the background and environment will *always* be affected.

However, there is a way to get around the problem and it would involve editing the FogBasic shader so it will, say, clip at a maximum depth. Personally, I don't really care for that solution because it doesn't really address the problem if you use other shaders on the Atmosphere layer.

A better solution would be to create an "exclusion shader". This would essentially be an "operator" that would allow you to exclude any object and/or surface from being shaded. The only peice of info that you'd need to create it is the object/surface/poly for the hit. This info isn't currently accessible via the API, but we'll add it.

-lyle

CGTalk Moderation
01-15-2006, 11:00 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.