mirror of
https://github.com/Fechin/reference.git
synced 2026-11-22 14:01:45 +03:00
Merge remote-tracking branch 'origin/main'
This commit is contained in:
commit
84a9d5bb19
2 files changed
+657
-194
No files matched your search
+42
-42
@@ -28,7 +28,7 @@ int main(void) {
|
||||
Compile `hello.c` file with `gcc`
|
||||
|
||||
```bash
|
||||
$ gcc hello.c -o hello
|
||||
$ gcc -Wall -g hello.c -o hello
|
||||
```
|
||||
|
||||
Run the compiled binary `hello`
|
||||
@@ -78,7 +78,7 @@ const int BIRTHYEAR = 1980;
|
||||
|
||||
```c
|
||||
// this is a comment
|
||||
printf("Hello World!"); // Can comment anywhere in file
|
||||
printf("Hello World!\n"); // Can comment anywhere in file
|
||||
|
||||
/*Multi-line comment, print Hello World!
|
||||
to the screen, it's awesome */
|
||||
@@ -87,12 +87,12 @@ to the screen, it's awesome */
|
||||
### Print text
|
||||
|
||||
```c
|
||||
printf("I am learning C.");
|
||||
printf("I am learning C.\n");
|
||||
int testInteger = 5;
|
||||
printf("Number = %d", testInteger);
|
||||
printf("Number = %d\n", testInteger);
|
||||
|
||||
float f = 5.99; // floating point number
|
||||
printf("Value = %f", f);
|
||||
printf("Value = %f\n", f);
|
||||
|
||||
short a = 0b1010110; // binary number
|
||||
int b = 02713; // octal number
|
||||
@@ -183,7 +183,7 @@ printf("%s", greetings);
|
||||
```
|
||||
|
||||
**NOTE**: String literals might be stored in read-only section of memory. Modifying a string literal invokes undefined
|
||||
behavior. You can't modify it.!
|
||||
behavior. You can't modify it!
|
||||
|
||||
`C` **does not** have a String type, use `char` type and create an `array` of characters
|
||||
|
||||
@@ -192,18 +192,18 @@ behavior. You can't modify it.!
|
||||
```c
|
||||
int time = 20;
|
||||
if (time < 18) {
|
||||
printf("Goodbye!");
|
||||
printf("Goodbye!\n");
|
||||
} else {
|
||||
printf("Good evening!");
|
||||
printf("Good evening!\n");
|
||||
}
|
||||
// Output -> "Good evening!"
|
||||
int time = 22;
|
||||
if (time < 10) {
|
||||
printf("Good morning!");
|
||||
printf("Good morning!\n");
|
||||
} else if (time < 20) {
|
||||
printf("Goodbye!");
|
||||
printf("Goodbye!\n");
|
||||
} else {
|
||||
printf("Good evening!");
|
||||
printf("Good evening!\n");
|
||||
}
|
||||
// Output -> "Good evening!"
|
||||
```
|
||||
@@ -212,7 +212,7 @@ if (time < 10) {
|
||||
|
||||
```c
|
||||
int age = 20;
|
||||
(age > 19) ? printf("Adult") : printf("Teenager");
|
||||
(age > 19) ? printf("Adult\n") : printf("Teenager\n");
|
||||
```
|
||||
|
||||
### Switch
|
||||
@@ -221,10 +221,10 @@ int age = 20;
|
||||
int day = 4;
|
||||
|
||||
switch (day) {
|
||||
case 3: printf("Wednesday"); break;
|
||||
case 4: printf("Thursday"); break;
|
||||
case 3: printf("Wednesday\n"); break;
|
||||
case 4: printf("Thursday\n"); break;
|
||||
default:
|
||||
printf("Weekend!");
|
||||
printf("Weekend!\n");
|
||||
}
|
||||
// output -> "Thursday" (day 4)
|
||||
```
|
||||
@@ -403,13 +403,13 @@ switch(day) {
|
||||
int myNum;
|
||||
|
||||
// Ask the user to enter a number
|
||||
printf("Please enter a number: \n");
|
||||
printf("Enter a number: ");
|
||||
|
||||
// Get and save the number entered by the user
|
||||
scanf("%d", &myNum);
|
||||
|
||||
// Output the number entered by the user
|
||||
printf("The number you entered: %d", myNum);
|
||||
printf("The number you entered: %d\n", myNum);
|
||||
```
|
||||
|
||||
### User input string
|
||||
@@ -418,11 +418,11 @@ printf("The number you entered: %d", myNum);
|
||||
// create a string
|
||||
char firstName[30];
|
||||
// Ask the user to enter some text
|
||||
printf("Enter your name: \n");
|
||||
printf("Enter your name: ");
|
||||
// get and save the text
|
||||
scanf("%s", &firstName);
|
||||
// output text
|
||||
printf("Hello %s.", firstName);
|
||||
printf("Hello %s.\n", firstName);
|
||||
```
|
||||
|
||||
### memory address
|
||||
@@ -442,10 +442,10 @@ To access it, use the reference operator (`&`)
|
||||
|
||||
```c
|
||||
int myAge = 43; // an int variable
|
||||
printf("%d", myAge); // output the value of myAge(43)
|
||||
printf("%d\n", myAge); // output the value of myAge(43)
|
||||
|
||||
// Output the memory address of myAge (0x7ffe5367e044)
|
||||
printf("%p", &myAge);
|
||||
printf("%p\n", &myAge);
|
||||
```
|
||||
|
||||
### pointer variable {.col-span-2}
|
||||
@@ -716,12 +716,12 @@ printf("%c\n", myLetter);
|
||||
```c
|
||||
#include <stdio.h>
|
||||
|
||||
int main() {
|
||||
printf("File :%s\n", __FILE__);
|
||||
printf("Date :%s\n", __DATE__);
|
||||
printf("Time :%s\n", __TIME__);
|
||||
printf("Line :%d\n", __LINE__);
|
||||
printf("ANSI :%d\n", __STDC__);
|
||||
int main(void) {
|
||||
printf("File: %s\n", __FILE__);
|
||||
printf("Date: %s\n", __DATE__);
|
||||
printf("Time: %s\n", __TIME__);
|
||||
printf("Line: %d\n", __LINE__);
|
||||
printf("ANSI: %d\n", __STDC__);
|
||||
}
|
||||
```
|
||||
|
||||
@@ -764,7 +764,7 @@ When you need to convert a macro parameter to a string constant, use the string
|
||||
```c
|
||||
#include <stdio.h>
|
||||
|
||||
#define tokenpaster(n) printf ("token" #n " = %d", token##n)
|
||||
#define tokenpaster(n) printf ("Token " #n " = %d\n", token##n)
|
||||
|
||||
int main(void) {
|
||||
int token34 = 40;
|
||||
@@ -823,7 +823,7 @@ int main(void) {
|
||||
|
||||
```c
|
||||
int main(void) {
|
||||
printf("Hello World!");
|
||||
printf("Hello World!\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -855,7 +855,7 @@ int main() {
|
||||
}
|
||||
|
||||
void myFunction() {// Function definition
|
||||
printf("Good evening!");
|
||||
printf("Good evening!\n");
|
||||
}
|
||||
```
|
||||
|
||||
@@ -864,7 +864,7 @@ void myFunction() {// Function definition
|
||||
```c
|
||||
// create function
|
||||
void myFunction() {
|
||||
printf("Good evening!");
|
||||
printf("Good evening!\n");
|
||||
}
|
||||
|
||||
int main() {
|
||||
@@ -918,7 +918,7 @@ int myFunction(int x) {
|
||||
}
|
||||
|
||||
int main() {
|
||||
printf("Result: %d", myFunction(3));
|
||||
printf("Result: %d\n", myFunction(3));
|
||||
return 0;
|
||||
}
|
||||
// output 8 (5 + 3)
|
||||
@@ -932,10 +932,10 @@ int myFunction(int x, int y) {
|
||||
}
|
||||
|
||||
int main() {
|
||||
printf("Result: %d", myFunction(5, 3));
|
||||
printf("Result: %d\n", myFunction(5, 3));
|
||||
// store the result in a variable
|
||||
int result = myFunction(5, 3);
|
||||
printf("Result = %d", result);
|
||||
printf("Result = %d\n", result);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -950,7 +950,7 @@ int sum(int k);
|
||||
|
||||
int main() {
|
||||
int result = sum(10);
|
||||
printf("%d", result);
|
||||
printf("%d\n", result);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -970,10 +970,10 @@ int sum(int k) {
|
||||
#include <math.h>
|
||||
|
||||
void main(void) {
|
||||
printf("%f", sqrt(16)); // square root
|
||||
printf("%f", ceil(1.4)); // round up (round)
|
||||
printf("%f", floor(1.4)); // round down (round)
|
||||
printf("%f", pow(4, 3)); // x(4) to the power of y(3)
|
||||
printf("%f\n", sqrt(16)); // square root
|
||||
printf("%f\n", ceil(1.4)); // round up (round)
|
||||
printf("%f\n", floor(1.4)); // round down (round)
|
||||
printf("%f\n", pow(4, 3)); // x(4) to the power of y(3)
|
||||
}
|
||||
```
|
||||
|
||||
@@ -1028,13 +1028,13 @@ int main() {
|
||||
struct myStructure s1;
|
||||
strcpy(s1. myString, "Some text");
|
||||
// print value
|
||||
printf("my string: %s", s1.myString);
|
||||
printf("My string: %s\n", s1.myString);
|
||||
|
||||
return 0;
|
||||
}
|
||||
```
|
||||
|
||||
Assigning values to strings using the `strcpy` function
|
||||
Assigning values to strings using the `strcpy` function
|
||||
|
||||
### Accessing structure members {.row-span-2}
|
||||
|
||||
@@ -1100,7 +1100,7 @@ struct myStructure s1 = {
|
||||
s1.myNum = 30;
|
||||
s1.myLetter = 'C';
|
||||
// print value
|
||||
printf("%d %c %s",
|
||||
printf("%d %c",
|
||||
s1.myNum,
|
||||
s1.myLetter);
|
||||
```
|
||||
|
||||
+615
-152
@@ -18,339 +18,802 @@ intro: |
|
||||
|
||||
<code>We are using <yel>**SAIT**</yel> to indicate the output type is "same as the input type".</code> {.col-span-2}
|
||||
|
||||
### Basic Nodes
|
||||
## 1. Attributes {.cols-2}
|
||||
|
||||
<yel>Position</yel> - provides vertex position {.cols-2}
|
||||
### Positioning {.row-span-2}
|
||||
|
||||
<yel>**Position**</yel> - provides vertex position
|
||||
- **Inputs**
|
||||
- |-|-|
|
||||
| -------- | ---------------------- |
|
||||
| None | No inputs |
|
||||
| / | No inputs |
|
||||
|
||||
{.left-text}
|
||||
|
||||
- **Outputs**
|
||||
- |-|-|
|
||||
| -------- | ---------------------- |
|
||||
| `Vector3`| Provides vertex position|
|
||||
|
||||
{.left-text}
|
||||
|
||||
{.shortcuts .marker-round .cols-2}
|
||||
|
||||
<yel>Normal</yel> - supplies surface normal direction {.cols-2}
|
||||
<yel>**Normal**</yel> - supplies surface normal direction
|
||||
- **Inputs**
|
||||
- |-|-|
|
||||
| -------- | ---------------------- |
|
||||
| None | No inputs |
|
||||
| / | No inputs |
|
||||
|
||||
{.left-text}
|
||||
|
||||
- **Outputs**
|
||||
- |-|-|
|
||||
| -------- | ---------------------- |
|
||||
| `Vector3`| Provides surface normal |
|
||||
|
||||
{.left-text}
|
||||
|
||||
{.shortcuts .marker-round .cols-2}
|
||||
|
||||
<yel>Time</yel> - outputs time values {.cols-2}
|
||||
<yel>**World Position**</yel> - returns the object's world space position
|
||||
- **Inputs**
|
||||
- |-|-|
|
||||
| -------- | ---------------------- |
|
||||
| None | No inputs |
|
||||
| / | No inputs |
|
||||
|
||||
{.left-text}
|
||||
|
||||
- **Outputs**
|
||||
- |-|-|
|
||||
| -------- | ---------------------- |
|
||||
| `Float` | Outputs time values |
|
||||
| `Vector3` | World space position |
|
||||
|
||||
{.left-text}
|
||||
|
||||
{.shortcuts .marker-round .cols-2}
|
||||
|
||||
<yel>Multiply</yel> - multiplies two values {.cols-2}
|
||||
<yel>**Object Position**</yel> - returns the object's local space position
|
||||
- **Inputs**
|
||||
- |-|-|
|
||||
| -------- | ---------------------- |
|
||||
| `Float`, `Vector`, `Matrix` | First value |
|
||||
| `Float`, `Vector`, `Matrix` | Second value|
|
||||
| / | No inputs |
|
||||
|
||||
{.left-text}
|
||||
|
||||
- **Outputs**
|
||||
- |-|-|
|
||||
| -------- | ---------------------- |
|
||||
| SAIT | The product of the two inputs |
|
||||
| `Vector3` | Local space position |
|
||||
|
||||
{.left-text}
|
||||
|
||||
{.shortcuts .marker-round .cols-2}
|
||||
|
||||
<yel>Lerp</yel> - linear interpolation between two values {.cols-2}
|
||||
<yel>**Screen Position**</yel> - returns the object's screen space position
|
||||
- **Inputs**
|
||||
- |-|-|
|
||||
| -------- | ---------------------- |
|
||||
| `Float` | Start value |
|
||||
| `Float` | End value |
|
||||
| `Float` | Interpolation factor (T)|
|
||||
| / | No inputs |
|
||||
|
||||
{.left-text}
|
||||
|
||||
- **Outputs**
|
||||
- |-|-|
|
||||
| -------- | ---------------------- |
|
||||
| `Float` | Interpolated result |
|
||||
| `Vector4` | Screen space position |
|
||||
|
||||
{.left-text}
|
||||
|
||||
{.shortcuts .marker-round .cols-2}
|
||||
|
||||
<yel>Step</yel> - creates a step between two thresholds {.cols-2}
|
||||
<yel>**Camera Position**</yel> - returns the camera's world space position
|
||||
- **Inputs**
|
||||
- |-|-|
|
||||
| -------- | ---------------------- |
|
||||
| `Float` | Threshold |
|
||||
| `Float` | Input |
|
||||
| / | No inputs |
|
||||
|
||||
{.left-text}
|
||||
|
||||
- **Outputs**
|
||||
- |-|-|
|
||||
| -------- | ---------------------- |
|
||||
| `Float` | Step result |
|
||||
| `Vector3` | Camera world space position |
|
||||
|
||||
{.left-text}
|
||||
|
||||
{.shortcuts .marker-round .cols-2}
|
||||
|
||||
### Math Nodes
|
||||
### Timing
|
||||
|
||||
<yel>Add</yel> - adds two values {.cols-2}
|
||||
<yel>**Time**</yel> - outputs various time-related values
|
||||
- **Inputs**
|
||||
- |-|-|
|
||||
| -------- | ---------------------- |
|
||||
| `Float` or `Vector` | First value |
|
||||
| `Float` or `Vector` | Second value |
|
||||
| / | No inputs |
|
||||
|
||||
{.left-text}
|
||||
|
||||
- **Outputs**
|
||||
- |-|-|
|
||||
| -------- | ---------------------- |
|
||||
| `Float` | Time (T) - The total elapsed time since the start of the shader |
|
||||
| `Float` | Sin Time (T/8π) - A sine wave based on time |
|
||||
| `Float` | Cos Time (T/8π) - A cosine wave based on time |
|
||||
| `Float` | Delta Time - Time passed between the previous frame and the current frame |
|
||||
|
||||
{.left-text}
|
||||
|
||||
{.shortcuts .marker-round .cols-2}
|
||||
|
||||
|
||||
## 2. Math Operations {.cols-2}
|
||||
|
||||
### Basic Math
|
||||
|
||||
<yel>**Add**</yel> - adds two values
|
||||
- **Inputs**
|
||||
- |-|-|
|
||||
| -------- | ---------------------- |
|
||||
| `Float` <br> `Vector` | First value |
|
||||
| `Float` <br> `Vector` | Second value |
|
||||
|
||||
{.left-text}
|
||||
|
||||
- **Outputs**
|
||||
- |-|-|
|
||||
| -------- | ---------------------- |
|
||||
| SAIT | Sum of the two inputs |
|
||||
|
||||
{.left-text}
|
||||
|
||||
{.shortcuts .marker-round .cols-2}
|
||||
|
||||
<yel>Subtract</yel> - subtracts one value from another {.cols-2}
|
||||
<yel>**Subtract**</yel> - subtracts one value from another
|
||||
- **Inputs**
|
||||
- |-|-|
|
||||
| -------- | ---------------------- |
|
||||
| `Float` or `Vector` | Minuend |
|
||||
| `Float` or `Vector` | Subtrahend |
|
||||
| `Float` <br> `Vector` | Minuend |
|
||||
| `Float` <br> `Vector` | Subtrahend |
|
||||
|
||||
{.left-text}
|
||||
|
||||
- **Outputs**
|
||||
- |-|-|
|
||||
| -------- | ---------------------- |
|
||||
| SAIT | Difference of the two inputs |
|
||||
|
||||
{.left-text}
|
||||
|
||||
{.shortcuts .marker-round .cols-2}
|
||||
|
||||
<yel>Sin</yel> - outputs sine of input {.cols-2}
|
||||
<yel>**Multiply**</yel> - multiplies two values
|
||||
- **Inputs**
|
||||
- |-|-|
|
||||
| -------- | ---------------------- |
|
||||
| `Float` | Input in radians |
|
||||
| `Float` <br> `Vector` <br> `Matrix` | First value |
|
||||
| `Float` <br> `Vector` <br> `Matrix` | Second value|
|
||||
|
||||
{.left-text}
|
||||
|
||||
- **Outputs**
|
||||
- |-|-|
|
||||
| -------- | ---------------------- |
|
||||
| `Float` | Sine of the input |
|
||||
| SAIT | The product of the two inputs |
|
||||
|
||||
{.left-text}
|
||||
|
||||
{.shortcuts .marker-round .cols-2}
|
||||
|
||||
<yel>Cos</yel> - outputs cosine of input {.cols-2}
|
||||
- **Inputs**
|
||||
- |-|-|
|
||||
| -------- | ---------------------- |
|
||||
| `Float` | Input in radians |
|
||||
- **Outputs**
|
||||
- |-|-|
|
||||
| -------- | ---------------------- |
|
||||
| `Float` | Cosine of the input |
|
||||
{.shortcuts .marker-round .cols-2}
|
||||
### Advanced Math {.row-span-2}
|
||||
|
||||
<yel>Power</yel> - raises input to a power {.cols-2}
|
||||
<yel>**Power**</yel> - raises input to a power
|
||||
- **Inputs**
|
||||
- |-|-|
|
||||
| -------- | ---------------------- |
|
||||
| `Float` | Base |
|
||||
| `Float` | Exponent |
|
||||
|
||||
{.left-text}
|
||||
|
||||
- **Outputs**
|
||||
- |-|-|
|
||||
| -------- | ---------------------- |
|
||||
| `Float` | Result of base raised to the power of the exponent |
|
||||
|
||||
{.left-text}
|
||||
|
||||
{.shortcuts .marker-round .cols-2}
|
||||
|
||||
<yel>Sqrt</yel> - square root of input {.cols-2}
|
||||
<yel>**Sqrt**</yel> - square root of input
|
||||
- **Inputs**
|
||||
- |-|-|
|
||||
| -------- | ---------------------- |
|
||||
| `Float` | Input value |
|
||||
|
||||
{.left-text}
|
||||
|
||||
- **Outputs**
|
||||
- |-|-|
|
||||
| -------- | ---------------------- |
|
||||
| `Float` | Square root of the input |
|
||||
|
||||
{.left-text}
|
||||
|
||||
{.shortcuts .marker-round .cols-2}
|
||||
|
||||
<yel>Abs</yel> - outputs absolute value {.cols-2}
|
||||
<yel>**Abs**</yel> - outputs absolute value
|
||||
- **Inputs**
|
||||
- |-|-|
|
||||
| -------- | ---------------------- |
|
||||
| `Float` or `Vector` | Input value |
|
||||
| `Float` <br> `Vector` | Input value |
|
||||
|
||||
{.left-text}
|
||||
|
||||
- **Outputs**
|
||||
- |-|-|
|
||||
| -------- | ---------------------- |
|
||||
| SAIT | Absolute value of the input |
|
||||
|
||||
{.left-text}
|
||||
|
||||
{.shortcuts .marker-round .cols-2}
|
||||
|
||||
|
||||
|
||||
### Texture Nodes
|
||||
|
||||
<yel>Sample Texture</yel> - retrieves color data from texture {.cols-2}
|
||||
<yel>**Dot Product**</yel> - calculates dot product between two vectors
|
||||
- **Inputs**
|
||||
- |-|-|
|
||||
| -------- | ---------------------- |
|
||||
| Texture (sampler) | Texture input |
|
||||
| `Vector3` <br> `Vector4` | First vector |
|
||||
| `Vector3` <br> `Vector4` | Second vector|
|
||||
|
||||
{.left-text}
|
||||
|
||||
- **Outputs**
|
||||
- |-|-|
|
||||
| -------- | ---------------------- |
|
||||
|`Float` | Dot product result |
|
||||
|
||||
{.left-text}
|
||||
|
||||
{.shortcuts .marker-round .cols-2}
|
||||
|
||||
<yel>**Cross Product**</yel> - calculates cross product between two vectors
|
||||
- **Inputs**
|
||||
- |-|-|
|
||||
| -------- | ---------------------- |
|
||||
| `Vector3` | First vector |
|
||||
| `Vector3` | Second vector |
|
||||
|
||||
{.left-text}
|
||||
|
||||
- **Outputs**
|
||||
- |-|-|
|
||||
| -------- | ---------------------- |
|
||||
| `Vector3` | Cross product result |
|
||||
|
||||
{.left-text}
|
||||
|
||||
{.shortcuts .marker-round .cols-2}
|
||||
|
||||
### Trigonometry
|
||||
|
||||
<yel>**Sin**</yel> - outputs sine of input
|
||||
- **Inputs**
|
||||
- |-|-|
|
||||
| -------- | ---------------------- |
|
||||
| `Float` | Input in radians |
|
||||
|
||||
{.left-text}
|
||||
|
||||
- **Outputs**
|
||||
- |-|-|
|
||||
| -------- | ---------------------- |
|
||||
| `Float` | Sine of the input |
|
||||
|
||||
{.left-text}
|
||||
|
||||
{.shortcuts .marker-round .cols-2}
|
||||
|
||||
<yel>**Cos**</yel> - outputs cosine of input
|
||||
- **Inputs**
|
||||
- |-|-|
|
||||
| -------- | ---------------------- |
|
||||
| `Float` | Input in radians |
|
||||
|
||||
{.left-text}
|
||||
|
||||
- **Outputs**
|
||||
- |-|-|
|
||||
| -------- | ---------------------- |
|
||||
| `Float` | Cosine of the input |
|
||||
|
||||
{.left-text}
|
||||
|
||||
{.shortcuts .marker-round .cols-2}
|
||||
|
||||
### Interpolation {.row-span-2}
|
||||
|
||||
<yel>**Lerp**</yel> - linear interpolation between two values
|
||||
- **Inputs**
|
||||
- |-|-|
|
||||
| -------- | ---------------------- |
|
||||
| `Float` <br> `Vector` | Start value |
|
||||
| `Float` <br> `Vector` | End value |
|
||||
| `Float` <br> `Vector` | Interpolation factor (T)|
|
||||
|
||||
{.left-text}
|
||||
|
||||
- **Outputs**
|
||||
- |-|-|
|
||||
| -------- | ---------------------- |
|
||||
| SAIT | Interpolated result |
|
||||
|
||||
{.left-text}
|
||||
|
||||
{.shortcuts .marker-round .cols-2}
|
||||
|
||||
<yel>**Step**</yel> - creates a step between two thresholds
|
||||
- **Inputs**
|
||||
- |-|-|
|
||||
| -------- | ---------------------- |
|
||||
| `Float` <br> `Vector` | Threshold |
|
||||
| `Float` <br> `Vector` | Input |
|
||||
|
||||
{.left-text}
|
||||
|
||||
- **Outputs**
|
||||
- |-|-|
|
||||
| -------- | ---------------------- |
|
||||
| SAIT | Step result |
|
||||
|
||||
{.left-text}
|
||||
|
||||
{.shortcuts .marker-round .cols-2}
|
||||
|
||||
|
||||
## 3. Color Processing {.cols-2}
|
||||
|
||||
### Basic Color Manipulation
|
||||
|
||||
<yel>**Color**</yel> - provides a constant color value
|
||||
- **Inputs**
|
||||
- |-|-|
|
||||
| -------- | ---------------------- |
|
||||
| / | No inputs |
|
||||
|
||||
{.left-text}
|
||||
|
||||
- **Outputs**
|
||||
- |-|-|
|
||||
| -------- | ---------------------- |
|
||||
| `Vector4` | RGBA color value |
|
||||
|
||||
{.left-text}
|
||||
|
||||
{.shortcuts .marker-round .cols-2}
|
||||
|
||||
<yel>**Add Color**</yel> - adds two color values
|
||||
- **Inputs**
|
||||
- |-|-|
|
||||
| -------- | ---------------------- |
|
||||
| `Vector4` | First color |
|
||||
| `Vector4` | Second color |
|
||||
|
||||
{.left-text}
|
||||
|
||||
- **Outputs**
|
||||
- |-|-|
|
||||
| -------- | ---------------------- |
|
||||
| `Vector4` | Sum of the two colors |
|
||||
|
||||
{.left-text}
|
||||
|
||||
{.shortcuts .marker-round .cols-2}
|
||||
|
||||
<yel>**Multiply Color**</yel> - multiplies two color values
|
||||
- **Inputs**
|
||||
- |-|-|
|
||||
| -------- | ---------------------- |
|
||||
| `Vector4` | First color |
|
||||
| `Vector4` | Second color |
|
||||
|
||||
{.left-text}
|
||||
|
||||
- **Outputs**
|
||||
- |-|-|
|
||||
| -------- | ---------------------- |
|
||||
| `Vector4` | Product of the two colors |
|
||||
|
||||
{.left-text}
|
||||
|
||||
{.shortcuts .marker-round .cols-2}
|
||||
|
||||
<yel>**Lerp Color**</yel> - interpolates between two colors
|
||||
- **Inputs**
|
||||
- |-|-|
|
||||
| -------- | ---------------------- |
|
||||
| `Vector4` | Start color |
|
||||
| `Vector4` | End color |
|
||||
| `Float` | Interpolation factor (T)|
|
||||
|
||||
{.left-text}
|
||||
|
||||
- **Outputs**
|
||||
- |-|-|
|
||||
| -------- | ---------------------- |
|
||||
| `Vector4` | Interpolated color |
|
||||
|
||||
{.left-text}
|
||||
|
||||
{.shortcuts .marker-round .cols-2}
|
||||
|
||||
### Color Adjustment {.row-span-2}
|
||||
|
||||
<yel>**Saturation**</yel> - adjusts the saturation of input color
|
||||
- **Inputs**
|
||||
- |-|-|
|
||||
| -------- | ---------------------- |
|
||||
| `Vector4` | Input color |
|
||||
| `Float` | Saturation factor |
|
||||
|
||||
{.left-text}
|
||||
|
||||
- **Outputs**
|
||||
- |-|-|
|
||||
| -------- | ---------------------- |
|
||||
| `Vector4` | Adjusted color |
|
||||
|
||||
{.left-text}
|
||||
|
||||
{.shortcuts .marker-round .cols-2}
|
||||
|
||||
<yel>**Contrast**</yel> - adjusts contrast of input color
|
||||
- **Inputs**
|
||||
- |-|-|
|
||||
| -------- | ---------------------- |
|
||||
| `Vector4` | Input color |
|
||||
| `Float` | Contrast factor |
|
||||
|
||||
{.left-text}
|
||||
|
||||
- **Outputs**
|
||||
- |-|-|
|
||||
| -------- | ---------------------- |
|
||||
| `Vector4` | Adjusted color |
|
||||
|
||||
{.left-text}
|
||||
|
||||
{.shortcuts .marker-round .cols-2}
|
||||
|
||||
<yel>**Hue**</yel> - shifts the hue of the input color
|
||||
- **Inputs**
|
||||
- |-|-|
|
||||
| -------- | ---------------------- |
|
||||
| `Vector4` | Input color |
|
||||
| `Float` | Hue shift amount |
|
||||
|
||||
{.left-text}
|
||||
|
||||
- **Outputs**
|
||||
- |-|-|
|
||||
| -------- | ---------------------- |
|
||||
| `Vector4` | Color with shifted hue |
|
||||
|
||||
{.left-text}
|
||||
|
||||
{.shortcuts .marker-round .cols-2}
|
||||
|
||||
<yel>**Invert Colors**</yel> - inverts the input color
|
||||
- **Inputs**
|
||||
- |-|-|
|
||||
| -------- | ---------------------- |
|
||||
| `Vector4` | Input color |
|
||||
|
||||
{.left-text}
|
||||
|
||||
- **Outputs**
|
||||
- |-|-|
|
||||
| -------- | ---------------------- |
|
||||
| `Vector4` | Inverted color |
|
||||
|
||||
{.left-text}
|
||||
|
||||
{.shortcuts .marker-round .cols-2}
|
||||
|
||||
<yel>**Replace Color**</yel> - replaces a specific color in the input with a new color
|
||||
- **Inputs**
|
||||
- |-|-|
|
||||
| -------- | ---------------------- |
|
||||
| `Vector4` | Input color |
|
||||
| `Vector4` | Target color |
|
||||
| `Vector4` | Replacement color |
|
||||
|
||||
{.left-text}
|
||||
|
||||
- **Outputs**
|
||||
- |-|-|
|
||||
| -------- | ---------------------- |
|
||||
| `Vector4` | Color with replaced values |
|
||||
|
||||
{.left-text}
|
||||
|
||||
{.shortcuts .marker-round .cols-2}
|
||||
|
||||
<yel>**White Balance**</yel> - adjusts the white balance of input color
|
||||
- **Inputs**
|
||||
- |-|-|
|
||||
| -------- | ---------------------- |
|
||||
| `Vector4` | Input color |
|
||||
| `Float` | Temperature value |
|
||||
| `Float` | Tint value |
|
||||
|
||||
{.left-text}
|
||||
|
||||
- **Outputs**
|
||||
- |-|-|
|
||||
| -------- | ---------------------- |
|
||||
| `Vector4` | Adjusted color |
|
||||
|
||||
{.left-text}
|
||||
|
||||
{.shortcuts .marker-round .cols-2}
|
||||
|
||||
### Channel Operations
|
||||
|
||||
<yel>**Channel Mixer**</yel> - modifies color channels independently
|
||||
- **Inputs**
|
||||
- |-|-|
|
||||
| -------- | ---------------------- |
|
||||
| `Vector4` | Input color |
|
||||
| `Float` | Red channel multiplier |
|
||||
| `Float` | Green channel multiplier |
|
||||
| `Float` | Blue channel multiplier |
|
||||
|
||||
{.left-text}
|
||||
|
||||
- **Outputs**
|
||||
- |-|-|
|
||||
| -------- | ---------------------- |
|
||||
| `Vector4` | Modified color |
|
||||
|
||||
{.left-text}
|
||||
|
||||
{.shortcuts .marker-round .cols-2}
|
||||
|
||||
## 4. Texture Processing {.cols-2}
|
||||
|
||||
### Sampling
|
||||
|
||||
<yel>**Sample Texture**</yel> - retrieves color data from texture
|
||||
- **Inputs**
|
||||
- |-|-|
|
||||
| -------- | ---------------------- |
|
||||
| `Texture (sampler)` | Texture input |
|
||||
| `Vector2` | UV coordinates |
|
||||
|
||||
{.left-text}
|
||||
|
||||
- **Outputs**
|
||||
- |-|-|
|
||||
| -------- | ---------------------- |
|
||||
| `Vector4` | Color data from the texture |
|
||||
|
||||
{.left-text}
|
||||
|
||||
{.shortcuts .marker-round .cols-2}
|
||||
|
||||
<yel>UV</yel> - provides UV coordinates for texture mapping {.cols-2}
|
||||
<yel>**UV**</yel> - provides UV coordinates for texture mapping
|
||||
- **Inputs**
|
||||
- |-|-|
|
||||
| -------- | ---------------------- |
|
||||
| None | No inputs |
|
||||
| / | No inputs |
|
||||
|
||||
{.left-text}
|
||||
|
||||
- **Outputs**
|
||||
- |-|-|
|
||||
| -------- | ---------------------- |
|
||||
| `Vector2` | UV coordinates |
|
||||
|
||||
{.left-text}
|
||||
|
||||
{.shortcuts .marker-round .cols-2}
|
||||
|
||||
<yel>Tiling Offset</yel> - adjusts tiling and offset of texture {.cols-2}
|
||||
### Manipulation {.row-span-2}
|
||||
|
||||
<yel>**Tiling Offset**</yel> - adjusts tiling and offset of texture
|
||||
- **Inputs**
|
||||
- |-|-|
|
||||
| -------- | ---------------------- |
|
||||
| `Vector2` | Tiling values |
|
||||
| `Vector2` | Offset values |
|
||||
|
||||
{.left-text}
|
||||
|
||||
- **Outputs**
|
||||
- |-|-|
|
||||
| -------- | ---------------------- |
|
||||
| `Vector2` | Modified UV coordinates |
|
||||
|
||||
{.left-text}
|
||||
|
||||
{.shortcuts .marker-round .cols-2}
|
||||
|
||||
|
||||
|
||||
### Effects Nodes
|
||||
|
||||
<yel>Fresnel Effect</yel> - creates a glow effect on object edges {.cols-2}
|
||||
- **Inputs**
|
||||
- |-|-|
|
||||
| -------- | ---------------------- |
|
||||
| `Vector3` | View direction |
|
||||
| `Float` | Power of the effect |
|
||||
- **Outputs**
|
||||
- |-|-|
|
||||
| -------- | ---------------------- |
|
||||
| `Float` | Fresnel effect value |
|
||||
{.shortcuts .marker-round .cols-2}
|
||||
|
||||
<yel>Dissolve</yel> - generates a dissolve transition effect {.cols-2}
|
||||
- **Inputs**
|
||||
- |-|-|
|
||||
| -------- | ---------------------- |
|
||||
| Texture (sampler) | Input texture |
|
||||
| `Float` | Dissolve threshold |
|
||||
- **Outputs**
|
||||
- |-|-|
|
||||
| -------- | ---------------------- |
|
||||
| `Vector4` | Dissolve effect output |
|
||||
{.shortcuts .marker-round .cols-2}
|
||||
|
||||
<yel>Distortion</yel> - warps the surface of the object {.cols-2}
|
||||
<yel>**Distortion**</yel> - warps the surface of the object
|
||||
- **Inputs**
|
||||
- |-|-|
|
||||
| -------- | ---------------------- |
|
||||
| `Float` | Distortion strength |
|
||||
| `Vector2` | UV coordinates |
|
||||
|
||||
{.left-text}
|
||||
|
||||
- **Outputs**
|
||||
- |-|-|
|
||||
| -------- | ---------------------- |
|
||||
| `Vector2` | Warped UV coordinates |
|
||||
|
||||
{.left-text}
|
||||
|
||||
{.shortcuts .marker-round .cols-2}
|
||||
|
||||
<yel>Reflection</yel> - reflects based on surface normal direction {.cols-2}
|
||||
- **Inputs**
|
||||
- |-|-|
|
||||
| -------- | ---------------------- |
|
||||
| `Vector3` | Incident direction |
|
||||
| `Vector3` | Surface normal |
|
||||
- **Outputs**
|
||||
- |-|-|
|
||||
| -------- | ---------------------- |
|
||||
| `Vector3` | Reflected direction |
|
||||
{.shortcuts .marker-round .cols-2}
|
||||
|
||||
|
||||
|
||||
### Advanced Nodes
|
||||
|
||||
<yel>World Position</yel> - returns the object's world space position {.cols-2}
|
||||
- **Inputs**
|
||||
- |-|-|
|
||||
| -------- | ---------------------- |
|
||||
| None | No inputs |
|
||||
- **Outputs**
|
||||
- |-|-|
|
||||
| -------- | ---------------------- |
|
||||
| `Vector3` | World space position |
|
||||
{.shortcuts .marker-round .cols-2}
|
||||
|
||||
<yel>Object Position</yel> - returns the object's local space position {.cols-2}
|
||||
- **Inputs**
|
||||
- |-|-|
|
||||
| -------- | ---------------------- |
|
||||
| None | No inputs |
|
||||
- **Outputs**
|
||||
- |-|-|
|
||||
| -------- | ---------------------- |
|
||||
| `Vector3` | Local space position |
|
||||
{.shortcuts .marker-round .cols-2}
|
||||
|
||||
<yel>Screen Position</yel> - returns the object's screen space position {.cols-2}
|
||||
- **Inputs**
|
||||
- |-|-|
|
||||
| -------- | ---------------------- |
|
||||
| None | No inputs |
|
||||
- **Outputs**
|
||||
- |-|-|
|
||||
| -------- | ---------------------- |
|
||||
| `Vector4` | Screen space position |
|
||||
{.shortcuts .marker-round .cols-2}
|
||||
|
||||
<yel>Parallax</yel> - simulates depth using parallax mapping {.cols-2}
|
||||
<yel>**Parallax**</yel> - simulates depth using parallax mapping
|
||||
- **Inputs**
|
||||
- |-|-|
|
||||
| -------- | ---------------------- |
|
||||
| Texture (sampler) | Input texture |
|
||||
| `Vector2` | UV coordinates |
|
||||
| `Float` | Depth value |
|
||||
|
||||
{.left-text}
|
||||
|
||||
- **Outputs**
|
||||
- |-|-|
|
||||
| -------- | ---------------------- |
|
||||
| `Vector2` | Adjusted UV coordinates|
|
||||
|
||||
{.left-text}
|
||||
|
||||
{.shortcuts .marker-round .cols-2}
|
||||
|
||||
<yel>Camera Position</yel> - returns the camera's world space position {.cols-2}
|
||||
## 5. Effects {.cols-2}
|
||||
|
||||
### Visual Effects {.row-span-2}
|
||||
|
||||
<yel>**Fresnel Effect**</yel> - creates a glow effect on object edges
|
||||
- **Inputs**
|
||||
- |-|-|
|
||||
| -------- | ---------------------- |
|
||||
| None | No inputs |
|
||||
| `Vector3` | View direction |
|
||||
| `Float` | Power of the effect |
|
||||
|
||||
{.left-text}
|
||||
|
||||
- **Outputs**
|
||||
- |-|-|
|
||||
| -------- | ---------------------- |
|
||||
| `Vector3` | Camera world space position |
|
||||
| `Float` | Fresnel effect value |
|
||||
|
||||
{.left-text}
|
||||
|
||||
{.shortcuts .marker-round .cols-2}
|
||||
|
||||
<yel>**Dissolve**</yel> - generates a dissolve transition effect
|
||||
|
||||
- **Inputs**
|
||||
- |-|-|
|
||||
| -------- | ---------------------- |
|
||||
| `Texture (sampler)` | Input texture |
|
||||
| `Float` | Dissolve threshold |
|
||||
|
||||
{.left-text}
|
||||
|
||||
- **Outputs**
|
||||
- |-|-|
|
||||
| -------- | ---------------------- |
|
||||
| `Vector4` | Dissolve effect output |
|
||||
|
||||
{.left-text}
|
||||
|
||||
{.shortcuts .marker-round .cols-2}
|
||||
|
||||
### Reflection {.row-span-2}
|
||||
|
||||
<yel>**Reflection**</yel> - reflects based on surface normal direction
|
||||
- **Inputs**
|
||||
- |-|-|
|
||||
| -------- | ---------------------- |
|
||||
| `Vector3` | Incident direction |
|
||||
| `Vector3` | Surface normal |
|
||||
|
||||
{.left-text}
|
||||
|
||||
- **Outputs**
|
||||
- |-|-|
|
||||
| -------- | ---------------------- |
|
||||
| `Vector3` | Reflected direction |
|
||||
|
||||
{.left-text}
|
||||
|
||||
{.shortcuts .marker-round .cols-2}
|
||||
|
||||
|
||||
### Custom Function Node
|
||||
|
||||
#### Steps to Create a Custom Function Node:
|
||||
## Custom Function Node
|
||||
|
||||
- **Add Custom Function Node**
|
||||
### Steps to Create a Custom Function Node {.col-span-2}
|
||||
|
||||
- **Step 1: Add Custom Function Node in Shader Graph**
|
||||
|
||||
- Right-click in Shader Graph and choose **"Create Node"** > **"Custom Function"**.
|
||||
- Choose between **"String"** (for inline HLSL code) or **"File"** (for an external HLSL file).
|
||||
|
||||
- **Configure the Node**
|
||||
- Set a name and choose between **"String"** (inline code) or **"File"** (external HLSL file).
|
||||
- **Step 2: Configure the Node in Shader Graph**
|
||||
- Set the name of the node.
|
||||
- If using **"File"**, ensure the external HLSL file name exactly matches the function name defined in the HLSL file. This ensures the function is correctly referenced in the Shader Graph pipeline.
|
||||
|
||||
<yel>**Example**</yel>: If the file is named `CustomFunction.hlsl`, the function inside it should also be named `CustomFunction`.
|
||||
|
||||
- **Add Inputs/Outputs**: Define inputs (e.g., float, vector) and outputs. Example:
|
||||
- **Inputs**: Float (time), Vector3 (position)
|
||||
- **Outputs**: Vector3 (new position)
|
||||
- **Step 3: Add Inputs/Outputs in Shader Graph**
|
||||
- Define the required `Inputs` and `Outputs` for the custom function in Shader Graph. These will automatically generate ports for you to connect other nodes.
|
||||
|
||||
<yel>**Example**</yel>:
|
||||
- **Inputs**: `Float` (time), `Vector3` (position)
|
||||
- **Outputs**: `Vector3` (new position)
|
||||
|
||||
In the custom HLSL code, the `in` and `out` parameters correspond to these inputs and outputs:
|
||||
- `in` represents the data coming into the function (e.g., `time`, `position`).
|
||||
- `out` defines the return value (e.g., modified `position`).
|
||||
|
||||
- **Write Shader Code**: Enter the custom HLSL code. Example:
|
||||
- **Step 4: Write HLSL Code**
|
||||
|
||||
```hlsl
|
||||
float3 CustomPosition(float time, float3 position) {
|
||||
return position + float3(sin(time), cos(time), 0.0);
|
||||
}
|
||||
```
|
||||
- If using the **"String"** option:
|
||||
- Directly write the HLSL code inside the custom function node editor in Shader Graph.
|
||||
- Ensure that the `in` and `out` parameters match the inputs and outputs you defined in Shader Graph.
|
||||
|
||||
- **Use the Node**: Integrate the custom node into your shader graph.
|
||||
- <yel>**Example of inline code**</yel> (using **"String"** mode):
|
||||
|
||||
```cpp
|
||||
float3 CustomPosition(in float time, in float3 position, out float3 newPosition) {
|
||||
newPosition = position + float3(sin(time), cos(time), 0.0);
|
||||
return newPosition;
|
||||
}
|
||||
```
|
||||
|
||||
- If using the **"File"** option:
|
||||
- Write the HLSL code in an external `.hlsl` file and reference the file in Shader Graph.
|
||||
|
||||
- <yel>**Example of an external HLSL file**</yel> (using **"File"** mode):
|
||||
|
||||
1. **1. Create an HLSL file** named `CustomPosition.hlsl`.
|
||||
|
||||
2. **2. Write the custom function** inside the file. The `in` and `out` parameters should match the Shader Graph inputs and outputs.
|
||||
|
||||
```cpp
|
||||
float3 CustomPosition(in float time, in float3 position, out float3 newPosition) {
|
||||
newPosition = position + float3(sin(time), cos(time), 0.0);
|
||||
return newPosition;
|
||||
}
|
||||
```
|
||||
|
||||
3. **3. Save the file** in your project directory, for example, `Assets/Shaders/CustomPosition.hlsl`.
|
||||
|
||||
4. **4. Link the file** in Shader Graph:
|
||||
- In the Custom Function Node, switch to **"File"** mode and reference `CustomPosition.hlsl`.
|
||||
|
||||
- **Step 5: Use the Node in Shader Graph**
|
||||
- Connect the custom function node’s input ports to other nodes, such as `Time` and `Position`, to feed data into the custom function.
|
||||
- Connect the output port to apply the function result in the Shader Graph pipeline.
|
||||
|
||||
- <yel>**Example Pipeline**</yel>:
|
||||
|
||||
- **Inputs**: `Time` (as a float) and `Position` (as a vector)
|
||||
- **Outputs**: `Modified Position` (vector with new position)
|
||||
|
||||
This would make the custom node update an object's position based on time in the shader.
|
||||
|
||||
{.marker-timeline .shortcuts}
|
||||
|
||||
{.marker-timeline}
|
||||
|
||||
## Also see {.cols-1}
|
||||
|
||||
|
||||
Reference in new issue
Block a user