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
Hey everyone.

I have very little knowledge in how to code shaders but I downloaded some glsl shader examples. But when I imported the .vert/.frag files and run the engine, I either crash the engine or else the texture with the shader on it is totally transparent(Or so it seems).

Here is the shader code.
Code:
uniform sampler2D tex0;

void main(void)
{
    vec4 blurSample = 0.0;
    vec4 tmpPix;
    vec4 offPix;
    vec2 uv = gl_TexCoord[0].st;
    for(int i=-4;i<5;i++)
    {
        tmpPix = texture2D(tex0,uv + vec2( i*0.005,0 ));
        offPix = -0.3+tmpPix;
        offPix = offPix * 15;
        if( (offPix.r+offPix.g+offPix.b)>0 )
        {            
                blurSample = blurSample + offPix;    
        }
    }

    for(int i=-4;i<5;i++)
    {
        tmpPix = texture2D(tex0,uv + vec2( 0,i*0.005 ));
                  offPix = -0.3+tmpPix;
        offPix = offPix * 15;
        if( (offPix.r+offPix.g+offPix.b)>0 )
        {
            blurSample += offPix;
        }

    }

    blurSample = blurSample / 64;
    gl_FragColor = blurSample*1.2;
}

What can I do to fix this?
shaders will have to be changed to work with the engine. they don't get as much output from the game as they would from openGL.
i don't know what to do, shaders are the one thing that i've never scripted...
Next version I'm hopefully going to take a look at some shaders and maybe write up a document.  What people don't realize is that shaders have two components; one is the shader and the other is the code in the engine that communicates with it (i.e., sets up variables, states, textures, etc, in special ways that the shader wants.)

In dim3, there's a generic way to set these up, but most shaders won't work without some alteration to use the proper variables, etc.

There's some docs that came with dim3, but you have to understand how shaders work (and be able to write them) to be able to do this; you won't be able to just plug and play them.

[>] Brian
Where are the docs?
Anonymous Helper Wrote:Where are the docs?

It's on the main left menu of the docs, "Shaders". Right now you'll need to get them from an older version, the betas don't have docs with them.

[>] Brian
:-( It covers almost nothing.
Anonymous Helper Wrote::-( It covers almost nothing.

It covers what engine does; this is the missing part you need to know to write a shader.

You see this bit at the top:

Code:
uniform sampler2D tex0;

That's data coming in from the engine, and is tied directly to the opengl code that's the other part of this.  That's why it wouldn't run correctly.  This is the problem, most of these GLSL samples are tied to sample code on the OpenGL side.

That one looks like a pretty good idea to ue tex0, tex1, etc, to pass in the textures.  I'll implement that, add it to the docs, and then in the next beta check to see if you shader is working.

That's the big problem with these shaders; these variables are passed in from the engine, and my docs are meant to show the names of the variables I use, and hopefully somebody will know enough GLSL to be able to substitute. That why it's good to see some of these shaders because I know what is then needed.

[>] Brian
brian, could you post a list of what doesn't work with dim3 in shaders?
and functions we could use that are ONLY in dim3?
(then i could learn to substitute)
and last of all, do you have anything i can play around with and try to convert? anyone?
ccccc Wrote:brian, could you post a list of what doesn't work with dim3 in shaders?
and functions we could use that are ONLY in dim3?
(then i could learn to substitute)
and last of all, do you have anything i can play around with and try to convert? anyone?

You're not getting it.  You can use whatever functions your card supports.  That's not the problem.  The problem is shaders DO NOT STAND ALONE.  They are tied directly to CORE code.  Core code passes variables, the shaders use those variables.

That's what my docs tell you, what variables I have setup in dim3.  You need to know what the GLSL program is doing so you can decide that it's this variable from me that equals the one they are using.

[>] Brian
The next beta will have these new variables:

tex
tex0
tex1
tex2
tex3

(tex and tex0 are equivalent, I've seen another example where that was used.) This *should* make the shader above begin to work. I'll add these to the doc.

Helper, check this out on the next beta for me, please.

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