week 9 homework

For this assignment, I 3D modeled an animated block model/block puzzle. The animation breaks apart the blocks in slow motion and then brings them back together. I wanted to try a different material or shader for each block. I downloaded 2 textured materials (the first, yellow metallic shader, the second, concrete shader). For the third material, I made a 2D textured Surface shader. I used one of the shaders I made for my midterm which animates the 2D texture based on time, sin, and cosine. The original frag shader does not warp the texture so it was cool to see how the texture image gets warped in Unity’s surface shader material. I also animated the color of the material based on time. I also added a skybox hdri render texture to the skybox and used a reflection probe and point lights.

 

screen-shot-2021-03-27-at-2-04-59-am

screen-shot-2021-03-27-at-10-02-21-pm

screen-shot-2021-03-27-at-10-39-09-pm

CGPROGRAM
// Physically based Standard lighting model, and enable shadows on all light types
#pragma surface surf Standard fullforwardshadows

// Use shader model 3.0 target, to get nicer looking lighting
#pragma target 3.0

sampler2D _MainTex;

struct Input
{
float2 uv_MainTex;
};

half _Glossiness;
half _Metallic;
fixed4 _Color;

// Add instancing support for this shader. You need to check 'Enable Instancing' on materials that use the shader.
// See https://docs.unity3d.com/Manual/GPUInstancing.html for more information about instancing.
// #pragma instancing_options assumeuniformscaling
UNITY_INSTANCING_BUFFER_START(Props)
// put more per-instance properties here
UNITY_INSTANCING_BUFFER_END(Props)

void surf (Input IN, inout SurfaceOutputStandard o)
{

//COLOUR CHANGE OVERTIME

_Color.r = cos( _Time / 0.03);
_Color.g = cos( _Time / 0.09);
_Color.b = cos( _Time / 0.4);
_Color.b = cos( _Time / 0.03);

//TEXTURE IMPORTED

float2 uv0 = IN.uv_MainTex;

//PART FROM FRAG SHADER CONVERTED TO HLSL - TEXTURE DISTORT

uv0.x += cos( uv0.x/ _Time * 0.6) + sin(_Time + uv0.x * 0.5)*0.1 - cos(_Time/0.03) * sin(_Time/ 0.30);
uv0.y += cos( uv0.x/ _Time * 0.6) + sin(_Time.y + uv0.x * 0.5)*0.1 - cos(_Time.y/0.3) * sin(_Time.x/ 0.3);

// Albedo comes from a texture tinted by color

fixed4 c = tex2D (_MainTex,uv0.xy) * _Color;

o.Albedo = c.rgb;
// Metallic and smoothness come from slider variables
o.Metallic = _Metallic;
o.Smoothness = _Glossiness;
o.Alpha = c.a;
}
ENDCG
}
FallBack "Diffuse"
}

 

Week 3 shaders

screen-shot-2021-02-11-at-6-22-59-pm screen-shot-2021-02-11-at-6-57-31-pm

I made a simple grid of squares that change colour randomly. I imported the shader into P5. The shader also has a layer of a different coloured grid that overlays on top occasionally.

code:

#ifdef GL_ES
precision mediump float;
#endif

uniform vec2 u_resolution;
uniform vec2 u_mouse;
uniform float u_time;

float stipes = 24.072;

float random (vec2 st) {
return fract(sin(dot(st.xy,
vec2(-0.062,stipes + u_time * 0.064)))*
4.409);
}

void main() {
vec2 st = gl_FragCoord.xy/u_resolution.xy;

st *= 9.280; // Scale the coordinate system
vec2 ipos = floor(st*0.396 + abs(sin(u_time *0.396))); // get the integer coords
vec2 fpos = fract(st *-0.068 + abs(cos(u_time *-0.332))); // get the fractional coords
// Assign a random value based on the integer coord
vec3 color = vec3(random( ipos ), fpos);

gl_FragColor = vec4(color,1.0);
}