BASIC

Author Topic: GLSL - The OpenGL Shader Language: for 2d and 3d SFX  (Read 15393 times)

Offline Hemlos

  • To boldy go where no pixel has gone before!
  • Global Moderator
  • Prof. Inline
  • *******
  • Posts: 1634
  • Particle Hawk
    • View Profile
I made a new Shader, for increasing the brightness of an object by 50%.
I will add more in this thread later on.


Example for using GLSL:
Code: Text [Select]
X_LOADSHADER(0, "Bright.vert", "Bright.frag")
 
-
Code: Text [Select]
X_SETSHADER 0;
DRAWSPRITE
X_SETSHADER -1
 
-
Code: Text [Select]
X_SETSHADER 0;
X_DRAWOBJ
X_SETSHADER -1
 

-Hemlos

EDIT: This post is updated with the proper shader.
===============================================================
EDIT: COLOR SHADER BELOW:
I made a color shader, it adds color to your texture in the gpu.
This can also be used as a "brightness".
To use as brightness, increase R G B the same amount.
Remember, this is additive, so if your texture is already bright...itll push the color closer to white.

This will add some red:
Code: Text [Select]
X_COLORSHADER( 0.5, 0.0, 0.0 )
 

The colors in GLSL ranges from 0.0 to 1.0 which is the equivilant of 0x00 to 0xff


Put the shader files with the exe, and use this function to declare and set the color.
You call this function right before X_SETTEXTURE.

Code: GLBasic [Select]
        X_COLORSHADER( 0.5, 0.0, 0.0 )
        X_SETTEXTURE Texture0 ,-1
        X_DRAWOBJ Object0, 0
        X_SETSHADER -1
 


You can reduce cycles by preloading the shader instead of putting it in the function.

Code: Text [Select]
FUNCTION X_COLORSHADER: R,G,B //RGB Addition

        STATIC Initialize, Test
        IF Initialize<>TRUE
                Initialize=TRUE
                Test=X_LOADSHADER(11,"Color.vert","Color.frag")
        ENDIF

        X_SETSHADER 11
        X_PUTSHADER "R",R
        X_PUTSHADER "G",G
        X_PUTSHADER "B",B
       
        RETURN Test

ENDFUNCTION
 

edit July 2012:
I reupload the colorshader.rar, it wasnt correct.



[attachment deleted by admin]
« Last Edit: 2012-Jul-21 by Hemlos »
Volume_of_Earth(km^3) = 4/3*3.14*POW(6371.392896,3)

Offline Kitty Hello

  • code monkey
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 10697
  • here on my island the sea says 'hello'
    • View Profile
    • http://www.glbasic.com
the internal bump mapping and cel shading use different techniques. No shaders, thus compatible with older hardware.

Offline Hemlos

  • To boldy go where no pixel has gone before!
  • Global Moderator
  • Prof. Inline
  • *******
  • Posts: 1634
  • Particle Hawk
    • View Profile
Ok cool good to know, Gernot..

And Thanks for the info...

Ok here is the "Shiny" shader...

Scalar Variables in shader are adjustable with the settings at top of BumpLight.frag:
You can adjust Ambient, Specular, And Diffuse
Also you can adjust the size of the texture.

Test: If you set the Specular to 2.0 and the TextureScale to 0.1 - 0.5 you can make a GLASS ball for instance.

It makes it "shiny".... You must use both inputs of X_SETTEXTURE 3d bumpmap system.
Here are the files:

[attachment deleted by admin]
« Last Edit: 2009-Jul-02 by Hemlos »
Volume_of_Earth(km^3) = 4/3*3.14*POW(6371.392896,3)

Offline Kitty Hello

  • code monkey
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 10697
  • here on my island the sea says 'hello'
    • View Profile
    • http://www.glbasic.com
// GLBasic exports 2 "uniform sampler2D" variables if
// you set X_SETTEXTURE a,b after X_SETSHADER!
// TextureID1 = a
// TextureID2 = b
uniform sampler2D TextureID1;
uniform sampler2D TextureID2;

Offline Hemlos

  • To boldy go where no pixel has gone before!
  • Global Moderator
  • Prof. Inline
  • *******
  • Posts: 1634
  • Particle Hawk
    • View Profile
Hi again,

I am learning more about GLSL, couple questions please.

Is there anything else GLBasic exports to shaders?

What  OpenGL and GLSL version is GLBasic using?
Volume_of_Earth(km^3) = 4/3*3.14*POW(6371.392896,3)

Offline Kitty Hello

  • code monkey
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 10697
  • here on my island the sea says 'hello'
    • View Profile
    • http://www.glbasic.com
The version depends on your drivers (2.x) and no, I'm not exporting anything else, but you can manually export variables with uhm... there's a command ;)

Offline Hemlos

  • To boldy go where no pixel has gone before!
  • Global Moderator
  • Prof. Inline
  • *******
  • Posts: 1634
  • Particle Hawk
    • View Profile
Aye uniform


All the projection matrix, texture coordinate matrix, and all those other matrixs....are these normal in the sense that my shaders will read them as intended by the language?

Also, all the stuff that a frag shader exports into the standard matrixs....are these compatible with GLBasic?

Are you aware of anything the language wont do, which is actually intended to be possible with the shader language?
Volume_of_Earth(km^3) = 4/3*3.14*POW(6371.392896,3)

Offline Kitty Hello

  • code monkey
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 10697
  • here on my island the sea says 'hello'
    • View Profile
    • http://www.glbasic.com
no, there should not be any limit.

Offline Hemlos

  • To boldy go where no pixel has gone before!
  • Global Moderator
  • Prof. Inline
  • *******
  • Posts: 1634
  • Particle Hawk
    • View Profile
How do i get this info?
glGetString(GL_SHADING_LANGUAGE_VERSION)
Volume_of_Earth(km^3) = 4/3*3.14*POW(6371.392896,3)

Offline Kitty Hello

  • code monkey
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 10697
  • here on my island the sea says 'hello'
    • View Profile
    • http://www.glbasic.com
Code: GLBasic [Select]
CONSTANT GL_SHADING_LANGUAGE_VERSION = 35724

PRINT glGetString$(GL_SHADING_LANGUAGE_VERSION), 0,0
SHOWSCREEN
MOUSEWAIT



FUNCTION foo:



ENDFUNCTION


INLINE
extern "C" const unsigned char* __stdcall glGetString( int name );
ENDINLINE


FUNCTION glGetString$: id%
        INLINE
                return DGStr((const char*)glGetString(id));
        ENDINLINE
ENDFUNCTION
 

Constants are here:
http://www.khronos.org/registry/gles/api/2.0/gl2.h

Offline Hemlos

  • To boldy go where no pixel has gone before!
  • Global Moderator
  • Prof. Inline
  • *******
  • Posts: 1634
  • Particle Hawk
    • View Profile
Awesome,

1.2 on nvidia, using Cg compiler.

Things that make me go "Hmmmmmm"



[attachment deleted by admin]
Volume_of_Earth(km^3) = 4/3*3.14*POW(6371.392896,3)

Offline Hemlos

  • To boldy go where no pixel has gone before!
  • Global Moderator
  • Prof. Inline
  • *******
  • Posts: 1634
  • Particle Hawk
    • View Profile
3 questions:

1.
Can i use x_putshader multiple times before calling the X_DRAWOBJ?

2.
Also, does x_shader need to be set before the x_make3d?
Or after move scale and rotate?
I ask because I realize you noted to put it before the x_settexture
And theres a bunch of matrix it needs to read for model and views.

3.
Can multiple shaders be applied in a sequence?
This language seems to be oriented to doing stuff this way.

apply matrices
apply shader.glsl 1
apply shader.glsl  2
apply shader.glsl  3, etc
draw object

The way i understand it in OpenGL, each new apply of a shader affects all the previously pipelined shader information before drawing an object.
An example of this is RenderMonkey program.
This program applies multple shaders to an object to create AMAZING effect (whichi cant seem to replicate)

Oh ya thanks for the getsetring command....i added a version info program showing all extensions and internal versions of opengl for any 3d card.
link: http://www.glbasic.com/forum/index.php?topic=3631.0

« Last Edit: 2009-Oct-11 by Hemlos »
Volume_of_Earth(km^3) = 4/3*3.14*POW(6371.392896,3)

Offline Kitty Hello

  • code monkey
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 10697
  • here on my island the sea says 'hello'
    • View Profile
    • http://www.glbasic.com
1. Yes of course.
2. it doesn't matter where you put shader variables, just before x_settexture. I can't remember why, though.
3. uhm. Can you apply several shaders? I don't think that's possible (in OpenGL).

Offline Hemlos

  • To boldy go where no pixel has gone before!
  • Global Moderator
  • Prof. Inline
  • *******
  • Posts: 1634
  • Particle Hawk
    • View Profile
This is a screenshot of AMD's render monkey.
It is a program that processes shaders like an IDE and view port.

Here you can see that several shaders are being applied to achieve this effect "GL OOZE Effect"..looks awesome, and it works with glsl 1.20 apparently.

To make this effect with shaders, it uses 3 shader.vert and .frags in one group, and it needs a second shader set which contains 6 more shaders.

[attachment deleted by admin]
Volume_of_Earth(km^3) = 4/3*3.14*POW(6371.392896,3)

Offline Kitty Hello

  • code monkey
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 10697
  • here on my island the sea says 'hello'
    • View Profile
    • http://www.glbasic.com
They must render the model twice with different shaders then. There's no GLSL extension function hidden that you can't use with GLBasic.