Posts

VLC stream to render texture

   In VLC, click Stream Select your media, click stream Add a HTTP, choose a port - say "8080", and give it a name, lets say "q" Make sure you activate "transcoding". Select Ogg as the main wrapper. In the video codec tab, select "Theora" (this is the ogg video codec I think). Save this preset, hit next and then finally Stream. I haven't figured out how to stream a playlist yet. Perhaps using VLC in command line mode?   In Unity, create a Videoplayer object. Set it to render to a Render Texture(and assign this render texture to a material on a quad or something). For the video player's source, set it to URL and enter something resembling the following - http://192.168.1.44:8080/q the 192.168.1.44 will be your machine's IP (run ipconfig in command prompt to find out what it actually is). The :8080 is to access the port you specified earlier, the "q" is what we named the stream. Now if you hit play , your object should have th...

GLSL plotting a line, 2 ways.

Firstly, to plot a "function"..  float plot(vec2 uv, float pct){     return step(pct-0.01,uv.y)-         step(pct+0.01,uv.y); } void main(void) {     vec2 uv = v_texcoord;     vec3 col=vec3(0);          float y = smoothstep(0.,1.,uv.x);     y=(sin(uv.x*6.28)+1)*0.5;     float pct=plot(uv,y);     col+=pct*vec3(0.0,1.0,0.0);          gl_FragColor = vec4(col,         1.0); }   In the main function, I've made a float value "y", which I intialise with a boring smoothstep function between the values 0 and 1. However we're not plotting that. I immediately overwrite y with what is essentially a sin(x) function. The numbers added and multiplied are just there to fit one cycle into the UV space of 0-1. (6.28 is a bad approximation of 2*PI - ie 360 degrees, +1 is to shift...

random number generation, noise and fbm, glsl

I should really change the name of this blog to Shader Shit.... anyway.. I'll get back to Unity specific crap one day. The following code is all for GLSL & will need adapting for use in a Unity fragment shader. I like to use Kodelife to test out my shader ideas. Look it up & give it some support if you like it! This post is about fake randomness, learnt from The Book of Shaders & The Art of Coding, on the website & youtube channel respectively. Within your main GLSL function, you might need to create a random value, often just a float value (remember you can make a vector from multiple floats). A great thing to feed such a random number generating function is your UV value. Here's an example- float random(vec2 uv){ return fract(sin(dot(uv,vec2(52.2957001,2355.957250024))*574.9829619)); } What we're doing here is getting the dot product of our UV coordinate, with an arbitrary vector that consists of large numbers with plenty of "complex" fractiona l...

sin vertex displacement shader

 The following vertex-surface shader moves vertices up and down based on some sine waves and the time variable. Combining lots of waves is a cool way to generate funky displacements. Things to note - we calculate a new normal in the vert function to prevent weird shading issues.  Shader "Dave/Unlit/waves" {     Properties     {         _MainTex ("Texture", 2D) = "white" {}         _Tint("Colour Tint",color)=(1,1,1,1)         _Freq("Frequency",Range(0,5))=3         _Speed("Speed",Range(0,100))=10         _Amp("Amplitude",Range(0,1))=0.5     }     SubShader     {        CGPROGRAM     #pragma surface surf Lambert vertex:vert        struct Input {         ...

slightly better outlines

  This approach to outlines is a bit more robust & adds outlines to areas within the shape's silhouette - eg details around say the nose and eyes, vs just the outline of the head. It utilises passes - first drawing the shape as normal with a standard struct input and void surf... then adding outlines on top using a vert-frag shader. This is quite cool to see both surface and vert frag shaders being mixed Things to note - we Cull the Front...We're essentially rendering the inside of the mesh as the outlines. I've found an explanation online about this shader, pasted below the code.. From the docs - UNITY_MATRIX_IT_MV Inverse transpose of model * view matrix.   I'm not entirely sure what is happening with this code - but I'm fairly sure we're taking the vertex normal and multiplying it by something, before getting it into screenspace.  Shader "Dave/Unlit/advancedOutline" {     Properties     {         _MainTex...

simple outline shader, using the vertex normal

Beneath is a method of drawing outlines around our mesh - or rather, we're expanding the mesh, giving it a flat colour and then drawing the mesh as normal on top of it. Note that we have two CGPROGRAM blocks, which get executed in order. This type of outline requires the transparent tag to work properly, and this could cause problems elsewhere.. Also it only outlines the extremities of a shape - or you could say, just the alpha edges . Next post will feature a more advanced shader    Shader "Dave/Unlit/simpleOutline" {     Properties     {         _MainTex("Texture",2D) = "white"{}         _OutlineColor("Outline Colour",color)=(0,0,0,1)         _Outline("Outline Width",Range(-0.1,0.1))=0.005     }     SubShader{         Tags{"Queue"="Transparent"}         ZWrite off ...

shader scroll UVs

This nice short & sweet shader scrolls the texture using time & some float values, in the x/y or u/v directions. All we're doing is manipulating the u and v values. Unity provides us with the time variable "_Time". According to the docs, the time is in Seconds & is scaled by the game's time multiplier. Beneath the shader are some docs time variables and info.    Shader "Dave/Unlit/UVSCROLL"{     Properties{         _MainTex("Texture",2D) = "white"{}         _ScrollX("Scroll X",Range(-5,5))=1         _ScrollY("Scroll Y",Range(-5,5))=1              }         SubShader{         CGPROGRAM         #pragma surface surf Lambert         sampler2D _MainTex;         float _ScrollX...