Jump to content

havenphillip

Members
  • Posts

    550
  • Joined

  • Last visited

Everything posted by havenphillip

  1. I'm working on this geometry shader I just want to instance a box but the instance disappears when the original goes off screen. Why does this happen? How can I fix it?
  2. It's a cool effect. Thanks to Ma-Shell for posting it. I think the only collection of shaders currently is in the workshop. I'm thinking of starting a thread where I post a shader a week for a year, 52 shaders, then putting it in the workshop so there's a collection of shaders somewhere. I'm weighing it out. Just don't know if I'm good enough. I did develop this a bit if you're looking for a whole wet look:
  3. You can also go into any material shader under the "void main ()" and write " discard; " anywhere. (and also disable "cast shadows" in the material editor then hit the save icon). void main() { discard; }
  4. Dude, you're 97?! Congrats, man. And born on Christmas Eve. I can relate. Mine's the 26th.
  5. Yeah instead of hiding it there's an invisible material you can put on it
  6. One way you could just make an invisible ramp.
  7. Well I deleted the player out of the scene and put him back in and it works fine now. Looks like the water plane has to be set up before the player is placed in the scene. Something to do with the camera order of operations or something I guess.
  8. I'm finally beginning to understand the depth projection in the Leadwerks water. I have a script set up to set the depth to a buffer (otherwise you have to turn on water mode, which I don't want to do) and it's almost working but it's shifting like crazy. When I walk around its fine but as soon as I move the camera it goes nuts. This doesn't happen with the LE water so what is different about the water mode that keeps that from happening? Is there a lua code behind the LE water somewhere or what? How do I get it to stop? Here's my code which I reduced down from an old Shadmar water function Script:Start() self.context=Context:GetCurrent() buffer2 = Buffer:Create(self.context:GetWidth(),self.context:GetHeight(),1,1,0) buffer = Buffer:GetCurrent() surface = self.entity:GetFace(0) --for brushes water = surface:GetMaterial() depth = buffer2:GetDepthTexture() water:SetTexture(depth,4) end function Script:UpdateWorld() buffer2:Enable(); self.entity:Hide(); world:Render() buffer:Enable() self.entity:Show(); end .
  9. Thanks, guys! Ok I'll put it in the workshop.
  10. Easy to use. Fast. Good realism. Has reflection, refraction, and fresnel. Variables added at the top of the shader so you can easily adjust the water color, creek speed, creek direction, ripple size, refraction amount, and fresnel intensity. I desaturated the skybox reflection in the water, and there's a subtle plane displacement in the vertex to give a rising and falling effect along the shoreline. Notes: Put the skybox texture in slot 0 on the material Disable cast shadows on material Enable z-sort on material Make a box or plane and slap the material on it creek.zip
  11. Yeah man "how it looks" is huge. It looks cool but I'm not sure what this is. It's like a tool for making programs that work with Ultra Engine? Can noobs make stuff with it?
  12. Here's a terrain model with a pixel depth offset shader with trails. I managed to figure out how to keep it from looking like things are slipping over the parallaxed surface so now you can put stuff on it. It's a little temperamental still. It doesn't like horizontal intersecting (shifts a bit. Not sure how to fix that) and the effect deteriorates with distance (which I think I can fix). But I figured out that you can get this thing quite a bit faster by shrinking all the textures except the diffuse since the parallax effect and diffuse do most of the work on realism, and I got it working on smoothed lumpy surfaces such as hills, etc. You can make your own trail pattern with a texture and use whatever trail diffuse you want and adjust the size and blend and other things. I added a bunch of variables to the shader to fiddle with so you can highly customize it or just mess with it. Notes: Put the included material on the terrain model (6 textures. The texture order is rocky soil diffuse, rocky soil normal, rocky soil smooth, rocky soil height, trails, hardpack diffuse, hardpack normal). Disable "Cast Shadows" on the material. Make sure the model has physics. I use poly mesh. Put the model in the scene and set the scale to 12*12*12 (temperamental. This is the size for the model the shader is set to work with) Put stuff on it so you can see the pixel offset effect. parallax_pixel_depth_offset.zip
  13. Ok so you should be able to go to Scene/Root/Post Effects/Add. I couldn't see much of an effect. You might have better luck.
  14. That's cool, dude. I was wondering what they were. Oxygen, stamina, health, temperature, pressure, water...??? idk
  15. Yeah man one nice thought is that everyone here was there at one point. I'm no genius and even I figured it out. Leadwerks really held up their end on the claim that this is the easiest way to learn to code games, imo.
  16. There's the API reference, which is useful if you have some familiarity with coding at all. https://www.leadwerks.com/learn?page=API-Reference Also there's a lot of examples in the workshop, and on this forum, if you do a search for something specific. One of the guys used to have a video series that was really helpful but he deleted them. There's still a few guys in here who will help out (and Josh still responds to a lot, though I can't understand half the things he says). This guy has a few tutorials. May be enough to jump start you: https://www.youtube.com/channel/UCdNkNE5acxWUf2vCEo-eOcw
  17. I really like the animation and modeling that you do. This is a great shot.
  18. Idk the only other thing I can think is maybe it has something to do with the script you're importing. Other than that maybe you can try putting your System:Print() line under the UpdateWorld() function also.
  19. I think you need " Script.cameraPlayer = entity " ?
  20. Actually I made a mistake above I multiplied the lightPosition, not the cameraposition: vec3 lightVector = normalize(lightPosition * modelvertexposition.xyz);//lightVector vec3 viewVector = normalize(cameraposition - modelvertexposition.xyz);//viewVector
  21. Here's an old Shadmar water that shows how you can manipulate a shader in lua: Create a large plane to be your water plane Attach the water.lua to the plane Drag and drop whatever your player or camera is into the "player or camera" slot apply the normals in the normals slot (you might have to manipulate the normals to get the right size It will show up when you run your game but not otherwise. But it shows how you can use lua to affect the shader Edit: Some other examples of this are in the HUD Elements in the Leadwerks workshop. Actually quite a bit but they're all post-render things. The pattern is there, though. shadmar water.zip
  22. Alright bro I put it up. Didn't take as long as I thought. It's in Technical Assistance. If there's a specific shader you're eyeballin' I'll make a walkthrough of it.
  23. I like ShaderFrog because it's all model shaders, which is my big interest at the moment. So this is the basic vertex shader in ShaderFrog: vNormal = normal; vUv = uv; vUv2 = uv2; vPosition = position; gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 ); To translate these over the "projectionMatrix = "projectioncameramatrix" in Leadwerks and the "modelViewMatrix" = " entitymatrix." "position" = "vertex_position" in Leadwerks. If you try to use this, however, it won't work. For whatever reason the matrixes aren't there. The Leadwerks vertex shader is superior anyway so again I just use that and rarely bother with ShaderFrog shaders that are heavy on vertex changes. Good to know, though, if you want to do something like a vertex displacement shader or something. ShaderFrog has some shaders that are called "composed shaders" and you can't really use those - (or at least I can't) because they're made with nodes using other ShaderFrog shaders. But often you can find a regular shader that is similar to a composed one. Let's do this rim lighting shader: https://shaderfrog.com/app/view/2716?view=shader //--------------------------------------------------------------------------------------------------------------------- The steps are similar to Shadertoy shaders: Copy/paste the vertex part of the "diffuse+normal+specular" to your vertex. You notice a line that says "vec4 modelvertexposition = entitymatrix_ * vec4(vertex_position, 1.0);"? Erase "vec4" so that it just says "modelvertexposition = entitymatrix_ * vec4(vertex_position, 1.0);" and instead under your Outputs section write "out vec4 modelvertexposition" Copy/paste everything above "void main ()" from the fragment part of the "diffuse+normal+specular" to your shader. Under the "Inputs" section write "in vec4 modelvertexposition". Now you're passing "modelvertexposition" from your vertex to fragment shader. Copy/paste the fragment part of the ShaderFrog shader under the information in the previous step into your fragment shader. At this point you should have a vertex shader from Leadwerks and a bunch of variables from Leadwerks in the fragment shader, and your entire "void main()" from ShaderFrog and a few variables from ShaderFrog (that may say "uniform" in front of them and you don't want that because you want to adjust them yourself). Sort of this weird hybrid shader that doesn't work at all. //--------------------------------------------------------------------------------------------------------------------- Maybe the best thing to do at this point is break this shader down line by line. It's a bit tedious but once you confront these problems a few times you can do it fast: The first line of this shader is: vec3 worldPosition = ( modelMatrix * vec4( vPosition, 1.0 )).xyz; I don't know why they do it this way but this line here is the same as this line in the Leadwerks vertex shader: modelvertexposition = entitymatrix_ * vec4(vertex_position, 1.0); So you don't need it. You can delete it. Instead of "worldPosition" just use the "modelvertexposition" that you passed from the vertex shader. One thing to note is that "modelvertexposition" Is a vec4 and "worldPosition" is a vec3. The fix is simple. Whenever you need "modelvertexposition" as a vec3 just use "modelvertexposition.xyz" Also, if at some point you need to change a vec3 to a vec4 you can do that by adding an arbitrary "1.0" to the end of it. For instance "vec3 worldPosition" as a vec4 is simply "vec4(worldPosition,1.0)". The next line is: vec3 worldNormal = normalize( vec3( modelMatrix * vec4( vNormal, 0.0 ) ) ); This is also done already in the Leadwerks vertex shader here. ShaderFrog doesn't use the tangents and binormals I guess, but Leadwerks does. It's better and it's already set up: mat3 nmat = mat3(entitymatrix); ex_normal = normalize(nmat * vertex_normal); ex_tangent = normalize(nmat * vertex_tangent); ex_binormal = normalize(nmat * vertex_binormal); So you don't need it. In some of the lines to come instead of "worldNormal" use "normal" which is a section of about 5 lines already in the fragment part of of the Leadwerks "diffuse+normal+specular" shader which makes the normals work the same all around the model. So delete this worldNormal line and paste in this: vec3 normal = ex_normal; normal = normalize(texture(texture1,ex_texcoords0).xyz * 2.0 - 1.0); float ao = normal.z; normal = ex_tangent * normal.x + ex_binormal * normal.y + ex_normal * normal.z; normal = normalize(normal); Next we have: vec3 lightVector = normalize( lightPosition - worldPosition ); We don't have a "lightPosition" anywhere so we need to make one. Above this line write "vec3 lightPosition;" If you add no "=" sign it just defaults to 0, which is fine for us here. Then, since we have "modelvertexposition" instead of "worldPosition" this line should look like this: vec3 lightVector = normalize(lightPosition - modelvertexposition.xyz); For viewVector we have neither "cameraPosition" nor "worldPosition." So up at the top with your other uniforms add "uniform vec3 cameraposition" (one word, no capitals). This is one of those built-in words that Leadwerks recognizes but it has to be written exactly like that. So this line should be: vec3 viewVector = normalize(cameraposition - modelvertexposition.xyz); (I actually went back later and changed the line to multiplication because it wasn't working all the way around the model) vec3 viewVector = normalize(cameraposition * modelvertexposition.xyz); Next line is: float rimndotv = max(0.0, rimWidth - clamp(dot(worldNormal, viewVector), 0.0, 1.0)); We don't have rimWidth, among other things so to make this quick just copy/paste these variables above this line: vec3 albedoColor = vec3(1,1,1); vec3 sunColor = vec3(0.8,0.8,1.0); float sunStrength = 0.5; float rimWidth = 0.8; vec3 rimColor = vec3(0.5,0.7,1); float rimStrength = 0.5; float iblStrength = 0.5; vec3 iblColor = vec3(0,1,1); And because "worldNormal" is now "normal" this line should be: float rimndotv = max(0.0, rimWidth - clamp(dot(normal, viewVector),0.0,1.0)); Next line is easy. No changes: vec3 rimLight = rimndotv * rimColor * rimStrength; Next line should be: vec3 reflection = reflect(-viewVector, normal); Next line we have "reflection" as our texture coordinates, which is a vec3, rather than the vec2 of our texture coords. It's a cube map so what we need to do is add at the top of our shader with our other uniforms this: "uniform samplerCube texture5;" ( "texture5" is arbitrary. It's just far enough out of the way in case I want to add a height map later, etc.). Then in this line we simply use "texture" rather than "textureCube" and because texture5 is a cubemap it will allow us to use the vec3 texture coordinates. So this line: vec3 iblLight = iblColor * textureCube(iblCube, reflection).rgb * iblStrength; Should look like this: vec3 iblLight = iblColor * texture(texture5,reflection).rgb*iblStrength; //"rgb" or "xyz" Next line change "worldNormal" to "normal": float ndotl = max(0.0, dot(normal, lightVector)); Next no change: vec3 sunLight = sunColor * sunStrength * ndotl; Next no change: vec3 finalLight = rimLight + iblLight + sunLight; And finally: gl_FragColor = vec4( albedoColor * finalLight, 1.0 ); should be: fragData0 = vec4(albedoColor * finalLight,1.0); Ok so this will work but it as it is your diffuse texture is black. That's no good. So the solution is to put it in the fragData2 output which handles emission: Go back to your "diffuse+normal+specular" fragment shader and copy/paste everything under the "fragData0" line into your shader under the same "fragData0" line. Copy/paste these lines from the "diffuse+normal+specular" shader into your shader up near the top within the "void main ()": if (clipdistance0>0.0) discard; vec4 outcolor = ex_color; //"ex_color" is a vec4 being passed in from the vertex outcolor *= texture(texture0,ex_texcoords0); Change your fragData0 line to: fragData0 = outcolor; Move down to the fragData2 line and change it to: fragData2 = vec4( albedoColor * finalLight, specular ); And voila! //--------------------------------------------------------------------------------------------------------------------- Here's the working Leadwerks equivalent of this shader. See if you can do it before you look at the answer: https://shaderfrog.com/app/view/2716?view=fragment //Fragment #version 400 #define BFN_ENABLED 1 //Uniforms uniform sampler2D texture0;//diffuse map uniform sampler2D texture1;//normal map uniform sampler2D texture2;//specular map uniform samplerCube texture5;//cube map uniform samplerCube texture15;//BFN map uniform mat4 cameramatrix; uniform mat4 projectioncameramatrix; uniform vec2 camerarange; uniform float camerazoom; uniform vec2 buffersize; uniform mat4 camerainversematrix; uniform vec4 ambientlight; uniform vec4 materialcolorspecular; uniform mat3 cameranormalmatrix; uniform vec3 cameraposition; uniform int decalmode; uniform float materialroughness; //Inputs in vec4 ex_vertexposition; in vec2 ex_texcoords0; in vec2 ex_texcoords1; in vec4 ex_color; in float ex_selectionstate; in vec3 ex_normal; in vec3 ex_tangent; in vec3 ex_binormal; in float clipdistance0; in vec3 ex_VertexCameraPosition; in mat4 ex_entitymat; out vec4 fragData0; out vec4 fragData1; out vec4 fragData2; out vec4 fragData3; void main() { //Clip plane discard if (clipdistance0>0.0) discard; vec4 outcolor = ex_color; //Modulate blend with diffuse map outcolor *= texture(texture0,ex_texcoords0); //Normal map vec3 normal = ex_normal; normal = normalize(texture(texture1,ex_texcoords0).xyz * 2.0 - 1.0); float ao = normal.z; normal = ex_tangent * normal.x + ex_binormal * normal.y + ex_normal * normal.z; normal = normalize(normal); //Rim Lighting //from https://shaderfrog.com/app/view/2716?view=fragment //------------------------------------------------------- vec3 albedoColor = vec3(1,1,1); vec3 sunColor = vec3(0.8,0.8,1.0); float sunStrength = 0.5; float rimWidth = 0.8; vec3 rimColor = vec3(0.5,0.7,1); float rimStrength = 0.5; float iblStrength = 0.5; vec3 lightPosition; vec3 viewVector = normalize(cameraposition - ex_vertexposition.xyz);//viewVector vec3 lightVector = normalize(lightPosition * ex_vertexposition.xyz);//lightVector float rimndotv = max(0.0, rimWidth - clamp(dot(normal, viewVector),0.0,1.0)); vec3 rimLight = rimndotv * rimColor * rimStrength; vec3 reflection = reflect(-viewVector,normal); float normdot1 = max(0.0, dot(normal, lightVector)); vec3 sunLight = sunColor * sunStrength * normdot1; vec3 iblLight = 0.0 * texture(texture5,reflection).rgb*iblStrength; vec3 finalLight = rimLight + iblLight + sunLight; //------------------------------------------------------- //Output fragData0 = outcolor; #if BFN_ENABLED==1 //Best-fit normals fragData1 = texture(texture15,normalize(vec3(normal.x,-normal.y,normal.z))); fragData1.a = fragData0.a; #else //Low-res normals fragData1 = vec4(normalize(normal)*0.5+0.5,fragData0.a); #endif float specular = materialcolorspecular.r * 0.299 + materialcolorspecular.g * 0.587 + materialcolorspecular.b * 0.114; int materialflags=1; if (ex_selectionstate>0.0) materialflags += 2; if (decalmode==1) materialflags += 4;//brush if (decalmode==2) materialflags += 8;//model if (decalmode==4) materialflags += 16;//terrain fragData1.a = materialflags/255.0; fragData2 = vec4( albedoColor * finalLight, specular );//Rim/Lighting fragData3 = vec4(ex_VertexCameraPosition,1.0f); } //Vertex #version 400 #define MAX_INSTANCES 256 //Uniforms uniform vec4 materialcolordiffuse; uniform mat4 cameramatrix; uniform mat4 camerainversematrix; uniform mat4 projectioncameramatrix; 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_tangent; in vec3 vertex_binormal; //Outputs out vec4 ex_vertexposition; out vec4 ex_color; out vec2 ex_texcoords0; out vec2 ex_texcoords1; out float ex_selectionstate; out vec3 ex_normal; out vec3 ex_tangent; out vec3 ex_binormal; out float clipdistance0; out vec3 ex_VertexCameraPosition; 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; ex_vertexposition = entitymatrix_ * vec4(vertex_position, 1.0); //Clip planes if (length(clipplane0.xyz)>0.0001) { clipdistance0 = ex_vertexposition.x*clipplane0.x + ex_vertexposition.y*clipplane0.y + ex_vertexposition.z*clipplane0.z + clipplane0.w; } else { clipdistance0 = 0.0; } gl_Position = projectioncameramatrix * ex_vertexposition; 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; }
×
×
  • Create New...