OK…
I need some help getting the HLSL version to work…
I don’t need help porting into a Unity3D Shader file.
If I have a working HLSL shader, then it is no issue porting to Unity.
I am playing around with this process, with some success.
But before importing anything into an actual *.shader file
I have to do two things (since most examples are GLSL shaders)
Get the GLSL shader to work. sometimes some minor tweaking or fixing is needed.
Convert the GLSL shader to an HLSL shader.
Once I get both working, the rest is mostly smooth sailing.
Now for some GLSL shaders, I will have no difficulty at all.
The ones that don’t work, the difficulty is in determining why?
I get no compiler errors, the GLSL displays + works…
I am mostly interested in WHY my example HLSL is not working, since this will absolutely help when I have the “same” issues porting other GLSL shaders.
I attached the 2 shader versions in a zip file.
one is a GLSL version
the other is a HLSL version .(converted from GLSL)
So once I get that working…onto the conversion process.
Open/Create a new HLSL file in VS.Code.
Add or Paste the HLSL code into it. (of course it goes without saying this will not work in GLSL viewer)
Use the HLSL view to run/preview the shader.
Fix/Tweak anything needed.
Now the conversion is mostly straight forward process.
I have to convert…
vec to float
And mix → lerp
mat to floatx
fract → frac
mod → fmod
most of the time, that is all the conversion that needs to be done.
I can usually get the HLSL working (with tweaks or minor fixes),
The rest is smooth sailing
Now for the example GLSL + HLSL program (attached in previous post)
I did this, but could not get the HLSL to work (the GLSL worked out of the box)
But could not figure out why it didn’t work…
Could somebody take a peak and see if something obvious is wrong?
What is correct GLSL to HLSL conversion for this code snippet?
ORIGINAL GLSL SNIPPET
float dif = dot(n, normalize(vec3(1,2,3)))*.5+.5;
vec3 col = vec3(dif);
CONVERTED HLSL SNIPPET(?)
float dif = dot(n, normalize(float3(1,2,3)))*.5+.5;
float3 col = float3(dif, dif, dif); <— Is this correct way to do it? OR
float3 col = float3(dif, 0, 0); <— Is this correct way to do it?
How do you slow down a shader, it was running so fast it was hard to tell if it was working or not.
(the previous fix worked, but it was animating so fast it was hard to tell)
Additional note: instead of replace “vec” with “float” , in HLSL we can define own data types, so you can write following instruction: typedef vector <float, 2> vec2; typedef vector <float, 3> vec3;
Additional note: instead of replace “vec” with “float” , in HLSL we can define own data types, so you can write following instruction: typedef vector <float, 2> vec2; typedef vector <float, 3> vec3;
I like this idea, because you can go back and forth when having trouble doing conversion.
So if I have trouble, rename the file as GLSL, and try that in the GLSL preview, to see if changes broke the GLSL version, without having to re=replace floats back to vecs.
Here’s a question, for most shaders, it makes sense to use a plane, and display the shader on a plane for a nice effect.
But I was wondering if it would be complicated to make the effect exist in 3D space itself?
For example, I have a shader (made up example)…
I did the whole conversion process and got it to work…
The shader has a cube that morphs back and forth from a cube to a sphere…
Now I can do all this, and use it as a material on a 2D plane…and it works of course.
But how hard would it be to make this a real 3D entity in the scene view?
So a player could walk around it etc…and view it…
So instead of a cube morphing back and forth, on a 2D plane…
It is morphing in the 3D space of the scene itself.
Would this be complicated to achieve?
Set Main Camera to following position (0,50,0).
In Unity3D editor, add 3D Object/Quad as child object to Main Camera, then bind material with shader to the quad. Set quad position at (x=0 ; y=0; z=0.4 ).
Add CameraController to Main Camera. Play.
Has anyone used glscc for converting glsl to hlsl? I haven’t quite gotten it to work right, so not sure if it’s been updated recently. Seems to be a couple up-to-date tools for hlsl-to-glsl conversion, but having trouble locating one that works for other direction.