Hi, I have no idea how shaders work, so I'm not entirely sure if this is possible. I have used quite a few different day/night systems, weather systems and cloud systems. The only problem is that since most of them require me to place a sphere surround my terrain, and my terrain is pretty big, I have to set the clipping plains max to a very large number, which slows down my game, or have had to use particle clouds (which look great, but are even slower) . So what I'm wondering is: is it possible to make a sky-sphere (as opposed to a skybox (to make it look more realistic)), that works like a skybox (no huge object surrounding the terrain, showing up behind objects yet looking infinitly far away ), except it will show up in front of the first skybox (optional), have moving textures, be able to have different colours and brightness (optional), and if possible, look more voluminus than a flat cloud texture (bump maps?)? Could anyone point me in the right direction? Thanks!
The codes given don't work; the first one constantly generates errors, and the second one, you can't see the terrain behind it.
Hi, I tweaked the shader from apple motion, it works now. I make a sphere and place it in the same position as camera. If camera moves, create a script that makes sphere position to follow camera position. Hope that helps. Code (csharp): Shader "Skybox" { Properties { color_map ("color_map", 2D) = "white" {} } SubShader { Pass { CULL FRONT ZWrite Off CGPROGRAM #pragma vertex vert #pragma fragment frag struct a2v { float4 vertex : POSITION; float4 texcoord : TEXCOORD0; }; struct v2f { float4 position : POSITION; float4 texcoord : TEXCOORD0; }; v2f vert(a2v IN) { v2f OUT; OUT.position = mul(UNITY_MATRIX_MVP, IN.vertex); OUT.texcoord = IN.texcoord; return OUT; } sampler2D color_map; float4 col; float4 frag( v2f IN ): COLOR { col.xyz = tex2D(color_map, IN.texcoord.xy); col.w = 1; //depth = 1; return col; } ENDCG } } }
Hi, thank you for your time, but I still cant see anything behind it, and if there's nothing behind it, it goes invisible, where as it should be the other way around.
Make it slightly smaller than the desired clip plane size ? [Edit] Ok, I understand it now, you are right.
Ok, this works on my mac. Code (csharp): Shader "Skybox" { Properties { color_map ("color_map", 2D) = "white" {} } SubShader { Pass { CULL FRONT ZWrite On CGPROGRAM #pragma vertex vert #pragma fragment frag struct a2v { float4 vertex : POSITION; float4 texcoord : TEXCOORD0; }; struct v2f { float4 position : POSITION; float4 texcoord : TEXCOORD0; }; v2f vert(a2v IN) { v2f OUT; OUT.position = mul(UNITY_MATRIX_MVP, IN.vertex); OUT.texcoord = IN.texcoord; return OUT; } void frag( v2f IN, sampler2D color_map, out float4 col:COLOR, out float depth:DEPTH) { col.xyz = tex2D(color_map, IN.texcoord.xy); col.w = 1; depth = 1; } ENDCG } } }
I'm getting the following errors: Shader error in 'Skybox': D3D shader assembly failed with: (10): error X2022: scalar registers cannot be masked Shader warning in 'Skybox': No subshaders can run on this graphics card Material doesn't have a texture property 'color_map' You say it's running on your mac, I have a windows laptop, do you think it's a apple to microsoft problem? Or the fact that I'm running a laptop rather than a destop? Either way, thank you for your help.
Hi, I was unsure on Iphone compatibility, not Windows. I tried it with Graphics emulation Shader model 2 and 3. It fails at Shader model 1 ( old cards ). If you do not mind, try it at another computer too. Also, Perhaps it could be solved as Code (csharp): Shader "Skybox" { Properties { color_map ("color_map", 2D) = "white" {} } SubShader { Pass { CULL FRONT ZWrite On CGPROGRAM #pragma vertex vert #pragma fragment frag struct a2v { float4 vertex : POSITION; float4 texcoord : TEXCOORD0; }; struct v2f { float4 position : POSITION; float4 texcoord : TEXCOORD0; }; v2f vert(a2v IN) { v2f OUT; OUT.position = mul(UNITY_MATRIX_MVP, IN.vertex); OUT.texcoord = IN.texcoord; return OUT; } void frag( v2f IN, sampler2D color_map, out float4 col:COLOR, out float depth:DEPTH) { float4 color1; color1 = tex2D(color_map, IN.texcoord.xy); color1.w = 1; col = color1; depth = 1; } ENDCG } } }
Hmm, I still get: Material doesn't have a texture property 'color_map' I'll be able to transfer this to my desktop in about two days, I'll get back to you with the results. Thank you.
Sorry for coming back late, but even on my desktop, I'm still getting the same error EDIT: by same error, I meant one in before post, see next post.
Sorry, it's: Shader error in 'Skybox': D3D shader assembly failed with: (10): error X2022: scalar registers cannot be masked Shader warning in 'Skybox': No subshaders can run on this graphics card
I don't think modifying the fragment depth is a good idea in this situation. It won't work on older graphics cards (or any Macs), and I don't think it will get the effect you want, anyway. Try this. All it does is draw early without writing to the Z buffer. Everything else will be drawn in front of it. Code (csharp): Shader "Custom/Background" { Properties { _MainTex ("Base (RGB)", 2D) = "white" {} } SubShader { Tags { "RenderQueue"="Background" } Pass { ZWrite Off SetTexture [_MainTex] {} } } }
It's now, although not giving any errors, not visible from the inside, and only draws in front of things; I make the main texture an orange texture, assign the material to a sphere, and put the sphere in front (it's not visible from the inside) of the camera. The terrain, along with any other object is orange, but any place where there is no object (empty space; where the skybox is visible), it's transparent. I may have found a different approach. I attached a water material under the rendersettings skybox material, and it actually made a moving water affect, infinitley far away that did not get culled. Although, when I put some materials in front of it, it makes this stange affect where anything that is visible is drawn on there, without getting erased. Example: a cube flies across the screen. There is now a trail that does not disappear until something else is drawn on top of it. Would I be able to create a procedural cloud shader, attach it to a material, put it as the skybox material without getting that strange effect?
For any other shader novices interested in a shader for this purpose, I have hacked the default skybox shader to just use a single texture ( as the shaders posted here were problematic ) : Code (csharp): Shader "RenderFX/Skybox Single Texture" { Properties { _Tint ("Tint Color", Color) = (.5, .5, .5, .5) _FrontTex ("Front (+Z)", 2D) = "white" {} } SubShader { Tags { "Queue"="Background" "RenderType"="Background" } Cull Off ZWrite Off Fog { Mode Off } CGINCLUDE #include "UnityCG.cginc" fixed4 _Tint; struct appdata_t { float4 vertex : POSITION; float2 texcoord : TEXCOORD0; }; struct v2f { float4 vertex : POSITION; float2 texcoord : TEXCOORD0; }; v2f vert (appdata_t v) { v2f o; o.vertex = mul(UNITY_MATRIX_MVP, v.vertex); o.texcoord = v.texcoord; return o; } fixed4 skybox_frag (v2f i, sampler2D smp) { fixed4 tex = tex2D (smp, i.texcoord); fixed4 col; col.rgb = tex.rgb + _Tint.rgb - 0.5; col.a = tex.a * _Tint.a; return col; } ENDCG Pass { CGPROGRAM #pragma vertex vert #pragma fragment frag #pragma fragmentoption ARB_precision_hint_fastest sampler2D _FrontTex; fixed4 frag (v2f i) : COLOR { return skybox_frag(i,_FrontTex); } ENDCG } } SubShader { Tags { "Queue"="Background" "RenderType"="Background" } Cull Off ZWrite Off Fog { Mode Off } Color [_Tint] Pass { SetTexture [_FrontTex] { combine texture +- primary, texture * primary } } } } Note: - You will need to make sure the normals of your skybox mesh are pointing inward ( may have been one of the previous poster's problems ). - Any existing Skyboxes will need to removed / unset ( Render Settings / Camera ). - You will likely need to attach a script to your camera to move the Skybox mesh along with it, something like: Code (csharp): void LateUpdate ( ) { Skybox.transform.position = transform.position; } ( or you can child the skybox object to the camera, and then reset its orientation ( I haven't tested this myself though ) ).
I'm unable to write depth in OSX, according to Unity they deny you this ability for what to me seems to be no reason. Did you actually get depth writing per fragment working? outputting outfloatdepthEPTH seems to just turn whatever mesh invisible.. did you really get depth writing working per fragment? heres the bullshit: On OpenGL (Mac OS X), depth texture is the native OpenGL depth buffer (see ARB_depth_texture). Graphics card must support OpenGL 1.4 or ARB_depth_texture extension. Depth texture corresponds to Z buffer contents that are rendered, it does not use the result from the fragment program.