zaterdag 5 januari 2019

Disable case sensitivity for WSL (Windows Subsystem for Linux)

I ren in to an issue opening a Unity3D project while setting up my windows machine for game development.

The project is on case sensitive file system.Case sensitive files systems are not supported at the moment.Please move the project folder to a case insensitive file system.

This Unity project was cloned with git cli on WSL, this might have caused some issues with files that have case sensitive names since Ubuntu is case sensitive by default and Windows 10 is not.

This behavior can be altered by editing the /etc/wsl.conf file to include:

[automount]
    options = "case=off"

Make sure to un-mount and remount or restart the pc for the changes to take effect.

Store git credentials in WSL (Windows Subsystem for Linux)

This is a short guide for using wincred from Git for Windows in WSL (Windows Subsystem for Linux). All you have to do is add a view lines to you global .gitconfig


  1. Make sure you have installed Git for Windows
  2. Add the following to you ~/.gitconfig file 
    [credential]
        helper = /mnt/c/Program\\ Files/Git/mingw64/libexec/git-core/git-credential-wincred.exe
    
Thats it, wincred will safely store you credentials in the Windows Credential Manager te next time git prompt you for authentication. From that point on wincred will take care of authentication.

vrijdag 2 februari 2018

A* Pathfinding

If never used pathfinding in any of my projects and I felt it was time to see what pathfinding is all about so I can use this for future projects.

I started with looking through through the different pathfinding algorithms out there, this website visualizes several options for pathfinding. And helps getting a better understanding of how different solutions function.

I have chosen to implement the A* algorithm a variation on the Dijkstra algorithm. I have chosen this algorithm because it the best for finding the shortest path fast in a static environment.

There are a ton of good articles and videos that explain how A* works and even step by step guides how to implement it. So I'm not going to do that as well, but I wil recommend a few I found useful.

Sebastian Lague has a really good video series that gives a step by step example of A* pathfinding including some optimization and things like weights with all the the project material available on GitHub.  You can find the videos here.

Mike Clift has a article that also gives a step by step explanation how A* works with code snippets and good visualization of what is going one. You can find his post here.

Jasper Flick has a cool series on making a terrain with hexagons tiles. Part 16 is a cool tutorial on how to navigate a grid of hexagons with A*. You can find this post here.

Instead i'll show of my implementation that visualizes how A* works.

Use Q to set a start W to set a finish and E to set walls. When you're ready to execute A* press Space.
You can play around with a larger version here

After playing around with A* I gained a intrest in trying out D*lite, which uses the same principles as D* with is a improvement on A*. The research paper is a great resource witch kan be found here. But can be a bit technical. My best bet for quickly implementing D*lite was to look at a java implementation of D*lite. This helpt me a lot in understanding how D*lite functions. Regretfully I couldn't fint more time to finish this implementation and probably continue working on it in the future.

Clift M. (2014) A Simple A* Path-Finding Example in C# [online] Available at: http://blog.two-cats.com/2014/06/a-star-example/

Koenig S, Likhachev M. (2002) D*Lite [online] Available at: http://idm-lab.org/bib/abstracts/papers/aaai02b.pdf


donderdag 7 april 2016

Volumetric light cones

I want to have a volumetric light beam on my spotlights so you see an actual light beam in game. This is a very important element for a project I’m working on for school. The atmosphere of the game I’m developing is about the dark and the spotlights.

Unity does not have built in volumetric light effects except for Sun Shafts. The Sun Shaft effect looks good but only supports 1 light source.

The alternatives I found are:

Volumetric Light Beam Kit

This is a $40 Unity package that does create the desired effect with a cone mesh and a shader. However this package has been deprecated and cannot be purchased anymore
https://www.assetstore.unity3d.com/en/#!/content/3559 


Sunshine!

This must be the best looking lighting effect that you can buy at the asset store, however it comes with a price tag of $95. This is way too expensive for a student project. https://www.assetstore.unity3d.com/en/#!/content/10153

Light shafeds

This was the best solution that I could find. It’s a public domain package that creates the exact effect I was looking for.
https://github.com/robertcupisz/LightShafts

The only problem is that this effect stacks with multiple beams so it still is not the volumetric effect that I’m looking for.

Light shafeds effect stacking.

Unity announced a volumetric light effect that will release in June 2016 with the Unity 5.4 release. I think I will wait for that since it’s a really complex effect and I don't feel experienced enough to build my own volumetric light effect.

Interacting with games through a website

For a small art project I was asked to create a website that is able to interact with a game. The assignment was to develop a web form that users can fill to submit a message to the game. The information that has been sent to the game becomes part of the game.

The game, is a Tamagotchi, fed by people sending food through a website. You also can  add a message when sending the food and the Tamagotchi will react to it.

I’ve created a simple PHP based service that adds “food” to a queue in a database and another service to request the content of this queue. This service returns a Json object on request that is de-serialized in Unity by using LitJson. I was not able to use the build in Json serializer of Unity, it didn’t accept an array of objects for some reason.


GetFood.cs


using UnityEngine;
using System.Collections;
using LitJson;

public class LucyGetsFood : MonoBehaviour {
    private string _URL = "url to a website/service.php";

 public void GetFood()
 {
  StartCoroutine(GetFood());
 }

 IEnumerator GetFood() {
  WWW www = new WWW(_URL);
  yield return www;
        string jsonString = System.Text.ASCIIEncoding.ASCII.GetString(www.bytes).TrimEnd('\0');
        JsonData inputList = JsonMapper.ToObject(jsonString);

        if(inputList["inputList"].Count > 0)
        {
            print(inputList["inputList"][0]["name"].ToString());
            for(int i = 0; inputList["inputList"].Count > i; i++)
            {
                string name = inputList["inputList"][i]["name"].ToString();
                string color = inputList["inputList"][i]["color"].ToString();
                string message = inputList["inputList"][i]["message"].ToString();

                SpwanFood(name, color, message);
            }
        }
 }
}

I have worked with Json before so I thought that is would be done in no time. But it turned out to be different. I did not expect the difficulties I encountered with the build in Unity Json serializer. It was interesting to work with Json for Unity and I think it is valuable knowledge for the future. I would like to learn more about web-database based user information for things like users save games and high scores.
This project was a good experience to be better prepared to properly perform other tasks related to games interacting with web databases.

zondag 13 maart 2016

Directional Color Shader


I wanted to replicate an effect that a friend made with directional light in Unity. The goal was to make a shader that colors an object based on its normal direction in world space. 

DirectionalColor.shader

Shader "Custom/DirectionalColor" {
    Properties {
        _ColorX ("ColorX", Color) = (1,0,0,1)
        _ColorY ("ColorY", Color) = (0,1,0,1)
        _ColorZ ("ColorZ", Color) = (0,0,1,1)
    }
    SubShader {
        Tags {
            "RenderType"="Opaque"
        }
        Pass {
            Name "FORWARD"
            Tags {
                "LightMode"="ForwardBase"
            }

            CGPROGRAM
            #pragma vertex vert
            #pragma fragment frag
            #define UNITY_PASS_FORWARDBASE
            #include "UnityCG.cginc"
            #pragma multi_compile_fwdbase_fullshadows
            #pragma exclude_renderers gles3 metal d3d11_9x xbox360 xboxone ps3 ps4 psp2
            #pragma target 3.0

            uniform float4 _ColorX;
            uniform float4 _ColorY;
            uniform float4 _ColorZ;

            struct VertexInput {
                float4 vertex : POSITION;
                float3 normal : NORMAL;
            };

            struct VertexOutput {
                float4 pos : SV_POSITION;
                float3 normalDir : TEXCOORD0;
            };

            VertexOutput vert (VertexInput v) {
                VertexOutput o = (VertexOutput)0;
                o.normalDir = UnityObjectToWorldNormal(v.normal);
                o.pos = mul(UNITY_MATRIX_MVP, v.vertex );
                return o;
            }

            float4 frag(VertexOutput i) : COLOR {
                i.normalDir = normalize(i.normalDir);
                float3 normalDirection = i.normalDir;
                float3 squared = (i.normalDir*i.normalDir);
                float3 finalColor = (squared.r*_ColorX.rgb + squared.g*_ColorY.rgb + squared.b*_ColorZ.rgb);
                return fixed4(finalColor,1);
            }
            ENDCG
        }
    }
    FallBack "Diffuse"
}