[updated] An Ogre shader collection ?

Anything and everything that's related to OGRE or the wider graphics field that doesn't fit into the other forums.
User avatar
guilderstein
Halfling
Posts: 66
Joined: Wed Jan 04, 2006 11:48 am
Location: Hungary, Budapest

Post by guilderstein »

WIKI just finished with some screenies :)
Hope it works for ya too.
User avatar
guilderstein
Halfling
Posts: 66
Joined: Wed Jan 04, 2006 11:48 am
Location: Hungary, Budapest

Post by guilderstein »

@big_o

Ya wrote:

- I have already learned a lot of stuff from this shader, and It was a pretty
good idea.

Thx. But it just supposed to be practical, not to learn from :P

- One question though, is this shader written to use grayscale bumpmaps,
and meshes without tangents, or the multicolored normal maps?

No. Since it is based on OgreDemo shaders, it supports:

normal-mapping with color RGB texture,
(I know there are several techniques on normal-mapping, this one
uses the object-space one, I believe, just like in OgreDemos,
basically blueish)

offset(parallax-mapping) with again blueish RGB texture +
grayscale height (bump) map in texture A channel

But since at least normal-mapping is so general today, and looks way better than using grayscale instead of color map, I do not plan to add support to that bump-mapping. HW requirements are also not really a concern for normal-mapping given todays cards.[/quote]
big_o
Goblin
Posts: 279
Joined: Sun Feb 19, 2006 1:08 am

Post by big_o »

Nice!!! It works and looks good too!8)

guilderstein:

I know you meant for it to be practical. It just helped clear up some things.
You'll have to bear with me on the normal mapping, I had gotten use to Blender's bump-maping.
User avatar
eugen
OGRE Expert User
OGRE Expert User
Posts: 1422
Joined: Sat May 22, 2004 5:28 am
Location: Bucharest
x 8

Post by eugen »

i have added texture support to the wiki article perpixel lighting part 1, @Wretched_Wyx those errors can be mine :)
pls post the shader u got here (maybe u got it while i was editiing, there were some mistakes i fixed after i added the code) or take it again from the site
(i had also problems with the original shaders not compiling but that was due to wrong parameters type in the shader code)
big_o
Goblin
Posts: 279
Joined: Sun Feb 19, 2006 1:08 am

Post by big_o »

Found a bug(I think).

I am using guilderstein's final monster release. I have a proceduraly generated sphere mesh that uses just the per-pixel, 2 light, any an diffuse tex, ambient, spec, and diffuse parameters with no attenuation.

There is a little black circle around the top of the sphere, almost like the topmost ring of faces have been turned black, not transparent. This only occurs in OpenGL and it looks fine if no shader is used.

Just in case, I am runnning this on a Geforce 7600GS drivers version:83.91

If needed I can get a picture up later.
User avatar
Wretched_Wyx
Orc
Posts: 498
Joined: Thu Mar 16, 2006 5:27 pm

Post by Wretched_Wyx »

Hey thanks Eugen, though I've since wandered away from shader use for the moment. I like the amount of control I have with my prefabs, and thus probably won't be using shaders until I can write my own that fit in and cooperate nicely with what I'm doing.

One of the things that also added to me not using shaders, was the fact that I'm aiming for speed and high-quality visuals (who woulda thought right?). Adding in that per-pixel shader (the new one, tried it moments ago to see the new differences) resulted in massive framerate drops, which just isn't my jive. Went from getting 300+ FPS with pretty nice looking lighting, to 20 FPS with pretty nice++ lighting.

So until I can manage to find or make a PPL shader that's light and speedy, and doesn't force me to change my units settings (see code below) I'll be sticking to vertex lighting I guess. Here's a code snippet to maybe clarify what I'm doing, and it might prove useful to someone...

corePrefabs.h snippet:

Code: Select all

...
...
void createPointLight(String _pLightName,
					  bool _pLightShadows,
					  Vector3 _pLightPosition, 
					  const ColourValue _pLightDiffuseColor, 
					  const ColourValue _pLightSpecularColor,
					  const Real _pLightAttRange,
					  const Real _pLightAttConstant,
					  const Real _pLightAttLinear,
					  const Real _pLightAttQuadratic)
	{
	Light *_Light = mSceneMgr->createLight(_pLightName + ".pointlight");
	_Light->setType(Light::LT_POINT);
	_Light->setCastShadows(_pLightShadows);
	_Light->setDiffuseColour(_pLightDiffuseColor / 255);
	_Light->setSpecularColour(_pLightSpecularColor / 255);
	_Light->setAttenuation(
		(_pLightAttRange),
		(_pLightAttConstant / 255),
		(_pLightAttLinear / 100000),
		(_pLightAttQuadratic / 100000));
	
	SceneNode* _node = mSceneMgr->
		getRootSceneNode()->createChildSceneNode(_pLightName + ".lightnode");
	_node->attachObject(_Light);
	_node->setPosition(_pLightPosition);
}

...
...

void createPointLightFlourescent(void) {
		createPointLight(
			"PointLightFlourescent",		// Name
			true,							// Shadows false/true
			Vector3(0,64,0),				// Position
			(ColourValue(230,230,255)),		// Diffuse Color
			(ColourValue(0,0,0)),			// Specular Color
			512,							// Attenuation Range
			128,							// Attenuation Constant
			16,								// Attenuation Linear
			16								// Attenuation Quadratic
			);
	}

...
...
Create the "flourescent" light:

Code: Select all

createPointLightFlourescent();
Some of you may be able to guess what I might be moving towards here, but for those of you who don't: I want to create an editor, a simple one at first. Not to battle with the existing ones or anything, but just as a learning project.
User avatar
Falagard
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 2060
Joined: Thu Feb 26, 2004 12:11 am
Location: Toronto, Canada
x 3

Post by Falagard »

who woulda thought right
You can't go from fixed function to per pixel lighting and expect the same frame rate. Ever. And you can't just drop in a shader into any scene and expect it to be the best way to do things.

For example, with the shaders I'm writing I'll be creating per pixel shaders, per vertex shaders, different shadow types depending upon the meshes (self shadowing for characters, not self shadowing for other types of objects). The materials will be set up to go from per pixel to per vertex based on distance, and there will likely be a shader that blends the two as a transition between them.

Shaders are not necessary for good looking scenes. They can look good, but the amount of effort required compared to fixed function lighting is pretty crazy. There are problems like overbrightening when dealing with multiple lights, especially when doing per light passes. There are problems with performance. There are problems with different types of hardware. etc.
User avatar
Wretched_Wyx
Orc
Posts: 498
Joined: Thu Mar 16, 2006 5:27 pm

Post by Wretched_Wyx »

Everything you said, I already knew, I'm not that green :wink:. But to further iterate on my last post, let me say this: I've seen per-pixel shaders that operate much faster and look better than the one from the wiki. As cool as it is, it's messy and in-efficient. Sure, I could fix that. And I will, once I understand shaders more.

Sorry if I sounded rude there, but it's true, I did know those things. As a matter of fact I've spent the laster several days reading pages from Game Programming Gems, Game Design: Secrets of the Sages, as well as numerous articles on GameDev and Gamasutra. It's given me a lot more insight into optimization throughout games in general, as well as the lower level stuff. From what you were saying you were doing, and from the shaders I looked at from GOOF, I can see you have the same things in mind.

Sure is a daunting task though... And if you don't do it from the beginning, it's even more difficult. That's one of the reasons I was pushing for this nice new shader addition to the wiki to be more... You get my drift I think.

Anyhow, I have a simple concept for the lighting shaders in the wiki code snippets section:

Shaders
---
Introduction
Getting Started With Ogre CG Materials
Orange Shader
Fading Object Shader
Holographe Shader
Per-Vertex Lighting <--- !
Per-Pixel Lighting Simple <--- !
Per-Pixel Lighting Advanced <--- !
Hemispherical Lighting <--- !
Custom Shadow Mapping

I actually created the sections for per-pixel and hemispherical lighting, and I think what I propose above would be much cleaner. Hemispherical lighting isn't so important, I just think it looks really nice :). Having those 4 pages for the shaders guilderstein submitted seems messy. I know, I know... I'm probably getting annoying with that. I guess if no one else cares I don't either.
User avatar
guilderstein
Halfling
Posts: 66
Joined: Wed Jan 04, 2006 11:48 am
Location: Hungary, Budapest

Post by guilderstein »

Hi!

I'm afraid I was way too overambitious about those shaders. Sorry 'bout that, I always had a big mouth :) . In WIKI, I now have only 1 page there, /apart from simple-perpixel which I won't touch since it has been modified/.
I kept all other pages, too, but I link them from simple perpixel, rather that codesnippits/shaders. I think thats correct.
If you have good solutions to either (perpixel, offset, etc), please post them, let me learn :)

@big_o

Sometimes I have issues with openGL, in varying topics. May be driver bug.
If you've got MONSTER working with D3D9, that's good. I myself use D3D9
because it is generally faster with my drivers on 9600XT (+10..50 FPS)

By the way, I updated MONSTER, supports now light0 as directional,
while light1 and light2 are point lights with atten. All 3 can go with offset
max. And added a fadeout part in vert shader, but I have a bug there,
so experimental.

http://rapidshare.de/files/23197779/won ... 1.zip.html

@Wretched_Wyx

/Though the following might sound sarcastic, it is not meant to :)/
I'd love to hear how those perpixel shaders you mentioned work.
How can they be faster than MONSTER reduced to do only perpixel?
If set to do, MONSTER will only calc. lightdir and eyedir in vertex,
do NdotL and NdotH in frag, and issue a lit(...) to get a color.
Even parameters given to vert, and from vert to frag are reduced to the ones necessary.
Or course if you mentioned simple_perpixel 1 from WIKI, that is meant to be slow. An accuracy tradeoff.
User avatar
Wretched_Wyx
Orc
Posts: 498
Joined: Thu Mar 16, 2006 5:27 pm

Post by Wretched_Wyx »

Guilderstein,

No offense taken :). Here's a direct comparison- if I run the Ogre demo Dot3Bump, and change the material to offset specular mapping, I can pull about 80 FPS. Running the latest (as of yesterday) MONSTER shader, on an even *simpler* scene than the Dot3Bump, I only get 20 FPS. I left settings at default. I'll try those settings you gave me, and see how much of a difference in FPS there. I'm guessing it should be significant.

Nice job on the new wiki layout, much cleaner. I can relate to just getting something put up so people can use it, being pressed for time and all. Right now I'm spread thin across several projects- AVLabs (Design, Dev, Wiki, Forums, backend for Design/Dev, etc), learning C++, shaders, PHP... And of course working with Ogre, and trying to earn my weight on a team working on a top-secret game project :twisted:.

I think I've just realised that I'm a neat freak. I'm guessing that is a good thing if I want to be a good programmer eh? I'll re-organize whole projects, taking hours to do it just so that things look "right". Oi! I'm turning into a blog monster thing-a-mabob.

[edit]
My 200th post :shock:
[/edit]
big_o
Goblin
Posts: 279
Joined: Sun Feb 19, 2006 1:08 am

Post by big_o »

guilderstein:

Yeah, I pretty much figured It was some sort of OpenGL issue, but there is very little difference performance wise between the two in my prgram.
Typicaly, OpenGL will run at little quicker. It isn't a very big deal, its just that most of my target audience has doesn't have D3D9, and most of them are stuck with integrated graphics.

Thanks for releasing such an awesome resorce! :D
User avatar
guilderstein
Halfling
Posts: 66
Joined: Wed Jan 04, 2006 11:48 am
Location: Hungary, Budapest

Post by guilderstein »

Hi!

I'm glad someone might actually find it useful. I have no performance problems, MONSTER is just flying like a rocket.

Could you guys help me a bit on that fadeout part?
If I do not use scene_blend alpha_blend in material script, I get no blending at all. But even then, if I have objects that are using textures
and not just lighting behind the knot with MONSTER as material,
the knot will not fade, but darken to black, covering everything that is behind it. However, fading works when only skybox is behind the knot.
No picture now, pls try fading.

Thx. Any requests what I shall add to MONSTER?
User avatar
guilderstein
Halfling
Posts: 66
Joined: Wed Jan 04, 2006 11:48 am
Location: Hungary, Budapest

Post by guilderstein »

Hohoho!

Yesterday I got monster working with oFusion!
Give it a go :)

http://rapidshare.de/files/24150015/ofusion.zip.html

pic:
Image
Last edited by guilderstein on Mon Jun 26, 2006 10:20 am, edited 1 time in total.
User avatar
Evak
Orc Shaman
Posts: 707
Joined: Sun Apr 02, 2006 7:51 pm
Location: Sacramento, CA
x 1

Post by Evak »

Hi guilderstein

I tried your shader but it crashes Ofusion when you start the Ogre viewport. None of the other shaders that come with ofusion do, Just happens when I add monster.

Here's the error I get in the Ogre.log

Code: Select all

15:53:22: Parsing script monster.program
15:53:22: An exception has been thrown!

-----------------------------------
Details:
-----------------------------------
Error #: 8
Function: ResourceGroupManager::openResource
Description: Cannot locate resource monster_vs.source in resource group General.. 
File: C:\ogre3d\OgreMain\src\OgreResourceGroupManager.cpp
Line: 501
Stack unwinding: <<beginning of stack>>
Some new Ofusion shaders would be fantastic :) so thanks for the effort and I hope the problem can be fixed. I did follow the instructions as directed in the readme.

Hope the above helps.
Lioric
Google Summer of Code Mentor
Google Summer of Code Mentor
Posts: 295
Joined: Fri Aug 06, 2004 10:25 pm

Post by Lioric »

very nice, excellent job :)

Im sure i will test it as soon as possible
Some new Ofusion shaders would be fantastic so thanks for the effort and I hope the problem can be fixed. I did follow the instructions as directed in the readme.
The shaders are within a single file but they are referenced in the program definition as separated files

Open the "monster.source" file and change the main vs method name form "monster" to "monster_vs"

Code: Select all

/////////////////////////////////////////////////////////////////////////////////////////////////
    //									VERT COMES
    ///////////////////////////////////////////////////////////////////////////////////////////////// 

    void monster_vs  // ******Change to this method name********
    (
             float4 position	: POSITION,
             float3 normal		: NORMAL,
             out float4 oPosition	: POSITION
   ...
do the same for the fragment part (on the same file) but change its name to monster_ps

Code: Select all

    /////////////////////////////////////////////////////////////////////////////////////////////////
    //									FRAG COMES
    /////////////////////////////////////////////////////////////////////////////////////////////////
 
 
 
    void monster_ps(  // ******Change to this method name********
 
        #if DIFFUSE_TEXTURE
              uniform sampler2D diffuseMap : register(s1),

...
In the "monster.program" file change "source" attribute value of the vertex program definition from "monster_vs.source" to "monster.source" and the "entry point" value to "monster_vs"

Code: Select all

    vertex_program monster_vs cg
    {
        source monster.source  // ******Change to value name********
 
        default_params
        {
            param_named_auto lightPosition0 light_position_object_space 0
            param_named_auto lightPosition1 light_position_object_space 1
            param_named_auto lightPosition2 light_position_object_space 2
            param_named_auto eyePosition camera_position_object_space
            param_named_auto worldviewproj worldviewproj_matrix
            param_named scale float 2 
        }
 
        entry_point monster_vs // ******Change to value name********
        profiles vs_1_1 arbvp1
    }
And the same for the fragment program definition, but with "monster_ps" for the entry point name

Code: Select all

fragment_program monster_ps cg
    {
        source monster.source // ******Change to value name********
 
        default_params
        {
            param_named_auto lightDiffuse0 light_diffuse_colour 0
            param_named_auto lightDiffuse1 light_diffuse_colour 1
            param_named_auto lightDiffuse2 light_diffuse_colour 2
 
            param_named_auto lightSpecular0 light_specular_colour 0
            param_named_auto lightSpecular1 light_specular_colour 1
            param_named_auto lightSpecular2 light_specular_colour 2
 
            param_named_auto atten0 light_attenuation 0
            param_named_auto atten1 light_attenuation 1
            param_named_auto atten2 light_attenuation 2
 
            param_named exponent0 float 127
            param_named scaleBias float4 0.04 -0.02 1 0 
            param_named ambient float4 0.0 0.0 0.1 1.0
 
        }
 
        entry_point monster_ps // ******Change to value name********
        profiles ps_2_0 arbfp1
    }
User avatar
jacmoe
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 20570
Joined: Thu Jan 22, 2004 10:13 am
Location: Denmark
x 179

Post by jacmoe »

This is nice! :)

Just one thing, though: Why does offset mapping always look like slimy alien skin? Looks cool, but bricks normally doesn't look like that. :wink:
/* Less noise. More signal. */
Ogitor Scenebuilder - powered by Ogre, presented by Qt, fueled by Passion.
OgreAddons - the Ogre code suppository.
User avatar
stoneCold
OGRE Expert User
OGRE Expert User
Posts: 867
Joined: Fri Oct 01, 2004 9:13 pm
Location: Carinthia, Austria
x 1

Post by stoneCold »

jacmoe wrote:This is nice! :)

Just one thing, though: Why does offset mapping always look like slimy alien skin? Looks cool, but bricks normally doesn't look like that. :wink:
... because it emphasises the effect :wink: (not needed though)

btw, nice work
my tweets | www.fuse-software.com | home of vektrix (Flash GUI for Ogre3D) and caspin (ActionScript 3 Virtual Machine Wrapper)
User avatar
guilderstein
Halfling
Posts: 66
Joined: Wed Jan 04, 2006 11:48 am
Location: Hungary, Budapest

Post by guilderstein »

Hello men!

Sorry 'bout that file problem, I just wanted to get it work without separate ..._vs and ..._ps files, and probably packaged the wrong setup :)

Package is correct now. (hope)

About the slime:
result of high specular coeff, to show that it works
if ya set that to lower value, or zero out SPECULAR in source files,
ya will get better/no slime at all, just diffuse offset-mappin'
Check out some specular-offset shaders
(for ex in the relief-demo of Fabio Policarpo) they are all slimy

btw I like Aliens
:twisted:
"I go where I please, and I please where I go"
- Duke Nukem
User avatar
dfacchin
Greenskin
Posts: 105
Joined: Fri May 13, 2005 10:11 am

Post by dfacchin »

just to let u know, the ofusion file u put on rapidshare is not working anymore :( can u upload it again or send it to me pls :P!

dfacchin(at)yahoo.com

TX
Captain Nemo
Greenskin
Posts: 134
Joined: Sun May 02, 2004 5:06 pm
Location: Kassel, Germany

Post by Captain Nemo »

Yep, I too found that the file link in the Wiki is no longer working. Has someone still got the file and could upload it to a more permanent location? (If necessary I could host it on my site.)
http://www.aridocean.com
The Marine Life Simulation
User avatar
jacmoe
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 20570
Joined: Thu Jan 22, 2004 10:13 am
Location: Denmark
x 179

Post by jacmoe »

Would be a shame if it was lost. I don't have it - but I planned to use it! :(
/* Less noise. More signal. */
Ogitor Scenebuilder - powered by Ogre, presented by Qt, fueled by Passion.
OgreAddons - the Ogre code suppository.
User avatar
Evak
Orc Shaman
Posts: 707
Joined: Sun Apr 02, 2006 7:51 pm
Location: Sacramento, CA
x 1

Post by Evak »

I stuck the Ofusion version on my FTP for the time being.

http://s93153354.onlinehome.us/ofusion_The_Monster.zip

if anyone updates/improves it, let me know. I'll update the file. The original author never added the commented out features as far as I know.
Captain Nemo
Greenskin
Posts: 134
Joined: Sun May 02, 2004 5:06 pm
Location: Kassel, Germany

Post by Captain Nemo »

Thanks a lot, Evak!
http://www.aridocean.com
The Marine Life Simulation
User avatar
dfacchin
Greenskin
Posts: 105
Joined: Fri May 13, 2005 10:11 am

Post by dfacchin »

tx man!
User avatar
Yaraher
Greenskin
Posts: 142
Joined: Tue Dec 13, 2005 11:37 pm
Location: Lima, Peru

Post by Yaraher »

I was just cheking out the PerPixel Lighting material, and tried to used in my project, but I keep having some errors:

Code: Select all

Error #: 9
Function: CgProgram::loadFromSource
Description: Unable to compile Cg program Simple_Perpixel_Vert: CG ERROR : The compile returned an error.
(78) : warning C7011: implicit cast from "float4" to "float3"
(88) : error C0000: syntax error, unexpected ',', expecting '(' at token ","
(88) : error C0501: type name expected at token ","
(91) : error C1068: too much data in type constructor
(91) : error C1033: cast not allowed
(91) : error C0000: syntax error, unexpected ';', expecting ')' at token ";"
(91) : error C0501: type name expected at token ";"

Code: Select all

Error #: 9
Function: CgProgram::loadFromSource
Description: Unable to compile Cg program Simple_PerPixel_Frag: CG ERROR : The compile returned an error.
(78) : warning C7011: implicit cast from "float4" to "float3"
(88) : error C0000: syntax error, unexpected ',', expecting '(' at token ","
(88) : error C0501: type name expected at token ","
(91) : error C1068: too much data in type constructor
(91) : error C1033: cast not allowed
(91) : error C0000: syntax error, unexpected ';', expecting ')' at token ";"
(91) : error C0501: type name expected at token ";"

Code: Select all

Error #: 9
Function: CgProgram::loadFromSource
Description: Unable to compile Cg program Ambient: CG ERROR : The compile returned an error.
(78) : warning C7011: implicit cast from "float4" to "float3"
(88) : error C0000: syntax error, unexpected ',', expecting '(' at token ","
(88) : error C0501: type name expected at token ","
(91) : error C1068: too much data in type constructor
(91) : error C1033: cast not allowed
(91) : error C0000: syntax error, unexpected ';', expecting ')' at token ";"
(91) : error C0501: type name expected at token ";"
Each of them seems to be some sort of syntaxis errors, but can't figure out what is wrong in the .cg files. Any idea?