浏览代码
WIP dump - working prototype
WIP dump - working prototype
Updates to CameraSensor / CameraSensorComponent: * new settings object to set up layer masks, depth, etc * support for arbitrary # channels returned by the sensor * channels include depth, layer mask, RGB, or grayscale Updates to VisualFoodCollector: * food doesn't roll (for now), simplifies learning without stacking * added layers Updates to mlagents_envs: * decode multiple pngs packed into a single observation/hw20-segmentation
Jonathan Harper
4 年前
当前提交
5906cd61
共有 24 个文件被更改,包括 2058 次插入 和 905 次删除
-
92Project/Assets/ML-Agents/Examples/FoodCollector/Prefabs/BadFood.prefab
-
92Project/Assets/ML-Agents/Examples/FoodCollector/Prefabs/Food.prefab
-
854Project/Assets/ML-Agents/Examples/FoodCollector/Prefabs/VisualFoodCollectorArea.prefab
-
9Project/Assets/ML-Agents/Examples/FoodCollector/Scenes/VisualFoodCollector.unity
-
24Project/Assets/ML-Agents/Examples/GridWorld/Prefabs/Area.prefab
-
318Project/Assets/ML-Agents/Examples/GridWorld/Prefabs/goal.prefab
-
326Project/Assets/ML-Agents/Examples/GridWorld/Prefabs/pit.prefab
-
5Project/ProjectSettings/EditorBuildSettings.asset
-
2Project/ProjectSettings/ProjectVersion.txt
-
16Project/ProjectSettings/TagManager.asset
-
1com.unity.ml-agents/Editor/CameraSensorComponentEditor.cs
-
481com.unity.ml-agents/Runtime/Sensors/CameraSensor.cs
-
24com.unity.ml-agents/Runtime/Sensors/CameraSensorComponent.cs
-
28ml-agents-envs/mlagents_envs/rpc_utils.py
-
105com.unity.ml-agents/Editor/CameraSensorSettingsDrawer.cs
-
3com.unity.ml-agents/Editor/CameraSensorSettingsDrawer.cs.meta
-
37com.unity.ml-agents/Runtime/Sensors/CameraSensorSettings.cs
-
3com.unity.ml-agents/Runtime/Sensors/CameraSensorSettings.cs.meta
-
83com.unity.ml-agents/Runtime/Sensors/ColorEncoding.cs
-
3com.unity.ml-agents/Runtime/Sensors/ColorEncoding.cs.meta
-
8com.unity.ml-agents/Runtime/Shaders.meta
-
440com.unity.ml-agents/Runtime/Shaders/UberReplacement.shader
-
9com.unity.ml-agents/Runtime/Shaders/UberReplacement.shader.meta
854
Project/Assets/ML-Agents/Examples/FoodCollector/Prefabs/VisualFoodCollectorArea.prefab
文件差异内容过多而无法显示
查看文件
文件差异内容过多而无法显示
查看文件
|
|||
m_EditorVersion: 2018.4.17f1 |
|||
m_EditorVersion: 2018.4.18f1 |
|
|||
using Unity.MLAgents.Sensors; |
|||
using UnityEditor; |
|||
using UnityEngine; |
|||
|
|||
namespace Unity.MLAgents.Editor |
|||
{ |
|||
/// <summary>
|
|||
/// PropertyDrawer for BrainParameters. Defines how BrainParameters are displayed in the
|
|||
/// Inspector.
|
|||
/// </summary>
|
|||
[CustomPropertyDrawer(typeof(CameraSensorSettings))] |
|||
internal class CameraSensorSettingsDrawer : PropertyDrawer |
|||
{ |
|||
// The height of a line in the Unity Inspectors
|
|||
const float k_LineHeight = 17f; |
|||
const string k_LayerMasksPropName = "LayerMasks"; |
|||
const string k_DisableCameraPropName = "DisableCamera"; |
|||
const string k_EnableDepthPropName = "EnableDepth"; |
|||
const string k_EnableAutoSegmentPropName = "EnableAutoSegment"; |
|||
|
|||
public override float GetPropertyHeight(SerializedProperty property, GUIContent label) |
|||
{ |
|||
return GetHeightDrawLayerMasks(property) + 4 * k_LineHeight; |
|||
} |
|||
|
|||
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) |
|||
{ |
|||
var indent = EditorGUI.indentLevel; |
|||
position.height = k_LineHeight; |
|||
EditorGUI.BeginProperty(position, label, property); |
|||
|
|||
var disableCamProp = property.FindPropertyRelative(k_DisableCameraPropName); |
|||
EditorGUI.PropertyField(position, disableCamProp, new GUIContent("Disable camera")); |
|||
position.y += k_LineHeight; |
|||
|
|||
var enableDepthProp = property.FindPropertyRelative(k_EnableDepthPropName); |
|||
EditorGUI.PropertyField(position, enableDepthProp, new GUIContent("Enable depth channel")); |
|||
position.y += k_LineHeight; |
|||
|
|||
var enableAutoSegmentProp = property.FindPropertyRelative(k_EnableAutoSegmentPropName); |
|||
EditorGUI.PropertyField(position, enableAutoSegmentProp, new GUIContent("Enable auto segment")); |
|||
position.y += k_LineHeight; |
|||
|
|||
// Vector Observations
|
|||
DrawLayerMasks(position, property); |
|||
position.y += GetHeightDrawLayerMasks(property); |
|||
|
|||
EditorGUI.EndProperty(); |
|||
EditorGUI.indentLevel = indent; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Draws the Layer Masks for the CameraSensorComponent
|
|||
/// </summary>
|
|||
/// <param name="position">Rectangle on the screen to use for the property GUI.</param>
|
|||
/// <param name="property">The SerializedProperty of the CameraSensorComponent
|
|||
/// to make the custom GUI for.</param>
|
|||
static void DrawLayerMasks(Rect position, SerializedProperty property) |
|||
{ |
|||
var layerMasksProp = property.FindPropertyRelative(k_LayerMasksPropName); |
|||
var newSize = EditorGUI.IntField( |
|||
position, |
|||
"# Layer Masks", |
|||
layerMasksProp.arraySize |
|||
); |
|||
|
|||
// This check is here due to:
|
|||
// https://fogbugz.unity3d.com/f/cases/1246524/
|
|||
// If this case has been resolved, please remove this if condition.
|
|||
if (newSize != layerMasksProp.arraySize) |
|||
{ |
|||
layerMasksProp.arraySize = newSize; |
|||
} |
|||
|
|||
position.y += k_LineHeight; |
|||
position.x += 20; |
|||
position.width -= 20; |
|||
for (var branchIndex = 0; |
|||
branchIndex < layerMasksProp.arraySize; |
|||
branchIndex++) |
|||
{ |
|||
var layerMask = |
|||
layerMasksProp.GetArrayElementAtIndex(branchIndex); |
|||
|
|||
var newMaskLayer = EditorGUI.LayerField( |
|||
position, |
|||
new GUIContent("Mask " + branchIndex + " layer number:", |
|||
"Layer number for layer mask " + branchIndex + "."), |
|||
layerMask.intValue |
|||
); |
|||
if (layerMask.intValue != newMaskLayer) |
|||
{ |
|||
layerMask.intValue = newMaskLayer; |
|||
} |
|||
position.y += k_LineHeight; |
|||
} |
|||
} |
|||
|
|||
static float GetHeightDrawLayerMasks(SerializedProperty property) |
|||
{ |
|||
var layerMasksProp = property.FindPropertyRelative(k_LayerMasksPropName); |
|||
return (1 + layerMasksProp.arraySize) * k_LineHeight; |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 10f930409af6449fa72f05801f08cfb6 |
|||
timeCreated: 1592871661 |
|
|||
using System; |
|||
|
|||
namespace Unity.MLAgents.Sensors |
|||
{ |
|||
[Serializable] |
|||
public class CameraSensorSettings |
|||
{ |
|||
/// <summary>
|
|||
/// Whether to disable sensor reporting back the raw pixels from the camera.
|
|||
/// </summary>
|
|||
/// <remarks>
|
|||
/// This may be useful if using depth, layer masks, etc. if the raw pixels from the camera
|
|||
/// would be redundant.
|
|||
/// </remarks>
|
|||
public bool DisableCamera; |
|||
|
|||
/// <summary>
|
|||
/// Whether to add a depth field channel to the sensor.
|
|||
/// </summary>
|
|||
public bool EnableDepth; |
|||
|
|||
/// <summary>
|
|||
/// Whether to enable automatic segmentation by layer
|
|||
/// </summary>
|
|||
public bool EnableAutoSegment; |
|||
|
|||
/// <summary>
|
|||
/// The list of Unity Layers to render masks for.
|
|||
/// </summary>
|
|||
/// <remarks>
|
|||
/// In addition to RGB, Grayscale, or other image channels, we provide "layer masks" as
|
|||
/// a way to explicitly capture whether objects in a certain Unity Layer fall within each
|
|||
/// pixel.
|
|||
/// </remarks>
|
|||
public int[] LayerMasks = {}; |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: f02d656dd2124d339fd2056ca0f26839 |
|||
timeCreated: 1592871589 |
|
|||
using UnityEngine; |
|||
|
|||
namespace Unity.MLAgents.Sensors |
|||
{ |
|||
|
|||
public class ColorEncoding |
|||
{ |
|||
public static byte ReverseBits(byte value) |
|||
{ |
|||
return (byte)((value * 0x0202020202 & 0x010884422010) % 1023); |
|||
} |
|||
|
|||
public static int SparsifyBits(byte value, int sparse) |
|||
{ |
|||
int retVal = 0; |
|||
for (int bits = 0; bits < 8; bits++, value >>= 1) |
|||
{ |
|||
retVal |= (value & 1); |
|||
retVal <<= sparse; |
|||
} |
|||
return retVal >> sparse; |
|||
} |
|||
|
|||
public static Color EncodeIDAsColor(int instanceId) |
|||
{ |
|||
var uid = instanceId * 2; |
|||
if (uid < 0) |
|||
uid = -uid + 1; |
|||
|
|||
var sid = |
|||
(SparsifyBits((byte)(uid >> 16), 3) << 2) | |
|||
(SparsifyBits((byte)(uid >> 8), 3) << 1) | |
|||
SparsifyBits((byte)(uid ), 3); |
|||
//Debug.Log(uid + " >>> " + System.Convert.ToString(sid, 2).PadLeft(24, '0'));
|
|||
|
|||
var r = (byte)(sid >> 8); |
|||
var g = (byte)(sid >> 16); |
|||
var b = (byte)(sid); |
|||
|
|||
//Debug.Log(r + " " + g + " " + b);
|
|||
return new Color32 (r, g, b, 255); |
|||
} |
|||
|
|||
public static Color EncodeTagAsColor(string tag) |
|||
{ |
|||
var hash = tag.GetHashCode(); |
|||
var a = (byte)(hash >> 24); |
|||
var r = (byte)(hash >> 16); |
|||
var g = (byte)(hash >> 8); |
|||
var b = (byte)(hash); |
|||
return new Color32 (r, g, b, a); |
|||
} |
|||
|
|||
public static Color EncodeLayerAsColor(int layer) |
|||
{ |
|||
// Following value must be in the range (0.5 .. 1.0)
|
|||
// in order to avoid color overlaps when using 'divider' in this func
|
|||
var z = .7f; |
|||
|
|||
// First 8 layers are Unity Builtin layers
|
|||
// Unity supports up to 32 layers in total
|
|||
|
|||
// Lets create palette of unique 16 colors
|
|||
var uniqueColors = new []{ |
|||
new Color(1,1,1,1), new Color(z,z,z,1), // 0
|
|||
new Color(1,1,z,1), new Color(1,z,1,1), new Color(z,1,1,1), //
|
|||
new Color(1,z,0,1), new Color(z,0,1,1), new Color(0,1,z,1), // 7
|
|||
|
|||
new Color(1,0,0,1), new Color(0,1,0,1), new Color(0,0,1,1), // 8
|
|||
new Color(1,1,0,1), new Color(1,0,1,1), new Color(0,1,1,1), //
|
|||
new Color(1,z,z,1), new Color(z,1,z,1) // 15
|
|||
}; |
|||
|
|||
// Create as many colors as necessary by using base 16 color palette
|
|||
// To create more than 16 - will simply adjust brightness with 'divider'
|
|||
var color = uniqueColors[layer % uniqueColors.Length]; |
|||
var divider = 1.0f + Mathf.Floor(layer / uniqueColors.Length); |
|||
color /= divider; |
|||
|
|||
return color; |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: e3d8e3ee929e4029af6d000dbc7ca686 |
|||
timeCreated: 1592847947 |
|
|||
fileFormatVersion: 2 |
|||
guid: b5af96abaf69d4ed2956e12ef0bf7e8f |
|||
folderAsset: yes |
|||
DefaultImporter: |
|||
externalObjects: {} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
// Based on builtin Internal-DepthNormalsTexture.shader |
|||
// EncodeDepthNormal() is replaced with custom Output() function |
|||
|
|||
Shader "Hidden/UberReplacement" { |
|||
Properties { |
|||
_MainTex ("", 2D) = "white" {} |
|||
_Cutoff ("", Float) = 0.5 |
|||
_Color ("", Color) = (1,1,1,1) |
|||
|
|||
_ObjectColor ("Object Color", Color) = (1,1,1,1) |
|||
_CategoryColor ("Category Color", Color) = (0,1,0,1) |
|||
_LayerNumber ("Layer Number", int) = -1 |
|||
} |
|||
|
|||
SubShader { |
|||
CGINCLUDE |
|||
|
|||
fixed4 _ObjectColor; |
|||
fixed4 _CategoryColor; |
|||
int _LayerNumber; |
|||
int _OutputMode; |
|||
|
|||
// remap depth: [0 @ eye .. 1 @ far] => [0 @ near .. 1 @ far] |
|||
inline float Linear01FromEyeToLinear01FromNear(float depth01) |
|||
{ |
|||
float near = _ProjectionParams.y; |
|||
float far = _ProjectionParams.z; |
|||
return (depth01 - near/far) * (1 + near/far); |
|||
} |
|||
|
|||
float4 Output(float depth01, float3 normal) |
|||
{ |
|||
if (_OutputMode == 0) // ObjectId |
|||
{ |
|||
return _ObjectColor; |
|||
} |
|||
else if (_OutputMode == 1) // CategoryId |
|||
{ |
|||
return _CategoryColor; |
|||
} |
|||
else if (_OutputMode == 2) // DepthCompressed |
|||
{ |
|||
float linearZFromNear = Linear01FromEyeToLinear01FromNear(depth01); |
|||
float k = 0.25; // compression factor |
|||
return pow(linearZFromNear, k); |
|||
} |
|||
else if (_OutputMode == 3) // Layers |
|||
{ |
|||
return float4(_LayerNumber / 100.0, 0.0, 0.0, 1); |
|||
} |
|||
|
|||
// unsupported _OutputMode |
|||
return float4(1, 0.5, 0.5, 1); |
|||
} |
|||
ENDCG |
|||
|
|||
// Support for different RenderTypes |
|||
// The following code is based on builtin Internal-DepthNormalsTexture.shader |
|||
|
|||
Tags { "RenderType"="Opaque" } |
|||
Pass { |
|||
CGPROGRAM |
|||
#pragma vertex vert |
|||
#pragma fragment frag |
|||
#include "UnityCG.cginc" |
|||
struct v2f { |
|||
float4 pos : SV_POSITION; |
|||
float4 nz : TEXCOORD0; |
|||
UNITY_VERTEX_OUTPUT_STEREO |
|||
}; |
|||
v2f vert( appdata_base v ) { |
|||
v2f o; |
|||
UNITY_SETUP_INSTANCE_ID(v); |
|||
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); |
|||
o.pos = UnityObjectToClipPos(v.vertex); |
|||
o.nz.xyz = COMPUTE_VIEW_NORMAL; |
|||
o.nz.w = COMPUTE_DEPTH_01; |
|||
return o; |
|||
} |
|||
fixed4 frag(v2f i) : SV_Target { |
|||
return Output (i.nz.w, i.nz.xyz); |
|||
} |
|||
ENDCG |
|||
} |
|||
} |
|||
|
|||
SubShader { |
|||
Tags { "RenderType"="TransparentCutout" } |
|||
Pass { |
|||
CGPROGRAM |
|||
#pragma vertex vert |
|||
#pragma fragment frag |
|||
#include "UnityCG.cginc" |
|||
struct v2f { |
|||
float4 pos : SV_POSITION; |
|||
float2 uv : TEXCOORD0; |
|||
float4 nz : TEXCOORD1; |
|||
UNITY_VERTEX_OUTPUT_STEREO |
|||
}; |
|||
uniform float4 _MainTex_ST; |
|||
v2f vert( appdata_base v ) { |
|||
v2f o; |
|||
UNITY_SETUP_INSTANCE_ID(v); |
|||
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); |
|||
o.pos = UnityObjectToClipPos(v.vertex); |
|||
o.uv = TRANSFORM_TEX(v.texcoord, _MainTex); |
|||
o.nz.xyz = COMPUTE_VIEW_NORMAL; |
|||
o.nz.w = COMPUTE_DEPTH_01; |
|||
return o; |
|||
} |
|||
uniform sampler2D _MainTex; |
|||
uniform fixed _Cutoff; |
|||
uniform fixed4 _Color; |
|||
fixed4 frag(v2f i) : SV_Target { |
|||
fixed4 texcol = tex2D( _MainTex, i.uv ); |
|||
clip( texcol.a*_Color.a - _Cutoff ); |
|||
return Output (i.nz.w, i.nz.xyz); |
|||
} |
|||
ENDCG |
|||
} |
|||
} |
|||
|
|||
SubShader { |
|||
Tags { "RenderType"="TreeBark" } |
|||
Pass { |
|||
CGPROGRAM |
|||
#pragma vertex vert |
|||
#pragma fragment frag |
|||
#include "UnityCG.cginc" |
|||
#include "Lighting.cginc" |
|||
#include "UnityBuiltin3xTreeLibrary.cginc" |
|||
struct v2f { |
|||
float4 pos : SV_POSITION; |
|||
float2 uv : TEXCOORD0; |
|||
float4 nz : TEXCOORD1; |
|||
UNITY_VERTEX_OUTPUT_STEREO |
|||
}; |
|||
v2f vert( appdata_full v ) { |
|||
v2f o; |
|||
UNITY_SETUP_INSTANCE_ID(v); |
|||
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); |
|||
TreeVertBark(v); |
|||
|
|||
o.pos = UnityObjectToClipPos(v.vertex); |
|||
o.uv = v.texcoord.xy; |
|||
o.nz.xyz = COMPUTE_VIEW_NORMAL; |
|||
o.nz.w = COMPUTE_DEPTH_01; |
|||
return o; |
|||
} |
|||
fixed4 frag( v2f i ) : SV_Target { |
|||
return Output (i.nz.w, i.nz.xyz); |
|||
} |
|||
ENDCG |
|||
} |
|||
} |
|||
|
|||
SubShader { |
|||
Tags { "RenderType"="TreeLeaf" } |
|||
Pass { |
|||
CGPROGRAM |
|||
#pragma vertex vert |
|||
#pragma fragment frag |
|||
#include "UnityCG.cginc" |
|||
#include "Lighting.cginc" |
|||
#include "UnityBuiltin3xTreeLibrary.cginc" |
|||
struct v2f { |
|||
float4 pos : SV_POSITION; |
|||
float2 uv : TEXCOORD0; |
|||
float4 nz : TEXCOORD1; |
|||
UNITY_VERTEX_OUTPUT_STEREO |
|||
}; |
|||
v2f vert( appdata_full v ) { |
|||
v2f o; |
|||
UNITY_SETUP_INSTANCE_ID(v); |
|||
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); |
|||
TreeVertLeaf(v); |
|||
|
|||
o.pos = UnityObjectToClipPos(v.vertex); |
|||
o.uv = v.texcoord.xy; |
|||
o.nz.xyz = COMPUTE_VIEW_NORMAL; |
|||
o.nz.w = COMPUTE_DEPTH_01; |
|||
return o; |
|||
} |
|||
uniform sampler2D _MainTex; |
|||
uniform fixed _Cutoff; |
|||
fixed4 frag( v2f i ) : SV_Target { |
|||
half alpha = tex2D(_MainTex, i.uv).a; |
|||
|
|||
clip (alpha - _Cutoff); |
|||
return Output (i.nz.w, i.nz.xyz); |
|||
} |
|||
ENDCG |
|||
} |
|||
} |
|||
|
|||
SubShader { |
|||
Tags { "RenderType"="TreeOpaque" "DisableBatching"="True" } |
|||
Pass { |
|||
CGPROGRAM |
|||
#pragma vertex vert |
|||
#pragma fragment frag |
|||
#include "UnityCG.cginc" |
|||
#include "TerrainEngine.cginc" |
|||
struct v2f { |
|||
float4 pos : SV_POSITION; |
|||
float4 nz : TEXCOORD0; |
|||
UNITY_VERTEX_OUTPUT_STEREO |
|||
}; |
|||
struct appdata { |
|||
float4 vertex : POSITION; |
|||
float3 normal : NORMAL; |
|||
fixed4 color : COLOR; |
|||
UNITY_VERTEX_INPUT_INSTANCE_ID |
|||
}; |
|||
v2f vert( appdata v ) { |
|||
v2f o; |
|||
UNITY_SETUP_INSTANCE_ID(v); |
|||
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); |
|||
TerrainAnimateTree(v.vertex, v.color.w); |
|||
o.pos = UnityObjectToClipPos(v.vertex); |
|||
o.nz.xyz = COMPUTE_VIEW_NORMAL; |
|||
o.nz.w = COMPUTE_DEPTH_01; |
|||
return o; |
|||
} |
|||
fixed4 frag(v2f i) : SV_Target { |
|||
return Output (i.nz.w, i.nz.xyz); |
|||
} |
|||
ENDCG |
|||
} |
|||
} |
|||
|
|||
SubShader { |
|||
Tags { "RenderType"="TreeTransparentCutout" "DisableBatching"="True" } |
|||
Pass { |
|||
Cull Back |
|||
CGPROGRAM |
|||
#pragma vertex vert |
|||
#pragma fragment frag |
|||
#include "UnityCG.cginc" |
|||
#include "TerrainEngine.cginc" |
|||
|
|||
struct v2f { |
|||
float4 pos : SV_POSITION; |
|||
float2 uv : TEXCOORD0; |
|||
float4 nz : TEXCOORD1; |
|||
UNITY_VERTEX_OUTPUT_STEREO |
|||
}; |
|||
struct appdata { |
|||
float4 vertex : POSITION; |
|||
float3 normal : NORMAL; |
|||
fixed4 color : COLOR; |
|||
float4 texcoord : TEXCOORD0; |
|||
UNITY_VERTEX_INPUT_INSTANCE_ID |
|||
}; |
|||
v2f vert( appdata v ) { |
|||
v2f o; |
|||
UNITY_SETUP_INSTANCE_ID(v); |
|||
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); |
|||
TerrainAnimateTree(v.vertex, v.color.w); |
|||
o.pos = UnityObjectToClipPos(v.vertex); |
|||
o.uv = v.texcoord.xy; |
|||
o.nz.xyz = COMPUTE_VIEW_NORMAL; |
|||
o.nz.w = COMPUTE_DEPTH_01; |
|||
return o; |
|||
} |
|||
uniform sampler2D _MainTex; |
|||
uniform fixed _Cutoff; |
|||
fixed4 frag(v2f i) : SV_Target { |
|||
half alpha = tex2D(_MainTex, i.uv).a; |
|||
|
|||
clip (alpha - _Cutoff); |
|||
return Output (i.nz.w, i.nz.xyz); |
|||
} |
|||
ENDCG |
|||
} |
|||
Pass { |
|||
Cull Front |
|||
CGPROGRAM |
|||
#pragma vertex vert |
|||
#pragma fragment frag |
|||
#include "UnityCG.cginc" |
|||
#include "TerrainEngine.cginc" |
|||
|
|||
struct v2f { |
|||
float4 pos : SV_POSITION; |
|||
float2 uv : TEXCOORD0; |
|||
float4 nz : TEXCOORD1; |
|||
UNITY_VERTEX_OUTPUT_STEREO |
|||
}; |
|||
struct appdata { |
|||
float4 vertex : POSITION; |
|||
float3 normal : NORMAL; |
|||
fixed4 color : COLOR; |
|||
float4 texcoord : TEXCOORD0; |
|||
UNITY_VERTEX_INPUT_INSTANCE_ID |
|||
}; |
|||
v2f vert( appdata v ) { |
|||
v2f o; |
|||
UNITY_SETUP_INSTANCE_ID(v); |
|||
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); |
|||
TerrainAnimateTree(v.vertex, v.color.w); |
|||
o.pos = UnityObjectToClipPos(v.vertex); |
|||
o.uv = v.texcoord.xy; |
|||
o.nz.xyz = -COMPUTE_VIEW_NORMAL; |
|||
o.nz.w = COMPUTE_DEPTH_01; |
|||
return o; |
|||
} |
|||
uniform sampler2D _MainTex; |
|||
uniform fixed _Cutoff; |
|||
fixed4 frag(v2f i) : SV_Target { |
|||
fixed4 texcol = tex2D( _MainTex, i.uv ); |
|||
clip( texcol.a - _Cutoff ); |
|||
return Output (i.nz.w, i.nz.xyz); |
|||
} |
|||
ENDCG |
|||
} |
|||
|
|||
} |
|||
|
|||
SubShader { |
|||
Tags { "RenderType"="TreeBillboard" } |
|||
Pass { |
|||
Cull Off |
|||
CGPROGRAM |
|||
#pragma vertex vert |
|||
#pragma fragment frag |
|||
#include "UnityCG.cginc" |
|||
#include "TerrainEngine.cginc" |
|||
struct v2f { |
|||
float4 pos : SV_POSITION; |
|||
float2 uv : TEXCOORD0; |
|||
float4 nz : TEXCOORD1; |
|||
UNITY_VERTEX_OUTPUT_STEREO |
|||
}; |
|||
v2f vert (appdata_tree_billboard v) { |
|||
v2f o; |
|||
UNITY_SETUP_INSTANCE_ID(v); |
|||
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); |
|||
TerrainBillboardTree(v.vertex, v.texcoord1.xy, v.texcoord.y); |
|||
o.pos = UnityObjectToClipPos(v.vertex); |
|||
o.uv.x = v.texcoord.x; |
|||
o.uv.y = v.texcoord.y > 0; |
|||
o.nz.xyz = float3(0,0,1); |
|||
o.nz.w = COMPUTE_DEPTH_01; |
|||
return o; |
|||
} |
|||
uniform sampler2D _MainTex; |
|||
fixed4 frag(v2f i) : SV_Target { |
|||
fixed4 texcol = tex2D( _MainTex, i.uv ); |
|||
clip( texcol.a - 0.001 ); |
|||
return Output (i.nz.w, i.nz.xyz); |
|||
} |
|||
ENDCG |
|||
} |
|||
} |
|||
|
|||
SubShader { |
|||
Tags { "RenderType"="GrassBillboard" } |
|||
Pass { |
|||
Cull Off |
|||
CGPROGRAM |
|||
#pragma vertex vert |
|||
#pragma fragment frag |
|||
#include "UnityCG.cginc" |
|||
#include "TerrainEngine.cginc" |
|||
|
|||
struct v2f { |
|||
float4 pos : SV_POSITION; |
|||
fixed4 color : COLOR; |
|||
float2 uv : TEXCOORD0; |
|||
float4 nz : TEXCOORD1; |
|||
UNITY_VERTEX_OUTPUT_STEREO |
|||
}; |
|||
|
|||
v2f vert (appdata_full v) { |
|||
v2f o; |
|||
UNITY_SETUP_INSTANCE_ID(v); |
|||
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); |
|||
WavingGrassBillboardVert (v); |
|||
o.color = v.color; |
|||
o.pos = UnityObjectToClipPos(v.vertex); |
|||
o.uv = v.texcoord.xy; |
|||
o.nz.xyz = COMPUTE_VIEW_NORMAL; |
|||
o.nz.w = COMPUTE_DEPTH_01; |
|||
return o; |
|||
} |
|||
uniform sampler2D _MainTex; |
|||
uniform fixed _Cutoff; |
|||
fixed4 frag(v2f i) : SV_Target { |
|||
fixed4 texcol = tex2D( _MainTex, i.uv ); |
|||
fixed alpha = texcol.a * i.color.a; |
|||
clip( alpha - _Cutoff ); |
|||
return Output (i.nz.w, i.nz.xyz); |
|||
} |
|||
ENDCG |
|||
} |
|||
} |
|||
|
|||
SubShader { |
|||
Tags { "RenderType"="Grass" } |
|||
Pass { |
|||
Cull Off |
|||
CGPROGRAM |
|||
#pragma vertex vert |
|||
#pragma fragment frag |
|||
#include "UnityCG.cginc" |
|||
#include "TerrainEngine.cginc" |
|||
struct v2f { |
|||
float4 pos : SV_POSITION; |
|||
fixed4 color : COLOR; |
|||
float2 uv : TEXCOORD0; |
|||
float4 nz : TEXCOORD1; |
|||
UNITY_VERTEX_OUTPUT_STEREO |
|||
}; |
|||
|
|||
v2f vert (appdata_full v) { |
|||
v2f o; |
|||
UNITY_SETUP_INSTANCE_ID(v); |
|||
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); |
|||
WavingGrassVert (v); |
|||
o.color = v.color; |
|||
o.pos = UnityObjectToClipPos(v.vertex); |
|||
o.uv = v.texcoord; |
|||
o.nz.xyz = COMPUTE_VIEW_NORMAL; |
|||
o.nz.w = COMPUTE_DEPTH_01; |
|||
return o; |
|||
} |
|||
uniform sampler2D _MainTex; |
|||
uniform fixed _Cutoff; |
|||
fixed4 frag(v2f i) : SV_Target { |
|||
fixed4 texcol = tex2D( _MainTex, i.uv ); |
|||
fixed alpha = texcol.a * i.color.a; |
|||
clip( alpha - _Cutoff ); |
|||
return Output (i.nz.w, i.nz.xyz); |
|||
} |
|||
ENDCG |
|||
} |
|||
} |
|||
Fallback Off |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 3ffefcbf3b7a34356bd15ac448c73d3e |
|||
ShaderImporter: |
|||
externalObjects: {} |
|||
defaultTextures: [] |
|||
nonModifiableTextures: [] |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
撰写
预览
正在加载...
取消
保存
Reference in new issue