-
Posts
556 -
Joined
-
Last visited
Content Type
Blogs
Forums
Store
Gallery
Videos
Downloads
Everything posted by havenphillip
-
That looks great. Can we do vertex displacement in LE4? I found this little code segment on the internet. I get it in the editor but not in-game on the brush. vec4 dv = textureLod(texture3,ex_texcoords0.xy,0.0); float df = 0.015*dv.x + 0.024*dv.y + 0.021*dv.z; vec4 newVertexPos = vec4(vec3(dv.xyz* ex_normal*0.01) * df * 100.0, 0.0) + ex_vertexposition; gl_Position = (projectioncameramatrix * newVertexPos);
-
Cool, man. I had fun trying to solve that one.
-
This appears to be doing it. It's limiting the zoom but the wheel is cumulative I don't know how to fix that. Once you reach the limit, if you keep rolling the wheel it keeps counting it... Script.minZoom = 0 Script.maxZoom = 30 Script.curZoom = 0 function Script:Zoom() local oldWheelPos = 0.0 if self.currentMousePos ~= nil then oldWheelPos = self.currentMousePos.z end self.currentMousePos = window:GetMousePosition() self.currentMousePos.x = Math:Round(self.currentMousePos.x) self.currentMousePos.y = Math:Round(self.currentMousePos.y) local newWheelPos = (self.currentMousePos.z - oldWheelPos) if oldWheelPos < 0.0 then self.entity:Move(0,0,self.curZoom) self.curZoom = 0 - newWheelPos System:Print("Zoom in") if self.currentMousePos.z < self.minZoom then --limits max in zoom self.curZoom = 0 end elseif oldWheelPos > 0.0 then self.entity:Move(0,0,-self.curZoom) self.curZoom = 0 + newWheelPos System:Print("Zoom out") if self.currentMousePos.z > self.maxZoom then -- limits max out zoom self.curZoom = 0 end end end
-
You know what I just assumed there was something like a "mouse.back." I made it up as a dummy command because I thought you already had something there. I sort of got it working from this post. I've never bothered with the mouse wheel: This sort of works: function Script:UpdateWorld() self.maxZoom = 10 self.minZoom = 0 local oldWheelPos = 0.0 if self.currentMousePos ~= nil then oldWheelPos = self.currentMousePos.z end self.currentMousePos = window:GetMousePosition() self.currentMousePos.x = Math:Round(self.currentMousePos.x) self.currentMousePos.y = Math:Round(self.currentMousePos.y) local newWheelPos = (self.currentMousePos.z - oldWheelPos) * 0.1 if newWheelPos > 0.0 or newWheelPos < 0.0 then self.curZoom = oldWheelPos + newWheelPos self.camera:Move(0,0,self.curZoom) self.curZoom = Math:Clamp(self.curZoom, self.minZoom, self.maxZoom) -- limits the zoom to stay between min and max zoom end
-
Something like: function Script:UpdateWorld() if MouseWheel(Mouse.Back) then cameraposition.z = cameraposition.z - 1 end if MouseWheel(Mouse.Forward) then cameraposition.z = cameraposition.z + 1 end Math:Clamp(cameraposition.z,0, 10) end
-
You could try Math:Clamp(number to clamp, minimum zoom, maximum zoom) https://www.leadwerks.com/learn?page=API-Reference_Object_Math_Clamp
-
Is there a way to get rid of this doubling up of the gun and hands in the refraction shader? I'm wracking my brain here. Here's my fragment shader: #version 400 #define BFN_ENABLED 1 //Uniforms uniform sampler2D texture0;//diffuse map uniform sampler2D texture1;//light map uniform sampler2D texture2;//specular map uniform samplerCube texture5;//cube map uniform sampler2DMS texture9; uniform sampler2D texture10;//screen color uniform samplerCube texture15;//BFN map uniform vec4 materialcolorspecular; //uniform vec4 lighting_ambient; //uniform vec4 ambientlight; uniform int decalmode; uniform float materialroughness; uniform vec2 buffersize; uniform bool isbackbuffer; //Camera uniforms uniform mat4 cameramatrix; uniform mat4 projectioncameramatrix; uniform vec2 camerarange; uniform float camerazoom; uniform mat4 camerainversematrix; uniform mat3 cameranormalmatrix; uniform vec3 cameraposition; //My uniforms #define BUMPINESS 0.01 //Inputs in vec2 ex_texcoords0; in vec4 ex_color; in float ex_selectionstate; in vec3 ex_VertexCameraPosition; in vec4 ex_vertexposition; 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; float DepthToZPosition(in float depth) { return camerarange.x / (camerarange.y - depth * (camerarange.y - camerarange.x)) * camerarange.y; } void main(void) { //Clip plane discard if (clipdistance0>0.0) discard; vec4 outcolor = ex_color; vec4 color_specular = materialcolorspecular; //Normal map vec3 normal = ex_normal; normal = 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); //Refraction //----------------------------------------------------------------- vec2 texcoord = (gl_FragCoord.xy / buffersize); if (isbackbuffer) texcoord.y = 1.0f - texcoord.y; vec3 texAdjust = vec3(texcoord.x,texcoord.y,1.0); //vec3 texAdjust = (vec3(texcoord.x*1.2,texcoord.y,1.5)+0.2 //+vec3(texcoord.x,texcoord.y+0.1,1.2) //+vec3(texcoord.x,texcoord.y/2.0,1.2)+0.5); texAdjust = normalize(texAdjust); vec4 screencolor = textureProj(texture10,texAdjust + normal.xyz*BUMPINESS); outcolor = screencolor * 0.75; //----------------------------------------------------------------- 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 = color_specular.r * 0.299 + color_specular.g * 0.587 + color_specular.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 if (materialroughness>=0.5) { materialflags += 32; if (materialroughness>=0.75) materialflags += 64; } else { if (materialroughness>=0.25) materialflags += 64; } fragData1.a = materialflags/255.0; fragData2 = vec4(0.0,0.0,0.0,specular); fragData3 = vec4(ex_VertexCameraPosition,1.0f); }
-
What do you already have? I bet it's as simple as adding a timer to it.
-
How do you access imported terrain in code?
havenphillip replied to havenphillip's topic in Programming
My bad. I did something else and forgot. The terrain works fine. Sorry about that lol. But is there a way to access the imported terrain in script? -
Wet and rainy environment. I haven't quite worked out all the kinks but this is pretty good. An improved wet terrain from my last one, an object "wettener" shader and a rain shader. Included a map showing it all together in Wet Environment/Maps. Also the mud material and skybox I used in the map. Create a pivot and attach the wet.lua script. Drag a material to your terrain platform and attach wetterrain.lua script. Put rain.lua in the PostEffects box under the root in the Scene tab. Credits to Shadmar, Ma-Shell, and a few things from Shadertoy somewhere I don't even know. Wet Environment.zip
-
I have this wettening effect I'm working on but as soon as I create terrain everything vanishes. So I want to know how to tell it not to count the .raw.
-
Oh, duh. I was telling it to go nil for k,v in pairs (self.modelTable) do for i = 0, self.modelTable[k]:CountSurfaces()-1, 1 do surface = self.modelTable[k]:GetSurface(i) mat = surface:GetMaterial() mat:SetShader(shader) shader:SetVec4("ex_color",self.color) mat:SetColor(self.color) self.modelTable[k] = nil -- derp end end
-
Ah man now I'm getting "attempt to index nil value" error when I add a crawler to the scene. What's that about? Do I need to do some kind of CountChildren() cycle? for k,v in pairs (self.modelTable) do for i = 0, self.modelTable[k]:CountSurfaces()-1, 1 do surface = self.modelTable[k]:GetSurface(i) <- giving me an error on this line mat = surface:GetMaterial() mat:SetShader(shader) shader:SetVec4("ex_color",self.color) mat:SetColor(self.color) self.modelTable[k] = nil end end
-
Ah thanks! This seems to be working so far: for k,v in pairs (self.modelTable) do for i = 0, self.modelTable[k]:CountSurfaces()-1, 1 do surface = self.modelTable[k]:GetSurface(i) mat = surface:GetMaterial() mat:SetShader(shader) shader:SetVec4("ex_color",self.color) mat:SetColor(self.color) self.modelTable[k] = nil end end
-
I keep getting this error. How can I fix this? I'm trying to grab everything in the scene and change the color of it with a bounding box. It works fine so long as I don't put a model in the scene that has a model childed to it. The "generator_withbutton.mdl" is an example. When I put that in the scene I get the error. for k,v in pairs (self.modelTable) do surface = self.modelTable[k]:GetSurface(0) mat = surface:GetMaterial() mat:SetShader(shader) shader:SetVec4("ex_color",self.color) mat:SetColor(self.color) self.modelTable[k] = nil end
-
Is there a way to access an entity's current material from code?
havenphillip replied to havenphillip's topic in Programming
Ah it's my shader. I got it. Thanks for reading lol -
Is there a way to access an entity's current material from code?
havenphillip replied to havenphillip's topic in Programming
Ah ok I see. But now it's blue, even though the color is set to 1,1,1. How do I fix that?: surface = self.entity:GetSurface(0) mat = surface:GetMaterial() mat:SetColor(1,1,1) shader = Shader:Load("Gloss/wet_rock.shader"); mat:SetShader(shader) self.entity:SetMaterial(mat) shader:SetFloat("puddlesize", self.puddleSize) shader:SetFloat("puddlefade", self.puddleFade) shader:SetFloat("intensity" , self.intensity) mat:Release() -
Is there a way to access an entity's current material from code?
havenphillip replied to havenphillip's topic in Programming
Actually I see GetSurface() but I'm getting this funky looking rock which ought to look more like the second picture. Here's my code here so far: function Script:Start() --mat = Material:Load("Gloss/wet_rock.mat") mat = Material:Create() surface = self.entity:GetSurface(0) surface:SetMaterial(material) shader = Shader:Load("Gloss/wet_rock.shader"); mat:SetShader(shader) self.entity:SetMaterial(mat) shader:SetFloat("puddlesize", self.puddleSize) shader:SetFloat("puddlefade", self.puddleFade) shader:SetFloat("intensity" , self.intensity) mat:Release() end -
In the above timer script you have to use "defaultFont = context:GetFont()" at the start of your PostRender() function, then you set the font to the font you want with " context:SetFont(self.font) ", then you "DrawText(...)" and after you have to set it back to the default font with " context:SetFont(defaultFont)." I'm guessing you have other scripts that use the DrawText() function? You have to use "defaultFont = context:GetFont()" and " context:SetFont(defaultFont) " in every script that uses "DrawText(...)". Basic Font script: This shouldn't change your other fonts because you're resetting the font back to the default here: Script.myFont = "" --path "Font" Script.color = Vec4(1,1,1,1) --color "Color" Script.size = 12 function Script:Start() self.myFont= Font:Load(self.myFont,self.size) end function Script:PostRender(context) defaultFont = context:GetFont() --at start of every postrender function context:SetBlendMode(1) context:SetColor(self.color) context:SetFont(self.myFont) -- changed to your font context:DrawText("My Text" ,20,20,100,100) context:SetFont(defaultFont) -- change font back to default at end of every postrender function anywhere "SetFont()" and "DrawText()" are used end
-
The clock isn't restarting because the script is calling Time:GetCurrent(). When you change maps the application doesn't restart, so it's counting the application running time. So what you need is Time:GetSpeed(). That's probably a better way to do a timer anyway. Script.font = "" -- path "Font" -- use TrueType font file Script.pos = Vec2(0,30) -- Vec2 "Position" Script.size = 15 -- float "Size" Script.color = Vec4(1,1,0,1) -- color "Color" Script.offset = 20 -- int "Offset" -- make larger if numbers get cut off Script.countSpeed = 0.05 -- float "Count Speed" (smaller is slower) Script.time = 0 function Script:Start() self.font = Font:Load(self.font,self.size) if self.font == nil then Debug:Error("Select a font") end end function Script:UpdateWorld() self.counter = Time:GetSpeed() * self.countSpeed self.time = self.time + self.counter end function Script:PostRender(context) defaultFont = context:GetFont() r = self.size + self.offset w = self.pos.x + window:GetWidth()/2 - self.offset h = self.pos.y context:SetBlendMode(1) context:SetColor(self.color) context:SetFont(self.font) context:DrawText(Math:Round(self.time),w,h,r,r,Text.VCenter+Text.Center) context:SetFont(defaultFont) end Not sure what you mean by the font sizes. You want to change the font in the gui?
-
I would try something like: function Script:UpdateWorld() If window:KeyHit(Key.A) then changemapname=self.mapname end Here's the triggerChangeMap script. --[[ This script will act as a trigger to change the current map. Place this at the end of your map to make the player progress to the next level. ]]-- Script.mapname=""--string "Map Name" function Script:Start() self.enabled=true end function Script:Collision(entity, position, normal, speed) changemapname=self.mapname end function Script:Enable()--in if self.enabled==false then self.enabled=true self:CallOutputs("Enable") end end function Script:Disable()--in if self.enabled then self.enabled=false self:CallOutputs("Disable") end end
-
Yeah Macklebee is pretty good. I fiddled with this script for a long time. Here's this as a circular minimap. You can just drop the prefab in your scene to see it working. basic minimap.zip
-
You can also change the terrain quality in-game. If you start your game then hit Esc you can adjust terrain quality in options.
-
Did you try unchecking the mipmaps box in the diffuse texture editor?