hey guys, thanks so far, i've been working with it, and have come up with decent results, but their's still clearly something wrong.
first off, let me post my shader code currently:
Vertex for encoding images:
#version 150
uniform mat4 ProjMatrix;
uniform mat4 ViewMatrix;
uniform mat4 MeshMatrix;
in vec3 i_Vertex;
in vec2 i_TexCoord;
in vec3 i_Normal;
out vec2 o_TexCoord;
out vec3 o_Normal;
out vec4 o_Vertex;
void main(void){
mat3 NormalMatrix = transpose(inverse(mat3(MeshMatrix)));
o_Vertex = MeshMatrix*vec4(i_Vertex, 1.0f);
o_TexCoord = i_TexCoord;
o_Normal = normalize(NormalMatrix*i_Normal);
gl_Position = ProjMatrix*ViewMatrix*o_Vertex;
return;
}
pixel for encoding the images:
#version 150
uniform sampler2D Texture;
uniform vec4 g_Color;
in vec2 o_TexCoord;
in vec3 o_Normal;
in vec4 o_Vertex;
out vec4 o_ColorBuffer;
out vec4 o_NormalBuffer;
out vec4 o_PosBuffer;
void main(void){
o_ColorBuffer = g_Color*texture2D(Texture, o_TexCoord);
if(o_ColorBuffer.a<=0.0f) discard;
o_ColorBuffer.rgb *= o_ColorBuffer.a;
o_NormalBuffer = vec4((o_Normal+1.0f)*0.5f, 1.0f);
o_PosBuffer = vec4((normalize(o_Vertex.xyz)+1.0f)*0.5f, length(o_Vertex.xyz));
}
and here is the shader's for drawing/doing lighting:
Vertex shader:
#version 150
uniform mat4 ProjMatrix;
uniform mat4 ViewMatrix;
uniform mat4 MeshMatrix;
in vec3 i_Vertex;
in vec2 i_TexCoord;
out vec2 o_TexCoord;
void main(void){
gl_Position = ProjMatrix*ViewMatrix*MeshMatrix*vec4(i_Vertex,1.0f);
o_TexCoord = i_TexCoord;
return;
}
pixel shader:
#version 150
#extension GL_EXT_gpu_shader4: enable
uniform sampler2D TextureColorMap;
uniform sampler2D TextureNormalMap;
uniform sampler2D TextureHeightMap;
uniform mat4 ViewMatrix;
uniform mat4 MeshMatrix;
uniform vec4 g_Color;
uniform int i_LightCount;
uniform samplerBuffer i_LightBuffer;
in vec2 o_TexCoord;
out vec4 o_Color;
void main(void){
vec4 Texel = texture2D(TextureColorMap, o_TexCoord);
if(Texel.a<=0.1f) discard;
o_Color = vec4(0.1f, 0.1f, 0.1f, 1.0f)*g_Color*Texel;
mat4 ViewModel = ViewMatrix;
mat3 NormMatrix= transpose(inverse(mat3(ViewModel)));
vec4 o_NormMap = texture2D(TextureNormalMap, o_TexCoord);
vec4 o_HeightMap = texture2D(TextureHeightMap, o_TexCoord);
vec3 o_Normal = NormMatrix*(o_NormMap.rgb*2.0f-1.0f);
vec4 o_Vertex = ViewModel*vec4((o_HeightMap.rgb*2.0f-1.0f)*20.0f*(o_HeightMap.a),1.0f); //the 20.0 is scaling for the sprite which has a radius of 20.
for(int i=0;i<i_LightCount*3;){
vec4 Light_Pos = texelFetchBuffer(i_LightBuffer, i++);
vec4 Light_Dif = texelFetchBuffer(i_LightBuffer, i++);
vec4 Light_Aten= texelFetchBuffer(i_LightBuffer, i++);
vec3 Aux = Light_Pos.xyz-o_Vertex.xyz;
float NdotL = max(dot(o_Normal, normalize(Aux)), 0.0f);
float D = length(Aux);
float Att = 1.0f/(Light_Aten.x+Light_Aten.y*D+Light_Aten.z*D*D);
o_Color+=Att*(Light_Dif*NdotL);
}
o_Color.rgb*=o_Color.a;
}
here are the current results:
using a sphere works perfectly(although it is the simplist example to use.):
Color Map:
Normal Map:
Height Map:
Results:
A:
B:
here is an irregular shaped home that i tried encoding, as you can see, it doesn't follow the light correctly:
Color Map:
Normal Map:
Height Map:
and this is the weird results:
The green dot is the light's center.
@Clickalot, i'm attempting to keep it all within model space, but i can't seem to translate it correctly in drawing.
i'll take a look at your alternative depth approach, thanks=-).
i feel i'm close, hopefully only a bit more.