Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implicit compile-type casting not working #27

Open
philip-peterson opened this issue Apr 14, 2013 · 1 comment
Open

Implicit compile-type casting not working #27

philip-peterson opened this issue Apr 14, 2013 · 1 comment

Comments

@philip-peterson
Copy link

Consider the following code from a surface shader:

float bar() {
    return tex2D(_PermTexture, float2(.5f, .5f));
}

float foo(float baz) {
    float2 mycoord = float2(baz, .2);
    return mycoord.x;
}

void surf (Input IN, inout EditorSurfaceOutput o) {
    o.Normal = float3(0.0,0.0,1.0);
    o.Alpha = 1.0;
    o.Albedo = 0.0;
    o.Emission = 0.0;
    o.Gloss = 0.0;
    o.Specular = 0.0;
    o.Custom = 0.0;

    o.Albedo = foo(bar());
    o.Normal = normalize(o.Normal);
}

The function float bar() is declared to return a single float value. The expression after return is the result of a call to tex2D, which is a float3, but since the function's signature is of type float, the first channel should be implicitly selected and used as the output, i.e. line 2 should effectively have a .x inserted before the semicolon by the compiler.

However, when we try to construct a float2 using baz and another float (line 6), the compiler/translator sees that baz "returned a float3" (line 2) and decides that a float3 and another float is "too much data". It is, in essence ignoring the fact that foo returns a float AND the fact that the dummy variable baz is declared to be of type float (line 5), and instead is looking solely at the code body (line 2) to determine a datatype.

There is no way, however that "baz" will end up being any more than a float at runtime. So there is no way (line 6) can be providing too much information to the float2 constructor at runtime. Yet, the compiler dies with the message "too much data in type constructor" at line 6.

@aras-p
Copy link
Owner

aras-p commented Apr 14, 2013

Since you're talking about surface shaders, that sounds like it's something Unity specific. You're sure the error is caused by hlsl2glsl, and not by any of the other ten-or-so shader compilers that Unity uses? (might be Cg, HLSL, HLSL360, CgPS3 etc.)

Do you have full shader that causes the problem?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants