diff --git a/Assets/GFX/Shaders/Deferred/Internal-DeferredShading.shader b/Assets/GFX/Shaders/Deferred/Internal-DeferredShading.shader index 12b19425..1fc3857b 100644 --- a/Assets/GFX/Shaders/Deferred/Internal-DeferredShading.shader +++ b/Assets/GFX/Shaders/Deferred/Internal-DeferredShading.shader @@ -40,13 +40,159 @@ CGPROGRAM sampler2D _CameraGBufferTexture0; sampler2D _CameraGBufferTexture1; sampler2D _CameraGBufferTexture2; +sampler1D WaterRampSampler; + +uniform int _Area; +uniform half4 _AreaRect; +half _GridScale; +uniform int _ShaderID; +uniform int _Water; +uniform half LightingMultiplier; +uniform fixed4 SunColor; +uniform fixed4 SunDirection; +uniform fixed4 SunAmbience; +uniform fixed4 ShadowFillColor; +uniform fixed4 SpecularColor; +uniform float WaterElevation; + + +float3 ApplyWaterColor(float waterDepth, float3 color) +{ + if (waterDepth > 0) { + float4 waterColor = tex1D(WaterRampSampler, waterDepth); + color = lerp(color.xyz, waterColor.rgb, waterColor.a); + } + return color; +} + +float3 ApplyWaterColorExponentially(float3 viewDirection, float waterDepth, float3 color) +{ + if (waterDepth > 0) { + float3 up = float3(0,1,0); + // this is the length that the light travels underwater back to the camera + float oneOverCosV = 1 / max(dot(up, normalize(viewDirection)), 0.0001); + // Light gets absorbed exponentially, + // to simplify, we assume that the light enters vertically into the water. + // We need to multiply by 2 to reach 98% absorption as the waterDepth can't go over 1. + float waterAbsorption = 1 - saturate(exp(-waterDepth * 2 * (1 + oneOverCosV))); + // darken the color first to simulate the light absorption on the way in and out + color *= 1 - waterAbsorption; + // lerp in the watercolor to simulate the scattered light from the dirty water + float4 waterColor = tex1D(WaterRampSampler, waterAbsorption); + color = lerp(color, waterColor.rgb, waterAbsorption); + } + return color; +} + +float4 CalculateLighting( float3 inNormal, float3 viewDirection, float3 inAlbedo, float specAmount, float shadow) +{ + float4 color = float4( 0, 0, 0, 0 ); + + float SunDotNormal = dot( SunDirection, inNormal); + float3 R = SunDirection - 2.0f * SunDotNormal * inNormal; + float specular = pow( saturate( dot(R, viewDirection) ), 80) * SpecularColor.x * specAmount; + + float3 light = SunColor * saturate( SunDotNormal) * shadow + SunAmbience + specular; + light = LightingMultiplier * light + ShadowFillColor * ( 1 - light ); + color.rgb = light * inAlbedo; + + color.a = 0.01f + (specular*SpecularColor.w); + return color; +} + +float4 CalculateXPLighting( float3 normal, float3 viewDirection, float4 albedo, float shadow) +{ + float3 r = reflect(viewDirection,normal); + float3 specular = pow(saturate(dot(r,SunDirection)),80)*albedo.aaa*SpecularColor.a*SpecularColor.rgb; -uniform int _TTerrainXP; -uniform half _LightingMultiplier; -uniform fixed4 _SunColor; -uniform fixed4 _SunAmbience; -uniform fixed4 _ShadowColor; -uniform fixed4 _SpecularColor; + float dotSunNormal = dot(SunDirection,normal); + + float3 light = SunColor*saturate(dotSunNormal)*shadow + SunAmbience; + light = LightingMultiplier*light + ShadowFillColor*(1-light); + albedo.rgb = light * ( albedo.rgb + specular.rgb ); + + return albedo; +} + +float3 FresnelSchlick(float hDotN, float3 F0) +{ + return F0 + (1.0 - F0) * pow(1.0 - hDotN, 5.0); +} + +float NormalDistribution(float3 n, float3 h, float roughness) +{ + float a2 = roughness*roughness; + float nDotH = max(dot(n, h), 0.0); + float nDotH2 = nDotH*nDotH; + + float num = a2; + float denom = nDotH2 * (a2 - 1.0) + 1.0; + denom = 3.14159265359 * denom * denom; + + return num / denom; +} + +float GeometrySchlick(float nDotV, float roughness) +{ + float r = (roughness + 1.0); + float k = (r*r) / 8.0; + + float num = nDotV; + float denom = nDotV * (1.0 - k) + k; + + return num / denom; +} + +float GeometrySmith(float3 n, float nDotV, float3 l, float roughness) +{ + float nDotL = max(dot(n, l), 0.0); + float gs2 = GeometrySchlick(nDotV, roughness); + float gs1 = GeometrySchlick(nDotL, roughness); + + return gs1 * gs2; +} + +float3 PBR(float3 wpos, float3 viewDirection, float3 albedo, float3 n, float roughness, float shadow) { + // See https://blog.selfshadow.com/publications/s2013-shading-course/ + + float facingSpecular = 0.04; + float underwater = step(wpos, WaterElevation); + facingSpecular *= 1 - 0.9 * underwater; + + float3 v = -viewDirection; + float3 F0 = float3(facingSpecular, facingSpecular, facingSpecular); + float3 l = SunDirection; + float3 h = normalize(v + l); + float nDotL = max(dot(n, l), 0.0); + // Normal maps can cause an angle > 90° betweeen n and v which would + // cause artifacts if we don't take some countermeasures + float nDotV = abs(dot(n, v)) + 0.001; + float3 sunLight = SunColor * LightingMultiplier * shadow; + + // Cook-Torrance BRDF + float3 F = FresnelSchlick(max(dot(h, v), 0.0), F0); + float NDF = NormalDistribution(n, h, roughness); + float G = GeometrySmith(n, nDotV, l, roughness); + + // For point lights we need to multiply with Pi + float3 numerator = 3.14159265359 * NDF * G * F; + // add 0.0001 to avoid division by zero + float denominator = 4.0 * nDotV * nDotL + 0.0001; + float3 reflected = numerator / denominator; + + float3 kD = float3(1.0, 1.0, 1.0) - F; + float3 refracted = kD * albedo; + float3 irradiance = sunLight * nDotL; + float3 color = (refracted + reflected) * irradiance; + + float3 shadowColor = (1 - (SunColor * shadow * nDotL + SunAmbience)) * ShadowFillColor; + float3 ambient = SunAmbience * LightingMultiplier + shadowColor; + + // we simplify here for the ambient lighting + color += albedo * ambient; + + return color; +} half4 CalculateLight (unity_v2f_deferred i) { @@ -59,73 +205,61 @@ half4 CalculateLight (unity_v2f_deferred i) light.color = _LightColor.rgb * atten; - - // unpack Gbuffer half4 gbuffer0 = tex2D (_CameraGBufferTexture0, uv); half4 gbuffer1 = tex2D (_CameraGBufferTexture1, uv); half4 gbuffer2 = tex2D (_CameraGBufferTexture2, uv); - UnityStandardData data = UnityStandardDataFromGbuffer(gbuffer0, gbuffer1, gbuffer2); - - data.diffuseColor.rgb = gbuffer0.rgb; float3 eyeVec = normalize(wpos-_WorldSpaceCameraPos); - half oneMinusReflectivity = 1 - SpecularStrength(data.specularColor.rgb); - - UnityIndirect ind; - UNITY_INITIALIZE_OUTPUT(UnityIndirect, ind); - ind.diffuse = 0; - ind.specular = 0; - - // if (light.ndotl <= 0.0) - // light.ndotl = 0; - // else - // light.ndotl = 1; - - //half4 res = UNITY_BRDF_PBS (data.diffuseColor, data.specularColor, oneMinusReflectivity, data.smoothness, data.normalWorld, -eyeVec, light, ind); - float4 c; - float3 spec = float3(0,0,0); - float AlbedoAlpha = gbuffer1.a; - fixed3 SunColor = _SunColor.rgb * 2; - fixed3 SunAmbience = _SunAmbience.rgb * 2; - fixed3 ShadowFillColor = _ShadowColor.rgb * 2; - fixed4 SpecularColor = _SpecularColor.rgba * 2; - - if(_TTerrainXP <= 0){ // Normal lighting - float NdotL = dot (light.dir, data.normalWorld); - - float3 R = light.dir - 2.0f * NdotL * data.normalWorld; - float specular = pow( saturate( dot(R, eyeVec) ), 8) * SpecularColor.r * AlbedoAlpha * 2; - float3 lighting = SunColor * saturate(NdotL) * atten + SunAmbience + specular; - lighting = _LightingMultiplier * lighting + ShadowFillColor * (1 - lighting); - c.rgb = (data.diffuseColor + spec) * lighting; - c.a = 1; - } - else{ // XP lighting - - float NdotL = dot (light.dir, data.normalWorld); - - float3 r = reflect(eyeVec, data.normalWorld); - - float3 specular = (pow(saturate(dot(r, light.dir)), 80) * AlbedoAlpha * SpecularColor.a) * SpecularColor.rgb; - - float dotSunNormal = dot(light.dir, data.normalWorld); - //float shadow = tex2D(ShadowSampler, pixel.mShadow.xy).g; - float3 light = SunColor * saturate(dotSunNormal) * atten + SunAmbience; - light = _LightingMultiplier * light + ShadowFillColor * (1 - light); - c.rgb = light * (data.diffuseColor + specular.rgb); + float3 albedo = gbuffer0.rgb; + float alpha = gbuffer0.a; + float mapShadow = gbuffer1.r; + float waterDepth = gbuffer1.g; + float roughness = gbuffer1.b; + float3 worldNormal = gbuffer2.rgb; + + worldNormal = worldNormal * 2 - 1; + // The game is using a different coordinate system, so we need to correct for that + worldNormal.z = worldNormal.z * -1; + eyeVec.z = eyeVec.z * -1; + + float4 color; + + if (_ShaderID == 0) { + color.rgb = CalculateLighting(worldNormal, eyeVec, albedo, 1-alpha, atten); + } else if (_ShaderID == 1) { + color.rgb = CalculateXPLighting(worldNormal, eyeVec, float4(albedo, alpha), atten); + } else if (_ShaderID == 2) { + color.rgb = PBR(wpos, eyeVec, albedo, worldNormal, roughness, mapShadow * atten); + } - //float waterDepth = tex2Dproj(UtilitySamplerC, pixel.mTexWT*TerrainScale).g; - //float4 water = tex1D(WaterRampSampler, waterDepth); - //c.rgb = lerp(albedo.rgb, water.rgb, water.a); + if (_Water) { + // Trigger for exponential water absorption + if (LightingMultiplier > 2.1) { + color.rgb = ApplyWaterColorExponentially(-eyeVec, waterDepth, color.rgb); + } else { + color.rgb = ApplyWaterColor(waterDepth, color.rgb); + } + } + color.a = 1; + if(_Area > 0){ + if(wpos.x < _AreaRect.x){ + color.rgb = 0; + } + else if(wpos.x > _AreaRect.z){ + color.rgb = 0; + } + else if(wpos.z < _AreaRect.y - _GridScale){ + color.rgb = 0; + } + else if(wpos.z > _AreaRect.w - _GridScale){ + color.rgb = 0; + } } - - //half4 res = data.diffuseColor; - - return c; + return color; } #ifdef UNITY_HDR_ON diff --git a/Assets/GFX/Shaders/FaTerrainShader.shader b/Assets/GFX/Shaders/FaTerrainShader.shader index cd5df40f..9b2ac113 100644 --- a/Assets/GFX/Shaders/FaTerrainShader.shader +++ b/Assets/GFX/Shaders/FaTerrainShader.shader @@ -1,366 +1,573 @@ -// Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)' - -Shader "MapEditor/FaTerrainShader" { -Properties { - _SpecColor ("Specular Color", Color) = (0.5, 0.5, 0.5, 1) - _Shininess ("Shininess", Range (0.03, 1)) = 0.078125 - [MaterialToggle] _Grid("Grid", Int) = 0 - _GridType("Grid type", Int) = 0 - [MaterialToggle] _Slope("Slope", Int) = 0 - [MaterialToggle] _UseSlopeTex("Use Slope Data", Int) = 0 - _SlopeTex ("Slope data", 2D) = "black" {} - - // set by terrain engine - _Control ("Control (RGBA)", 2D) = "black" {} - _ControlXP ("ControlXP (RGBA)", 2D) = "black" {} - _Control2XP ("Control2XP (RGBA)", 2D) = "black" {} - - - [MaterialToggle] _HideSplat0("Hide splat 2", Int) = 0 - [MaterialToggle] _HideSplat1("Hide splat 2", Int) = 0 - [MaterialToggle] _HideSplat2("Hide splat 3", Int) = 0 - [MaterialToggle] _HideSplat3("Hide splat 4", Int) = 0 - [MaterialToggle] _HideSplat4("Hide splat 5", Int) = 0 - [MaterialToggle] _HideSplat5("Hide splat 6", Int) = 0 - [MaterialToggle] _HideSplat6("Hide splat 7", Int) = 0 - [MaterialToggle] _HideSplat7("Hide splat 8", Int) = 0 - [MaterialToggle] _HideSplat8("Hide splat Upper", Int) = 0 - [MaterialToggle] _HideTerrainType("Hide Terrain Type", Int) = 0 - - _SplatAlbedoArray ("Albedo array", 2DArray) = "" {} - _SplatNormalArray ("Normal array", 2DArray) = "" {} - - - _Splat0Scale ("Splat1 Level", Range (1, 1024)) = 10 - _Splat1Scale ("Splat2 Level", Range (1, 1024)) = 10 - _Splat2Scale ("Splat3 Level", Range (1, 1024)) = 10 - _Splat3Scale ("Splat4 Level", Range (1, 1024)) = 10 - _Splat4Scale ("Splat5 Level", Range (1, 1024)) = 10 - _Splat5Scale ("Splat6 Level", Range (1, 1024)) = 10 - _Splat6Scale ("Splat7 Level", Range (1, 1024)) = 10 - _Splat7Scale ("Splat8 Level", Range (1, 1024)) = 10 - - // set by terrain engine - [MaterialToggle] _GeneratingNormal("Generating Normal", Int) = 0 - _TerrainNormal ("Terrain Normal", 2D) = "bump" {} - - - _Splat0ScaleNormal ("Splat1 Normal Level", Range (1, 1024)) = 10 - _Splat1ScaleNormal ("Splat2 Normal Level", Range (1, 1024)) = 10 - _Splat2ScaleNormal ("Splat3 Normal Level", Range (1, 1024)) = 10 - _Splat3ScaleNormal ("Splat4 Normal Level", Range (1, 1024)) = 10 - _Splat4ScaleNormal ("Splat5 Normal Level", Range (1, 1024)) = 10 - _Splat5ScaleNormal ("Splat6 Normal Level", Range (1, 1024)) = 10 - _Splat6ScaleNormal ("Splat7 Normal Level", Range (1, 1024)) = 10 - _Splat7ScaleNormal ("Splat8 Normal Level", Range (1, 1024)) = 10 - - // used in fallback on old cards & base map - [HideInInspector] _MainTex ("BaseMap (RGB)", 2D) = "white" {} - [HideInInspector] _Color ("Main Color", Color) = (1,1,1,1) - - [MaterialToggle] _Brush ("Brush", Int) = 0 - [MaterialToggle] _BrushPainting ("Brush painting", Int) = 0 - _BrushTex ("Brush (RGB)", 2D) = "white" {} - _BrushSize ("Brush Size", Range (0, 128)) = 0 - _BrushUvX ("Brush X", Range (0, 1)) = 0 - _BrushUvY ("Brush Y", Range (0, 1)) = 0 - - //Lower Stratum - _SplatLower ("Layer Lower (R)", 2D) = "white" {} - _NormalLower ("Normal Lower (R)", 2D) = "bump" {} - _LowerScale ("Lower Level", Range (1, 128)) = 1 - _LowerScaleNormal ("Lower Normal Level", Range (1, 128)) = 1 - - //Upper Stratum - _SplatUpper ("Layer Lower (R)", 2D) = "white" {} - _NormalUpper ("Normal Lower (R)", 2D) = "bump" {} - _UpperScale ("Upper Level", Range (1, 128)) = 1 - _UpperScaleNormal ("Upper Normal Level", Range (1, 128)) = 1 - - _GridScale ("Grid Scale", Range (0, 2048)) = 512 - _GridTexture ("Grid Texture", 2D) = "white" {} - - _TerrainTypeAlbedo ("Terrain Type Albedo", 2D) = "black" {} - _TerrainTypeCapacity ("Terrain Type Capacity", Range(0,1)) = 0.228 -} - - SubShader { - - CGPROGRAM - #define UNITY_BRDF_PBS BRDF3_Unity_PBS - - #pragma surface surf SimpleLambert vertex:vert fullforwardshadows addshadow nometa -#pragma multi_compile_fog - //#pragma debug +Shader "FAShaders/Terrain" +{ + Properties + { + // It is conventional to begin all property names with an underscore. + // However, to be as close to the FA shader code as possible, we ignore this here. + // We use underscores only for variables that are introduced by the editor. + + LowerAlbedoTile ("Lower Albedo Tile", Float) = 1 + LowerNormalTile ("Lower Normal Tile", Float) = 1 + Stratum0AlbedoTile ("Stratum 0 Albedo Tile", Float) = 1 + Stratum1AlbedoTile ("Stratum 1 Albedo Tile", Float) = 1 + Stratum2AlbedoTile ("Stratum 2 Albedo Tile", Float) = 1 + Stratum3AlbedoTile ("Stratum 3 Albedo Tile", Float) = 1 + Stratum4AlbedoTile ("Stratum 4 Albedo Tile", Float) = 1 + Stratum5AlbedoTile ("Stratum 5 Albedo Tile", Float) = 1 + Stratum6AlbedoTile ("Stratum 6 Albedo Tile", Float) = 1 + Stratum7AlbedoTile ("Stratum 7 Albedo Tile", Float) = 1 + Stratum0NormalTile ("Stratum 0 Normal Tile", Float) = 1 + Stratum1NormalTile ("Stratum 1 Normal Tile", Float) = 1 + Stratum2NormalTile ("Stratum 2 Normal Tile", Float) = 1 + Stratum3NormalTile ("Stratum 3 Normal Tile", Float) = 1 + Stratum4NormalTile ("Stratum 4 Normal Tile", Float) = 1 + Stratum5NormalTile ("Stratum 5 Normal Tile", Float) = 1 + Stratum6NormalTile ("Stratum 6 Normal Tile", Float) = 1 + Stratum7NormalTile ("Stratum 7 Normal Tile", Float) = 1 + UpperAlbedoTile ("Upper Albedo Tile", Float) = 1 + UpperNormalTile ("Upper Normal Tile", Float) = 1 + + // used to generate texture coordinates + // this is 1/mapresolution + TerrainScale ("Terrain Scale", Range (0, 1)) = 1 + + UtilitySamplerA ("masks of stratum layers 0 - 3", 2D) = "black" {} + UtilitySamplerB ("masks of stratum layers 4 - 7", 2D) = "black" {} + UtilitySamplerC ("water properties", 2D) = "black" {} // not set? + + LowerAlbedoSampler ("Layer Lower (R)", 2D) = "white" {} + LowerNormalSampler ("Normal Lower (R)", 2D) = "bump" {} + UpperAlbedoSampler ("Layer Lower (R)", 2D) = "white" {} + + _StratumAlbedoArray ("Albedo array", 2DArray) = "" {} + _StratumNormalArray ("Normal array", 2DArray) = "" {} + + [MaterialToggle] _HideStratum0("Hide stratum 0", Integer) = 0 + [MaterialToggle] _HideStratum1("Hide stratum 1", Integer) = 0 + [MaterialToggle] _HideStratum2("Hide stratum 2", Integer) = 0 + [MaterialToggle] _HideStratum3("Hide stratum 3", Integer) = 0 + [MaterialToggle] _HideStratum4("Hide stratum 4", Integer) = 0 + [MaterialToggle] _HideStratum5("Hide stratum 5", Integer) = 0 + [MaterialToggle] _HideStratum6("Hide stratum 6", Integer) = 0 + [MaterialToggle] _HideStratum7("Hide stratum 7", Integer) = 0 + [MaterialToggle] _HideStratum8("Hide upper stratum", Integer) = 0 + + [MaterialToggle] _HideTerrainType("Hide Terrain Type", Integer) = 0 + _TerrainTypeAlbedo ("Terrain Type Albedo", 2D) = "black" {} + _TerrainTypeCapacity ("Terrain Type Capacity", Range(0,1)) = 0.228 + + [MaterialToggle] _Grid("Grid", Integer) = 0 + _GridType("Grid type", Integer) = 0 + // This should be refactored so we can use TerrainScale instead + _GridScale ("Grid Scale", Range (0, 2048)) = 512 + _GridTexture ("Grid Texture", 2D) = "white" {} + + [MaterialToggle] _Slope("Slope", Integer) = 0 + [MaterialToggle] _UseSlopeTex("Use Slope Data", Integer) = 0 + _SlopeTex ("Slope data", 2D) = "black" {} + + [MaterialToggle] _Brush ("Brush", Integer) = 0 + [MaterialToggle] _BrushPainting ("Brush painting", Integer) = 0 + _BrushTex ("Brush (RGB)", 2D) = "white" {} + _BrushSize ("Brush Size", Range (0, 128)) = 0 + _BrushUvX ("Brush X", Range (0, 1)) = 0 + _BrushUvY ("Brush Y", Range (0, 1)) = 0 + + // Is this still needed? + [MaterialToggle] _GeneratingNormal("Generating Normal", Integer) = 0 + _TerrainNormal ("Terrain Normal", 2D) = "bump" {} + + } + SubShader + { + + CGPROGRAM + #pragma surface surf SimpleLambert vertex:TerrainVS exclude_path:forward nometa + #pragma multi_compile_fog #pragma target 3.5 - #pragma exclude_renderers gles - #include "UnityLightingCommon.cginc" - #include "UnityGBuffer.cginc" - #include "UnityGlobalIllumination.cginc" #include "Assets/GFX/Shaders/SimpleLambert.cginc" - #pragma multi_compile PREVIEW_OFF PREVIEW_ON - - struct Input { - float2 uv_Control : TEXCOORD0; - float3 worldPos; - float SlopeLerp; - float4 grabUV; - half fog; - }; - - half _GeneratingNormal; - uniform half4 unity_FogStart; - uniform half4 unity_FogEnd; - - - void vert (inout appdata_full v, out Input o){ - UNITY_INITIALIZE_OUTPUT(Input,o); - - o.SlopeLerp = dot(v.normal, half3(0,1,0)); - - if(_GeneratingNormal == 0) - v.normal = float3(0,1,0); - v.tangent.xyz = cross(v.normal, float3(0,0,1)); - v.tangent.w = -1; - float4 hpos = UnityObjectToClipPos (v.vertex); - o.grabUV = ComputeGrabScreenPos(hpos); - float pos = length(UnityObjectToViewPos(v.vertex).xyz); - float diff = unity_FogEnd.x - unity_FogStart.x; - float invDiff = 1.0f / diff; - o.fog = saturate((unity_FogEnd.x - pos) * invDiff); - } + // include file that contains UnityObjectToWorldNormal helper function + #include "UnityCG.cginc" - sampler2D _MyGrabTexture3; - sampler2D _WaterRam; - half _Shininess; - fixed4 _Abyss; - fixed4 _Deep; - int _Water; - float _WaterLevel; - int _Slope, _UseSlopeTex; + int _Slope; + int _UseSlopeTex; sampler2D _SlopeTex; int _Grid, _GridType; - half _GridScale; + half _GridScale; half _GridCamDist; sampler2D _GridTexture; - //uniform - sampler2D _ControlXP; - sampler2D _Control2XP; - uniform sampler2D _UtilitySamplerC; sampler2D _TerrainNormal; - sampler2D _SplatLower, _SplatUpper; sampler2D _TerrainTypeAlbedo; - sampler2D _NormalLower; - half _Splat0Scale, _Splat1Scale, _Splat2Scale, _Splat3Scale, _Splat4Scale, _Splat5Scale, _Splat6Scale, _Splat7Scale; - half _Splat0ScaleNormal, _Splat1ScaleNormal, _Splat2ScaleNormal, _Splat3ScaleNormal, _Splat4ScaleNormal, _Splat5ScaleNormal, _Splat6ScaleNormal, _Splat7ScaleNormal; - - UNITY_DECLARE_TEX2DARRAY(_SplatAlbedoArray); - UNITY_DECLARE_TEX2DARRAY(_SplatNormalArray); - int _HideSplat0, _HideSplat1, _HideSplat2, _HideSplat3, _HideSplat4, _HideSplat5, _HideSplat6, _HideSplat7, _HideSplat8; + int _HideStratum0; + int _HideStratum1; + int _HideStratum2; + int _HideStratum3; + int _HideStratum4; + int _HideStratum5; + int _HideStratum6; + int _HideStratum7; + int _HideStratum8; int _HideTerrainType; float _TerrainTypeCapacity; - - half _LowerScale, _UpperScale; - half _LowerScaleNormal, _UpperScaleNormal; - uniform int _TTerrainXP; - uniform float _WaterScaleX, _WaterScaleZ; - int _Brush, _BrushPainting; + int _Brush; + int _BrushPainting; sampler2D _BrushTex; half _BrushSize; half _BrushUvX; half _BrushUvY; - uniform int _Area; - uniform half4 _AreaRect; - - - - float3 ApplyWaterColor( float depth, float3 inColor){ - float4 wcolor = tex2D(_WaterRam, float2(depth,0)); - return lerp( inColor.rgb, wcolor.rgb, wcolor.a ); - } - - float4 RenderGrid(sampler2D _GridTex, float2 uv_Control, float Offset, float GridScale) { - fixed4 GridColor = tex2D(_GridTex, uv_Control * GridScale + float2(-Offset, Offset)); - fixed4 GridFinal = fixed4(0, 0, 0, GridColor.a); - if (_GridCamDist < 1) { - GridFinal.rgb = lerp(GridFinal.rgb, fixed3(1, 1, 1), GridColor.r * lerp(1, 0, _GridCamDist)); - GridFinal.rgb = lerp(GridFinal.rgb, fixed3(0, 1, 0), GridColor.g * lerp(1, 0, _GridCamDist)); - GridFinal.rgb = lerp(GridFinal.rgb, fixed3(0, 1, 0), GridColor.b * lerp(0, 1, _GridCamDist)); - } - else { - GridFinal.rgb = lerp(GridFinal.rgb, fixed3(0, 1, 0), GridColor.b); - } - - GridFinal *= GridColor.a; - - half CenterGridSize = lerp(0.005, 0.015, _GridCamDist) / _GridScale; - if (uv_Control.x > 0.5 - CenterGridSize && uv_Control.x < 0.5 + CenterGridSize) - GridFinal.rgb = fixed3(0.4, 1, 0); - else if (uv_Control.y > 0.5 - CenterGridSize && uv_Control.y < 0.5 + CenterGridSize) - GridFinal.rgb = fixed3(0.4, 1, 0); - - return GridFinal; - } - - inline fixed3 UnpackNormalDXT5nmScaled (fixed4 packednormal, fixed scale) - { - fixed3 normal = 0; - normal.xz = packednormal.wx * 2 - 1; - normal.y = sqrt(1 - saturate(dot(normal.xz, normal.xz))); - normal.xz *= scale; - - return normal.xzy; - } - - #if defined(SHADER_API_D3D11) || defined(SHADER_API_XBOXONE) || defined(SHADER_API_GLES3) || defined(SHADER_API_GLCORE) - #define UNITY_SAMPLE_TEX2DARRAY_GRAD(tex,coord,dx,dy) tex.SampleGrad (sampler##tex,coord,dx,dy) - #else - #if defined(UNITY_COMPILER_HLSL2GLSL) || defined(SHADER_TARGET_SURFACE_ANALYSIS) - #define UNITY_SAMPLE_TEX2DARRAY_GRAD(tex,coord,dx,dy) float4(0,0,0,0) //tex2DArray(tex,coord,dx,dy) - #endif - #endif - - void surf (Input IN, inout SurfaceOutput o) { - - float4 waterTexture = tex2D( _UtilitySamplerC, IN.uv_Control * float2(1, -1) + float2(1 / (_WaterScaleX * 1), 1 / (_WaterScaleZ * 1) + 1)); - - float WaterDepth = waterTexture.g; - - float2 UVCtrl = IN.uv_Control * fixed2(1, -1) + half2(0, 1); - float2 UV = IN.uv_Control * fixed2(1, -1) + half2(0, 1); - float4 splat_control = saturate(tex2D (_ControlXP, UVCtrl) * 2 - 1); - float4 splat_control2 = saturate(tex2D (_Control2XP, UVCtrl) * 2 - 1); - - - float4 col = tex2D(_SplatLower, UV * _LowerScale); - - if(_HideSplat0 == 0) - col = lerp(col, UNITY_SAMPLE_TEX2DARRAY(_SplatAlbedoArray, float3(UV * _Splat0Scale, 0)), splat_control.r); - if(_HideSplat1 == 0) - col = lerp(col, UNITY_SAMPLE_TEX2DARRAY(_SplatAlbedoArray, float3(UV * _Splat1Scale, 1)), splat_control.g); - if(_HideSplat2 == 0) - col = lerp(col, UNITY_SAMPLE_TEX2DARRAY(_SplatAlbedoArray, float3(UV * _Splat2Scale, 2)), splat_control.b); - if(_HideSplat3 == 0) - col = lerp(col, UNITY_SAMPLE_TEX2DARRAY(_SplatAlbedoArray, float3(UV * _Splat3Scale, 3)), splat_control.a); - - if (_TTerrainXP > 0) { - if(_HideSplat4 == 0) - col = lerp(col, UNITY_SAMPLE_TEX2DARRAY(_SplatAlbedoArray, float3(UV * _Splat4Scale, 4)), splat_control2.r); - if(_HideSplat5 == 0) - col = lerp(col, UNITY_SAMPLE_TEX2DARRAY(_SplatAlbedoArray, float3(UV * _Splat5Scale, 5)), splat_control2.g); - if(_HideSplat6 == 0) - col = lerp(col, UNITY_SAMPLE_TEX2DARRAY(_SplatAlbedoArray, float3(UV * _Splat6Scale, 6)), splat_control2.b); - if(_HideSplat7 == 0) - col = lerp(col, UNITY_SAMPLE_TEX2DARRAY(_SplatAlbedoArray, float3(UV * _Splat7Scale, 7)), splat_control2.a); - } - - if(_HideSplat8 == 0){ - float4 UpperAlbedo = tex2D (_SplatUpper, UV * _UpperScale); - col = lerp(col, UpperAlbedo, UpperAlbedo.a); - } - -#if defined(PREVIEW_ON) - -#else - if(_HideTerrainType == 0) { - float4 TerrainTypeAlbedo = tex2D (_TerrainTypeAlbedo, UV); - col = lerp(col, TerrainTypeAlbedo, TerrainTypeAlbedo.a*_TerrainTypeCapacity); - } -#endif - - half4 nrm; - nrm = tex2D (_NormalLower, UV * _LowerScaleNormal); - if(_HideSplat0 == 0) - nrm = lerp(nrm, UNITY_SAMPLE_TEX2DARRAY(_SplatNormalArray, float3(UV * _Splat0ScaleNormal, 0)), splat_control.r); - if(_HideSplat1 == 0) - nrm = lerp(nrm, UNITY_SAMPLE_TEX2DARRAY(_SplatNormalArray, float3(UV * _Splat1ScaleNormal, 1)), splat_control.g); - if(_HideSplat2 == 0) - nrm = lerp(nrm, UNITY_SAMPLE_TEX2DARRAY(_SplatNormalArray, float3(UV * _Splat2ScaleNormal, 2)), splat_control.b); - if(_HideSplat3 == 0) - nrm = lerp(nrm, UNITY_SAMPLE_TEX2DARRAY(_SplatNormalArray, float3(UV * _Splat3ScaleNormal, 3)), splat_control.a); - - if (_TTerrainXP > 0) { - if(_HideSplat4 == 0) - nrm = lerp(nrm, UNITY_SAMPLE_TEX2DARRAY(_SplatNormalArray, float3(UV * _Splat4ScaleNormal, 4)), splat_control2.r); - if(_HideSplat5 == 0) - nrm = lerp(nrm, UNITY_SAMPLE_TEX2DARRAY(_SplatNormalArray, float3(UV * _Splat5ScaleNormal, 5)), splat_control2.g); - if(_HideSplat6 == 0) - nrm = lerp(nrm, UNITY_SAMPLE_TEX2DARRAY(_SplatNormalArray, float3(UV * _Splat6ScaleNormal, 6)), splat_control2.b); - if(_HideSplat7 == 0) - nrm = lerp(nrm, UNITY_SAMPLE_TEX2DARRAY(_SplatNormalArray, float3(UV * _Splat7ScaleNormal, 7)), splat_control2.a); - } - - - if(_GeneratingNormal == 0){ - half4 TerrainNormal = tex2D(_TerrainNormal, UVCtrl ); - half3 TerrainNormalVector = UnpackNormalDXT5nm( half4(TerrainNormal.r, 1 - TerrainNormal.g, TerrainNormal.b, TerrainNormal.a)); - IN.SlopeLerp = dot(TerrainNormalVector, half3(0,0,1)); - //o.Albedo = IN.SlopeLerp; - o.Normal = BlendNormals(TerrainNormalVector , UnpackNormalDXT5nmScaled(nrm.rgbg, 1)); - - } - else - o.Normal = UnpackNormalDXT5nmScaled(nrm.rgbg, 1); - - - // o.Normal.y *= 0.5f; - //o.Normal = normalize(o.Normal); - - //half3 Emit = _SunAmbience.rgb * 2; - half3 Emit = 0; - -#if defined(PREVIEW_ON) - if (_Water > 0) col.rgb = ApplyWaterColor(WaterDepth, col.rgb); -#else - - if (_Slope > 0) { - o.Normal = half3(0, 0, 1); - half3 SlopeColor = 0; - if (_UseSlopeTex > 0) { - //col = 0; - float2 UV2 = IN.uv_Control * fixed2(1, 1) + half2(0, 0) - float2(-0.00, -0.00) / _GridScale; - float4 splat_control = tex2D(_SlopeTex, UV2); - SlopeColor = splat_control.rgb; - - } - else { - - if (IN.worldPos.y < _WaterLevel) { - if (IN.SlopeLerp > 0.75) SlopeColor = half3(0, 0.4, 1); - else SlopeColor = half3(0.6, 0, 1); - } - else if (IN.SlopeLerp > 0.999) SlopeColor = half3(0, 0.8, 0); - else if (IN.SlopeLerp > 0.95) SlopeColor = half3(0.3, 0.89, 0); - else if (IN.SlopeLerp > 0.80) SlopeColor = half3(0.5, 0.8, 0); - else SlopeColor = half3(1, 0, 0); - - } - Emit = SlopeColor * 0.8; - col.rgb = lerp(col.rgb, 0, 0.8); - } - else if (_Water > 0) col.rgb = ApplyWaterColor(WaterDepth, col.rgb); - - - if (_Grid > 0) { - if(_GridType == 1) - Emit += RenderGrid(_GridTexture, IN.uv_Control, 0, _GridScale); - else if (_GridType == 2) - Emit += RenderGrid(_GridTexture, IN.uv_Control, 0.0015, _GridScale / 5.12); - else if (_GridType == 3) - Emit += RenderGrid(_GridTexture, IN.uv_Control, 0.0015, 16); - else - Emit += RenderGrid(_GridTexture, IN.uv_Control, 0, _GridScale); - } + uniform int _ShaderID; + + // Most light values are already defined in SimpleLambert + float4 SpecularColor; + float WaterElevation; + + float LowerAlbedoTile; + float LowerNormalTile; + float Stratum0AlbedoTile; + float Stratum1AlbedoTile; + float Stratum2AlbedoTile; + float Stratum3AlbedoTile; + float Stratum4AlbedoTile; + float Stratum5AlbedoTile; + float Stratum6AlbedoTile; + float Stratum7AlbedoTile; + float Stratum0NormalTile; + float Stratum1NormalTile; + float Stratum2NormalTile; + float Stratum3NormalTile; + float Stratum4NormalTile; + float Stratum5NormalTile; + float Stratum6NormalTile; + float Stratum7NormalTile; + float UpperAlbedoTile; + float UpperNormalTile; + + float TerrainScale; + + sampler2D UtilitySamplerA; + sampler2D UtilitySamplerB; + sampler2D UtilitySamplerC; + sampler1D WaterRampSampler; + + sampler2D LowerAlbedoSampler; + sampler2D UpperAlbedoSampler; + sampler2D LowerNormalSampler; + + UNITY_DECLARE_TEX2DARRAY(_StratumAlbedoArray); + UNITY_DECLARE_TEX2DARRAY(_StratumNormalArray); + + uniform half4 unity_FogStart; + uniform half4 unity_FogEnd; - if (_Brush > 0) { - float2 BrushUv = ((IN.uv_Control - float2(_BrushUvX, _BrushUvY)) * _GridScale) / (_BrushSize * _GridScale * 0.002); + // This struct has to be named 'Input'. Changing it to VS_OUTPUT does not compile. + struct Input + { + float4 mPos : POSITION0; + // These are absolute world coordinates + float3 mTexWT : TEXCOORD1; + // these three vectors will hold a 3x3 rotation matrix + // that transforms from tangent to world space + half3 tspace0 : TEXCOORD2; // tangent.x, bitangent.x, normal.x + half3 tspace1 : TEXCOORD3; // tangent.y, bitangent.y, normal.y + half3 tspace2 : TEXCOORD4; // tangent.z, bitangent.z, normal.z + float3 mViewDirection : TEXCOORD5; + float4 nearScales : TEXCOORD6; + float4 farScales : TEXCOORD7; + + float SlopeLerp; + half fog; + }; + + float4 StratumAlbedoSampler(int layer, float2 uv) { + return UNITY_SAMPLE_TEX2DARRAY(_StratumAlbedoArray, float3(uv, layer)); + } + + float4 StratumNormalSampler(int layer, float2 uv) { + return UNITY_SAMPLE_TEX2DARRAY(_StratumNormalArray, float3(uv, layer)); + } + + float3 TangentToWorldSpace(Input v, float3 tnormal) { + float3 worldNormal; + if (UpperAlbedoTile < 1.0) { + float3 normal; + normal.xz = tex2D(UpperAlbedoSampler, TerrainScale * v.mTexWT.xy) * 2 - 1; + normal.z = normal.z * -1; + // reconstruct y component + normal.y = sqrt(1 - dot(normal.xz, normal.xz)); + + // when we read the terrain normals from a texture, we need to build our own TBN matrix + float3 tangent = cross(normal, float3(0, 0, 1)); + float3 bitangent = cross(normal, tangent); + float3 TBN0 = float3(tangent.x, bitangent.x, normal.x); + float3 TBN1 = float3(tangent.y, bitangent.y, normal.y); + float3 TBN2 = float3(tangent.z, bitangent.z, normal.z); + + worldNormal.x = dot(TBN0, tnormal); + worldNormal.y = dot(TBN1, tnormal); + worldNormal.z = dot(TBN2, tnormal); + } else { + // transform normal from tangent to world space using our vertex shader data + worldNormal.x = dot(v.tspace0, tnormal); + worldNormal.y = dot(v.tspace1, tnormal); + worldNormal.z = dot(v.tspace2, tnormal); + } + return worldNormal; + } + + // Because the underlying engine is different, the vertex shader has to differ considerably from fa. + // Still, we try to set up things in a way that we only have to minimally modify the fa pixel shaders + void TerrainVS(inout appdata_full v, out Input result) + { + result.nearScales = float4(Stratum0AlbedoTile.x, Stratum1AlbedoTile.x, Stratum2AlbedoTile.x, Stratum3AlbedoTile.x); + result.farScales = float4(Stratum0NormalTile.x, Stratum1NormalTile.x, Stratum2NormalTile.x, Stratum3NormalTile.x); + + // calculate output position + result.mPos = UnityObjectToClipPos(v.vertex); + + // Unity uses lower left origin, fa uses upper left, so we need to invert the y axis + // and for some ungodly reason we have a scale factor of 10. I don't know where this comes from. + result.mTexWT = v.vertex.xzy * float3(10, -10, 10); + // We also need to move the origin from the bottom corner to the top corner + result.mTexWT.y += 1.0 / TerrainScale; + + result.mViewDirection = normalize(v.vertex.xyz - _WorldSpaceCameraPos.xyz); + + half3 worldNormal = UnityObjectToWorldNormal(v.normal); + half3 worldTangent = UnityObjectToWorldDir(v.tangent.xyz); + // compute bitangent from cross product of normal and tangent + half tangentSign = v.tangent.w * unity_WorldTransformParams.w; + half3 worldBitangent = cross(worldNormal, worldTangent) * tangentSign; + // output the tangent space matrix + result.tspace0 = half3(worldTangent.x, worldBitangent.x, worldNormal.x); + result.tspace1 = half3(worldTangent.y, worldBitangent.y, worldNormal.y); + result.tspace2 = half3(worldTangent.z, worldBitangent.z, worldNormal.z); + + result.SlopeLerp = dot(v.normal, half3(0,1,0)); + float pos = length(UnityObjectToViewPos(v.vertex).xyz); + float diff = unity_FogEnd.x - unity_FogStart.x; + float invDiff = 1.0f / diff; + result.fog = saturate((unity_FogEnd.x - pos) * invDiff); + } + + float4 TerrainNormalsPS( Input inV ) + { + // sample all the textures we'll need + float4 mask = saturate(tex2D( UtilitySamplerA, inV.mTexWT * TerrainScale)); + + float4 lowerNormal = normalize(tex2D( LowerNormalSampler, inV.mTexWT * TerrainScale * LowerNormalTile ) * 2 - 1); + float4 stratum0Normal = normalize(StratumNormalSampler(0, inV.mTexWT * TerrainScale * Stratum0NormalTile) * 2 - 1); + float4 stratum1Normal = normalize(StratumNormalSampler(1, inV.mTexWT * TerrainScale * Stratum1NormalTile) * 2 - 1); + float4 stratum2Normal = normalize(StratumNormalSampler(2, inV.mTexWT * TerrainScale * Stratum2NormalTile) * 2 - 1); + float4 stratum3Normal = normalize(StratumNormalSampler(3, inV.mTexWT * TerrainScale * Stratum3NormalTile) * 2 - 1); + + // blend all normals together + float4 normal = lowerNormal; + if(_HideStratum0 == 0) + normal = lerp( normal, stratum0Normal, mask.x ); + if(_HideStratum1 == 0) + normal = lerp( normal, stratum1Normal, mask.y ); + if(_HideStratum2 == 0) + normal = lerp( normal, stratum2Normal, mask.z ); + if(_HideStratum3 == 0) + normal = lerp( normal, stratum3Normal, mask.w ); + normal.xyz = normalize( normal.xyz ); + + return normal; + } + + float4 TerrainPS( Input inV ) + { + // sample all the textures we'll need + float4 mask = saturate(tex2D( UtilitySamplerA, inV.mTexWT * TerrainScale) * 2 - 1); + float4 upperAlbedo = tex2D( UpperAlbedoSampler, inV.mTexWT * TerrainScale * UpperAlbedoTile); + float4 lowerAlbedo = tex2D( LowerAlbedoSampler, inV.mTexWT * TerrainScale * LowerAlbedoTile); + float4 stratum0Albedo = StratumAlbedoSampler(0, inV.mTexWT * TerrainScale * Stratum0AlbedoTile); + float4 stratum1Albedo = StratumAlbedoSampler(1, inV.mTexWT * TerrainScale * Stratum1AlbedoTile); + float4 stratum2Albedo = StratumAlbedoSampler(2, inV.mTexWT * TerrainScale * Stratum2AlbedoTile); + float4 stratum3Albedo = StratumAlbedoSampler(3, inV.mTexWT * TerrainScale * Stratum3AlbedoTile); + + // blend all albedos together + float4 albedo = lowerAlbedo; + if(_HideStratum0 == 0) + albedo = lerp( albedo, stratum0Albedo, mask.x ); + if(_HideStratum1 == 0) + albedo = lerp( albedo, stratum1Albedo, mask.y ); + if(_HideStratum2 == 0) + albedo = lerp( albedo, stratum2Albedo, mask.z ); + if(_HideStratum3 == 0) + albedo = lerp( albedo, stratum3Albedo, mask.w ); + albedo.xyz = lerp( albedo.xyz, upperAlbedo.xyz, upperAlbedo.w ); + + return albedo; + } + + float4 TerrainNormalsXP( Input pixel ) + { + float4 mask0 = saturate(tex2D(UtilitySamplerA,pixel.mTexWT*TerrainScale)); + float4 mask1 = saturate(tex2D(UtilitySamplerB,pixel.mTexWT*TerrainScale)); + + float4 lowerNormal = normalize(tex2D(LowerNormalSampler,pixel.mTexWT*TerrainScale*LowerNormalTile)*2-1); + float4 stratum0Normal = normalize(StratumNormalSampler(0,pixel.mTexWT*TerrainScale*Stratum0NormalTile)*2-1); + float4 stratum1Normal = normalize(StratumNormalSampler(1,pixel.mTexWT*TerrainScale*Stratum1NormalTile)*2-1); + float4 stratum2Normal = normalize(StratumNormalSampler(2,pixel.mTexWT*TerrainScale*Stratum2NormalTile)*2-1); + float4 stratum3Normal = normalize(StratumNormalSampler(3,pixel.mTexWT*TerrainScale*Stratum3NormalTile)*2-1); + float4 stratum4Normal = normalize(StratumNormalSampler(4,pixel.mTexWT*TerrainScale*Stratum4NormalTile)*2-1); + float4 stratum5Normal = normalize(StratumNormalSampler(5,pixel.mTexWT*TerrainScale*Stratum5NormalTile)*2-1); + float4 stratum6Normal = normalize(StratumNormalSampler(6,pixel.mTexWT*TerrainScale*Stratum6NormalTile)*2-1); + float4 stratum7Normal = normalize(StratumNormalSampler(7,pixel.mTexWT*TerrainScale*Stratum7NormalTile)*2-1); + + float4 normal = lowerNormal; + if(_HideStratum0 == 0) + normal = lerp(normal,stratum0Normal,mask0.x); + if(_HideStratum1 == 0) + normal = lerp(normal,stratum1Normal,mask0.y); + if(_HideStratum2 == 0) + normal = lerp(normal,stratum2Normal,mask0.z); + if(_HideStratum3 == 0) + normal = lerp(normal,stratum3Normal,mask0.w); + if(_HideStratum4 == 0) + normal = lerp(normal,stratum4Normal,mask1.x); + if(_HideStratum5 == 0) + normal = lerp(normal,stratum5Normal,mask1.y); + if(_HideStratum6 == 0) + normal = lerp(normal,stratum6Normal,mask1.z); + if(_HideStratum7 == 0) + normal = lerp(normal,stratum7Normal,mask1.w); + normal.xyz = normalize( normal.xyz ); + + return normal; + } + + float4 TerrainAlbedoXP( Input pixel) + { + float3 position = TerrainScale*pixel.mTexWT; + + float4 mask0 = saturate(tex2D(UtilitySamplerA,position)*2-1); + float4 mask1 = saturate(tex2D(UtilitySamplerB,position)*2-1); + + float4 lowerAlbedo = tex2D(LowerAlbedoSampler,position*LowerAlbedoTile); + float4 stratum0Albedo = StratumAlbedoSampler(0,position*Stratum0AlbedoTile); + float4 stratum1Albedo = StratumAlbedoSampler(1,position*Stratum1AlbedoTile); + float4 stratum2Albedo = StratumAlbedoSampler(2,position*Stratum2AlbedoTile); + float4 stratum3Albedo = StratumAlbedoSampler(3,position*Stratum3AlbedoTile); + float4 stratum4Albedo = StratumAlbedoSampler(4,position*Stratum4AlbedoTile); + float4 stratum5Albedo = StratumAlbedoSampler(5,position*Stratum5AlbedoTile); + float4 stratum6Albedo = StratumAlbedoSampler(6,position*Stratum6AlbedoTile); + float4 stratum7Albedo = StratumAlbedoSampler(7,position*Stratum7AlbedoTile); + float4 upperAlbedo = tex2D(UpperAlbedoSampler,position*UpperAlbedoTile); + + float4 albedo = lowerAlbedo; + if(_HideStratum0 == 0) + albedo = lerp(albedo,stratum0Albedo,mask0.x); + if(_HideStratum1 == 0) + albedo = lerp(albedo,stratum1Albedo,mask0.y); + if(_HideStratum2 == 0) + albedo = lerp(albedo,stratum2Albedo,mask0.z); + if(_HideStratum3 == 0) + albedo = lerp(albedo,stratum3Albedo,mask0.w); + if(_HideStratum4 == 0) + albedo = lerp(albedo,stratum4Albedo,mask1.x); + if(_HideStratum5 == 0) + albedo = lerp(albedo,stratum5Albedo,mask1.y); + if(_HideStratum6 == 0) + albedo = lerp(albedo,stratum6Albedo,mask1.z); + if(_HideStratum7 == 0) + albedo = lerp(albedo,stratum7Albedo,mask1.w); + if(_HideStratum8 == 0) + albedo.rgb = lerp(albedo.xyz,upperAlbedo.xyz,upperAlbedo.w); + + return albedo; + } + + float4 splatLerp(float4 t1, float4 t2, float t2height, float opacity, uniform float blurriness = 0.06) { + float height1 = 1; + float height2 = t2height * (1 - 2 * blurriness) + blurriness + opacity; + float ma = max(height1, height2) - blurriness; + float factor1 = max(height1 - ma, 0); + float factor2 = max(height2 - ma, 0); + return (t1 * factor1 + t2 * factor2) / (factor1 + factor2); + } + + float3 splatBlendNormal(float3 n1, float3 n2, float t2height, float opacity, uniform float blurriness = 0.06) { + float height1 = 1; + float height2 = t2height * (1 - 2 * blurriness) + blurriness + opacity; + float ma = max(height1, height2) - blurriness; + float factor1 = max(height1 - ma, 0); + float factor2 = max(height2 - ma, 0); + // These factors are to make low opacity normal maps more visible, + // as we notice small changes to the albedo maps more easily. + // The value of 0.5 is just eyeballed. + float factor1modified = pow(factor1 / (factor1 + factor2), 0.6); + float factor2modified = pow(factor2 / (factor1 + factor2), 0.6); + // UDN blending + return normalize(float3((n1.xy * factor1modified + n2.xy * factor2modified), n1.z)); + } + + /* # Sample a 2D 2x2 texture atlas # */ + /* To prevent bleeding from the neighboring tiles, we need to work with padding */ + float4 atlas2D(float2 uv, uniform float2 offset) { + uv.x = frac(uv.x) / 4 + offset.x + 0.125; + uv.y = frac(uv.y) / 4 + offset.y + 0.125; + return StratumNormalSampler(7, uv); + } + + float4 sampleAlbedoStratum(int layer, float2 position, uniform float2 scale, uniform float2 offset, uniform bool firstBatch) { + float4 albedo = StratumAlbedoSampler(layer, position * scale); + // store roughness in albedo alpha so we get the roughness splatting for free + if (firstBatch) { + albedo.a = atlas2D(position * scale, offset).y; + } else { + albedo.a = atlas2D(position * scale, offset).w; + } + return albedo; + } + + float4 sampleAlbedo(sampler2D s, float2 position, uniform float2 scale, uniform float2 offset, uniform bool firstBatch) { + float4 albedo = tex2D(s, position * scale); + // store roughness in albedo alpha so we get the roughness splatting for free + if (firstBatch) { + albedo.a = atlas2D(position * scale, offset).y; + } else { + albedo.a = atlas2D(position * scale, offset).w; + } + return albedo; + } + + float sampleHeight(float2 position, uniform float2 nearScale, uniform float2 farScale, uniform float2 offset, uniform bool firstBatch) { + float heightNear; + float heightFar; + if (firstBatch) { + heightNear = atlas2D(position * nearScale, offset).x; + heightFar = atlas2D(position * farScale, offset).x; + } else { + heightNear = atlas2D(position * nearScale, offset).z; + heightFar = atlas2D(position * farScale, offset).z; + } + return (heightNear + heightFar) / 2; + } + float3 Terrain301NormalsPS ( Input inV, uniform bool halfRange ) + { + float4 position; + position.xy = TerrainScale * inV.mTexWT; + // 30° rotation + float2x2 rotationMatrix = float2x2(float2(0.866, -0.5), float2(0.5, 0.866)); + position.zw = mul(position.xy, rotationMatrix); + + float4 mask0 = tex2D(UtilitySamplerA, position.xy); + float4 mask1 = tex2D(UtilitySamplerB, position.xy); + + if (halfRange) { + mask0 = saturate(mask0 * 2 - 1); + mask1 = saturate(mask1 * 2 - 1); + } + + float3 lowerNormal = normalize(tex2D(LowerNormalSampler, position.xy * LowerAlbedoTile.xx).rgb * 2 - 1); + float3 stratum0Normal = normalize(StratumNormalSampler(0, position.zw * Stratum0AlbedoTile.xx).rgb * 2 - 1); + float3 stratum1Normal = normalize(StratumNormalSampler(1, position.xy * Stratum1AlbedoTile.xx).rgb * 2 - 1); + float3 stratum2Normal = normalize(StratumNormalSampler(2, position.zw * Stratum2AlbedoTile.xx).rgb * 2 - 1); + float3 stratum3Normal = normalize(StratumNormalSampler(3, position.xy * Stratum3AlbedoTile.xx).rgb * 2 - 1); + float3 stratum4Normal = normalize(StratumNormalSampler(4, position.zw * Stratum4AlbedoTile.xx).rgb * 2 - 1); + float3 stratum5Normal = normalize(StratumNormalSampler(5, position.xy * Stratum5AlbedoTile.xx).rgb * 2 - 1); + float3 stratum6Normal = normalize(StratumNormalSampler(6, position.zw * Stratum6AlbedoTile.xx).rgb * 2 - 1); + + float stratum0Height = sampleHeight(position.zw, Stratum0AlbedoTile.xx, Stratum0NormalTile.xx, float2(0.5, 0.0), true); + float stratum1Height = sampleHeight(position.xy, Stratum1AlbedoTile.xx, Stratum1NormalTile.xx, float2(0.0, 0.5), true); + float stratum2Height = sampleHeight(position.zw, Stratum2AlbedoTile.xx, Stratum2NormalTile.xx, float2(0.5, 0.5), true); + float stratum3Height = sampleHeight(position.xy, Stratum3AlbedoTile.xx, Stratum3NormalTile.xx, float2(0.0, 0.0), false); + float stratum4Height = sampleHeight(position.zw, Stratum4AlbedoTile.xx, Stratum4NormalTile.xx, float2(0.5, 0.0), false); + float stratum5Height = sampleHeight(position.xy, Stratum5AlbedoTile.xx, Stratum5NormalTile.xx, float2(0.0, 0.5), false); + float stratum6Height = sampleHeight(position.zw, Stratum6AlbedoTile.xx, Stratum6NormalTile.xx, float2(0.5, 0.5), false); + + float3 normal = lowerNormal; + if(_HideStratum0 == 0) + normal = splatBlendNormal(normal, stratum0Normal, stratum0Height, mask0.x, SpecularColor.r); + if(_HideStratum1 == 0) + normal = splatBlendNormal(normal, stratum1Normal, stratum1Height, mask0.y, SpecularColor.r); + if(_HideStratum2 == 0) + normal = splatBlendNormal(normal, stratum2Normal, stratum2Height, mask0.z, SpecularColor.r); + if(_HideStratum3 == 0) + normal = splatBlendNormal(normal, stratum3Normal, stratum3Height, mask0.w, SpecularColor.r); + if(_HideStratum4 == 0) + normal = splatBlendNormal(normal, stratum4Normal, stratum4Height, mask1.x, SpecularColor.r); + if(_HideStratum5 == 0) + normal = splatBlendNormal(normal, stratum5Normal, stratum5Height, mask1.y, SpecularColor.r); + if(_HideStratum6 == 0) + normal = splatBlendNormal(normal, stratum6Normal, stratum6Height, mask1.z, SpecularColor.r); + + return normal; + } + + float4 Terrain301AlbedoPS ( Input inV, uniform bool halfRange ) + { + float4 position; + position.xy = TerrainScale * inV.mTexWT; + // 30° rotation + float2x2 rotationMatrix = float2x2(float2(0.866, -0.5), float2(0.5, 0.866)); + position.zw = mul(position.xy, rotationMatrix); + + float4 mask0 = tex2D(UtilitySamplerA, position.xy); + float4 mask1 = tex2D(UtilitySamplerB, position.xy); + + if (halfRange) { + mask0 = saturate(mask0 * 2 - 1); + mask1 = saturate(mask1 * 2 - 1); + } + + // This shader wouldn't compile because it would have to store too many variables if we didn't use this trick in the vertex shader + float4 lowerAlbedo = sampleAlbedo(LowerAlbedoSampler, position.xy, LowerAlbedoTile.xx, float2(0.0, 0.0), true); + float4 stratum0Albedo = sampleAlbedoStratum(0, position.zw, inV.nearScales.xx, float2(0.5, 0.0), true); + float4 stratum1Albedo = sampleAlbedoStratum(1, position.xy, inV.nearScales.yy, float2(0.0, 0.5), true); + float4 stratum2Albedo = sampleAlbedoStratum(2, position.zw, inV.nearScales.zz, float2(0.5, 0.5), true); + float4 stratum3Albedo = sampleAlbedoStratum(3, position.xy, inV.nearScales.ww, float2(0.0, 0.0), false); + float4 stratum4Albedo = sampleAlbedoStratum(4, position.zw, Stratum4AlbedoTile.xx, float2(0.5, 0.0), false); + float4 stratum5Albedo = sampleAlbedoStratum(5, position.xy, Stratum5AlbedoTile.xx, float2(0.0, 0.5), false); + float4 stratum6Albedo = sampleAlbedoStratum(6, position.zw, Stratum6AlbedoTile.xx, float2(0.5, 0.5), false); + + float stratum0Height = sampleHeight(position.zw, inV.nearScales.xx, inV.farScales.xx, float2(0.5, 0.0), true); + float stratum1Height = sampleHeight(position.xy, inV.nearScales.yy, inV.farScales.yy, float2(0.0, 0.5), true); + float stratum2Height = sampleHeight(position.zw, inV.nearScales.zz, inV.farScales.zz, float2(0.5, 0.5), true); + float stratum3Height = sampleHeight(position.xy, inV.nearScales.ww, inV.farScales.ww, float2(0.0, 0.0), false); + float stratum4Height = sampleHeight(position.zw, Stratum4AlbedoTile.xx, Stratum4NormalTile.xx, float2(0.5, 0.0), false); + float stratum5Height = sampleHeight(position.xy, Stratum5AlbedoTile.xx, Stratum5NormalTile.xx, float2(0.0, 0.5), false); + float stratum6Height = sampleHeight(position.zw, Stratum6AlbedoTile.xx, Stratum6NormalTile.xx, float2(0.5, 0.5), false); + + float4 albedo = lowerAlbedo; + if(_HideStratum0 == 0) + albedo = splatLerp(albedo, stratum0Albedo, stratum0Height, mask0.x, SpecularColor.r); + if(_HideStratum1 == 0) + albedo = splatLerp(albedo, stratum1Albedo, stratum1Height, mask0.y, SpecularColor.r); + if(_HideStratum2 == 0) + albedo = splatLerp(albedo, stratum2Albedo, stratum2Height, mask0.z, SpecularColor.r); + if(_HideStratum3 == 0) + albedo = splatLerp(albedo, stratum3Albedo, stratum3Height, mask0.w, SpecularColor.r); + if(_HideStratum4 == 0) + albedo = splatLerp(albedo, stratum4Albedo, stratum4Height, mask1.x, SpecularColor.r); + if(_HideStratum5 == 0) + albedo = splatLerp(albedo, stratum5Albedo, stratum5Height, mask1.y, SpecularColor.r); + if(_HideStratum6 == 0) + albedo = splatLerp(albedo, stratum6Albedo, stratum6Height, mask1.z, SpecularColor.r); + float4 mapwide = StratumAlbedoSampler(7, position.xy); + if(_HideStratum7 == 0) + albedo.rgb = lerp(albedo.rgb, mapwide.rgb, mapwide.a); + + // We need to add 0.01 as the reflection disappears at 0 + float roughness = saturate(albedo.a * mask1.w * 2 + 0.01); + + return float4(albedo.rgb, roughness); + } + + float3 renderBrush(float2 uv){ + float3 Emit = 0; + if (_Brush > 0) { + uv.y = 1-uv.y; + float2 BrushUv = ((uv - float2(_BrushUvX, _BrushUvY)) * _GridScale) / (_BrushSize * _GridScale * 0.002); fixed4 BrushColor = tex2D(_BrushTex, BrushUv); if (BrushUv.x >= 0 && BrushUv.y >= 0 && BrushUv.x <= 1 && BrushUv.y <= 1) { @@ -390,55 +597,136 @@ Properties { Emit += half3(0, BrushColor.r * 0.1, BrushColor.r * 0.2) * 0.2; } } -#endif + return Emit; + } - //FOG - col.rgb = lerp(0, col.rgb, IN.fog); - Emit = lerp(unity_FogColor, Emit, IN.fog); + float3 renderSlope(Input IN){ + float3 Emit = 0; + if (_Slope > 0) { + half3 SlopeColor = 0; + if (_UseSlopeTex > 0) { + float4 splat_control = tex2D(_SlopeTex, IN.mTexWT); + SlopeColor = splat_control.rgb; + } + else { - o.Albedo = col; - o.Emission = Emit; + if (IN.mTexWT.y * TerrainScale < WaterElevation) { + if (IN.SlopeLerp > 0.75) SlopeColor = half3(0, 0.4, 1); + else SlopeColor = half3(0.6, 0, 1); + } + else if (IN.SlopeLerp > 0.999) SlopeColor = half3(0, 0.8, 0); + else if (IN.SlopeLerp > 0.95) SlopeColor = half3(0.3, 0.89, 0); + else if (IN.SlopeLerp > 0.80) SlopeColor = half3(0.5, 0.8, 0); + else SlopeColor = half3(1, 0, 0); - if(_Area > 0){ - fixed3 BlackEmit = -1; - fixed3 Albedo = 0; - if(IN.worldPos.x < _AreaRect.x){ - o.Emission = BlackEmit; - o.Albedo = Albedo; - } - else if(IN.worldPos.x > _AreaRect.z){ - o.Emission = BlackEmit; - o.Albedo = Albedo; - } - else if(IN.worldPos.z < _AreaRect.y - _GridScale){ - o.Emission = BlackEmit; - o.Albedo = Albedo; - } - else if(IN.worldPos.z > _AreaRect.w - _GridScale){ - o.Emission = BlackEmit; - o.Albedo = Albedo; } + Emit = SlopeColor * 0.8; + // col.rgb = lerp(col.rgb, 0, 0.8); } + return Emit; + } - if (_TTerrainXP > 0) { - o.Gloss = (1 - col.a); - o.Specular = col.a; + float3 renderTerrainType(float3 albedo, float2 uv){ + if(_HideTerrainType == 0) { + float4 TerrainTypeAlbedo = tex2D (_TerrainTypeAlbedo, uv); + albedo = lerp(albedo, TerrainTypeAlbedo, TerrainTypeAlbedo.a*_TerrainTypeCapacity); + } + return albedo; + } + + float4 RenderGrid(sampler2D _GridTex, float2 uv_Control, float Offset, float GridScale) { + fixed4 GridColor = tex2D(_GridTex, uv_Control * GridScale + float2(-Offset, Offset)); + fixed4 GridFinal = fixed4(0, 0, 0, GridColor.a); + if (_GridCamDist < 1) { + GridFinal.rgb = lerp(GridFinal.rgb, fixed3(1, 1, 1), GridColor.r * lerp(1, 0, _GridCamDist)); + GridFinal.rgb = lerp(GridFinal.rgb, fixed3(0, 1, 0), GridColor.g * lerp(1, 0, _GridCamDist)); + GridFinal.rgb = lerp(GridFinal.rgb, fixed3(0, 1, 0), GridColor.b * lerp(0, 1, _GridCamDist)); } else { - o.Gloss = (1 - col.a) + 0.01; - o.Specular = col.a + 0.01; + GridFinal.rgb = lerp(GridFinal.rgb, fixed3(0, 1, 0), GridColor.b); } + GridFinal *= GridColor.a; + half CenterGridSize = lerp(0.005, 0.015, _GridCamDist) / _GridScale; + if (uv_Control.x > 0.5 - CenterGridSize && uv_Control.x < 0.5 + CenterGridSize) + GridFinal.rgb = fixed3(0.4, 1, 0); + else if (uv_Control.y > 0.5 - CenterGridSize && uv_Control.y < 0.5 + CenterGridSize) + GridFinal.rgb = fixed3(0.4, 1, 0); - o.Alpha = col.a; + return GridFinal; } - ENDCG - -} - - -//FallBack "Diffuse" + float3 renderGridOverlay(float2 uv){ + float3 Emit = 0; + if (_Grid > 0) { + if(_GridType == 1) + Emit += RenderGrid(_GridTexture, uv, 0, _GridScale); + else if (_GridType == 2) + Emit += RenderGrid(_GridTexture, uv, 0.0015, _GridScale / 5.12); + else if (_GridType == 3) + Emit += RenderGrid(_GridTexture, uv, 0.0015, 16); + else + Emit += RenderGrid(_GridTexture, uv, 0, _GridScale); + } + return Emit; + } + + // The decals get written directly in the gBuffer, so here we only prepare all necessary terrain inputs. + // The actual lighting calculations happen in Assets\GFX\Shaders\Deferred\Internal-DeferredShading.shader + // This way the decals and the terrain have consistent lighting + void surf(Input inV, inout CustomSurfaceOutput o) + { + float3 position = TerrainScale * inV.mTexWT.xyz; + if (_ShaderID == 0) + { + float4 albedo = TerrainPS(inV); + o.Albedo = albedo.rgb; + o.Alpha = albedo.a; // for specularity + + float3 normal = TangentToWorldSpace(inV, TerrainNormalsPS(inV).xyz); + o.wNormal = normalize(normal); + + o.WaterDepth = tex2D(UtilitySamplerC, position.xy).g; + } + else if (_ShaderID == 1) + { + float4 albedo = TerrainAlbedoXP(inV); + o.Albedo = albedo.rgb; + o.Alpha = albedo.a; // for specularity + + float3 normal = TangentToWorldSpace(inV, TerrainNormalsXP(inV).xyz); + o.wNormal = normalize(normal); + + o.WaterDepth = tex2D(UtilitySamplerC, position.xy).g; + } + else if (_ShaderID == 2) + { + float4 albedo = Terrain301AlbedoPS(inV, true); + o.Albedo = albedo.rgb; + o.Roughness = albedo.a; + + float3 normal = TangentToWorldSpace(inV, Terrain301NormalsPS(inV, true).xyz); + o.wNormal = normalize(normal); + + o.WaterDepth = tex2D(UpperAlbedoSampler, position.xy).b; + + o.MapShadow = tex2D(UpperAlbedoSampler, position.xy).w; + } + else { + o.Albedo = float3(1, 0, 1); + } + + o.Emission = renderBrush(position.xy); + o.Emission += renderSlope(inV); + o.Albedo = renderTerrainType(o.Albedo, position.xy); + o.Emission += renderGridOverlay(position.xy); + + // fog + o.Albedo = lerp(0, o.Albedo, inV.fog); + o.Emission = lerp(unity_FogColor, o.Emission, inV.fog); + } + ENDCG + } } diff --git a/Assets/GFX/Shaders/FaWater.shader b/Assets/GFX/Shaders/FaWater.shader deleted file mode 100644 index 20aecf79..00000000 --- a/Assets/GFX/Shaders/FaWater.shader +++ /dev/null @@ -1,284 +0,0 @@ -Shader "MapEditor/FaWater" { - Properties { - waterColor ("waterColor", Color) = (0.0, 0.7, 1.5, 1) - sunColor ("Sun Color", Color) = (1.1, 0.7, 0.5, 1) - _WaterData ("Water Data", 2D) = "white" {} - SkySampler("SkySampler", CUBE) = "" {} - ReflectionSampler ("ReflectionSampler", 2D) = "white" {} - - NormalSampler0 ("NormalSampler0", 2D) = "white" {} - NormalSampler1 ("NormalSampler1", 2D) = "white" {} - NormalSampler2 ("NormalSampler2", 2D) = "white" {} - NormalSampler3 ("NormalSampler3", 2D) = "white" {} - - _GridScale ("Grid Scale", Range (0, 2048)) = 512 - } - SubShader { - Tags { "Queue"="Transparent+6" "RenderType"="Transparent" } - - GrabPass - { - "_WaterGrabTexture" - } - - //Blend SrcAlpha OneMinusSrcAlpha - //Offset 0, -20000 - - - CGPROGRAM - #pragma target 3.5 - - #pragma surface surf Lambert vertex:vert alpha noambient - #pragma exclude_renderers gles - #pragma multi_compile ___ UNITY_HDR_ON - - - //************ Water Params - - uniform float _WaterScaleX, _WaterScaleZ; - float waveCrestThreshold = 1; - float3 waveCrestColor = float3(1,1,1); - float refractionScale = 0.015; - - // 3 repeat rate for 3 texture layers - float4 normalRepeatRate = float4(0.0009, 0.009, 0.05, 0.5); - - // 3 vectors of normal movements - //float2 normal1Movement = float2(0.5, -0.95); - float2 normal1Movement = float2(5.5, -9.95); - float2 normal2Movement = float2(0.05, -0.095); - float2 normal3Movement = float2(0.01, 0.03); - float2 normal4Movement = float2(0.0005, 0.0009); - - float fresnelBias = 0.1; - float fresnelPower = 1.5; - - float SunShininess; - float sunReflectionAmount; - float unitreflectionAmount; - float skyreflectionAmount; - float2 waterLerp; - float3 SunDirection; - - float SunGlow; - - fixed4 waterColor, sunColor; - half _GridScale; - - int _Area; - half4 _AreaRect; - - //*********** End Water Params - sampler2D _WaterGrabTexture; - - - half4 LightingEmpty (SurfaceOutput s, half3 lightDir, half atten) { - half4 c; - c.rgb = s.Albedo; - c.a = s.Alpha; - return c; - } - - struct Input { - //float4 position : SV_POSITION; - float2 uv_UtilitySamplerC : TEXCOORD0; - float4 mLayer01 : TEXCOORD1; - float4 mLayer23 : TEXCOORD2; - //float2 mLayer2 : TEXCOORD3; - //float2 mLayer3 : TEXCOORD4; - float3 mViewVec : TEXCOORD3; - float4 mScreenPos : TEXCOORD4; - float4 AddVar : TEXCOORD5; - float4 grabUV; - float3 worldPos; - //float3 viewDir; - }; - - void vert (inout appdata_full v, out Input o){ - UNITY_INITIALIZE_OUTPUT(Input,o); - //o.position = UnityObjectToClipPos (v.vertex); - o.mScreenPos = ComputeNonStereoScreenPos(UnityObjectToClipPos (v.vertex)); - //o.mScreenPos.xy /= o.mScreenPos.w; - //o.mScreenPos.xy /= _ScreenParams.xy * 0.1; - - //o.mTexUV = v.texcoord0; - float2 WaterLayerUv = float2(v.vertex.x * _WaterScaleX, -v.vertex.z * _WaterScaleZ); - //o.mLayer0 = (WaterLayerUv * _WaterScale + (float2(5.5, -9.95) * _Time.y)) * 0.0009; - //o.mLayer1 = (WaterLayerUv * _WaterScale + (float2(0.05, -0.095) * _Time.y)) * 0.09; - //o.mLayer2 = (WaterLayerUv * _WaterScale + (float2(0.01, 0.03) * _Time.y)) * 0.05; - //o.mLayer3 = (WaterLayerUv * _WaterScale + (float2(0.0005, 0.0009) * _Time.y)) * 0.5; - - float timer = _Time.y * 10; - o.mLayer01.xy = (WaterLayerUv + (normal1Movement * timer)) * normalRepeatRate.x; - o.mLayer01.zw = (WaterLayerUv + (normal2Movement * timer)) * normalRepeatRate.y; - o.mLayer23.xy = (WaterLayerUv + (normal3Movement * timer)) * normalRepeatRate.z; - o.mLayer23.zw = (WaterLayerUv + (normal4Movement * timer)) * normalRepeatRate.w; - - //o.mScreenPos = mul (UNITY_MATRIX_MVP, float4(0,0,0,1)); - //o.mScreenPos.xy /= o.mScreenPos.w; - - o.mViewVec = mul (unity_ObjectToWorld, v.vertex).xyz - _WorldSpaceCameraPos; - o.mViewVec = normalize(o.mViewVec); - o.AddVar = float4(length(_WorldSpaceCameraPos - mul(unity_ObjectToWorld, v.vertex).xyz), 0, 0, 0); - float4 hpos = UnityObjectToClipPos (v.vertex); - o.grabUV = ComputeGrabScreenPos(hpos); - //v.color = _Abyss; - } - - - uniform sampler2D _UtilitySamplerC; - uniform sampler2D RefractionSampler; - sampler2D ReflectionSampler; - sampler2D _ReflectionTexture; - uniform sampler2D NormalSampler0, NormalSampler1, NormalSampler2, NormalSampler3; - //samplerCUBE _Reflection; - samplerCUBE SkySampler; - - - void surf (Input IN, inout SurfaceOutput o) { - - float4 ViewportScaleOffset = float4((_ScreenParams.x / _ScreenParams.y) * 1, 1.0, (_ScreenParams.x / _ScreenParams.y) * -0.25, 0); - //float3 SunDirection = normalize(float3( -0.2 , -0.967, -0.453)); - // calculate the depth of water at this pixel, we use this to decide - // how to shade and it should become lesser as we get shallower - // so that we don't have a sharp line - float4 waterTexture = tex2D( _UtilitySamplerC, IN.uv_UtilitySamplerC * float2(-1, 1) + float2(1 / (_WaterScaleX * 1) + 1, 1 / (_WaterScaleZ * 1)) ); - - - float waterDepth = clamp( waterTexture.g * 10, 0, 1); - - // calculate the correct viewvector - float3 viewVector = normalize(IN.mViewVec); - //viewVector = WorldSpaceViewDir(float4(0, 0, 1, 1)); - //viewVector = IN.viewDir; - float OneOverW = 1 / IN.mScreenPos.w; - - - // calculate the background pixel - float4 backGroundPixels = tex2Dproj( _WaterGrabTexture, UNITY_PROJ_COORD(IN.grabUV) ); - - #ifdef UNITY_HDR_ON - //backGroundPixels.rgb = exp2(-backGroundPixels.rgb); - #endif - //float4 col = tex2Dproj( _MyGrabTexture3, UNITY_PROJ_COORD(IN.grabUV)); - - float mask = saturate(backGroundPixels.a * 255); - - // calculate the normal we will be using for the water surface - float4 W0 = tex2D( NormalSampler0, IN.mLayer01.xy ); - float4 W1 = tex2D( NormalSampler1, IN.mLayer01.zw ); - float4 W2 = tex2D( NormalSampler2, IN.mLayer23.xy ); - float4 W3 = tex2D( NormalSampler3, IN.mLayer23.zw ); - - float4 sum = W0 + W1 + W2 + W3; - waveCrestThreshold = 1.2; - float waveCrest = saturate( sum.a - waveCrestThreshold ); - - // average, scale, bias and normalize - float3 N = 2.0 * sum.xyz - 4.0; - - // flatness - N = normalize(N.xzy); - float3 up = float3(0, 1, 0); - N = lerp(up, N, waterTexture.r); - - // calculate the reflection vector - float3 R = reflect( viewVector, N ); - - // calculate the sky reflection color - float4 skyReflection = texCUBE( SkySampler, R ); - - // get the correct coordinate for sampling refraction and reflection - - float2 screenPos = UNITY_PROJ_COORD(IN.mScreenPos.xy / IN.mScreenPos.w); - - float4 refractionPos = IN.mScreenPos; - refractionPos.xy -= refractionScale * N.xz * OneOverW * 0.1; - - float4 GrabUvPos = IN.grabUV; - GrabUvPos.xy -= N.xz * OneOverW * 0.1 * refractionScale; - //GrabUvPos.xy = clamp(GrabUvPos.xy, 0, 1); - // calculate the refract pixel, corrected for fetching a non-refractable pixel - float4 refractedPixels = tex2Dproj(_WaterGrabTexture, UNITY_PROJ_COORD(GrabUvPos)); // UNITY_PROJ_COORD(IN.grabUV) - // because the range of the alpha value that we use for the water is very small - // we multiply by a large number and then saturate - // this will also help in the case where we filter to an intermediate value - refractedPixels.xyz = lerp(refractedPixels, backGroundPixels, saturate((IN.AddVar.x - 40) / 30 ) ).xyz; //255 - - // - // calculate the reflected value at this pixel - // - float4 reflectedPixels = tex2D( _ReflectionTexture, refractionPos); - - - float NDotL = saturate(dot(-viewVector, N)); - float fresnel = saturate(pow(saturate((1 - NDotL)), fresnelPower) + fresnelBias); - - // figure out the sun reflection - float SunDotR = saturate(dot(-R, SunDirection)); - float3 sunReflection = pow( SunDotR, SunShininess) * sunColor.rgb * 2; - - // lerp the reflections together - reflectedPixels = lerp( skyReflection, reflectedPixels, saturate(unitreflectionAmount * reflectedPixels.w)); - //reflectedPixels = skyReflection; - - // we want to lerp in some of the water color based on depth, but - // not totally on depth as it gets clamped - float waterLerp2 = clamp(waterDepth, waterLerp.x, waterLerp.y); - - // lerp in the color - refractedPixels.xyz = lerp( refractedPixels.xyz, waterColor.rgb * 2, waterLerp2); - - // implement the water depth into the reflection - float depthReflectionAmount = 10; - skyreflectionAmount *= saturate(waterDepth * depthReflectionAmount); - - // lerp the reflection into the refraction - refractedPixels = lerp( refractedPixels, reflectedPixels, saturate(skyreflectionAmount * fresnel)); - //refractedPixels = skyReflection; - //refractedPixels = - - // add in the sky reflection - sunReflection = sunReflection * fresnel; - refractedPixels.xyz += sunReflection; - - // Lerp in a wave crest - waveCrestColor = float3(1,1,1); - refractedPixels.xyz = lerp( refractedPixels.xyz, waveCrestColor, ( 1 - waterTexture.a ) * waveCrest); - - - float4 returnPixels = refractedPixels; - - returnPixels.a = waterDepth; - //clip(waterDepth - 0.01); - - - if(_Area > 0){ - fixed3 BlackEmit = -1; - fixed3 Albedo = 0; - if(IN.worldPos.x < _AreaRect.x){ - returnPixels.rgb = 0; - } - else if(IN.worldPos.x > _AreaRect.z){ - returnPixels.rgb = 0; - } - else if(IN.worldPos.z < _AreaRect.y - _GridScale){ - returnPixels.rgb = 0; - } - else if(IN.worldPos.z > _AreaRect.w - _GridScale){ - returnPixels.rgb = 0; - } - } - - - o.Albedo = 0; - //color.rgb = exp2(-color.rgb); - o.Emission = returnPixels.rgb; - //o.Emission = tex2Dproj(_WaterGrabTexture, UNITY_PROJ_COORD(GrabUvPos)); - //o.Emission = 1; - o.Alpha = returnPixels.a; - //o.Alpha = 1; - } - ENDCG - } -} \ No newline at end of file diff --git a/Assets/GFX/Shaders/FaWaterShader.shader b/Assets/GFX/Shaders/FaWaterShader.shader new file mode 100644 index 00000000..a946f430 --- /dev/null +++ b/Assets/GFX/Shaders/FaWaterShader.shader @@ -0,0 +1,273 @@ +Shader "FAShaders/Water" { + Properties { + waterColor ("waterColor", Color) = (0, 0, 0, 0) + SunColor ("Sun Color", Color) = (0, 0, 0, 0) + waterLerp ("water Lerp", Vector) = (0, 0, 0, 0) + SunDirection ("Sun Direction", Vector) = (0, 0, 0, 0) + SunShininess ("SunShininess", Float) = 0 + skyreflectionAmount ("sky reflection Amount", Float) = 0 + refractionScale ("refraction Scale", Float) = 0 + normal1Movement ("normal 1 movement", Vector) = (0, 0, 0, 0) + normal2Movement ("normal 2 movement", Vector) = (0, 0, 0, 0) + normal3Movement ("normal 3 movement", Vector) = (0, 0, 0, 0) + normal4Movement ("normal 4 movement", Vector) = (0, 0, 0, 0) + normalRepeatRate ("normal repeat rate", Vector) = (0, 0, 0, 0) + + SkySampler("SkySampler", CUBE) = "" {} + NormalSampler0 ("NormalSampler0", 2D) = "white" {} + NormalSampler1 ("NormalSampler1", 2D) = "white" {} + NormalSampler2 ("NormalSampler2", 2D) = "white" {} + NormalSampler3 ("NormalSampler3", 2D) = "white" {} + UtilitySamplerC ("water properties", 2D) = "white" {} + } + SubShader { + Tags { "Queue"="Transparent+6" "RenderType"="Transparent" } + + GrabPass { "RefractionSampler" } + + CGPROGRAM + #pragma target 3.5 + + #pragma surface surf Lambert vertex:vert alpha noambient + #pragma exclude_renderers gles + + + //************ FA Water Params + float4 ViewportScaleOffset; + + float waveCrestThreshold; + float3 waveCrestColor; + + samplerCUBE SkySampler; + sampler2D NormalSampler0, NormalSampler1, NormalSampler2, NormalSampler3; + sampler2D RefractionSampler; + sampler2D UtilitySamplerC; + + float4 waterColor; + float2 waterLerp; + float refractionScale; + float unitreflectionAmount; + float skyreflectionAmount; + + float4 normalRepeatRate; + + float2 normal1Movement; + float2 normal2Movement; + float2 normal3Movement; + float2 normal4Movement; + + float SunShininess; + float3 SunDirection; + float4 SunColor; + + //*********** End FA Water Params + + uniform float _WaterScaleX, _WaterScaleZ; + half _GridScale; + int _Area; + half4 _AreaRect; + uniform int _ShaderID; + + + struct Input { + float2 mLayer0 : TEXCOORD0; + float2 mLayer1 : TEXCOORD1; + float2 mLayer2 : TEXCOORD2; + float2 mLayer3 : TEXCOORD3; + float3 mViewVec : TEXCOORD4; + float4 mScreenPos : TEXCOORD5; + float2 mTexUV : TEXCOORD6; + float3 worldPos; + }; + + void vert (inout appdata_full v, out Input result){ + UNITY_INITIALIZE_OUTPUT(Input,result); + + result.mTexUV = v.vertex.xz * float2(1, -1); + + result.mScreenPos = ComputeNonStereoScreenPos(UnityObjectToClipPos (v.vertex)); + + float2 WaterLayerUv = float2(v.vertex.x * _WaterScaleX, -v.vertex.z * _WaterScaleZ); + float timer = _Time.y * 10; + result.mLayer0 = (WaterLayerUv + (normal1Movement * timer)) * normalRepeatRate.x; + result.mLayer1 = (WaterLayerUv + (normal2Movement * timer)) * normalRepeatRate.y; + result.mLayer2 = (WaterLayerUv + (normal3Movement * timer)) * normalRepeatRate.z; + result.mLayer3 = (WaterLayerUv + (normal4Movement * timer)) * normalRepeatRate.w; + + float3 ViewVec = _WorldSpaceCameraPos - mul(unity_ObjectToWorld, v.vertex).xyz; + ViewVec = normalize (ViewVec); + // The game uses a different coordinate system, so we need to correct for that + ViewVec.z *= -1; + result.mViewVec = ViewVec; + } + + float FresnelSchlick(float dot, float F0) + { + return F0 + (1.0 - F0) * pow(1.0 - dot, 5.0); + } + + float NormalDistribution(float3 n, float3 h, float roughness) + { + float a2 = roughness*roughness; + float nDotH = max(dot(n, h), 0.0); + float nDotH2 = nDotH*nDotH; + + float num = a2; + float denom = nDotH2 * (a2 - 1.0) + 1.0; + denom = 3.14159265359 * denom * denom; + + return num / denom; + } + + float GeometrySchlick(float nDotV, float roughness) + { + float r = (roughness + 1.0); + float k = (r*r) / 8.0; + + float num = nDotV; + float denom = nDotV * (1.0 - k) + k; + + return num / denom; + } + + float GeometrySmith(float3 n, float nDotV, float3 l, float roughness) + { + float nDotL = max(dot(n, l), 0.0); + float gs2 = GeometrySchlick(nDotV, roughness); + float gs1 = GeometrySchlick(nDotL, roughness); + + return gs1 * gs2; + } + + float3 calculateSunReflection(float3 R, float3 v, float3 n) + { + // for unknown reasons the game seems to mess with the SunColor, so we also need to correct + if (_ShaderID == 0) { + SunColor *= 2; + } else { + SunColor *= 0.75; + } + + float3 color; + // Legacy fallback for the old behaviour, so we don't change all maps accidentally. + // This check works because the default sun position is under the horizon. + if (SunDirection.y < 0.0) { + float3 sunReflection = pow(saturate(dot(-R, SunDirection)), SunShininess) * SunColor; + color = sunReflection * FresnelSchlick(max(dot(n, v), 0.0), 0.06); + } else { + float roughness = 1.0 / SunShininess; + float facingSpecular = 0.02; + float3 l = SunDirection; + float3 h = normalize(v + l); + float nDotL = max(dot(n, l), 0.0); + float nDotV = abs(dot(n, v)) + 0.001; + float3 F = FresnelSchlick(max(dot(h, v), 0.0), facingSpecular).xxx; + float NDF = NormalDistribution(n, h, roughness); + float G = GeometrySmith(n, nDotV, l, roughness); + + float3 numerator = 3.14159265359 * NDF * G * F; + // add 0.0001 to avoid division by zero + float denominator = 4.0 * nDotV * nDotL + 0.0001; + float3 reflected = numerator / denominator; + color = reflected * SunColor * nDotL; + } + return color; + } + + void surf (Input inV, inout SurfaceOutput o) { + ViewportScaleOffset = float4(1, 1, 0, 0); + waveCrestColor = float3(1,1,1); + waveCrestThreshold = 1; + + // calculate the depth of water at this pixel + float4 waterTexture = tex2D( UtilitySamplerC, inV.mTexUV ); + float waterDepth = waterTexture.g; + + float3 viewVector = normalize(inV.mViewVec); + + // get perspective correct coordinate for sampling from the other textures + // the screenPos is then in 0..1 range with the origin at the top left of the screen + float OneOverW = 1.0 / inV.mScreenPos.w; + inV.mScreenPos.xyz *= OneOverW; + float2 screenPos = inV.mScreenPos.xy * ViewportScaleOffset.xy; + screenPos += ViewportScaleOffset.zw; + + // calculate the normal we will be using for the water surface + float4 W0 = tex2D( NormalSampler0, inV.mLayer0 ); + float4 W1 = tex2D( NormalSampler1, inV.mLayer1 ); + float4 W2 = tex2D( NormalSampler2, inV.mLayer2 ); + float4 W3 = tex2D( NormalSampler3, inV.mLayer3 ); + + float4 sum = W0 + W1 + W2 + W3; + float waveCrest = saturate( sum.a - waveCrestThreshold ); + + // scale, bias and normalize + float3 N = 2.0 * sum.xyz - 4.0; + N = normalize(N.xzy); + + float3 R = reflect(-viewVector, N); + + // get the correct coordinate for sampling refraction and reflection + float2 refractionPos = screenPos; + refractionPos -= sqrt(waterDepth) * refractionScale * N.xz * OneOverW * 0.1; + + float4 refractedPixels = tex2D(RefractionSampler, refractionPos); + // the editor doesn't have info about unit reflections, so we will skip these operations here + + // we want to lerp in the water color based on depth, but clamped + float factor = clamp(waterDepth, waterLerp.x, waterLerp.y); + refractedPixels.rgb = lerp(refractedPixels.rgb, waterColor, factor); + + float4 skyReflection = texCUBE(SkySampler, R); + float3 reflections = skyReflection.rgb; + + // Schlick approximation for fresnel + float NDotV = saturate(dot(viewVector, N)); + float fresnel = FresnelSchlick(NDotV, 0.08); + + // the default value of 1.5 is way to high, but we want to preserve manually set values in existing maps + if (skyreflectionAmount == 1.5) + skyreflectionAmount = 1.0; + float3 water = lerp(refractedPixels, reflections, saturate(fresnel * skyreflectionAmount)); + + // add in the sun reflection + float3 sunReflection = calculateSunReflection(R, viewVector, N); + // there appears to be a problem with the editor sometimes falsely reading + // the red channel of the waterTexture as 0 even if it isn't. For now we + // disable the behviour + // sunReflection *= waterTexture.r; + water += sunReflection; + + // Lerp in the wave crests + water = lerp(water, waveCrestColor, (1 - waterTexture.a) * (1 - waterTexture.b) * waveCrest); + + // in contrast to the game we don't need an alpha mask here to combat artifacts + float4 returnPixels; + returnPixels.rgb = water; + returnPixels.a = 1; + + + if(_Area > 0){ + if(inV.worldPos.x < _AreaRect.x){ + returnPixels.rgb = 0; + } + else if(inV.worldPos.x > _AreaRect.z){ + returnPixels.rgb = 0; + } + else if(inV.worldPos.z < _AreaRect.y - _GridScale){ + returnPixels.rgb = 0; + } + else if(inV.worldPos.z > _AreaRect.w - _GridScale){ + returnPixels.rgb = 0; + } + } + + + o.Albedo = 0; + // By using the emission we bypass all shading operations by Unity + o.Emission = returnPixels.rgb; + o.Alpha = returnPixels.a; + } + ENDCG + } +} \ No newline at end of file diff --git a/Assets/GFX/Shaders/FaWater.shader.meta b/Assets/GFX/Shaders/FaWaterShader.shader.meta similarity index 100% rename from Assets/GFX/Shaders/FaWater.shader.meta rename to Assets/GFX/Shaders/FaWaterShader.shader.meta diff --git a/Assets/GFX/Shaders/PropShader.shader b/Assets/GFX/Shaders/PropShader.shader index 0e29622b..a926e543 100644 --- a/Assets/GFX/Shaders/PropShader.shader +++ b/Assets/GFX/Shaders/PropShader.shader @@ -16,11 +16,9 @@ Shader "Custom/PropShader" { LOD 200 CGPROGRAM - // Physically based Standard lighting model, and enable shadows on all light types - #pragma surface surf BlinnPhong addshadow noshadowmask halfasview interpolateview - - // Use shader model 3.0 target, to get nicer looking lighting - #pragma target 3.0 + #pragma surface surf SimpleLambert addshadow noshadowmask halfasview interpolateview + #include "Assets/GFX/Shaders/SimpleLambert.cginc" + #pragma target 3.5 CBUFFER_START(UnityPerMaterial) @@ -72,9 +70,8 @@ Shader "Custom/PropShader" { return normal.xzy; }*/ - void surf (Input IN, inout SurfaceOutput o) { - // Albedo comes from a texture tinted by color - half4 c = tex2D (_MainTex, IN.uv_MainTex) * 0.65; + void surf (Input IN, inout CustomSurfaceOutput o) { + half4 c = tex2D (_MainTex, IN.uv_MainTex); o.Albedo = c.rgb; //half4 n = tex2D(_BumpMap, IN.uv_MainTex); o.Normal = UnpackNormalDXT5nm(tex2D(_BumpMap, IN.uv_MainTex)); diff --git a/Assets/GFX/Shaders/SimpleLambert.cginc b/Assets/GFX/Shaders/SimpleLambert.cginc index e7123614..2615697e 100644 --- a/Assets/GFX/Shaders/SimpleLambert.cginc +++ b/Assets/GFX/Shaders/SimpleLambert.cginc @@ -1,92 +1,67 @@ -uniform half _LightingMultiplier; -uniform fixed4 _SunColor; -uniform fixed4 _SunAmbience; -uniform fixed4 _ShadowColor; -uniform half _SpecularAmmount; - -/* -float4 LightingSimpleLambertLight (SurfaceOutput s, float3 lightDir, half atten) { - float NdotL = dot (lightDir, s.Normal); - - float4 c; - float3 spec = float3(0,0,0); - - float3 light = _SunColor.rgb * 2 * saturate(NdotL) * atten + _SunAmbience.rgb * 2; - light = _LightingMultiplier * light + _ShadowColor.rgb * 2 * (1 - light); - - - c.rgb = (s.Albedo + spec) * light; - c.a = s.Alpha; - return c; -}*/ - +float3 ShadowFillColor; +float LightingMultiplier; +float3 SunDirection; +float3 SunAmbience; +float3 SunColor; +struct CustomSurfaceOutput +{ + fixed3 Albedo; + float3 wNormal; // world space normal, we use this one to prevent the automatic tangent to world space conversion + half3 Emission; // for overlays + half WaterDepth; + half MapShadow; // manual terrain shadow that is defined by input texture + half Roughness; + half Alpha; + + // this only exists to make the surface shader compile and is unused + float3 Normal; +}; -inline float4 LightingSimpleLambertLight (SurfaceOutput s, UnityLight light) +inline float4 LightingSimpleLambertLight(CustomSurfaceOutput s, UnityLight l) { - float NdotL = dot (light.dir, s.Normal); - fixed diff = max (0, dot (s.Normal, light.dir)); - - float4 c; - float R = light.dir - 2.0f * NdotL * s.Normal; - float3 viewDirection = light.dir; - float specular = pow(saturate(dot(R, viewDirection)), 80);// * specAmount; - float3 spec = float3(0,0,0); - - float3 lighting = light.color * saturate(NdotL) + specular; - lighting = _LightingMultiplier * lighting + _ShadowColor.rgb * 2 * (1 - lighting); - - - c.rgb = (s.Albedo + spec) * lighting; - c.a = s.Alpha; + float4 c; + s.Normal.z *= -1; + float dotLightNormal = dot(SunDirection, s.Normal); + float3 light = SunColor * saturate(dotLightNormal) * 1 + SunAmbience; + light = LightingMultiplier * light + (1 - light) * ShadowFillColor; + c.rgb = s.Albedo * light; + c.a = s.Alpha; return c; } -inline fixed4 LightingSimpleLambert_PrePass (SurfaceOutput s, half4 light) +inline fixed4 LightingSimpleLambert_PrePass(CustomSurfaceOutput s, half4 light) { fixed4 c; - c.rgb = s.Albedo * light.rgb; - c.rgb = s.Albedo; - c.a = s.Alpha; + c.rgb = s.Albedo; + c.a = s.Alpha; return c; } -inline fixed4 LightingSimpleLambert (SurfaceOutput s, UnityGI gi) +inline fixed4 LightingSimpleLambert(CustomSurfaceOutput s, UnityGI gi) { fixed4 c; c = LightingSimpleLambertLight (s, gi.light); - //#ifdef UNITY_LIGHT_FUNCTION_APPLY_INDIRECT - // c.rgb += s.Albedo * gi.indirect.diffuse; - //#endif - return c; } -inline half4 LightingSimpleLambert_Deferred (SurfaceOutput s, UnityGI gi, out half4 outGBuffer0, out half4 outGBuffer1, out half4 outGBuffer2) +inline half4 LightingSimpleLambert_Deferred(CustomSurfaceOutput s, UnityGI gi, out half4 outGBuffer0, out half4 outGBuffer1, out half4 outGBuffer2) { - UnityStandardData data; - data.diffuseColor = s.Albedo; - data.occlusion = 1; - data.specularColor = 0; - data.smoothness = s.Gloss; - data.normalWorld = s.Normal; - - UnityStandardDataToGbuffer(data, outGBuffer0, outGBuffer1, outGBuffer2); + outGBuffer0 = half4(s.Albedo, s.Alpha); - half4 emission = half4(s.Emission, 1); + outGBuffer1 = half4(s.MapShadow, s.WaterDepth, s.Roughness, 0); - //#ifdef UNITY_LIGHT_FUNCTION_APPLY_INDIRECT - // emission.rgb += s.Albedo * gi.indirect.diffuse; - //#endif + outGBuffer2 = half4(s.wNormal * 0.5f + 0.5f, 0); + half4 emission = half4(s.Emission, 1); return emission; } inline void LightingSimpleLambert_GI ( - SurfaceOutput s, + CustomSurfaceOutput s, UnityGIInput data, inout UnityGI gi) { - gi = UnityGlobalIllumination (data, 1.0, s.Normal); + gi = UnityGlobalIllumination (data, 1.0, s.wNormal); } \ No newline at end of file diff --git a/Assets/GFX/Terrain/ScmapTerrain.asset b/Assets/GFX/Terrain/ScmapTerrain.asset index f5ffdf18..31c5f22c 100644 Binary files a/Assets/GFX/Terrain/ScmapTerrain.asset and b/Assets/GFX/Terrain/ScmapTerrain.asset differ diff --git a/Assets/GFX/Terrain/TerrainShader.mat b/Assets/GFX/Terrain/Terrain.mat similarity index 79% rename from Assets/GFX/Terrain/TerrainShader.mat rename to Assets/GFX/Terrain/Terrain.mat index 9ac7058b..0f86b105 100644 --- a/Assets/GFX/Terrain/TerrainShader.mat +++ b/Assets/GFX/Terrain/Terrain.mat @@ -7,16 +7,13 @@ Material: m_CorrespondingSourceObject: {fileID: 0} m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} - m_Name: TerrainShader + m_Name: Terrain m_Shader: {fileID: 4800000, guid: 07332981e20e66d40a9ee102d13a9be8, type: 3} m_Parent: {fileID: 0} m_ModifiedSerializedProperties: 0 m_ValidKeywords: [] m_InvalidKeywords: - _AREA_ON - - _BRUSH_ON - - _HIDETERRAINTYPE_ON - - _USESLOPETEX_ON m_LightmapFlags: 5 m_EnableInstancingVariants: 0 m_DoubleSidedGI: 0 @@ -27,6 +24,30 @@ Material: m_SavedProperties: serializedVersion: 3 m_TexEnvs: + - LowerAlbedoSampler: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - LowerNormalSampler: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - UpperAlbedoSampler: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - UtilitySamplerA: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - UtilitySamplerB: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - UtilitySamplerC: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} - _BrushTex: m_Texture: {fileID: 0} m_Scale: {x: 1, y: 1} @@ -235,6 +256,14 @@ Material: m_Texture: {fileID: 0} m_Scale: {x: 1, y: 1} m_Offset: {x: 0, y: 0} + - _StratumAlbedoArray: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _StratumNormalArray: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} - _TerrainNormal: m_Texture: {fileID: 0} m_Scale: {x: 1, y: 1} @@ -251,8 +280,48 @@ Material: m_Texture: {fileID: 0} m_Scale: {x: 1, y: 1} m_Offset: {x: 0, y: 0} - m_Ints: [] + m_Ints: + - _Brush: 0 + - _BrushPainting: 0 + - _GeneratingNormal: 0 + - _Grid: 0 + - _GridType: 0 + - _HideStratum0: 0 + - _HideStratum1: 0 + - _HideStratum2: 0 + - _HideStratum3: 0 + - _HideStratum4: 0 + - _HideStratum5: 0 + - _HideStratum6: 0 + - _HideStratum7: 0 + - _HideStratum8: 0 + - _HideTerrainType: 0 + - _Slope: 0 + - _UseSlopeTex: 0 m_Floats: + - LightingMultiplier: 1 + - LowerAlbedoTile: 256 + - LowerNormalTile: 117.02857 + - Stratum0AlbedoTile: 256 + - Stratum0NormalTile: 256 + - Stratum1AlbedoTile: 292.57144 + - Stratum1NormalTile: 89.04348 + - Stratum2AlbedoTile: 60.952385 + - Stratum2NormalTile: 512 + - Stratum3AlbedoTile: 170.66667 + - Stratum3NormalTile: 256 + - Stratum4AlbedoTile: 256 + - Stratum4NormalTile: 256 + - Stratum5AlbedoTile: 256 + - Stratum5NormalTile: 256 + - Stratum6AlbedoTile: 256 + - Stratum6NormalTile: 256 + - Stratum7AlbedoTile: 256 + - Stratum7NormalTile: 256 + - TerrainScale: 0.0009765625 + - UpperAlbedoTile: 8 + - UpperNormalTile: 1 + - WaterElevation: 0 - _AbyssLevel: 0.25 - _Area: 1 - _AreaHeight: 128 @@ -314,6 +383,11 @@ Material: - _WaterScaleX: 1024 - _WaterScaleZ: 1024 m_Colors: + - ShadowFillColor: {r: 0, g: 0, b: 0, a: 1} + - SpecularColor: {r: 0, g: 0, b: 0, a: 1} + - SunAmbience: {r: 0, g: 0, b: 0, a: 1} + - SunColor: {r: 0, g: 0, b: 0, a: 1} + - SunDirection: {r: 0, g: -1, b: 0, a: 1} - _Abyss: {r: 0.005190316, g: 0.051962737, b: 0.2352941, a: 1} - _Color: {r: 1, g: 1, b: 1, a: 1} - _Deep: {r: 0.22577855, g: 0.4590157, b: 0.5294118, a: 1} diff --git a/Assets/GFX/Terrain/TerrainShader.mat.meta b/Assets/GFX/Terrain/Terrain.mat.meta similarity index 100% rename from Assets/GFX/Terrain/TerrainShader.mat.meta rename to Assets/GFX/Terrain/Terrain.mat.meta diff --git a/Assets/GFX/Terrain/WaterShader.mat b/Assets/GFX/Terrain/Water.mat similarity index 82% rename from Assets/GFX/Terrain/WaterShader.mat rename to Assets/GFX/Terrain/Water.mat index eb005bc7..6a59f2da 100644 --- a/Assets/GFX/Terrain/WaterShader.mat +++ b/Assets/GFX/Terrain/Water.mat @@ -7,7 +7,7 @@ Material: m_CorrespondingSourceObject: {fileID: 0} m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} - m_Name: WaterShader + m_Name: Water m_Shader: {fileID: 4800000, guid: a4a5e3f2343cea345a332945c7bba4e7, type: 3} m_Parent: {fileID: 0} m_ModifiedSerializedProperties: 0 @@ -16,7 +16,7 @@ Material: m_LightmapFlags: 5 m_EnableInstancingVariants: 0 m_DoubleSidedGI: 0 - m_CustomRenderQueue: 3000 + m_CustomRenderQueue: -1 stringTagMap: {} disabledShaderPasses: [] m_LockedProperties: @@ -55,6 +55,10 @@ Material: m_Texture: {fileID: 0} m_Scale: {x: 1, y: 1} m_Offset: {x: 0, y: 0} + - UtilitySamplerC: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} - _BumpMap: m_Texture: {fileID: 0} m_Scale: {x: 1, y: 1} @@ -105,6 +109,7 @@ Material: m_Offset: {x: 0, y: 0} m_Ints: [] m_Floats: + - SunShininess: 78.9 - _BumpScale: 1 - _Cutoff: 0.5 - _DetailNormalMapScale: 1 @@ -121,9 +126,19 @@ Material: - _WaterScaleX: 1024 - _WaterScaleZ: 1024 - _ZWrite: 1 + - refractionScale: 0.38000003 + - skyreflectionAmount: 0.67800003 m_Colors: + - SunColor: {r: 0.52, g: 0.47, b: 0.35, a: 0} + - SunDirection: {r: 0.09954818, g: -0.9626309, b: 0.2518569, a: 0} - _Color: {r: 1, g: 1, b: 1, a: 1} - _EmissionColor: {r: 0, g: 0, b: 0, a: 1} + - normal1Movement: {r: -0, g: 0.01, b: 0, a: 0} + - normal2Movement: {r: -0.086602546, g: 0.049999997, b: 0, a: 0} + - normal3Movement: {r: 0.001307336, g: 0.014942921, b: 0, a: 0} + - normal4Movement: {r: 0.0049497476, g: 0.0049497476, b: 0, a: 0} + - normalRepeatRate: {r: 0.08, g: 0.009, b: 0.06, a: 0.5} - sunColor: {r: 0.40637133, g: 0.23704992, b: 0.16932137, a: 1} - - waterColor: {r: 0, g: 0.35, b: 0.75, a: 1} + - waterColor: {r: 0, g: 0.7, b: 1.5, a: 0} + - waterLerp: {r: 0.064, g: 0.119, b: 0, a: 0} m_BuildTextureStacks: [] diff --git a/Assets/GFX/Terrain/WaterShader.mat.meta b/Assets/GFX/Terrain/Water.mat.meta similarity index 100% rename from Assets/GFX/Terrain/WaterShader.mat.meta rename to Assets/GFX/Terrain/Water.mat.meta diff --git a/Assets/MapEditor.unity b/Assets/MapEditor.unity index 9e2eb353..734f8afa 100644 --- a/Assets/MapEditor.unity +++ b/Assets/MapEditor.unity @@ -16909,6 +16909,24 @@ CanvasRenderer: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 186840662} m_CullTransparentMesh: 0 +--- !u!224 &186977229 stripped +RectTransform: + m_CorrespondingSourceObject: {fileID: 224682333546820604, guid: 148b00b6296385545afdc97e83496834, + type: 3} + m_PrefabInstance: {fileID: 1566107984} + m_PrefabAsset: {fileID: 0} +--- !u!114 &186977231 stripped +MonoBehaviour: + m_CorrespondingSourceObject: {fileID: 114549324857000576, guid: 148b00b6296385545afdc97e83496834, + type: 3} + m_PrefabInstance: {fileID: 1566107984} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 8c60df5520bfea740b1f3db0c3478272, type: 3} + m_Name: + m_EditorClassIdentifier: --- !u!1 &187349553 GameObject: m_ObjectHideFlags: 0 @@ -47434,7 +47452,7 @@ Camera: serializedVersion: 2 m_Bits: 2560 m_RenderingPath: 1 - m_TargetTexture: {fileID: 987366519} + m_TargetTexture: {fileID: 583577642} m_TargetDisplay: 0 m_TargetEye: 3 m_HDR: 0 @@ -51707,6 +51725,44 @@ RectTransform: m_AnchoredPosition: {x: 0, y: 0} m_SizeDelta: {x: -20, y: 0} m_Pivot: {x: 0.5, y: 0.5} +--- !u!84 &583577642 +RenderTexture: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_Name: + m_ImageContentsHash: + serializedVersion: 2 + Hash: 00000000000000000000000000000000 + m_ForcedFallbackFormat: 4 + m_DownscaleFallback: 0 + m_IsAlphaChannelOptional: 0 + serializedVersion: 5 + m_Width: 256 + m_Height: 256 + m_AntiAliasing: 1 + m_MipCount: -1 + m_DepthStencilFormat: 90 + m_ColorFormat: 8 + m_MipMap: 0 + m_GenerateMips: 1 + m_SRGB: 0 + m_UseDynamicScale: 0 + m_BindMS: 0 + m_EnableCompatibleFormat: 1 + m_EnableRandomWrite: 0 + m_TextureSettings: + serializedVersion: 2 + m_FilterMode: 1 + m_Aniso: 1 + m_MipBias: 0 + m_WrapU: 1 + m_WrapV: 1 + m_WrapW: 1 + m_Dimension: 2 + m_VolumeDepth: 1 + m_ShadowSamplingMode: 2 --- !u!1001 &584136142 PrefabInstance: m_ObjectHideFlags: 0 @@ -87520,44 +87576,6 @@ RectTransform: type: 3} m_PrefabInstance: {fileID: 986485559} m_PrefabAsset: {fileID: 0} ---- !u!84 &987366519 -RenderTexture: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_Name: - m_ImageContentsHash: - serializedVersion: 2 - Hash: 00000000000000000000000000000000 - m_ForcedFallbackFormat: 4 - m_DownscaleFallback: 0 - m_IsAlphaChannelOptional: 0 - serializedVersion: 5 - m_Width: 256 - m_Height: 256 - m_AntiAliasing: 1 - m_MipCount: -1 - m_DepthStencilFormat: 90 - m_ColorFormat: 8 - m_MipMap: 0 - m_GenerateMips: 1 - m_SRGB: 0 - m_UseDynamicScale: 0 - m_BindMS: 0 - m_EnableCompatibleFormat: 1 - m_EnableRandomWrite: 0 - m_TextureSettings: - serializedVersion: 2 - m_FilterMode: 1 - m_Aniso: 1 - m_MipBias: 0 - m_WrapU: 1 - m_WrapV: 1 - m_WrapW: 1 - m_Dimension: 2 - m_VolumeDepth: 1 - m_ShadowSamplingMode: 2 --- !u!1001 &991035797 PrefabInstance: m_ObjectHideFlags: 0 @@ -119082,182 +119100,6 @@ CanvasRenderer: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 1345426714} m_CullTransparentMesh: 0 ---- !u!1001 &1347066541 -PrefabInstance: - m_ObjectHideFlags: 0 - serializedVersion: 2 - m_Modification: - serializedVersion: 3 - m_TransformParent: {fileID: 212914999} - m_Modifications: - - target: {fileID: 114659475374214984, guid: b68527975f2edce489c9336fa9650c39, - type: 3} - propertyPath: onValueChanged.m_PersistentCalls.m_Calls.Array.size - value: 2 - objectReference: {fileID: 0} - - target: {fileID: 114659475374214984, guid: b68527975f2edce489c9336fa9650c39, - type: 3} - propertyPath: onValueChanged.m_PersistentCalls.m_Calls.Array.data[1].m_Mode - value: 1 - objectReference: {fileID: 0} - - target: {fileID: 114659475374214984, guid: b68527975f2edce489c9336fa9650c39, - type: 3} - propertyPath: onValueChanged.m_PersistentCalls.m_Calls.Array.data[0].m_Target - value: - objectReference: {fileID: 1334852568} - - target: {fileID: 114659475374214984, guid: b68527975f2edce489c9336fa9650c39, - type: 3} - propertyPath: onValueChanged.m_PersistentCalls.m_Calls.Array.data[1].m_Target - value: - objectReference: {fileID: 2126589256} - - target: {fileID: 114659475374214984, guid: b68527975f2edce489c9336fa9650c39, - type: 3} - propertyPath: onValueChanged.m_PersistentCalls.m_Calls.Array.data[1].m_CallState - value: 2 - objectReference: {fileID: 0} - - target: {fileID: 114659475374214984, guid: b68527975f2edce489c9336fa9650c39, - type: 3} - propertyPath: onValueChanged.m_PersistentCalls.m_Calls.Array.data[0].m_MethodName - value: ToogleShader - objectReference: {fileID: 0} - - target: {fileID: 114659475374214984, guid: b68527975f2edce489c9336fa9650c39, - type: 3} - propertyPath: onValueChanged.m_PersistentCalls.m_Calls.Array.data[1].m_MethodName - value: RefreshLayerUI - objectReference: {fileID: 0} - - target: {fileID: 114659475374214984, guid: b68527975f2edce489c9336fa9650c39, - type: 3} - propertyPath: onValueChanged.m_PersistentCalls.m_Calls.Array.data[0].m_TargetAssemblyTypeName - value: ScmapEditor, Assembly-CSharp - objectReference: {fileID: 0} - - target: {fileID: 114659475374214984, guid: b68527975f2edce489c9336fa9650c39, - type: 3} - propertyPath: onValueChanged.m_PersistentCalls.m_Calls.Array.data[1].m_TargetAssemblyTypeName - value: EditMap.StratumInfo, Assembly-CSharp - objectReference: {fileID: 0} - - target: {fileID: 114659475374214984, guid: b68527975f2edce489c9336fa9650c39, - type: 3} - propertyPath: onValueChanged.m_PersistentCalls.m_Calls.Array.data[1].m_Arguments.m_ObjectArgumentAssemblyTypeName - value: UnityEngine.Object, UnityEngine - objectReference: {fileID: 0} - - target: {fileID: 114733048155632102, guid: b68527975f2edce489c9336fa9650c39, - type: 3} - propertyPath: m_Text - value: Use TTerrainXP shader - objectReference: {fileID: 0} - - target: {fileID: 224654035474944384, guid: b68527975f2edce489c9336fa9650c39, - type: 3} - propertyPath: m_Pivot.x - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 224654035474944384, guid: b68527975f2edce489c9336fa9650c39, - type: 3} - propertyPath: m_Pivot.y - value: 0.5 - objectReference: {fileID: 0} - - target: {fileID: 224654035474944384, guid: b68527975f2edce489c9336fa9650c39, - type: 3} - propertyPath: m_RootOrder - value: 1 - objectReference: {fileID: 0} - - target: {fileID: 224654035474944384, guid: b68527975f2edce489c9336fa9650c39, - type: 3} - propertyPath: m_AnchorMax.x - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 224654035474944384, guid: b68527975f2edce489c9336fa9650c39, - type: 3} - propertyPath: m_AnchorMax.y - value: 1 - objectReference: {fileID: 0} - - target: {fileID: 224654035474944384, guid: b68527975f2edce489c9336fa9650c39, - type: 3} - propertyPath: m_AnchorMin.x - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 224654035474944384, guid: b68527975f2edce489c9336fa9650c39, - type: 3} - propertyPath: m_AnchorMin.y - value: 1 - objectReference: {fileID: 0} - - target: {fileID: 224654035474944384, guid: b68527975f2edce489c9336fa9650c39, - type: 3} - propertyPath: m_SizeDelta.x - value: 282.7 - objectReference: {fileID: 0} - - target: {fileID: 224654035474944384, guid: b68527975f2edce489c9336fa9650c39, - type: 3} - propertyPath: m_SizeDelta.y - value: 20 - objectReference: {fileID: 0} - - target: {fileID: 224654035474944384, guid: b68527975f2edce489c9336fa9650c39, - type: 3} - propertyPath: m_LocalPosition.x - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 224654035474944384, guid: b68527975f2edce489c9336fa9650c39, - type: 3} - propertyPath: m_LocalPosition.y - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 224654035474944384, guid: b68527975f2edce489c9336fa9650c39, - type: 3} - propertyPath: m_LocalPosition.z - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 224654035474944384, guid: b68527975f2edce489c9336fa9650c39, - type: 3} - propertyPath: m_LocalRotation.w - value: 1 - objectReference: {fileID: 0} - - target: {fileID: 224654035474944384, guid: b68527975f2edce489c9336fa9650c39, - type: 3} - propertyPath: m_LocalRotation.x - value: -0 - objectReference: {fileID: 0} - - target: {fileID: 224654035474944384, guid: b68527975f2edce489c9336fa9650c39, - type: 3} - propertyPath: m_LocalRotation.y - value: -0 - objectReference: {fileID: 0} - - target: {fileID: 224654035474944384, guid: b68527975f2edce489c9336fa9650c39, - type: 3} - propertyPath: m_LocalRotation.z - value: -0 - objectReference: {fileID: 0} - - target: {fileID: 224654035474944384, guid: b68527975f2edce489c9336fa9650c39, - type: 3} - propertyPath: m_AnchoredPosition.x - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 224654035474944384, guid: b68527975f2edce489c9336fa9650c39, - type: 3} - propertyPath: m_AnchoredPosition.y - value: -54 - objectReference: {fileID: 0} - m_RemovedComponents: [] - m_RemovedGameObjects: [] - m_AddedGameObjects: [] - m_AddedComponents: [] - m_SourcePrefab: {fileID: 100100000, guid: b68527975f2edce489c9336fa9650c39, type: 3} ---- !u!224 &1347066542 stripped -RectTransform: - m_CorrespondingSourceObject: {fileID: 224654035474944384, guid: b68527975f2edce489c9336fa9650c39, - type: 3} - m_PrefabInstance: {fileID: 1347066541} - m_PrefabAsset: {fileID: 0} ---- !u!114 &1347066543 stripped -MonoBehaviour: - m_CorrespondingSourceObject: {fileID: 114659475374214984, guid: b68527975f2edce489c9336fa9650c39, - type: 3} - m_PrefabInstance: {fileID: 1347066541} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 0} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 9085046f02f69544eb97fd06b6048fe2, type: 3} - m_Name: - m_EditorClassIdentifier: --- !u!1 &1347463400 GameObject: m_ObjectHideFlags: 0 @@ -138091,6 +137933,178 @@ CanvasRenderer: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 1564735887} m_CullTransparentMesh: 0 +--- !u!1001 &1566107984 +PrefabInstance: + m_ObjectHideFlags: 0 + serializedVersion: 2 + m_Modification: + serializedVersion: 3 + m_TransformParent: {fileID: 212914999} + m_Modifications: + - target: {fileID: 1541227934717128, guid: 148b00b6296385545afdc97e83496834, type: 3} + propertyPath: m_Name + value: ShaderName + objectReference: {fileID: 0} + - target: {fileID: 114300400988709808, guid: 148b00b6296385545afdc97e83496834, + type: 3} + propertyPath: m_Text + value: Shader Name + objectReference: {fileID: 0} + - target: {fileID: 114549324857000576, guid: 148b00b6296385545afdc97e83496834, + type: 3} + propertyPath: OnEndEdit.m_PersistentCalls.m_Calls.Array.size + value: 2 + objectReference: {fileID: 0} + - target: {fileID: 114549324857000576, guid: 148b00b6296385545afdc97e83496834, + type: 3} + propertyPath: OnEndEdit.m_PersistentCalls.m_Calls.Array.data[1].m_Mode + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 114549324857000576, guid: 148b00b6296385545afdc97e83496834, + type: 3} + propertyPath: OnEndEdit.m_PersistentCalls.m_Calls.Array.data[0].m_Target + value: + objectReference: {fileID: 1334852568} + - target: {fileID: 114549324857000576, guid: 148b00b6296385545afdc97e83496834, + type: 3} + propertyPath: OnEndEdit.m_PersistentCalls.m_Calls.Array.data[1].m_Target + value: + objectReference: {fileID: 2126589256} + - target: {fileID: 114549324857000576, guid: 148b00b6296385545afdc97e83496834, + type: 3} + propertyPath: OnEndEdit.m_PersistentCalls.m_Calls.Array.data[1].m_CallState + value: 2 + objectReference: {fileID: 0} + - target: {fileID: 114549324857000576, guid: 148b00b6296385545afdc97e83496834, + type: 3} + propertyPath: OnEndEdit.m_PersistentCalls.m_Calls.Array.data[0].m_MethodName + value: ToogleShader + objectReference: {fileID: 0} + - target: {fileID: 114549324857000576, guid: 148b00b6296385545afdc97e83496834, + type: 3} + propertyPath: OnEndEdit.m_PersistentCalls.m_Calls.Array.data[1].m_MethodName + value: RefreshLayerUI + objectReference: {fileID: 0} + - target: {fileID: 114549324857000576, guid: 148b00b6296385545afdc97e83496834, + type: 3} + propertyPath: OnEndEdit.m_PersistentCalls.m_Calls.Array.data[0].m_TargetAssemblyTypeName + value: ScmapEditor, Assembly-CSharp + objectReference: {fileID: 0} + - target: {fileID: 114549324857000576, guid: 148b00b6296385545afdc97e83496834, + type: 3} + propertyPath: OnEndEdit.m_PersistentCalls.m_Calls.Array.data[1].m_TargetAssemblyTypeName + value: EditMap.StratumInfo, Assembly-CSharp + objectReference: {fileID: 0} + - target: {fileID: 114549324857000576, guid: 148b00b6296385545afdc97e83496834, + type: 3} + propertyPath: OnEndEdit.m_PersistentCalls.m_Calls.Array.data[1].m_Arguments.m_ObjectArgumentAssemblyTypeName + value: UnityEngine.Object, UnityEngine + objectReference: {fileID: 0} + - target: {fileID: 224682333546820604, guid: 148b00b6296385545afdc97e83496834, + type: 3} + propertyPath: m_Pivot.x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 224682333546820604, guid: 148b00b6296385545afdc97e83496834, + type: 3} + propertyPath: m_Pivot.y + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 224682333546820604, guid: 148b00b6296385545afdc97e83496834, + type: 3} + propertyPath: m_AnchorMax.x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 224682333546820604, guid: 148b00b6296385545afdc97e83496834, + type: 3} + propertyPath: m_AnchorMax.y + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 224682333546820604, guid: 148b00b6296385545afdc97e83496834, + type: 3} + propertyPath: m_AnchorMin.x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 224682333546820604, guid: 148b00b6296385545afdc97e83496834, + type: 3} + propertyPath: m_AnchorMin.y + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 224682333546820604, guid: 148b00b6296385545afdc97e83496834, + type: 3} + propertyPath: m_SizeDelta.x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 224682333546820604, guid: 148b00b6296385545afdc97e83496834, + type: 3} + propertyPath: m_SizeDelta.y + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 224682333546820604, guid: 148b00b6296385545afdc97e83496834, + type: 3} + propertyPath: m_LocalPosition.x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 224682333546820604, guid: 148b00b6296385545afdc97e83496834, + type: 3} + propertyPath: m_LocalPosition.y + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 224682333546820604, guid: 148b00b6296385545afdc97e83496834, + type: 3} + propertyPath: m_LocalPosition.z + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 224682333546820604, guid: 148b00b6296385545afdc97e83496834, + type: 3} + propertyPath: m_LocalRotation.w + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 224682333546820604, guid: 148b00b6296385545afdc97e83496834, + type: 3} + propertyPath: m_LocalRotation.x + value: -0 + objectReference: {fileID: 0} + - target: {fileID: 224682333546820604, guid: 148b00b6296385545afdc97e83496834, + type: 3} + propertyPath: m_LocalRotation.y + value: -0 + objectReference: {fileID: 0} + - target: {fileID: 224682333546820604, guid: 148b00b6296385545afdc97e83496834, + type: 3} + propertyPath: m_LocalRotation.z + value: -0 + objectReference: {fileID: 0} + - target: {fileID: 224682333546820604, guid: 148b00b6296385545afdc97e83496834, + type: 3} + propertyPath: m_AnchoredPosition.x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 224682333546820604, guid: 148b00b6296385545afdc97e83496834, + type: 3} + propertyPath: m_AnchoredPosition.y + value: -0.000061035156 + objectReference: {fileID: 0} + - target: {fileID: 224682333546820604, guid: 148b00b6296385545afdc97e83496834, + type: 3} + propertyPath: m_LocalEulerAnglesHint.x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 224682333546820604, guid: 148b00b6296385545afdc97e83496834, + type: 3} + propertyPath: m_LocalEulerAnglesHint.y + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 224682333546820604, guid: 148b00b6296385545afdc97e83496834, + type: 3} + propertyPath: m_LocalEulerAnglesHint.z + value: 0 + objectReference: {fileID: 0} + m_RemovedComponents: [] + m_RemovedGameObjects: [] + m_AddedGameObjects: [] + m_AddedComponents: [] + m_SourcePrefab: {fileID: 100100000, guid: 148b00b6296385545afdc97e83496834, type: 3} --- !u!1001 &1567442268 PrefabInstance: m_ObjectHideFlags: 0 @@ -158270,7 +158284,7 @@ PrefabInstance: - targetCorrespondingSourceObject: {fileID: 7116784941686974531, guid: 19f207330ece4db409fb300e477c9218, type: 3} insertIndex: -1 - addedObject: {fileID: 1347066542} + addedObject: {fileID: 186977229} m_AddedComponents: [] m_SourcePrefab: {fileID: 100100000, guid: 19f207330ece4db409fb300e477c9218, type: 3} --- !u!1 &1821636112 @@ -182053,7 +182067,7 @@ MonoBehaviour: BrushMax: {fileID: 156321333} Scatter: {fileID: 287704505} LinearBrush: {fileID: 1567442270} - TTerrainXP: {fileID: 1347066543} + ShaderName: {fileID: 186977231} TerrainMask: serializedVersion: 2 m_Bits: 256 diff --git a/Assets/Scripts/GFX/OzoneDecals/Shader/OzoneDeferredDecal.shader b/Assets/Scripts/GFX/OzoneDecals/Shader/OzoneDeferredDecal.shader index 6fb886ad..1b4f3894 100644 --- a/Assets/Scripts/GFX/OzoneDecals/Shader/OzoneDeferredDecal.shader +++ b/Assets/Scripts/GFX/OzoneDecals/Shader/OzoneDeferredDecal.shader @@ -32,7 +32,7 @@ Shader "Ozone/Deferred Decal" ZTest GEqual ZWrite Off - // Pass 0: Albedo and emission/lighting + // Pass 0: Albedo Pass { Blend One OneMinusSrcAlpha @@ -45,81 +45,35 @@ Shader "Ozone/Deferred Decal" #pragma multi_compile_instancing #include "DecalsCommon.cginc" -// float4 _Color; sampler2D _Mask; sampler2D _Glow; - uniform sampler2D _WaterRam; - uniform sampler2D _UtilitySamplerC; - uniform int _Water; - uniform float _WaterScaleX, _WaterScaleZ; - - - float3 ApplyWaterColor( float depth, float3 inColor){ - float4 wcolor = tex2D(_WaterRam, float2(depth,0)); - return lerp( inColor.rgb, wcolor.rgb, wcolor.a ); - } - void frag(v2f i, out float4 outAlbedo : SV_Target0, out float4 outGlow : SV_Target1) // + + void frag(v2f i, out float4 outAlbedo : SV_Target0) // { // Common header for all fragment shaders DEFERRED_FRAG_HEADER - // Get normal from GBuffer - //float3 gbuffer_normal = tex2D(_CameraGBufferTexture2, uv) * 2.0f - 1.0f; - //clip(dot(gbuffer_normal, i.decalNormal) - _AngleLimit); // 60 degree clamp - // Get color from texture and property float4 color = tex2D(_MainTex, texUV);// * _Color; - - float4 waterTexture = tex2D( _UtilitySamplerC, (wpos.xz -float2(-0.1, 0.1)) * half2(0.009765 / (_WaterScaleX / 1024.0), -0.009765 / (_WaterScaleZ / 1024.0))); - if(_Water > 0) - color.rgb = ApplyWaterColor( waterTexture.g, color.rgb); - //color.a = saturate(color.a); //color.a = 1; fixed4 Mask = tex2D(_Mask, texUV); color.a *= blend; float RawAlpha = color.a; - //color.rgb = blend * 1000; - // Write albedo, premultiply for proper blending outAlbedo = float4(color.rgb * color.a, color.a); clip(color.a - 0.003); - //color *= 1 - float4(ShadeSH9(float4(gbuffer_normal, 1.0f)), 1.0f); - - //color.rgb = 10000 * RawAlpha; - - // Handle logarithmic encoding in Gamma space -#ifndef UNITY_HDR_ON - //color *= float4(ShadeSH9(float4(gbuffer_normal, 1.0f)), 1.0f); - //color.rgb = exp2(-color.rgb); -#endif - - // Write emission, premultiply for proper blending - //outEmission = float4(color.rgb * color.a, color.a) + tex2D(_Glow, texUV); - - //outAlbedo = tex2D(_CameraGBufferTexture4Copy, uv); - //outAlbedo.rgb = lerp(outAlbedo.rgb, color.rgb * color.a, color.a); - - //outEmission = tex2D(_CameraGBufferTexture4Copy, uv); - //outEmission.rgb = lerp(outEmission.rgb, outAlbedo.rgb, outAlbedo.a); - - //outEmission.rgb = 0.2; - //outEmission.a = 1; - - //outEmission.rgb = color.rgb * tex2D(_Glow, texUV).rgb * (blend * 5 * RawAlpha); - //outEmission.a = RawAlpha; - outGlow = float4(RawAlpha,0,0,0); } ENDCG } - // Pass 1: Normals and specular / smoothness + // Pass 1: Normals Pass { // Manual blending @@ -158,44 +112,22 @@ Shader "Ozone/Deferred Decal" decalBitangent = cross(i.decalNormal, i.decalTangent); } - // Get normal from normal map - //float3 normal = UnpackScaleNormal(tex2D(_NormalTex, texUV), _NormalMultiplier); - //float3 normal = UnpackNormalDXT5nm(tex2D(_NormalTex, texUV)); - //float4 decalRaw = tex2D(_NormalTex, texUV); float3 normal; - //normal.xz = decalRaw.ag * 2 - 1; - //normal.y = sqrt(1 - dot(normal.xz,normal.xz)) ; - float4 NormalRaw = tex2D(_NormalTex, texUV); normal = UnpackNormalDXT5nm(NormalRaw); - //float AlphaNormal = saturate((1 - normal.z) * 1) * NormalRaw.r; float AlphaNormal = NormalRaw.r; - //normal.z *= 1; - //normal.z = saturate(normal.z - 0.9); - //normal.z = 1 - blend; normal.xy *= blend; normal = normalize(normal); - // Clip to blend it with other normal maps - //float AlphaNormal = clamp(dot(normal, half3(0,0,1)) * 10, 0, 1); - //clip(0.999 - AlphaNormal); - //clip(0.5 - normal.y); clip(AlphaNormal - 0.004); normal = mul(normal, half3x3(i.decalTangent, decalBitangent, i.decalNormal)); - // Simple alpha blending of normals - //float normalMask = _MaskNormals ? mask : UNITY_ACCESS_INSTANCED_PROP(_MaskMultiplier); - //float normalMask = 1; - //normal = (1.0f - normalMask) * gbuffer_normal + normalMask * normal; - //normal = normalize(normal); - - // Write normal outNormal = float4(normal * 0.5 + 0.5, saturate(AlphaNormal * blend)); } diff --git a/Assets/Scripts/Ozone SCMAP Code/ScmapEditor.cs b/Assets/Scripts/Ozone SCMAP Code/ScmapEditor.cs index 0952b816..aeb532e1 100644 --- a/Assets/Scripts/Ozone SCMAP Code/ScmapEditor.cs +++ b/Assets/Scripts/Ozone SCMAP Code/ScmapEditor.cs @@ -84,9 +84,6 @@ public void UpdateLighting() { Vector3 SunDIr = new Vector3(-map.SunDirection.x, -map.SunDirection.y, map.SunDirection.z); Sun.transform.rotation = Quaternion.LookRotation(SunDIr); - Sun.color = new Color(map.SunColor.x, map.SunColor.y, map.SunColor.z, 1); - Sun.intensity = map.LightingMultiplier * EditMap.LightingInfo.SunMultipiler; - RenderSettings.ambientLight = new Color(map.ShadowFillColor.x, map.ShadowFillColor.y, map.ShadowFillColor.z, 1); /*BloomModel.Settings Bs = PostProcessing.bloom.settings; Bs.bloom.intensity = map.Bloom * 10; @@ -99,13 +96,12 @@ public void UpdateLighting() RenderSettings.fogStartDistance = map.FogStart * 4f; RenderSettings.fogEndDistance = map.FogEnd * 4f; - - Shader.SetGlobalFloat("_LightingMultiplier", map.LightingMultiplier); - Shader.SetGlobalColor("_SunColor", new Color(map.SunColor.x * 0.5f, map.SunColor.y * 0.5f, map.SunColor.z * 0.5f, 1)); - Shader.SetGlobalColor("_SunAmbience", new Color(map.SunAmbience.x * 0.5f, map.SunAmbience.y * 0.5f, map.SunAmbience.z * 0.5f, 1)); - Shader.SetGlobalColor("_ShadowColor", new Color(map.ShadowFillColor.x * 0.5f, map.ShadowFillColor.y * 0.5f, map.ShadowFillColor.z * 0.5f, 1)); - - Shader.SetGlobalColor("_SpecularColor", new Color(map.SpecularColor.x * 0.5f, map.SpecularColor.y * 0.5f, map.SpecularColor.z * 0.5f, map.SpecularColor.w * 0.5f)); + Shader.SetGlobalVector("ShadowFillColor", map.ShadowFillColor); + Shader.SetGlobalFloat("LightingMultiplier", map.LightingMultiplier); + Shader.SetGlobalVector("SunDirection", map.SunDirection); + Shader.SetGlobalVector("SunAmbience", map.SunAmbience); + Shader.SetGlobalVector("SunColor", map.SunColor); + Shader.SetGlobalVector("SpecularColor", map.SpecularColor); } @@ -140,8 +136,8 @@ public IEnumerator LoadScmapFile() EnvPaths.CurrentGamedataPath = EnvPaths.GamedataPath; //Shader - MapLuaParser.Current.EditMenu.TexturesMenu.TTerrainXP.isOn = map.TerrainShader == "TTerrainXP"; - ToogleShader(); + MapLuaParser.Current.EditMenu.TexturesMenu.ShaderName.SetValue(map.TerrainShader); + ToogleShader(); // Set Variables int xRes = MapLuaParser.Current.ScenarioLuaFile.Data.Size[0]; @@ -151,7 +147,7 @@ public IEnumerator LoadScmapFile() TerrainMaterial.SetTexture("_TerrainNormal", map.UncompressedNormalmapTex); - Shader.SetGlobalTexture("_UtilitySamplerC", map.UncompressedWatermapTex); + WaterMaterial.SetTexture("UtilitySamplerC", map.UncompressedWatermapTex); Shader.SetGlobalFloat("_WaterScaleX", xRes); Shader.SetGlobalFloat("_WaterScaleZ", xRes); @@ -168,9 +164,9 @@ public IEnumerator LoadScmapFile() WaterLevel.transform.localScale = new Vector3(HalfxRes, 1, HalfzRes); - TerrainMaterial.SetFloat("_GridScale", HalfxRes); - TerrainMaterial.SetTexture("_UtilitySamplerC", map.UncompressedWatermapTex); - WaterMaterial.SetFloat("_GridScale", HalfxRes); + TerrainMaterial.SetFloat("TerrainScale", (float) 1.0 / xRes); + Shader.SetGlobalFloat("_GridScale", HalfxRes); + TerrainMaterial.SetTexture("UtilitySamplerC", map.UncompressedWatermapTex); for (int i = 0; i < map.EnvCubemapsFile.Length; i++) @@ -390,19 +386,13 @@ public void SetWater() WaterLevel.gameObject.SetActive(map.Water.HasWater); WaterLevel.transform.position = Vector3.up * (map.Water.Elevation / 10.0f); - WaterMaterial.SetColor("waterColor", new Color(map.Water.SurfaceColor.x * 0.5f, map.Water.SurfaceColor.y * 0.5f, map.Water.SurfaceColor.z * 0.5f, 1)); - WaterMaterial.SetColor("sunColor", new Color(map.Water.SunColor.x * 0.5f, map.Water.SunColor.y * 0.5f, map.Water.SunColor.z * 0.5f, 1)); - - Shader.SetGlobalVector("waterLerp", map.Water.ColorLerp); - Shader.SetGlobalVector("SunDirection", new Vector3(map.Water.SunDirection.x, map.Water.SunDirection.y, -map.Water.SunDirection.z)); - Shader.SetGlobalFloat("SunShininess", map.Water.SunShininess); - Shader.SetGlobalFloat("sunReflectionAmount", map.Water.SunReflection); - Shader.SetGlobalFloat("unitreflectionAmount", map.Water.UnitReflection); - Shader.SetGlobalFloat("skyreflectionAmount", map.Water.SkyReflection); - Shader.SetGlobalFloat("refractionScale", map.Water.RefractionScale); - - Shader.SetGlobalFloat("fresnelPower", map.Water.FresnelPower); - Shader.SetGlobalFloat("fresnelBias", map.Water.FresnelBias); + WaterMaterial.SetVector("waterColor", map.Water.SurfaceColor); + WaterMaterial.SetVector("SunColor", map.Water.SunColor); + WaterMaterial.SetVector("waterLerp", map.Water.ColorLerp); + WaterMaterial.SetVector("SunDirection", map.Water.SunDirection); + WaterMaterial.SetFloat("SunShininess", map.Water.SunShininess); + WaterMaterial.SetFloat("skyreflectionAmount", map.Water.SkyReflection); + WaterMaterial.SetFloat("refractionScale", map.Water.RefractionScale); /* for (int w = 0; w < map.WaveGenerators.Count; w++) @@ -411,9 +401,7 @@ public void SetWater() } */ - //Shader.SetGlobalVector("waterLerp", map.Water.WaveTextures); - - Shader.SetGlobalFloat("_WaterLevel", map.Water.Elevation / 10.0f); + Shader.SetGlobalFloat("WaterElevation", map.Water.Elevation / 10.0f); //TerrainMaterial.SetFloat("_DepthLevel", map.Water.ElevationDeep / 10.0f); //TerrainMaterial.SetFloat("_AbyssLevel", map.Water.ElevationAbyss / 10.0f); //TerrainMaterial.SetInt("_Water", map.Water.HasWater ? 1 : 0); @@ -424,7 +412,7 @@ public void SetWaterTextures() { Texture2D WaterRamp = GetGamedataFile.LoadTexture2D(map.Water.TexPathWaterRamp, false, true, true); WaterRamp.wrapMode = TextureWrapMode.Clamp; - Shader.SetGlobalTexture("_WaterRam", WaterRamp); + Shader.SetGlobalTexture("WaterRampSampler", WaterRamp); try { @@ -451,73 +439,69 @@ public void SetWaterTextures() WaterNormal.anisoLevel = WaterAnisoLevel; WaterMaterial.SetTexture("NormalSampler3", WaterNormal); - Shader.SetGlobalVector("normal1Movement", map.Water.WaveTextures[0].NormalMovement); - Shader.SetGlobalVector("normal2Movement", map.Water.WaveTextures[1].NormalMovement); - Shader.SetGlobalVector("normal3Movement", map.Water.WaveTextures[2].NormalMovement); - Shader.SetGlobalVector("normal4Movement", map.Water.WaveTextures[3].NormalMovement); - Shader.SetGlobalVector("normalRepeatRate", new Vector4(map.Water.WaveTextures[0].NormalRepeat, map.Water.WaveTextures[1].NormalRepeat, map.Water.WaveTextures[2].NormalRepeat, map.Water.WaveTextures[3].NormalRepeat)); + WaterMaterial.SetVector("normal1Movement", map.Water.WaveTextures[0].NormalMovement); + WaterMaterial.SetVector("normal2Movement", map.Water.WaveTextures[1].NormalMovement); + WaterMaterial.SetVector("normal3Movement", map.Water.WaveTextures[2].NormalMovement); + WaterMaterial.SetVector("normal4Movement", map.Water.WaveTextures[3].NormalMovement); + WaterMaterial.SetVector("normalRepeatRate", new Vector4(map.Water.WaveTextures[0].NormalRepeat, map.Water.WaveTextures[1].NormalRepeat, map.Water.WaveTextures[2].NormalRepeat, map.Water.WaveTextures[3].NormalRepeat)); } #endregion #region Textures - public void SetTextures(int OnlyOne = -1) + public void SetTextures(int Layer = -1) { - if (OnlyOne < 0) + if (Layer < 0) { - TerrainMaterial.SetTexture("_ControlXP", map.TexturemapTex); + TerrainMaterial.SetTexture("UtilitySamplerA", map.TexturemapTex); if (Textures[5].Albedo || Textures[6].Albedo || Textures[7].Albedo || Textures[8].Albedo) - TerrainMaterial.SetTexture("_Control2XP", map.TexturemapTex2); + TerrainMaterial.SetTexture("UtilitySamplerB", map.TexturemapTex2); } - if (OnlyOne <= 0) + if (Layer <= 0) { - TerrainMaterial.SetFloat("_LowerScale", map.Width / Textures[0].AlbedoScale); - TerrainMaterial.SetFloat("_LowerScaleNormal", map.Width / Textures[0].NormalScale); - TerrainMaterial.SetTexture("_SplatLower", Textures[0].Albedo); - TerrainMaterial.SetTexture("_NormalLower", Textures[0].Normal); + TerrainMaterial.SetFloat("LowerAlbedoTile", map.Width / Textures[0].AlbedoScale); + TerrainMaterial.SetFloat("LowerNormalTile", map.Width / Textures[0].NormalScale); + TerrainMaterial.SetTexture("LowerAlbedoSampler", Textures[0].Albedo); + TerrainMaterial.SetTexture("LowerNormalSampler", Textures[0].Normal); } - if (OnlyOne > 0 && OnlyOne < 9) + if (Layer > 0 && Layer < 9) { - string IdStrig = (OnlyOne - 1).ToString(); - //TerrainMaterial.SetTexture("_Splat" + IdStrig + "XP", Textures[OnlyOne].Albedo); - TerrainMaterial.SetFloat("_Splat" + IdStrig + "Scale", map.Width / Textures[OnlyOne].AlbedoScale); - //TerrainMaterial.SetTexture("_SplatNormal" + IdStrig, Textures[OnlyOne].Normal); - TerrainMaterial.SetFloat("_Splat" + IdStrig + "ScaleNormal", map.Width / Textures[OnlyOne].NormalScale); + string IdStrig = (Layer - 1).ToString(); + TerrainMaterial.SetFloat("Stratum" + IdStrig + "AlbedoTile", map.Width / Textures[Layer].AlbedoScale); + TerrainMaterial.SetFloat("Stratum" + IdStrig + "NormalTile", map.Width / Textures[Layer].NormalScale); } else { - TerrainMaterial.SetFloat("_Splat0Scale", map.Width / Textures[1].AlbedoScale); - TerrainMaterial.SetFloat("_Splat1Scale", map.Width / Textures[2].AlbedoScale); - TerrainMaterial.SetFloat("_Splat2Scale", map.Width / Textures[3].AlbedoScale); - TerrainMaterial.SetFloat("_Splat3Scale", map.Width / Textures[4].AlbedoScale); - TerrainMaterial.SetFloat("_Splat4Scale", map.Width / Textures[5].AlbedoScale); - TerrainMaterial.SetFloat("_Splat5Scale", map.Width / Textures[6].AlbedoScale); - TerrainMaterial.SetFloat("_Splat6Scale", map.Width / Textures[7].AlbedoScale); - TerrainMaterial.SetFloat("_Splat7Scale", map.Width / Textures[8].AlbedoScale); - - TerrainMaterial.SetFloat("_Splat0ScaleNormal", map.Width / Textures[1].NormalScale); - TerrainMaterial.SetFloat("_Splat1ScaleNormal", map.Width / Textures[2].NormalScale); - TerrainMaterial.SetFloat("_Splat2ScaleNormal", map.Width / Textures[3].NormalScale); - TerrainMaterial.SetFloat("_Splat3ScaleNormal", map.Width / Textures[4].NormalScale); - TerrainMaterial.SetFloat("_Splat4ScaleNormal", map.Width / Textures[5].NormalScale); - TerrainMaterial.SetFloat("_Splat5ScaleNormal", map.Width / Textures[6].NormalScale); - TerrainMaterial.SetFloat("_Splat6ScaleNormal", map.Width / Textures[7].NormalScale); - TerrainMaterial.SetFloat("_Splat7ScaleNormal", map.Width / Textures[8].NormalScale); + TerrainMaterial.SetFloat("Stratum0AlbedoTile", map.Width / Textures[1].AlbedoScale); + TerrainMaterial.SetFloat("Stratum1AlbedoTile", map.Width / Textures[2].AlbedoScale); + TerrainMaterial.SetFloat("Stratum2AlbedoTile", map.Width / Textures[3].AlbedoScale); + TerrainMaterial.SetFloat("Stratum3AlbedoTile", map.Width / Textures[4].AlbedoScale); + TerrainMaterial.SetFloat("Stratum4AlbedoTile", map.Width / Textures[5].AlbedoScale); + TerrainMaterial.SetFloat("Stratum5AlbedoTile", map.Width / Textures[6].AlbedoScale); + TerrainMaterial.SetFloat("Stratum6AlbedoTile", map.Width / Textures[7].AlbedoScale); + TerrainMaterial.SetFloat("Stratum7AlbedoTile", map.Width / Textures[8].AlbedoScale); + + TerrainMaterial.SetFloat("Stratum0NormalTile", map.Width / Textures[1].NormalScale); + TerrainMaterial.SetFloat("Stratum1NormalTile", map.Width / Textures[2].NormalScale); + TerrainMaterial.SetFloat("Stratum2NormalTile", map.Width / Textures[3].NormalScale); + TerrainMaterial.SetFloat("Stratum3NormalTile", map.Width / Textures[4].NormalScale); + TerrainMaterial.SetFloat("Stratum4NormalTile", map.Width / Textures[5].NormalScale); + TerrainMaterial.SetFloat("Stratum5NormalTile", map.Width / Textures[6].NormalScale); + TerrainMaterial.SetFloat("Stratum6NormalTile", map.Width / Textures[7].NormalScale); + TerrainMaterial.SetFloat("Stratum7NormalTile", map.Width / Textures[8].NormalScale); } - if (OnlyOne == 9 || OnlyOne < 0) + if (Layer == 9 || Layer < 0) { - TerrainMaterial.SetFloat("_UpperScale", map.Width / Textures[9].AlbedoScale); - TerrainMaterial.SetFloat("_UpperScaleNormal", map.Width / Textures[9].NormalScale); - TerrainMaterial.SetTexture("_SplatUpper", Textures[9].Albedo); - TerrainMaterial.SetTexture("_NormalUpper", Textures[9].Normal); + TerrainMaterial.SetFloat("UpperAlbedoTile", map.Width / Textures[9].AlbedoScale); + TerrainMaterial.SetTexture("UpperAlbedoSampler", Textures[9].Albedo); } - if(OnlyOne != 9 && OnlyOne != 0) + if(Layer != 9 && Layer != 0) { GenerateArrays(); } @@ -580,7 +564,7 @@ void GenerateArrays() AlbedoArray.mipMapBias = 0.0f; AlbedoArray.Apply(false); - TerrainMaterial.SetTexture("_SplatAlbedoArray", AlbedoArray); + TerrainMaterial.SetTexture("_StratumAlbedoArray", AlbedoArray); AlbedoSize = 256; @@ -627,26 +611,26 @@ void GenerateArrays() NormalArray.anisoLevel = 2; NormalArray.Apply(false); - TerrainMaterial.SetTexture("_SplatNormalArray", NormalArray); + TerrainMaterial.SetTexture("_StratumNormalArray", NormalArray); } public void UpdateScales(int id) { if (id == 0) { - TerrainMaterial.SetFloat("_LowerScale", map.Width / Textures[0].AlbedoScale); - TerrainMaterial.SetFloat("_LowerScaleNormal", map.Width / Textures[0].NormalScale); + TerrainMaterial.SetFloat("LowerAlbedoTile", map.Width / Textures[0].AlbedoScale); + TerrainMaterial.SetFloat("LowerNormalTile", map.Width / Textures[0].NormalScale); } else if (id == 9) { - TerrainMaterial.SetFloat("_UpperScale", map.Width / Textures[9].AlbedoScale); - TerrainMaterial.SetFloat("_UpperScaleNormal", map.Width / Textures[9].NormalScale); + TerrainMaterial.SetFloat("UpperAlbedoTile", map.Width / Textures[9].AlbedoScale); + TerrainMaterial.SetFloat("UpperNormalTile", map.Width / Textures[9].NormalScale); } else { string IdStrig = (id - 1).ToString(); - TerrainMaterial.SetFloat("_Splat" + IdStrig + "Scale", map.Width / Textures[id].AlbedoScale); - TerrainMaterial.SetFloat("_Splat" + IdStrig + "ScaleNormal", map.Width / Textures[id].NormalScale); + TerrainMaterial.SetFloat("Stratum" + IdStrig + "AlbedoTile", map.Width / Textures[id].AlbedoScale); + TerrainMaterial.SetFloat("Stratum" + IdStrig + "NormalTile", map.Width / Textures[id].NormalScale); } } #endregion @@ -722,9 +706,7 @@ public void SaveScmapFile() //string MapPath = EnvPaths.GetMapsPath(); string path = MapLuaParser.MapRelativePath(MapLuaParser.Current.ScenarioLuaFile.Data.map); - //TODO force values if needed - //map.TerrainShader = Shader; - map.TerrainShader = MapLuaParser.Current.EditMenu.TexturesMenu.TTerrainXP.isOn ? ("TTerrainXP") : ("TTerrain"); + map.TerrainShader = MapLuaParser.Current.EditMenu.TexturesMenu.ShaderName.text; map.MinimapContourColor = new Color32(0, 0, 0, 255); map.MinimapDeepWaterColor = new Color32(71, 140, 181, 255); @@ -1084,15 +1066,15 @@ public void ToogleAIGrid(bool To) void UpdateGrid() { - TerrainMaterial.SetTexture("_GridTexture", GridTextures[(int)GridType]); - TerrainMaterial.SetInt("_Grid", Grid ? 1 : 0); - TerrainMaterial.SetInt("_GridType", (int)GridType); + TerrainMaterial.SetTexture("_GridTexture", GridTextures[(int) GridType]); + TerrainMaterial.SetInteger("_Grid", Grid ? 1 : 0); + TerrainMaterial.SetInteger("_GridType", (int) GridType); } public void ToogleSlope(bool To) { Slope = To; - TerrainMaterial.SetInt("_Slope", Slope ? 1 : 0); + TerrainMaterial.SetInteger("_Slope", Slope ? 1 : 0); if (To) { GenerateControlTex.Current.GenerateSlopeTexture(); @@ -1103,7 +1085,21 @@ public void ToogleSlope(bool To) public void ToogleShader() { - Shader.SetGlobalInt("_TTerrainXP", (MapLuaParser.Current.EditMenu.TexturesMenu.TTerrainXP.isOn) ? 1 : 0); + if (MapLuaParser.Current.EditMenu.TexturesMenu.ShaderName.text == "TTerrain") + { + Shader.SetGlobalInt("_ShaderID", 0); + } + else if (MapLuaParser.Current.EditMenu.TexturesMenu.ShaderName.text == "TTerrainXP") + { + Shader.SetGlobalInt("_ShaderID", 1); + } + else if (MapLuaParser.Current.EditMenu.TexturesMenu.ShaderName.text == "Terrain301") + { + Shader.SetGlobalInt("_ShaderID", 2); + } else + { + Shader.SetGlobalInt("_ShaderID", -1); + } } #endregion } diff --git a/Assets/Scripts/Ozone SCMAP Code/Texture/GenerateControlTex.cs b/Assets/Scripts/Ozone SCMAP Code/Texture/GenerateControlTex.cs index 8d363fa9..eaa4b7f8 100644 --- a/Assets/Scripts/Ozone SCMAP Code/Texture/GenerateControlTex.cs +++ b/Assets/Scripts/Ozone SCMAP Code/Texture/GenerateControlTex.cs @@ -175,7 +175,7 @@ public static void StopGenerateNormal() BufforNormalTex = false; Current.StopCoroutine(NormalCoroutine); NormalCoroutine = null; - ScmapEditor.Current.TerrainMaterial.SetFloat("_GeneratingNormal", 0); + ScmapEditor.Current.TerrainMaterial.SetInteger("_GeneratingNormal", 0); } } @@ -193,7 +193,7 @@ static bool GeneratingNormalTex public IEnumerator GeneratingNormal() { //Debug.Log("Begin Generate Normals"); - ScmapEditor.Current.TerrainMaterial.SetFloat("_GeneratingNormal", 1); + ScmapEditor.Current.TerrainMaterial.SetInteger("_GeneratingNormal", 1); Color[] AllColors = ScmapEditor.Current.map.UncompressedNormalmapTex.GetPixels(); float Width = ScmapEditor.Current.map.UncompressedNormalmapTex.width; @@ -234,7 +234,7 @@ public IEnumerator GeneratingNormal() //Debug.Log("Success Generate Normals"); ScmapEditor.Current.map.UncompressedNormalmapTex.SetPixels(AllColors); ScmapEditor.Current.map.UncompressedNormalmapTex.Apply(false); - ScmapEditor.Current.TerrainMaterial.SetFloat("_GeneratingNormal", 0); + ScmapEditor.Current.TerrainMaterial.SetInteger("_GeneratingNormal", 0); ScmapEditor.Current.TerrainMaterial.SetTexture("_TerrainNormal", ScmapEditor.Current.map.UncompressedNormalmapTex); yield return null; diff --git a/Assets/Scripts/UI/Tools/Props/PropsInfo.cs b/Assets/Scripts/UI/Tools/Props/PropsInfo.cs index 1c0c702a..572a93d1 100644 --- a/Assets/Scripts/UI/Tools/Props/PropsInfo.cs +++ b/Assets/Scripts/UI/Tools/Props/PropsInfo.cs @@ -175,7 +175,7 @@ void OnDisable() void DisableBrush() { - TerrainMaterial.SetInt("_Brush", 0); + TerrainMaterial.SetInteger("_Brush", 0); TerrainMaterial.SetFloat("_BrushSize", 0); } @@ -207,7 +207,7 @@ void GoToPainting() SelectionManager.Current.SetAffectedGameObjects(new GameObject[0], SelectionManager.SelectionControlTypes.None); BrushGenerator.Current.LoadBrushes(); - TerrainMaterial.SetInt("_Brush", 1); + TerrainMaterial.SetInteger("_Brush", 1); BrushGenerator.Current.Brushes[SelectedFalloff].wrapMode = TextureWrapMode.Clamp; BrushGenerator.Current.Brushes[SelectedFalloff].mipMapBias = -1f; @@ -662,7 +662,7 @@ bool Painting { set { - TerrainMaterial.SetInt("_BrushPainting", _Painting ? (1) : (0)); + TerrainMaterial.SetInteger("_BrushPainting", _Painting ? (1) : (0)); _Painting = value; } get diff --git a/Assets/Scripts/UI/Tools/Terrain/TerrainInfo.cs b/Assets/Scripts/UI/Tools/Terrain/TerrainInfo.cs index e27cf4bc..224d6d5f 100644 --- a/Assets/Scripts/UI/Tools/Terrain/TerrainInfo.cs +++ b/Assets/Scripts/UI/Tools/Terrain/TerrainInfo.cs @@ -68,7 +68,7 @@ void ResetBrushes() void SetBrush() { - TerrainMaterial.SetInt("_Brush", 1); + TerrainMaterial.SetInteger("_Brush", 1); BrushGenerator.SetFalloff(SelectedFalloff, LastRotation); TerrainMaterial.SetTexture("_BrushTex", (Texture)BrushGenerator.Current.Brushes[SelectedFalloff]); @@ -81,7 +81,7 @@ void SetBrush() void OnDisable() { - TerrainMaterial.SetInt("_Brush", 0); + TerrainMaterial.SetInteger("_Brush", 0); } @@ -99,10 +99,10 @@ public override bool ChangePage(int PageId) SetBrush(); break; case 2: - TerrainMaterial.SetInt("_Brush", 1); + TerrainMaterial.SetInteger("_Brush", 1); break; default: - TerrainMaterial.SetInt("_Brush", 0); + TerrainMaterial.SetInteger("_Brush", 0); break; } } @@ -283,7 +283,7 @@ void Update() { ScmapEditor.Current.Teren.heightmapPixelError = 20; GenerateControlTex.StopGenerateNormal(); - ScmapEditor.Current.TerrainMaterial.SetFloat("_GeneratingNormal", 1); + ScmapEditor.Current.TerrainMaterial.SetInteger("_GeneratingNormal", 1); PaintStarted = true; RecalcTerrainClamp(); SymmetryPaint(); @@ -890,7 +890,7 @@ bool Painting set { _Painting = value; - TerrainMaterial.SetInt("_BrushPainting", _Painting ? (1) : (0)); + TerrainMaterial.SetInteger("_BrushPainting", _Painting ? (1) : (0)); } get { diff --git a/Assets/Scripts/UI/Tools/Terrain/TerrainTypes/TerrainTypeWindow.cs b/Assets/Scripts/UI/Tools/Terrain/TerrainTypes/TerrainTypeWindow.cs index b85aad33..85d5e051 100644 --- a/Assets/Scripts/UI/Tools/Terrain/TerrainTypes/TerrainTypeWindow.cs +++ b/Assets/Scripts/UI/Tools/Terrain/TerrainTypes/TerrainTypeWindow.cs @@ -413,11 +413,11 @@ private void Init() RebuildBrush(BrushSize); - ScmapEditor.Current.TerrainMaterial.SetInt("_Brush", 1); + ScmapEditor.Current.TerrainMaterial.SetInteger("_Brush", 1); ScmapEditor.Current.TerrainMaterial.SetTexture("_BrushTex", brushTexture); ScmapEditor.Current.TerrainMaterial.SetFloat("_BrushSize", BrushSizeRecalc); ScmapEditor.Current.TerrainMaterial.SetTexture("_TerrainTypeAlbedo", TerrainTypeTexture); - ScmapEditor.Current.TerrainMaterial.SetInt("_HideTerrainType", 0); + ScmapEditor.Current.TerrainMaterial.SetInteger("_HideTerrainType", 0); layerCapacityField.SetValue(0.228f * 100); CreateUILayerSettings(); @@ -580,8 +580,8 @@ private void Close() ApplyTerrainTypeChanges(); HideMoreLayerInfo(); - ScmapEditor.Current.TerrainMaterial.SetInt("_Brush", 0); - ScmapEditor.Current.TerrainMaterial.SetInt("_HideTerrainType", 1); + ScmapEditor.Current.TerrainMaterial.SetInteger("_Brush", 0); + ScmapEditor.Current.TerrainMaterial.SetInteger("_HideTerrainType", 1); ScmapEditor.Current.TerrainMaterial.SetTexture("_TerrainTypeAlbedo", null); TerrainTypeTexture = null; diff --git a/Assets/Scripts/UI/Tools/Textures/StratumInfo.cs b/Assets/Scripts/UI/Tools/Textures/StratumInfo.cs index 1d2ca481..178662ae 100644 --- a/Assets/Scripts/UI/Tools/Textures/StratumInfo.cs +++ b/Assets/Scripts/UI/Tools/Textures/StratumInfo.cs @@ -49,9 +49,9 @@ public partial class StratumInfo : ToolPage public UiTextField Scatter; public Toggle LinearBrush; - public Toggle TTerrainXP; + public UiTextField ShaderName; - public LayerMask TerrainMask; + public LayerMask TerrainMask; public List BrushToggles; public ToggleGroup ToogleGroup; @@ -293,15 +293,15 @@ void Update() #region Stratums public void VisibleStratums() { - ScmapEditor.Current.TerrainMaterial.SetInt("_HideSplat0", StratumHide[1]?1:0); - ScmapEditor.Current.TerrainMaterial.SetInt("_HideSplat1", StratumHide[2] ? 1 : 0); - ScmapEditor.Current.TerrainMaterial.SetInt("_HideSplat2", StratumHide[3] ? 1 : 0); - ScmapEditor.Current.TerrainMaterial.SetInt("_HideSplat3", StratumHide[4] ? 1 : 0); - ScmapEditor.Current.TerrainMaterial.SetInt("_HideSplat4", StratumHide[5] ? 1 : 0); - ScmapEditor.Current.TerrainMaterial.SetInt("_HideSplat5", StratumHide[6] ? 1 : 0); - ScmapEditor.Current.TerrainMaterial.SetInt("_HideSplat6", StratumHide[7] ? 1 : 0); - ScmapEditor.Current.TerrainMaterial.SetInt("_HideSplat7", StratumHide[8] ? 1 : 0); - ScmapEditor.Current.TerrainMaterial.SetInt("_HideSplat8", StratumHide[9] ? 1 : 0); + ScmapEditor.Current.TerrainMaterial.SetInteger("_HideStratum0", StratumHide[1] ? 1 : 0); + ScmapEditor.Current.TerrainMaterial.SetInteger("_HideStratum1", StratumHide[2] ? 1 : 0); + ScmapEditor.Current.TerrainMaterial.SetInteger("_HideStratum2", StratumHide[3] ? 1 : 0); + ScmapEditor.Current.TerrainMaterial.SetInteger("_HideStratum3", StratumHide[4] ? 1 : 0); + ScmapEditor.Current.TerrainMaterial.SetInteger("_HideStratum4", StratumHide[5] ? 1 : 0); + ScmapEditor.Current.TerrainMaterial.SetInteger("_HideStratum5", StratumHide[6] ? 1 : 0); + ScmapEditor.Current.TerrainMaterial.SetInteger("_HideStratum6", StratumHide[7] ? 1 : 0); + ScmapEditor.Current.TerrainMaterial.SetInteger("_HideStratum7", StratumHide[8] ? 1 : 0); + ScmapEditor.Current.TerrainMaterial.SetInteger("_HideStratum8", StratumHide[9] ? 1 : 0); const string TextVisible = "V"; @@ -440,7 +440,7 @@ private void ConfigureForPaintPage() if (!BrusheshLoaded) LoadBrushesh(); UpdateStratumMenu(); - TerrainMaterial.SetInt("_Brush", 1); + TerrainMaterial.SetInteger("_Brush", 1); BrushGenerator.SetFalloff(SelectedFalloff, LastRotation); TerrainMaterial.SetTexture("_BrushTex", (Texture)BrushGenerator.Current.Brushes[SelectedFalloff]); } @@ -454,15 +454,16 @@ private void ConfigureForSettingsPage() public void RefreshLayerUI() { + bool allLayers = ShaderName.text != "TTerrain"; for(int i = 0; i < StratumSettings.XpShaderLayers.Length; i++) { - StratumSettings.XpShaderLayers[i].color = TTerrainXP.isOn ? Color.white : DisabledLayerColor; + StratumSettings.XpShaderLayers[i].color = allLayers ? Color.white : DisabledLayerColor; } - StratumSettings.Stratum8_Mask.gameObject.SetActive(TTerrainXP.isOn); - StratumSettings.Stratum7_Mask.gameObject.SetActive(TTerrainXP.isOn); - StratumSettings.Stratum6_Mask.gameObject.SetActive(TTerrainXP.isOn); - StratumSettings.Stratum5_Mask.gameObject.SetActive(TTerrainXP.isOn); + StratumSettings.Stratum8_Mask.gameObject.SetActive(allLayers); + StratumSettings.Stratum7_Mask.gameObject.SetActive(allLayers); + StratumSettings.Stratum6_Mask.gameObject.SetActive(allLayers); + StratumSettings.Stratum5_Mask.gameObject.SetActive(allLayers); } public float Min = 0; @@ -559,10 +560,10 @@ public void UpdateStratumMenu(bool Slider = false) //TerrainMaterial.SetFloat("_BrushSize", BrushSize.value); } } - #endregion + #endregion - #region Load all brushesh - bool BrusheshLoaded = false; + #region Load all brushesh + bool BrusheshLoaded = false; string StructurePath; public void LoadBrushesh() { @@ -682,7 +683,7 @@ bool Painting set { _Painting = value; - TerrainMaterial.SetInt("_BrushPainting", _Painting ? (1) : (0)); + TerrainMaterial.SetInteger("_BrushPainting", _Painting ? (1) : (0)); } get @@ -1401,7 +1402,7 @@ public void ImportStratum() class StratumTemplate { - public bool TTerrainXP = false; + public string ShaderName; public ScmapEditor.TerrainTexture Stratum0; public ScmapEditor.TerrainTexture Stratum1; public ScmapEditor.TerrainTexture Stratum2; @@ -1428,7 +1429,7 @@ public void ExportStratumTemplate() { StratumTemplate NewTemplate = new StratumTemplate(); - NewTemplate.TTerrainXP = TTerrainXP.isOn; + NewTemplate.ShaderName = ShaderName.text; NewTemplate.Stratum0 = ScmapEditor.Current.Textures[0]; NewTemplate.Stratum1 = ScmapEditor.Current.Textures[1]; NewTemplate.Stratum2 = ScmapEditor.Current.Textures[2]; @@ -1463,8 +1464,8 @@ public void ImportStratumTemplate() StratumTemplate NewTemplate = UnityEngine.JsonUtility.FromJson(data); - TTerrainXP.isOn = NewTemplate.TTerrainXP; + ShaderName.SetValue(NewTemplate.ShaderName); ScmapEditor.Current.Textures[0] = NewTemplate.Stratum0; ScmapEditor.Current.Textures[1] = NewTemplate.Stratum1; ScmapEditor.Current.Textures[2] = NewTemplate.Stratum2; diff --git a/Assets/Scripts/UI/Windows/NewMap.cs b/Assets/Scripts/UI/Windows/NewMap.cs index b87983b4..ad9f6882 100644 --- a/Assets/Scripts/UI/Windows/NewMap.cs +++ b/Assets/Scripts/UI/Windows/NewMap.cs @@ -215,7 +215,7 @@ IEnumerator CreateFiles() ScmapEditor.Current.LoadHeights(); MapLuaParser.Current.EditMenu.MapInfoMenu.SaveAsFa.isOn = false; - MapLuaParser.Current.EditMenu.TexturesMenu.TTerrainXP.isOn = true; + MapLuaParser.Current.EditMenu.TexturesMenu.ShaderName.SetValue("TTerrain"); yield return new WaitForSeconds(0.5f); MapLuaParser.Current.SaveMap(false);