GLSL zu HLSL konvertieren

Fragen zu Grafik- & Soundproblemen und zur Spieleprogrammierung haben hier ihren Platz.
Benutzeravatar
udg
Beiträge: 560
Registriert: 20.06.2013 23:27

GLSL zu HLSL konvertieren

Beitrag von udg »

Schon lange fasziniert mich der vielseitige GLSL code von: https://www.shadertoy.com/view/XsSSzy

diesen zB. umschreiben in HLSL Code, könnte man ihn benutzen in Purebasic als hübschen Effekt.

Leider fehlt mir das ausreichende Wissen um diese umzusetzen. Ich habe einige nette HLSL Codes hier und würde gern meine Sammlung erweitern.

Kann mir da jemand bei helfen?

hier mal ein Beispiel *.FX code der in PureBasic funktioniert:

Code: Alles auswählen

uniform float time;
uniform float2 resolution = float2(800,600);// change Resolution

static const float PI = 3.14159;
static const float RADIUS = 50.;

static const float CELL_SIZE = 8.;
static const float CELL_THICK = 0.2;
static const float CELL_RADIUS = .5*CELL_SIZE - CELL_THICK;

float squared_distance(const float2 a, const float2 b)
{
	float2 d = a - b;
	return dot(d, d);
}

float add_blob(const float2 center, const float2 gl_FragCoord)
{
	return 2.5e5/(1. + squared_distance(gl_FragCoord.xy, center));
}

float mod(const float x, const float y)
{
	return x - y * floor(x/y);
}

float4 main(float2 Tex : TEXCOORD, float4 gl_FragCoord : VPOS) : COLOR
{
	gl_FragCoord.y = resolution.y - gl_FragCoord.y;
	float2 origin  = .5*resolution;
	float v =
		add_blob(origin + float2(150.*sin(2.1 + 1.6*time), 205.*cos(5.7 + 1.8*time)), gl_FragCoord) +
		add_blob(origin + float2(100.*cos(.5 + 2.1*time), 100.*sin(7.5 + 5.2*time)), gl_FragCoord) +
		add_blob(origin + float2(60.*sin(.3 + 1.6*time), 200.*cos(3.3 + 1.6*time)), gl_FragCoord);	
	float w = v - RADIUS;
	
	float r = pow(1. + pow(w, 2.), -.2)*CELL_RADIUS;

	float2 offs = float2(step(CELL_SIZE, mod(gl_FragCoord.y, 2.*CELL_SIZE))*.5*CELL_SIZE, 0);
	float2 cell_center = offs + CELL_SIZE*floor((gl_FragCoord.xy - offs)/CELL_SIZE) + .5*float2(CELL_SIZE, CELL_SIZE);
	float d = distance(gl_FragCoord.xy, cell_center);
	float c = smoothstep(r + CELL_THICK, r, d);
	
	return float4(c, c, c, 1);
}

// Vertex Shader
struct VS_INPUT
{
	float3 position	: POSITION;
	float2 texture0     : TEXCOORD0;
};

struct VS_OUTPUT
{
	float4 hposition : POSITION;
	float2 texture0  : TEXCOORD0;
};

VS_OUTPUT myvs( VS_INPUT IN )
{
	VS_OUTPUT OUT;

	OUT.hposition = float4(IN.position.x ,IN.position.y ,IN.position.z, 1);
	OUT.texture0 = IN.texture0;
	return OUT;
}

technique Start
{
	pass p1
	{
		VertexShader = compile vs_3_0 myvs();
		PixelShader = compile ps_3_0 main();
	}
}
und so schaut der Effect in Purebasic aus:
Bild


Danke fürs lesen und evtl. kann mir jemand helfen :)

Hab Euch mal eine kompilierte Demo exe angehangen. Da kommt noch Scrollschrift und 3D Objekt und was weis ich noch drübber :)

www.inc-games-design.de/Tools/shaderDemo.rar



Grüße
Zuletzt geändert von udg am 22.05.2016 20:20, insgesamt 1-mal geändert.
PB v5.43 LTS + v6.02 LTS | Windows 7 x86 + 11 x64 - Gforce RTX 4090 - AMD Ryzen 9 5900X 12-Core Processor 4.2 GHz - 64,0 GB RAM,
ASUSTEK TUF Gaming X570 Plus
ASUS ROG Thor-1200P Platinum (1200W, Aura Sync, OLED Display, 0dB-Cooling)
1x 1 TByte Samsung MZ-V7S500BW 970 EVO Plus 1 TB NVMe M.2 Internal SSD
1x 2 TByte Samsung MZ-V7S2T0BW 970 EVO Plus 2 TB NVMe M.2 Internal SSD
von BiSONTE! TOP. Kauft Eure Hardware gern bei ihm.
Monitor:
LG 38GL950G-B 95 (38 Zoll) Ultragear Curved 21: 9 UltraWide QHD IPS
Benutzeravatar
mpz
Beiträge: 497
Registriert: 14.06.2005 15:53
Computerausstattung: Win 10 Pro, 16 GB Ram, Intel I5 CPU und TI1070 Grafikkarte, PB 5.73 / 6.00 beta4
Wohnort: Berlin, Tempelhof

Re: GLSL zu HLSL konvertieren

Beitrag von mpz »

Hi udg,

leider konnte ich Dein Beispiel nicht mehr laden, war wohl weg...

Ich habe für meine mp3d Endgine (dx9) einen Shadereditor gebaut der (dx9) Shadereffekte testen konnte und auch einen recht primitiven glsl to hlsl Konverter. Es gab halt einige Dinge zu beachten die man dann doch noch manuell umbenennen musste, aber einfache Shader konnte man gut konvertieren. Ich suche das mal raus und hänge es hier ran. Ich schaue mal das ich es nächste Woche fertig machen kann...

Dein Beispiel würde mich interessieren...

Grüsse Michael
Working on - MP3D Engine -
Benutzeravatar
udg
Beiträge: 560
Registriert: 20.06.2013 23:27

Re: GLSL zu HLSL konvertieren

Beitrag von udg »

ich habe den Link erneuert, wusste nicht, dass FileDropper die Dateien wieder löscht :(
ist nun permanent Online
in meiner Demo lade ich nun GLSL Shader und das geht wunderbar. Also denke ich, dass wir auf eine Konvertierung von glsl zu hlsl verzichten können... wenn! es geht, dass deine 3D Lib es handeln könnte, wir nun auf den GLSL Screen, deine anderen ganzen Effekte draufladen können.
Scroller, 3D Objekte ect.

Habe mich noch nicht weiter damit befasst, ob und wie ich das Ganze realisiere.

PS.
hast Du mal meine Frage gelesen zum handling von *.3ds Objekten?
http://www.purebasic.fr/german/viewtopi ... &start=200

VG
inc
PB v5.43 LTS + v6.02 LTS | Windows 7 x86 + 11 x64 - Gforce RTX 4090 - AMD Ryzen 9 5900X 12-Core Processor 4.2 GHz - 64,0 GB RAM,
ASUSTEK TUF Gaming X570 Plus
ASUS ROG Thor-1200P Platinum (1200W, Aura Sync, OLED Display, 0dB-Cooling)
1x 1 TByte Samsung MZ-V7S500BW 970 EVO Plus 1 TB NVMe M.2 Internal SSD
1x 2 TByte Samsung MZ-V7S2T0BW 970 EVO Plus 2 TB NVMe M.2 Internal SSD
von BiSONTE! TOP. Kauft Eure Hardware gern bei ihm.
Monitor:
LG 38GL950G-B 95 (38 Zoll) Ultragear Curved 21: 9 UltraWide QHD IPS
Antworten