dim3 Forum

Full Version: Shaders and Dim3
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3 4 5
btw: anonymous, is that a vertex or a fragment script?
I think he messed up. Correct me if I'm wrong, but that looks like he attempted to combine a vertex shader with a fragment shader...
It's a fragment shader. Helper, new version out right *now* Smile Give the shader a try, it should work *out of the box* (I hope.) Make sure to read the docs quickly to get it setup right, and then try it out.

I do NOT guarantee any other shader will work out of the box (see problems above), but I'm seeing a couple similar variables used in these shaders, and if I can get them put into core, a couple more might work with just minor tweaking.

[>] Brian
I tried an 'out of the box' shader for toon rendering. It was interesting. It still uses global positioned lights instead of dim3's lights. I know how to fix this, I think. It's because I didn't change the light variable to the closest light one that you added a while back. Even then, it didn't look right. It was totally white and the texture only sometimes showed through. Not to mention the framerate severely dropped...
teh1ghool Wrote:I tried an 'out of the box' shader for toon rendering. It was interesting. It still uses global positioned lights instead of dim3's lights. I know how to fix this, I think. It's because I didn't change the light variable to the closest light one that you added a while back. Even then, it didn't look right. It was totally white and the texture only sometimes showed through. Not to mention the framerate severely dropped...

There isn't a "closest light" position. Paste in the script here and let me take a look. You might be getting a frame rate drop because it's actually happening in software. What OS do you have?

[>] Brian
10.4.8, PPC

ggadwa Wrote:uniform vec3 dim3CameraPosition; // x,y,z
uniform int dim3LightCount;
uniform vec3 dim3LightPositions[64]; // x,y,z
uniform vec4 dim3LightColors[64]; // r,g,b,intensity
teh1ghool Wrote:10.4.8, PPC

ggadwa Wrote:uniform vec3 dim3CameraPosition; // x,y,z
uniform int dim3LightCount;
uniform vec3 dim3LightPositions[64]; // x,y,z
uniform vec4 dim3LightColors[64]; // r,g,b,intensity

Right, those are all the lights that could shine on that segment, but it doesn't pick one that is closest. That's maybe something I should add. Please post up the shader, I want to see what it requires since a toon shader has been asked before (it's not really necessary, though, if you use bright colors and diffuse lighting, that's what a toon shader really is.)

[>] Brian
You guys are going to have a real hard time with shaders here unless you are an GLSL expert, which I'm quickly becoming.  I'm trying to go through both AH's shaders and teh1ghools.  There's problems everywhere.

I don't know where AH got his, but it's full of syntax errors.  I'm thinking this shader works on PCs maybe, or somewhere where the compiler is less strict.  For instance:

Code:
        tmpPix = texture2D(tex,uv + vec2(i*0.005,0));

Is supposed to be illegal, i is an int and 0.005 is not.  There is no automatic conversions.  This throws an exception on OS X.  You need to check the logs (same place, console) whenever you get a shader that isn't working.

The correct code should be:

Code:
        tmpPix = texture2D(tex,uv + vec2(float(i)*0.005,0));

And that, BTW, is 1 out of 10 or so errors SO FAR!

More later ....

AH, what is this shader supposed to do so I know if I get the right results?

[>] Brian
OK,

I got both the shaders compiling and working (I assume, the toon shader works but the "blur" shader doesn't seem to do much -- it might be actually bluring but it's hard to tell.)  I added more variable support to the core.  There's a couple "closest light" variables, and a new "dim3TexColor" variable.  Textures can now have an alternate color to be used in shaders.

Note that the original toon shader did everything in pink, I altered it to use this texture color.  Here's a pick:

[Image: toon_joefoe.png]

Of course, in real usage, you'll want to pick a color other than orange and you'll want multiple textures with multiple colors.

Note that these shaders will only work in the next version.  For reference, here they are:

toon vertex:

Code:
varying vec3 normal;

void main()
{
    normal=gl_Normal;
    gl_Position=ftransform();
}

toon fragment:

Code:
uniform vec3 dim3ClosestLightNormal;
uniform vec4 dim3TexColor;
varying vec3 normal;

void main()
{
    float    intensity;
    vec4    color;

    intensity = dot(dim3ClosestLightNormal,normal);
    
    if (intensity > 0.95)
        color = dim3TexColor;
    else if (intensity > 0.5)
        color = dim3TexColor * 0.6;
    else if (intensity > 0.25)
        color = dim3TexColor * 0.4;
    else
        color = dim3TexColor * 0.2;
    
    gl_FragColor = color;
}

Doing a toon shader that is NOT flat-color based is a simple operation from here.

[>] Brian
Pages: 1 2 3 4 5
Reference URL's