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"
}

 

Leave a Reply