Skip to content

Commit

Permalink
分离了左右眼睛,移动了shader资源
Browse files Browse the repository at this point in the history
  • Loading branch information
bob committed Nov 12, 2022
1 parent d754bc2 commit 44a7a78
Show file tree
Hide file tree
Showing 16 changed files with 248 additions and 25 deletions.
3 changes: 1 addition & 2 deletions Assets/Emotions/Scripts/FaceAnimation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -236,8 +236,7 @@ private void Start()
LoadData();
}

[ExecuteInEditMode]
void Update()
void _Update()
{
if(_State==State.Play)
{
Expand Down
89 changes: 89 additions & 0 deletions Assets/Emotions/Scripts/FurBallParams.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace FurBall
{
//[System.Serializable]
public class BaseParams : ScriptableObject
{
public float _Radius = 1;
public Vector3 _EyeUVR;
public float _EyeScale;

[Range(-30.0f, 30.0f)]
public float _ULid_XY_Rot_Deg = 0;
[Range(-30.0f, 30.0f)]
public float _DLid_XY_Rot_Deg = 0;

[Range(-10.0f, 10.0f)]
public float _ULid_YZ_Rot_Start_Deg = 0;
[Range(-10.0f, 10.0f)]
public float _DLid_YZ_Rot_Start_Deg = 0;

[Range(-10.0f, 90.0f)]
public float _ULid_YZ_Rot_Range_Deg = 80;
[Range(-90.0f, 10.0f)]
public float _DLid_YZ_Rot_Range_Deg = -80;

public Color _FurColor = Color.white;
}

public class AniParams
{
public Vector3 _Pos = Vector3.zero;
public Quaternion _Rot = Quaternion.identity;


public float _Eye1Open = 1;
public float _Eye2Open = 1;

}

public class FurBallParams : MonoBehaviour
{
public BaseParams _baseParams;


Transform _trans;
Transform trans
{
get
{
if(_trans==null)
{
_trans = transform;
}
return _trans;
}
}

Material _mat;
Material mat
{
get
{
if(_mat==null)
{
var mr = GetComponent<MeshRenderer>();
_mat = mr.sharedMaterial;
}
return _mat;
}
}

[ContextMenu("SaveBaseParams")]
void saveBaseParams()
{

}



private void Update()
{

}

}
}
11 changes: 11 additions & 0 deletions Assets/Emotions/Scripts/FurBallParams.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Assets/Emotions/Scripts/Utils.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

61 changes: 61 additions & 0 deletions Assets/Emotions/Scripts/Utils/Utils.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace FFUtils
{
public static class Maths
{
public static Vector3 sphericalToCartesian(Vector3 uvr, Vector3 center)
{
Vector3 pos;

uvr.x = Mathf.Clamp01(uvr.x);
uvr.y = Mathf.Clamp01(uvr.y);
uvr.x *= Mathf.PI;
uvr.y *= Mathf.PI;

pos.x = Mathf.Sin(uvr.y) * Mathf.Cos(uvr.x);
pos.z = Mathf.Sin(uvr.y) * Mathf.Sin(uvr.x);
pos.y = Mathf.Cos(uvr.y);
pos *= uvr.z;
pos += center;
return pos;
}
}

public class Mat_NameID
{
private string _Name;
private int _ID;

public string Name
{
get
{
return _Name;
}
}

public int ID
{
get
{
return _ID;
}
set
{
_ID = value;
}
}

public Mat_NameID(string name)
{
_Name = name;
_ID = Shader.PropertyToID(_Name);
}
}


}

11 changes: 11 additions & 0 deletions Assets/Emotions/Scripts/Utils/Utils.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Assets/Emotions/Shaders.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ Material:
- _DetailNormalMapScale: 1
- _DstBlend: 0
- _EnvironmentReflections: 1
- _Eye1Open: 1
- _Eye2Open: 1
- _EyelidThickness: 0.05
- _FurDepth: 0.362
- _FurDepthScale: 5
Expand Down Expand Up @@ -122,17 +124,17 @@ Material:
- _BlockBall_Offset_Scale: {r: 0, g: 0, b: 0, a: 0.8}
- _Color: {r: 1, g: 1, b: 1, a: 1}
- _DownlidOffset: {r: 0, g: 0, b: 0, a: 1}
- _Downlid_Start_Range: {r: -1.8, g: 3.9, b: 0, a: 1}
- _Downlid_Start_Range: {r: 0, g: -0.9, b: 0, a: 1}
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1}
- _Eyeball_Pos_Scale: {r: 0.22, g: 0, b: 0.35, a: 0.32}
- _FurColor: {r: 1, g: 1, b: 1, a: 1}
- _HighlightOffset: {r: 0.05, g: 0.05, b: 0, a: 1}
- _IrisColor: {r: 0.089999996, g: 0.0315, b: 0.0135, a: 1}
- _Iris_UV: {r: 0.5, g: 0.5, b: 0, a: 1}
- _SpecColor: {r: 0.19999996, g: 0.19999996, b: 0.19999996, a: 1}
- _UpDownLid_XYRot: {r: -0.6, g: 0.6, b: 0, a: 1}
- _UpDownLid_XYRot: {r: 0, g: 0, b: 0, a: 1}
- _UplidOffset: {r: 0, g: -0.2, b: -0, a: 1}
- _Uplid_Start_Range: {r: 1.8, g: -3.9, b: 0, a: 1}
- _Uplid_Start_Range: {r: 0, g: 0.9, b: 0, a: 1}
m_BuildTextureStacks: []
--- !u!114 &1260275427789698038
MonoBehaviour:
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ Shader "Unlit/furBall"

_UpDownLid_XYRot("UpDownLid_XYRot",Vector) = (0.6,-0.6,0.0)

_Eye1Open("Eye1Open",Range(0,1)) = 0.5
_Eye2Open("Eye2Open",Range(0,1)) = 0.5

_Iris_UV("Iris_UV",Vector) = (0.5,0.5,0.0)
_IrisColor("IrisColor", Color) = (0.09,0.0315,0.0135)
_IrisSize("IrisSize", Range(0.1,1.0)) = 0.8
Expand Down Expand Up @@ -124,6 +127,8 @@ Shader "Unlit/furBall"
float2 _HighlightOffset;
float _AAScale;
float4 _FurColor;
float _Eye1Open;
float _Eye2Open;

float3 animData;

Expand Down Expand Up @@ -267,39 +272,53 @@ Shader "Unlit/furBall"

//return ret;

//eyelid
float3 oos = qos - _Eyeball_Pos_Scale.xyz*_Radius;
float d2 = sdSphere(oos,_Radius*(_Eyeball_Pos_Scale.w + _EyelidThickness));

oos += _UplidOffset * _Radius;
//eyelid1
float3 posEye1 = pos - _Eyeball_Pos_Scale.xyz*_Radius;
float dLid1 = sdSphere(posEye1,_Radius*(_Eyeball_Pos_Scale.w + _EyelidThickness));

float3 posUpLid = posEye1;
posUpLid += _UplidOffset * _Radius;
posUpLid.xy = rot(posUpLid.xy, _UpDownLid_XYRot.x);

float3 posDownLid = posEye1;
posDownLid += _DownlidOffset * _Radius;
posDownLid.xy = rot(posDownLid.xy, _UpDownLid_XYRot.y);

posUpLid.yz = rot(posUpLid.yz,_Uplid_Start_Range.x+_Uplid_Start_Range.y*_Eye1Open);
posDownLid.yz = rot(posDownLid.yz,_Downlid_Start_Range.x+_Downlid_Start_Range.y*_Eye1Open);

// oos.z += 0.2;
// oos.y += -0.0;
dLid1 = smax(dLid1-0.005*_Radius, -max(posUpLid.y+0.098*_Radius,-posDownLid.y-0.025*_Radius), 0.06*_Radius );

oos.xy = rot(oos.xy, _UpDownLid_XYRot.x);
oos.yz = rot(oos.yz,_Uplid_Start_Range.x+_Uplid_Start_Range.y*animData.x);
//eyelid2
float3 posEye2 = pos - float3(-_Eyeball_Pos_Scale.x,_Eyeball_Pos_Scale.yz)*_Radius;
float dLid2 = sdSphere(posEye2,_Radius*(_Eyeball_Pos_Scale.w + _EyelidThickness));

float3 eos = qos - _Eyeball_Pos_Scale.xyz*_Radius;
posUpLid = posEye2;
posUpLid += _UplidOffset * _Radius;
posUpLid.xy = rot(posUpLid.xy, -_UpDownLid_XYRot.x);

eos += _DownlidOffset * _Radius;
eos.xy = rot(eos.xy, _UpDownLid_XYRot.y);
eos.yz = rot(eos.yz,_Downlid_Start_Range.x+_Downlid_Start_Range.y*animData.x);
posDownLid = posEye2;
posDownLid += _DownlidOffset * _Radius;
posDownLid.xy = rot(posDownLid.xy, -_UpDownLid_XYRot.y);

d2 = smax(d2-0.005*_Radius, -max(oos.y+0.098*_Radius,-eos.y-0.025*_Radius), 0.06*_Radius );
d2 = smin(d2,d,0.1*_Radius);
// d2 = min(d2,d);
posUpLid.yz = rot(posUpLid.yz,_Uplid_Start_Range.x+_Uplid_Start_Range.y*_Eye2Open);
posDownLid.yz = rot(posDownLid.yz,_Downlid_Start_Range.x+_Downlid_Start_Range.y*_Eye2Open);

//d2 = d;
dLid2 = smax(dLid2-0.005*_Radius, -max(posUpLid.y+0.098*_Radius,-posDownLid.y-0.025*_Radius), 0.06*_Radius );

ret.x = d2;
float dLid = smin(dLid1,dLid2,0.1*_Radius);

d = smin(dLid,d,0.1*_Radius);

ret.x = d;
outMat = 1.0;
uvw = pos;

// return ret;

//eyeball
// pos.x /= 1.05;
eos = qos-_Eyeball_Pos_Scale.xyz*_Radius;
float3 eos = qos-_Eyeball_Pos_Scale.xyz*_Radius;
d = sdSphere(eos,_Eyeball_Pos_Scale.w*_Radius);

if(d<ret.x)
Expand Down Expand Up @@ -594,6 +613,8 @@ Shader "Unlit/furBall"
// animData.y = 0.0;
animData.z = -0.25 + 0.2*(1.0-turn)*smoothstep(-0.3,0.9,sin(_Time.y*1.1)) + 0.05*cos(_Time.y*2.7);

animData = 0;

// sample the texture
float4 col = scene(ray);
total += col;
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ GameObject:
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
m_IsActive: 0
--- !u!4 &17069873
Transform:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -1455,6 +1455,7 @@ GameObject:
- component: {fileID: 1313802208}
- component: {fileID: 1313802207}
- component: {fileID: 1313802206}
- component: {fileID: 1313802210}
m_Layer: 1
m_Name: furBall
m_TagString: Untagged
Expand Down Expand Up @@ -1541,6 +1542,18 @@ Transform:
m_Father: {fileID: 0}
m_RootOrder: 11
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &1313802210
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1313802205}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 372442555c619394092be7d04348066d, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!1 &1327010782
GameObject:
m_ObjectHideFlags: 0
Expand Down

0 comments on commit 44a7a78

Please sign in to comment.