73 lines
No EOL
2.9 KiB
Text
73 lines
No EOL
2.9 KiB
Text
Hiya Brad
|
|
Would you do me a favor please? I want to put this shadertoy shader on a skybox
|
|
https://www.shadertoy.com/view/MllXz4
|
|
shadertoy.com
|
|
Shadertoy
|
|
Build shaders, share them, and learn from the best community.
|
|
https://www.shadertoy.com/media/shaders/MllXz4.jpg
|
|
I'm trying to follow the instructions on the forum for converting shadertoy shaders to work with skyboxes but i'm having no luck
|
|
here's the current state of it:
|
|
http://hifi-content.s3.amazonaws.com/caitlyn/scratch/trippy2.fs
|
|
Can you see what I might be doing wrong and help me out?
|
|
|
|
Austin [9:21 AM]
|
|
so typically you want to start in shadertoy with a sort of equivalent to a skybox....
|
|
I have a small shader that does this.... take a look at https://www.shadertoy.com/view/lsdfW8
|
|
|
|
notice that you can use the mouse to pan around and that the image is ultimately defined in terms of the direction `d`
|
|
the most basic form of this would be:
|
|
|
|
mat3 rot(vec3 a, float b) {
|
|
a = normalize(a);
|
|
float s = sin(b);
|
|
float c = cos(b);
|
|
float d = 1.0 - c;
|
|
return mat3(d * a.x * a.x + c, d * a.x * a.y - a.z * s, d * a.z * a.x + a.y * s, d * a.x * a.y + a.z * s, d * a.y * a.y + c,
|
|
d * a.y * a.z - a.x * s, d * a.z * a.x - a.y * s, d * a.y * a.z + a.x * s, d * a.z * a.z + c);
|
|
}
|
|
|
|
float e = 2.3, p = atan(1.) * 4.;
|
|
|
|
vec3 getPixelDirection(in vec2 fragCoord) {
|
|
vec2 R = iResolution.xy, u = fragCoord / R;
|
|
vec4 m = iMouse / R.xyxx;
|
|
mat3 rmx = rot(vec3(0, 1, 0), clamp(-m.w * R.x, 0., 1.) * 3.14 / 10. + m.x * p * 2.);
|
|
rmx *= rot(cross(vec3(0, 1, 0), vec3(0, 0, 1) * rmx), m.y * p - p / 2.);
|
|
vec3 d = normalize(vec3((u * 2. - 1.) * vec2(iResolution.x / iResolution.y, 1), 1)) * rmx;
|
|
return d;
|
|
}
|
|
|
|
|
|
void mainImage( out vec4 fragColor, in vec2 fragCoord )
|
|
{
|
|
vec3 d = getPixelDirection(fragCoord);
|
|
fragColor = vec4(d, 1.0);
|
|
}
|
|
|
|
if you make a shader with that, you can get a basic colorbox
|
|
|
|
if you define a function `vec3 getOutput(vec3 d)` you can replace the last line above with `fragColor = vec4(getOutput(d), 1.0);` and start fiddling with the implementation of `getOutput`
|
|
now the shader you've provided is designed for 2D display.... ultimately all the real interesting logic is in `myoutput` it takes the fragCoord, converts it to a uv coord and then uses that to populate two values, dist and angle
|
|
dist and angle are the actual inputs to the rest of the function. so i can dump the beginning of `myoutput` and replace it with this...
|
|
|
|
vec4 myoutput( vec2 spherical )
|
|
{
|
|
float dist = spherical.y;
|
|
float angle = spherical.x;
|
|
}
|
|
|
|
now I just have to write my `getOutput` function to produce the spherical coordinates
|
|
|
|
https://www.shadertoy.com/view/MsdBD7
|
|
|
|
|
|
To adapt that to our system, you'd want a function that looks like this....
|
|
|
|
vec3 getSkyboxColor()
|
|
{
|
|
return getOutput(normalize(_normal));
|
|
}
|
|
|
|
Change `iTime` to `iGlobalTime`
|
|
|
|
Put #define iTime iGlobalTime at the top of your file. |