Posts

Showing posts from October, 2020

light mapping notes

 A few things that weren't completely obvious at first/ good to know You can make an object invisible, but still cast a shadow - click on the shadows drop down, there is a "shadows only" option To enable an object for light map baking, set it to Static by ticking the box in the Inspector. Similarly, to make a light part of the bake, set its mode to "Baked" or "Mixed" (Inspector) Occlusion can be tweaked and baked - it's in the light map settings - should save you from adding a SSAO post processing layer! An object can contribute to baked global illumination, you need to tick the box that allows this (in the mesh renderer) In the light map settings, the Multiple Importance Sampling check box can speed up a bake, but lead to noisy results. Lightmaps can actually have different UVs to the standard texture. Unity can autogenerate these  if you choose so, in the FBX import settings. If you wish to make these yourself, assign them to the UV1 set. Standar

Legacy / Built-in Renderer Post Processing, Tilt Brush & Unity

 The Tiltbrush export from the Oculus Quest comes as a .glb file. This can be opened in Blender & also Houdini - but they won't really look like much without the Unity shaders. So... find the latest Unity Tiltbrush package online somewhere, install it in the latest Unity - at time of writing, I used Unity 2020.1.2f1 with Tiltbrush Unity Package 23.0.1. At some point Unity or Google will probably stop supporting this! Once you've installed the package, you should be able to import your glb file & it will display correctly in Unity! Hooray! What's that? Some of it is displaying as bright pink? Oh... did you make a URP or HDRP project? Bad news. Take that fancy stuff outta here. Tiltbrush shaders only work with the legacy/ built in renderer.  What's that? You want to make it nice and post processed though? Oh ok.. You can still use the old post processing layer system. Here's how - In your Project window/Assets area, Right Click and make a new Post Processing P

setting VFX graph properties using C#

How to set values for your custom properties in VFX Graph. Yeah, there are binders, but I find they expect a rather precise  way of working.. Making your own scripts forces Unity to do what you actually want haha. In my VFX graph, I have a VECTOR 3 value named "realSpawnPos" which I'm using as the spawn position for some particles. It's important to note that "position", whilst it is a Vector3.. doesn't like receiving Vector 3 values. So make sure you set it up as a Vector 3 in the VFX graph. Further to this - Make sure in the VFX Graph, your position node is set to WORLD, if you need to set/get/whatever the world position and not local... your objects are probably nested in a million groups/transforms..   using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.VFX; public class bindPosition : MonoBehaviour {     public GameObject target_thing;     public VisualEffect visualEffect;     void Update()     {         

setting MSAA to 4x

 The Unity/Oculus docs suggest you set the MSAA to 4x for optimal performance/quality.  However, in the camera options the MSAA is always locked to "use pipeline settings". What you need to do is look for the actual Pipeline object in your assets. So do a search for "universal" or "HDRP" to locate the object and voila - you can now set the MSAA!

vfx graph particles disappear when camera moves

 So my particles kept vanishing when I moved or rotated the camera. It turns out the bounds of my particles weren't being set - despite having set a "set position" AA box beneath. Make sure you set the bounds as well!! Plugging in the same AA Box should do the trick. Think of it like setting the Flip fluid domain in Houdini, only the fluid will vanish if you step out of it haha.

Setting up Unity for Oculus Quest development

Image
 https://www.bradleynewman.io/consolidated-setup-for-quest-dev   This was a super pain in the ass, as the Unity docs and Oculus docs are trash. But the above blog solves it all. I'm just pasting the entire blog post below in case his site ever goes down. The Oculus documentation for setting up for Quest development in Unity is scattered across several pages. This post is my consolidated list of settings to get you up and running quickly. I'm using   Unity 2019.1.0f2 , which   Oculus recommends. Older recommended versions include 2018.4 LTS, or 2017.4 LTS. ​ Quest Device Setup Setup Organization First off you have to setup a developer organization: Make sure you have an Oculus account and are logged into it on the Oculus website and on your Quest. Go to: https://dashboard.oculus.com/organizations/create/ Fill in the appropriate information. ​ Developer Mode Next, you need to put your Quest in Developer Mode: Download and start the Oculus

apply force to objects within an area and other stuff

Bit of a messy example, but it demonstrates a few things in a simple way. 1 - finding the gameobjects that a collider is connected to 2 - finding the rigidbody component of said gameobject 3 - applying a force to rigidbody 4 - optional destroying gameobjects 5 - Oh and the "Physics Overlap Sphere" function. It returns all the colliders within a given spherical volume.   public void physicsSphereMake(Vector3 coord, float radius, float multiply)     {       //get an array of colliders within an overlap sphere that we provide position and radius for            Collider[] hitColliders = Physics.OverlapSphere(coord, radius);         //loop through array         foreach(var hitCollider in hitColliders)         {               //find out the game object             GameObject temp = hitCollider.gameObject;               //find the rigidbody (more on this in a bit)             Rigidbody rb_temp = temp.GetComponent<Rigidbody>();               //get position of the game object  

casting rays, layer masks, filter objects

 An edit if you will.. When casting rays with masks/filters, remember the ray will keep going until it hits something...so if you have some junk under your floor geo, it's likely the ray will hit it. So be sure to have a function that checks the hit object somewhere..   Some code -                  LayerMask mask = LayerMask.GetMask("spawnObject");                          Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); //cast ray             RaycastHit hit; //create hit event variable             if (Physics.Raycast(ray, out hit,50f,mask)) //if ray hits object             {                 worldPos = hit.point;  //position of ray hit                 Vector3 adjust_y = new Vector3(worldPos.x, worldPos.y+2, worldPos.z);                 Spawn(adjust_y, hit.normal);               }     LayerMask mask - here we create  a layer mask, and specify the layer we've created and called "spawnObject".  Ray ray - we're making a ray called ray and we'

GetComponent usage

 public class startingForce : MonoBehaviour {     public float yval;     Rigidbody thisRigidBody;     // Start is called before the first frame update     void Start()     {         thisRigidBody = GetComponent<Rigidbody>();         thisRigidBody.AddRelativeForce(0,yval,0);     }     // Update is called once per frame     void Update()     {              } } Like this! ^ here we use GetComponent to look for the Rigidbody component attached to the same GameObject Note the use of < to surround > the component type and how it is followed by the ( ) <-something I keep forgetting. Also note how we make a variable of the same component type equal to it, so we can then refer to it.

repeating code every __ seconds

 lets say you want to spawn a gameobject every 3 seconds. First you'll need a Spawner object. It could be anything - lets use an Empty. Place it wherever you want. Make a new C# script and apply it to the Empty. Here's the code, with some comments using System.Collections; using System.Collections.Generic; using UnityEngine; public class spawner : MonoBehaviour {     public GameObject thing; //the object you want to spawn. Set it in the Inspector         void Start()     {         InvokeRepeating("makeThing", 3.0f, 1.0f); //calls makeThing function after 3 secs, every 1 sec     }     void makeThing() //the actual spawn script     {                  Instantiate(thing, transform.position, Random.rotation); //uses object "thing", at your Empty's position, with a random rotation//     } } https://docs.unity3d.com/ScriptReference/MonoBehaviour.InvokeRepeating.html

"on click" basics

From the Unity pages, a simple way to detect your mouse clicks - using UnityEngine; using System.Collections; // Detects clicks from the mouse and prints a message // depending on the click detected. public class ExampleClass : MonoBehaviour { void Update () { if ( Input.GetMouseButtonDown (0)) Debug.Log ("Pressed primary button."); if ( Input.GetMouseButtonDown (1)) Debug.Log ("Pressed secondary button."); if ( Input.GetMouseButtonDown (2)) Debug.Log ("Pressed middle click."); } }    And from this site - void Update ( ) { if ( Input . GetMouseButtonDown ( 0 ) )        {      Ray ray = Camera . main . ScreenPointToRay ( Input . mousePosition ) ;      RaycastHit hit ;      if ( Physics . Raycast ( ray , out hit ) )             {           Destroy ( hit . transform . gameObject ) ;           }      } }     You'll want to put the 2nd script in th

Messing with VFX Graph time scale/playback rate

Unity Forum user Olmi did a nice code snippet for this https://forum.unity.com/threads/what-is-the-right-way-to-pause-particles.837889/ using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.VFX; public class vfxgraph_playrate : MonoBehaviour {     [SerializeField] float timeScale = 1.0f;     [SerializeField] VisualEffect VFX;     void Start()     {         VFX = GetComponent<VisualEffect>();     }     void Update()     {         VFX.playRate = timeScale;     } } NEAT AS HECK. WHY ISN'T THIS A NODE IN VFX GRAPH?

Procedural line in shader

Image
 A quick shader graph tidbit, lifted from https://www.codinblack.com/the-big-shader-graph-tutorial-second-part/ How to put a tweakable line on an object. Naturally this doesn't quite work with the VFX Graph.. As the position analyses per-object - ie, the whole VFX Graph, instead of per particle.