Author Topic: [PROCEDURAL] glsl_plasma  (Read 14204 times)

0 Members and 1 Guest are viewing this topic.

Offline Dr_D

  • Atari ST
  • ***
  • Posts: 151
  • Karma: 29
    • View Profile
[PROCEDURAL] glsl_plasma
« on: April 29, 2008 »
I decided to make another entry since my other one sucked. :whack: This one isn't really anything special either, but I think it's pretty fun to do old-school effects with glsl.

EDIT: I was just informed by a couple of guys with nVidia 8800GTX cards that this just presents a blank screen in Vista. Can anyne confirm that this works on any other card in Vista?

EDIT: Removed old version and added one that should be more compatible with ATI cards.
« Last Edit: May 03, 2008 by Dr_D »
The Dr. is INsane!!!

Offline Voltage

  • Professor
  • Pentium
  • *****
  • Posts: 857
  • Karma: 53
    • View Profile
Re: [PROCEDURAL] glsl_plasma
« Reply #1 on: April 29, 2008 »
Yepper, black screen for me too.  Vista, nVidia 5700.

It's a nice black screen though, and it exits without any errors.  ::)
Challenge Trophies Won:

Offline Dr_D

  • Atari ST
  • ***
  • Posts: 151
  • Karma: 29
    • View Profile
Re: [PROCEDURAL] glsl_plasma
« Reply #2 on: April 29, 2008 »
hehehe... i win!  :boxer:
The Dr. is INsane!!!

Offline hellfire

  • Sponsor
  • Pentium
  • *******
  • Posts: 1294
  • Karma: 466
    • View Profile
    • my stuff
Re: [PROCEDURAL] glsl_plasma
« Reply #3 on: April 29, 2008 »
Runs fine at work (Geforce 7600), doesn't run at home (Radeon 9600).
Looking at the fragment-program, this might be a ati-problem with gl_FragCoord.

Nevertheless a very nice plasma, indeed.
Challenge Trophies Won:

Offline rain_storm

  • Here comes the Rain
  • DBF Aficionado
  • ******
  • Posts: 3088
  • Karma: 182
  • Rain never hurt nobody
    • View Profile
    • org_100h
Re: [PROCEDURAL] glsl_plasma
« Reply #4 on: April 29, 2008 »
nice colourful plasma  :cheers:

Challenge Trophies Won:

Offline Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5301
  • Karma: 402
    • View Profile
Re: [PROCEDURAL] glsl_plasma
« Reply #5 on: April 30, 2008 »
Black screen here on my Vista 8600GT, but massive props (K+) for supplying source, so I will try to find out what went wrong and post back :)

Jim
Challenge Trophies Won:

Offline benny!

  • Senior Member
  • DBF Aficionado
  • ********
  • Posts: 4384
  • Karma: 228
  • in this place forever!
    • View Profile
    • bennyschuetz.com - mycroBlog
Re: [PROCEDURAL] glsl_plasma
« Reply #6 on: April 30, 2008 »
Very sweet plasma. Good entry. I like it!
[ mycroBLOG - POUET :: whatever keeps us longing - for another breath of air - is getting rare ]

Challenge Trophies Won:

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17412
  • Karma: 498
  • evil/good
    • View Profile
    • My Homepage
Re: [PROCEDURAL] glsl_plasma
« Reply #7 on: April 30, 2008 »
Seems like the link won't download here.. It should be able to be attached to the post easily though? Media Fire said that the file is only about 60kb, upload limit is 300kb here.

Screen shot looks nice though!
Shockwave ^ Codigos
Challenge Trophies Won:

Offline Dr_D

  • Atari ST
  • ***
  • Posts: 151
  • Karma: 29
    • View Profile
Re: [PROCEDURAL] glsl_plasma
« Reply #8 on: April 30, 2008 »
Ok, I added it as an attachment. ;) I don't have any idea what could be causing it to totally black out on Vista, unless it's a driver problem. I have another glsl demo that works fine on Vista though.


EDIT: Ok, here's something really weird. My buddy tried to run this on an ATI mobility radeon 9600, and got this as the error log output. I've been going by the standard OpenGL Shading Language 2nd edition documentation, but I haven't found anything that says why this works on nVidia, but not ATI.


Quote
Shader Infolog error message:
ERROR: 0:13:'*' :  wrong operand types  no operation '*' exists that takes a left-hand operand of type 'float' and a right operand of type 'const int' (or there is no acceptable conversion)
ERROR: 1 compilation errors.  No code generated.
« Last Edit: May 01, 2008 by Dr_D »
The Dr. is INsane!!!

Offline Optimus

  • DBF Aficionado
  • ******
  • Posts: 2456
  • Karma: 128
    • View Profile
    • Optimouse Demo Site
Re: [PROCEDURAL] glsl_plasma
« Reply #9 on: May 02, 2008 »
I really wondered how a plasma will look in pixel shaders. Now I see it :)
Challenge Trophies Won:

Offline va!n

  • Pentium
  • *****
  • Posts: 1435
  • Karma: 109
    • View Profile
    • http://www.secretly.de
Re: [PROCEDURAL] glsl_plasma
« Reply #10 on: May 02, 2008 »
does not works here :(   openwindow (white n frozen) n showing console with this info:

Code: [Select]
GL_EXT_framebuffer_object is supported
GL_ARB_multitexture is supported
GL_ARB_shading_language_100 is supported

Location of Timer variable in shader:0

Nothing happens... just frozen... when trying to close the app an error messagebox with this text is shown:

Code: [Select]
---------------------------
glsl_plasma.exe - Fehler in Anwendung
---------------------------
Die Anweisung in "0x5f0e95ec" verweist auf Speicher in "0x7ff50007". Der Vorgang
"read" konnte nicht auf dem Speicher durchgeführt werden.

Klicken Sie auf "OK", um das Programm zu beenden.
---------------------------
OK   
---------------------------
- hp EliteBook 8540p, 4 GB RAM, Windows 8.1 x64
- Asus P5Q, Intel Q8200, 6 GB DDR2, Radeon 4870, Windows 8.1 x64
http://www.secretly.de
Challenge Trophies Won:

Offline hellfire

  • Sponsor
  • Pentium
  • *******
  • Posts: 1294
  • Karma: 466
    • View Profile
    • my stuff
Re: [PROCEDURAL] glsl_plasma
« Reply #11 on: May 02, 2008 »
Quote
does not works here :(
So you've got ATI, too :)

Seriously, Dr_D, remove "gl_FragCoord" from your shader, it causes the ati-driver to fall back to software-rendering.
Just feed gl_Vertex into an additional uniform and all is fine.

Quote
wrong operand types  no operation '*' exists that takes a left-hand operand of type 'float' and a right operand of type 'const int'
so... just use a float then :)
(i've never seen this happen, probably *very* old drivers?)

Challenge Trophies Won:

Offline Dr_D

  • Atari ST
  • ***
  • Posts: 151
  • Karma: 29
    • View Profile
Re: [PROCEDURAL] glsl_plasma
« Reply #12 on: May 02, 2008 »
Well, I didn't really want to do that. Any idea why ATI doesn't support gl_FragCoord? That seems strange not to support it in hardware.
The Dr. is INsane!!!

Offline va!n

  • Pentium
  • *****
  • Posts: 1435
  • Karma: 109
    • View Profile
    • http://www.secretly.de
Re: [PROCEDURAL] glsl_plasma
« Reply #13 on: May 02, 2008 »
possible only ATI will know this ^^
- hp EliteBook 8540p, 4 GB RAM, Windows 8.1 x64
- Asus P5Q, Intel Q8200, 6 GB DDR2, Radeon 4870, Windows 8.1 x64
http://www.secretly.de
Challenge Trophies Won:

Offline Dr_D

  • Atari ST
  • ***
  • Posts: 151
  • Karma: 29
    • View Profile
Re: [PROCEDURAL] glsl_plasma
« Reply #14 on: May 02, 2008 »
I think that may be an incorrect assumption. Can you try this program and tell me if it works ok? It also uses gl_FragCoord. Thanks! :)

http://www.mediafire.com/download.php?6rwxmwonj3d
The Dr. is INsane!!!

Offline Rbz

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 2757
  • Karma: 493
    • View Profile
    • https://www.rbraz.com/
Re: [PROCEDURAL] glsl_plasma
« Reply #15 on: May 02, 2008 »
I hate ATI   ;D , your glsl plasma works fine here - Nvidia 6600GT
Challenge Trophies Won:

Offline Dr_D

  • Atari ST
  • ***
  • Posts: 151
  • Karma: 29
    • View Profile
Re: [PROCEDURAL] glsl_plasma
« Reply #16 on: May 03, 2008 »
Well, I've added one that will hopefully be more compatible with ATI cards. It's in my first post. :)
The Dr. is INsane!!!

Offline Deleter

  • C= 64
  • **
  • Posts: 73
  • Karma: 11
    • View Profile
    • Deleter's Rants
Re: [PROCEDURAL] glsl_plasma
« Reply #17 on: May 03, 2008 »
now I get a shaderlog info message, something about it failing to compile something...cant read as it goes away too fast and for some reason I cannot take a screenshot

Offline Dr_D

  • Atari ST
  • ***
  • Posts: 151
  • Karma: 29
    • View Profile
Re: [PROCEDURAL] glsl_plasma
« Reply #18 on: May 03, 2008 »
Deleter, can you compile this and see if it leaves the message up longer? Thanks.


Code: [Select]
'GLSL demo by Dr_D 4/27/08
'Note: these structures are nowhere near complete.
#include "gl/gl.bi"
#include "gl/glu.bi"
#include "gl/glext.bi"
#include "fbgfx.bi"

type DisplayMode
    W       as uinteger
    H       as uinteger
    BPP     as uinteger
    D_BITS  as uinteger
    S_BITS  as uinteger
    MODE    as uinteger
    GlVer   as zstring ptr
    FOV     as single
    Aspect  as single
    zNear   as single
    zFar    as single
end type


declare sub Set_Ortho( byref Display as DisplayMode )
declare sub Drop_Ortho( byref Display as DisplayMode )
declare function Load_Texture( byref Texture as Gluint, byref Filename as string ) as integer
declare sub Open_GL_Window( byval W as integer, byval H as integer, byval BPP as integer, byval Num_buffers as integer, byval Num_Samples as integer, byval Fullscreen as integer )
declare sub Gather_Extensions()
declare function Init_Shader( File_Name as string, Shader_Type as integer )as GlHandleARB


'framebuffer
common shared _framebuffer_                    as integer
common shared glGenFramebuffersEXT             as PFNglGenFramebuffersEXTPROC
common shared glDeleteFramebuffersEXT          as PFNglDeleteFramebuffersEXTPROC
common shared glBindFramebufferEXT             as PFNglBindFramebufferEXTPROC
common shared glFramebufferTexture2DEXT        as PFNglFramebufferTexture2DEXTPROC
common shared glFramebufferRenderbufferEXT     as PFNglFramebufferRenderbufferEXTPROC
common shared glGenRenderbuffersEXT            as PFNglGenRenderbuffersEXTPROC
common shared glBindRenderbufferEXT            as PFNglBindRenderbufferEXTPROC
common shared glRenderbufferStorageEXT         as PFNglRenderbufferStorageEXTPROC

'multitexture
common shared _multitexture_                    as integer
common shared maxTexelUnits                     as Gluint
common shared glMultiTexCoord2fARB              as PFNglMultiTexCoord2fARBPROC
common shared glActiveTextureARB                as PFNGlActiveTextureARBPROC
common shared glClientActiveTextureARB          as PFNglClientActiveTextureARBPROC
common shared glGenerateMipmapEXT               as PFNglGenerateMipmapEXTPROC

'shaders
common shared _shader100_                      as integer
common shared glCreateShaderObjectARB          as PFNglCreateShaderObjectARBPROC
common shared glShaderSourceARB                as PFNglShaderSourceARBPROC
common shared glGetShaderSourceARB             as PFNglGetShaderSourceARBPROC
common shared glCompileShaderARB               as PFNglCompileShaderARBPROC
common shared glDeleteObjectARB                as PFNglDeleteObjectARBPROC
common shared glCreateProgramObjectARB         as PFNglCreateProgramObjectARBPROC
common shared glAttachObjectARB                as PFNglAttachObjectARBPROC
common shared glUseProgramObjectARB            as PFNglUseProgramObjectARBPROC
common shared glLinkProgramARB                 as PFNglLinkProgramARBPROC
common shared glValidateProgramARB             as PFNglValidateProgramARBPROC
common shared glGetObjectParameterivARB        as PFNglGetObjectParameterivARBPROC
common shared glGetInfoLogARB                  as PFNglGetInfoLogARBPROC
common shared glGetUniformLocationARB          as PFNglGetUniformLocationARBPROC
common shared glUniform1iARB                   as PFNglUniform1iARBPROC
common shared glUniform2ivARB                   as PFNglUniform2ivARBPROC
common shared glUniform1fARB                   as PFNglUniform1fARBPROC
common shared glUniform2fvARB                  as PFNglUniform2fvARBPROC
common shared glUniform3fvARB                  as PFNglUniform3fvARBPROC


dim shared as DisplayMode Display
dim shared as integer errlog
dim as Gluint Quad, Shader_Compile_Success
dim as GlHandleARB Vertex_Shader, Fragment_Shader, Shader_Program
dim as single sTime
dim as GlInt TimerLoc
dim as integer use_shader = 1

errlog = freefile
Open_GL_Window( 640, 480, 32, 1, 0, 0 )
WindowTitle("GLSL Plasma By Dr_D")
open cons for output as #errlog
Gather_Extensions()

if _shader100_ <> 0 then
   
    Vertex_Shader = Init_Shader( "Shaders/plasma.vert", GL_VERTEX_SHADER_ARB )
    Fragment_Shader = Init_Shader( "Shaders/plasma.frag", GL_FRAGMENT_SHADER_ARB )
    Shader_Program = GlCreateProgramObjectARB()
    glAttachObjectARB( Shader_Program, Vertex_Shader )
    glAttachObjectARB( Shader_Program, Fragment_Shader )
    glLinkProgramARB( Shader_Program )
   
    GlValidateProgramARB( Shader_Program )
    glGetObjectParameterivARB( Shader_Program, GL_OBJECT_VALIDATE_STATUS_ARB, @Shader_Compile_Success )
   
    if Shader_Compile_Success = 0 then
        print #errlog, "ARGHHHH!!!! GLSL program failed to compile."
        sleep 5000, 1
        close #errlog
        end
    end if
   
    'This gets the memory location of variable("name"), so that we can send data to the gpu at the correct address.
    TimerLoc  = glGetUniformLocationARB( Shader_Program, strptr("sTime") )
    print #errlog, "Location of Timer variable in shader:" & TimerLoc 
else   
    print #errlog, "OpenGL Shader Language is not supported on this card."
    print #errlog, "This demo will not work as expected."
    sleep 5000,1
end if

Quad = GlGenLists(1)
GlNewList( Quad, GL_COMPILE )
    glbegin( GL_QUADS )
        GlVertex2F( Display.W,0 )
        GlVertex2F( Display.W,Display.H )
        GlVertex2F( 0,Display.H )
        GlVertex2F( 0,0 )
    glend()
GlEndList()

if GlIsList( Quad ) = GL_FALSE then
    print #errlog, "Display list got borked somehow."
    sleep 5000, 1
    close #errlog
    end
end if


glmatrixmode( GL_MODELVIEW )
glloadidentity()
Set_Ortho( Display )

do 
   
    sTime = timer
   
    if _shader100_ then
        if use_shader then
            glUseProgramObjectARB( Shader_Program )
            glUniform1fARB( TimerLoc,  sTime )
        else
            glUseProgramObjectARB( 0 )
        end if
    end if
   
    GlCallList( Quad )
   
    flip
loop until multikey(FB.SC_ESCAPE)

Drop_Ortho( Display )
gldeletelists( Quad, 1 )

if _shader100_ then
    GlDeleteObjectArb( Vertex_Shader )
    GlDeleteObjectArb( Fragment_Shader )
    GlDeleteObjectArb( Shader_Program )
end if
print #errlog, "Exit was okay! :)"
close #errlog



sub Gather_Extensions()
   
    dim extensions as string
    ScreenControl FB.GET_GL_EXTENSIONS, extensions
   
    if (instr(extensions, "GL_EXT_framebuffer_object") <> 0) then
        print #errlog, "GL_EXT_framebuffer_object is supported"
        _framebuffer_ = 1
        glGenFramebuffersEXT            = ScreenGLProc("glGenFramebuffersEXT")
        glDeleteFramebuffersEXT         = ScreenGLProc("glDeleteFramebuffersEXT")
        glBindFramebufferEXT            = ScreenGLProc("glBindFramebufferEXT")
        glFramebufferTexture2DEXT       = ScreenGLProc("glFramebufferTexture2DEXT")       
        glFramebufferRenderbufferEXT    = ScreenGLProc("glFramebufferRenderbufferEXT")
        glGenRenderbuffersEXT           = ScreenGLProc("glGenRenderbuffersEXT")
        glBindRenderbufferEXT           = ScreenGLProc("glBindRenderbufferEXT")
        glRenderbufferStorageEXT        = ScreenGLProc("glRenderbufferStorageEXT")
    else
        print #errlog, "GL_EXT_framebuffer_object is NOT supported"
    end if
   
   
    if (instr(extensions, "GL_ARB_multitexture") <> 0) then
        print #errlog, "GL_ARB_multitexture is supported"
        _multitexture_ = 1
        glMultiTexCoord2fARB            = ScreenGLProc("glMultiTexCoord2fARB")
        glActiveTextureARB              = ScreenGLProc("glActiveTextureARB")
        glClientActiveTextureARB        = ScreenGLProc("glClientActiveTextureARB")
        glGetIntegerv(GL_MAX_TEXTURE_UNITS_ARB, @maxTexelUnits)
    else
        print #errlog, "GL_ARB_multitexture is NOT supported"
    end if
   
   
    if (instr(extensions, "GL_ARB_shading_language_100") <> 0) then
        print #errlog, "GL_ARB_shading_language_100 is supported"
        _shader100_ = 1
        glCreateShaderObjectARB     = ScreenGLProc("glCreateShaderObjectARB")
        glShaderSourceARB           = ScreenGLProc("glShaderSourceARB")
        glGetShaderSourceARB        = ScreenGLProc("glGetShaderSourceARB")
        glCompileShaderARB          = ScreenGLProc("glCompileShaderARB")
        glDeleteObjectARB           = ScreenGLProc("glDeleteObjectARB")
        glCreateProgramObjectARB    = ScreenGLProc("glCreateProgramObjectARB")
        glAttachObjectARB           = ScreenGLProc("glAttachObjectARB")
        glUseProgramObjectARB       = ScreenGLProc("glUseProgramObjectARB")
        glLinkProgramARB            = ScreenGLProc("glLinkProgramARB")
        glValidateProgramARB        = ScreenGLProc("glValidateProgramARB")
        glGetInfoLogARB             = ScreenGLProc("glGetInfoLogARB")
        glGetObjectParameterivARB   = ScreenGLProc("glGetObjectParameterivARB")
        glGetUniformLocationARB     = ScreenGLProc("glGetUniformLocationARB")
        glUniform1iARB              = ScreenGLProc("glUniform1iARB")
        glUniform2ivARB              = ScreenGLProc("glUniform2ivARB")
        glUniform1fARB              = ScreenGLProc("glUniform1fARB")
        glUniform2fvARB             = ScreenGLProc("glUniform2fvARB")
        glUniform3fvARB             = ScreenGLProc("glUniform3fvARB")
    else
        print #errlog, "GL_ARB_shading_language_100 is NOT supported"
    end if
   
    print #errlog, " "
end sub

sub Set_Ortho( byref Display as DisplayMode )
    glmatrixmode( Gl_Projection )
    glpushmatrix
    glloadidentity
    glmatrixmode( Gl_Modelview )
    glpushmatrix
    glloadidentity
    GlOrtho( 0, Display.W, 0, Display.H, -1, 1 )
end sub

sub Drop_Ortho( byref Display as DisplayMode )
    glmatrixmode( Gl_Projection )
    glpopmatrix
    glmatrixmode( Gl_Modelview )
    glpopmatrix
end sub



sub Open_GL_Window( byval W as integer, byval H as integer, byval BPP as integer, byval Num_buffers as integer, byval Num_Samples as integer, byval Fullscreen as integer )
    dim Flags as integer = FB.GFX_OPENGL
    if FullScreen then
        Flags or = FB.GFX_FULLSCREEN
    end if
    ScreenControl FB.SET_GL_COLOR_BITS, BPP
    ScreenControl FB.SET_GL_DEPTH_BITS, 24
    if Num_Samples>0 then
        ScreenControl FB.SET_GL_NUM_SAMPLES, Num_Samples
        Flags or = FB.GFX_MULTISAMPLE
    end if
    screenres W, H, BPP, Num_Buffers, Flags
   
    glViewport( 0, 0, W, H )
    glmatrixmode( GL_PROJECTION )
    glloadidentity()
    Display.W = W
    Display.H = H
    Display.BPP = BPP
    Display.FOV = 45.0
    Display.Aspect = W/H
    Display.znear = 1
    Display.zfar = 100
    gluPerspective( Display.FOV, Display.Aspect, Display.zNear, Display.zFar )
   
    glShadeModel( GL_SMOOTH )
    glClearColor( 0.0, 0.0, 0.0, 1.0 )
    glClearDepth( 1.0 )
    glenable( GL_DEPTH_TEST )
    glDepthFunc( GL_LEQUAL )
    glenable( GL_COLOR_MATERIAL )
   
    glHint( GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST )
    glPolygonMode( GL_FRONT_AND_BACK, GL_FILL )
    glenable( GL_CULL_FACE )
    glmatrixmode( GL_MODELVIEW )
end sub


function Init_Shader( File_Name as string, Shader_Type as integer )as GlHandleARB
    dim as integer i
    dim as integer Line_Cnt
    dim as string Shader_Text, tString
    dim as Gluint Shader_Compile_Success
    dim as GlHandleARB Shader
    dim as uinteger FileNum = freefile
   
    open File_Name for binary as #FileNum
    do while not eof(FileNum)
        line input #FileNum, tString
        Shader_Text += tString + chr( 13, 10 )
    loop
    close #FileNum
   
    dim as GLcharARB ptr table(0) => { strptr( Shader_Text ) }
    Shader = glCreateShaderObjectARB( Shader_Type )
    glShaderSourceARB( Shader, 1, @table(0), 0 )
    glCompileShaderARB( Shader )
   
    glGetObjectParameterivARB( Shader, GL_OBJECT_COMPILE_STATUS_ARB, @Shader_Compile_Success )
    if Shader_Compile_Success = 0 then
        dim as Gluint infologsize
        glGetObjectParameterivARB( Shader, GL_OBJECT_INFO_LOG_LENGTH_ARB, @infoLogSize)
        dim as GlByte infolog(InfoLogSize)
        glGetInfoLogARB( Shader, InfoLogSize, 0, @infoLog(0))
        tString=""
        for i = 0 to InfoLogSize-1
            tString+=chr(InfoLog(i))
        next
        print #errlog, "Shader Infolog error message:"
        print #errlog, tString
        sleep 5000,1
        return 0
    else
        return Shader
    end if
end function
The Dr. is INsane!!!

Offline hellfire

  • Sponsor
  • Pentium
  • *******
  • Posts: 1294
  • Karma: 466
    • View Profile
    • my stuff
Re: [PROCEDURAL] glsl_plasma
« Reply #19 on: May 08, 2008 »
ATI's shader-compiler reports an invalid cast in the vertex-shader (which is correct since gl_Vertex is vec4 while coord is vec3) - Nvidia doesn't bother about it.
Fixing plasma.vert makes the shader compile without errors but still produces a black screen only (and after a while displaying some constant memory-garbage).
Seems like the fragment-program runs in cpu-emulation.

Edited your fragment-program to a minimum:
Code: [Select]
void main(void) {
    gl_FragColor = vec4(1,1,1,1);
}
...now the black screen shows some white "garbage".
However, it doesn't seem to fall back to cpu.

Do you *ever* clear the zbuffer?
So, that's where the black screen comes from...

The cpu-fallback is most probably because your fragment-program is too long.
My radeon just features shadermodel 2.0 while the geforce runs 3.0 (which allows way longer code).
Keep in mind that every sin/cos is effectively replaced by some taylor-approximation which just blows the code-size.

Edit:
As I was on it, I pasted your code into my C++ framework and fixed the shader (see attachment) - hope you don't mind :)
All I did is "overloading" the sin() & cos() functions with a texture lookup:
Code: [Select]
uniform sampler1D sinLookup;
uniform float time;
varying vec4 coord;
float PI= 3.1415926535897932384626433832795;

float sin(float x) {
  return texture1D(sinLookup, x/(PI*2.0)).a*2.0-1.0;
}

float cos(float x) {
  return texture1D(sinLookup, x/(PI*2.0)+0.25).a*2.0-1.0;
}

void main(void) {
    vec4 Color1 = vec4(0.0);
    float t = time;
    float x = coord.x;
    float y = coord.y;
    Color1.r = (0.5 + 0.49 * cos(t+x / (128.0 + 32.0 * cos(y / 64.0+t))) * cos(y / (320.0 + 16.0 * sin(x / 64.0 ))));
    Color1.g = (0.5 - 0.49 * cos(x*2 / (96.0 + 16.0 * cos(y*2.0 / (256.0+t)))) * cos(y / (64.0 + 16.0  * sin(x / 64.0 + t))));
    Color1.b = (0.5 - 0.49 * sin(y / (128.0 + 8.0 * cos(x / (96.0 + t)))) * cos(x / (64.0 + 32.0  * sin(y / 512.0 )) ));
    gl_FragColor = Color1;
}

The texture is set up like this:
Code: [Select]
   unsigned char data[1024];
   for (i=0;i<1024;i++)
   data[i]= (int) (sin(i*PI/512.0)*127.5+127.5f);
   glTexImage1D(GL_TEXTURE_1D, 0, GL_ALPHA, 1024, 0, GL_ALPHA, GL_UNSIGNED_BYTE, data);

Hope I didn't mess up anything...
« Last Edit: May 08, 2008 by hellfire »
Challenge Trophies Won: