» pixelshader_for_newbies
  • You were redirected to the new location of this resource. Please update your bookmarks.
  • You can find the old version of this document at legacy.vvvv.org.
This site relies heavily on Javascript. You should enable it if you want the full experience. Learn more.

pixelshader_for_newbies

01 Introduction

This tutorial is for newbies in the shader business and not for the pros. That means, we have a brief look at the pixelshader aspect and keep everything more or less simple.
Hopefully there is soon a tutorial for the vertex part of shader programming.
Pixelshaders are much more easy to understand than Vertexshaders, so for the beginning pixelshaders should be your choice ...

01.1 Why should I use a shader?

First it's just a performance thing: shaders are fast. these small prgramms run "independently" form the rest of your patch in your graphic card. But the main reason of course is: you can do a lot of new things!

01.2 How to insert an effect in your patch

Effect nodes/shaders are programmed in (HLSL "high level shader language") but are represented within vvvv as normal nodes. The main difference between shader nodes and other nodes is, that you can look into them by right clicking on the node. A window will open that contains the shader code.

vvvv comes preloaded with some shaders that have the extension ".fx" can be found in the "effects" directory. If you create a new effect or download one from somewhere, simply place it there. After rescanning for externals (Alt+E) they will show up in the nodelist (Middleclick in a patch window), like any other node or you can simply open in patch with (Shift+Ctrl+O).

All the shaders we do in this tutorial are based on the node "template" (guess why this node is named template) ... this node is always a good starting point to write your own shaders.

Please note: For the examples in this tutorial you need a graphic card capable of using Pixelshader Version 2.0 (PS 2.0)!

01.3 The 4 parts of an effect file

PARAMETERS // create input pins and define variabels ^^VERTEXSHADERS // vertex effects ^^PIXELSHADERS // pixelshader effects (we work mainly here in this tutorial)^^TECHNIQUES // specify PS version and technique

Some important hints before we start programming: :

  • keep the code inside the shader as short as possible eg. instead of writing if (col.r > threshold) col.r = 1,

write col.r = (col.r > threshold)

  • often it's better do to something with 2 renders and two shaders eg. it's better to do blur first horizontal then over the result an vertical blur ...

But for now: Enough theory! let's start programming our first shader!
And don't forget to share all the cool new shaders you will do!

Before you start with the tutorials, you should download package of all patches & shaders used form here:
pixelshader_for_newbies_20050922.zip

links:

just google for "morphologic filter" or "kernel filters" there are plenty sites

if you wanna post shader code in the tiki be aware:
you have to replace < with ~lt~ and > with ~gt~

greetings MrBenefit

anonymous user login

Shoutbox

18:26, 29.07.10

fibo: @dujoducom: in Genoa we are 3 of us (fibo,kalle,e1n :)

18:19, 29.07.10

rrrr: @frank totally. no need for flash, silverlight or any other plugin any more. and no other OS besides a browser in the future

17:23, 29.07.10

m4d: still waiting for higher webgl adoption..

17:16, 29.07.10

frank: @rrrr 3d-html5 stuff is awesome, isnt it?

16:41, 29.07.10

rrrr: Javascript / HTML5 canvas http://www.zynaps.com/jsl...

16:39, 29.07.10

qwas: @io me gusta mucho!

23:07, 28.07.10

io: New location and new vid for my first public project http://vimeo.com/13688082

18:07, 28.07.10

dujoducom: @u7angel don't feel bad, I'm 1 of 4 in the US :(