Hi,
We’ve been having a few issues with getting the standard shader to show similar results in WebGL as on other platforms.
The main problem is that materials appear way too shiny, and that adjacent triangles are sometimes shown with different smoothness, without a smooth transition.
Triangles also change their smoothness too much in response to changed viewing angles.
While investigating these issues, I’ve experimented with the shader sources and found some of the causes and have tried to remedy them. I would appreciate cmments from Unity regarding these issues, and if they are actively being improved or if our best bet for the future is to keep modifying the standard shader:
First of all, eyeVec is only normalized per vertex. I know this is done for performance reasons on SM2, but WebGL is mainly run on computers that can handle per pixel normalization.
When changing this, smoothness of the surface is much more predictable, both in response to viewing angle, and also between triangles that share edges.
After adjusting eyeVec, surfaces are still too smooth in comparison with other platforms, and there is still a small difference in smoothness between adjacent surfaces in certain viewing angles.
Both these issues have to do with texCUBElod() not being supported on SM2 / WebGL.
I dont know exactly how texCUBEbias works, but I’m guessing that the bias depends on whatever lod is automatically calculated for a given pixel?
Anyway, the lod chosen by the bias function does not correspond to what texCUBElod gives, and surfaces are therefore smoother in WebGL.
I changed the macro that uses texCUBEbias to use lod * 1.3 instead of lod * 1, and we are seeing more similar results.
This feels like a big hack however, and also seems to depend a bit on aniso level of reflection cubemaps.
Any and all ideas about better ways to get higher quality on blurry reflections would be appreciated!
Last of all, transparent materials are not looking the same on WebGL.
This one was easy, the alpha of a semi-transparent pixel is calculated in a much simpler way on SM2.
But the same as before applies here, WebGL is run on computers, and we found no issues using the more expensive calculations targeted at SM3.
So, basically we have a working shader right now that gives acceptable quality. But we would really like to know if any of the proposed changes will make it into the standard shader (or other better solutions).
We will probably use WebGL a lot in the coming year, and we are not comfortable with having to keep separate modified versions of the standard shader for each project, remembering to keep to keep it in sync with the official sources.