Skip to content

Commit

Permalink
Changed the way alpha is set up
Browse files Browse the repository at this point in the history
  • Loading branch information
Pseudopode committed Nov 27, 2019
1 parent bb019e4 commit 1480494
Show file tree
Hide file tree
Showing 8 changed files with 123 additions and 61 deletions.
Binary file added Assets/Fur/fur-leo2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
90 changes: 90 additions & 0 deletions Assets/Fur/fur-leo2.png.meta

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

81 changes: 24 additions & 57 deletions Assets/PickObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,15 @@ public static void SetAlpha(this Material material, float value)
color.a = value;
material.color = color;
}

public static void SetColorFloat(this Material material, float value)
{
Color color = material.color;
color.r = value;
color.g = value;
color.b = value;
material.color = color;
}
}


Expand All @@ -45,22 +54,16 @@ public class PickObject : MonoBehaviour
public Material baseMaterial;
public Material shellMaterial;
public Texture2D shellTexture;
//public bool export = false;

public Button buttonFur;

public GameObject infoText;


// Start is called before the first frame update
void Start()
{

}


public void createFur()
{
//if (duplicate)

{
float scaleX = 1, scaleY = 1, scaleZ = 1;
float localY = 0.0f;
Expand All @@ -72,7 +75,9 @@ public void createFur()
scaleY = shellRoot.transform.localScale.y;
scaleZ = shellRoot.transform.localScale.z;

//localY = shellRoot.transform.position.y;
//we just need to set the parent GameObject to have the same material (only useful for this demo)
Material m = Instantiate(baseMaterial);
objToDuplicate.GetComponent<Renderer>().sharedMaterial = m;
}

for (int i = 0; i < shellNumber; i++)
Expand All @@ -85,44 +90,28 @@ public void createFur()
shell.transform.localScale = new Vector3(scaleX, scaleY, scaleZ);

Material m = Instantiate(shellMaterial);
//Material mat = new Material(Shader.Find("Standard");
m.SetAsFade();

Color color = m.color;
//Color color = new Color(1.0f, 1.0f, 1.0f, 1.0f);
color.r = 1.0f / shellNumber * i + colorStartingValue;
color.g = 1.0f / shellNumber * i + colorStartingValue;
color.b = 1.0f / shellNumber * i + colorStartingValue;
color.r = Mathf.Lerp(colorStartingValue, 1.0f, shellNumber);
color.g = Mathf.Lerp(colorStartingValue, 1.0f, shellNumber);
color.b = Mathf.Lerp(colorStartingValue, 1.0f, shellNumber);
m.color = color;

m.name = "Shell_" + i.ToString();
m.SetTexture("_MainTex", shellTexture);
//m.SetAlpha(1.0f - (1.0f / i));
m.SetAlpha((1.0f / (i / 2)));

if (i == 0)
{
Debug.Log("i: " + i + "Alpha value: " + color.a);
m.SetAlpha(0.9f);
}
if (i == 1)
{
Debug.Log("i: " + i + "Alpha value: " + color.a);
m.SetAlpha(0.75f);
}

float layerCoeff = ((float)i) / ((float)shellNumber);
Debug.Log("layerCoeff: " + layerCoeff);
Debug.Log("Value: " + Mathf.Lerp(colorStartingValue, 1.0f, layerCoeff));

m.SetAlpha(Mathf.Lerp(colorStartingValue, 1.0f, layerCoeff));

shell.GetComponent<Renderer>().sharedMaterial = m;
//shell.GetComponent<Renderer>().material.SetAsFade();
//shell.GetComponent<Renderer>().material.SetAlpha(1.0f - (1.0f / i));
//shell.GetComponent<Renderer>().material.name = "Shell_" + i.ToString();
//shell.GetComponent<Renderer>().material.SetTexture("_MainTex", shellTexture);
//shell.GetComponent<Renderer>().material.SetColor("_Color", color);
// shell.GetComponent<Renderer>().material.DisableKeyword("_EMISSION");
shell.GetComponent<Renderer>().material.SetFloat("_Glossiness", Mathf.Lerp(colorStartingValue, 1.0f, layerCoeff) - 0.5f);
}

shellRoot.transform.parent = objToDuplicate.transform;
//objToDuplicate.transform.position = new Vector3(0.0f, 0.0f, 0.0f);
//shellRoot.transform.position = new Vector3(0.0f, 0.0f, 0.0f);

Material mRoot = Instantiate(baseMaterial);
shellRoot.GetComponent<Renderer>().material = mRoot;
Expand All @@ -135,8 +124,6 @@ void Update()
{
if (Input.GetMouseButtonDown(0))
{
// Debug.Log("Mouse is down");

RaycastHit hitInfo = new RaycastHit();
bool hit = Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hitInfo);
if (hit)
Expand All @@ -145,27 +132,7 @@ void Update()

buttonFur.interactable = true;
infoText.SetActive(false);
/* Debug.Log("Hit " + hitInfo.transform.gameObject.name);
if (hitInfo.transform.gameObject.tag == "Construction")
{
Debug.Log("It's working!");
}
else
{
Debug.Log("nopz");
}*/
}
/*else
{
Debug.Log("No hit");
}
Debug.Log("Mouse is down");*/
}






}
}
4 changes: 2 additions & 2 deletions Assets/Scenes/SampleScene.unity
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ MonoBehaviour:
colorStartingValue: 0.75
baseMaterial: {fileID: 2100000, guid: f5e7e0376718e7045a0b807a6e2eb913, type: 2}
shellMaterial: {fileID: 2100000, guid: df35f0ff42acccf46a46daaaaee8c136, type: 2}
shellTexture: {fileID: 2800000, guid: 166e04a991603c040ae1302e93068897, type: 3}
shellTexture: {fileID: 2800000, guid: e30efced99f28894e8b9a878a8ff5817, type: 3}
buttonFur: {fileID: 1404210155}
infoText: {fileID: 1206362163}
--- !u!4 &683208518
Expand Down Expand Up @@ -775,7 +775,7 @@ Transform:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 963194225}
m_LocalRotation: {x: -0.22874412, y: 0.65991217, z: -0.22184816, w: -0.680423}
m_LocalPosition: {x: 6.2603693, y: 4.880243, z: 0.87538666}
m_LocalPosition: {x: 6, y: 4.880243, z: 0.87538666}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
Expand Down
2 changes: 1 addition & 1 deletion Assets/standard_material.mat
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ Material:
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _MainTex:
m_Texture: {fileID: 2800000, guid: 47d2d908061f54ba8bf31c9af00a9a3c, type: 3}
m_Texture: {fileID: 2800000, guid: e30efced99f28894e8b9a878a8ff5817, type: 3}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _MetallicGlossMap:
Expand Down
Binary file added Documentation/texture1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Documentation/texture2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
![Fur Shell Example](Documentation/screen_shells1.png "")

# Quick’n’dirty Fur Shell Demo V1.0
# Quick’n’dirty Fur Shell Demo V1.1

QnFurShell is a demo of the "sheel concept" for Fur rendering in 3D models.

The app is made with Unity, and has been tested & run on Windows & OSX.

## Update 1.1
Changed the way the fur alpha is set, as well as the base color.
![Image008](Documentation/texture1.png)
![Image009](Documentation/texture2.png)

## System Requirements
Unity 2018.3 or more (the script should work on lower version, but the minimum version I used was that one)

Expand Down

0 comments on commit 1480494

Please sign in to comment.