So,
nachdem ganzen shader gelaber hab ich mir gedacht ich fang halt mal mit an.
Damit ich das ganze raff, erstma Vertex Programme.
Hab mein kleines 3D gerüst (www.radical3d.de) welches PerPixel Lighting mit Diffusem Bumpmapping und Stencil Shadow Volumes realisiert umgebaut auf Vertex Shader.
Besser gesagt, ich bin noch dabei und es gibt da auch schon probleme:
Das Vertex Program für den Diffusen Bump Pass steht:
Code: !!ARBvp1.0 OPTION ARB_position_invariant; # Diffuse Vertex Program # ********************** # Attribute: # 0 = Licht Position # 1 = Normal # 2 = Tangent # 3 = BiNormal # Konstanten PARAM cLightPos = program.local[1]; # Attribute ATTRIB iNormal = vertex.attrib[1]; ATTRIB iTangent = vertex.attrib[2]; ATTRIB iBiNormal = vertex.attrib[3]; OUTPUT oTexcoord0 = result.texcoord[0]; OUTPUT oTexcoord1 = result.texcoord[1]; # Temporäre Variablen TEMP lightvec, outlight; # Licht Vektor berechnen SUB lightvec, cLightPos, vertex.position; DP3 outlight.x, lightvec, iBiNormal; DP3 outlight.y, lightvec, iTangent; DP3 outlight.z, lightvec, iNormal; # Farbwerte variieren MOV result.color, vertex.color; # Texturkoordinaten weitergeben MOV oTexcoord0, vertex.texcoord[0]; MOV oTexcoord1, outlight; END
Nun wollte ich den ganz primitiven pass für Light Attenuation auch in nen Vertex Shader packen, aber:
Das ganze sieht so im normalen OpenGL aus:
Rendern für ein Vertex:
Code: procedure TR3DLight.processLightIntensityVertex(const _Vertex : TR3DVector); //var // texCoords : TR3DVector; // versuborig : TR3DVector; begin // Texture Koordinaten berechnen für Lightmap //versuborig := r3d_VectorSub(_Vertex, Position); //texCoords := r3d_VectorDiv(versuborig, Radius * 2.0); //texCoords.Add(0.5); //glMultiTexCoord2fARB(GL_TEXTURE0_ARB, texCoords.x, texCoords.y); //glMultiTexCoord2fARB(GL_TEXTURE1_ARB, texCoords.z, 0.5); glVertex3fv(@_Vertex); end;
Das was ausgeklammert ist, will ich in dem Light Intesity Vertex Shader einbauen welches noch so aussieht:
Code: !!ARBvp1.0 OPTION ARB_position_invariant; # Light Intensity Vertex Program # ****************************** # Lokale: # 0 = Licht Position # 1 = Radius # Konstanten PARAM cHalf = { 0.5 }; PARAM cLightPos = program.local[1]; PARAM cLightRadius = program.local[2]; OUTPUT oTexcoord0 = result.texcoord[0]; OUTPUT oTexcoord1 = result.texcoord[1]; # Temporäre Variablen TEMP vpsub, texcoords; # Light Attenuation berechnen SUB vpsub, vertex.position, cLightPos; # texcoords = vpsub / Radius * 2 ADD texcoords, texcoords, cHalf; # Texturkoordinaten weitergeben #MOV oTexcoord0.s, texcoords.x; #MOV oTexcoord0.t, texcoords.y; #MOV oTexcoord1.s, texcoords.z; #MOV oTexcoord1.t, cHalf; # Farbwerte variieren MOV result.color, vertex.color; END
Nun kommen aber die probs, sobald ich das so starte, bekomm ich erstmal fehler im vertex program.
MOV oTexcoord0.s, texcoords.x; MOV oTexcoord0.t, texcoords.y; MOV oTexcoord1.s, texcoords.z; MOV oTexcoord1.t, cHalf;
das gefällt ihm schon nicht, ich muss aber die texcoordinaten so binden:
glMultiTexCoord2fARB(GL_TEXTURE0_ARB, texCoords.x, texCoords.y);
glMultiTexCoord2fARB(GL_TEXTURE1_ARB, texCoords.z, 0.5);
und noch dazu hab ich mal kein plan wie ich:
texcoords = vpsub / Radius * 2
als Vertex Program Operationen machen soll, es gibt ja kein Befehl für einfaches Dividieren oder irr ich mich ?
Hat wer ne ahnung wie ich das am besten lösen kann ?
Thx im voraus,
Final
|