The pencil appears to bend owing to the refraction of light, or the change in direction of light when it passes through transparent materials. The light rays coming from the submerged part of the pencil are bent as they live the water.
Light rays are reflected and absorbed by opaque materials such as glass, air, water, oil and certain plastics, allow the light rays to pass through them. But in doing so they bend them to a greater or lesser degree.
Refraction occurs in nature. The stars not directly overhead are in different position from those they appear to be in, because the light rays from them are refracted by the earth’s atmosphere. Desert travelers sometimes see mirages which are caused by refraction through the atmosphere.