- Home /
How to Modify Standard Surface Shader's SpecCube?
Unity's Standard Surface Shader reflection style doesn't give the visual result I want, and I'd like to be able to modify it before it's displayed. But, the convenience of surface shaders, notably the blurring of said reflections by the Smoothness float, is incredible. So, is there a method to access Unity_SpecCube0 as, say, a fixed4, and edit its colors and values before reassigning it? Alternatively, how can I dynamically blur a cubemap in the same manner as the Smoothness float? (Or preferably, do modify it with Smoothness) I'm not opposed to having to write a vertex/fragment shader to manage it all, but I'd just like to know if there's an immensely easier means of achieving either of those within an existing surface shader before I start down that road. Either method would work, although the first would of course be the best. Any help or advice is appreciated, hopefully I don't sound too novice.
And if I posted this incorrectly, or in the wrong place, please forgive me.
Answer by Namey5 · Jan 09, 2019 at 05:49 AM
The way the reflection probe blurring works is by accessing different mip levels of the reflection probe's cubemap based on the surface's roughness. If you wanted to blur a cubemap in the same way (although it won't be quite as high quality due to the custom mip filtering that Unity pre-generates for their probes).
The way you would implement this in a surface shader would be accessing the reflection cubemap like normal, but with a slightly different sampling function;
//Where _Cube is the reflection cubemap and _MaxBlurLevel is a value from 0-10 (0 being no blur, 10 being essentially a flat colour).
half4 refl = texCUBElod (_Cube, float4 (IN.worldRefl, lerp (_MaxBlurLevel, 0.0, _Smoothness)));
Keep in mind that you may need to enable mip-map generation for the cubemap beforehand.
Thank you! It works fantastically, and the blur quality you mentioned is easily achieved by setting the cubemap's Convolution Type to "Specular". It works beautifully, exactly what I wanted. I may still face a headache in implementing reflection probe data into the cubemap slot of the shader (or maybe not, fingers crossed), but this is already perfect for static objects. That's a big mystery out of the way, thank you very much.
Small note: I found even a _$$anonymous$$axBlurLevel value of 4 is flat enough, and makes the transition between glossy and blurred much more even.
Your answer
Follow this Question
Related Questions
Z value shader 1 Answer
Surface shader ParallaxOffset issue 1 Answer
uv array and surface shader? 0 Answers
reflective glass shader 3 Answers
How to I get a reflection on the floor and on other objects ? 0 Answers