ThePixelgon, hello Grant

This commit is contained in:
spatialfree 2021-01-22 20:55:48 -08:00
parent 91233f31dd
commit f6727465b3
8 changed files with 479 additions and 6 deletions

View file

@ -0,0 +1,78 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!21 &2100000
Material:
serializedVersion: 6
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: Pixelgon
m_Shader: {fileID: 4800000, guid: 84128a9a537450e45ae8fd3343411f69, type: 3}
m_ShaderKeywords:
m_LightmapFlags: 4
m_EnableInstancingVariants: 0
m_DoubleSidedGI: 0
m_CustomRenderQueue: -1
stringTagMap: {}
disabledShaderPasses: []
m_SavedProperties:
serializedVersion: 3
m_TexEnvs:
- _BumpMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailAlbedoMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailMask:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailNormalMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _EmissionMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _MainTex:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _MetallicGlossMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _OcclusionMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _ParallaxMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
m_Floats:
- _BumpScale: 1
- _Cutoff: 0.5
- _DetailNormalMapScale: 1
- _DstBlend: 0
- _GlossMapScale: 1
- _Glossiness: 0.5
- _GlossyReflections: 1
- _Metallic: 0
- _Mode: 0
- _OcclusionStrength: 1
- _Parallax: 0.02
- _Shade: 1
- _SmoothnessTextureChannel: 0
- _SpecularHighlights: 1
- _SrcBlend: 1
- _UVSec: 0
- _ZWrite: 1
m_Colors:
- _Color: {r: 1, g: 1, b: 1, a: 1}
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1}

View file

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: a585c23dd38de0a47b19356467c1f28e
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 0
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,92 @@
Shader "Custom/Pixelgon"
{
Properties
{
_MainTex ("Texture", 2D) = "" {}
_Shade ("Shade", Float) = 1
}
SubShader
{
Tags { "RenderType"="Transparent" }
Cull Off
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
sampler2D _MainTex;
float4 _MainTex_ST;
float _Shade;
struct meshdata
{
float4 vertex : POSITION;
float3 normal : NORMAL;
float2 uv : TEXCOORD0;
float4 color : COLOR;
};
struct v2f
{
float4 vertex : SV_POSITION;
float4 worldPos : TEXCOORD1;
float3 normal : TEXCOORD2;
float2 uv : TEXCOORD0;
float4 color : COLOR;
};
float DeRez(float value)
{
return float(round(value * 420)) / 420;
}
float3 hsv2rgb(float3 c)
{
c = float3(c.x, clamp(c.yz, 0.0, 1.0));
float4 K = float4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);
float3 p = abs(frac(c.xxx + K.xyz) * 6.0 - K.www);
return c.z * lerp(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);
}
v2f vert (meshdata v)
{
v2f o;
v.vertex.x = DeRez(v.vertex.x);
v.vertex.y = DeRez(v.vertex.y);
v.vertex.z = DeRez(v.vertex.z);
o.vertex = UnityObjectToClipPos(v.vertex);
o.worldPos = mul(unity_ObjectToWorld, v.vertex);
o.normal = UnityObjectToWorldNormal(v.normal);
o.uv = TRANSFORM_TEX(v.uv, _MainTex);
o.color = v.color * _Shade;
return o;
}
float4 frag (v2f i) : SV_Target
{
float4 col = tex2D(_MainTex, i.uv);
clip(col.a - 0.5);
// float shade = clamp(1.5 + dot(i.normal, float3(0, -1, 0)), 0, 1);
// col.r *= 1.5 - shade;
// col.g *= 1.5 - shade;
// col.b *= shade;
if (saturate(dot(normalize(UnityWorldSpaceViewDir(i.worldPos)), i.normal)) < 0.333)
{
col *= 0.9;
}
// col *= float4(hsv2rgb(float3(saturate(dot(normalize(UnityWorldSpaceViewDir(i.worldPos)), i.normal)), 1, 1)), 1);
return col * i.color;
}
ENDCG
}
}
Fallback "Legacy Shaders/Transparent/Cutout/Soft Edge Unlit"
}

View file

@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 84128a9a537450e45ae8fd3343411f69
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
userData:
assetBundleName:
assetBundleVariant:

View file

@ -48,6 +48,7 @@
o.vertex = UnityObjectToClipPos(v.vertex);
o.worldPos = mul(unity_ObjectToWorld, v.vertex);
o.normal = UnityObjectToWorldNormal(v.normal);
o.color = float4(1,1,1,1);
return o;
}

View file

@ -122,6 +122,151 @@ NavMeshSettings:
debug:
m_Flags: 0
m_NavMeshData: {fileID: 0}
--- !u!1 &809303
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 809305}
- component: {fileID: 809304}
m_Layer: 0
m_Name: The Pixelgon
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!114 &809304
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 809303}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 96d4e00eaa35fc8448455b6901a0c20b, type: 3}
m_Name:
m_EditorClassIdentifier:
vertices:
- {x: 0, y: 0, z: 0}
- {x: 0, y: 0.5, z: 0.5}
- {x: 0.5, y: 0.5, z: 0.5}
- {x: 0.5, y: 0, z: 0}
meshPoint: {fileID: -5658524651756503351, guid: dc6240c783ee7974e8811c10e071e0cc,
type: 3}
mat: {fileID: 2100000, guid: a585c23dd38de0a47b19356467c1f28e, type: 2}
--- !u!4 &809305
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 809303}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 8
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &59300833
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 59300837}
- component: {fileID: 59300836}
- component: {fileID: 59300835}
- component: {fileID: 59300834}
m_Layer: 0
m_Name: Quad
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!64 &59300834
MeshCollider:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 59300833}
m_Material: {fileID: 0}
m_IsTrigger: 0
m_Enabled: 1
serializedVersion: 3
m_Convex: 0
m_CookingOptions: 30
m_Mesh: {fileID: 10210, guid: 0000000000000000e000000000000000, type: 0}
--- !u!23 &59300835
MeshRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 59300833}
m_Enabled: 1
m_CastShadows: 1
m_ReceiveShadows: 1
m_DynamicOccludee: 1
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1
m_RayTracingMode: 2
m_RenderingLayerMask: 1
m_RendererPriority: 0
m_Materials:
- {fileID: 2100000, guid: a585c23dd38de0a47b19356467c1f28e, type: 2}
m_StaticBatchInfo:
firstSubMesh: 0
subMeshCount: 0
m_StaticBatchRoot: {fileID: 0}
m_ProbeAnchor: {fileID: 0}
m_LightProbeVolumeOverride: {fileID: 0}
m_ScaleInLightmap: 1
m_ReceiveGI: 1
m_PreserveUVs: 0
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_StitchLightmapSeams: 1
m_SelectedEditorRenderState: 3
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5
m_AutoUVMaxAngle: 89
m_LightmapParameters: {fileID: 0}
m_SortingLayerID: 0
m_SortingLayer: 0
m_SortingOrder: 0
--- !u!33 &59300836
MeshFilter:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 59300833}
m_Mesh: {fileID: 10210, guid: 0000000000000000e000000000000000, type: 0}
--- !u!4 &59300837
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 59300833}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0.09, z: 0.18}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 1
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &112711653
GameObject:
m_ObjectHideFlags: 0
@ -294,7 +439,7 @@ Transform:
m_Children:
- {fileID: 370173446}
m_Father: {fileID: 0}
m_RootOrder: 1
m_RootOrder: 2
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &370173443
GameObject:
@ -546,7 +691,7 @@ Transform:
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 4
m_RootOrder: 5
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &913361947
GameObject:
@ -578,7 +723,7 @@ Transform:
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 2
m_RootOrder: 3
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!23 &913361949
MeshRenderer:
@ -704,7 +849,7 @@ Transform:
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 5
m_RootOrder: 6
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &1257753975
GameObject:
@ -783,7 +928,7 @@ Transform:
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 6
m_RootOrder: 7
m_LocalEulerAnglesHint: {x: 0, y: 90, z: 0}
--- !u!1 &1464358247
GameObject:
@ -862,5 +1007,5 @@ Transform:
m_LocalScale: {x: 0.1, y: 0.1, z: 0.1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 3
m_RootOrder: 4
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}

View file

@ -0,0 +1,129 @@
using System;
using UnityEngine;
using System.Collections.Generic;
public class ThePixelgon : MonoBehaviour
{
public List<Vector3> vertices;
public Mesh meshPoint;
public Material mat;
// just edit in the inspector (arrays and such)
void Start()
{
}
void Update()
{
Mesh mesh = new Mesh();
mesh.SetVertices(vertices);
// triangle
// clock wise
// 0 1 2, 1 2 3 ?
List<int> tris = new List<int>();//{ 0, 1, 2 };
int trav = 1;
int numSides = vertices.Count;
for (int i = 0; i < numSides - 2; i++)
{
tris.Add(0);
tris.Add(trav);
tris.Add(trav + 1);
trav++;
}
/*
*/
mesh.SetTriangles(tris, 0);
// pixelgon
// ngon
// vertices, tris, uvs
List<Vector2> uvs = new List<Vector2>();
// uvs
Vector3 cv = Vector3.zero;
for (int i = 0; i < vertices.Count; i++)
{
cv += vertices[i];
}
cv = cv / vertices.Count;
Vector3 farthest = cv;
for (int i = 0; i < vertices.Count; i++)
{
if (Vector3.Distance(cv, vertices[i]) > Vector3.Distance(cv, farthest))
{
farthest = vertices[i];
}
}
float radius = Vector3.Distance(cv, farthest);
Vector3 normal = Vector3.Cross(vertices[1] - vertices[0], vertices[vertices.Count - 1] - vertices[0]).normalized;
for (int i = 0; i < vertices.Count; i++)
{
Vector3 local = vertices[i] - cv;
local = Quaternion.Inverse(Quaternion.LookRotation(normal)) * local;
Vector3 uvPos = new Vector2(local.x + radius, local.y + radius);
// scaling
Debug.Log(uvPos);
uvs.Add(uvPos);
}
mesh.SetUVs(0, uvs);
Graphics.DrawMesh(meshPoint, cv, Quaternion.identity, mat, 0);
Graphics.DrawMesh(meshPoint, farthest, Quaternion.identity, mat, 0);
Graphics.DrawMesh(meshPoint, cv + normal, Quaternion.identity, mat, 0);
int width = 4, height = 4;
var texture = new Texture2D(width, height, TextureFormat.ARGB32, false);
bool black = true;
for (int j = 0; j < width; j++)
{
for (int k = 0; k < height; k++)
{
if (black)
texture.SetPixel(j, k, Color.black);
else
texture.SetPixel(j, k, Color.white);
black = !black;
}
black = !black;
}
/*
var texture = new Texture2D(2, 2, TextureFormat.ARGB32, false);
texture.SetPixel(0, 0, Color.black);
texture.SetPixel(1, 0, Color.white);
texture.SetPixel(1, 1, Color.black);
texture.SetPixel(0, 1, Color.white);
*/
texture.Apply();
texture.filterMode = FilterMode.Point;
mat.mainTexture = texture;
// pixels
// texture, scale, rotation, rendering options(point filtering, and cutout transparency)
// just reference a 2d texture for now
Graphics.DrawMesh(mesh,
Vector3.zero,
Quaternion.identity,
mat, 0
);
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 96d4e00eaa35fc8448455b6901a0c20b
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: