• Stars
    star
    107
  • Rank 323,587 (Top 7 %)
  • Language
    C++
  • Created over 11 years ago
  • Updated about 4 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

shadertoy-dx11 is inspired by www.shadertoy.com

This project is duplicated, please check flow


shadertoy-dx11

Introduction

shadertoy-dx11 is inspired by www.shadertoy.com

ShaderToy is such an amazing website, I enjoy learning from the fabulous shaders.
In daily work, I care more about Hlsl, which is the shader language for Microsoft Direct3D API. So it would be nice for me to have a standalone Hlsl version of ShaderToy. Certainly it won't run in a browser since there is no WebD3D :)

Basic

The usage is quite straightforward:

./bin/shadertoy-dx11.exe ./samples/HelloWorld.toy

Take HelloWorld.hlsl as an example, which does nothing except showing textures[0] aka "photo_4.jpg" on screen.

// demonstrate the use of local image
// photo_4.jpg
// ducky.png
 
float4 main(float4 pos : SV_POSITION) : SV_Target
{
    float4 clr0 = textures[0].Sample( smooth, pos.xy / resolution );
    float4 clr1 = textures[1].Sample( blocky, pos.xy / resolution );

    return lerp(clr0, clr1, mouse.x / resolution.x);
}

screenshot

If you have previous experience with Hlsl coding, then you must be wondering WTF is smooth and blocky. And how can be photo_4.jpg and ducky.png reference by textures[0] and textures[1]?

Take it easy, the secret behind is that following lines are automatilly added to the shader you write:

Texture2D backbuffer : register( t0 );
Texture2D textures[#n] : register( t1 ); // the exact number of #n is automatically calculated by the shadertoy-dx11

SamplerState smooth : register( s0 );
SamplerState blocky : register( s1 );
SamplerState mirror : register( s2 );

cbuffer CBOneFrame : register( b0 )
{
    float2     resolution;     // viewport resolution (in pixels)
    float      time;           // shader playback time (in seconds)
    float      aspect;         // cached aspect of viewport
    float4     mouse;          // mouse pixel coords. xy: current (if MLB down), zw: click (TODO:)
    float4     date;           // (year, month, day, time in seconds) (TODO:)
};

Advanced

shadertoy-dx11 turns various input source into texture:

  • relative image path, as // photo_4.jpg.
  • absolute image path, as // C:/photo_4.jpg.
  • image on Internet, as // https://f.cloud.github.com/assets/558657/590903/5b36a0e0-c9f3-11e2-93f0-743a1469c0d9.png, also refer to samplers/HelloWorldUrl.toy.
  • physical camera devices, as // camera, also refer to samplers/HelloWorldCamera.toy.

More Repositories

1

awesome-vulkan

Awesome Vulkan ecosystem
2,918
star
2

perf-doctor

性能医生, a mobile game profiler.
Python
344
star
3

opencv-2-cookbook-src

《OpenCV 2 计算机视觉编程手册》 配套代码,支持 OpenCV 3.x / 4.x
C++
215
star
4

awesome-d3d12

Awesome D3D12 ecosystem
202
star
5

pkg-doctor

包体医生,Unity 及 Unreal 游戏包体优化工具
C#
172
star
6

awesome-rtx

Curated collection of projects leveraging NVIDIA RTX technology (OptiX, DXR, VKR)
78
star
7

render-doctor

渲染医生,基于 RenderDoc 的渲染分析工具,以 html 形式展现方便阅读和分享。
Python
63
star
8

hudo.it

hudo.it
50
star
9

learn-raytracing

to make smallpt bigger
C++
45
star
10

GpuProf

Realtime GPU Profiler for AMD / NVIDIA / Intel GPUs
JavaScript
28
star
11

vgfx

Vinjn's Low-level wrapper of Direct3D12 / Vulkan
C++
21
star
12

chihuahua

🐶chihuahua - tiny & fast rendering library
C++
13
star
13

renderdoc-frame-reporter

https://vinjn.github.io/renderdoc-frame-reporter/
HTML
12
star
14

injector

C
10
star
15

articles

Everything is possible
C++
8
star
16

one-minute-omniverse

Tutorials on Omniverse
PowerShell
7
star
17

WinTools

Tools to improve vinjn's Windows experience
C++
4
star
18

slides

基于 markdown 的演讲稿
JavaScript
4
star
19

rdc-script

Scripts to inspect renderdoc capture files (*.rdc)
Python
4
star
20

Pixar128-Library

3
star
21

vinjn

2
star
22

vulkan-layers

2
star
23

CinderBgfx

C++
2
star
24

net-doctor

Python
1
star
25

mad

Native markdown editor for document & slides
JavaScript
1
star
26

RenderdocManager

C
1
star
27

android-survival-kit.cpp

It's hard for a C++ engineer to survive in Android, let me help you.
C++
1
star
28

Island

C++
1
star
29

swim-agent

Python
1
star