Shader System Questions

Started by
113 comments, last by cyansoft 20 years ago
quote:Original post by c t o a n
...


thanks now I'm starting to understand more about this effect thing.


quote:Original post by sBibi
I was just wondering... has anyone implemented meta bouncing as Yann described it? or something similar? that is, automatic effect bouncing without any explicit links.


I have some kind of meta-bouncing... not the same as Yann described though

the shaders in my engine is broken down so that different "Effects" needs several shaders to be visible I have one shader that apply the Ambient and diffuse color of the material and another that sets the Specular and shininess if I need all four then all four are choosen, and then a third shader that applies a texture (or several) I choose them through a bit-field as an MaterialEffect description and the bit-field is set depending on what the Material has e.g. Texture etc.



EDIT:

I have been thinking.. if I create an Effect file that looks like this

--- Effects.fx ---

Effect 0
{
.description "Diffuse color"
.vertexstreams (position, normal)
.datastreams COLOR(ambient, diffuse)
}
Effect 1
{
.description "Diffuse texture"
.vertexstreams (position, normal, texcoord)
.datastreams TEXTURE(diffuse)
}
Effect 2
{
.description "Diffuse textured with lightmap"
.vertexstreams (position, normal, texcoord)
.datastreams TEXTURE(diffuse,lightmap)
}

And some material scripts that looks something like this to describe the material of the current mesh:

--- some Material scripts ---

Material "Diffuse blue"
{
.Effect "Diffuse color"

.color.ambient = 0.2 0.2 0.4
.color.diffuse = 0.4 0.4 0.8
}

Material "simple marble textured"
{
.Effect "Diffuse texture"

.texture.diffuse = "textures\marble.tga"
.texture.texcoordset = 0
}

then the egine knows when it encounter the .Effect line that the material is built from that effect..



[edited by - McZ on April 16, 2004 8:08:13 AM]
Advertisement
how abstract should the Effects be?

and how,when or where should I turn on the lights?
quote:Original post by McZ
how abstract should the Effects be?


What exactly do you mean by this - do you mean the balancing of effects vs adding parameters to existing effects - or the info stored in the effects?

quote:
and how,when or where should I turn on the lights?


The lights are objects within your scenegraph. You simply hold a list of the lights for the current frame - if a light isn''t on, simply don''t add it to the light pool for that frame.

Darkwing: then how do you bind the correct pBuffer in the place it''s needed? At that point you have no info about the pBuffer (at least that''s what I would imagine).
The general effect doesn''t know about pBuffer, but specific shader does. For example: I made a effect that draws blured screen texture over full screen (something like glare/bloom). I have one shader that renders this effect, but this shader requests 2 other effects: "render to texture" and "bluring of texture". So this shader sets parametrs of this child (bounced) effects. RTT shader gets render target assigned. The same ID is used for this shader source ID. So individual shaders will not know that they belong to some more complex shader/effect. I''m not sure this anwsers your question.

You should never let your fears become the boundaries of your dreams.
You should never let your fears become the boundaries of your dreams.
I think it does, thank you.

I was thinking more along the lines of a basic material tree into which you could slot textures, or other shaders. A reflection would then be made by putting a texture into the diffuse slot, and a reflection shader into the specular slot. But now I''m thinking that sort of thing would be too generic.

Another question for everybody here: how do shaders communicate with eachother? In the above post by Darkwing, how does the main shader request the pBuffer ID from the RTT shader?
quote:Original post by jamessharpe
What exactly do you mean by this - do you mean the balancing of effects vs adding parameters to existing effects - or the info stored in the effects?


I mean how much of the visual apperance is controlled by the Effect and not the Material-script

e.g.
A) here I define that the Effect controls two textures diffuse and lightmap no more no less.

--- Effects.txt ---
Effect "Diffuse and lightmap texture"
{
.description "Diffuse texture"
.vertexstreams(position,texcoord)
.datastreams TEXTURE(diffuse,lightmap)
}
--- lightmaptest.mat ---
Material "lightmaped texture"
{
.effect "Diffuse and lightmap texture"

.texture[0].name = "diffuse"
.texture[0].file = "data\textures\a.tga"
.texture[0].some_texture_operations = some_value

.texture[1].name = "lightmap"
.texture[1].file = "data\textures\a_lm.tga"
.texture[1].some_texture_operations = some_value
}

B) here in this effect I just declear that the material has textures but the number is unknown

--- Effects.txt ---
Effect "Textured"
{
.description "textured"
.vertexstreams(position,texcoords)
.datastreams(textures)
}

--- lightmaptest.mat ---
Material "lightmaped texture"
{
.effect "textured"

.texture[0].file = "data\textures\a.tga"
.texture[0].some_texture_operations = some_value

.texture[1].file = "data\textures\a_lm.tga"
.texture[1].some_texture_operations = some_value
}

quote:Original post by jamessharpe
The lights are objects within your scenegraph. You simply hold a list of the lights for the current frame - if a light isn't on, simply don't add it to the light pool for that frame.


but which shader should turn on the nearest lights to the current mesh?

my current shadersystem resolves several shaders for one material becouse the shaders either set the color of the material or the texture or somethingelse... but if all shaders are able to turn on lights then the lights would be turned on several times for each object, should have some kind of flag on the lights so the shader knows if it is on already?! or should I create a Helper shader that turns on lights if no resolved shaders has the ability to turn on the lights it self

[edited by - McZ on April 20, 2004 6:06:53 AM]
quote:Original post by rick_appleton
Another question for everybody here: how do shaders communicate with eachother? In the above post by Darkwing, how does the main shader request the pBuffer ID from the RTT shader?


This is one big weaknes of my engine. Its created more like a hack, then anything else. So I would also like to hear how everyone else is doing this. My shader has a function that sets all it's parameters. The input is a list of named settings and shader just takes the ones it needs. In my example, main shader takes value of "texture(screen)" as source texture(or generates a unique name if it's not specified) and then sets another setting "texture(render)" with same value and sends it to RTT shader. And since all textures come form texture manager they both get same texture ID since they reference same texture name.

example material (fs_glare.txt)
# effect IDID = 200# source texturetexture(screen) = mainScreenTexture# source texture sizetextureSize = 256# glare cutoff rengecutoffRange = 0.30  


part of effect configuration (effects.xml)
...	Render to 2D texture	<!-- material parameters:		texture(render)	: render target 2D texture		textureSize	: size of texture (default=128)		[mirrorPlane]	: camera mirror plane (XYZD)		-->				...	Fullscreen bloom filter	<!-- result += (blured_screen_texture-cutoffRange)*2 -->	<!-- material parameters:		texture(screen) : screen texture name		textureSize 	: screen texture size			cutoffRange	: bloom cutoff range		-->			  


[edited by - _DarkWIng_ on April 20, 2004 8:40:39 AM]

[edited by - _DarkWIng_ on April 20, 2004 8:43:30 AM]
You should never let your fears become the boundaries of your dreams.
The communication between shaders is a difficult issue, however it seems most people have missed a comment made by Yann at the end of the other thread:

quote:
(2) is basically included in the facility that forwards data between shaders in different passes. A good and highly flexible way to do this, are GC-tags. I don''t remember if I explained those, if not let me know.


What I have started to implement is this tag system. Basically what I am doing is attaching a structure to each geometry chunk which contains the data that is output from the shaders. I''m not quite sure how to represent this data, but at the moment I''m thinking of either a stack based system or possibly a property map of sorts.

James
Hi.

Could you explain what is the way these tags should be used and what data should they contain?

Another thing that confuses me a bit is about relations between effects and shaders. So far in my shader system design I only let an effect to have several shaders attached to itself, but then _DarkWIng_ mentioned about possibility of attaching multiple effects to one shader in his system.
What would be the best relation graph between shaders and effects then?

Thanks.

ps. I''m right after having read through those pretty long, but excellent Yann''s explanations on his shader system in another thread, so I might still be missing some important details
Maciej Sawitus
my blog | my games

This topic is closed to new replies.

Advertisement