Hey again everyone.
I’m once again tinkering around with and dabbling in shaders and ran into something mainly for webplayer and OpenGLES2 shaders…
A few shaders i want to re-implement simply use too many temporary libraries to be straight-away compatible for webplayer or OpenGL ES2 usage.
I find it really hard to trace back concrete info if it comes to multipassing a shader to maybe overcome certain limitations.
One of the shaders i want to re-implement employs a threefold normal textures (So height, diff and normal to be specific), but i want to add a CubeMap and AmbOcc map in a seperate pass (throwing it all in one would require too many texture interpolators), The AmbOcc map should be possible to keep seperate for me, as it’s input will be adjusted seperately.
Is it possible to handle a shader multi-pass as if it behaves as follows:
Shader will make a first pass, writing some values to o.Normal, o.Albedo and o.Gloss and one float-value
Second pass will be able to adjust excisting Albedo and Gloss channel, and read into the float values generated during the first pass. Basically allowing this pass to be used mostly for any calculations i want to do to o.Emission (and possibly edit the o.Albedo from the earlier pass?)
Or would i still need as many texture interpolators as would be needed for the two seperate passes combined?
This is only for a very specific shader which won’t be employed many times, but will be specific in it’s function.
Performance testing will still have to come after, but i first want to find out if it’s at-all possible in this way
As far as I know, the only way you can do this is using a texture. Something along these lines should work:
In your first pass, do what you’re doing now, but also add your float as o.Alpha
Use GrabPass
In your next pass, you have the final color stored as _GrabTexture.rgb and your float as _GrabTexture.a
Note that the color you get is AFTER the lighting is done, so you’ll probably want to use a regular vertex/fragment shader for the second pass, so its not lighted twice.
So if i understand correctly, GrabPass can also only grab your complete result of the shader pass? You can’t omit the lighting pass from this?
In this case the float would be used to pass on from the first pass as an inversion of the gloss channel with some minor adjustments, that resulting value will be multiplied with my cubemap reflection. The data of that float may not be manipulated further then the first pass does by itself.
Yes… Think of each pass as a black box that produces the final color from input. You can’t access anything from the outside, except the final result using GrabPass. That means you can only encode four values.
As I said, if you don’t wish to include lighting in any of the passes, don’t use surface shaders.
Perhaps there is an easier way to do this… mind sharing the source?
Don’t use GrabPass with OpenGL ES*; use GrabPass in your second SubShader so you can see something in the Editor, but just read the color buffer value directly on the GLES device.
Hmm… that’s interesting, concerning the GrabPass though; wouldn’t it be possible to retrieve an UNLIT grabpass so i can use that in my surface shader instead?