Shaders in Unity by Zoel

646
-1

Published on

0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
646
On Slideshare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
11
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide

Shaders in Unity by Zoel

  1. 1. @agatestudio Shaders in Unity Zoel Knight Agate Studio
  2. 2. Geometry Deformation. Pixels processing. Math intensive calculations. GPGPU.
  3. 3. • D3D / OpenGL Render Pipeline Stages Vertex Shader Fragment Shader Geometry ShaderTessellation Primitive Assembly Rasterization Raster Operations Pixels Vertex Assembly Screen Hull DomainTessellator Stage
  4. 4. • Runs per input vertex. • Transform 3D into 2D (screen space) position. • Can perform vertex position, color ,UV (texture coordinates) manipulation. • Cannot create new vertices. • Cannot “see” other vertices.
  5. 5. • Runs per fragment. • Computes fragment’s color. • With fragment shader you can create: bump mapping, shadows, lights, post processing effects and other cool shit. • See http://glsl.heroku.com/
  6. 6. Shaders before Cg/HLSL/GLSL: TEX H0, f[TEX0], TEX4, 2D; TEX H1, f[TEX2], TEX5, CUBE; DP3X H1.xyz, H1, LUMINANCE; MULX H0.w, H0.w, LUMINANCE.w; MULX H1.w, H1.x, H1.x; MOVH H2, f[TEX3].wxyz; MULX H1.w, H1.x, H1.w; DP3X H0.xyz, H2.xzyw, H0; MULX H0.xyz, H0, H1.w; TEX H1, f[TEX0], TEX1, 2D; TEX H3, f[TEX0], TEX3, 2D; MULX H0.xyz, H0, H3; Bla… Bla… Bla…
  7. 7. CG Shader • “C for graphics” • High Level language. Cg != C • No classes, pointers, malloc , IO etc. • Cg has loops, conditionals, functions/overloads. • Member variables, local (temporary) variables constants. • Data types: numeric primitives, vectors, matrices, arrays, structs, and interfaces. • Built-in trig and other math methods. • Static & Dynamic compilation.
  8. 8. Cg and Graphics APIs interop scheme:
  9. 9. 3 Ways of writing shaders in Unity: Surface shaders. Vertex and fragment shaders. Fixed function shaders.
  10. 10. Simple Custom shader:
  11. 11. Passing vertex attributes and uniforms • Programmable setup (via scripts): - SetFloat() - SetVector() - SetMatrix() - SetColor() - SetBuffer() - SetTexture() • Shader lab properties: [UniformName+(*“Uniform property panel name“+, *Data Type+) = [Default value]
  12. 12. Accessing uniforms: Very simple!!! Declare uniforms in the shader header with exactly the same names and data types as they have in Shader Lab prop block.
  13. 13. Thank you!!! http://aras-p.info/blog/ http://docs.unity3d.com/Documentation/Manual/Shaders.html http://http.developer.nvidia.com/CgTutorial/cg_tutorial_chapter01.html https://developer.nvidia.com/shader-library http://wiki.unity3d.com/index.php/Shaders zoelbastianbach@agategames.com

×