Dark Bit Factory & Gravity
GENERAL => Challenges & Competitions => Topic started by: Dr_D 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.
-
Yepper, black screen for me too. Vista, nVidia 5700.
It's a nice black screen though, and it exits without any errors. ::)
-
hehehe... i win! :boxer:
-
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.
-
nice colourful plasma :cheers:
-
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
-
Very sweet plasma. Good entry. I like it!
-
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!
-
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.
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.
-
I really wondered how a plasma will look in pixel shaders. Now I see it :)
-
does not works here :( openwindow (white n frozen) n showing console with this info:
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:
---------------------------
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
---------------------------
-
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.
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?)
-
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.
-
possible only ATI will know this ^^
-
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
-
I hate ATI ;D , your glsl plasma works fine here - Nvidia 6600GT
-
Well, I've added one that will hopefully be more compatible with ATI cards. It's in my first post. :)
-
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
-
Deleter, can you compile this and see if it leaves the message up longer? Thanks.
'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
-
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:
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:
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:
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...
-
Error 0:7: 'assign' : cannot convert from 'attribute 4-component vector of float' to 'varying 3-component of float'
edit: seems as if he's already figured out whats up with it ;)
-
So it works for you now? Man, I really wish there was a standard. That seems so counter productive for one brand of card to support some of the funcions, and another brand to fallback on software. Especially that casting error. I wish they would at least make a standard for the type structures. You know what I mean? That's part of the language itself, which should be constant. Also, the documentation could use some work because according to the book i've been reading, it doesn't say anything about not using the built in trig functions, or the use of them bloating it. :\
-
You're probably interessted in some of these (http://3dshaders.com/home/index.php?option=com_weblinks&catid=13&Itemid=33).
ShaderModel 2 is not very far from 1.1 (very limited instruction-set) except of higher precision and longer programs.
All what GLSL does is translating your commands to the available instruction-set - unluckily most of the things it does is hidden from the user...
-
Hmm. Well, yes, I have the books from that list that were recommended to me. I didn't read anywhere suggesting not to use native trig functions or glFragCoord... which seems ridiculous to me, in the first place. If that's the case, then ATI has serious issues and is going to fail, eventually. What's next? Don't use RGBA because it falls back on software? Don't use swizzling? Don't use any of the native noise functions? That's silly. It's ok... just forget about it. I did my research, so if it doesn't compile and run properly using functions that are supposed to be part of the standard, it isn't my fault. Thanks for the advice, but I'm going to stick with what's in the books. ;)
-
The link refered to that "GLSL Validate"-Tool which checks your source for standard-compliance, so your shader won't contain "errors" your driver just doesn't tell you about.
In this case you shouldn't blame ATI - although they did (and still do) have some ridiculous bugs in their drivers (especially on the OpenGL-side), like that fragcoord-thing for example (which seems to be fixed for a while already) - however, your fragment program probably (haven't tried) would't work on ps2.0-based nvidia-cards either.
Usually ATI goes the more compatible way, giving better precision, less surprises (and bigger code) while Nvidia "optimizes" your code pretty optimistically (which can fail pretty badly, too).
I just wish that the glsl-compiler would give some more feedback about that (instead of just falling back to emulation) or shows the produced assembler-code (what Direct3D does for example)...
-
Thanks Hellfire for making a compatible version of this so that finally I am able to run it. For all the effort that you put into sorting this out it deserves some good karma, especially as you're helping a fellow competitor in the competition out.
Very sporting of you.
Thank you!
-
...
For all the effort that you put into sorting this out it deserves some good karma,
especially as you're helping a fellow competitor in the competition out.
Very sporting of you.
Thank you!
I 100% second that!
K UP!
-
I also had problems running your demo. I have a ATI Radion Xpress 1100. The second lens demo worked fine though.
I was able to do a screen grab of my error message seconds before it exited.