It's just a quick test with the VehicleMultiBody and the UserHeightFieldCollision.
No idea if this demo running good with ati card.
http://evadlevarg.googlepages.com/Basic ... hicle2.zip
This is really beta...
Moderator: Alain
procedure TOXNewtonUserHeightField.PrepareShaderVert;
begin
with FShaderVertStr do begin
Clear;
Add('attribute vec3 s_attribute_0;');
Add('attribute vec4 s_attribute_1;');
Add('attribute vec4 gl_Vertex;');
Add('uniform vec3 camera;');
Add('uniform vec4 lods;');
Add('varying vec3 lightDir,normal;');
Add('void main()');
Add('{');
Add(' float dist = length(camera-s_attribute_0);');
Add(' gl_Vertex = vec4(s_attribute_0,1.0);');
Add(' if(dist>lods.w){');
Add(' gl_Vertex.y = s_attribute_1.w;');
Add(' }else');
Add(' if(dist>lods.z){');
Add(' float k = (dist-lods.z)/(lods.w-lods.z);');
Add(' gl_Vertex.y = s_attribute_0.z*(1.0-k)+s_attribute_1.w*k;');
Add(' }else');
Add(' if(dist>lods.y){');
Add(' float k = (dist-lods.y)/(lods.z-lods.y);');
Add(' gl_Vertex.y = s_attribute_0.y*(1.0-k)+s_attribute_1.z*k;');
Add(' }else');
Add(' if(dist>lods.x){');
Add(' float k = (dist-lods.x)/(lods.y-lods.x);');
Add(' gl_Vertex.y = s_attribute_0.x*(1.0-k)+s_attribute_1.y*k;');
Add(' }else{');
Add(' float k = clamp((dist/lods.x)*2.0-1.0,0.0,1.0);');
Add(' gl_Vertex.y = s_attribute_0.y*(1.0-k)+s_attribute_1.x*k;');
Add(' }');
Add(' gl_Position = gl_ModelViewProjectionMatrix*gl_Vertex;');
//Add(' gl_Position = ftransform();');
Add(' gl_TexCoord[0] = gl_MultiTexCoord0;');
Add('}');
end;
end;
procedure TOXNewtonUserHeightField.PrepareShaderFrag;
begin
with FShaderFragStr do begin
Clear;
Add('uniform sampler2D tex1;');
Add('uniform sampler2D tex2;');
Add('uniform sampler2D tex3;');
Add('uniform sampler2D tex4;');
Add('uniform float SplatScale = 40.0f;');
Add('varying vec3 lightDir,normal;');
Add('void main()');
Add('{');
Add(' vec4 final;');
Add(' vec4 a1 = texture2D(tex1,gl_TexCoord[0].st);');
Add(' vec4 a2 = texture2D(tex2,gl_TexCoord[0].st);');
Add(' vec4 a3 = texture2D(tex3,gl_TexCoord[0].st);');
Add(' vec4 a4 = texture2D(tex4,gl_TexCoord[0].st);');
Add(' vec4 color1 = texture2D(tex1,gl_TexCoord[0].st*SplatScale);');
Add(' vec4 color2 = texture2D(tex2,gl_TexCoord[0].st*SplatScale);');
Add(' vec4 color3 = texture2D(tex3,gl_TexCoord[0].st*SplatScale);');
Add(' vec4 color4 = texture2D(tex4,gl_TexCoord[0].st*SplatScale);');
Add(' final.r = (color1.r*a1.a)+(color2.r*a2.a)+(color3.r*a3.a)+(color4.r*a4.a);');
Add(' final.g = (color1.g*a1.a)+(color2.g*a2.a)+(color3.g*a3.a)+(color4.g*a4.a);');
Add(' final.b = (color1.b*a1.a)+(color2.b*a2.a)+(color3.b*a3.a)+(color4.b*a4.a);');
Add(' final.a = 1.0;');
Add(' vec4 texel;');
Add(' float intensity,at,af;');
Add(' lightDir = normalize(vec3(gl_LightSource[0].position));');
Add(' intensity = max(dot(lightDir,normalize(normal)),1.0);');
Add(' texel = texture2D(tex1,gl_TexCoord[0].st);');
Add(' vec4 ffcol1;');
Add(' ffcol1 = vec4(vec3(texel.rgb)*vec3(intensity*(gl_FrontMaterial.diffuse).rgb+');
Add(' gl_FrontMaterial.ambient.rgb),float(texel.a*gl_FrontMaterial.diffuse.a));');
Add(' gl_FragColor = vec4(final * ffcol1);');
Add('}');
end;
end;
And it is apply like this.
with FTerrainGLSL do begin
UseProgramObject;
Uniform1i['tex1']:=0; ApplyMultiTex(0);
Uniform1i['tex2']:=1; ApplyMultiTex(1);
Uniform1i['tex3']:=2; ApplyMultiTex(2);
Uniform1i['tex4']:=3; ApplyMultiTex(3);
Uniform1f['SplatScale']:=128;
Uniform3f['camera']:=AbsoluteToLocal(Scene.CurrentGLCamera.AbsoluteAffinePosition);
Uniform4f['lods']:=VectorMake(5000,5000,5000,5000);
glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER,FVBOIndices);
glDrawRangeElements(GL_TRIANGLES,0,FIndiceCount,FIndiceCount,GL_UNSIGNED_INT,nil);
UnApplyMultiTex;
EndUseProgramObject;
end;
Users browsing this forum: No registered users and 20 guests