We may earn an affiliate commission when you visit our partners.
Benjamin Swee

Write Unity CG Shaders From Scratch (2D, 3D)

Have you ever wanted to write your own CG/HLSL shader code from scratch? Do you need help with understanding the intricate details of what happens on the back end? Learn to write shaders without the help of the material editor, and rather use the material editor as a prototyping tool?

In this Unity CG course, I will be teaching you the fundamentals of shader code so that you can write, create and develop unique looks that not only look amazing but run optimally too.

Read more

Write Unity CG Shaders From Scratch (2D, 3D)

Have you ever wanted to write your own CG/HLSL shader code from scratch? Do you need help with understanding the intricate details of what happens on the back end? Learn to write shaders without the help of the material editor, and rather use the material editor as a prototyping tool?

In this Unity CG course, I will be teaching you the fundamentals of shader code so that you can write, create and develop unique looks that not only look amazing but run optimally too.

These techniques can be used for personal game development, and I will also go over best practices that can be used on the job in larger game companies.

My name is Benjamin Swee, your course instructor. I have been working at various game companies and been a Lead Rendering Engineer on popular titles such as Marvel Contest of Champions, Fast and the Furious games, & a few Lineage titles.

My role was often solo, as such I would create complete in-house rendering systems.

In this course, I not only want to bring you creative thinking when it comes to rendering, but also real-world industry experience, and the best practices that are used in titles that are launched today.

Shaders are a black box to many, I aim to unbox it

Note that this course is a work in progress. I plan on continually updating it. Let me know in the course messages, what moreyou want to see.

Enroll now

What's inside

Syllabus

Introductions, setups, and basic structure of a shader

An introduction to myself, why rendering, and the initial setup that you need to begin this course.

Read more

This is how I've set up everything in Unity, remember, while I will give you all the course material, write your own shaders!

Welcome to the very first lesson of the shader course. I want to start right away by jumping into the basics of the shader. I will be going over exactly, line by line the core structure of a shader. It is unlike any other programming language, and strange to many programmers, so dive right into it.

We will cover the basics of 2d shading

Here we will be doing our very first texture sample! We will be learning UVs, what they mean, and how to use them to display our very first texture.

Once we got a handle on how UVs work, let's use them to sample textures. But more than that, we can also learn about how to transform and scale textures while we are at it.

Let's learn about transparency or ideally, blending. Blending is how all transparencies work across all games and even different game engines.  So let's learn about the blend formula.

2D Shaders - Animation and Texture Erosion

In this lesson, we will be learning about how UV animations work, how they slide, and how they animate

Two texture samples? Why would we ever do that? There are many reasons why and how a 2nd texture can support the first one.

Texture erosion. This is a cool-looking effect that helps make objects disappear. It's not the easiest to explain in the description, so just jump right in!

One of the really cool ways you can make erosion look even more awesome is by adding these searing colours.

2D Shaders - Animating Along UVs

Here we are going to animate a specific texture along with another texture that represents a UV. If that doesn't make much sense, check out the lesson, it will be much clearer.

Doing distortions and warps, concepts are similar to previous lessons, but what can we really achieve with these skills?

Creating UVs not from texture, but from math. That way, the UVs are perfect with no pixelation, and you can still do cool effects!

You don't want to have distortion everywhere, let's mask it and work with it

2D Shaders - Screen Space UV

Screen Space UVs are ideal for creating shines and effects that go across the entire screen, often used in the UI for UI effects

Creating textured shines. But these shines are driven by the texture itself, no supporting textures needed

2D Shaders - Rotation UVs

We will be rotating an image using a rotation matrix. This type of sampling combined with previous lessons can create all types of interesting effects!

3D Shaders - Basic Diffuse

In this lesson we will cover the basic's of setting up a 3D shader, involving lighting

Now let's also make sure we get ambient lighting, lighting from the light probes and global illumination.

Notice a small issue here, we should have lighting done in the fragment for that extra smooth look

3D Shaders - Spec

In this lesson we will do basic specular math, let's create that specular highlight!

3D Shaders - Normal mapping, how it works

The core concepts of normal mapping and how it works, from the math to the implementation

Reflections using reflection probes and how it works
Shader Misc

It's odd to have some features on and some off, creates weird bugs, let's solve them!

3D Shaders Effects

I'm sure you have seen this effect before, it will make sense once you go through it.

3d Shaders Normals and Water

A cheap way to get some version that looks like water, is normal blending

Let's start making our water flow, a basic way to do it, also a recap from some of the UV flow we did in past lessons.

Advanced flow, here is how we generate constant flowing water.

Want objects to look like they are underwater? Me too, let's make it happen!

Save this course

Save Write Unity CG Shaders From Scratch (2D, 3D) to your list so you can find it easily later:
Save

Activities

Be better prepared before your course. Deepen your understanding during and after it. Supplement your coursework and achieve mastery of the topics covered in Write Unity CG Shaders From Scratch (2D, 3D) with these activities:
Review Linear Algebra Fundamentals
Reinforce your understanding of linear algebra, which is essential for understanding transformations and coordinate systems used in shader programming.
Browse courses on Linear Algebra
Show steps
  • Review vector operations (addition, subtraction, dot product, cross product).
  • Study matrix operations (multiplication, transpose, inverse).
  • Understand how matrices represent transformations (translation, rotation, scaling).
The Book of Shaders
Supplement your learning with a comprehensive guide to shader programming concepts and techniques.
Show steps
  • Read the introductory chapters on shader basics and GLSL syntax.
  • Experiment with the code examples provided in the book.
  • Try to recreate some of the effects discussed in Unity using CG/HLSL.
Implement Basic Shaders
Solidify your understanding of shader code by implementing basic shaders from scratch.
Show steps
  • Create a simple diffuse shader with basic lighting calculations.
  • Implement a specular shader with adjustable highlight parameters.
  • Write a shader that applies a texture to a 3D object.
  • Experiment with different blending modes to achieve transparency effects.
Four other activities
Expand to see all activities and additional details
Show all seven activities
Real-Time Rendering
Expand your knowledge of real-time rendering techniques and shading algorithms.
Show steps
  • Read chapters related to shading models, lighting, and texturing.
  • Study the mathematical foundations of rendering algorithms.
  • Explore advanced rendering techniques such as shadow mapping and global illumination.
Shader Breakdown Blog Post
Deepen your understanding by explaining the inner workings of a complex shader.
Show steps
  • Choose a shader effect (e.g., water shader, fire shader, dissolve effect).
  • Analyze the shader code and identify the key components.
  • Write a blog post explaining the purpose of each section of the code.
  • Include diagrams and illustrations to clarify complex concepts.
Create a Custom Shader Library
Apply your knowledge by building a collection of reusable shader functions and effects.
Show steps
  • Identify common shader operations (e.g., lighting calculations, texture sampling, color manipulation).
  • Write functions that encapsulate these operations.
  • Organize the functions into a library with clear documentation.
  • Test the library by using it in different shader projects.
Contribute to a Shader Project
Enhance your skills by collaborating with other developers on a real-world shader project.
Show steps
  • Find an open-source shader project on platforms like GitHub.
  • Review the project's documentation and code.
  • Identify areas where you can contribute (e.g., bug fixes, new features, documentation).
  • Submit your contributions according to the project's guidelines.

Career center

Learners who complete Write Unity CG Shaders From Scratch (2D, 3D) will develop knowledge and skills that may be useful to these careers:
Shader Developer
A Shader Developer specializes in creating and optimizing shaders, which are programs that instruct the graphics card on how to render visuals. This course helps aspiring shader developers understand the fundamentals of shader code, enabling them to write, create, and develop unique and optimized visual looks. The course's focus on writing shaders from scratch, without relying on material editors, directly translates to the skills needed to craft custom visual effects and rendering techniques. Further, experience with 2D and 3D shaders in Unity is invaluable for this role. The instructor's real-world industry experience and best practices are especially helpful for excelling as a Shader Developer.
Rendering Engineer
A Rendering Engineer focuses on the technical aspects of generating images from a model, using various rendering techniques and algorithms. This course helps build a foundation in shader development, which is crucial for creating rendering systems. Learning to write CG or HLSL shader code from scratch allows a rendering engineer to optimize performance and achieve specific visual goals. The course's coverage of both 2D and 3D shaders provides a versatile skill set for tackling different rendering challenges. The instructor's experience as a Lead Rendering Engineer and creating in-house rendering systems makes this course particularly useful for aspiring rendering engineers.
Technical Artist
The Technical Artist role bridges the gap between artists and programmers, ensuring that art assets are implemented efficiently and effectively within a game or application. This course may be useful as it provides a deep understanding of shaders and how they interact with the rendering pipeline. Knowing how to write shaders from scratch allows a technical artist to create custom tools and effects, optimize art assets, and troubleshoot rendering issues. The course's coverage of 2D and 3D shaders in Unity is especially relevant, as Unity is a popular engine for game development. The lessons on UV animation, texture erosion, and screen space UVs will be highly relevant to the challenges a technical artist faces.
Game Developer
A Game Developer is involved in the creation of video games, encompassing various aspects from programming to visual effects. This course may be useful as it teaches shader development, a key skill for creating visually appealing and optimized games. The course's emphasis on writing CG or HLSL shader code from scratch allows a game developer to customize the look and feel of their games. The coverage of 2D and 3D shaders in Unity is directly applicable to game development workflows. The instructor's experience in the game industry makes this course an excellent choice for aspiring game developers.
Graphics Programmer
A Graphics Programmer specializes in the development of rendering techniques and algorithms, often working on the engine level. The course may be useful as it can teach the fundamentals of shader code, allowing graphics programmers to customize and optimize rendering pipelines. The course's focus on writing shaders from scratch and understanding the back-end details of rendering is crucial for this role. The knowledge gained from this course can be applied to various rendering tasks, such as implementing lighting models, creating special effects, and optimizing performance. The 3D shaders segment is especially relevant to a graphics programmer.
Visual Effects Artist
A Visual Effects Artist creates compelling visual effects for games, film, and other media. This course may be useful to become a visual effects artist as it provides a strong foundation in shader development. The course's focus on writing CG or HLSL shader code from scratch empowers a visual effects artist to create unique and eye-catching effects. The course's coverage of 2D and 3D shaders is valuable for creating a wide range of effects, from simple animations to complex simulations. The lessons on texture erosion, animating along UVs, and screen space UVs are particularly relevant to visual effects work.
Software Engineer
A Software Engineer designs, develops, and tests software applications. While it is more general of a career, this course may be useful if the software engineer works on projects that involve rendering or graphics, such as game engines, simulations, or visualization tools. The course's coverage of shader code and rendering techniques can be valuable for optimizing performance and creating custom visual effects. The knowledge of CG and HLSL shader code learned in this course can be applied to various software engineering tasks related to graphics development.
Simulation Developer
A Simulation Developer creates simulations for various purposes, such as training, research, or entertainment. This course may be useful for simulation developers working on graphically intensive simulations, as it provides a foundation in shader development and rendering techniques. The ability to write shaders from scratch can be valuable for optimizing performance and creating realistic visuals. The course's coverage of 2D and 3D shaders in Unity can be directly applied to simulation development projects. The segments on normal blending and underwater effects would be particularly helpful.
Augmented Reality Developer
An Augmented Reality Developer creates applications that overlay digital content onto the real world. This course may be useful for developers working on AR applications that require custom visual effects or optimized rendering techniques. The course's coverage of shader code and rendering techniques can be valuable for creating immersive and realistic AR experiences. The knowledge of how to write CG and HLSL shader code from scratch can be applied to various AR development tasks, such as creating custom lighting models or implementing special effects. The screen space UVs and rotation UVs segments are important for AR.
Virtual Reality Developer
A Virtual Reality Developer creates immersive experiences for virtual reality platforms. This course may be useful for developers working on VR applications that require custom visual effects or optimized rendering techniques. The course's coverage of shader code and rendering techniques can be valuable for creating engaging and realistic VR environments. The knowledge of how to write CG and HLSL shader code from scratch can be applied to various VR development tasks, such as creating custom lighting models or implementing special effects. The course's coverage of 3D shaders is especially relevant.
UI/UX Designer
A UI/UX Designer focuses on creating user interfaces and user experiences for software applications and websites. This course may be useful for UI/UX designers working on projects that involve visually rich interfaces or interactive elements. The course's coverage of shader code and rendering techniques can be valuable for creating custom UI effects and animations. The knowledge of how to write CG and HLSL shader code from scratch can be applied to various UI/UX design tasks, such as creating custom transitions or implementing visual feedback. The 2D shaders and screen space UV segments are valuable.
Animator
Animators create moving images using computer software. This course may be useful to animators who are working on projects that involve custom visual effects or stylized rendering. The course's coverage of shader code and rendering techniques may be valuable for creating unique and artistic animations. The knowledge of how to write CG and HLSL shader code from scratch may be applied to various animation tasks, such as creating custom character shaders or implementing special effects. The UV animations segment is particularly valuable for this.
Web Developer
A Web Developer creates websites and web applications. This course may be useful for web developers who are working on projects that involve interactive graphics or visualizations. The course's coverage of shader code and rendering techniques can be valuable for creating custom visual effects and animations within web applications. The knowledge of how to write CG and HLSL shader code from scratch can be applied to various web development tasks, such as creating custom charts or implementing interactive data visualizations. The 2D shaders content is more relevant to this role.
Data Visualization Specialist
A Data Visualization Specialist creates visual representations of data to communicate insights and trends. This course may be useful for data visualization specialists who are working on projects that require interactive or custom visualizations. The course's coverage of shader code and rendering techniques may be valuable for creating custom visual effects and animations within data visualizations. The knowledge of how to write CG and HLSL shader code from scratch may be applied to various data visualization tasks, such as creating custom charts or implementing interactive data explorations. The 2D shading segments are more relevant to this role.
Quality Assurance Tester
A Quality Assurance Tester tests software applications to ensure they meet quality standards. This course may be useful for quality assurance testers who are working on projects that involve graphics or rendering. The course's coverage of shader code and rendering techniques can be valuable for identifying and reporting visual bugs or performance issues. The knowledge of how shaders work can help testers understand potential problems and communicate them effectively to developers. While this role is not directly involved in shader development, understanding the fundamentals can enhance a tester's ability to identify and report issues related to rendering and visual quality.

Reading list

We've selected two books that we think will supplement your learning. Use these to develop background knowledge, enrich your coursework, and gain a deeper understanding of the topics covered in Write Unity CG Shaders From Scratch (2D, 3D).
Provides a gentle introduction to shader programming concepts. It covers the fundamentals of GLSL, which is similar to CG/HLSL, and explores various visual effects. It's a great resource for understanding the underlying principles of shader development and can be used as a reference throughout the course. The book is available online for free, making it easily accessible.
Comprehensive resource on real-time rendering techniques. While it covers a broad range of topics, it provides in-depth explanations of shading algorithms and rendering pipelines. It's a valuable reference for understanding the theoretical foundations of shader programming and exploring advanced rendering techniques. This book is commonly used as a textbook in computer graphics courses.

Share

Help others find this course page by sharing it with your friends and followers:

Similar courses

Similar courses are unavailable at this time. Please try again later.
Our mission

OpenCourser helps millions of learners each year. People visit us to learn workspace skills, ace their exams, and nurture their curiosity.

Our extensive catalog contains over 50,000 courses and twice as many books. Browse by search, by topic, or even by career interests. We'll match you to the right resources quickly.

Find this site helpful? Tell a friend about us.

Affiliate disclosure

We're supported by our community of learners. When you purchase or subscribe to courses and programs or purchase books, we may earn a commission from our partners.

Your purchases help us maintain our catalog and keep our servers humming without ads.

Thank you for supporting OpenCourser.

© 2016 - 2025 OpenCourser