MirrorReflection.shader in V2.0

i have a strange problem with the GREAT “MirrorReflection.shader” written by Aras Pranckevicius (wiki link : http://www.unifycommunity.com/wiki/index.php?title=MirrorReflection)

This is an very helpfull shader BUT it don’t work on Windows since Unity V2.0 :frowning: (in fact it seems don’t work with directX, b’cause it was OK with Unity 1.6.2 -OpenGl)

Any idea Aras ? :roll:
Thanks to the UnityTeam for 2.0 :smile:

The public gets what the public wants!

Mirror Reflection for Unity 2.0

It has several bonuses over 1.x version: works in scene view and with multiple cameras, does not require vertex shaders, the mirror can have a texture, and the mirror can be arbitrarily scaled.

WhooAaa ! [public is happy]…

You are the best 8)
Many thanks Aras :!:

Many thanks, your work is awesome as usual :wink:

I just setup the Mirror reflection shader and its super cool. I have a couple of problems though:

  1. Doesn’t work with Orthographic cameras
  2. I want to use a black texture for my reflective surface (a la Leopards Cover flow style) but the reflection is almost invisible
  3. The reflective layer seems to lose the nice effect of the pixel lights in the scene, which makes it look a little dull - is there a way to just “add” the reflections to an existing material?

Thanks
Shaun

Maybe, I didn’t try. Will take a look.

The shader multiplies texture with the reflection (combine texture * previous). You can change that to add (combine texture + previous), add signed (combine previous ± texture) and so on, whatever you like.

I did not try, but I think what could work is:

  1. setup the mirror renderer to use two materials (change array size in mesh renderer),
  2. set first material to use regular material you want,
  3. set second material to use mirror shader,
  4. change shader to do additive blending, something like (untested):
Shader "FX/Mirror Reflection Additive" { 
Properties {
    _Color("Color", Color) = (1,1,1,1)
    _ReflectionTex ("Reflection", 2D) = "white" { TexGen ObjectLinear }
}
Subshader { 
    Blend One One
    ZWrite Off
    Pass {
        SetTexture[_ReflectionTex] {
            matrix [_ProjMatrix]
            constantColor [_Color]
            combine texture * constant
        }
    }
} 
}

Edit: fixed syntax error in the shader (removed {})
Edit2: changed ‘primary’ to ‘constant’, makes the shader actually work

Awesome, thanks Aras. Will see what I can wrangle together with my limited shader skills :wink:

What could cause the shader to fail under Ortho camera conditions?

Aras - I’ve tried that script and setup things as best I can, but I’m not seeing the reflection in the final result.

I’ve assigned 2 materials to the Mesh, the first being the base, the 2nd being the reflection with the new Additive Mirror shader.

I checked the Rendertexture at runtime, and it seems to contain the correct reflect image, but its just not being combined with the final somehow.

Also the example shader generated an exception at {} in this line (so i removed it)

 _Color("Color", Color) = (1,1,1,1) {}

Thanks for your help
Shaun

EDIT:
ah - and I tried this with both Ortho and Persp modes… same result.

Oh yeah, turns out posting untested shaders directly to the forum makes them not work in some cases… :roll:

I updated the shader above. Also updated the script on MirrorReflection2 to support multiple materials on the object.

This makes it work for me.

Thx again Aras :slight_smile: - I seem to have it pretty much working(grey is Ok, but pure black gives a transparent output)

Ortho mode is still a no-no… is there any way around this?

Didn’t look into that yet… will do once I’m done with whatever I’m doing right now :slight_smile:

Rock n roll!
I hereby request a pay-rise for Aras - maybe better in the wish list :wink:

Aras is overworked. Doesn’t even know what he’s working on right now!

All of you guys need a vacation…but make it after you do the small list of things that is the wish-list ok? :wink:

-Jeremy

If you’ve got nothing under your mirror plane, then just commenting out call to CalculateObliqueMatrix in the mirror reflection script should work.

Meanwhile I’m trying to figure out how to do this oblique clipping matrix for orthographic camera, and this projective math is a bit over my head. If anyone knows how to do it, let me know…

Nice - I’ll give that a shot as its good enough in the meantime.

As for the shader math - if its over your head, then it must be pretty bloody difficult. Hope someone can help - Stephen Hawkings maybe :wink:

I figured it out. Wasn’t that hard.

Updated the MirrorReflection2 on the wiki, now supports orthographic cameras. Only the CalculateObliqueMatrix function in MirrorReflection script has changed.

this works great. is there anyway of making the reflection say 10% strength… trying to achieve a highly polished concrete floor that reflects the columns and ceiling around it… any suggestions?

cheers.

@thylaxene to get a reflection on the surface of a material rather than a mirror, take a look at Aras’s suggestion earlier in this thread:

Since I was doing something similar just now, the alpha channel of the main texture controls the reflection strength (I just changed the FX/Mirror Reflection shader slightly):

Shader "FX/Mirror Blend" { 
Properties {
	_MainTex ("Base (RGB) RefStrength (A)", 2D) = "white" {}
	_ReflectionTex ("Reflection", 2D) = "white" { TexGen ObjectLinear }
}

// two texture cards: full thing
Subshader { 
	Pass {
		SetTexture [_ReflectionTex] { matrix [_ProjMatrix] combine texture }
		SetTexture [_MainTex] { combine texture lerp (texture) previous }
	}
}

// fallback: just main texture
Subshader {
	Pass {
		SetTexture [_MainTex] { combine texture }
	}
}

}

–Eric

Is it my imagination, or can unity not read a solid color as an alpha channel?
I created a flat color with a solid grey alpha channel and it kept coming up white ie no alpha. I changed the levels of gray from white through black still nothing. I then scribbled black and white and there is was. Even a small dot of different shade enabled the alpha. But flat no way. Is it me or is that weird?

Try it.