View Single Post
Old 10-30-06, 02:15 PM   #6
oc2k1
Registered User
 
Join Date: Aug 2006
Posts: 38
Default Re: Shadereditor experiment

Some source:
http://cpux.de/opengl.qsa7.tar.bz2

For recompiling use "qmake && make" the sorce depends to QT-3.3.x, QSA-1.1.x and Glew. Don't use QT4.x with QSA-1.2.x that doesn' work.
Start the program via shell "./gl" to see the GLSLcompiler warnings and errors.

Known Bugs:
All objects should have different names, because they are used by scripts. That's not checked jet. Rename objects using F2.
Testobjectscript: Only sphere is working.
OBJ importer: LWO name is wrong. Many OBJ files use multiple Indexstreams but that's incompatible to VBOs.
Don't close the cam.

A Simple Test:

Make a leftklick on the Wold and add a "node".
Add via Nodes contexmenu: Vertexshader, Fragmentshader, Script and a Texture
Texture : Load media/2kEarth_comp.jpg via contextmenu
Klick on the Node to select it, than run plugins/test_object.js from "Scripts" menu and say create.

Script:
Code:
shader = gl.Shader(Vertexshader,Fragmentshader); 
shader.Uniformi("Tex0",0); 
 
function render(){ 
   Texture.Bind(0); 
   shader.Bind(); 
 
   Sphere.UvCoords.Bind(); 
   Sphere.Tangent.Bind(shader.Loc("Tangent")); 
   Sphere.Vertex.Bind(); 
   Sphere.Normal.Bind(); 
  
   Sphere.Index.Draw(gl.QUADS); 
 
   Sphere.Normal.Unbind(); 
   Sphere.UvCoords.Unbind(); 
   Sphere.Tangent.Unbind(); 
   Sphere.Vertex.Unbind(); 
 
   shader.Unbind(); 
   }
Vertexshader:
Code:
varying vec3 T,B,N; 
attribute vec3 Tangent; 
varying vec3 col; 
void main(void){ 
    gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;   
    gl_TexCoord[0] = gl_MultiTexCoord0 * vec4(1,.5,1,1) + vec4(0.35,0,0,0);  
    N = gl_Normal; 
    T = Tangent; 
    B = cross (T,N); 
    }
Fragmentshader:
Code:
uniform sampler2D Tex0; 
varying vec3 T,B,N; 
vec3 lvec= vec3(0.707,0,0.707); 
void main(void){ 
     vec3 nmap = -1 + 2* texture2D(Tex0, vec2(gl_TexCoord[0])); 
     nmap = normalize(vec3(dot(T,nmap),dot(B,nmap), dot(N,nmap))); 
     float l = dot(nmap,lvec); 
     l += 1 * pow(max(dot(reflect (lvec,nmap),vec3(0,0,-1)), 0),4); 
     gl_FragColor =l * texture2D(Tex0, vec2(gl_TexCoord[0])+vec2(0,.5)); 
     }
Then selelct "Run Script" from Scriptcontextmenu. You should see the dot3 bumpmapped earth.

Last edited by oc2k1; 10-30-06 at 06:27 PM.
oc2k1 is offline   Reply With Quote