- Home /
Is there a way of creating upside-down terrain?
Hi
I'm involved making a game which involves switching gravity as a core mechanic and want to create two terrains which can both be travelled on; one normal one and another which is flipped upside-down.
There could be a really easy way doing this that I've missed but anyway, any help would be very much appreciated!
(and it should be mentioned that I'm really awful at scripting!)
Answer by Eric5h5 · Nov 22, 2010 at 07:52 PM
Unity terrains can't be flipped or rotated. In order to do that you have to use a standard mesh.
Answer by OndrejP · May 21, 2019 at 08:55 AM
We're using upside-down terrain as ceiling for caves. What is needed is custom terrain shader with flipped normals and "Cull Front"
What is not working properly is shadows from Directional Light (sun), there are issues caused by Bias a SlopeBias, because shadow shader is applying them in opposive way. We didn't try to fix it since we don't need sun in caves.
We've taken original terrain shader, made a copy and changed few lines. Similar changes has been done in other shaders (Add pass, Base, Base-gen, Picking, Selection)
Zip archive with all shaders & material (Unity 2019.1): TerrainFlip.zip
// Unity built-in shader source. Copyright (c) 2016 Unity Technologies. MIT license (see license.txt)
Shader "Nature/Terrain/Standard (flipped)" {
Properties {
// used in fallback on old cards & base map
[HideInInspector] _MainTex ("BaseMap (RGB)", 2D) = "white" {}
[HideInInspector] _Color ("Main Color", Color) = (1,1,1,1)
}
SubShader {
Tags {
"Queue" = "Geometry-100"
"RenderType" = "Opaque"
}
Cull Front // FIRST CHANGE
CGPROGRAM
#pragma surface surf Standard vertex:SplatmapVert finalcolor:SplatmapFinalColor finalgbuffer:SplatmapFinalGBuffer addshadow fullforwardshadows
#pragma instancing_options assumeuniformscaling nomatrices nolightprobe nolightmap forwardadd
#pragma multi_compile_fog // needed because finalcolor oppresses fog code generation.
#pragma target 3.0
// needs more than 8 texcoords
#pragma exclude_renderers gles
#include "UnityPBSLighting.cginc"
#pragma multi_compile __ _NORMALMAP
#define TERRAIN_STANDARD_SHADER
#define TERRAIN_INSTANCED_PERPIXEL_NORMAL
#define TERRAIN_SURFACE_OUTPUT SurfaceOutputStandard
#include "TerrainSplatmapCommon.cginc"
half _Metallic0;
half _Metallic1;
half _Metallic2;
half _Metallic3;
half _Smoothness0;
half _Smoothness1;
half _Smoothness2;
half _Smoothness3;
void surf (Input IN, inout SurfaceOutputStandard o) {
half4 splat_control;
half weight;
fixed4 mixedDiffuse;
half4 defaultSmoothness = half4(_Smoothness0, _Smoothness1, _Smoothness2, _Smoothness3);
SplatmapMix(IN, defaultSmoothness, splat_control, weight, mixedDiffuse, o.Normal);
o.Albedo = mixedDiffuse.rgb;
o.Alpha = weight;
o.Normal *= -1; // SECOND CHANGE
o.Smoothness = mixedDiffuse.a;
o.Metallic = dot(splat_control, half4(_Metallic0, _Metallic1, _Metallic2, _Metallic3));
}
ENDCG
UsePass "Hidden/Nature/Terrain/Utilities-flip/PICKING"
UsePass "Hidden/Nature/Terrain/Utilities-flip/SELECTION"
}
// THIRD CHANGE (using flipped dependencies)
Dependency "AddPassShader" = "Hidden/TerrainEngine/Splatmap/Standard-flip-AddPass"
Dependency "BaseMapShader" = "Hidden/TerrainEngine/Splatmap/Standard-flip-Base"
Dependency "BaseMapGenShader" = "Hidden/TerrainEngine/Splatmap/Standard-flip-BaseGen"
Fallback "Nature/Terrain/Diffuse"
}
@OndrejP This is exactly what I was looking for I just don't know how to use what you provided here.I am just learning Unity. I have a $$anonymous$$ap$$anonymous$$agic terrain and I plan to use the same terrain as the ceiling. Could you possibly elaborate on how I could achieve this? Thank you.
Don't know what $$anonymous$$ap$$anonymous$$agic is. You download terrainflip.zip and unpack it somewhere into your project. Then on Terrain component in settings choose custom shader / material and assign TerrainFlip material there.
Thanks for the quick response! So what I learned was that $$anonymous$$icroSplat creates its own shader based on a texture array and this is don automatically every time you update the array. So I just added an option in $$anonymous$$icroSplat to invert the shader and ins$$anonymous$$d of cull back I just set it to automatically cull front.. I did not set the normal to -1 but I am getting the desired effect. Now to solve the shadow issue :) I really do appreciate you sharing this information!
Answer by Adil_Alhilali · Jul 03, 2020 at 11:30 AM
Export the unity terrain to any 3d modeling software save it as plain then imported back to unity