shaders in unity by zoel
Post on 06-May-2015
451 Views
Preview:
TRANSCRIPT
@agatestudio
Shaders in Unity
Zoel
Knight
Agate Studio
Geometry Deformation.
Pixels processing.
Math intensive calculations.
GPGPU.
• D3D / OpenGL Render Pipeline Stages
Vertex Shader
Fragment Shader
Geometry ShaderTessellation
Primitive Assembly
Rasterization
Raster Operations
Pixels
Vertex Assembly
Screen
Hull DomainTessellator Stage
• 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.
• 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/
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…
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.
Cg and Graphics APIs interop scheme:
3 Ways of writing shaders in Unity:
Surface shaders.
Vertex and fragment shaders.
Fixed function shaders.
Simple Custom shader:
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]
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.
Thank you!!!http://aras-p.info/blog/
http://docs.unity3d.com/Documentation/Manual/Shaders.htmlhttp://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
top related