Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Unity 2018 Shaders and Effects Cookbook
Unity 2018 Shaders and Effects Cookbook

Unity 2018 Shaders and Effects Cookbook: Transform your game into a visually stunning masterpiece with over 70 recipes , Third Edition

Arrow left icon
Profile Icon John P. Doran Profile Icon Alan Zucconi
Arrow right icon
€18.99 per month
Full star icon Full star icon Half star icon Empty star icon Empty star icon 2.9 (8 Ratings)
Paperback Jun 2018 392 pages 3rd Edition
eBook
€22.99 €32.99
Paperback
€41.99
Subscription
Free Trial
Renews at €18.99p/m
Arrow left icon
Profile Icon John P. Doran Profile Icon Alan Zucconi
Arrow right icon
€18.99 per month
Full star icon Full star icon Half star icon Empty star icon Empty star icon 2.9 (8 Ratings)
Paperback Jun 2018 392 pages 3rd Edition
eBook
€22.99 €32.99
Paperback
€41.99
Subscription
Free Trial
Renews at €18.99p/m
eBook
€22.99 €32.99
Paperback
€41.99
Subscription
Free Trial
Renews at €18.99p/m

What do you get with a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing
Table of content icon View table of contents Preview book icon Preview Book

Unity 2018 Shaders and Effects Cookbook

Creating Your First Shader

In this chapter, you will learn about the following recipes:

  • Creating a basic Standard Shader
  • Adding properties to a shader
  • Using properties in a Surface Shader

Introduction

This chapter will cover some of the more common diffuse techniques found in today's game development shading pipelines. Let's imagine a cube that has been painted white uniformly in a 3D environment with a directional light. Even if the color used is the same on each face, they will all have different shades of white on them depending on the direction that the light is coming from and the angle that we are looking at it from. This extra level of realism is achieved in 3D graphics through the use of shaders, special programs that are mostly used to simulate how light works. A wooden cube and a metal one may share the same 3D model, but what makes them look different is the shader that they use.

This first chapter will introduce you to shader coding in Unity. If you have little to no previous experience with shaders, this chapter is what you need in order...

Creating a basic Standard Shader

In Unity, when we create a game object, we then attach additional functionality through the use of components. In fact, every game object is required to have a Transform component; there are a number of components included in Unity already, and we create components of our own when we write scripts that extend from MonoBehaviour.

All the objects that are part of a game contain a number of components that affect their look and behavior. While scripts determine how objects should behave, renderers decide how they should appear on the screen. Unity comes with several renderers, depending on the type of object that we are trying to visualize; every 3D model typically has a MeshRenderer component attached to it. An object should have only one renderer, but the renderer itself can contain several materials. Each material is a wrapper for a single shader...

Adding properties to a shader

Properties of a shader are very important for the shader pipeline as they are the method that you use to let the artist or user of the shader assign textures and tweak your shader values. Properties allow you to expose GUI elements in a material's Inspector tab without you having to use a separate editor, which provides visual ways to tweak a shader. With your shader opened in your IDE of choice, look at the block of lines two through seven. This is called the Properties block of the script. Currently, it will have one texture property in it called _MainTex.

If you look at your material that has this shader applied to it, you will notice that there is one texture GUI element in the Inspector tab. These lines of code in our shader are creating this GUI element for us. Again, Unity has made this process very efficient in terms of coding and the...

Using properties in a Surface Shader

Now that we have created some properties, let's actually hook them up to the shader so that we can use them as tweaks to our shader and make the material process much more interactive. We can use the Properties values from the material's Inspector tab because we have attached a variable name to the property itself, but in the shader code, you have to set up a couple of things before you can start calling the value by its variable name.

How to do it...

The following steps show you how to use the properties in a Surface Shader:

  1. Continuing from the previous example, let's create another shader with the name ParameterExample. Just like before, remove the _MainTex property in...
Left arrow icon Right arrow icon

Key benefits

  • • Learn the secrets of creating AAA quality shaders without writing long algorithms
  • • Master shader programming through easy-to-follow examples
  • • Create stunning visual effects that can be used in 3D games

Description

Since their introduction to Unity, shaders have been seen as notoriously difficult to understand and implement in games. Complex mathematics has always stood in the way of creating your own shaders and attaining the level of realism you crave. Unity 2018 Shaders and Effects Cookbook changes that by giving you a recipe-based guide to creating shaders using Unity. It will show you everything you need to know about vectors, how lighting is constructed with them, and how textures are used to create complex effects without the heavy math. This book starts by teaching you how to use shaders without writing code with the post-processing stack. Then, you’ll learn how to write shaders from scratch, build up essential lighting, and finish by creating stunning screen effects just like those in high-quality 3D and mobile games. You'll discover techniques, such as normal mapping, image-based lighting, and animating your models inside a shader. We'll explore how to use physically based rendering to treat light the way it behaves in the real world. At the end, we’ll even look at Unity 2018’s new Shader Graph system. With this book, what seems like a dark art today will be second nature by tomorrow.

Who is this book for?

Unity Shaders and Effects Cookbook is for developers who want to create their first shaders in Unity 2018 or wish to take their game to a whole new level by adding professional post-processing effects. A solid understanding of Unity is required to get the most from this book.

What you will learn

  • • Understand physically based rendering to fit the aesthetic of your game
  • • Write shaders from scratch in ShaderLab and HLSL/Cg
  • • Combine shader programming with interactive scripts to add life to your materials
  • • Design efficient shaders for mobile platforms without sacrificing their realism
  • • Use state-of-the-art techniques, such as volumetric explosions and fur shading
  • • Master the math and algorithms behind the most used lighting models
  • • Understand how shader models have evolved and how you can create your own

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Jun 29, 2018
Length: 392 pages
Edition : 3rd
Language : English
ISBN-13 : 9781788396233
Languages :
Concepts :
Tools :

What do you get with a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing

Product Details

Publication date : Jun 29, 2018
Length: 392 pages
Edition : 3rd
Language : English
ISBN-13 : 9781788396233
Languages :
Concepts :
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
€18.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
€189.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts
€264.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total 124.97
Unity 2018 Shaders and Effects Cookbook
€41.99
Unity 2018 Artificial Intelligence Cookbook
€36.99
Unity 2018 Cookbook
€45.99
Total 124.97 Stars icon

Table of Contents

13 Chapters
Post Processing Stack Chevron down icon Chevron up icon
Creating Your First Shader Chevron down icon Chevron up icon
Surface Shaders and Texture Mapping Chevron down icon Chevron up icon
Understanding Lighting Models Chevron down icon Chevron up icon
Physically-Based Rendering Chevron down icon Chevron up icon
Vertex Functions Chevron down icon Chevron up icon
Fragment Shaders and Grab Passes Chevron down icon Chevron up icon
Mobile Shader Adjustment Chevron down icon Chevron up icon
Screen Effects with Unity Render Textures Chevron down icon Chevron up icon
Gameplay and Screen Effects Chevron down icon Chevron up icon
Advanced Shading Techniques Chevron down icon Chevron up icon
Shader Graph Chevron down icon Chevron up icon
Other Books You May Enjoy Chevron down icon Chevron up icon

Customer reviews

Top Reviews
Rating distribution
Full star icon Full star icon Half star icon Empty star icon Empty star icon 2.9
(8 Ratings)
5 star 25%
4 star 12.5%
3 star 25%
2 star 0%
1 star 37.5%
Filter icon Filter
Top Reviews

Filter reviews by




thomas Feb 08, 2019
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Great book, for those of you looking to learn some shader programming and are like me where you dont know where to start then this book is for you, i like how it takes you through set up and also provides demo materials which you can use as a guide or if you get stuck
Amazon Verified review Amazon
Adr Kindle Oct 17, 2018
Full star icon Full star icon Full star icon Full star icon Full star icon 5
I'm a professional web developer who's been into game programming for some time. Most Unity books cover 3D objects manipulation, game dynamics, etc. but they rarely touch on shaders' internals. Things like screen effects, different lighting types, liquids, fur, explosions - all seem like some kind of magic, written in a language with weird syntax and semantics that only few people understand.I've been trying to follow YouTube tutorials on writing shaders, reading blogs and articles, but always felt like I only understand a tiny piece of the puzzle. I was missing a holistic view and I couldn't find a good resource which would cover everything.This book is exactly what I've been looking for. It moves fast - reader is treated as a professional who doesn't need hundreds of examples for one topic - but it's also thorough. When you use a variable type, it tells you what other types there are and where to read about them more. It covers every topic I wanted to learn about plus some more. After reading the first few chapters I was already writing my own shaders, even coming up myself with ideas that were actually covered later in the book.The only thing that some readers may not like at first is the format of chapters. They follow this scenario: setting up a project, writing all of the code, running it, and then the explanation of what's going on. I'm personally more used to story-type tutorials where concepts are eased into. But very quickly I realised the potential of the approach this book takes. Every chapter is an entity of its own, allowing you to quickly come back to a specific topic when you need it, and gives you everything you need to see the concept in action.If you're a non-beginner software developer who wants to holistically understand shaders and write your own, this book is definitely worth reading.
Amazon Verified review Amazon
かるばどす Oct 29, 2018
Full star icon Full star icon Full star icon Full star icon Empty star icon 4
例を示して動作を示す説明スタイルは、エントリーとしてとても解り易いです。残な点として、updateが最新に対応しきれていない点があり、ちょっと戸惑う点がある事です。まだunityで開発中の機能を説明しているので、タイムリーな更新が期待されます。
Amazon Verified review Amazon
M. HertZ Mar 12, 2019
Full star icon Full star icon Full star icon Empty star icon Empty star icon 3
It’s a decent primer if you’ve never worked with shader code before. The author does a decent job explaining the fundamentals of writing shader code. However for the price of the book and its subject, its pretty dissapointing that the images are low quality and in black and white. Furthermore getting the source code to follow along with the recipes is a pain. The publishers website provides confusing and inaccurate instructions. If you’re tired of reading blog posts and online tutorials then this book might be worth it for you.
Amazon Verified review Amazon
Amazon カスタマー Dec 22, 2019
Full star icon Full star icon Full star icon Empty star icon Empty star icon 3
シェーダーやポストプロセスの良い本だとは思うのですが、グラフィックスを扱う本なのにまさかのモノクロです。カラーページは一切ありません。それと当然ながら英語のみなので、注意してください。
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

What is included in a Packt subscription? Chevron down icon Chevron up icon

A subscription provides you with full access to view all Packt and licnesed content online, this includes exclusive access to Early Access titles. Depending on the tier chosen you can also earn credits and discounts to use for owning content

How can I cancel my subscription? Chevron down icon Chevron up icon

To cancel your subscription with us simply go to the account page - found in the top right of the page or at https://subscription.packtpub.com/my-account/subscription - From here you will see the ‘cancel subscription’ button in the grey box with your subscription information in.

What are credits? Chevron down icon Chevron up icon

Credits can be earned from reading 40 section of any title within the payment cycle - a month starting from the day of subscription payment. You also earn a Credit every month if you subscribe to our annual or 18 month plans. Credits can be used to buy books DRM free, the same way that you would pay for a book. Your credits can be found in the subscription homepage - subscription.packtpub.com - clicking on ‘the my’ library dropdown and selecting ‘credits’.

What happens if an Early Access Course is cancelled? Chevron down icon Chevron up icon

Projects are rarely cancelled, but sometimes it's unavoidable. If an Early Access course is cancelled or excessively delayed, you can exchange your purchase for another course. For further details, please contact us here.

Where can I send feedback about an Early Access title? Chevron down icon Chevron up icon

If you have any feedback about the product you're reading, or Early Access in general, then please fill out a contact form here and we'll make sure the feedback gets to the right team. 

Can I download the code files for Early Access titles? Chevron down icon Chevron up icon

We try to ensure that all books in Early Access have code available to use, download, and fork on GitHub. This helps us be more agile in the development of the book, and helps keep the often changing code base of new versions and new technologies as up to date as possible. Unfortunately, however, there will be rare cases when it is not possible for us to have downloadable code samples available until publication.

When we publish the book, the code files will also be available to download from the Packt website.

How accurate is the publication date? Chevron down icon Chevron up icon

The publication date is as accurate as we can be at any point in the project. Unfortunately, delays can happen. Often those delays are out of our control, such as changes to the technology code base or delays in the tech release. We do our best to give you an accurate estimate of the publication date at any given time, and as more chapters are delivered, the more accurate the delivery date will become.

How will I know when new chapters are ready? Chevron down icon Chevron up icon

We'll let you know every time there has been an update to a course that you've bought in Early Access. You'll get an email to let you know there has been a new chapter, or a change to a previous chapter. The new chapters are automatically added to your account, so you can also check back there any time you're ready and download or read them online.

I am a Packt subscriber, do I get Early Access? Chevron down icon Chevron up icon

Yes, all Early Access content is fully available through your subscription. You will need to have a paid for or active trial subscription in order to access all titles.

How is Early Access delivered? Chevron down icon Chevron up icon

Early Access is currently only available as a PDF or through our online reader. As we make changes or add new chapters, the files in your Packt account will be updated so you can download them again or view them online immediately.

How do I buy Early Access content? Chevron down icon Chevron up icon

Early Access is a way of us getting our content to you quicker, but the method of buying the Early Access course is still the same. Just find the course you want to buy, go through the check-out steps, and you’ll get a confirmation email from us with information and a link to the relevant Early Access courses.

What is Early Access? Chevron down icon Chevron up icon

Keeping up to date with the latest technology is difficult; new versions, new frameworks, new techniques. This feature gives you a head-start to our content, as it's being created. With Early Access you'll receive each chapter as it's written, and get regular updates throughout the product's development, as well as the final course as soon as it's ready.We created Early Access as a means of giving you the information you need, as soon as it's available. As we go through the process of developing a course, 99% of it can be ready but we can't publish until that last 1% falls in to place. Early Access helps to unlock the potential of our content early, to help you start your learning when you need it most. You not only get access to every chapter as it's delivered, edited, and updated, but you'll also get the finalized, DRM-free product to download in any format you want when it's published. As a member of Packt, you'll also be eligible for our exclusive offers, including a free course every day, and discounts on new and popular titles.