Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unity 5 4 #230

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Assets/Scripts/Chapter12/PostEffectsBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ protected void CheckResources() {

// Called in CheckResources to check support on this platform
protected bool CheckSupport() {
if (SystemInfo.supportsImageEffects == false || SystemInfo.supportsRenderTextures == false) {
Debug.LogWarning("This platform does not support image effects or render textures.");
if (SystemInfo.supportsImageEffects == false) {
Debug.LogWarning("This platform does not support image effects.");
return false;
}

Expand Down
2 changes: 1 addition & 1 deletion Assets/Scripts/Chapter13/FogWithDepthTexture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public Material material {
}

private Camera myCamera;
public Camera camera {
public new Camera camera {
get {
if (myCamera == null) {
myCamera = GetComponent<Camera>();
Expand Down
2 changes: 1 addition & 1 deletion Assets/Scripts/Chapter13/MotionBlurWithDepthTexture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public Material material {
}

private Camera myCamera;
public Camera camera {
public new Camera camera {
get {
if (myCamera == null) {
myCamera = GetComponent<Camera>();
Expand Down
2 changes: 1 addition & 1 deletion Assets/Scripts/Chapter15/FogWithNoise.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public Material material {
}

private Camera myCamera;
public Camera camera {
public new Camera camera {
get {
if (myCamera == null) {
myCamera = GetComponent<Camera>();
Expand Down
4 changes: 2 additions & 2 deletions Assets/Shaders/Chapter10/Chapter10-Fresnel.shader
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@

v2f vert(a2v v) {
v2f o;
o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
o.pos = UnityObjectToClipPos(v.vertex);

o.worldNormal = UnityObjectToWorldNormal(v.normal);

o.worldPos = mul(_Object2World, v.vertex).xyz;
o.worldPos = mul(unity_ObjectToWorld, v.vertex).xyz;

o.worldViewDir = UnityWorldSpaceViewDir(o.worldPos);

Expand Down
4 changes: 2 additions & 2 deletions Assets/Shaders/Chapter10/Chapter10-GlassRefraction.shader
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,14 @@

v2f vert (a2v v) {
v2f o;
o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
o.pos = UnityObjectToClipPos(v.vertex);

o.scrPos = ComputeGrabScreenPos(o.pos);

o.uv.xy = TRANSFORM_TEX(v.texcoord, _MainTex);
o.uv.zw = TRANSFORM_TEX(v.texcoord, _BumpMap);

float3 worldPos = mul(_Object2World, v.vertex).xyz;
float3 worldPos = mul(unity_ObjectToWorld, v.vertex).xyz;
fixed3 worldNormal = UnityObjectToWorldNormal(v.normal);
fixed3 worldTangent = UnityObjectToWorldDir(v.tangent.xyz);
fixed3 worldBinormal = cross(worldNormal, worldTangent) * v.tangent.w;
Expand Down
4 changes: 3 additions & 1 deletion Assets/Shaders/Chapter10/Chapter10-Mirror.shader
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

#pragma vertex vert
#pragma fragment frag

#include "UnityCG.cginc"

sampler2D _MainTex;

Expand All @@ -25,7 +27,7 @@

v2f vert(a2v v) {
v2f o;
o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
o.pos = UnityObjectToClipPos(v.vertex);

o.uv = v.texcoord;
// Mirror needs to filp x
Expand Down
4 changes: 2 additions & 2 deletions Assets/Shaders/Chapter10/Chapter10-Reflection.shader
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@
v2f vert(a2v v) {
v2f o;

o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
o.pos = UnityObjectToClipPos(v.vertex);

o.worldNormal = UnityObjectToWorldNormal(v.normal);

o.worldPos = mul(_Object2World, v.vertex).xyz;
o.worldPos = mul(unity_ObjectToWorld, v.vertex).xyz;

o.worldViewDir = UnityWorldSpaceViewDir(o.worldPos);

Expand Down
4 changes: 2 additions & 2 deletions Assets/Shaders/Chapter10/Chapter10-Refraction.shader
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@

v2f vert(a2v v) {
v2f o;
o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
o.pos = UnityObjectToClipPos(v.vertex);

o.worldNormal = UnityObjectToWorldNormal(v.normal);

o.worldPos = mul(_Object2World, v.vertex).xyz;
o.worldPos = mul(unity_ObjectToWorld, v.vertex).xyz;

o.worldViewDir = UnityWorldSpaceViewDir(o.worldPos);

Expand Down
4 changes: 2 additions & 2 deletions Assets/Shaders/Chapter11/Chapter11-Billboard.shader
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@

// Suppose the center in object space is fixed
float3 center = float3(0, 0, 0);
float3 viewer = mul(_World2Object,float4(_WorldSpaceCameraPos, 1));
float3 viewer = mul(unity_WorldToObject,float4(_WorldSpaceCameraPos, 1));

float3 normalDir = viewer - center;
// If _VerticalBillboarding equals 1, we use the desired view dir as the normal dir
Expand All @@ -61,7 +61,7 @@
float3 centerOffs = v.vertex.xyz - center;
float3 localPos = center + rightDir * centerOffs.x + upDir * centerOffs.y + normalDir * centerOffs.z;

o.pos = mul(UNITY_MATRIX_MVP, float4(localPos, 1));
o.pos = UnityObjectToClipPos(float4(localPos, 1));
o.uv = TRANSFORM_TEX(v.texcoord,_MainTex);

return o;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@

v2f vert (a2v v) {
v2f o;
o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
o.pos = UnityObjectToClipPos(v.vertex);
o.uv = TRANSFORM_TEX(v.texcoord, _MainTex);
return o;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@

v2f vert (a2v v) {
v2f o;
o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
o.pos = UnityObjectToClipPos(v.vertex);

o.uv.xy = TRANSFORM_TEX(v.texcoord, _MainTex) + frac(float2(_ScrollX, 0.0) * _Time.y);
o.uv.zw = TRANSFORM_TEX(v.texcoord, _DetailTex) + frac(float2(_Scroll2X, 0.0) * _Time.y);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
float4 offset;
offset.yzw = float3(0.0, 0.0, 0.0);
offset.x = sin(_Frequency * _Time.y + v.vertex.x * _InvWaveLength + v.vertex.y * _InvWaveLength + v.vertex.z * _InvWaveLength) * _Magnitude;
o.pos = mul(UNITY_MATRIX_MVP, v.vertex + offset);
o.pos = UnityObjectToClipPos(v.vertex + offset);

o.uv = TRANSFORM_TEX(v.texcoord, _MainTex);
o.uv += float2(0.0, _Time.y * _Speed);
Expand Down
2 changes: 1 addition & 1 deletion Assets/Shaders/Chapter11/Chapter11-Water.shader
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ Shader "Unity Shaders Book/Chapter 11/Water" {
float4 offset;
offset.yzw = float3(0.0, 0.0, 0.0);
offset.x = sin(_Frequency * _Time.y + v.vertex.x * _InvWaveLength + v.vertex.y * _InvWaveLength + v.vertex.z * _InvWaveLength) * _Magnitude;
o.pos = mul(UNITY_MATRIX_MVP, v.vertex + offset);
o.pos = UnityObjectToClipPos(v.vertex + offset);

o.uv = TRANSFORM_TEX(v.texcoord, _MainTex);
o.uv += float2(0.0, _Time.y * _Speed);
Expand Down
4 changes: 2 additions & 2 deletions Assets/Shaders/Chapter12/Chapter12-Bloom.shader
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
v2f vertExtractBright(appdata_img v) {
v2f o;

o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
o.pos = UnityObjectToClipPos(v.vertex);

o.uv = v.texcoord;

Expand All @@ -50,7 +50,7 @@
v2fBloom vertBloom(appdata_img v) {
v2fBloom o;

o.pos = mul (UNITY_MATRIX_MVP, v.vertex);
o.pos = UnityObjectToClipPos (v.vertex);
o.uv.xy = v.texcoord;
o.uv.zw = v.texcoord;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
v2f vert(appdata_img v) {
v2f o;

o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
o.pos = UnityObjectToClipPos(v.vertex);

o.uv = v.texcoord;

Expand Down
2 changes: 1 addition & 1 deletion Assets/Shaders/Chapter12/Chapter12-EdgeDetection.shader
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Shader "Unity Shaders Book/Chapter 12/Edge Detection" {

v2f vert(appdata_img v) {
v2f o;
o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
o.pos = UnityObjectToClipPos(v.vertex);

half2 uv = v.texcoord;

Expand Down
4 changes: 2 additions & 2 deletions Assets/Shaders/Chapter12/Chapter12-GaussianBlur.shader
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

v2f vertBlurVertical(appdata_img v) {
v2f o;
o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
o.pos = UnityObjectToClipPos(v.vertex);

half2 uv = v.texcoord;

Expand All @@ -34,7 +34,7 @@

v2f vertBlurHorizontal(appdata_img v) {
v2f o;
o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
o.pos = UnityObjectToClipPos(v.vertex);

half2 uv = v.texcoord;

Expand Down
2 changes: 1 addition & 1 deletion Assets/Shaders/Chapter12/Chapter12-MotionBlur.shader
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
v2f vert(appdata_img v) {
v2f o;

o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
o.pos = UnityObjectToClipPos(v.vertex);

o.uv = v.texcoord;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

v2f vert(appdata_img v) {
v2f o;
o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
o.pos = UnityObjectToClipPos(v.vertex);

half2 uv = v.texcoord;
o.uv[0] = uv;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

v2f vert(appdata_img v) {
v2f o;
o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
o.pos = UnityObjectToClipPos(v.vertex);

o.uv = v.texcoord;
o.uv_depth = v.texcoord;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

v2f vert(appdata_img v) {
v2f o;
o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
o.pos = UnityObjectToClipPos(v.vertex);

o.uv = v.texcoord;
o.uv_depth = v.texcoord;
Expand All @@ -39,6 +39,9 @@
fixed4 frag(v2f i) : SV_Target {
// Get the depth buffer value at this pixel.
float d = SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, i.uv_depth);
#if defined(UNITY_REVERSED_Z)
d = 1.0 - d;
#endif
// H is the viewport position at this pixel in the range -1 to 1.
float4 H = float4(i.uv.x * 2 - 1, i.uv.y * 2 - 1, d * 2 - 1, 1);
// Transform by the view-projection inverse.
Expand Down
4 changes: 2 additions & 2 deletions Assets/Shaders/Chapter14/Chapter14-Hatching.shader
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ Shader "Unity Shaders Book/Chapter 14/Hatching" {
v2f vert(a2v v) {
v2f o;

o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
o.pos = UnityObjectToClipPos(v.vertex);

o.uv = v.texcoord.xy * _TileFactor;

Expand Down Expand Up @@ -97,7 +97,7 @@ Shader "Unity Shaders Book/Chapter 14/Hatching" {
o.hatchWeights1.z = 1.0 - o.hatchWeights1.y;
}

o.worldPos = mul(_Object2World, v.vertex).xyz;
o.worldPos = mul(unity_ObjectToWorld, v.vertex).xyz;

TRANSFER_SHADOW(o);

Expand Down
4 changes: 2 additions & 2 deletions Assets/Shaders/Chapter14/Chapter14-ToonShading.shader
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,10 @@
v2f vert (a2v v) {
v2f o;

o.pos = mul( UNITY_MATRIX_MVP, v.vertex);
o.pos = UnityObjectToClipPos( v.vertex);
o.uv = TRANSFORM_TEX (v.texcoord, _MainTex);
o.worldNormal = UnityObjectToWorldNormal(v.normal);
o.worldPos = mul(_Object2World, v.vertex).xyz;
o.worldPos = mul(unity_ObjectToWorld, v.vertex).xyz;

TRANSFER_SHADOW(o);

Expand Down
4 changes: 2 additions & 2 deletions Assets/Shaders/Chapter15/Chapter15-Dissolve.shader
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@

v2f vert(a2v v) {
v2f o;
o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
o.pos = UnityObjectToClipPos(v.vertex);

o.uvMainTex = TRANSFORM_TEX(v.texcoord, _MainTex);
o.uvBumpMap = TRANSFORM_TEX(v.texcoord, _BumpMap);
Expand All @@ -66,7 +66,7 @@
TANGENT_SPACE_ROTATION;
o.lightDir = mul(rotation, ObjSpaceLightDir(v.vertex)).xyz;

o.worldPos = mul(_Object2World, v.vertex).xyz;
o.worldPos = mul(unity_ObjectToWorld, v.vertex).xyz;

TRANSFER_SHADOW(o);

Expand Down
2 changes: 1 addition & 1 deletion Assets/Shaders/Chapter15/Chapter15-FogWithNoise.shader
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@

v2f vert(appdata_img v) {
v2f o;
o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
o.pos = UnityObjectToClipPos(v.vertex);

o.uv = v.texcoord;
o.uv_depth = v.texcoord;
Expand Down
4 changes: 2 additions & 2 deletions Assets/Shaders/Chapter15/Chapter15-WaterWave.shader
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,14 @@

v2f vert(a2v v) {
v2f o;
o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
o.pos = UnityObjectToClipPos(v.vertex);

o.scrPos = ComputeGrabScreenPos(o.pos);

o.uv.xy = TRANSFORM_TEX(v.texcoord, _MainTex);
o.uv.zw = TRANSFORM_TEX(v.texcoord, _WaveMap);

float3 worldPos = mul(_Object2World, v.vertex).xyz;
float3 worldPos = mul(unity_ObjectToWorld, v.vertex).xyz;
fixed3 worldNormal = UnityObjectToWorldNormal(v.normal);
fixed3 worldTangent = UnityObjectToWorldDir(v.tangent.xyz);
fixed3 worldBinormal = cross(worldNormal, worldTangent) * v.tangent.w;
Expand Down
2 changes: 1 addition & 1 deletion Assets/Shaders/Chapter18/SimpleBlend.shader
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

v2f vert(a2v v) {
v2f o;
o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
o.pos = UnityObjectToClipPos(v.vertex);
o.uv = TRANSFORM_TEX(v.texcoord, _MainTex);
return o;
}
Expand Down
2 changes: 1 addition & 1 deletion Assets/Shaders/Chapter5/Chapter5-FalseColor.shader
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

v2f vert(appdata_full v) {
v2f o;
o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
o.pos = UnityObjectToClipPos(v.vertex);

// Visualize normal
o.color = fixed4(v.normal * 0.5 + fixed3(0.5, 0.5, 0.5), 1.0);
Expand Down
4 changes: 3 additions & 1 deletion Assets/Shaders/Chapter5/Chapter5-SimpleShader.shader
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
Pass {
CGPROGRAM

#include "UnityCG.cginc"

#pragma vertex vert
#pragma fragment frag

Expand All @@ -24,7 +26,7 @@

v2f vert(a2v v) {
v2f o;
o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
o.pos = UnityObjectToClipPos(v.vertex);
o.color = v.normal * 0.5 + fixed3(0.5, 0.5, 0.5);
return o;
}
Expand Down
6 changes: 3 additions & 3 deletions Assets/Shaders/Chapter6/Chapter6-BlinnPhong.shader
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@
v2f vert(a2v v) {
v2f o;
// Transform the vertex from object space to projection space
o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
o.pos = UnityObjectToClipPos(v.vertex);

// Transform the normal from object space to world space
o.worldNormal = mul(v.normal, (float3x3)_World2Object);
o.worldNormal = mul(v.normal, (float3x3)unity_WorldToObject);

// Transform the vertex from object spacet to world space
o.worldPos = mul(_Object2World, v.vertex).xyz;
o.worldPos = mul(unity_ObjectToWorld, v.vertex).xyz;

return o;
}
Expand Down
Loading