Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - directedchaos

Pages: [1]
1
Other Packages / Re: Tasharen Fog of War
« on: July 03, 2015, 11:53:06 PM »
You forgot to specify the vertex shader in your #pragma define:
  1. #pragma surface surf Lambert alphatest:_Cutoff
should be:
  1. #pragma surface surf Lambert vertex:vert alphatest:_Cutoff

Thank you so much, that fixed it!  I now have a working Transparent/Cutout/Diffuse shader with Fog of War, very cool!  I'd be nice if you could include it, though I'm not sure about any legal complications since it's based on a free Unity shader.  It's pretty straightforward to add if you know about those steps though.  Another little perf tidbit, I'm finding that about 256x256 is getting to the upper limit on my iPhone 5 in terms of speed -- something like a second or two delay, which can be masked well with the fading.

2
Other Packages / Re: Tasharen Fog of War
« on: June 22, 2015, 11:10:36 PM »
Thanks for getting back to me!  Unfortunately I know very little about shaders, and my simple copy-paste of those 4 sections to the built-in "Transparent/Cutout/Diffuse" (download built-in shaders source code, AlphaTest-Diffuse.shader) results in odd stripes.  I suspect step 3 doesn't apply cleanly to the cutout shader.  I've played with all kinds of conversions (float, half, fixed), nothing seemed to change it, but if I force the fog.g and fog.r properties I can see it is blending properly.  So I think it's just not mapping to the right spot in the fog texture.  Also odd, the striping seems to change with the camera (the revealer isn't moving, just the camera).

Here's what I have:
  1. Shader "Custom/Cutout Diffuse (FoW)" {
  2. Properties {
  3.         _Color ("Main Color", Color) = (1,1,1,1)
  4.         _MainTex ("Base (RGB) Trans (A)", 2D) = "white" {}
  5.         _Cutoff ("Alpha cutoff", Range(0,1)) = 0.5
  6. }
  7.  
  8. SubShader {
  9.         Tags {"Queue"="AlphaTest" "IgnoreProjector"="True" "RenderType"="TransparentCutout"}
  10.         LOD 200
  11.        
  12. CGPROGRAM
  13. #pragma surface surf Lambert alphatest:_Cutoff
  14.  
  15. sampler2D _MainTex;
  16. fixed4 _Color;
  17.  
  18. // FOW #1: Requires parameters (set by FOWSystem)
  19. sampler2D _FOWTex0, _FOWTex1;
  20. float4 _FOWParams;
  21. half4 _FOWUnexplored, _FOWExplored;
  22.  
  23. struct Input {
  24.         float2 uv_MainTex;
  25.  
  26.         // FOW #2: Fog texture coordinates
  27.         float2 fog : TEXCOORD2;
  28. };
  29.  
  30. void vert (inout appdata_full v, out Input o)
  31. {
  32.         UNITY_INITIALIZE_OUTPUT(Input, o);
  33.  
  34.         // FOW #3: Set the fog texture coordinates
  35.         float4 worldPos = mul (_Object2World, v.vertex);
  36.         o.fog.xy = worldPos.xz * _FOWParams.z + _FOWParams.xy;
  37. }
  38.  
  39. void surf (Input IN, inout SurfaceOutput o) {
  40.         fixed4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color;
  41.        
  42.         // FOW #4: Tint the final color by the Fog of War
  43.         half4 fog = lerp(tex2D(_FOWTex0, IN.fog), tex2D(_FOWTex1, IN.fog), _FOWParams.w);
  44.         c.rgb = lerp(lerp(c.rgb * _FOWUnexplored, c.rgb * _FOWExplored, fog.g), c.rgb, fog.r);
  45.  
  46.         o.Albedo = c.rgb;
  47.         o.Alpha = c.a;
  48. }
  49. ENDCG
  50. }
  51.  
  52. Fallback "Transparent/Cutout/Diffuse"
  53. }
  54.  

Here's Unity's built-in shader I'm trying to add Fog of War to:
  1. Shader "Transparent/Cutout/Diffuse" {
  2. Properties {
  3.         _Color ("Main Color", Color) = (1,1,1,1)
  4.         _MainTex ("Base (RGB) Trans (A)", 2D) = "white" {}
  5.         _Cutoff ("Alpha cutoff", Range(0,1)) = 0.5
  6. }
  7.  
  8. SubShader {
  9.         Tags {"Queue"="AlphaTest" "IgnoreProjector"="True" "RenderType"="TransparentCutout"}
  10.         LOD 200
  11.        
  12. CGPROGRAM
  13. #pragma surface surf Lambert alphatest:_Cutoff
  14.  
  15. sampler2D _MainTex;
  16. fixed4 _Color;
  17.  
  18. struct Input {
  19.         float2 uv_MainTex;
  20. };
  21.  
  22. void surf (Input IN, inout SurfaceOutput o) {
  23.         fixed4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color;
  24.         o.Albedo = c.rgb;
  25.         o.Alpha = c.a;
  26. }
  27. ENDCG
  28. }
  29.  
  30. Fallback "Transparent/Cutout/VertexLit"
  31. }
  32.  

3
Other Packages / Re: Tasharen Fog of War
« on: June 20, 2015, 10:51:10 PM »
It's a great effect, and using the provided shaders (terrain and diffuse) I got a simple scene running seemingly without a framerate hit on an iPhone 5.  Awesome!  I know it's not your target platform, but you might include some simple notes/suggestions.  For example, here's how I got it working (probably obvious to those more experienced with shaders):
  • You have to go to Terrain Settings and set the Material to a material that uses the shader Fog of War/Terrain
  • It only seems to support 4 textures on a  terrain.  Textures after that were always full brightness.
  • You have to set the shader for anything with Diffuse shaders that you want to have this effect to Fog of War/Diffuse
Using those shaders was a bit of a breakthrough for me.  Using the effect on the camera showed cool results, but really hit the framerate hard on mobile.

I have two questions:
  • Can you include more shaders, particularly Transparent/Cutout/Diffuse?  Or has anybody else created one that samples the Fog of War texture properly?
  • How does the memory footprint scale?  I mean, does it just increase with the World Size and Texture Size parameters, not with the size of the objects (like terrain) that use the shaders?
Again, it's a great effect, and I'm excited about using it!

4
Hello,

I have this structure (UIGrid under a ScrollView, instantiating objects under the UIGrid):
ScrollView
|-UIGrid
|--SomethingWithCollidersLikeAButton(Copy)
|--SomethingWithCollidersLikeAButton(Copy)
[...]

I call NGUITools.AddChild(UIGrid, SomethingWithCollidersLikeAButton).  The colliders don't hit -- no matter what I do.  I move them in the editor so nothing is over them, change the z-order, change the parent (so it's not even under the UIGrid, or ScrollView, etc.)... nothing.  UICamera debug is on and not showing it.  Another interesting bit: when I move them, visually they don't move until I disable and re-enable the object.

If I add them to the ScrollView directly, it works.  If I add them to anything else then move them (in the editor) to the UIGrid, it works.  If it use a UITable instead, it works.  So it's probably a bug with the UIGrid.  I'm using UITable for now, and my overall setup is pretty complex so it's hard to give a simple example, but hopefully this helps find the bug and warns others who may hit this.  I'm on the latest (3.8, but I hit this before updating too, not sure how old).

5
I just ran into this too, with a UISprite anchored in code to another UISprite's background whose size changes.  However, even when the size of the target doesn't change, it keeps shooting the transform's y to infinity.

Pages: [1]