Thanks.
It looks like I got a very similar code, because i just copied it from the sample, so that does not help me a lot, the problem is something else i'm missing.
this is the vertex shader:
Code: Select all
float4 main(
float3 position,
float3 normal,
float2 texcoord,
uniform float4x4 u_mvp_matrix,
out float3 out_position : TEXCOORD2,
out float3 out_normal: TEXCOORD1,
out float2 out_texcoord: TEXCOORD0) : POSITION
{
out_position = position;
out_texcoord = texcoord;
out_normal = normal;
return mul(u_mvp_matrix, float4(position, 1.0f));
}
I assume this works well because the 3D model looks perfect, so the vertex position is being exported.
Then the fragment shader:
Code: Select all
struct phong_material {
float3 ambient;
float3 diffuse;
float3 specular;
float shininess;
};
struct light {
float3 position;
float3 color;
};
uniform float4x4 u_modelview_matrix;
uniform float3x3 u_normal_matrix;
uniform phong_material u_material;
uniform light u_light;
float3 phong_lighting(float3 normal, float3 L, float3 position)
{
/* Ambient */
float3 ambient = u_material.ambient;
/* Diffuse */
float3 diffuse = max(0.0f, dot(L, normal)) * (u_material.diffuse);
/* Specular */
float3 R = reflect(-L, normal);
float3 V = normalize(-position);
float specular_component = pow(max(0.0f, dot(R, V)), u_material.shininess);
float3 specular = specular_component * (u_material.specular);
return (ambient + diffuse + specular) * (u_light.color);
}
void main(
float2 texcoord : TEXCOORD0,
float3 normal : TEXCOORD1,
float3 position : TEXCOORD2,
uniform sampler2D u_texture : TEXUNIT0,
out float4 out_color : COLOR)
{
float3 position_eyespace = mul(u_modelview_matrix, float4(position, 1.0f)).xyz;
float3 L = normalize(u_light.position - position_eyespace);
float3 normal_eyespace = normalize(mul(u_normal_matrix, normal));
float4 texcolor = tex2D(u_texture, texcoord);
out_color = float4(phong_lighting(normal_eyespace, L, position_eyespace), 1.0f) * texcolor;
}
It just shows a black model, If i change the code to export "texcolor" to COLOR, the psvita will show the textured model without the light, so the texture part is working.
All the uniforms are declared in main code, and the vita is not crashing (it will crash a lot when editing the shaders
).