Yeah, Mark it's glUniformIArb(blah) with the sampler object.
Discovered it the old fashioned way.(Looked at someone elses code :) )
-
Joah, I know what you mean about not knowing why shaders fail to compile(I hate the generate lack of debug info too) but glsl does have shader and program logs(English) that can be 'got'. No idea the kind of information they return though.
Here's a new version of shaderGen, for anyone interested. It now generates lights as well as blend modes/color scale.
example vert shader,
Discovered it the old fashioned way.(Looked at someone elses code :) )
-
Joah, I know what you mean about not knowing why shaders fail to compile(I hate the generate lack of debug info too) but glsl does have shader and program logs(English) that can be 'got'. No idea the kind of information they return though.
Here's a new version of shaderGen, for anyone interested. It now generates lights as well as blend modes/color scale.
Type ShaderGen Method NewShader(name:String) Local vertFile:String = name+"Vert.glsl" Local pixFile:String = name+"Pix.glsl" vfile=WriteFile(vertfile) pfile=WriteFile(pixfile) useLights=0 End Method Method GenLights() useLights=True End Method Method addTexture( blendMode,coordset,colorscale) texblend[texnum]=blendmode texset[texnum]=coordset texcscale[texnum]=colorscale texnum:+1 useTextures=1 End Method Method genPPLights() useppLights=True End Method Method Generate() If useTextures For Local j=1 To TexNum WriteLine vfile,"varying vec2 texCoord"+j+";" Next EndIf writeHeader(vfile) If uselights ' Rem WriteLine vfile,"vec3 normal,viewVector,halfVector;" WriteLine vfile,"vec3 lightDir;" WriteLine vfile,"vec4 diffuse, ambient, globalAmbient, specular = vec4(0.0);" WriteLine vfile,"float ndotl,ndothv;" WriteLine vfile,"" WriteLine vfile,"normal = normalize( gl_NormalMatrix * gl_Normal );" WriteLine vfile,"" ' Rem For Local j=1 To lcount WriteLine vfile,"lightDir = normalize( vec3( gl_LightSource["+(j-1)+"].position));" WriteLine vfile,"ndotl = max( dot(normal,lightDir),0.0);" WriteLine vfile,"diffuse=diffuse+gl_FrontMaterial.diffuse * gl_LightSource["+(j-1)+"].diffuse;" WriteLine vfile,"ambient=ambient+gl_FrontMaterial.ambient * gl_LightSource["+(j-1)+"].ambient;" WriteLine vfile,"globalAmbient=globalAmbient+gl_LightModel.ambient * gl_FrontMaterial.ambient;" WriteLine vfile,"" WriteLine vfile,"if(ndotl>0.0){" WriteLine vfile,"ndothv = max(dot(normal,normalize(gl_LightSource["+(j-1)+"].halfVector.xyz)),0.0);" WriteLine vfile,"specular=specular+ gl_FrontMaterial.specular * gl_LightSource["+(j-1)+"].specular * pow(ndothv,gl_FrontMaterial.shininess);" WriteLine vfile,"}" WriteLine vfile,"" Next 'End Rem WriteLine vfile,"gl_FrontColor = globalAmbient + ndotl * diffuse + ambient + specular;" EndIf WriteLine vfile,"gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;" 'writeVertexTForm() If useTextures For Local j=1 To texNum WriteLine vfile,"texCoord"+j+"= vec2(gl_MultiTexCoord"+(j-1)+");" Next EndIf writeEnd(vfile) Local pixOut:String = "" If useTextures Local prePad:String Local postPad:String For Local j=1 To TexNum WriteLine pfile,"varying vec2 texCoord"+j+";" WriteLine pfile,"uniform sampler2D cTexture"+j+";" prePad="" postPad="" If j>1 Select texblend[j-1] Case T_Normal pixOut="" Case T_ADD pixOut=pixOut+"+" Case T_Modulated pixOut=pixOut+"*" Case T_Subtract pixOut=pixOut+"-" Default Throw "Undefined texture blending mode." End Select EndIf Select texcScale[j-1] Case 1 'optimized. leaner. the real mcdaddy baddy. Default prePad="(" postPad="*"+texcScale[j-1]+")" End Select pixOut=pixOut+prePad+"texture2D(cTexture"+j+",texCoord"+texset[J-1]+")"+postPad Next pixOut=pixOut+";" EndIf writeHeader(pfile) If useLights For Local j=1 To lcount Next End If WriteLine pfile,"gl_FragColor = gl_Color +"+pixout+";" writeend(pfile) CloseFile vfile CloseFile pfile End Method Method writeVertexTForm() WriteLine vfile,"gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;" End Method Method writeHeader(file) WriteLine file,"void main()" WriteLine file,"{" End Method Method writeEnd(file) WriteLine file,"}" End Method Method addlight() lcount:+1 uselights=True End Method Method reset() uselights=0 usetextures=0 usepplights=0 texnum=0 lcount=0 End Method Field lcount Field useLights,useTextures Field usePPLights,texNum Field vfile,pfile,texcscale:Int[32] Field texBlend:Int[32],texSet:Int[32] Field dred!,dgreen!,dblue! Field sred!,sgreen!,sblue! End Type
example vert shader,
varying vec2 texCoord1; void main() { vec3 normal,viewVector,halfVector; vec3 lightDir; vec4 diffuse, ambient, globalAmbient, specular = vec4(0.0); float ndotl,ndothv; normal = normalize( gl_NormalMatrix * gl_Normal ); lightDir = normalize( vec3( gl_LightSource[0].position)); ndotl = max( dot(normal,lightDir),0.0); diffuse=diffuse+gl_FrontMaterial.diffuse * gl_LightSource[0].diffuse; ambient=ambient+gl_FrontMaterial.ambient * gl_LightSource[0].ambient; globalAmbient=globalAmbient+gl_LightModel.ambient * gl_FrontMaterial.ambient; if(ndotl>0.0){ ndothv = max(dot(normal,normalize(gl_LightSource[0].halfVector.xyz)),0.0); specular=specular+ gl_FrontMaterial.specular * gl_LightSource[0].specular * pow(ndothv,gl_FrontMaterial.shininess); } lightDir = normalize( vec3( gl_LightSource[1].position)); ndotl = max( dot(normal,lightDir),0.0); diffuse=diffuse+gl_FrontMaterial.diffuse * gl_LightSource[1].diffuse; ambient=ambient+gl_FrontMaterial.ambient * gl_LightSource[1].ambient; globalAmbient=globalAmbient+gl_LightModel.ambient * gl_FrontMaterial.ambient; if(ndotl>0.0){ ndothv = max(dot(normal,normalize(gl_LightSource[1].halfVector.xyz)),0.0); specular=specular+ gl_FrontMaterial.specular * gl_LightSource[1].specular * pow(ndothv,gl_FrontMaterial.shininess); } gl_FrontColor = globalAmbient + ndotl * diffuse + ambient + specular; gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; texCoord1= vec2(gl_MultiTexCoord0); }