Wings 3D Development Forum
AutoUV shaders [updated: 05/13/2020] - Printable Version

+- Wings 3D Development Forum (https://www.wings3d.com/forum)
+-- Forum: Wings 3D (https://www.wings3d.com/forum/forumdisplay.php?fid=1)
+--- Forum: Interface & Usage (https://www.wings3d.com/forum/forumdisplay.php?fid=3)
+--- Thread: AutoUV shaders [updated: 05/13/2020] (/showthread.php?tid=1433)

Pages: 1 2 3 4 5 6


RE: AutoUV shaders [updated: 10/29/2015] - micheus - 11-23-2015

You can try to compare the original code and the one I adapted for Wings3d, so you will find what you did wrong.

I can't tell you much about that just because it's new to me too. I can just point some things to be observed:
- you need to know a little of C language since GLSL language is very close to it;
- Wings3d uses 2D and 3D shaders and you will find a sample of 3D shader in Noise and in the others you will find how to work with 2D shader;
- in the Vertex Fragment (*.vf) files you work with UV coordinates [0,1], so one textel is not the same as one pixel in the image;
- I first modified the code in the online page replacing the future Wings3d parameters for constants or initialized variables. After I get it working I create the *.vf and *.auv to use the new code;
- if you don't know the algorithm used, you will need to play with some variables and observe what happens in order to try to understand it and make the changes/adaptations where they need to be done.

Good luck. Wink


RE: AutoUV shaders [updated: 10/29/2015] - Kagehi - 12-04-2015

Yeah. Tried a different and much more interesting one.

http://glslsandbox.com/e#29078.0

Rechecked the ones you used and replaced the resolution bit with the auv one that you used, set up the time as a slider (though I have no clue whether time runs from 0.0 to 1.0, or if its like seconds passed, but I tried just replacing it with 0.1 at one point...

Yeah.. Have no clue what I am screwing up... Will post the modded code here, maybe you can figure out what is bugged, and we can both learn something. lol

Code:
uniform float time; %% Tried just setting this to 0.1, but current version uses a slider.
uniform vec2 auv_texsz; %%Replaced here so it uses the Wings native resolution thing?

vec3 roty(vec3 p,float a){return p*mat3(cos(a),0,-sin(a),0,1,0,sin(a),0,cos(a));}

float map(in vec3 p) {
    float res=0.;vec3 c = p;
    for (int i = 0; i < 10; i++) {
        p =0.9*abs(p)/dot(p,p) -.7;
        p.yz= vec2(p.y*p.y-p.z*p.z,2.*p.y*p.z);
        res += exp(-20. * abs(dot(p,c)));}
    return res/2.0;}

vec3 raymarch(vec3 ro, vec3 rd){
    float t = 4.0;
    vec3 col=vec3(0.);float c=0.;
    for( int i=0; i<64; i++ ){
        t+=0.02*exp(-2.0*c);
        c = map(ro+t*rd);              
        col += vec3(c/2.0,c*c*c,c)/10.0;}    
    return col;}

void main(){
    vec2 p = (gl_FragCoord.xy-auv_texsz.xy/2.0)/(auv_texsz.y);
    vec3 ro = roty(vec3(3.),time*0.3);
    vec3 uu = normalize( cross(ro,vec3(0.0,1.0,0.0) ) );
    vec3 vv = normalize( cross(uu,ro));
    vec3 rd = normalize( p.x*uu + p.y*vv -ro*0.3 );
    gl_FragColor.rgb = 0.5*log(1.0+raymarch(ro,rd));}

Code:
{name, "Test"}.                  % The name in the shader selector
{vertex_shader, "standard.vs"}.     % Vertex shader used
{fragment_shader, "test_shader.fs"}.    % Fragment shader used
{auv, auv_texsz}.                   % vec2 width and height
{uniform, {slider,0.0,4.0}, "time", 0.1, "Time"}.

Obviously, the two things missing here that you normally have with code is a) error checking, and b) reports on crashes/what is actually happening. :p This is like.. throwing things at a black box and wondering, "WTF?" lol

In any case, both my attempts to do this resulted in -- totally blank textures, as in no image and 100% transparent. Just weird...


RE: AutoUV shaders [updated: 10/29/2015] - micheus - 12-04-2015

Yeah, that is a nice shader (another in my list too. Smile)

You jumped over one of my "tips". Check the console log:
Quote:Trying OpenGL modes
[{buffer_size,32},{depth_size,32},{stencil_size,8},{accum_size,16}]
Actual: RGBA: 8 8 8 8 Depth: 24 Stencil: 8 Accum: 16 16 16 16
Using GPU shaders.
Using GPU shaders.
AUV: Error Couldn't read file: f:/Program Files/wings3d_1.5.4/lib/wings-1.5.4/plugins/autouv/test_shader.fs
AUV: Edge Filter ok
AUV: No shader program found skipped 844
w h: 7 14
Info: Fragment:
WARNING: 0:1: '%' : symbol not available in current GLSL version
ERROR: 0:1: '%' : syntax error parse error


AUV: Error Compilation failed
AUV: Edge Filter ok
AUV: No shader program found skipped 844
You used '%' for the comment in the GLSL file - my tip you ignorede: "- you need to know a little of C language since GLSL language is very close to it;"
Comments in C:
- one line: // here come the one line comment
- many lines: /* here come
the block of lines
to be commented
*/


Reading the message:
- Info: Fragment:
That inform where the error occurred: Fragment shader - the file with .fs extension; If you see Vertex, then you need to look into the Vertex shader file (.vs);

- WARNING: 0:1: '%' : symbol not available in current GLSL version
ERROR: 0:1: '%' : syntax error parse error

That 0:1: for warning and/or error means the line number where you need to check the problem.

If you see a typical Erlang message on the console, that means you probably need to look into the .auv file.
______

Those variable in the top that begin with uniform are parameters, so they come from somewhere. At that site the time must be a parameter made available by its API.

In the code you can notice that time is used to define a rotation angle around Y. So, you can set your slider to allow you to select a value between 0.0-360.0 degrees (a more understandable value). This value must be converted to radians that is the correct value used with the trigonometric functions.

you can add this const to the begin of the file (after the variable declarations):
#define pi 3.14159265359;
and, by considering you change the time variable name to angle (a more appropriated name), you can replace:
vec3 ro = roty(vec3(3.),time*0.3);
with:
float a = angle/360.0 * 2.0*pi;
vec3 ro = roty(vec3(3.),a);



RE: AutoUV shaders [updated: 10/29/2015] - Kagehi - 12-04-2015

Well, actually.. I used the % in there in this post. The original attempt didn't have it. lol But, yeah. Didn't think about the console thing. Hmm. Will look at the other issues when I get back home from work. :p


RE: AutoUV shaders [updated: 10/29/2015] - Kagehi - 12-05-2015

Ok.. After few hickups..

Code:
{name, "Test"}.                  % The name in the shader selector
{vertex_shader, "standard.vs"}.     % Vertex shader used
{fragment_shader, "test_shader.fs"}.    % Fragment shader used
{auv, auv_texsz}.                   % vec2 width and height

{uniform, {slider,0.0,360.0}, "angle", 0.0, "Angle"}.

Code:
#define pi 3.14159265359;

uniform float angle;
uniform vec2 auv_texsz;

vec3 roty(vec3 p,float a){return p*mat3(cos(a),0,-sin(a),0,1,0,sin(a),0,cos(a));}

float map(in vec3 p) {
    float res=0.;vec3 c = p;
    for (int i = 0; i < 10; i++) {
        p =0.9*abs(p)/dot(p,p) -.7;
        p.yz= vec2(p.y*p.y-p.z*p.z,2.*p.y*p.z);
        res += exp(-20. * abs(dot(p,c)));}
    return res/2.0;}

vec3 raymarch(vec3 ro, vec3 rd){
    float t = 4.0;
    vec3 col=vec3(0.);float c=0.;
    for( int i=0; i<64; i++ ){
        t+=0.02*exp(-2.0*c);
        c = map(ro+t*rd);              
        col += vec3(c/2.0,c*c*c,c)/10.0;}    
    return col;}

void main(){
    vec2 p = (gl_FragCoord.xy-auv_texsz.xy/2.0)/(auv_texsz.y);
    //vec3 ro = roty(vec3(3.),time*0.3);
    float a = angle/360.0 * 2.0*pi;
    vec3 ro = roty(vec3(3.),a);
    vec3 uu = normalize( cross(ro,vec3(0.0,1.0,0.0) ) );
    vec3 vv = normalize( cross(uu,ro));
    vec3 rd = normalize( p.x*uu + p.y*vv -ro*0.3 );
    gl_FragColor.rgb = 0.5*log(1.0+raymarch(ro,rd));}

Result =
AUV: Test ok

No errors, but also.. no texture. Also... did figure out that part of my issue was that I have more than one install of Wings, since the mlab one, as well as the other one, insists on installing "new" versions into unique folders every time, instead of something sensible (and thus predictable). Was trying to edit the wrong copies... Sigh... lol

Still, editing the right ones.. still didn't get me any place.

Actually. That might be easy to fix. Modern copies of windows don't like people playing with the stuff in the program folders anyway. So, seems to me that there should be a plugin folder in "Documents" for each user as well, to be consistent with other applications. And, as long as it "shared" the name of this folder, editing things in it should effect "all" copies of Wings, regardless of version.

Anyway. With the above changes it seems to compile, but.. still not do anything. Might it be setting the "alpha" to full transparency, since its only using the RGB values? Or does it default to fully visible, unless you tell it otherwise? Only thing I can think of at this point.


RE: AutoUV shaders [updated: 10/29/2015] - micheus - 12-05-2015

That is interesting, because I made it work yesterday just fixing the comment in the fragment shader (.fs) file. I'm going to send you the files late, so you can test them.

About to play with content without have problems with the access rights, you can:
- install Wings3d other than programs files folder;
- if you have the v. 2.0.? Installed, it's "portable", so it means you can copy the installed version to anywhere and it still will work without to need any tweaking.
- you can start you editor using the context menu option "Run as Administrator " (or something like this - my Windows runs in Portuguese). This way it will be able to write to that folder.


Updated: here is the result and the files attached.

[Image: shader-test.png]


RE: AutoUV shaders [updated: 10/29/2015] - Kagehi - 12-05-2015

Bangs head on desk... Ok, no idea wtf is going on here. All of the stuff I previously installed that you did worked. This one.. no matter what I do, or where I put it, doesn't... I can't comprehend it, like, at all... Its crazy. And you are right, other than a few note lines, and some white space differences, there is no real difference between your version and mine... I just can't comprehend it.


RE: AutoUV shaders [updated: 10/29/2015] - micheus - 12-05-2015

Could you try these files I attached? Did they work?
If so, you can send me your files in order I can try them on my side.

Also, did you tried other "install" option as I suggested?


RE: AutoUV shaders [updated: 10/29/2015] - Kagehi - 12-06-2015

... Thought I had it worked out. Noticed that the files seem to have permissions for Admin, SYSTEM, Users, but not my account, so, set them to also work with my account. And.. still not working.

Tried to run Wings as Admin, no dice.

Also, I did a direct replacement of my files with your files, so.. no reason that shouldn't work.

Trying your suggesting, since I need to upgrade my copy of Wings to the latest build anyway. Unzipped your files to the new place. And, tried again. Same result.

I looked in the system registry, in case something odd was in there. Nothing.

Considering looking in the prefs, to see what might be up in there, but can't see that doing it (though, this one confuses me, because the main Wings opens full screen, but the other one doesn't, and I have no clue how I got the first one to do that, but the second one won't, or even if that is "in" the preferences file. So, something is different there, but.. why it would effect this shader, or even my prior attempt at one..

Ok, had a brief hickup due to not having copied the "standard.vs" file over to the folder for the new copy. Now the old ones I got from you work, but.. again, the new one doesn't. Before copying that file, they didn't either.

Wow.. something damn strange going on. The new manifold version crashes when trying to pick a color for me, and half the shaders just stopped working at all in it after a few attempts to play with them. Could having more than one version installed be doing this?

Hmm. Nope, that isn't it either. Trying the new official build.

And.. still no dice, either the 32 or 64 bit one. It can't be my machine having some issue with this shader. I suppose there might be something being "saved" by windows, and attached to Wings that is doing it, but for the life of me I can't imagine what. I am baffled at this point.


RE: AutoUV shaders [updated: 10/29/2015] - Kagehi - 12-08-2015

Hmm. Tried something else, i.e., a different shader. Seems my problem must be in dot(), normalize(), or cross(). One of those must not be working, because something that doesn't use them works. Also - I have Visual Studio installed, so an "updated" version of the DLL that Wings 3D needs, so.. maybe there is a compatibility issue with its GLSL implementation and the newer dll?

It is literally the only possible thing I can come up with for why it isn't working. But, the issue, based on looking at what did work, and what is in the one that didn't, has to be one of those commands.. Just wish I knew enough math to have a clue how to find which one. lol