Jump to content

havenphillip

Members
  • Posts

    550
  • Joined

  • Last visited

Everything posted by havenphillip

  1. Actually I had messed with the above shader before. Here's some variation of it. I don't even remember what I did to this but sometimes a comparison can help. And the vertex part of the shader is the same: //Fragment #version 400 #define BFN_ENABLED 1 //Uniforms uniform sampler2D texture0;//diffuse map uniform sampler2D texture1;//light map uniform vec4 materialcolorspecular; uniform vec4 lighting_ambient; uniform samplerCube texture15; uniform int decalmode; uniform float materialroughness; uniform float currenttime; float time = currenttime/1000; //Inputs in vec2 ex_texcoords0; in vec4 ex_color; in float ex_selectionstate; in vec3 ex_VertexCameraPosition; in vec3 ex_normal; in vec3 ex_tangent; in vec3 ex_binormal; in float clipdistance0; out vec4 fragData0; out vec4 fragData1; out vec4 fragData2; out vec4 fragData3; const float PI = 3.1415926535897932; // play with these parameters to custimize the effect // =================================================== //speed const float speed = 0.1; const float speed_x = 0.2; const float speed_y = 0.2; // refraction const float emboss = 0.50; const float intensity = 2.9; const int steps = 2; const float frequency = 18.0; const int angle = 5; // better when a prime // reflection const float delta = 55.; const float intence = 700.; const float reflectionCutOff = 0.012; const float reflectionIntence = 200000.; // =================================================== float rand(float s) { float r = fract(6.2 - 3.14); float p = floor(30.0); for (float i=0; i < 4.0; i++) { r = r/r/r* sin(p); s = (r*2.0)/p; } return s; } float col(vec2 coord,float time) { float delta_theta = 2.0 * PI / float(angle); float col = 0.0; float theta = 0.0; for (int i = 0; i < steps; i++) { vec2 adjc = coord; theta = delta_theta*float(i); adjc.x += cos(theta)*time*speed + time * speed_x; adjc.y -= sin(theta)*time*speed - time * speed_y; col = col + cos( (adjc.x*cos(theta) - adjc.y*sin(theta))*frequency)*intensity; col *= vec4(1.0,1.0,1.0,0.5).r; } return cos(col); } //---------- main void main() { float time = time*0.5; vec2 p = ex_texcoords0.xy, c1 = p, c2 = p; float cc1 = col(c1,time); c2.x += ex_texcoords0.x; float dx = emboss*(cc1-col(c2,time))/delta; c2.x = p.x; c2.y += ex_texcoords0.y; float dy = emboss*(cc1-col(c2,time))/delta; c1.x += dx*2.; c1.y = -(c1.y+dy*2.); float alpha = 1.+dot(dx,dy)*intence; float ddx = dx - reflectionCutOff; float ddy = dy - reflectionCutOff; if (ddx > 0. && ddy > 0.) alpha = pow(alpha, ddx*ddy*reflectionIntence); #define amp 0.005 vec2 tc = ex_texcoords0; tc -= 0.5; vec2 p2 = -1.0 + 4.0 * tc; float len = length(p)*sin(3.0); c1 += tc + (p2/len)*cos(len*10.0-time*3.0)*rand(len)-p2; c1 += ((vec2(.5)-texture(texture0, c1*0.3+vec2(time/7.0*0.9, sin(time)/7.0*0.25)).xy)*amp + (vec2(p2)-texture(texture0, c1*0.3-vec2(-time/5.0*0.25, time/5.0*0.025)).xy)*amp); //vec4 col = texture(texture0,uv); vec4 col = texture(texture0,c1)*(alpha); fragData0 = col; } //vertex #version 400 #define MAX_INSTANCES 256 //Uniforms uniform vec4 materialcolordiffuse; uniform mat4 projectioncameramatrix; uniform mat4 camerainversematrix; uniform instancematrices { mat4 matrix[MAX_INSTANCES];} entity; uniform vec4 clipplane0 = vec4(0.0); //Attributes in vec3 vertex_position; in vec4 vertex_color; in vec2 vertex_texcoords0; in vec3 vertex_normal; in vec3 vertex_binormal; in vec3 vertex_tangent; //Outputs out vec4 ex_color; out vec2 ex_texcoords0; out float ex_selectionstate; out vec3 ex_VertexCameraPosition; out vec3 ex_normal; out vec3 ex_tangent; out vec3 ex_binormal; out float clipdistance0; void main() { mat4 entitymatrix = entity.matrix[gl_InstanceID]; mat4 entitymatrix_=entitymatrix; entitymatrix_[0][3]=0.0; entitymatrix_[1][3]=0.0; entitymatrix_[2][3]=0.0; entitymatrix_[3][3]=1.0; vec4 modelvertexposition = entitymatrix_ * vec4(vertex_position,1.0); //Clip planes if (length(clipplane0.xyz)>0.0001) { clipdistance0 = modelvertexposition.x*clipplane0.x + modelvertexposition.y*clipplane0.y + modelvertexposition.z*clipplane0.z + clipplane0.w; } else { clipdistance0 = 0.0; } ex_VertexCameraPosition = vec3(camerainversematrix * modelvertexposition); gl_Position = projectioncameramatrix * modelvertexposition; //mat3 nmat = mat3(camerainversematrix[0].xyz,camerainversematrix[1].xyz,camerainversematrix[2].xyz);//39 //nmat = nmat * mat3(entitymatrix[0].xyz,entitymatrix[1].xyz,entitymatrix[2].xyz);//40 mat3 nmat = mat3(entitymatrix); ex_normal = normalize(nmat * vertex_normal); ex_tangent = normalize(nmat * vertex_tangent); ex_binormal = normalize(nmat * vertex_binormal); ex_texcoords0 = vertex_texcoords0; ex_color = vec4(entitymatrix[0][3],entitymatrix[1][3],entitymatrix[2][3],entitymatrix[3][3]); //If an object is selected, 10 is subtracted from the alpha color. //This is a bit of a hack that packs a per-object boolean into the alpha value. ex_selectionstate = 0.0; if (ex_color.a<-5.0) { ex_color.a += 10.0; ex_selectionstate = 1.0; } ex_color *= vec4(1.0-vertex_color.r,1.0-vertex_color.g,1.0-vertex_color.b,vertex_color.a) * materialcolordiffuse; }
  2. So let's say you want this Shadertoy shader but you want to use it on a model. Luckily this is pretty easy to do as well. Just a couple changes: First change is you need model shader vertex information. Probably the best one to use for this kind of thing in general is the Leadwerks "diffuse + normal + specular" shader. The steps: Copy/Paste all of the vertex information from Leadwerks' "diffuse + normal + specular" shader to the vertex part of your shader. Copy paste everything above the "main" from Leadwerks' "diffuse + normal + specular" fragment shader to your fragment shader (don't erase the variables from the shadertoy shader!). Change anything that says "gl_FragCoord.xy/buffersize.xy" or anywhere it says "buffersize" to your texture coordinates instead. This is an "in vec2" from your vertex. It's something like "in vec2 vTexCoords0" or "in vec2 ex_texcoords0." (for the super-noobs: notice that all the outputs that go "out" from vertex also have to come "in" to the fragment shader). Remember I mentioned you want to change the "texture1" from the post-effect shader to "texture0" for the model shader. "texture0" is the diffuse texture slot. "texture1" is the normals. If you leave it as "texture1" still it's going to look like the normals rather than the diffuse. Find a material, double click it and set the shader to the material in the Material Editor/shaders. //--------------------------------------------------------------------------------------------------------------------- That's the gist of it. There's more you can do like add all the normal and specular fragment information in but I'm too lazy to do it and you can probably figure it out. Mostly just a lot of copy/pasting. Here's the working Leadwerks equivalent of this MODEL shader. You can see it wobbling the texture around. See if you can do it before you look at the answer: https://www.shadertoy.com/view/4slGRM //Fragment #version 400 #define BFN_ENABLED 1 //https://www.shadertoy.com/view/4slGRM //Uniforms uniform sampler2D texture0;//diffuse map uniform sampler2D texture1;//normal map uniform sampler2D texture2;//specular map uniform vec4 materialcolorspecular; uniform vec4 lighting_ambient; uniform samplerCube texture15; uniform vec2 camerarange; uniform vec2 buffersize; uniform float camerazoom; uniform int decalmode; uniform float materialroughness; uniform float currenttime; float time = currenttime/1000; //Inputs in vec2 ex_texcoords0; in vec4 ex_color; in float ex_selectionstate; in vec3 ex_VertexCameraPosition; in vec3 ex_normal; in vec3 ex_tangent; in vec3 ex_binormal; in float clipdistance0; //Outputs out vec4 fragData0; out vec4 fragData1; out vec4 fragData2; out vec4 fragData3; // Simple Water shader. (c) Victor Korsun, bitekas@gmail.com; 2012. // // Attribution-ShareAlike CC License. #ifdef GL_ES precision highp float; #endif float PI = 3.1415926535897932; // play with these parameters to custimize the effect // =================================================== //speed float speed = 0.2; float speed_x = 0.3; float speed_y = 0.3; // refraction float emboss = 0.50; float intensity = 2.4; int steps = 8; float frequency = 6.0; int angle = 7; // better when a prime // reflection float delta = 60.; float intence = 700.; float reflectionCutOff = 0.012; float reflectionIntence = 200000.; // =================================================== float col(vec2 coord,float time) { float delta_theta = 2.0 * PI / float(angle); float col = 0.0; float theta = 0.0; for (int i = 0; i < steps; i++) { vec2 adjc = coord; theta = delta_theta*float(i); adjc.x += cos(theta)*time*speed + time * speed_x; adjc.y -= sin(theta)*time*speed - time * speed_y; col = col + cos( (adjc.x*cos(theta) - adjc.y*sin(theta))*frequency)*intensity; } return cos(col); } //---------- main void main() { time *= 1.3; vec2 p = ex_texcoords0, c1 = p, c2 = p; float cc1 = col(c1,time); c2.x += ex_texcoords0.x/delta; float dx = emboss*(cc1-col(c2,time))/delta; c2.x = p.x; c2.y += ex_texcoords0.y/delta; float dy = emboss*(cc1-col(c2,time))/delta; c1.x += dx*2.; c1.y = -(c1.y+dy*2.); float alpha = 1.+dot(dx,dy)*intence; float ddx = dx - reflectionCutOff; float ddy = dy - reflectionCutOff; if (ddx > 0. && ddy > 0.) alpha = pow(alpha, ddx*ddy*reflectionIntence); vec4 col = texture(texture0,c1)*(alpha); fragData0 = col; } //Vertex #version 400 #define MAX_INSTANCES 256 //Uniforms uniform vec4 materialcolordiffuse; uniform mat4 projectioncameramatrix; uniform mat4 camerainversematrix; uniform instancematrices { mat4 matrix[MAX_INSTANCES];} entity; uniform vec4 clipplane0 = vec4(0.0); uniform mat4 cameramatrix; //Attributes in vec3 vertex_position; in vec4 vertex_color; in vec2 vertex_texcoords0; in vec3 vertex_normal; in vec3 vertex_binormal; in vec3 vertex_tangent; //in vec4 vertex_boneweights; //in ivec4 vertex_boneindices; //Outputs out vec4 ex_color; out vec2 ex_texcoords0; out float ex_selectionstate; out vec3 ex_VertexCameraPosition; out vec3 ex_normal; out vec3 ex_tangent; out vec3 ex_binormal; out float clipdistance0; void main() { mat4 entitymatrix = entity.matrix[gl_InstanceID]; mat4 entitymatrix_=entitymatrix; entitymatrix_[0][3]=0.0; entitymatrix_[1][3]=0.0; entitymatrix_[2][3]=0.0; entitymatrix_[3][3]=1.0; vec4 modelvertexposition = entitymatrix_ * vec4(vertex_position,1.0); //Clip planes if (length(clipplane0.xyz)>0.0001) { clipdistance0 = modelvertexposition.x*clipplane0.x + modelvertexposition.y*clipplane0.y + modelvertexposition.z*clipplane0.z + clipplane0.w; } else { clipdistance0 = 0.0; } ex_VertexCameraPosition = vec3(camerainversematrix * modelvertexposition); gl_Position = projectioncameramatrix * modelvertexposition; mat3 nmat = mat3(entitymatrix); ex_normal = normalize(nmat * vertex_normal); ex_tangent = normalize(nmat * vertex_tangent); ex_binormal = normalize(nmat * vertex_binormal); ex_texcoords0 = vertex_texcoords0; ex_color = vec4(entitymatrix[0][3],entitymatrix[1][3],entitymatrix[2][3],entitymatrix[3][3]); //ex_color = vec4(vertex_boneindices[0]) * 60.0; //If an object is selected, 10 is subtracted from the alpha color. //This is a bit of a hack that packs a per-object boolean into the alpha value. ex_selectionstate = 0.0; if (ex_color.a<-5.0) { ex_color.a += 10.0; ex_selectionstate = 1.0; } ex_color *= vec4(1.0-vertex_color.r,1.0-vertex_color.g,1.0-vertex_color.b,vertex_color.a) * materialcolordiffuse; } Shaderfrog next....
  3. So someone asked for a tutorial on this so here goes. I wouldn't consider myself much of a coder, but luckily translating these over to Leadwerks isn't hard to do. I don't know why all of it works the way it does but here's a go: Shadertoy shaders are all post-effect shaders, so you can just use the vertex information from any Leadwerks post-effect shader with it. And there's no "in/out" variables so really none of it has to do with the vertex information. You have to use a certain language with some things in Leadwerks (I think Josh posted a list somewhere around here maybe if you know where it is you could drop it in this thread). Leadwerks understands "uniform vec3 cameraposition" for instance, but not " uniform vec3 cameraPosition" (with a capital P). Here's a checklist of things I always see, the equivalencies from Shadertoy: iResolution = use "buffersize" iChannel0 = use "texture0" (and so on with textures. In the post-effect you want to use texture1 instead. As a model shader you want texture0. You might have to mess with it a bit) fragCoord.xy = use "gl_FragCoord.xy" iTime = currenttime (then float time = currenttime/1000;) // and use "time" fragColor = use "fragData0" (I think you can use fragColor as long as you have it as a vec4 out. You have to tell the shader what the output is. I just write "out vec4 fragData0" before the "main" somewhere ) void mainImage( out vec4 fragColor, in vec2 fragCoord ) = just use "void main ()" //--------------------------------------------------------------------------------------------------------------------- So you want Leadwerks post-effect vertex information, and at the top of your fragment shader you want all this information: uniform float currenttime; float time = currenttime/1000; uniform vec2 buffersize; uniform sampler2D texture0; uniform sampler2D texture1; out vec4 fragData0; Edit: first things first: Make sure you put at the top of your fragment shader as the very first two lines: #version 400 #define BFN_ENABLED 1 ... and at the top of your vertex: #version 400 #define MAX_INSTANCES 256 //--------------------------------------------------------------------------------------------------------------------- Then go through and change all the language as necessary. Hopefully I didn't miss anything. Sometimes you'll see "iMouse" on Shadertoy and I've never really messed with that but I think you can get away with just inserting a "vec2(1,1)" in it's place. One thing that messed me up at first was seeing this: " *= " or " += " , " -= " , and " /= " . That's just a simplified way to multiply, or add etc. So in Lua you might write: "time = time * 1.3". In GLSL you can just say "time *= 1.3". Also while I'm going through a shader conversion I'll get rid of anything that says "uniform " or "const" or "highp" before it (only on the Shadertoy variables, though) because for whatever reason those will just default to zero or something. And if you write a shader and want to access your variables from a script, you want to use "uniform" and then adjust the values in the script. I don't know why this is. (For the super-noob: to see a post-effects shader go to the "Scene" tab, click "Root" then find the Post-Effects box and click "Add") Here's the working Leadwerks equivalent of this shader. See if you can do it before you look at the answer: https://www.shadertoy.com/view/4slGRM //Fragment #version 400 //https://www.shadertoy.com/view/4slGRM out vec4 fragData0; uniform float currenttime; float time = currenttime/1000; uniform vec2 buffersize; uniform sampler2D texture0; uniform sampler2D texture1; uniform sampler2D texture2; uniform sampler2D texture3; // Simple Water shader. (c) Victor Korsun, bitekas@gmail.com; 2012. // // Attribution-ShareAlike CC License. #ifdef GL_ES precision highp float; #endif float PI = 3.1415926535897932; // play with these parameters to custimize the effect // =================================================== //speed float speed = 0.2; float speed_x = 0.3; float speed_y = 0.3; // refraction float emboss = 0.50; float intensity = 2.4; int steps = 8; float frequency = 6.0; int angle = 7; // better when a prime // reflection float delta = 60.; float intence = 700.; float reflectionCutOff = 0.012; float reflectionIntence = 200000.; // =================================================== float col(vec2 coord,float time) { float delta_theta = 2.0 * PI / float(angle); float col = 0.0; float theta = 0.0; for (int i = 0; i < steps; i++) { vec2 adjc = coord; theta = delta_theta*float(i); adjc.x += cos(theta)*time*speed + time * speed_x; adjc.y -= sin(theta)*time*speed - time * speed_y; col = col + cos( (adjc.x*cos(theta) - adjc.y*sin(theta))*frequency)*intensity; } return cos(col); } //---------- main void main() { time *= 1.3; vec2 p = (gl_FragCoord.xy) / buffersize.xy, c1 = p, c2 = p; float cc1 = col(c1,time); c2.x += buffersize.x/delta; float dx = emboss*(cc1-col(c2,time))/delta; c2.x = p.x; c2.y += buffersize.y/delta; float dy = emboss*(cc1-col(c2,time))/delta; c1.x += dx*2.; c1.y = -(c1.y+dy*2.); float alpha = 1.+dot(dx,dy)*intence; float ddx = dx - reflectionCutOff; float ddy = dy - reflectionCutOff; if (ddx > 0. && ddy > 0.) alpha = pow(alpha, ddx*ddy*reflectionIntence); vec4 col = texture(texture1,c1)*(alpha); fragData0 = col; } //Vertex (straight outta leadwerks) #version 400 uniform mat4 projectionmatrix; uniform mat4 drawmatrix; uniform vec2 offset; uniform vec2 position[4]; in vec3 vertex_position; void main(void) { gl_Position = projectionmatrix * (drawmatrix * vec4(position[gl_VertexID]+offset, 0.0, 1.0)); } More to come....
  4. Yeah that would be cool. I've seen ripple shaders and footprint shaders. The problem, I would think, is how to pick up the footsteps or raindrops.
  5. That's awesome, dude. That's how it goes for me. Just keep hacking it until you get something. The more time you spend changing numbers and values the more you understand it. Some resources you could investigate. Tons of shaders here. Flipping them over to Leadwerks isn't that hard: https://shaderfrog.com/app/ https://www.shadertoy.com/
  6. I think if I can figure this thing out I might be able to add foam at least. I do wonder how those big waves are created. Maybe vertex displacement or something.
  7. I've been meaning to pull the water shader apart to see how it works. I guess now is as good a time as any. Anything I should take note of specifically to get what I'm looking for like the fog or the amplitude or something?
  8. What about this? The foam around the rocks suggests to me that there is a way for the plane to "know" the shape of the things intersecting it. The question is what part of the shader knows that? http://fire-face.com/personal/water/
  9. I don't suppose you have a snippet that shows how to do this?
  10. Man I'm always in over my head. Sounds like what you're saying is a fresnel and using the DepthToZPosition that is in your water shader with vec3 screencoord? That's what I think I want. The problem I'm having is with the parallax shader. When I set things on it they look like they're floating above it. The rock highs and lows don't interact with like a box or tree model. So if you recall you can just cut the parallax texcoords and they appear to have a 3d "beyond the geometry" look. So if I can find all the intersections of items set on the parallaxed surface I can then discard those areas to give that impression on everything. UE's Pixel Depth Offset is the closest thing I've seen to accomplish this though I'm not entirely sure this is what they're actually doing. What approach do you recommend for solving that?
  11. What I really want is to make a plane on the ground and find all the objects that are intersecting it by the space they're occupying or the "hole" they're making in the plane. Ultimately I'm trying to develop a pixel depth offset effect like Unreal has but all their tutorials are using that goofyass node system. Some of them are doing this weird thing with that force field shader where they're using a depth buffer as a texture like "texture(depthbuffer, fragcoords);" What's the LE equivalent of that? Bounding boxes are probably good for finding the area but seems like a lot to do just to discard that space.
  12. Ok bounding boxes. Perfect. I'll start reading up on them.
  13. I just need to be pointed in the right direction is all. What's the term I should look up? Depth intersection? Something like that?
  14. I was thinking shaders but I'm not entirely opposed to Lua if I could get it to work. I'm looking at the forcefield shader I keep seeing all around the internet. It draws a line where the two intersect. https://cyangamedev.wordpress.com/2019/09/04/forcefield-shader-breakdown/
  15. Did you ever finish this? I was looking forward to it.
  16. ...or where can I find out how to do this? What's the term I should look up?
  17. Made a silhouette shader using geometry based on this idea of duplicating the mesh. It's got some bugs in it but I got the basic thing. Silhouette.zip http://wiki.unity3d.com/index.php/Silhouette-Outlined_Diffuse
  18. What makes this impractical for game development, out of curiosity? Seems like they're going to attempt to make games out of it.
  19. Trying to make this toon shader. It's compiling but I'm seeing nothing. https://prideout.net/blog/old/blog/index.html@tag=opengl-silhouette.html
  20. You got them sharper dude I can tell. They look real.
×
×
  • Create New...