The MASM Forum

General => The Laboratory => Topic started by: Siekmanski on February 07, 2018, 09:23:15 AM

Title: Fun with Pixel Shaders and maths
Post by: Siekmanski on February 07, 2018, 09:23:15 AM
These are my first steps into the world of Pixel Shaders.
Suggestions and/or remarks are always welcome.

My goal was to use pixel shaders in Direct3D9.
Unfortunately d3d9.dll ( which is standard present on all windows operating systems from 2003 till now ) doesn't have a shader compiler function.
The fully functional DirectX9 shader compiler function for shader version 3.0 is available in the wrapper libs D3DX9_32.dll up to D3DX9_43.dll.

So I programmed a small ShaderCompiler program that searches if one of the 12 D3DX9_xx.dlls is available on the developers computer and calls the compiler function by using "LoadLibrary" and "GetProcAddress".
The compiled pixel shader code can be saved as pre-compiled GPU code.

The pre-compiled GPU code can be included and executed from your program without the presence of one of the 12 D3DX9_xx.dlls on the end-users computer.
This way we don't bother the end-user with missing D3DX9_xx.dll messages.

As a pixel shader developer your computer must have at least one of the 12 D3DX9_xx.dlls present to compile the pixel shader code.

You can download the latest DirectX9 End-User Runtimes here:
DirectX End-User Runtimes (June 2010)
https://www.microsoft.com/en-us/download/details.aspx?id=8109 (https://www.microsoft.com/en-us/download/details.aspx?id=8109)

Shadertoy, https://www.shadertoy.com/ is a great source to learn pixel shader progamming.
At this moment there are more than 20.000 examples.
You have to convert the WebGL or GLSL to DirectX9 HLSL or GPU assembly.

Here are some great Youtube Video tutorials:
Shadertoy for absolute beginners https://www.youtube.com/watch?v=u5HAYVHsasc&t=829s (https://www.youtube.com/watch?v=u5HAYVHsasc&t=829s)

The following 3 examples are also in the source code attachment (converted to HLSL),

Simple3D -> https://www.youtube.com/watch?v=dKA5ZVALOhs (https://www.youtube.com/watch?v=dKA5ZVALOhs)
Camera3D -> https://www.youtube.com/watch?v=PBxuVlp7nuM (https://www.youtube.com/watch?v=PBxuVlp7nuM)
Tutorial palm tree -> https://www.youtube.com/watch?v=0ifChJ0nJfM (https://www.youtube.com/watch?v=0ifChJ0nJfM)

A great site about ray-marching:
http://jamie-wong.com/2016/07/15/ray-marching-signed-distance-functions/ (http://jamie-wong.com/2016/07/15/ray-marching-signed-distance-functions/)

The attachment contains 2 sources,
The ShaderCompiler source and the ShaderWindow source to execute the pre-compiled pixelshader.

There are 22 examples, most of them I have converted to HLSL from shadertoy examples.
Title: Re: Fun with Pixel Shaders and maths
Post by: avcaballero on February 07, 2018, 08:01:38 PM
Siekmanski, thank you for the stuff and resources. Great work. I'll have a close look when I have time :t

Amazing demos!
Title: Re: Fun with Pixel Shaders and maths
Post by: daydreamer on February 08, 2018, 12:32:16 AM
Great work Marinus  :t
is kinda CPU coded perlin noise procedural easiest to port to pixelshaders?
Title: Re: Fun with Pixel Shaders and maths
Post by: aw27 on February 08, 2018, 01:48:42 AM
Nice demos  :t
The usual stupid question: Why don't you use the 8 years old dx11 instead of the 16 years old dx9? You could reduced the number of shader compilers to 2, I believe.
Title: Re: Fun with Pixel Shaders and maths
Post by: Siekmanski on February 08, 2018, 03:08:22 AM
@aw27, I like to keep things as small and simple as possible.
Because dx9 also is available on XP and dx11 doesn't, dx9 don't need additional ddl's installed the way I use it.

@daydreamer2, yes it can be done.
Here's an example of procedural Perlin Noise,
Title: Re: Fun with Pixel Shaders and maths
Post by: avcaballero on February 08, 2018, 03:27:09 AM
Siekmanski, you are gaining a place next to the programmers' iron throne
(http://www.laverdad.es/noticias/201503/11/media/cortadas/GF0LO401--490x578.jpg)
Title: Re: Fun with Pixel Shaders and maths
Post by: jj2007 on February 08, 2018, 06:33:01 AM
Quote from: caballero on February 08, 2018, 03:27:09 AM
Siekmanski, you are gaining a place next to the programmers' iron throne
Right :t
Title: Re: Fun with Pixel Shaders and maths
Post by: avcaballero on February 11, 2018, 01:43:41 AM
Hello. This is my first attemp to pixel shaders programming. Here is a stupid example did in a hurry using the Siekmanski's pixel shaders compiler in D3D. Source code included.

I'd like to make any other more complex example. But there are many unknown things for me still as how to make random numbers and how to get colors from other rows/columns than the actual.

Regards.
Title: Re: Fun with Pixel Shaders and maths
Post by: Siekmanski on February 11, 2018, 03:34:59 AM
It is handy and logical to treat every window resolution as if they have all the same width and height.
By normalizing the screen viewport coordinates ( fragCoord.xy / iResolution.xy ) the width and height are both from 0.0 to 1.0. So coordinate 0.5,0.5 is exactly in the middle of the screen regardless the window resolution.
Pixel shaders are different in the way we normally paint a pixel on the screen just by telling to paint it at coordinate 100,230.
Now Pixel shaders:
ps_main is called for every pixel in the window, starting at left-top position (0.0,0.0) tracing all scanlines till right-bottom (1.0,1.0). You decide what color you paint at the current position given by the ps_main routine.
And of course you want to do that by using fancy math formulas.  :t
I wondered that myself and tested this by writing the Basic HLSL examples, look at the Basic3.hlsl example.

Made a sort of fake random generator,
Title: Re: Fun with Pixel Shaders and maths
Post by: avcaballero on February 11, 2018, 04:02:57 AM
Nice!

The "main" routine always returns a color for the fragCoord.xy to paint it in some canvas. What I want also is getting the color I have already painted in some coordinate here. I have thought on making a matrix for that, but maybe there is any other simpler way.
Title: Re: Fun with Pixel Shaders and maths
Post by: Siekmanski on February 11, 2018, 05:33:42 AM
Don't know, I'm just like you a beginner in pixel shading.
At the beginning I have studied the YouTube tutorials ( links in my first post ) to get an idea how pixel shaders behave.
To create something we have to do some backwards thinking I guess. In fact this is a logical, fast and short way to solve complex stuff.
I already use this approach for a long time, when I code new routines.
I'll try to explain what I mean by this. ( if you could understand Dutch it would be easier for me  :biggrin: )

A stupid example but I hope you get my drift:

A = the bottom of a tree.
B = one of the many leaves on that tree.

Q: How to find the shortest way between A and B?

From A to B, you get lost when choosing the wrong branches to reach the particular leaf at B and have to go back and start over again and over again until you get to the right leaf at B.

From B to A, you never get lost on a wrong branch because you have only one branch to choose from and end up in a straight way to A.

In pixel shader code this is kind of the same strategy because you know at the start where to paint the pixel, so work your way back to decide what color you want there.
Title: Re: Fun with Pixel Shaders and maths
Post by: Raistlin on February 11, 2018, 06:00:09 AM
Sounds like you are like me, Aspergers... Passion
dictates pseudo idealism and then solution follows.....If not,
must be as all else (comments) says, PURE Genius.  :greenclp:
PPS: I do not mean one is exclusive of the other, that would be like
telling myself I am brilliant and stupid at the same time. Come to think of it....
possibly the correct diagnosis.   
Title: Re: Fun with Pixel Shaders and maths
Post by: Siekmanski on February 11, 2018, 06:41:02 AM
My wife and my friends often call me an idiot.  :biggrin:
Title: Re: Fun with Pixel Shaders and maths
Post by: avcaballero on February 11, 2018, 09:12:24 AM
Well, it is easy, just use a matrix as double buffer. Just wonder if there is a standard way to get the color, not just to set it. Never mind... I'll try to do it when I have some time.

> if you could understand Dutch...
My God, I think I'm too old for that :lol:. Some years ago I shared a flat with some Erasmus Germans, they just taught me to say some swear words :greensml:. Fortunately, they spoke Spanish very well. One day they forced us to read a text in German to an American and me while they were videotaping us. I do not know how someone can read so many consonants together  :shock:.
Title: Re: Fun with Pixel Shaders and maths
Post by: Siekmanski on February 11, 2018, 09:55:17 AM
Quote from: caballero on February 11, 2018, 09:12:24 AM
Well, it is easy, just use a matrix as double buffer. Just wonder if there is a standard way to get the color, not just to set it. Never mind... I'll try to do it when I have some time.

It is possible to create a texture in floating point format and use that as a lookup table and access it from the pixel shader.
This is very fast because you can place in video memory.
I'll implement textures in the next week when time permits. I think it's cool to do texture deformations with the pixel shader.  8)

Quote
> if you could understand Dutch...
My God, I think I'm too old for that :lol:. Some years ago I shared a flat with some Erasmus Germans, they just taught me to say some swear words :greensml:. Fortunately, they spoke Spanish very well. One day they forced us to read a text in German to an American and me while they were videotaping us. I do not know how someone can read so many consonants together  :shock:.

:lol:
Then I would let you read these long Dutch words,
aansprakelijkheidswaardevaststellingsveranderingen ( 50 chars translation: liability value changes )
This one is cool,
Hippopotomonstrosesquippedaliofobie ( 35 chars translation: phobia for long words )

Longest Dutch palindrome,
koortsmeetsysteemstrook. ( 23 chars translation: fever measurement system strip )
Title: Re: Fun with Pixel Shaders and maths
Post by: HSE on February 11, 2018, 11:58:50 AM
Amazing... the long words!

Ah! Also the shader engine  :biggrin: :biggrin: :biggrin:
Title: Re: Fun with Pixel Shaders and maths
Post by: avcaballero on February 12, 2018, 03:59:25 AM
Those Polish I know tell me to say the next tongue twister:
"chrząszcz brzmi w trzcinie" that means "the beetle sounds in the reed"

but I always say :lol::
"ksiądz brzmi w trzcinie" that means "the priest sounds in the reed"

For me, the sound is the same. So, my counterattack is fierce :bgrin:. Recite the following tongue twister:
Quote
El arzobispo de Constantinopla
se quiere desarzobispoconstitanoponitalizar
el buen desarzobispoconstitanoponitalizador
que lo desarzobispoconstitanoponitalice
buen desarzobispoconstitanoponitalizador
será.

A word with 33 characters, not 55, but it's not bad. You won't see it in the RAE, but it is universal.
Title: Re: Fun with Pixel Shaders and maths
Post by: daydreamer on February 12, 2018, 10:56:31 PM
Quote from: Raistlin on February 11, 2018, 06:00:09 AM
Sounds like you are like me, Aspergers... Passion
dictates pseudo idealism and then solution follows.....If not,
must be as all else (comments) says, PURE Genius.  :greenclp:
PPS: I do not mean one is exclusive of the other, that would be like
telling myself I am brilliant and stupid at the same time. Come to think of it....
possibly the correct diagnosis.
I recommend you all read scott adams, the Dilbert principle
its cartoons mixed with background story for those cartoons and anymous people who have mailed him about crazy things on their job, thats even more crazy than his cartoons
at one Point he discuss everyone is an idiot
and I Think its good to dont take yourself too serious

I know C++ programmers also needs to learn "Polish notation" :P
Title: Re: Fun with Pixel Shaders and maths
Post by: Grincheux on February 15, 2018, 04:15:42 AM
Siekmanski, your work is wonderful.
I would stay many hours looking at the examples, beautifull...
Thanks :eusa_boohoo:
Title: Re: Fun with Pixel Shaders and maths
Post by: avcaballero on February 17, 2018, 06:36:55 AM
Hello, my first pixel shader plasma demo, full code for it. I've done a little experiment to compare the pixel shader with a simple gdi.
Title: Re: Fun with Pixel Shaders and maths
Post by: Siekmanski on February 17, 2018, 07:38:41 AM
Cool effect.  8)
We love pixel shaders   :biggrin:
Title: Re: Fun with Pixel Shaders and maths
Post by: avcaballero on February 18, 2018, 07:03:25 AM
> We love pixel shaders
Yes  :biggrin:

A sea scape made by Alexander Alekseev aka TDM here (https://www.shadertoy.com/view/Ms2SD1), where you can find its source code too. I only translated to Siekmanski's PSC. I have to improve the sun reflections, the original code is right.
Title: Re: Fun with Pixel Shaders and maths
Post by: Siekmanski on February 18, 2018, 08:27:20 AM
I also converted this shader some days ago.  :biggrin:
I can imagin you want to do the GLSL to HLSL conversion yourself but, if you want the HLSL code for this shader then let me know.
Title: Re: Fun with Pixel Shaders and maths
Post by: felipe on February 18, 2018, 02:25:58 PM
Nice!  :icon14:
Title: Re: Fun with Pixel Shaders and maths
Post by: avcaballero on February 18, 2018, 07:10:52 PM
> I can imagin you want to do the GLSL to HLSL conversion yourself
Yes, I'd like to try it by myself

> if you want the HLSL code for this shader then let me know
Ok, thank you, give me a bit of time first :biggrin:
Title: Re: Fun with Pixel Shaders and maths
Post by: avcaballero on February 18, 2018, 08:04:13 PM
I did it :eusa_dance: It was very easy, only needed a look :t
Title: Re: Fun with Pixel Shaders and maths
Post by: Siekmanski on February 18, 2018, 09:26:01 PM
Quote from: caballero on February 18, 2018, 08:04:13 PM
I did it :eusa_dance: It was very easy, only needed a look :t

I knew it. Cool  8)
Title: Re: Fun with Pixel Shaders and maths
Post by: felipe on April 06, 2018, 01:04:26 PM
Quote from: felipe on February 18, 2018, 02:25:58 PM
Nice!  :icon14:
:biggrin:
I have looked to this post a little more and looks just an amazing work siekmanski. Thank you very much to share it. I'm starting with directx 9 (mainly that version because i'm basing my learning in an old book of game development with that library). Is it true that d3d9.dll is standard, is in my machine too. I also realized that d3d8.lib is in the masm32 lib folder. Well, returning to my point, i guess that in this book there are no coverage to pixel shaders. I have downloaded the directx 9 sdk and i will check your .inc files with the ones of this sdk that i will need. If i need later (because i will start with the basics from this old book) something related with pixel shaders i will probably thank you again.

Btw, i have quoted myself with that smile comment, because with such stupid comment i didn't give the proper credit to this post. Probably still not now, but is a little better i think.
Title: Re: Fun with Pixel Shaders and maths
Post by: Siekmanski on April 06, 2018, 01:46:54 PM
Hi Felipe,

Thank you.
If the pixel shader examples run on your machine, d3d9.dll is on your machine too.
I don't use the DirectX9 wrapper lib anymore and wrote my own libs to keep the executables very small.

This could also be useful for you to try out the examples in the Directx 9 book:
The complete Direct3D9 9 SDK includes which I translated somewhere in 2004 to Masm assembly. http://members.home.nl/siekmanski/d3dx9_asm.zip
Title: Re: Fun with Pixel Shaders and maths
Post by: felipe on April 07, 2018, 10:53:27 AM
 :greenclp: Bravo siekmanski, amazing! Thank you very much.
Title: Re: Fun with Pixel Shaders and maths
Post by: felipe on April 08, 2018, 10:14:54 AM
Siekmanski from the example d3d9_alpha.asm i get this error:

Microsoft (R) Macro Assembler Version 6.14.8444
Copyright (C) Microsoft Corp 1981-1997.  All rights reserved.

Assembling: ...\d3dx9_asm\sources\d3d9xAlpha\d3d9_al
pha.asm

***********
ASCII build
***********

\masm32\d3dx9includes\limits.inc(33) : error A2005: symbol redefinition : MB_LEN
_MAX
_
Assembly Error
...

I have added the folders of the includes and libs in the masm32 folder (d3dx9includes and d3dx9libs). Thanks for any help, it will be great to use the includes for directx9.
Title: Re: Fun with Pixel Shaders and maths
Post by: felipe on April 08, 2018, 10:22:36 AM
Quote from: Siekmanski on April 06, 2018, 01:46:54 PM
I don't use the DirectX9 wrapper lib anymore and wrote my own libs to keep the executables very small.

Can you explain this a little bit please? If you want to do it here or in the game development forum is ok too.  :idea:
Title: Re: Fun with Pixel Shaders and maths
Post by: Siekmanski on April 08, 2018, 02:30:39 PM
QuoteI have added the folders of the includes and libs in the masm32 folder (d3dx9includes and d3dx9libs). Thanks for any help, it will be great to use the includes for directx9.
The reason I included all includes and libs is because they are not exactly the same as in the Masm32 SDK from 2004.
So, it's better to keep them apart from the original ones from the Masm32 SDK.
The sources are 14 years old and based on the DirectX 9 SDK from late 2003.

You can download the latest DirectX9 End-User Runtimes,
DirectX End-User Runtimes (June 2010)
https://www.microsoft.com/en-us/download/details.aspx?id=8109 (https://www.microsoft.com/en-us/download/details.aspx?id=8109)

Quote from: felipe on April 08, 2018, 10:22:36 AM
Quote from: Siekmanski on April 06, 2018, 01:46:54 PMI don't use the DirectX9 wrapper lib anymore and wrote my own libs to keep the executables very small.

Can you explain this a little bit please? If you want to do it here or in the game development forum is ok too.  :idea:

Because I was fed up with the fact that the user needed the exact same DirectX 9 wrapper-lib version (d3dx9.lib, more than 20 different libs......) installed to run.
To prefent this I wrote my own math lib and picture/texture loader lib for Direct3D9.
My latest sources only need d3d9.lib (d3d9.dll) to work.
Those libs use SIMD instructions so, you might want to update your Masm Assembler to a more resent one.

Title: Re: Fun with Pixel Shaders and maths
Post by: felipe on April 08, 2018, 02:48:12 PM
Siekmanski: first point: ok thanks one last question: any tips to create include files for libraries like those of the directx9 sdk? What was your main procedure to do such thing that time? To the second point: amazing!  :icon14:
Thanks a lot one more time.  :icon14:
Title: Re: Fun with Pixel Shaders and maths
Post by: Siekmanski on April 08, 2018, 03:03:11 PM
I translated it line by line myself, took a really long time.  :biggrin:
Title: Re: Fun with Pixel Shaders and maths
Post by: felipe on April 08, 2018, 03:27:50 PM

/*==========================================================================;
*
*  Copyright (C) Microsoft Corporation.  All Rights Reserved.
*
*  File:   d3d9.h
*  Content:    Direct3D include file
*
****************************************************************************/

#ifndef _D3D9_H_
#define _D3D9_H_

#ifndef DIRECT3D_VERSION
#define DIRECT3D_VERSION         0x0900
#endif  //DIRECT3D_VERSION

// include this file content only if compiling for DX9 interfaces
#if(DIRECT3D_VERSION >= 0x0900)


/* This identifier is passed to Direct3DCreate9 in order to ensure that an
* application was built against the correct header files. This number is
* incremented whenever a header (or other) change would require applications
* to be rebuilt. If the version doesn't match, Direct3DCreate9 will fail.
* (The number itself has no meaning.)*/

#ifdef D3D_DEBUG_INFO
#define D3D_SDK_VERSION   (32 | 0x80000000)
#define D3D9b_SDK_VERSION (31 | 0x80000000)

#else
#define D3D_SDK_VERSION   32
#define D3D9b_SDK_VERSION 31
#endif


#include <stdlib.h>

#define COM_NO_WINDOWS_H
#include <objbase.h>

#include <windows.h>


I see. I'm willing to do that, the problem is than i don't know how. Above is a little bit of the .h file of the d3d9. From the directx 9 sdk (which i believe is now freeware or something). I guess i will look to every include file in the masm package and compare with this .h files to undestand the syntax (actually i have never write a macro, maybe 1 very simple like an exercise or study and for 16 bits). Finally, if i really can't do this i guess i will give up with directx. I have searched in the fasm include from the main page and are very small and incompletes comparing with the ones of the masm package. So i really don't think there are other assemblers with includes for directx. Would be a good idea (just to do directx programming) to work with c to have this headers files working but using inline assembly all the time? Really don't want that, but can't think on more options by now. Ok good night and thanks again.  :icon14:
Title: Re: Fun with Pixel Shaders and maths
Post by: avcaballero on April 10, 2018, 04:38:13 AM
Why don't move this topic to the games thread that maybe should be named "graphics" and "games"? :t
Title: Re: Fun with Pixel Shaders and maths
Post by: LiaoMi on February 05, 2020, 01:17:04 AM
New DirectX Shader Compiler based on Clang/LLVM now available as Open Source - https://devblogs.microsoft.com/directx/new-directx-shader-compiler-based-on-clangllvm-now-available-as-open-source/ (https://devblogs.microsoft.com/directx/new-directx-shader-compiler-based-on-clangllvm-now-available-as-open-source/)
DX Compiler - https://github.com/microsoft/DirectXShaderCompiler (https://github.com/microsoft/DirectXShaderCompiler)
DX Compiler release for July 2019 - https://github.com/microsoft/DirectXShaderCompiler/releases (https://github.com/microsoft/DirectXShaderCompiler/releases)

The DirectX Shader Compiler project includes a compiler and related tools used to compile High-Level Shader Language (HLSL) programs into DirectX Intermediate Language (DXIL) representation. Applications that make use of DirectX for graphics, games, and computation can use it to generate shader programs.

Features and Goals
The starting point of the project is a fork of the LLVM and Clang projects, modified to accept HLSL and emit a validated container that can be consumed by GPU drivers. At the moment, the DirectX HLSL Compiler provides the following components: dxc.exe, a command-line tool that can compile HLSL programs for shader model 6.0 or higher dxcompiler.dll, a DLL providing a componentized compiler, assembler, disassembler, and validator various other tools based on the above components

The Microsoft Windows SDK releases include a supported version of the compiler and validator.

The goal of the project is to allow the broader community of shader developers to contribute to the language and representation of shader programs, maintaining the principles of compatibility and supportability for the platform. It's currently in active development across two axes: language evolution (with no impact to DXIL representation), and surfacing hardware capabilities (with impact to DXIL, and thus requiring coordination with GPU implementations).


ShaderFlex™ is a powerful stand-alone GPU shader authoring environment for DirectX 11 similar to legacy tools like NVidia FX Composer and AMD RenderMonkey.
Whether you're a beginner looking to learn about shaders, a graphics hobbyist wanting to sandbox and share your latest creations or a seasoned graphics engineer prototyping some killer special effects for an upcoming AAA game, ShaderFlex is the tool for you.
Scroll down for an overview of ShaderFlex or check out the Features page for more in-depth information.

NOTE: ShaderFlex is still in development and a beta program is planned for later this year.

Above is an image of ShaderFlex rendering over 500,000 dynamic blades of grass, with depth of field and HDR blooming

Main Features
DirectX 11 support ( extensive control of the API through ShaderFlex's material definitions )
Shader models ( 4_0_level_0_1, 4_0_level_0_3, 4_0, 4_1 and 5_0 )
Shader types ( compute, vertex, geometry, hull, domain, pixel )
Complex non-linear multi-pass support ( for rendering effects like smooth particle hydrodynamics or fluid simulations which require many scattered passes )
Uses proprietary 100% GPU accelerated user interface ( runs smooth on 4K+ displays, dockable, supports HiDPI scaling, abstracted from Windows )
NodeFlex support ( use NodeFlex and our customizable DX11 graph system to auto-generate your shaders and create your own reusable code generating logic )
Oculus Rift DK1 and DK2 support ( using Direct HMD Access and latest SDK )
3DConnexion SpaceMouse support ( and related products )
Debugging capabilities ( live preview, resources, ASM, timing, passes, shader feedback )
Scene scripting ( setup render targets, feed values to shaders, animated objects, and control the scene and rendering per frame )
Material definitions ( easy to use C++ style material definition for setting up resources, views, shaders, states, passes, etc. )
RenderFlex ( export your scenes in binary format to share with other using RenderFlex )
Simulation and Animation ( ability to run simulation passes at different frequencies than other rendering or compute passes )
Texture support ( .jpg, .png, .dds, .tga, .ppm, .bmp.dib, .pfm, .hdr, .tif, .gif )
ShaderFlex Material API ( lightweight API to access all data from a material )
ShaderFlex Rendering API ( integration API to load and render ShaderFlex materials in your rendering pipeline )
AutoDesk FBX support ( .fbx, .obj, .3ds, animation and CPU skinning )
Stream-output support ( render geometry to buffers for later use )
indirect draw/compute ( keep the GPU from stalling by initiating draw/dispatch calls using values from a DX Buffer )
Data Caching ( generate data from a compute shader in an INIT pass and save the data to file for future quick loading )
Pass iterations ( simply tell a pass how many times it should execute and access the iteration count and iteration index from your shaders )
Compute generated vertex and index buffers ( generate and render geometry entirely on the GPU )
Access mesh data from compute shaders ( get the position, normal and other data for processing in a compute shader, for example generating static ambient occlusion )
Flexible viewport ( go full screen, full window, choose from a selection of standard resolutions or choose your own )
Full access to mouse/touch input data from shaders
Auto-draw ( tell a rendering pass how many fake vertices to render, and use the SV_VertexID to dynamically generate geometry like grass blades for example )
Geometry instancing
Tweaks and presets ( shader variable overrides and per-material presets )
Supports WARP software rendering
Code Editing ( Intellisense style code editing, auto-completion tips and other helpers, code preview )
Multiple projects ( open multiple projects at the same time )
Scene editor ( build hierarchical scenes using frame/camera/light/mesh entities and post fx filters, each entity can have unlimited materials attached )
Auto generate mip map levels on the GPU
Volume Texture Targets ( render into volume slices or use a compute shader to do the same )
Cube Texture Targets ( render into cube faces or use a compute shader to do the same )
2D/3D/Volume texture arrays ( use them as shader resources, unordered access buffers or render targets )
Resource Views ( over 31 different types of shader resource, unordered access and render target views )

USING UNITY AS AN FX COMPOSER REPLACEMENT FOR SHADER PROTOTYPING - https://interplayoflight.wordpress.com/2013/02/04/unity-as-an-fx-composer-replacement-for-shader-prototyping/ (https://interplayoflight.wordpress.com/2013/02/04/unity-as-an-fx-composer-replacement-for-shader-prototyping/)
ShaderMan ShaderToy to ShaderLab Converter - https://github.com/smkplus/ShaderMan (https://github.com/smkplus/ShaderMan)

If you've tried dabbling with shaders at all, you've probably come across ShaderToy – an online shader showcase with some pretty amazing examples of what's possible in a few lines of shader code, inspired greatly by classic demoscene coding. Here's just two examples: https://www.shadertoy.com/view/4dl3zn

It's an amazing resource, not only for inspiration but for learning how to create shaders, since every example comes with full source code which you can edit and immediately test online in your browser, alter parameters, supply different inputs etc.

The shaders exhibited on ShaderToy are exclusively written in GLSL, and run in your browser using WebGL.I write an automatic conversion tool to turn a GLSL shader into an HLSL shader that help you fast convert ShaderToy to ShaderLab unity.

GLSL-to-HLSL reference - https://docs.microsoft.com/en-us/previous-versions/windows/apps/dn166865(v=win.10) (https://docs.microsoft.com/en-us/previous-versions/windows/apps/dn166865(v=win.10))

Open-sourcing the Microsoft Edge WebGL GLSL transpiler - https://blogs.windows.com/msedgedev/2016/06/09/open-sourcing-the-microsoft-edge-webgl-glsl-transpiler/ (https://blogs.windows.com/msedgedev/2016/06/09/open-sourcing-the-microsoft-edge-webgl-glsl-transpiler/)
Microsoft Edge WebGL Implementation - https://github.com/MicrosoftEdge/WebGL (https://github.com/MicrosoftEdge/WebGL)
What is a GLSL::HLSL transpiler?
WebGL web pages run 'programs' (shaders) on your GPU to render 3D content; these programs are written in the GLSL shading language. Microsoft Edge uses the DirectX subsystem in Windows (and HLSL, a different Windows-specific shading language) to render content.

Microsoft Edge converts WebGL content to DirectX equivalents to display it; the WebGL renderer converts WebGL calls into DirectX equivalents, and the transpiler converts GLSL shaders to HLSL shaders.

The ANGLE project - https://github.com/google/angle (https://github.com/google/angle) – as used in Chrome and Firefox – has similar functionality.

As an example of this conversion, here's a super-simple program that paints a red pixel:

GLSL:
void main()

{

    gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0); // r g b a

}
HLSL:
float4 main() : SV_Target

{

    return float4(1.0f, 0.0f, 0.0f, 1); // r g b a

}

The transpiler (like any compiler) parses the GLSL program, checks for correctness and security constraints, and applies a conversion process to produce HLSL output.

Title: Re: Fun with Pixel Shaders and maths
Post by: LiaoMi on February 05, 2020, 02:04:19 AM
CrossShader - A tool (Web-Tool) for cross compiling shaders. Convert between GLSL, HLSL, Metal Shader Language, or older versions of GLSL - https://alain.xyz/libraries/crossshader (https://alain.xyz/libraries/crossshader)
A cross compiler for shader languages. Convert between SPIR-V, GLSL / GLSL ES, HLSL, Metal Shader Language, or older versions of a given language.

Programming guide for HLSL https://docs.microsoft.com/en-us/windows/win32/direct3dhlsl/dx9-graphics-reference-asm-ps-3-0 (https://docs.microsoft.com/en-us/windows/win32/direct3dhlsl/dx9-graphics-reference-asm-ps-3-0)
PDF - https://docs.microsoft.com/en-us/windows/win32/opbuildpdf/direct3dhlsl/toc.pdf?branch=live (https://docs.microsoft.com/en-us/windows/win32/opbuildpdf/direct3dhlsl/toc.pdf?branch=live)

Effect-Compiler Tool - FXC (fxc.exe) is an offline tool for compiling HLSL shaders for all versions of Direct3D. The tool is located at: C:\Program Files (x86)\Windows Kits\10\bin\10.0.18362.0\x64
Offline Compiling - https://docs.microsoft.com/en-us/windows/win32/direct3dtools/dx-graphics-tools-fxc-using (https://docs.microsoft.com/en-us/windows/win32/direct3dtools/dx-graphics-tools-fxc-using)
Title: Re: Fun with Pixel Shaders and maths
Post by: daydreamer on February 05, 2020, 02:17:07 AM
many cool tools LiaoMi :thumbsup:
Title: Re: Fun with Pixel Shaders and maths
Post by: Siekmanski on February 05, 2020, 03:04:59 AM
Great research!  :cool:
The GLSL-HLSL transpiler is very interesting stuff.  :thumbsup:
Title: Re: Fun with Pixel Shaders and maths
Post by: LiaoMi on February 05, 2020, 03:25:14 AM
 :biggrin: Thanks!
I was looking for debugging capability and a converter that could translate shaders into each other. The web version(CrossShader) is the most convenient for conversion, unity engine as a tool for graphical presentation  :rolleyes:

WebGL - https://www.shadertoy.com/view/Xsc3RH (https://www.shadertoy.com/view/Xsc3RH)
#version 330
uniform vec3      iResolution;           // viewport resolution (in pixels)
uniform float     iTime;                 // shader playback time (in seconds)
uniform float     iTimeDelta;            // render time (in seconds)
uniform int       iFrame;                // shader playback frame
uniform float     iChannelTime[4];       // channel playback time (in seconds)
uniform vec3      iChannelResolution[4]; // channel resolution (in pixels)
uniform vec4      iMouse;                // mouse pixel coords. xy: current (if MLB down), zw: click

uniform sampler2D iChannel0;             // NOTE: this can vary depending on the shadertoy!
uniform sampler2D iChannel1;     
uniform sampler2D iChannel3;
uniform sampler2D iChannel4;

uniform vec4      iDate;                 // (year, month, day, time in seconds)
uniform float     iSampleRate;           // sound sample rate (i.e., 44100)

const float pi = 3.1415927;

float sdSphere( vec3 p, float s )
{
  return length(p)-s;
}

float sdTorus( vec3 p, vec2 t )
{
  vec2 q = vec2(length(p.xz)-t.x,p.y);
  return length(q)-t.y;
}

float sdCappedCylinder( vec3 p, vec2 h )
{
  vec2 d = abs(vec2(length(p.xz),p.y)) - h;
  return min(max(d.x,d.y),0.0) + length(max(d,0.0));
}

// 👉 Insert your shadertoy here:
void mainImage( out vec4 fragColor, in vec2 fragCoord )
{
vec2 pp = fragCoord.xy/iResolution.xy ;
pp = -1.0 + 2.0*pp;
pp.x *= iResolution.x/iResolution.y;

vec3 lookAt = vec3(0.0, 0.0, 0.0);
   
    float eyer = 2.0;
    float eyea = (iMouse.x / iResolution.x) * pi * 2.0;
    float eyea2 = ((iMouse.y / iResolution.y)-0.24) * pi * 2.0;
   
vec3 ro = vec3(
        eyer * cos(eyea) * sin(eyea2),
       eyer * cos(eyea2),
        eyer * sin(eyea) * sin(eyea2)); //camera position
   
   
vec3 front = normalize(lookAt - ro);
vec3 left = normalize(cross(normalize(vec3(0.0,1,0)), front));
vec3 up = normalize(cross(front, left));
vec3 rd = normalize(front + left*pp.x + up*pp.y); // rect vector
   
   
    vec3 bh = vec3(0.0,0.0,0.0);
    float bhr = 0.2;
    float bhmass = 20.0;
    bhmass *= 0.001; // premul G
   
    vec3 p = ro;
    vec3 pv = rd;
    float dt = 0.02;
   
    vec3 col = vec3(0.0);
   
    float noncaptured = 1.0;
     
    vec3 c1 = vec3(0.9,0.35,0.1);
    vec3 c2 = vec3(1.0,0.8,0.6);
   
   
    for(float t=0.0;t<1.0;t+=0.005)
    {
        p += pv * dt * noncaptured;
       
        // gravity
        vec3 bhv = bh - p;
        float r = dot(bhv,bhv);
        pv += normalize(bhv) * ((bhmass) / r);
       
        noncaptured = smoothstep(0.0, 0.1, sdSphere(p-bh,bhr));
       
        // Texture for the accretion disc
        float dr = length(bhv.xz);
        float da = atan(bhv.x,bhv.z);
        vec2 ra = vec2(dr,da * (0.01 + (dr - bhr)*0.002) + 2.0 * pi + iTime*0.002 );
        ra *= vec2(10.0,20.0);
       
        vec3 dcol = mix(c2,c1,pow(length(bhv)-bhr,0.5)) * max(0.0,texture(iChannel1,ra*vec2(0.1,0.5)).r+0.05) * (4.0 / ((0.001+(length(bhv) - bhr)*50.0) ));
       
        col += max(vec3(0.0),dcol * smoothstep(0.0, 1.0, -sdTorus( (p * vec3(1.0,25.0,1.0)) - bh, vec2(0.4,0.99))) * noncaptured);
       
     //   col += dcol * (1.0/dr) * noncaptured * 0.005;
       
        // Glow
        col += vec3(1.0,0.9,0.85) * (1.0/vec3(dot(bhv,bhv))) * 0.0033 * noncaptured;
       
    }
   
    // BG
//   col += pow(texture(iChannel0,pv.xy).rgb,vec3(5.0)) * 0.25;
   
    // FInal color
    fragColor = vec4(col,1.0);
}

void main()
{
    vec4 outColor = vec4(0.0, 0.0, 0.0, 0.0);
    mainImage(outColor, vec2(0.0, 0.0));
    gl_FragColor = outColor;
}


HLSL
uniform float3 iResolution;
uniform float4 iMouse;
uniform float iTime;
uniform sampler2D iChannel1;
uniform float iTimeDelta;
uniform int iFrame;
uniform float iChannelTime[4];
uniform float3 iChannelResolution[4];
uniform sampler2D iChannel0;
uniform sampler2D iChannel3;
uniform sampler2D iChannel4;
uniform float4 iDate;
uniform float iSampleRate;

static float4 _gl_FragColor;

struct SPIRV_Cross_Output
{
    float4 _gl_FragColor : COLOR0;
};

float sdSphere(float3 p, float s)
{
    return length(p) - s;
}

float sdTorus(float3 p, float2 t)
{
    float2 q = float2(length(p.xz) - t.x, p.y);
    return length(q) - t.y;
}

void mainImage(inout float4 fragColor, float2 fragCoord)
{
    float2 pp = fragCoord / iResolution.xy;
    pp = (-1.0f).xx + (pp * 2.0f);
    pp.x *= (iResolution.x / iResolution.y);
    float3 lookAt = 0.0f.xxx;
    float eyer = 2.0f;
    float eyea = ((iMouse.x / iResolution.x) * 3.1415927410125732421875f) * 2.0f;
    float eyea2 = (((iMouse.y / iResolution.y) - 0.23999999463558197021484375f) * 3.1415927410125732421875f) * 2.0f;
    float3 ro = float3((eyer * cos(eyea)) * sin(eyea2), eyer * cos(eyea2), (eyer * sin(eyea)) * sin(eyea2));
    float3 front = normalize(lookAt - ro);
    float3 left = normalize(cross(float3(0.0f, 1.0f, 0.0f), front));
    float3 up = normalize(cross(front, left));
    float3 rd = normalize((front + (left * pp.x)) + (up * pp.y));
    float3 bh = 0.0f.xxx;
    float bhr = 0.20000000298023223876953125f;
    float bhmass = 20.0f;
    bhmass *= 0.001000000047497451305389404296875f;
    float3 p = ro;
    float3 pv = rd;
    float dt = 0.0199999995529651641845703125f;
    float3 col = 0.0f.xxx;
    float noncaptured = 1.0f;
    float3 c1 = float3(0.89999997615814208984375f, 0.3499999940395355224609375f, 0.100000001490116119384765625f);
    float3 c2 = float3(1.0f, 0.800000011920928955078125f, 0.60000002384185791015625f);
    for (float t = 0.0f; t < 1.0f; t += 0.004999999888241291046142578125f)
    {
        p += ((pv * dt) * noncaptured);
        float3 bhv = bh - p;
        float r = dot(bhv, bhv);
        pv += (normalize(bhv) * (bhmass / r));
        float3 param = p - bh;
        float param_1 = bhr;
        noncaptured = smoothstep(0.0f, 0.100000001490116119384765625f, sdSphere(param, param_1));
        float dr = length(bhv.xz);
        float da = atan2(bhv.x, bhv.z);
        float2 ra = float2(dr, ((da * (0.00999999977648258209228515625f + ((dr - bhr) * 0.00200000009499490261077880859375f))) + 6.283185482025146484375f) + (iTime * 0.00200000009499490261077880859375f));
        ra *= float2(10.0f, 20.0f);
        float3 dcol = (lerp(c2, c1, pow(length(bhv) - bhr, 0.5f).xxx) * max(0.0f, tex2D(iChannel1, ra * float2(0.100000001490116119384765625f, 0.5f)).x + 0.0500000007450580596923828125f)) * (4.0f / (0.001000000047497451305389404296875f + ((length(bhv) - bhr) * 50.0f)));
        float3 param_2 = (p * float3(1.0f, 25.0f, 1.0f)) - bh;
        float2 param_3 = float2(0.4000000059604644775390625f, 0.9900000095367431640625f);
        col += max(0.0f.xxx, (dcol * smoothstep(0.0f, 1.0f, -sdTorus(param_2, param_3))) * noncaptured);
        col += (((float3(1.0f, 0.89999997615814208984375f, 0.85000002384185791015625f) * (1.0f.xxx / dot(bhv, bhv).xxx)) * 0.0032999999821186065673828125f) * noncaptured);
    }
    fragColor = float4(col, 1.0f);
}

void frag_main()
{
    float4 outColor = 0.0f.xxxx;
    float2 param_1 = 0.0f.xx;
    float4 param;
    mainImage(param, param_1);
    outColor = param;
    _gl_FragColor = outColor;
}

SPIRV_Cross_Output main()
{
    frag_main();
    SPIRV_Cross_Output stage_output;
    stage_output._gl_FragColor = float4(_gl_FragColor);
    return stage_output;
}


WebGL - this procedure is skipped  :undecided:
float sdCappedCylinder( vec3 p, vec2 h )
{
  vec2 d = abs(vec2(length(p.xz),p.y)) - h;
  return min(max(d.x,d.y),0.0) + length(max(d,0.0));
}
Title: Re: Fun with Pixel Shaders and maths
Post by: Siekmanski on February 05, 2020, 06:30:35 AM
https://alain.xyz gives a Malware warning....  :sad:
Title: Re: Fun with Pixel Shaders and maths
Post by: avcaballero on February 05, 2020, 06:39:17 AM
"Fun with Pixel Shaders and maths"

Hey guys, don't have fun only you eh?. I'm bussy now, but if you wait, I may do something here,
if providence does not prevent it  :thumbsup:
Title: Re: Fun with Pixel Shaders and maths
Post by: Siekmanski on February 05, 2020, 06:41:20 AM
 :biggrin: :thumbsup:
Title: Re: Fun with Pixel Shaders and maths
Post by: LiaoMi on February 05, 2020, 06:44:36 AM
Quote from: Siekmanski on February 05, 2020, 06:30:35 AM
https://alain.xyz gives a Malware warning....  :sad:

Do you have malwarebytes installed? This antivirus is crazy  :biggrin: My ESET-NOD antivirus did not find anything there ..  :tongue:
Title: Re: Fun with Pixel Shaders and maths
Post by: Siekmanski on February 05, 2020, 06:51:22 AM
Possibly a false positive???

But the cross shader is on Github too.

https://github.com/alaingalvan/crossshader.git (https://github.com/alaingalvan/crossshader.git)
Title: Re: Fun with Pixel Shaders and maths
Post by: LiaoMi on February 05, 2020, 07:14:17 AM
Quote from: Siekmanski on February 05, 2020, 06:51:22 AM
Possibly a false positive???

But the cross shader is on Github too.

https://github.com/alaingalvan/crossshader.git

The latest version of Malwarebytes blocks every second web page, I turned it off, github contains the source code and the same link to the working version. I forgot to provide a link to the source code  :azn:
Title: Re: Fun with Pixel Shaders and maths
Post by: Siekmanski on February 05, 2020, 09:23:02 AM
Realtime shader programming compo at Revision 2019 Demo Party  :thumbsup:

Revision 2019 - Event - Shader Showdown 2019 - Opening Round
https://www.youtube.com/watch?v=YKtvYAn-v2Y (https://www.youtube.com/watch?v=YKtvYAn-v2Y)

Revision 2019 - Event - Shader Showdown 2019 - Quarterfinals
https://www.youtube.com/watch?v=uifMBMt9ASU (https://www.youtube.com/watch?v=uifMBMt9ASU)

Revision 2019 - Event - Shader Showdown 2019 - Semifinals
https://www.youtube.com/watch?v=jNhQUksZYkY (https://www.youtube.com/watch?v=jNhQUksZYkY)

Revision 2019 - Event - Shader Showdown 2019 - Final
https://www.youtube.com/watch?v=gmMPvUwyMxA (https://www.youtube.com/watch?v=gmMPvUwyMxA)

Revision 2019 - Event - Shader Showdown 2020 - Qualification Semifinals
https://www.youtube.com/watch?v=tYU2DrI1sGM (https://www.youtube.com/watch?v=tYU2DrI1sGM)

Title: Re: Fun with Pixel Shaders and maths
Post by: daydreamer on February 05, 2020, 06:13:02 PM
Quote from: Siekmanski on February 05, 2020, 09:23:02 AM
Realtime shader programming compo at Revision 2019 Demo Party  :thumbsup:

Revision 2019 - Event - Shader Showdown 2019 - Opening Round
https://www.youtube.com/watch?v=YKtvYAn-v2Y

Revision 2019 - Event - Shader Showdown 2019 - Quarterfinals
https://www.youtube.com/watch?v=uifMBMt9ASU

Revision 2019 - Event - Shader Showdown 2019 - Semifinals
https://www.youtube.com/watch?v=jNhQUksZYkY

Revision 2019 - Event - Shader Showdown 2019 - Final
https://www.youtube.com/watch?v=gmMPvUwyMxA

Revision 2019 - Event - Shader Showdown 2020 - Qualification Semifinals
https://www.youtube.com/watch?v=tYU2DrI1sGM
very cool :thumbsup:
where is yours?
Title: Re: Fun with Pixel Shaders and maths
Post by: daydreamer on February 05, 2020, 06:33:11 PM
isnt you start with a simple curve and make it work and later add 3d transform functions on it,maybe function that bends it to look like its on inside of a sphere?
simplest do circles/sphere
next one,find a curve thats suitable and if x and y matches curves x and y,draw in different color?
y=c1*x^4+c2*x^3+c3*x^2+c4*line ;c1,c2,c3,c4 constants
Title: Re: Fun with Pixel Shaders and maths
Post by: LiaoMi on February 05, 2020, 07:44:13 PM
Quote from: Siekmanski on February 05, 2020, 09:23:02 AM
Realtime shader programming compo at Revision 2019 Demo Party  :thumbsup:

Revision 2019 - Event - Shader Showdown 2019 - Opening Round
https://www.youtube.com/watch?v=YKtvYAn-v2Y

Revision 2019 - Event - Shader Showdown 2019 - Quarterfinals
https://www.youtube.com/watch?v=uifMBMt9ASU

Revision 2019 - Event - Shader Showdown 2019 - Semifinals
https://www.youtube.com/watch?v=jNhQUksZYkY

Revision 2019 - Event - Shader Showdown 2019 - Final
https://www.youtube.com/watch?v=gmMPvUwyMxA

Revision 2019 - Event - Shader Showdown 2020 - Qualification Semifinals
https://www.youtube.com/watch?v=tYU2DrI1sGM

Reminds a hackathon, did not know that there is such a thing for graphics, downloaded a video, but only one watched  :thup: :thup: :thup:
Title: Re: Fun with Pixel Shaders and maths
Post by: Siekmanski on February 05, 2020, 09:42:50 PM
Hi Magnus,

Just try it out, and see what it does.  :cool:
Thinking outside of the box can lead to astonishing results.
What about using roots to draw circles, only calculating 1 octant and mirroring it to the other 7 octants?
No need for expensive trig functions like sin, cos or arctan2.

Hi LiaoMi,

There are many competitions at Demo Parties.
- Demo and intro coding.
- Graphics
- Music
- etc.

For example: Revision Demoparty
https://www.youtube.com/channel/UCFtrxOb0K67hvOt_lRuX1Uw (https://www.youtube.com/channel/UCFtrxOb0K67hvOt_lRuX1Uw)
Title: Re: Fun with Pixel Shaders and maths
Post by: daydreamer on February 06, 2020, 04:17:47 AM
Quote from: Siekmanski on February 05, 2020, 09:42:50 PM
Just try it out, and see what it does.  :cool:
Thinking outside of the box can lead to astonishing results.
What about using roots to draw circles, only calculating 1 octant and mirroring it to the other 7 octants?
No need for expensive trig functions like sin, cos or arctan2.
sounds like fun,blend together several circles with different sizes and colors looks good
want to try out simple curves to figure out bigstock pic
Title: Re: Fun with Pixel Shaders and maths
Post by: daydreamer on February 06, 2020, 08:22:42 PM
Marinus
dont have no sqrt in this,wonder how fast a packed compare that act on mask colors?
http://masm32.com/board/index.php?topic=7324.0 (http://masm32.com/board/index.php?topic=7324.0)

thats because you dont have sqrt or divide in MMX handling lots of pixels
Title: Re: Fun with Pixel Shaders and maths
Post by: Siekmanski on February 06, 2020, 09:50:44 PM
You want to do that in 16bit DOS?
Maybe do it the oldskool way.
Precalculated sqrt tables and/or reciprocal (fixed point) tables for the divisions.
Title: Re: Fun with Pixel Shaders and maths
Post by: daydreamer on February 06, 2020, 11:16:55 PM
Quote from: Siekmanski on February 06, 2020, 09:50:44 PMYou want to do that in 16bit DOS?
Maybe do it the oldskool way.
Precalculated sqrt tables and/or reciprocal (fixed point) tables for the divisions.
no,more fun to make it 128bit+ version of it
one part:
http://masm32.com/board/index.php?topic=7938.0 (http://masm32.com/board/index.php?topic=7938.0)
Title: Re: Fun with Pixel Shaders and maths
Post by: Xylitol on December 22, 2023, 11:54:07 PM
First of, thank you for your pixelshader code Siekmanski.

Here is my fork, i ported it to Dialogbox, tweaked a bit the ShaderCompiler to load file and compile the .hlsl on the fly with also a selector for the d3dx optimization flags.

Included in the zip are ShaderCompiler source and ShaderViewer.
i integrated also in the zip all the shaders made by the community in this thread
+ some shaders of mine
i've upx packed the .exe so i can stay in the 512kb zip file size limit.
there is still fews bugs as sometime it crash on system, but heh.. it work on mine :tongue:
Title: Re: Fun with Pixel Shaders and maths
Post by: jj2007 on December 23, 2023, 01:08:35 AM
It hangs with its cpu core at 100%. My Win10 system has C:\Windows\System32\d3dxof.dll but no C:\Windows\System32\d3dx_??.dll, so LoadLibrary fails; and my *of* does not know about D3DXCompileShaderFromFileA :cool:

To avoid the hanging program, you should give up after the last attempt and shout at the user.

Apart from that minor glitch, it's a nice project :thumbsup:
Title: Re: Fun with Pixel Shaders and maths
Post by: Siekmanski on December 23, 2023, 01:10:07 AM
Hi Xylitol,
Very cool!  :thumbsup:
Title: Re: Fun with Pixel Shaders and maths
Post by: TimoVJL on December 23, 2023, 09:36:42 AM
With 9 kB asm source can generate a 127 kB exe with simple trick, a big ICO  :thumbsup:
Size matters, sometimes not lives.
Title: Re: Fun with Pixel Shaders and maths
Post by: Siekmanski on December 23, 2023, 04:19:48 PM
Quote from: jj2007 on December 23, 2023, 01:08:35 AMIt hangs with its cpu core at 100%. My Win10 system has C:\Windows\System32\d3dxof.dll but no C:\Windows\System32\d3dx_??.dll, so LoadLibrary fails; and my *of* does not know about D3DXCompileShaderFromFileA :cool:

To avoid the hanging program, you should give up after the last attempt and shout at the user.

Apart from that minor glitch, it's a nice project :thumbsup:

Hi Jochen,

It's not a glitch, read the first post which explains it all.
This was exactly the reason why I coded the Pixel Shader Compiler so the end user wouldn't have this problem.

QuoteMy goal was to use pixel shaders in Direct3D9.
Unfortunately d3d9.dll ( which is standard present on all windows operating systems from 2003 till now ) doesn't have a shader compiler function.
The fully functional DirectX9 shader compiler function for shader version 3.0 is available in the wrapper libs D3DX9_32.dll up to D3DX9_43.dll.

So I programmed a small ShaderCompiler program that searches if one of the 12 D3DX9_xx.dlls is available on the developers computer and calls the compiler function by using "LoadLibrary" and "GetProcAddress".
The compiled pixel shader code can be saved as pre-compiled GPU code.

The pre-compiled GPU code can be included and executed from your program without the presence of one of the 12 D3DX9_xx.dlls on the end-users computer.
This way we don't bother the end-user with missing D3DX9_xx.dll messages.


As a pixel shader developer your computer must have at least one of the 12 D3DX9_xx.dlls present to compile the pixel shader code.

You can download the latest DirectX9 End-User Runtimes here:
DirectX End-User Runtimes (June 2010)
https://www.microsoft.com/en-us/download/details.aspx?id=8109

This way you can show your amazing pixel shaders only using d3d9.dll ( which is standard present on all windows operating systems from 2003 till now )
Title: Re: Fun with Pixel Shaders and maths
Post by: daydreamer on December 23, 2023, 05:43:47 PM
Quote from: TimoVJL on December 23, 2023, 09:36:42 AMWith 9 kB asm source can generate a 127 kB exe with simple trick, a big ICO  :thumbsup:
Size matters, sometimes not lives.
Check hitchhikers  two 1k d3d9 shader demos in old UK Forum?
Put d3d headers on diet to bare minimum to put up quad and start tiny pixelshader
Wouldn't that be possible too with newer d3d12 header files?
I only managed to put ddraw included libs on diet,by removing including gdi, because you can draw everything with d3d except when you need to draw text

Humans do not care of trees lives, when they need to power their fossil powerplants, to power many power hungry consoles and gaming computers to load bloat on 800 watt / hour, play games loads of hours
So 64k demo running few minutes on newer mobile gpu cards in laptop 40w / hour, few W / hour when idle
Lot nicer to environment, but also to your wallet not needing pay big electric bills

Title: Re: Fun with Pixel Shaders and maths
Post by: Siekmanski on December 23, 2023, 06:05:44 PM
QuoteCheck hitchhikers  two 1k d3d9 shader demos in old UK Forum?
Put d3d headers on diet to bare minimum to put up quad and start tiny pixelshader.

Then you have the same problem -> missing D3DX9_xx.dlls

With my code which only uses d3d9.dll, it will run from Windows XP and up, without extra dll's

Quotebecause you can draw everything with d3d except when you need to draw text.

I have a text drawing routine included in my D3D9 libs.  :cool:
Title: Re: Fun with Pixel Shaders and maths
Post by: jj2007 on December 23, 2023, 08:35:27 PM
Quote from: Siekmanski on December 23, 2023, 04:19:48 PMHi Jochen,

It's not a glitch, read the first post which explains it all.

Thanks, Marinus :thumbsup:

My fault, I had assumed I could skip reading your post, which is 5 years old.

The problem here is that Win10 has only one C:\Windows\System32\d3dxof.dll - it doesn't fit into the d3dx_xx.dll scheme (no understroke), Xylitol's program doesn't find it, and even if it did, GetProcAddress would miserably fail. Plus, there is no message to the user, and instead the program enters a loop at 100% cpu load. Not exactly a Christmas present ;-)
Title: Re: Fun with Pixel Shaders and maths
Post by: TimoVJL on December 24, 2023, 01:57:19 AM
link for dlls
Microsoft.DXSDK.D3DX  (https://www.nuget.org/packages/Microsoft.DXSDK.D3DX/9.29.952.7)
Title: Re: Fun with Pixel Shaders and maths
Post by: jj2007 on December 24, 2023, 05:24:01 AM
QuoteFor Direct3D 11 users, the recommendation is to switch from D3DX11 to one of many open-source replacements

Interesting advice from Microsoft :biggrin:
Title: Re: Fun with Pixel Shaders and maths
Post by: NoCforMe on December 24, 2023, 10:03:17 AM
OK, dumb question:

I know nothing about Direct3D and all its associated stuff--compute shaders, etc., etc.

I just took a look at the Micro$oft introductory documentation (https://learn.microsoft.com/en-us/windows/win32/direct3d) on this: it's extensive, voluminous and about as clear as mud.

So my first question is, what the hell is Direct3D, really? I mean on a very basic level: what exactly does it do? can I see some examples of what it does and how it works? an understandable explanation of why it exists?

I use GDI, and a very little GDI+, which is the extent of my understanding of Win32 graphics stuff.

Help me get a handle on this, please.
Title: Re: Fun with Pixel Shaders and maths
Post by: Siekmanski on December 24, 2023, 11:02:35 AM
Direct3D is mainly used to write games.
Direct3D gives you full access to all the capabilities of the video card.  :cool:  :thumbsup:
Title: Re: Fun with Pixel Shaders and maths
Post by: Siekmanski on December 24, 2023, 11:37:01 AM
Some examples:

Rotating skull: https://masm32.com/board/index.php?action=dlattach;attach=5337 (https://masm32.com/board/index.php?action=dlattach;attach=5337)
heightmap: https://masm32.com/board/index.php?topic=1890.msg20256#msg20256 (https://masm32.com/board/index.php?topic=1890.msg20256#msg20256)
3dstars: http://masm32.com/board/index.php?topic=4123.msg43687#msg43687 (http://masm32.com/board/index.php?topic=4123.msg43687#msg43687)
Color cubes: http://masm32.com/board/index.php?topic=4410.msg47103#msg47103 (http://masm32.com/board/index.php?topic=4410.msg47103#msg47103)
Webcam: http://masm32.com/board/index.php?topic=4858.msg52908#msg52908 (http://masm32.com/board/index.php?topic=4858.msg52908#msg52908)
Title: Re: Fun with Pixel Shaders and maths
Post by: HSE on December 26, 2023, 03:47:30 AM
Quote from: Xylitol on December 22, 2023, 11:54:07 PMHere is my fork, i ported it to Dialogbox, tweaked a bit the ShaderCompiler to load file and compile the .hlsl on the fly with also a selector for the d3dx optimization flags.

:thumbsup: Very nice!
Title: Re: Fun with Pixel Shaders and maths
Post by: daydreamer on December 28, 2023, 07:47:07 AM
Quote from: Siekmanski on December 24, 2023, 11:02:35 AMDirect3D is mainly used to write games.
Direct3D gives you full access to all the capabilities of the video card.  :cool:  :thumbsup:
but I mostly used DDRAW together with SSE to draw fast directly to screen memory
the different kind of mindset needed for pixelshaders is hard for me to master writing cool demos with
still some asm code is inspired by inverse way of computing each pixel by calculate pythagoras when drawing circles