mirror of
https://github.com/LazyDuchess/OpenTS2.git
synced 2025-01-22 08:11:47 -05:00
more work on neighborhood shading
This commit is contained in:
parent
fa072d3688
commit
5827a5d87a
10 changed files with 255 additions and 9 deletions
9
Assets/Materials/Terrain.mat
generated
9
Assets/Materials/Terrain.mat
generated
|
@ -8,7 +8,7 @@ Material:
|
|||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_Name: Terrain
|
||||
m_Shader: {fileID: 4800000, guid: 771ee9745e72c1647a3214591ac0e226, type: 3}
|
||||
m_Shader: {fileID: 4800000, guid: f56f884b040997b419d7f04eb5b8aace, type: 3}
|
||||
m_ShaderKeywords:
|
||||
m_LightmapFlags: 4
|
||||
m_EnableInstancingVariants: 0
|
||||
|
@ -47,6 +47,10 @@ Material:
|
|||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _MatCap:
|
||||
m_Texture: {fileID: 2800000, guid: 174675c9d2f4de84ba7e6face5995a2e, type: 3}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _MetallicGlossMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
|
@ -60,6 +64,7 @@ Material:
|
|||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
m_Floats:
|
||||
- _Ambient: 0.2
|
||||
- _BumpScale: 1
|
||||
- _ColorMask: 15
|
||||
- _Cutoff: 0.5
|
||||
|
@ -81,6 +86,7 @@ Material:
|
|||
- _StencilOp: 0
|
||||
- _StencilReadMask: 255
|
||||
- _StencilWriteMask: 255
|
||||
- _Subtract: 0.2
|
||||
- _UVSec: 0
|
||||
- _UseUIAlphaClip: 0
|
||||
- _ZWrite: 1
|
||||
|
@ -88,6 +94,7 @@ Material:
|
|||
- _Color: {r: 1, g: 1, b: 1, a: 1}
|
||||
- _Emission: {r: 0, g: 0, b: 0, a: 0}
|
||||
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1}
|
||||
- _LightVector: {r: 0.33, g: 0.33, b: -0.33, a: 0}
|
||||
- _SpecColor: {r: 1, g: 1, b: 1, a: 1}
|
||||
- _Specular: {r: 0, g: 0, b: 0, a: 0}
|
||||
m_BuildTextureStacks: []
|
||||
|
|
16
Assets/Scenes/Neighborhood.unity
generated
16
Assets/Scenes/Neighborhood.unity
generated
|
@ -20,7 +20,7 @@ RenderSettings:
|
|||
m_FogDensity: 0.01
|
||||
m_LinearFogStart: 0
|
||||
m_LinearFogEnd: 300
|
||||
m_AmbientSkyColor: {r: 0.57818615, g: 0.6051374, b: 0.6698113, a: 1}
|
||||
m_AmbientSkyColor: {r: 0.50980395, g: 0.50980395, b: 0.5647059, a: 1}
|
||||
m_AmbientEquatorColor: {r: 0.114, g: 0.125, b: 0.133, a: 1}
|
||||
m_AmbientGroundColor: {r: 0.047, g: 0.043, b: 0.035, a: 1}
|
||||
m_AmbientIntensity: 1
|
||||
|
@ -151,7 +151,7 @@ Light:
|
|||
serializedVersion: 10
|
||||
m_Type: 1
|
||||
m_Shape: 0
|
||||
m_Color: {r: 1, g: 0.94902664, b: 0.740566, a: 1}
|
||||
m_Color: {r: 0.9433962, g: 0.8287357, b: 0.50284797, a: 1}
|
||||
m_Intensity: 0.7
|
||||
m_Range: 10
|
||||
m_SpotAngle: 30
|
||||
|
@ -209,13 +209,13 @@ Transform:
|
|||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 138079089}
|
||||
m_LocalRotation: {x: -0.272682, y: 0.01046926, z: -0.28817546, w: -0.9178725}
|
||||
m_LocalPosition: {x: 0, y: 3, z: 0}
|
||||
m_LocalRotation: {x: 0.27918786, y: -0.3048527, z: 0.10756134, w: 0.90418446}
|
||||
m_LocalPosition: {x: 664.5133, y: 363.00726, z: 489.0098}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_Children: []
|
||||
m_Father: {fileID: 0}
|
||||
m_RootOrder: 1
|
||||
m_LocalEulerAnglesHint: {x: 30.438, y: 9.206, z: 397.37}
|
||||
m_LocalEulerAnglesHint: {x: 34.782, y: -36.733, z: 1.695}
|
||||
--- !u!1 &609160697
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
|
@ -369,8 +369,8 @@ MonoBehaviour:
|
|||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
RayDistance: 2000
|
||||
RayBias: 8
|
||||
BlurOffset: 10
|
||||
RayBias: 1
|
||||
BlurOffset: 0
|
||||
Sun: {fileID: 138079091}
|
||||
Reload: 0
|
||||
--- !u!1 &1015291787
|
||||
|
@ -619,7 +619,7 @@ Camera:
|
|||
m_Enabled: 1
|
||||
serializedVersion: 2
|
||||
m_ClearFlags: 2
|
||||
m_BackGroundColor: {r: 0.3207547, g: 0.3207547, b: 0.3207547, a: 0}
|
||||
m_BackGroundColor: {r: 0.40784314, g: 0.8392157, b: 1, a: 0}
|
||||
m_projectionMatrixMode: 1
|
||||
m_GateFitMode: 2
|
||||
m_FOVAxisMode: 0
|
||||
|
|
|
@ -1,4 +1,8 @@
|
|||
using OpenTS2.Common;
|
||||
using OpenTS2.Content;
|
||||
using OpenTS2.Content.DBPF;
|
||||
using OpenTS2.Engine;
|
||||
using OpenTS2.Files.Formats.DBPF;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
@ -7,6 +11,7 @@ namespace OpenTS2.Scenes
|
|||
{
|
||||
[RequireComponent(typeof(MeshFilter))]
|
||||
[RequireComponent(typeof(MeshCollider))]
|
||||
[RequireComponent(typeof(MeshRenderer))]
|
||||
public class NeighborhoodTerrain : MonoBehaviour
|
||||
{
|
||||
public float RayDistance = 2000f;
|
||||
|
@ -14,16 +19,35 @@ namespace OpenTS2.Scenes
|
|||
public float BlurOffset = 10f;
|
||||
public Transform Sun;
|
||||
public bool Reload = false;
|
||||
private static ResourceKey DayTimeMatCapKey = new ResourceKey(0x0BE702EF, 0x8BA01057, TypeIDs.IMG);
|
||||
private Material _terrainMaterial;
|
||||
private TextureAsset _matcapAsset;
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
var meshRenderer = GetComponent<MeshRenderer>();
|
||||
_terrainMaterial = meshRenderer.material;
|
||||
_terrainMaterial.SetVector("_LightVector", Sun.forward);
|
||||
_matcapAsset = ContentProvider.Get().GetAsset<TextureAsset>(DayTimeMatCapKey);
|
||||
if (_matcapAsset != null)
|
||||
{
|
||||
_matcapAsset.Texture.wrapMode = TextureWrapMode.Clamp;
|
||||
_terrainMaterial.SetTexture("_MatCap", _matcapAsset.Texture);
|
||||
}
|
||||
SetTerrainMesh();
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
if (_terrainMaterial != null)
|
||||
_terrainMaterial.Free();
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (Reload)
|
||||
{
|
||||
_terrainMaterial.SetVector("_LightVector", Sun.forward);
|
||||
var meshFilter = GetComponent<MeshFilter>();
|
||||
MakeVertexColors(meshFilter.sharedMesh);
|
||||
Reload = false;
|
||||
|
|
|
@ -50,6 +50,7 @@ namespace OpenTS2.UI.Layouts
|
|||
CursorController.Cursor = CursorController.CursorType.Hourglass;
|
||||
if (_mainMenu != null)
|
||||
return;
|
||||
Components[0].gameObject.SetActive(false);
|
||||
_mainMenu = new MainMenu(true);
|
||||
_mainMenu.OnClose += OnMainMenuClose;
|
||||
CursorController.Cursor = CursorController.CursorType.Default;
|
||||
|
@ -57,6 +58,7 @@ namespace OpenTS2.UI.Layouts
|
|||
|
||||
void OnMainMenuClose()
|
||||
{
|
||||
Components[0].gameObject.SetActive(true);
|
||||
_mainMenu = null;
|
||||
}
|
||||
}
|
||||
|
|
86
Assets/Shaders/ClassicTerrain.shader
Normal file
86
Assets/Shaders/ClassicTerrain.shader
Normal file
|
@ -0,0 +1,86 @@
|
|||
// Upgrade NOTE: replaced '_Object2World' with 'unity_ObjectToWorld'
|
||||
|
||||
Shader "OpenTS2/ClassicTerrain"
|
||||
{
|
||||
Properties
|
||||
{
|
||||
_MainTex ("Texture", 2D) = "white" {}
|
||||
_MatCap("MatCap", 2D) = "white" {}
|
||||
_LightVector("Light Vector", Vector) = (.33, .33, -.33, 0)
|
||||
_Ambient("Ambient", float) = 0
|
||||
_Subtract("Subtract", float) = 0
|
||||
}
|
||||
SubShader
|
||||
{
|
||||
Tags { "RenderType"="Opaque" }
|
||||
LOD 100
|
||||
|
||||
Pass
|
||||
{
|
||||
CGPROGRAM
|
||||
#pragma vertex vert
|
||||
#pragma fragment frag
|
||||
// make fog work
|
||||
#pragma multi_compile_fog
|
||||
|
||||
#include "UnityCG.cginc"
|
||||
|
||||
struct appdata
|
||||
{
|
||||
float4 vertex : POSITION;
|
||||
float2 uv : TEXCOORD0;
|
||||
float3 normal : NORMAL;
|
||||
float4 color : COLOR;
|
||||
};
|
||||
|
||||
struct v2f
|
||||
{
|
||||
float2 uv : TEXCOORD0;
|
||||
UNITY_FOG_COORDS(1)
|
||||
float4 vertex : SV_POSITION;
|
||||
};
|
||||
|
||||
sampler2D _MainTex;
|
||||
sampler2D _MatCap;
|
||||
float4 _MainTex_ST;
|
||||
float4 _LightVector;
|
||||
float _Subtract;
|
||||
float _Ambient;
|
||||
|
||||
v2f vert (appdata v)
|
||||
{
|
||||
v2f o;
|
||||
o.vertex = UnityObjectToClipPos(v.vertex);
|
||||
o.uv = TRANSFORM_TEX(v.uv, _MainTex);
|
||||
UNITY_TRANSFER_FOG(o,o.vertex);
|
||||
//o.uv = float2(v.normal.x, v.normal.y);
|
||||
float3 lightingDirection = -normalize(_LightVector.xyz);
|
||||
float3 lightCross = cross(lightingDirection, float3(0.0, 1.0, 0.0));
|
||||
float3 worldNormal = mul(unity_ObjectToWorld, float4(v.normal, 0.0)).xyz;
|
||||
float lightDot = dot(worldNormal, lightingDirection);
|
||||
float lightDotRight = dot(worldNormal, lightCross);
|
||||
|
||||
|
||||
//o.uv = float2(lightDotRight, lightDot) - float2(v.color.x,v.color.x) + float2(0.4,0.4);
|
||||
//o.uv.x = max(0.2, o.uv.x);
|
||||
//o.uv.y = max(0.2, o.uv.y);
|
||||
o.uv = max(0,((float2(lightDot, lightDot) + float2(lightDotRight, 0.0)) * -(v.color.x - 1)) - _Subtract);
|
||||
o.uv += float2(_Ambient, _Ambient);
|
||||
return o;
|
||||
}
|
||||
|
||||
fixed4 frag (v2f i) : SV_Target
|
||||
{
|
||||
// sample the texture
|
||||
fixed4 col = tex2D(_MatCap, i.uv);
|
||||
//col.z = 0;
|
||||
//col.x = i.uv.x;
|
||||
//col.y = i.uv.y;
|
||||
// apply fog
|
||||
UNITY_APPLY_FOG(i.fogCoord, col);
|
||||
return col;
|
||||
}
|
||||
ENDCG
|
||||
}
|
||||
}
|
||||
}
|
10
Assets/Shaders/ClassicTerrain.shader.meta
generated
Normal file
10
Assets/Shaders/ClassicTerrain.shader.meta
generated
Normal file
|
@ -0,0 +1,10 @@
|
|||
fileFormatVersion: 2
|
||||
guid: f56f884b040997b419d7f04eb5b8aace
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
preprocessorOverride: 0
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -19,6 +19,7 @@ Shader "OpenTS2/Terrain" {
|
|||
half NdotL = max(0,dot(s.Normal, lightDir));
|
||||
half4 c;
|
||||
atten -= s.Shadow;
|
||||
atten = max(atten, 0.0);
|
||||
float3 shading = _LightColor0.rgb * (NdotL * atten);
|
||||
c.rgb = s.Albedo * shading;
|
||||
|
||||
|
|
8
Assets/Textures.meta
generated
Normal file
8
Assets/Textures.meta
generated
Normal file
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 1168f30e8e7ee004bb34721f20cc0973
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
BIN
Assets/Textures/TerrainMatcapDebug.png
Normal file
BIN
Assets/Textures/TerrainMatcapDebug.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 7.4 KiB |
108
Assets/Textures/TerrainMatcapDebug.png.meta
generated
Normal file
108
Assets/Textures/TerrainMatcapDebug.png.meta
generated
Normal file
|
@ -0,0 +1,108 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 174675c9d2f4de84ba7e6face5995a2e
|
||||
TextureImporter:
|
||||
internalIDToNameTable: []
|
||||
externalObjects: {}
|
||||
serializedVersion: 11
|
||||
mipmaps:
|
||||
mipMapMode: 0
|
||||
enableMipMap: 1
|
||||
sRGBTexture: 1
|
||||
linearTexture: 0
|
||||
fadeOut: 0
|
||||
borderMipMap: 0
|
||||
mipMapsPreserveCoverage: 0
|
||||
alphaTestReferenceValue: 0.5
|
||||
mipMapFadeDistanceStart: 1
|
||||
mipMapFadeDistanceEnd: 3
|
||||
bumpmap:
|
||||
convertToNormalMap: 0
|
||||
externalNormalMap: 0
|
||||
heightScale: 0.25
|
||||
normalMapFilter: 0
|
||||
isReadable: 0
|
||||
streamingMipmaps: 0
|
||||
streamingMipmapsPriority: 0
|
||||
vTOnly: 0
|
||||
grayScaleToAlpha: 0
|
||||
generateCubemap: 6
|
||||
cubemapConvolution: 0
|
||||
seamlessCubemap: 0
|
||||
textureFormat: 1
|
||||
maxTextureSize: 2048
|
||||
textureSettings:
|
||||
serializedVersion: 2
|
||||
filterMode: 1
|
||||
aniso: 1
|
||||
mipBias: 0
|
||||
wrapU: 1
|
||||
wrapV: 1
|
||||
wrapW: 1
|
||||
nPOTScale: 1
|
||||
lightmap: 0
|
||||
compressionQuality: 50
|
||||
spriteMode: 0
|
||||
spriteExtrude: 1
|
||||
spriteMeshType: 1
|
||||
alignment: 0
|
||||
spritePivot: {x: 0.5, y: 0.5}
|
||||
spritePixelsToUnits: 100
|
||||
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
|
||||
spriteGenerateFallbackPhysicsShape: 1
|
||||
alphaUsage: 1
|
||||
alphaIsTransparency: 0
|
||||
spriteTessellationDetail: -1
|
||||
textureType: 0
|
||||
textureShape: 1
|
||||
singleChannelComponent: 0
|
||||
flipbookRows: 1
|
||||
flipbookColumns: 1
|
||||
maxTextureSizeSet: 0
|
||||
compressionQualitySet: 0
|
||||
textureFormatSet: 0
|
||||
ignorePngGamma: 0
|
||||
applyGammaDecoding: 0
|
||||
platformSettings:
|
||||
- serializedVersion: 3
|
||||
buildTarget: DefaultTexturePlatform
|
||||
maxTextureSize: 2048
|
||||
resizeAlgorithm: 0
|
||||
textureFormat: -1
|
||||
textureCompression: 1
|
||||
compressionQuality: 50
|
||||
crunchedCompression: 0
|
||||
allowsAlphaSplitting: 0
|
||||
overridden: 0
|
||||
androidETC2FallbackOverride: 0
|
||||
forceMaximumCompressionQuality_BC6H_BC7: 0
|
||||
- serializedVersion: 3
|
||||
buildTarget: Standalone
|
||||
maxTextureSize: 2048
|
||||
resizeAlgorithm: 0
|
||||
textureFormat: -1
|
||||
textureCompression: 1
|
||||
compressionQuality: 50
|
||||
crunchedCompression: 0
|
||||
allowsAlphaSplitting: 0
|
||||
overridden: 0
|
||||
androidETC2FallbackOverride: 0
|
||||
forceMaximumCompressionQuality_BC6H_BC7: 0
|
||||
spriteSheet:
|
||||
serializedVersion: 2
|
||||
sprites: []
|
||||
outline: []
|
||||
physicsShape: []
|
||||
bones: []
|
||||
spriteID:
|
||||
internalID: 0
|
||||
vertices: []
|
||||
indices:
|
||||
edges: []
|
||||
weights: []
|
||||
secondaryTextures: []
|
||||
spritePackingTag:
|
||||
pSDRemoveMatte: 0
|
||||
pSDShowRemoveMatteOption: 0
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Loading…
Reference in a new issue