Original GLSL
keijiro/ShaderSketches/Fragment/TriLattice.glsl
Unity Shader
1. Convert Functions Properties GLSL to Unity One. List here.
* GLSL SandboxをUnityに移植する方法その1 - 渋谷ほととぎす通信
* opengl:glsl_hlsl HYPERでんち
* half fixed float more proper.
Original GLSL
keijiro/ShaderSketches/Fragment/TriLattice.glsl
Unity Shader
1. Convert Functions Properties GLSL to Unity One. List here.
* GLSL SandboxをUnityに移植する方法その1 - 渋谷ほととぎす通信
* opengl:glsl_hlsl HYPERでんち
* half fixed float more proper.
| Shader "Unlit/Glsl1" | |
| { | |
| Properties | |
| { | |
| } | |
| SubShader | |
| { | |
| Tags { "RenderType"="Opaque" } | |
| LOD 100 | |
| Pass | |
| { | |
| CGPROGRAM | |
| #pragma vertex vert_img | |
| #pragma fragment frag | |
| #include "UnityCG.cginc" | |
| float rand(half2 uv) | |
| { | |
| return frac(sin(dot(uv, half2(12.9898, 78.233))) * 43758.5453); | |
| } | |
| half2 uv2tri(half2 uv) | |
| { | |
| float sx = uv.x - uv.y / 2; // skewed x | |
| float sxf = frac(sx); | |
| float offs = step(frac(1 - uv.y), sxf); | |
| return half2(floor(sx) * 2 + sxf + offs, uv.y); | |
| } | |
| fixed4 tri(half2 uv) | |
| { | |
| float sp = 1.2 + 3.3 * rand(floor(uv2tri(uv))); | |
| float time = _Time * 30; | |
| return max(0, sin(sp * time)); | |
| } | |
| //float4 frag (v2f_img i) : SV_Target | |
| fixed4 frag (v2f_img i) : SV_Target | |
| { | |
| fixed2 resolution = _ScreenParams; | |
| half2 uv = (i.uv*resolution.xy - resolution.xy / 2) / resolution.y; | |
| float time = _Time * 30; | |
| float t1 = time / 2; | |
| float t2 = t1 + 0.5; | |
| float c1 = tri(uv * (2 + 4 * frac(t1)) + floor(t1)); | |
| float c2 = tri(uv * (2 + 4 * frac(t2)) + floor(t2)); | |
| float a = lerp(c1, c2, abs(1 - 2 * frac(t1))); | |
| //return float4(a,a,a,a); | |
| return fixed4(a,a,a,a); | |
| } | |
| ENDCG | |
| } | |
| } | |
| } |
| #version 150 | |
| uniform float time; | |
| uniform vec2 resolution; | |
| out vec4 fragColor; | |
| float rand(vec2 uv) | |
| { | |
| return fract(sin(dot(uv, vec2(12.9898, 78.233))) * 43758.5453); | |
| } | |
| vec2 uv2tri(vec2 uv) | |
| { | |
| float sx = uv.x - uv.y / 2; // skewed x | |
| float sxf = fract(sx); | |
| float offs = step(fract(1 - uv.y), sxf); | |
| return vec2(floor(sx) * 2 + sxf + offs, uv.y); | |
| } | |
| float tri(vec2 uv) | |
| { | |
| float sp = 1.2 + 3.3 * rand(floor(uv2tri(uv))); | |
| return max(0, sin(sp * time)); | |
| } | |
| void main(void) | |
| { | |
| vec2 uv = (gl_FragCoord.xy - resolution.xy / 2) / resolution.y; | |
| float t1 = time / 2; | |
| float t2 = t1 + 0.5; | |
| float c1 = tri(uv * (2 + 4 * fract(t1)) + floor(t1)); | |
| float c2 = tri(uv * (2 + 4 * fract(t2)) + floor(t2)); | |
| fragColor = vec4(mix(c1, c2, abs(1 - 2 * fract(t1)))); | |
| } |