- Home /
Reflection and Specular Highlights: how to turn on/off? help pls!
hello world
what is the property to enable/disable Reflections and Specular Highlights (Standard Shader)?
_SpecularHighlights and _GlossyReflections are both "Float" but they are toggles (checkboxes) in the GUI
I want to control them via a checkbox but I don't know how, please help!
Sharder language don`t have boolean type, try set value to 0
I tried that, nothing happens
shapes.GetComponent<Renderer> ().material.SetFloat("_SpecularHighlights", 0);
looking at the source code of the Standard Shader I saw this:
Shader "Standard" {
Properties {
....
[ToggleOff] _SpecularHighlights ("Specular Highlights", Float) = 1.000000
[ToggleOff] _GlossyReflections ("Glossy Reflections", Float) = 1.000000
....
}
}
but I don't know how to access those properties via script...
I´ll try to explain it better:
I want a GUI checkbox for the user to be able to switch Specular Highlights On/Off while the project is running
this change should affect all GameObjects that use the same material
sorry, Arkins, but I don't see how your solution might work
I already managed to control other shader properties, like _Gloss$$anonymous$$apScale using:
shapes.GetComponent<Renderer> ().material.SetFloat ("_Gloss$$anonymous$$apScale", sldfind.value);
but the same approach is not working for _SpecularHighlights or _GlossyReflections
After a analyze of the shader code, i can say Specular Highlights are a shader_feature, and can not be changed at runtime, you can create 2 different material one with it enabled and other with disable and switch the render material when you want enable or disable it.
Answer by kbr0n · Sep 21, 2016 at 12:14 PM
Finally! I manage to get this working using keywords and setfloat
like this:
to turn ON:
shapes.GetComponent().material.DisableKeyword("_SPECULARHIGHLIGHTS_OFF");
shapes.GetComponent().material.SetFloat("_SpecularHighlights",1f);
to turn OFF:
shapes.GetComponent().material.EnableKeyword("_SPECULARHIGHLIGHTS_OFF");
shapes.GetComponent().material.SetFloat("_SpecularHighlights",0f);
it's tricky cause there's no "_specularhighlights_on", instead you disable or enable "_specularhightlights_off"
aí @sergio7888 - tem jeito sim, fião. cc @Arkins_prod_studio
Works for me! I experimented around with this and even setFloat("_SpecularHighlights, x); isn't necessary. Having just the enable and disable keyword works.
Thank you for this! This works for me as well (just enabling and disabling the keyword). This also worked with "_GLOSSYREFLECTIONS_OFF" as well, though they didn't always update properly in the inspector. (2017.3)
thisRenderer.material.Enable$$anonymous$$eyword("_SPECULARHIGHLIGHTS_OFF");
thisRenderer.material.Enable$$anonymous$$eyword("_GLOSSYREFLECTIONS_OFF");
Answer by Arkins_prod_studio · Sep 16, 2016 at 12:39 PM
you can create a new matherial with this prefab: i think it can work :)
maybe I don't understand what you are suggesting but
user must have the ability to switch Specular Highs ON/OFF while the project is running
and I really want to know how to control those properties, so just switching materials wouldn't do the trick
i aying its a shader_feature, shader feature are only compiled if selected, diferent from multicompile or standard shader options it cant be changed at runtime. and if you have 2 mateils with the same config, switch will resolve your problem, it can be a toggle but the property is not used in the shader code.
Answer by Haze-Games · Sep 20, 2017 at 08:59 AM
Hello there, Just to say thanks for sharing as this helped me today :)
Just a quick note: Unity doesn't update the state of the checkboxes; so even after editing those keywords, it'll still show checked / unchecked checkbox states regardless of the new value of keywords. But from now on you can ignore those checkboxes if you're changing it through script.
Even after restarting the project, checkboxes are not refreshed correctly, but new keywords set are saved so all works well ;)
Thanks, Charles
Your answer
Follow this Question
Related Questions
Put toggle label on left side of button and hover 1 Answer
UI Toggle Component Broken? 0 Answers
Gui Toggle help 2 Answers
Is there a way of using just basic gui.Buttons as toggles? 1 Answer
Toggle Switch 6 Answers