Forked from quizcanners/Unity Fragment Shader Cheat Sheet .cs
Created
October 17, 2021 19:27
-
-
Save unitycoder/abb20b84202fd725b647610cf45be1fc to your computer and use it in GitHub Desktop.
Revisions
-
quizcanners revised this gist
Oct 16, 2021 . 1 changed file with 2 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -79,6 +79,8 @@ float cheapstep(float x) { // https://www.shadertoy.com/view/4ldSD2 //*****COOL MATH***** // Nice sharp point light with smooth falloff sizeCoefficient/ distanceFromCenter; // Follaff in two direction 1 / (abs(CENTER - position)*SHARPNESS + 0.01); // Using smoothstep with ddx, ddy, fwidth const SMOOTHNESS = 5; // usually can be left constant after configured -
quizcanners revised this gist
Oct 11, 2021 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -195,7 +195,7 @@ float2 Rot(float2 uv, float angle) { i.tangentViewDir = normalize(i.tangentViewDir); i.tangentViewDir.xy /= (i.tangentViewDir.z + 0.42); // or ..... /= (abs(o.tangentViewDir.z) + 0.42); to work on both sides of a plane uv -= i.tangentViewDir.xy * height; //********** SCREEN SPACE EFFECTS -
quizcanners revised this gist
Oct 9, 2021 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -288,10 +288,10 @@ float sdGyroid(float3 pos, float scale, float thickness, float bias) { float2 screenUv = i.screenPos.xy / i.screenPos.w; float3 ray = normalize(i.worldPos - _WorldSpaceCameraPos); float orthoToPresp = dot(ray, -UNITY_MATRIX_V[2].xyz); float depth = SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, screenPos); depth = Linear01Depth(depth) * _ProjectionParams.z / orthoToPresp; // Getting distance from camera float3 projectedPos = _WorldSpaceCameraPos + ray * depth; float3 cubeSpacePos = mul(unity_WorldToObject, float4(projectedPos,1)).xyz; // xz + 0.5 could be used for UV -
quizcanners revised this gist
Oct 9, 2021 . 1 changed file with 4 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -296,6 +296,9 @@ float sdGyroid(float3 pos, float scale, float thickness, float bias) { float3 projectedPos = _WorldSpaceCameraPos + ray * depth; float3 cubeSpacePos = mul(unity_WorldToObject, float4(projectedPos,1)).xyz; // xz + 0.5 could be used for UV // Normal vector for Decal float3 normal = normalize(cross(ddy(cubeSpacePos), ddx(cubeSpacePos))); // From Target Surface float3 textureNormal = normalize(mul(float3(bumpMap.r, 0.5, bumpMap.g), unity_WorldToObject)); // From Bump Map -
quizcanners revised this gist
Oct 9, 2021 . 1 changed file with 2 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -295,6 +295,7 @@ float sdGyroid(float3 pos, float scale, float thickness, float bias) { float3 projectedPos = _WorldSpaceCameraPos + ray * depth; float3 cubeSpacePos = mul(unity_WorldToObject, float4(projectedPos,1)).xyz; // xz + 0.5 could be used for UV float3 normal = normalize(cross(ddy(cubeSpacePos), ddx(cubeSpacePos))); -
quizcanners revised this gist
Oct 9, 2021 . 1 changed file with 8 additions and 8 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -285,16 +285,16 @@ float sdGyroid(float3 pos, float scale, float thickness, float bias) { // Decal (Uses camera depth) float2 screenUv = i.screenPos.xy / i.screenPos.w; float3 ray = normalize(i.worldPos - _WorldSpaceCameraPos); ray /= dot(ray, -UNITY_MATRIX_V[2].xyz); float depth = SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, screenPos); depth = Linear01Depth(depth) * _ProjectionParams.z; float3 projectedPos = _WorldSpaceCameraPos + ray * depth; float3 cubeSpacePos = mul(unity_WorldToObject, float4(projectedPos,1)).xyz; // xz + 0.5 could be used for UV -
quizcanners revised this gist
Oct 9, 2021 . 1 changed file with 10 additions and 12 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -285,18 +285,16 @@ float sdGyroid(float3 pos, float scale, float thickness, float bias) { // Decal (Uses camera depth) float3 GetCubePosition(float2 screenPos, float3 worldPos) { float3 ray = normalize(worldPos - _WorldSpaceCameraPos); ray /= dot(ray, -UNITY_MATRIX_V[2].xyz); float depth = SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, screenPos); depth = Linear01Depth(depth) * _ProjectionParams.z; float3 projectedPos = _WorldSpaceCameraPos + ray * depth; return mul(unity_WorldToObject, float4(projectedPos,1)).xyz; // xz + 0.5 could be used for UV } -
quizcanners revised this gist
Oct 9, 2021 . 1 changed file with 19 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -281,4 +281,22 @@ float sdGyroid(float3 pos, float scale, float thickness, float bias) { } //Get proximity to culling edge (to apply fog as far as possible, for example) float dist01 = 1- saturate((_ProjectionParams.z - length(o.worldPos.xyz - _WorldSpaceCameraPos.xyz)) / _ProjectionParams.z); // Decal (Uses camera depth) float2 getProjectedUV(float2 screenPos, float3 worldPos) { float3 ray = normalize(worldPos - _WorldSpaceCameraPos); ray /= dot(ray, -UNITY_MATRIX_V[2].xyz); float depth = SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, screenPos); depth = Linear01Depth(depth) * _ProjectionParams.z; float3 projectedPos = _WorldSpaceCameraPos + ray * depth; float3 objectPos = mul(unity_WorldToObject, float4(projectedPos,1)).xyz; clip(0.5 - abs(objectPos)); objectPos += 0.5; return objectPos.xz; } -
quizcanners revised this gist
Oct 8, 2021 . 1 changed file with 4 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -278,4 +278,7 @@ float2 Rot(float2 uv, float angle) { float sdGyroid(float3 pos, float scale, float thickness, float bias) { pos *= scale; return abs(dot(sin(pos), cos(pos.zxy))+bias)/scale - thickness; } //Get proximity to culling edge (to apply fog as far as possible, for example) float dist01 = 1- saturate((_ProjectionParams.z - length(o.worldPos.xyz - _WorldSpaceCameraPos.xyz)) / _ProjectionParams.z); -
quizcanners revised this gist
Jul 12, 2021 . 1 changed file with 5 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -29,6 +29,11 @@ Blend OneMinusDstColor One // Soft Additive // MULTICOMPILE & SHADER FEATURE shader_feature_local // Same as shader_feature, but only for current shader (if Set from Properties) multi_compile_local // Use _local when planning to use any of the following [KeywordEnum(None, Regular, Combined)] _BUMP ("Bump Map", Float) = 0 #pragma shader_feature ___ _BUMP_NONE _BUMP_REGULAR _BUMP_COMBINED -
quizcanners revised this gist
Jul 9, 2021 . 1 changed file with 2 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -69,7 +69,8 @@ float cheapstep(float x) { // https://www.shadertoy.com/view/4ldSD2 normal = normalize(cross(ddy(worldPos),ddx(worldPos))); _MainTex_TexelSize // x,y=1.0/Size | zw=width,length _MainTex_ST // x,y = Tiling, z,w = Offset //*****COOL MATH***** // Nice sharp point light with smooth falloff sizeCoefficient/ distanceFromCenter; -
quizcanners revised this gist
Jul 9, 2021 . 1 changed file with 3 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -43,6 +43,9 @@ Blend OneMinusDstColor One // Soft Additive // or globally (If Shader has it in it's properties, it will ignore the global value) Shader.EnableKeyword("_BLABLABLA") // PRecision & PErformance #pragma fragmentoption ARB_precision_hint_fastest // or ARB_precision_hint_nicest // On some devices makes no difference. Nicest - if shader depends on precise calculations //*****COMMON OPERATORS/FUNCTIONS***** fwidth(x), ddx(x), ddy(x) // The only operation that lets you get info on pixels "Next Door". It tells difference of pixels in this block (https://www.programmersought.com/article/71564489650/). -
quizcanners revised this gist
Jul 6, 2021 . 1 changed file with 5 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -44,7 +44,7 @@ Blend OneMinusDstColor One // Soft Additive Shader.EnableKeyword("_BLABLABLA") //*****COMMON OPERATORS/FUNCTIONS***** fwidth(x), ddx(x), ddy(x) // The only operation that lets you get info on pixels "Next Door". It tells difference of pixels in this block (https://www.programmersought.com/article/71564489650/). y = saturate(x); // Clamp x between 0 and 1 floor(); // return smallest int part @@ -67,7 +67,10 @@ float cheapstep(float x) { // https://www.shadertoy.com/view/4ldSD2 normal = normalize(cross(ddy(worldPos),ddx(worldPos))); _MainTex_TexelSize : x y - 1.0/Size zw - size //*****COOL MATH***** // Nice sharp point light with smooth falloff sizeCoefficient/ distanceFromCenter; // Using smoothstep with ddx, ddy, fwidth const SMOOTHNESS = 5; // usually can be left constant after configured float offset = fwidth(uv); // To see how big the image is on the screen (Bigger => Sharper transition) -
quizcanners revised this gist
Jul 5, 2021 . 1 changed file with 8 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -168,18 +168,22 @@ float2 Rot(float2 uv, float angle) { // Parallax //v2f: float3 tangentViewDir : TEXCOORD5; // 5 or whichever is free //vert: float3x3 objectToTangent = float3x3( v.tangent.xyz, cross(v.normal, v.tangent.xyz) * v.tangent.w, v.normal ); o.tangentViewDir = mul(objectToTangent, ObjSpaceViewDir(v.vertex)); //frag i.tangentViewDir = normalize(i.tangentViewDir); i.tangentViewDir.xy /= (i.tangentViewDir.z + 0.42); // or ..... /= (abs(o.tangentViewDir.z) + 0.42); to work on both sides of a plane uv -= tangentViewDir.xy; //********** SCREEN SPACE EFFECTS -
quizcanners revised this gist
Jun 11, 2021 . 1 changed file with 6 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -65,10 +65,14 @@ float cheapstep(float x) { // https://www.shadertoy.com/view/4ldSD2 step(a, x) // returns 1 if x>a, 0 - otherwise normal = normalize(cross(ddy(worldPos),ddx(worldPos))); _MainTex_TexelSize : x y - 1.0/Size zw - size //*****COOL MATH***** // Using smoothstep with ddx, ddy, fwidth const SMOOTHNESS = 5; // usually can be left constant after configured float offset = fwidth(uv); // To see how big the image is on the screen (Bigger => Sharper transition) float pixelSmoothBox = smoothstep(1, 1 - offset * SMOOTHNESS , distanceToEdge); // Random ()Hash float hash11(float p) { -
quizcanners revised this gist
Jun 11, 2021 . 1 changed file with 5 additions and 5 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -99,11 +99,11 @@ float2 Rot(float2 uv, float angle) { // Get Angle in 01 space // Option A: float2 uv = IN.texcoord.xy - 0.5; const float PI2 = 3.14159265359 *2; float pixel_angle = atan2(uv.x, uv.y)/ PI2 + 0.5; float pixel_distance = length(uv)* 2; float2 uv2 = float2(pixel_angle, pixel_distance); // Option B: (Dont't remember but I think this helped me avoid some artifacs in some case) const float PI2 = 3.14159265359 * 2; -
quizcanners revised this gist
Jun 11, 2021 . 1 changed file with 8 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -98,6 +98,14 @@ float2 Rot(float2 uv, float angle) { float angle = (atan2(uv.x, uv.y) + pii) / pi2 // Get Angle in 01 space // Option A: float2 uv = IN.texcoord.xy - 0.5; const float PI2 = 3.14159265359 *2; float pixel_angle = atan2(uv.x, uv.y)/ PI2 + 0.5; float pixel_distance = length(uv) * 2.0; float2 uv2 = float2(pixel_angle, pixel_distance) * 0.5; // Option B: (Dont't remember but I think this helped me avoid some artifacs in some case) const float PI2 = 3.14159265359 * 2; float angle = atan2(-uv.x, -uv.y)+0.001; angle = saturate(max(angle, -
quizcanners revised this gist
May 14, 2021 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -67,6 +67,7 @@ float cheapstep(float x) { // https://www.shadertoy.com/view/4ldSD2 normal = normalize(cross(ddy(worldPos),ddx(worldPos))); _MainTex_TexelSize : x y - 1.0/Size zw - size //*****COOL MATH***** // Random ()Hash -
quizcanners revised this gist
May 14, 2021 . 1 changed file with 3 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -126,15 +126,15 @@ float2 Rot(float2 uv, float angle) { // Smooth Pixelation Sampling (Looks really cool) const float sharpness = 40; float2 perfTex = (floor(IN.uv_MainTex.xy*_MainTex_TexelSize.zw) + 0.5) * _MainTex_TexelSize.xy; float2 off = (IN.uv_MainTex.xy - perfTex); float2 diff = (abs(off) * _MainTex_TexelSize.zw); float2 edge = saturate((diff * 2 - 1)*sharpness + 1); perfTex += off * edge; float4 col = tex2D(_MainTex, perfTex); // To Also get the border: float2 diff = (abs(off) * _MainTex_TexelSize.zw); edge = saturate((diff * 2 - 1)*sharpness*0.1 + 1); // In some usages the are between pixels contains other pixels, then border needs to be less sharp to fully cover that area. float border = max(edge.x, edge.y); -
quizcanners revised this gist
May 14, 2021 . 1 changed file with 2 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -131,9 +131,10 @@ float2 Rot(float2 uv, float angle) { float2 diff = (abs(off) * _MainTex_TexelSize.z); float2 edge = saturate((diff * 2 - 1)*sharpness + 1); perfTex += off * edge; float4 col = tex2D(_MainTex, perfTex); // To Also get the border: float2 diff = (abs(off) * _MainTex_TexelSize.z); edge = saturate((diff * 2 - 1)*sharpness*0.1 + 1); // In some usages the are between pixels contains other pixels, then border needs to be less sharp to fully cover that area. float border = max(edge.x, edge.y); -
quizcanners revised this gist
May 2, 2021 . 1 changed file with 8 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -20,6 +20,14 @@ // [HideInInspector] - no need to show this in inspector _Test("Any value", float) = 1 // Blend Modes: Blend SrcAlpha OneMinusSrcAlpha // Traditional transparency Blend One One // Additive Blend OneMinusDstColor One // Soft Additive // MULTICOMPILE & SHADER FEATURE [KeywordEnum(None, Regular, Combined)] _BUMP ("Bump Map", Float) = 0 #pragma shader_feature ___ _BUMP_NONE _BUMP_REGULAR _BUMP_COMBINED -
quizcanners revised this gist
Apr 15, 2021 . 1 changed file with 7 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -234,4 +234,10 @@ float2 Rot(float2 uv, float angle) { // Color Bleed (https://www.quizcanners.com/single-post/2018/04/02/Color-Bleeding-in-Shader) float3 mix = col.gbr + col.brg; col.rgb += mix * mix*amount; // amount = 0.02 // Gyroid float sdGyroid(float3 pos, float scale, float thickness, float bias) { pos *= scale; return abs(dot(sin(pos), cos(pos.zxy))+bias)/scale - thickness; } -
quizcanners revised this gist
Apr 15, 2021 . 1 changed file with 3 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -12,7 +12,7 @@ [PerRendererData][NoScaleOffset]_MainTex("Albedo", 2D) = "white" {} // Image UI elements throw error in Build if Material(It's Shader) doesn't have _MainTex, so keep it here even if not used. // [PerRendererData] - For UI, to hide it from material inspector; // [NoScaleOffset] - To Hide scale and offset editing window - usefult if they are not utilized in shader // Alternative Default Values: "white", "black", "gray", "bump", "red" _Color("Color", Color) = (1,1,1,1) _SomeSlider("Reflectiveness or something", Range(0,1)) = 0 @@ -32,12 +32,12 @@ //Management // From script you can set this keywords renderer.material.EnableKeyword("_BLABLABLA"); // or globally (If Shader has it in it's properties, it will ignore the global value) Shader.EnableKeyword("_BLABLABLA") //*****COMMON OPERATORS/FUNCTIONS***** fwidth(x), ddx(x), ddy(x) // The only operation that lets you get info on pixels "Next Door". It tells difference of pixels in this block (https://www.programmersought.com/article/71564489650/). y = saturate(x); // Clamp x between 0 and 1 floor(); // return smallest int part x % 1 // get fraction part -
quizcanners renamed this gist
Apr 15, 2021 . 1 changed file with 1 addition and 8 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -234,11 +234,4 @@ float2 Rot(float2 uv, float angle) { // Color Bleed (https://www.quizcanners.com/single-post/2018/04/02/Color-Bleeding-in-Shader) float3 mix = col.gbr + col.brg; col.rgb += mix * mix*amount; // amount = 0.02 -
quizcanners revised this gist
Apr 15, 2021 . 1 changed file with 3 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -56,6 +56,9 @@ float cheapstep(float x) { // https://www.shadertoy.com/view/4ldSD2 step(a, x) // returns 1 if x>a, 0 - otherwise normal = normalize(cross(ddy(worldPos),ddx(worldPos))); //*****COOL MATH***** // Random ()Hash -
quizcanners revised this gist
Jun 6, 2020 . 1 changed file with 3 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -75,10 +75,11 @@ inline float DistToLine(float3 pos, float3 a, float3 b) { } // Rotation (Pivot in center) float2 Rot(float2 uv, float angle) { float si = sin(angle); float co = cos(angle); return float2(co * uv.x - si * uv.y, si * uv.x + co * uv.y); } // Get Angle: -
quizcanners revised this gist
Apr 26, 2020 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -37,7 +37,7 @@ //*****COMMON OPERATORS/FUNCTIONS***** fwidth(x), ddx(x), ddy(x) // The only operation that lets you get info from pixels "Next Door". It tells how diffrent (+-) X is in the next pixel. y = saturate(x); // Clamp x between 0 and 1 floor(); // return smallest int part x % 1 // get fraction part -
quizcanners revised this gist
Apr 20, 2020 . 1 changed file with 2 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -218,10 +218,11 @@ vec2 Rot(vec2 uv, float angle){ o.tspace2 = half3(wTangent.z, wBitangent.z, wNormal.z); // ..... frag float3 tnormal = UnpackNormal(tex2D(_BumpMap, TRANSFORM_TEX(i.texcoord, _BumpMap))); worldNormal.x = dot(i.tspace0, tnormal); worldNormal.y = dot(i.tspace1, tnormal); worldNormal.z = dot(i.tspace2, tnormal); // Shadow SHADOW_COORDS(2) TRANSFER_SHADOW(o); -
quizcanners revised this gist
Apr 8, 2020 . 1 changed file with 8 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -58,6 +58,14 @@ float cheapstep(float x) { // https://www.shadertoy.com/view/4ldSD2 //*****COOL MATH***** // Random ()Hash float hash11(float p) { p = fract(p * .1031); p *= p + 33.33; p *= p + p; return fract(p); } // Distance to a line: inline float DistToLine(float3 pos, float3 a, float3 b) { float3 pa = pos - a; -
quizcanners revised this gist
Mar 23, 2020 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -46,7 +46,7 @@ smoothstep (a, b , t); // Basically allows us to remap t from ab space to 01 space but with smoothing; // Returns 0 if t<a<b; 1 if t>b>a, interpolates in-between; Will reverse if b<a; x*x*(3.0 - (2.0*x)); // To apply smoothing when 0<=x<=1. (When applied to the function below will produce smoothstep). sharpstep(a, b, x) => saturate((x - a)/(b - a)); // Remap X to [A,B] sharply. float cheapstep(float x) { // https://www.shadertoy.com/view/4ldSD2 x = 1.0 - x*x; // MAD
NewerOlder