Simple HLSL question

Jo0oker

21-02-2011 14:56:17

Hello,

i tried to use a simple HLSL Shader in a Material:


//Einfache Kollorierung eines Objetes

//Vertexsahder Ausgabe
struct VS_OUTPUT
{
float4 Position : POSITION;
float4 Diffuse : COLOR0;
float2 TextureUV : TEXCOORD0;
}

VS_OUTPUT RenderColor_vp(float4 vPos : POSITION,
uniform float4x4 cWorldViewProj)
{
VS_OUTPUT Output = (VS_OUTPUT)0;

Output.Position = mul(vPos, uWorldViewProj);
Output.Diffuse = float4(1, 0, 0, 1);

return Output;
}

float4 RenderColor_fp(VS_OUTPUT VertexInput)
{
return VertexInput.Diffuse;
}

And here the Material


vertex_program Color/VP hlsl
{
source Color.hlsl
entry_point RenderColor_vp
target vs_2_0
}

fragment_program Color/FP hlsl
{
source Color.hlsl
entry_point RenderColor_fp
target ps_2_0
}

material SimpleColor
{
technique
{
pass
{

// Vertex program reference
vertex_program_ref Color/VP
{
param_named_auto cWorldViewProj worldviewproj_matrix
}

// Fragment program
fragment_program_ref Color/FP
{

}
}
}
}


But if i set the material to an object, it is still white.

Does any one a failure?

Greats,
Jo0oker

smiley80

21-02-2011 15:10:28

There's a semicolon missing after the struct declaration:
struct VS_OUTPUT
{
float4 Position : POSITION;
float4 Diffuse : COLOR0;
float2 TextureUV : TEXCOORD0;
};


and the semantic for 'RenderColor_fp' is missing:
float4 RenderColor_fp(VS_OUTPUT VertexInput) : COLOR0
{
return VertexInput.Diffuse;
}

Jo0oker

21-02-2011 15:47:01

At first, thank you for your fast reply.

Ok, i changed it to:

struct VS_OUTPUT
{
float4 Position : POSITION;
float4 Diffuse : COLOR0;
float2 TextureUV : TEXCOORD0;
};

VS_OUTPUT RenderColor_vp(uniform float4x4 uWorldViewProj)
{
VS_OUTPUT Output = (VS_OUTPUT)0;

float4 newPosition = float4(1, 0, -40, 0);

Output.Position = mul(newPosition, uWorldViewProj);
Output.Diffuse = float4(1, 0, 0, 1);

return Output;
}

float4 RenderColor_fp(VS_OUTPUT VertexInput) : COLOR0
{
return VertexInput.Diffuse;
}


But now the Object is still transparent.

Hm, i am a liite pbit confused.

P.S.: In the Ogre.log is no error.

EDIT:
When i only use this:

float4 TestRenderColor_fp() : COLOR0
{
float4 newColor = float4(0.7, 1, 0, 1);
return newColor;
}


it works perfect.

Greats,
Jo0oker

smiley80

21-02-2011 16:00:38

You're setting all vertices to the same position: 'newPosition * uWorldViewProj'

Jo0oker

21-02-2011 16:08:46

Ok, wen i change it back to:


//Einfache Kollorierung eines Objetes

//Vertexsahder Ausgabe
struct VS_OUTPUT
{
float4 Position : POSITION;
float4 Diffuse : COLOR0;
float2 TextureUV : TEXCOORD0;
};

VS_OUTPUT RenderColor_vp(
float4 vPos : POSITION,
uniform float4x4 uWorldViewProj)
{
VS_OUTPUT Output = (VS_OUTPUT)0;

Output.Position = mul(vPos, uWorldViewProj);
Output.Diffuse = float4(1, 0, 0, 1);

return Output;
}

float4 RenderColor_fp(VS_OUTPUT VertexInput) : COLOR0
{
return VertexInput.Diffuse;
}


Than it looks like:


Greats,
Jo0oker

smiley80

21-02-2011 22:41:40

In the material, 'cWorldViewProj' should be 'uWorldViewProj':
vertex_program_ref Color/VP
{
param_named_auto uWorldViewProj worldviewproj_matrix
}

Jo0oker

21-02-2011 23:53:15

I changed that, without posting it here, that isn't the failure.

Jo0oker

22-02-2011 00:24:34

Ok, i solved my Problem, now it works:

struct VS_OUTPUT
{
float4 Position : POSITION;
float4 Diffuse : COLOR0;
float2 TextureUV : TEXCOORD0;
};

VS_OUTPUT RenderColor_vp(
float4 vPos : POSITION,
float2 vTexCoord : TEXCOORD0,
uniform float4x4 uWorldViewProj)
{
VS_OUTPUT cOut = (VS_OUTPUT)0;

cOut.Position = mul(uWorldViewProj, vPos);
cOut.Diffuse = float4(1, 0, 0, 1);
return cOut;
}

float4 RenderColor_fp(VS_OUTPUT VertexInput) : COLOR0
{
return VertexInput.Diffuse;
}


Thank you, that helped my understanding much more of writing shaders.
My next Alpha-Blending-Shader is ready and i wrote it on my own :)

Greets,
Jo0oker