Various HLSL Compiler Errors

Started by
1 comment, last by huaner 17 years, 5 months ago
I write a shder .But it can't run.And the wrong that is hint by complier is it can't find "out". Also,I can't find where is wrong.The code id below: matrix matWorldViewProj; matrix matWorld; vector vecLightDir; struct VS_OUT { float4 position : POSITION; float3 light : TEXCOORD0; float3 normal : TEXCOORD1; }; VS_OUT VS(float4 pos : POSITION, float3 norm : NORMAL) { VS_OUT out = (VS_OUT)0; out.position = mul(pos, matWorldViewProj); out.normal = normalize(mul(norm, matWorld)); out.light = normalize(vecLightDir); return out; } float4 PS(float3 light : TEXCOORD0, float3 normal : TEXCOORD1) : COLOR { float4 diffuse = {1.0f, 0.0f, 0.0f, 1.0f}; float4 ambient = {0.1f, 0.0f, 0.0f, 1.0f}; return ambient + diffuse * saturate(dot(light, normal)); } thanks [Edited by - jollyjeffers on November 16, 2006 8:43:31 AM]
Advertisement
It fails because 'out' is a reserved word in HLSL. Change it to any other name, and it will magically work.

HLSL uses 'in', 'out', and 'inout' to specify how function parameters are passed. Parameters marked 'in' (default) and 'inout' are passed by value when the function starts. Parameters marked 'out' and 'inout' are returned by value when the function exits.

xyzzy

First, thank for your reply!
You are right!But It doesn't run also. The wrong is : Read of uninitialized
component(*)in r1: r/0 g/1 b/2 * a/3.Why?the shader is also the same before
matrix matWorldViewProj;
matrix matWorld;
vector vecLightDir;

struct VS_OUT
{
float4 position : POSITION;
float3 light : TEXCOORD0;
float3 normal : TEXCOORD1;
};

VS_OUT VS(float4 pos : POSITION, float3 norm : NORMAL)
{
VS_OUT outVS = (VS_OUT)0;
outVS.position = mul(pos, matWorldViewProj);
outVS.normal = normalize(mul(norm, matWorld));
outVS.light = normalize(vecLightDir);

return outVS;
}

float4 PS(float3 light : TEXCOORD0, float3 normal : TEXCOORD1) : COLOR
{
float4 diffuse = {1.0f, 0.0f, 0.0f, 1.0f};
float4 ambient = {0.1f, 0.0f, 0.0f, 1.0f};

return ambient + diffuse * saturate(dot(light, normal));
}
3Q!

This topic is closed to new replies.

Advertisement