I am trying to make a custom surface shader which uses reflection probes, but I am having difficulty. I found this thread. I am trying to accomplish the same thing but in a surface shader. Ive gotten close but the result is very blurry except when the camera is zoomed in very close.
here’s a code snippet.
You’re doing everything correctly, the only thin you could do is increase reflection probe resolution. Default resolution is quite small, IIRC 128x128 for each cubemap face.
Try increasing reflection probe resolution. That can be done on reflection probe (if you’ve placed it in the scene), or on lighting tab → skybox related settings.
Also, you’re writing surface shader. Surface shaders are supposed to integrate with unity’s PBR, so it is possible that blurred reflection is added on top of your reflection by unity - because unity DOES add blurred reflections to pretty much everything. You can get clean reflections if you write pure vertex/fragment shader.
Lighting kind of functions are supposed to be used to integrate your object with custom lighting system - custom attentuation and such. If I were you I’d try to first plug reflection into emissive channel of surface shader, paint albedo black and see if that works. That’s kinda a hack, but might produce good results.
Also, if you just wanted reflective object, use standard shader, set smoothness to 1, try bringing up “metallic” parameter to 1 too.
The probe is already at 1024 resolution. The strange thing is if you look closely at the screenshot the reflection becomes clearer when the camera is nearer.
I tried this in a fragment shader as well but the reflection is still blurry (at least on my machine)
and the fragment shader is the same one from your thread back in april, which is hella weird because there was a screenshot in that thread showing it working normally
Interesting. And you’re absolutely sure that material uses correct shader too?
Here’s the thing though. Accessing reflection probe is not officially documented (well, I never got an answer from unity on the subject), and the shader I posted back in aprel ran on different version of unity, and on windows 7 system.
Also, from what I remember, there was another specCube variable, and that one was unity_SpecCube, unity_SpecCube1_HDR and they refered to second cubemap. So perhaps your shader ended up being compiled differently or due to changes in the engine that older appraoch no longer works.
Either way.
It really looks like you simply want a normal reflective sphere, without fancy effects.
Are you sure you want to mess with custom shaders for that?
Setting metallic to 1 and smoothness to 1 should produce perfect mirror.
First.
You shouldn’t be trying to perform reflections within Lighting* (LightingReflect) functions. Those functions are for processing inidividual lights, and they’re not fit for dealing with enviornmental reflections. If the model is hit with multiple lihgts, you’ll get overbrightening. See this aritcle for info: Unity - Manual: Custom Lighting models in Surface Shaders
Second.
I experimented a bit, and apparently unity will rapidly reduce resolution of the cubemap if you’re using a shader with custom lighting model - as you’re doing in your case.
For example:
Apparently it is some sort of optimization technique. Also, it is possible that that cubemap doesn’t contain actual image from the probe, but some optimized cubemap solely for making specular highlights, or something like that.
However, I don’t really understand why you WANT to write you own reflective shader in the first place.
The simplest way to get a mirror surface is to set Metallic and Smoothness to 1.0.
interesting… so your saying a custom lightmodel with reflections is not possible?
I don’t want to use standard shader, because I want a “realish” look, not totally real. I’m of the opinion that PBR takes out a good deal of “artistic license” in rendering, so to speak. Don’t get me wrong PBR looks great I just want something that leaves more room for artistic interpretation, if that makes sense
It is possible, however you can’t grab reflection cubemap from lightprobe.
If you provide your own cubemap, you could plug that into your shader.
Legacy shaders emulate reflections, but can’t grab those reflection cubemaps from light probes.
You won’t look totally real unless you spend A LOT of time, money and effort on art.
There’s not much room for artistic interpretation in mirror ball.
You want mirror ball, there’s simple way to get it with standard model. Why bother with shader? You gain nothing and waste a lot of time.
The point of PBR is that you have less parameters to tinker with and get decent results in both indoors and outdoors quickly.
True. The point of this is not to create a mirrorball, the mirror is just a component I can use to render glossy metals or glass or eyes or other reflective surfaces. In the pre refleciton probe days I had a custom metal shader which used cubemap that I would pre generate using a camera and script, but now that we have reflection probes I find the idea of not having to generate each one quite attractive.
maybe I’m being retarded and PBR would do fine, I still want to try this though…
By this do you mean the old method I just described? I was thinking I could continue doing that if necessary, but the probes are so cool and I’d love to be able to use them
You’ll probably want to write pure vertex/pixel shader for that.
Before that you were writing surface shhader, and that one is expected to interact with PBR lighting, so there’s less control and restrictions on what you can do with that.
Sorta. More than one way to go about it, the only problem is that you don’t get data from reflection probe automatically.
Just download unity shader source, study one of the reflective legacy shaders.
If you want data from the probe, then Metallic = 1/Smoothness = 1 material is the best way to go, as far as I can tell.