当前位置:Gxlcms > mysql > 【OpenGL】Shader技巧集合

【OpenGL】Shader技巧集合

时间:2021-07-01 10:21:17 帮助过:24人阅读

这篇文章将收集unity中使用shader的相关技巧和特效,会不断地更新内容。关于在Unity中使用shader的介绍,请参考《【OpenGL】使用Unity来学习OpenGL》 常用的内置uniform iResolution =》_ScreenParams iGlobalTime = _Time.y glFragCoord = f loat4 sp:WPOS

这篇文章将收集unity中使用shader的相关技巧和特效,会不断地更新内容。关于在Unity中使用shader的介绍,请参考《【OpenGL】使用Unity来学习OpenGL》

常用的内置uniform

iResolution =》_ScreenParams

iGlobalTime => _Time.y

glFragCoord => float4 sp:WPOS // 需要 #pragma target 3.0, 另外的方式请见下面

vec2 => float2

mix => lerp

mod => fmod

texture2D => tex2D

textureCube => texCUBE

mat2=>float2x2

fract=>frac

========

关于glFragCoord, 可以使用另外一种方式计算(支持3.0之前的)参考官方例子

o.scrPos = ComputeScreenPos(o.pos);

float2 wcoord = (i.scrPos.xy/i.scrPos.w);

-------

float2 wcoord = sp.xy/_ScreenParams.xy;


关于数学的Shader:https://www.shadertoy.com/view/ldlSD2 https://www.shadertoy.com/view/ldlSWj


很好的一个教程:http://ogldev.atspace.co.uk/index.html


Deferred Shading 原理: http://ogldev.atspace.co.uk/www/tutorial35/tutorial35.html


关于Stencil Buffer 的理解:http://www.cnblogs.com/mikewolf2002/archive/2012/05/15/2500867.html

更多文章:1)http://docs.unity3d.com/Manual/SL-Stencil.html

2) http://answers.unity3d.com/questions/590800/how-to-cullrender-to-through-a-window.html


Stencil Shadow Volume : http://ogldev.atspace.co.uk/www/tutorial40/tutorial40.html

http://en.wikipedia.org/wiki/Shadow_volume


镜面反射的实现原理:

ftp://ftp.sgi.com/sgi/opengl/contrib/blythe/advanced99/notes/node158.html

其它镜面反射:

http://en.wikibooks.org/wiki/Cg_Programming/Unity/Mirrors


在unity cg中可以使用[HideInInspector]来隐藏uniform属性,这样就可以用作自定义常量。

Physically Based Rendering: Tutorial: Physically Based Rendering, And you can too!

边缘检测:1) http://www.codeproject.com/Articles/94817/Pixel-Shader-for-Edge-Detection-and-Cartoon-Effect

2) http://coding-experiments.blogspot.hk/2010/06/edge-detection.html

3) http://en.wikipedia.org/wiki/Edge_detection

Cg函数表:http://http.developer.nvidia.com/CgTutorial/cg_tutorial_appendix_e.html

heat effect : http://forum.unity3d.com/threads/50132-Heat-Distortion, http://www.cnblogs.com/geoffyange/archive/2013/06/06/3122570.html

skin shading in unity: http://www.altdevblogaday.com/2011/12/31/skin-shading-in-unity3d/

http://http.developer.nvidia.com/GPUGems3/gpugems3_ch14.html

http://gamedev.stackexchange.com/questions/31308/algorithm-for-creating-spheres

RenderMan University: http://renderman.pixar.com/view/renderman-university

一些shader的例子:









  1. Shader "stalendp/shaderTest02" { //see https://www.shadertoy.com/view/4sj3zy
  2. Properties {
  3. _MainTex ("Base (RGB)", 2D) = "white" {}
  4. }
  5. SubShader {
  6. Pass {
  7. CGPROGRAM
  8. #pragma vertex vert
  9. #pragma fragment frag
  10. #pragma target 3.0
  11. #include "UnityCG.cginc"
  12. sampler2D _MainTex;
  13. //Variable declarations
  14. struct myvars {
  15. float3 bgColor;
  16. float sphereScale;
  17. float sphereShine;
  18. float3 sphereDiff;
  19. float3 sphereSpec;
  20. float2 specPoint;
  21. };
  22. float4 vert(appdata_base v) : POSITION {
  23. return mul(UNITY_MATRIX_MVP, v.vertex);
  24. }
  25. float4 frag(float4 sp:WPOS): COLOR {
  26. myvars mv;
  27. mv.bgColor = float3(0.6, 0.5, 0.6);
  28. mv.sphereScale = 0.7;
  29. mv.sphereShine = 0.5;
  30. mv.sphereDiff = float3(0.5, 0.0, 0.5);
  31. mv.sphereSpec = float3(1.0, 1.0, 1.0);
  32. mv.specPoint = float2(0.2, -0.1);
  33. // creates shader pixel coordinates
  34. float2 uv = sp.xy/_ScreenParams.xy;
  35. // sets the position of the camera
  36. float2 p = uv * 2.5 - float2(1.0, 1.0);
  37. p.x *= _ScreenParams.x / _ScreenParams.y;
  38. // Rotates the sphere in a circle
  39. p.x += cos(-_Time.y) *0.35;
  40. p.y += sin(-_Time.y) * 0.35;
  41. // Rotates the specular point with the sphere
  42. mv.specPoint.x += cos(-_Time.y) * 0.35;
  43. mv.specPoint.y += sin(-_Time.y) * 0.35;
  44. //Sets the radius of the sphere to the middle of the screen
  45. float radius = length(p);//sqrt(dot(p, p));
  46. float3 col = mv.bgColor;
  47. //Sets the initial dark shadow around the edge of the sphere
  48. float f = smoothstep(mv.sphereScale * 0.7, mv.sphereScale, length(p + mv.specPoint));
  49. col -= lerp(col, float3(0.0,0.0,0.0), f) * 0.2;
  50. //Only carries out the logic if the radius of the sphere is less than the scale
  51. if(radius < mv.sphereScale) {
  52. float3 bg = col;
  53. //Sets the diffuse colour of the sphere (solid colour)
  54. col = mv.sphereDiff;
  55. //Adds smooth dark borders to help achieve 3D look
  56. f = smoothstep(mv.sphereScale * 0.7, mv.sphereScale, radius);
  57. col = lerp(col, mv.sphereDiff * 0.45, f);
  58. //Adds specular glow to help achive 3D look
  59. f = 1.0 - smoothstep(-0.2, 0.6, length(p - mv.specPoint));
  60. col += f * mv.sphereShine * mv.sphereSpec;
  61. //Smoothes the edge of the sphere
  62. f = smoothstep(mv.sphereScale - 0.01, mv.sphereScale, radius);
  63. col = lerp(col, bg, f);
  64. }
  65. //The final output of the shader logic above
  66. //gl_FragColor is a vector with 4 paramaters(red, green, blue, alpha)
  67. //Only 2 need to be used here, as "col" is a vector that already carries r, g, and b values
  68. return float4(col, 1);
  69. }
  70. ENDCG
  71. }
  72. }
  73. FallBack "Diffuse"
  74. }


  1. Shader "Custom/shaderTest03" { // https://www.shadertoy.com/view/Xdf3DS
  2. Properties {
  3. _MainTex ("Base (RGB)", 2D) = "white" {}
  4. }
  5. SubShader {
  6. Pass {
  7. CGPROGRAM
  8. #pragma vertex vert
  9. #pragma fragment frag
  10. #pragma target 3.0
  11. #include "UnityCG.cginc"
  12. sampler2D _MainTex;
  13. struct myvars {
  14. float k;
  15. float f;
  16. float threshold;
  17. float3 colour;
  18. float3 normal;
  19. float3 lightPos;
  20. float3 lightColour;
  21. float3 ambient;
  22. float shinyness;
  23. float diffuseFactor;
  24. float4 fragCoord;
  25. };
  26. float2 center ( float2 border , float2 _offset , float2 vel, myvars mv) {
  27. float2 c = _offset + vel * _Time * 0.5;
  28. c = fmod ( c , 2. - 4. * border );
  29. if ( c.x > 1. - border.x ) c.x = 2. - c.x - 2. * border.x;
  30. if ( c.x < border.x ) c.x = 2. * border.x - c.x;
  31. if ( c.y > 1. - border.y ) c.y = 2. - c.y - 2. * border.y;
  32. if ( c.y < border.y ) c.y = 2. * border.y - c.y;
  33. return c;
  34. }
  35. float field ( float b, float r , myvars mv) {
  36. if ( r > b )
  37. return 0.0;
  38. if ( r >= b/3.0 ) {
  39. float rb = 1.0 - r/b;
  40. return (3.0*mv.k)/2.0 * rb * rb;
  41. }
  42. if ( r >= 0.0 && r <= b/3.0 ) {
  43. return mv.k * ( 1.0 - ( (3.0*r*r)/(b*b) ) );
  44. }
  45. return 0.0;
  46. }
  47. void circle ( float r , float2 col , float2 _offset , float2 vel, myvars mv ) {
  48. float2 pos = mv.fragCoord.xy / _ScreenParams.y;
  49. float aspect = _ScreenParams.x / _ScreenParams.y;
  50. float2 c = center ( float2 ( r / aspect , r ) , _offset , vel, mv);
  51. c.x *= aspect;
  52. float d = distance ( pos , c );
  53. float thisField = field (r, d, mv);
  54. mv.f += thisField;
  55. mv.colour += float3(col, 0) * thisField;
  56. mv.normal += normalize(float3(pos.x-c.x, pos.y-c.y,r))*thisField;
  57. }
  58. float4 vert(appdata_base v) : POSITION {
  59. return mul(UNITY_MATRIX_MVP, v.vertex);
  60. }
  61. float4 frag(float4 sp:WPOS): COLOR {
  62. myvars mv;
  63. mv.fragCoord = sp;
  64. mv.k = 100.0;
  65. mv.f = 0.0;
  66. mv.threshold = 10.0;
  67. mv.colour = float3(0.0,0.0,0.0);
  68. mv.normal = float3(0.0,0.0,0.0);
  69. mv.lightPos = float3(_ScreenParams.xy,2000.0);
  70. mv.lightColour = float3(0.9,0.9,1.0);
  71. mv.ambient = float3(0.1,0.0,0.0);
  72. mv.shinyness = 20.0;
  73. mv.diffuseFactor = 0.0006;
  74. circle ( .10 , float3 ( 0.7 , 0.2 , 0.8 ) , float2 ( .6 ) , float2 ( .30 , .70 ), mv );
  75. circle ( .09 , float3 ( 0.7 , 0.9 , 0.6 ) , float2 ( .1 ) , float2 ( .02 , .20 ), mv );
  76. circle ( .12 , float3 ( 0.3 , 0.4 , 0.1 ) , float2 ( .1 ) , float2 ( .10 , .04 ), mv );
  77. circle ( .15 , float3 ( 0.2 , 0.5 , 0.1 ) , float2 ( .3 ) , float2 ( .10 , .20 ), mv );
  78. circle ( .20 , float3 ( 0.1 , 0.3 , 0.7 ) , float2 ( .2 ) , float2 ( .40 , .25 ), mv );
  79. circle ( .30 , float3 ( 0.9 , 0.4 , 0.2 ) , float2 ( .0 ) , float2 ( .15 , .20 ), mv );
  80. float3 c;
  81. if (mv.f < mv.threshold)
  82. c = float3(0.0,0.0,0.0);
  83. else {
  84. mv.colour /= mv.f;
  85. mv.normal = mv.normal/mv.f;
  86. c = mv.ambient;
  87. float3 lightDir = mv.lightPos - float3(sp.xy,0.0);
  88. c += mv.colour * mv.diffuseFactor * max(dot(mv.normal,lightDir), 0.0);
  89. float3 r = normalize ( reflect ( lightDir, mv.normal ) );
  90. c += mv.lightColour * pow(max(dot(r,float3(0.0,0.0,-1.0)), 0.0), mv.shinyness);
  91. }
  92. return float4(c, 1);
  93. }
  94. ENDCG
  95. }
  96. }
  97. }

  1. Shader "stalendp/shaderTest04" { //see https://www.shadertoy.com/view/Xsf3R8
  2. Properties {
  3. _MainTex ("Base (RGB)", 2D) = "white" {}
  4. }
  5. SubShader {
  6. Pass {
  7. CGPROGRAM
  8. #pragma vertex vert
  9. #pragma fragment frag
  10. #pragma target 3.0
  11. #include "UnityCG.cginc"
  12. sampler2D _MainTex;
  13. struct Ray {
  14. float3 org;
  15. float3 dir;
  16. };
  17. float rayPlaneIntersect( Ray ray, float4 plane ) {
  18. float f = dot( ray.dir, plane.xyz );
  19. float t = -( dot( ray.org, plane.xyz ) + plane.w );
  20. t /= f;
  21. return t;
  22. }
  23. float3 shade( float3 pos, float3 nrm, float4 light ) {
  24. float3 toLight = light.xyz - pos;
  25. float toLightLen = length( toLight );
  26. toLight = normalize( toLight );
  27. float diff = dot( nrm, toLight );
  28. float attn = 1.0 - pow( min( 1.0, toLightLen / light.w ), 2.0 );
  29. float comb = 2.0 * diff * attn;
  30. return float3( comb, comb, comb );
  31. }
  32. float4 vert(appdata_base v) : POSITION {
  33. return mul(UNITY_MATRIX_MVP, v.vertex);
  34. }
  35. float4 frag(float4 sp:WPOS): COLOR {
  36. // gl_FragCoord: location (0.5, 0.5) is returned
  37. // for the lower-left-most pixel in a window
  38. // XY of the normalized device coordinate
  39. // ranged from [-1, 1]
  40. float2 ndcXY = -1.0 + 2.0 * sp.xy / _ScreenParams.xy;
  41. // aspect ratio
  42. float aspectRatio = _ScreenParams.x / _ScreenParams.y;
  43. // scaled XY which fits the aspect ratio
  44. float2 scaledXY = ndcXY * float2( aspectRatio, 1.0 );
  45. // camera XYZ in world space
  46. float3 camWsXYZ = float3( 0.0, 1.0, 0.0 );
  47. camWsXYZ.z += 10.0 * cos( _Time.y );
  48. // construct the ray in world space
  49. Ray ray;
  50. ray.org = camWsXYZ;
  51. ray.dir = float3( scaledXY, -2.0 ); // OpenGL is right handed
  52. // define the plane in world space
  53. float4 plane = float4( 0.0, 1.0, 0.0, 0.0 );
  54. float t = rayPlaneIntersect( ray, plane );
  55. // define the point light in world space (XYZ, range)
  56. float4 lightWs = float4( 0.0, 5.0, -5.0, 10.0 );
  57. if ( t >= 0.0 )
  58. {
  59. float3 sceneWsPos = ray.org + t * ray.dir;
  60. float3 sceneWsNrm = plane.xyz;
  61. float2 sceneUV = sceneWsPos.xz / 4.0;
  62. float4 sceneBase = tex2D( _MainTex, sceneUV );
  63. float3 sceneShade = shade( sceneWsPos, sceneWsNrm, lightWs );
  64. return float4( sceneShade * sceneBase.xyz, 1.0 );
  65. }
  66. return float4( 0.0, 0.0, 0.0, 1.0 );
  67. }
  68. ENDCG
  69. }
  70. }
  71. FallBack "Diffuse"
  72. }


  1. Shader "stalendp/shaderTest04" { //see https://www.shadertoy.com/view/MdB3Dw
  2. Properties {
  3. _MainTex ("Base (RGB)", 2D) = "white" {}
  4. }
  5. SubShader {
  6. Pass {
  7. CGPROGRAM
  8. #pragma vertex vert
  9. #pragma fragment frag
  10. #pragma target 3.0
  11. #include "UnityCG.cginc"
  12. #define USE_ANALYTICAL_MBLUR
  13. sampler2D _MainTex;
  14. // intersect a MOVING sphere
  15. float2 iSphere( in float3 ro, in float3 rd, in float4 sp, in float3 ve, out float3 nor )
  16. {
  17. float t = -1.0;
  18. float s = 0.0;
  19. nor = float3(0.0);
  20. float3 rc = ro - sp.xyz;
  21. float A = dot(rc,rd);
  22. float B = dot(rc,rc) - sp.w*sp.w;
  23. float C = dot(ve,ve);
  24. float D = dot(rc,ve);
  25. float E = dot(rd,ve);
  26. float aab = A*A - B;
  27. float eec = E*E - C;
  28. float aed = A*E - D;
  29. float k = aed*aed - eec*aab;
  30. if( k>0.0 )
  31. {
  32. k = sqrt(k);
  33. float hb = (aed - k)/eec;
  34. float ha = (aed + k)/eec;
  35. float ta = max( 0.0, ha );
  36. float tb = min( 1.0, hb );
  37. if( ta < tb )
  38. {
  39. ta = 0.5*(ta+tb);
  40. t = -(A-E*ta) - sqrt( (A-E*ta)*(A-E*ta) - (B+C*ta*ta-2.0*D*ta) );
  41. nor = normalize( (ro+rd*t) - (sp.xyz+ta*ve ) );
  42. s = 2.0*(tb - ta);
  43. }
  44. }
  45. return float2(t,s);
  46. }
  47. // intersect a STATIC sphere
  48. float iSphere( in float3 ro, in float3 rd, in float4 sp, out float3 nor )
  49. {
  50. float t = -1.0;
  51. nor = float3(0.0);
  52. float3 rc = ro - sp.xyz;
  53. float b = dot(rc,rd);
  54. float c = dot(rc,rc) - sp.w*sp.w;
  55. float k = b*b - c;
  56. if( k>0.0 )
  57. {
  58. t = -b - sqrt(k);
  59. nor = normalize( (ro+rd*t) - sp.xyz );
  60. }
  61. return t;
  62. }
  63. float3 getPosition( float time ) { return float3( 2.5*sin(8.0*time), 0.0, 1.0*cos(8.0*time) ); }
  64. float3 getVelocity( float time ) { return float3( 8.0*2.5*cos(8.0*time), 0.0, -8.0*1.0*sin(8.0*time) ); }
  65. float4 vert(appdata_base v) : POSITION {
  66. return mul(UNITY_MATRIX_MVP, v.vertex);
  67. }
  68. float4 frag(float4 sp:WPOS): COLOR {
  69. float2 q = sp.xy / _ScreenParams.xy;
  70. float2 p = -1.0 + 2.0*q;
  71. p.x *= _ScreenParams.x/_ScreenParams.y;
  72. // camera
  73. float3 ro = float3(0.0,0.0,4.0);
  74. float3 rd = normalize( float3(p.xy,-2.0) );
  75. // sphere
  76. // render
  77. float3 col = float3(0.0);
  78. #ifdef USE_ANALYTICAL_MBLUR
  79. //---------------------------------------------------
  80. // render with analytical motion blur
  81. //---------------------------------------------------
  82. float3 ce = getPosition( _Time.y );
  83. float3 ve = getVelocity( _Time.y );
  84. col = float3(0.25) + 0.3*rd.y;
  85. float3 nor = float3(0.0);
  86. float3 tot = float3(0.25) + 0.3*rd.y;
  87. float2 res = iSphere( ro, rd, float4(ce,1.0), ve/24.0, nor );
  88. float t = res.x;
  89. if( t>0.0 )
  90. {
  91. float dif = clamp( dot(nor,float3(0.5703)), 0.0, 1.0 );
  92. float amb = 0.5 + 0.5*nor.y;
  93. float3 lcol = dif*float3(1.0,0.9,0.3) + amb*float3(0.1,0.2,0.3);
  94. col = lerp( tot, lcol, res.y );
  95. }
  96. #else
  97. //---------------------------------------------------
  98. // render with brute force sampled motion blur
  99. //---------------------------------------------------
  100. #define NUMSAMPLES 32
  101. float3 tot = float3(0.0);
  102. for( int i=0; i<numsamples; i++="" )="" {="" float="" fi="float(i)/float(NUMSAMPLES);" float3="" ce="getPosition(" _time.y="" +="" 24.0="" );="" nor="float3(0.0);" tmp="float3(0.25)" 0.3*rd.y;="" t="iSphere(" ro,="" rd,="" float4(ce,1.0),="" if(="">0.0 )
  103. {
  104. float dif = clamp( dot(nor,float3(0.5703)), 0.0, 1.0 );
  105. float amb = 0.5 + 0.5*nor.y;
  106. tmp = dif*float3(1.0,0.9,0.3) + amb*float3(0.1,0.2,0.3);
  107. }
  108. col += tmp;
  109. }
  110. col /= float(NUMSAMPLES);
  111. #endif
  112. col = pow( clamp(col,0.0,1.0), float3(0.45) );
  113. return float4( col, 1.0 );
  114. }
  115. ENDCG
  116. }
  117. }
  118. FallBack "Diffuse"
  119. }
  120. </numsamples;>

  1. Shader "stalendp/shaderTest05" { //see https://www.shadertoy.com/view/XsB3DW
  2. Properties {
  3. _MainTex ("Base (RGB)", 2D) = "white" {}
  4. _CubeDiffuse ("Cubemap Diffuse Map", CUBE) = "" {}
  5. vv1("vv1", float) = -1.0
  6. vv2("vv2", float) = 2.0
  7. }
  8. SubShader {
  9. Pass {
  10. CGPROGRAM
  11. #pragma vertex vert
  12. #pragma fragment frag
  13. #pragma target 3.0
  14. //下面防止编译错误:instruction limit of 1024 exceed;
  15. #pragma glsl
  16. #include "UnityCG.cginc"
  17. #define MAX_STEPS 64
  18. #define MAX_REFLECTIONS 4
  19. #define PI 3.1415926536
  20. sampler2D _MainTex;
  21. samplerCUBE _CubeDiffuse;
  22. float vv1, vv2;
  23. struct Ray {
  24. float3 o;
  25. float3 d;
  26. };
  27. struct Sphere {
  28. float3 o;
  29. float r;
  30. };
  31. struct Box {
  32. float3 o;
  33. float3 s;
  34. };
  35. struct Torus {
  36. float3 o;
  37. float2 s;
  38. };
  39. float2 rotate2d(in float2 v, in float a) {
  40. float sinA = sin(a);
  41. float cosA = cos(a);
  42. return float2(v.x * cosA - v.y * sinA, v.y * cosA + v.x * sinA);
  43. }
  44. float sdSphere(in float3 p, in Sphere s) {
  45. return length(p-s.o)-s.r;
  46. }
  47. float sdBox(in float3 p, in Box b) {
  48. float3 d = abs(p-b.o) - b.s;
  49. return min(max(d.x,max(d.y,d.z)),0.0) +
  50. length(max(d,0.0));
  51. }
  52. float sdTorus(in float3 p, in Torus t) {
  53. p -= t.o;
  54. float2 q = float2(length(p.xz)-t.s.x,p.y);
  55. return length(q)-t.s.y;
  56. }
  57. float world(in float3 p) {
  58. float ti = fmod(_Time.y,10.);
  59. if(ti > 2.) {
  60. Sphere s0 = Sphere(float3(0),1.);
  61. Box b0 = Box(float3(0),float3(.8));
  62. if(ti < 4.) {
  63. return max(-sdSphere(p,s0),sdBox(p,b0));
  64. } else if(ti < 6.) {
  65. return min(sdSphere(p,s0),sdBox(p,b0));
  66. } else if(ti < 8.) {
  67. return max(sdSphere(p,s0),sdBox(p,b0));
  68. } else {
  69. return max(sdSphere(p,s0),-sdBox(p,b0));
  70. }
  71. } else {
  72. float3 pr = p.xzy;
  73. return sdTorus(pr, Torus(float3(0),float2(1.,.5)));
  74. }
  75. }
  76. float3 getNormal(in float3 p) {
  77. float3 d = float3(.005,0,0);
  78. float3 n;
  79. n.x = world(p+d.xyy);
  80. n.y = world(p+d.yxy);
  81. n.z = world(p+d.yyx);
  82. return normalize(n);
  83. }
  84. bool march(in Ray r, out float3 p) {
  85. p = r.o;
  86. float d;
  87. for(int i = 0; i < MAX_STEPS; i++) {
  88. d = world(p);
  89. p += r.d*d;
  90. }
  91. return d<=0.01;
  92. }
  93. float3 colorMarch(in Ray r) {
  94. float3 p;
  95. float3 col = float3(0);
  96. for(int i = 0; i < MAX_REFLECTIONS; i++) {
  97. if(march(r,p)) {
  98. float3 ldir = normalize(float3(1,-1,.5));
  99. float3 n = getNormal(p);
  100. col += float3(dot(n,-ldir))*.25;
  101. r = Ray(p,reflect(r.d,n));
  102. r.o += r.d*0.2;
  103. } else {
  104. break;
  105. }
  106. }
  107. col += texCUBE(_CubeDiffuse, r.d).rgb;
  108. return col;
  109. }
  110. float4 vert(appdata_base v) : POSITION {
  111. return mul(UNITY_MATRIX_MVP, v.vertex);
  112. }
  113. float4 frag(float4 sp:WPOS): COLOR {
  114. float2 uv = 2.*sp.xy/_ScreenParams.xy-1.;
  115. uv.x *= _ScreenParams.x/_ScreenParams.y;
  116. Ray r = Ray(float3(0,0,-2),normalize(float3(uv,1)));
  117. r.o.xz = rotate2d(r.o.xz,_Time.y*.5);
  118. r.d.xz = rotate2d(r.d.xz,_Time.y*.5);
  119. float3 cc =colorMarch(r);
  120. return float4( cc, 1.0 );
  121. }
  122. ENDCG
  123. }
  124. }
  125. FallBack "Diffuse"
  126. }


CGINCLUDE的使用

人气教程排行