» EX9.HLSL.Introduction
This site relies heavily on Javascript. You should enable it if you want the full experience. Learn more.

EX9.HLSL.Introduction

French | Italian

Semantics

todo

Vectors and Swizzling

Apart from the simple datatypes like bool, int, float and double with HLSL you can use all those as vectors also, by simply writing something like:

float4 ff = {4, 3, 2, 1};
bool2 bb = {1, 0};

Now you can reach the individual vector components using swizzles, which work as suffixes to the variable names:

 .x, .y, .z, .w 

are the same as:

 .r, .g, .b, .a
float f = ff.a;     // f = 1
bool b = bb.y;      // b = 0
float2 f2 = ff.xz   // f2 = {4, 2}

Arrays

With all the basic datatypes you can also declare arrays, but note that their length is limited, depending on the constant register count of the shader profile used. You can find out about the number of allowed constants on msdn:
vs_2_0 registers
ps_2_0 registers
vs_3_0 registers
ps_3_0 registers

You can define and access arrays like the following example demonstrates:

float4 ff[2] = {{0, 1, 2, 3}, {4, 5, 6, 7}}
float4 f1 = f[0];        //f1 = {0, 1, 2, 3}
float3 f2 = f[1].rgb;    //f2 = {4, 5, 6}

Intrinsic Functions

HLSL has a small list of built-in functions. A rightclick in vvvvs shader editor pops up the list.

Functions and Includes

Besides the main vertex- and pixelshader functions you can define any number of helper functions in an effect file. If this gets too confusing functions can be outsourced into an extra textfile and linked to from any effect via the # include directive which offers 2 different usages:

//local: the referenced file is placed in the same directory as the .fx file which includes it
#include "myfunctions.fxh" 
 
//global: the filename is specified relative to vvvvs root directory
#include <effects\myfunctions.fxh>

Shader Profiles

In every technique you have to specify a shader profile with which you want the vertex- and pixelshader functions compiled. Generally speaking, the higher the profile number the more flexible it is. If your shader shows an error regarding that you are out of instructions with the currently set profile you may try one with a higher number.

Details about shader profiles and corresponding features can be found on msdn: Shader Models vs. Shader Profiles

Depending on the capabilities of your graphic card, vvvv supports the following profiles:

  • vs_1_0, ps_1_0
  • vs_1_1, ps_1_1
  • vs_2_0, ps_2_0
  • vs_2_a, ps_2_a
  • vs_2_b, ps_2_b
  • vs_3_0, ps_3_0 //note that when using vs_3_0 using ps_3_0 is mandatory in vvvv

anonymous user login

Shoutbox

~6d ago

joreg: vvvvTv S02E00 is out: Sensors & Servos with Arduino: https://visualprogramming.net/blog/2024/vvvvtv-is-back-with-season-2/

~7d ago

fleg: hey there! What's the best tool for remote work? Teamviewer feels terrible. Thanks!

~20d ago

joreg: Last call: 6-session vvvv beginner course starting November 4: https://thenodeinstitute.org/courses/ws24-5-vvvv-beginners-part-i/

~1mth ago

joreg: Missed the last meetup? You can rewatch it here: https://www.youtube.com/live/MdvTa58uxB0?si=Fwi-9hHoCmo794Ag

~1mth ago

theurbankind: When is the next big event, like node festival ?

~1mth ago

~1mth ago

joreg: Join us for the next vvvv meetup on Oktober 17th: https://visualprogramming.net/blog/2024/25.-vvvv-worldwide-meetup/

~1mth ago

joreg: 6 session beginner course part 2 "Deep Dive" starts January 13th: https://thenodeinstitute.org/courses/ws24-5-vvvv-beginners-part-ii/

~1mth ago

joreg: 6 session beginner course part 1 "Playground" starts November 4th: https://thenodeinstitute.org/courses/ws24-5-vvvv-beginners-part-i/