- Home /
Errors with ENDCG in shaders
I am not new to unity but i have very VERY little experience with the shaders in unity and this question probably has a simple answer. i am trying to have two skyboxes blend together as time passes and to do this i need to connect a day cycle code's "timeOfDay" variable with the "_Blend" property in the shader. my problem is that i need to place code into the shader and by looking at examples im pretty sure you need to start the code with "CGPROGAM" and end it with "ENDCG" but whenever i place "ENDCG" it gives me the error Parse error: Syntax error, unexpected "}" but whenever i remove whatever the error is it gives me another one, either attacking another bracket or attacking the fallback.
Shader "Custom/SkyboxFading" {
Properties
{
_Tint ("Tint Color", Color) = (.5, .5, .5, .5)
_Tint1 ("Tint Color one", Color) = (.5, .5, .5, .5)
_Tint2 ("Tint Color two", Color) = (.5, .5, .5, .5)
_Blend ("Blend", Range(0.0, 1.0)) = 0.5
_Skybox1 ("Skybox one", Cube) = ""
_Skybox2 ("Skybox two", Cube) = ""
}
SubShader
{
Tags { "Queue" = "Background" }
Cull Off
Fog { Mode Off }
Lighting Off
Color [_Tint]
Pass
{
SetTexture [_Skybox1] { combine texture }
SetTexture [_Skybox2] { constantColor (0,0,0,[_Blend]) combine texture lerp(constant) previous }
SetTexture [_Skybox2] { combine previous +- primary, previous * primary }
}
CGPROGRAM
ENDCG
}
Fallback "Custom/Skybox", 1
}
this is whats causing the problem. i have no code in between the CG's but it was causing the problem even when the code was there.
Answer by Bunny83 · Nov 09, 2017 at 11:32 PM
Uhm, just remove the CGPROGRAM and ENDCG when you don't have any cg code.
In addition +-
is no longer supported since Unity version 5+. While for certain things the legacy texture combiners might be enough, it's generally recommended to actually write a cg shader instead.
none of those things are the problem. yes i could just remove the CGPROGRA$$anonymous$$ and ENDCG but then i cannot place code into the shader which was the original point of this. i've tried to edit _Blend outside of the shader but its not possible without CG code. and if it is possible i would love to know.
Sorry but this comment is very confusing. Your shader uses the Fixed function pipeline of the shader hardware since you use SetTexture.
If you actually want to use a fragment shader you can't use SetTexture. Though if you want to use the fixed function pipeline you can't use a CG fragment shader. It's two different approaches to the same thing. The fixed function pipeline can not be programmed but only configured. So it's quite limited. Nowadays the fixed function pipeline usually isn't used anymore.
It's still not clear what you actually want to do. What do you mean by "i've tried to edit _Blend outside of the shader"
When i copy your shader into my project, remove the CG part and replace the "+-" by a simple "*" the shader works as expected. I can manipulate the _Blend slider in my skybox material and it correctly blends between the two cubemaps.
that is very strange because when i replace the "+-" with a "*" the shader doesn't work properly yet when i keep the "+-" it works fine, anyway that isnt the problem here. let me try to explain this better. my goal is to make the skybox fade between the two set skyboxes as time of day changes. the skybox fading itself works fine as the "_blend" slider works fine. my problem is that i want the _blend to be affected by a C# code but when i use
skyboxFading = new $$anonymous$$aterial(Resources.Load("$$anonymous$$aterials/SunBox") as $$anonymous$$aterial);
skyboxFading.SetFloat("_Blend", currentTime / 24);
it doesnt change the skybox. I have to be doing something wrong here.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
[Solved] False "variable not assigned" error 3 Answers
How do I get objects to render against the skybox? 2 Answers
worldPos in shader giving errors when game is paused 0 Answers
Shader / Compute Shader in Unity 1 Answer