Jump to content

whiterabbit

Members
  • Posts

    40
  • Joined

  • Last visited

Posts posted by whiterabbit

  1. Calling it with no parameters it writes to the %appdata% (on windows) folder with a default filename, and this works fine when ran from the editor.

    When called from a published project it creates the file ok, but then crashes.

     

    To test just add something like this in App:Loop()

    if self.window:KeyHit(Key.F5) then
    self.context:Screenshot()
    end
    

     

     

    Output from running in editor:

    Executing "F:\LeadwerksProjects\BugTest_ScreenshotCrash\BugTest_ScreenshotCrash.exe"...
    Initializing Lua...
    Executing file "F:/LeadwerksProjects/BugTest_ScreenshotCrash/Scripts/Error.lua"
    Executing file "F:/LeadwerksProjects/BugTest_ScreenshotCrash/Scripts/App.lua"
    Initializing OpenGL4 graphics driver...
    OpenGL version 441
    GLSL version 430
    Device: AMD Radeon R9 200 Series
    Loading map "F:/LeadwerksProjects/BugTest_ScreenshotCrash/Maps/temp.map"...
    Loading material "F:/LeadwerksProjects/BugTest_ScreenshotCrash/materials/developer/bluegrid.mat"...
    Loading texture "F:/LeadwerksProjects/BugTest_ScreenshotCrash/materials/developer/BlueGrid.tex"...
    Loading shader "F:/LeadwerksProjects/BugTest_ScreenshotCrash/Shaders/Model/diffuse.shader"...
    Loading material "F:/LeadwerksProjects/BugTest_ScreenshotCrash/materials/developer/orangegrid.mat"...
    Loading texture "F:/LeadwerksProjects/BugTest_ScreenshotCrash/materials/developer/orangegrid.tex"...
    Loading texture "F:/LeadwerksProjects/BugTest_ScreenshotCrash/Materials/Common/bfn.tex"...
    Loading shader "F:/LeadwerksProjects/BugTest_ScreenshotCrash/Shaders/Misc/occlusionquery.shader"...
    Loading shader "F:/LeadwerksProjects/BugTest_ScreenshotCrash/Shaders/Model/Shadow/shadow.shader"...
    Loading shader "F:/LeadwerksProjects/BugTest_ScreenshotCrash/Shaders/Lighting/directionallight.shader"...
    Writing screenshot "C:\Users\Ben\AppData\Local/BugTest_ScreenshotCrash/Screenshots/screenshot1.tga"...
    Saved screenshot "C:\Users\Ben\AppData\Local/BugTest_ScreenshotCrash/Screenshots/screenshot1.tga".
    Setting breakpad minidump AppID = 251810
    Steam_SetMinidumpSteamID: Caching Steam ID: 76561198056655896 [API loaded no]
    Process Complete.

     

     

    Output from running published project (tried both encrypted and unencrypted):

     

    Initializing Lua...
    Warning: Lua sandboxing disabled.
    Executing file "C:/Users/Ben/Desktop/BugTest_ScreenshotCrash_unencrypted/Scripts/Error.lua"
    Executing file "C:/Users/Ben/Desktop/BugTest_ScreenshotCrash_unencrypted/Scripts/App.lua"
    Initializing OpenGL4 graphics driver...
    OpenGL version 441
    GLSL version 430
    Device: AMD Radeon R9 200 Series
    Loading map "C:/Users/Ben/Desktop/BugTest_ScreenshotCrash_unencrypted/Maps/start.map"...
    Loading material "C:/Users/Ben/Desktop/BugTest_ScreenshotCrash_unencrypted/materials/developer/bluegrid.mat"...
    Loading texture "C:/Users/Ben/Desktop/BugTest_ScreenshotCrash_unencrypted/materials/developer/BlueGrid.tex"...
    Loading shader "C:/Users/Ben/Desktop/BugTest_ScreenshotCrash_unencrypted/Shaders/Model/diffuse.shader"...
    Loading material "C:/Users/Ben/Desktop/BugTest_ScreenshotCrash_unencrypted/materials/developer/orangegrid.mat"...
    Loading texture "C:/Users/Ben/Desktop/BugTest_ScreenshotCrash_unencrypted/materials/developer/orangegrid.tex"...
    Loading texture "C:/Users/Ben/Desktop/BugTest_ScreenshotCrash_unencrypted/Materials/Common/bfn.tex"...
    Loading shader "C:/Users/Ben/Desktop/BugTest_ScreenshotCrash_unencrypted/Shaders/Misc/occlusionquery.shader"...
    Loading shader "C:/Users/Ben/Desktop/BugTest_ScreenshotCrash_unencrypted/Shaders/Model/Shadow/shadow.shader"...
    Loading shader "C:/Users/Ben/Desktop/BugTest_ScreenshotCrash_unencrypted/Shaders/Lighting/directionallight.shader"...
    Writing screenshot "C:\Users\Ben\AppData\Local/BugTest_ScreenshotCrash/Screenshots/screenshot3.tga"...

    It stops there and pops up with

    post-12570-0-01570500-1415341871.png

    The screenshot file is created ok but the program stops running.

     

     

     

    In the attached project press F5 and it should trigger it.

     

     

     

    EDIT: Just changed back to the non-beta branch and it is the same, crashes for me but the screenshot is written ok.

    post-12570-0-01570500-1415341871.png

    BugTest_ScreenshotCrash_published.zip

  2. You need to get the 'length' of their velocity, that will tell you how fast they are moving. You could then multiply JUMPBOOST by that value, but you should probably limit the multiplier to a certain range.

     

    I don't know how you do it in C but Lua is easy.

    local Velocity = ent:GetVelocity()
    local Speed = Velocity:GetLength()
    local JumpPower = JUMPBOOST*Speed; --todo: if Speed is 0, what will you do?
    

    • Upvote 1
  3. I first noticed this on a mesh generated using the Surface class but have also checked it against the default teapot model.

     

    The result of a pick ( World:Pick() ) will always have triangle 0 instead of whatever the correct triangle id is.

     

    I am using the latest Steam version of Leadwerks and my project is up to date. I'll try to put together a simple demonstration scene but it should be pretty easy for anyone to confirm this.

     

    It's pretty much as simple as:

    local Picked = PickInfo()
    local Hit = World:GetCurrent():Pick(StartPos,EndPos,Picked,0,true) --true for getting the 'nearest' hit
    --make sure StartPos and EndPos go through a model
    print(Picked.triangle) --always 0
    

  4. Is it possible to attach a script to an entity created with code?

    My searching suggests that there was a function called Entity:SetScript() but I can't find it when searching the documentation (and I am not at the computer with LeadWerks to test it right now).

     

    EDIT:

    Ok it looks like Entity:SetScript() does exist but isn't documented. Some documentation would be nice, I still need to experiment to see whether Script:Start() is called automatically or not after attaching it.

  5. That is C++ code, you are using Lua.

     

    Changing -> to : fixes your initial error, but you'll get another error once it gets to std::string

     

    I haven't seen the god ray script but I think this is what you need:

    camera:SetKeyValue("godray_pos", Vec3(-x, -y, -z));
    

  6. I never really thought about the shadow fading out. That's interesting.

     

    You can do the exact same thing with the shadow shader. Just copy and paste the animated shadow shader to make a new one, add it to the material, and use the same trick. Because of the shadow blur, your shadow will actually appear to fade smoothly.

     

    How do I actually do it in the shadow shader since it doesn't have a fragment shader just a vertex shader? As far as I know (and I don't know much about shaders) you can't discard during the vertex shader.

     

     

    EDIT: Should have tried it before posting. I added a very basic fragment shader to it and it works. biggrin.png

     

     

    I copied the fragment from the regular shader and took out everything I didn't need, leaving me with:

    #version 400
    //Uniforms
    uniform sampler2D texture4;//noise map
    //Inputs
    in vec2 ex_texcoords0;
    in vec4 ex_color;
    void main(void)
    {
       float NoiseV = texture(texture4,ex_texcoords0).x; //Lookup the pixel and grab its red (x) value
    
       float InvAlpha = 1-ex_color.a; //Invert range from 0...1 to 1...0
       if (InvAlpha==1) InvAlpha = 1.1; //Change 1 to 1.1 so < is true
    
       if (NoiseV<InvAlpha) discard; //If the red value of the pixel is less than the alpha value of the model, discard
    }
    

     

    And added to the vertex part:

    //at thte top
    in vec2 vertex_texcoords0;
    out vec4 ex_color;
    out vec2 ex_texcoords0;
    
    //after entitymatrix_ *= animmatrix;
    ex_texcoords0 = vertex_texcoords0;
    ex_color = vec4(entitymatrix[0][3],entitymatrix[1][3],entitymatrix[2][3],entitymatrix[3][3]);
    

    • Upvote 2
  7. Since the noise is greyscale you just take the R G or B value of the pixel and use that as your noise. To get the value of the pixel you need to pass your texture into the shader and look it up the same way it (for example) looks up the diffuse texture.

     

    This is what I'm thinking, still need to actually test it:

     

    float NoiseV = texture(texture4,ex_texcoords0).x; //Lookup the pixel and grab its red (x) value //Assuming texture4 is the noise texture
    
    float InvAlpha = 1-ex_color.a; //Invert range from 0...1 to 1...0 //(Better logic might negate the need for this)
    if (InvAlpha==1) InvAlpha = 1.1; //Change 1 to 1.1 so < is true //(Better logic would negate the need for this)
    
    if (NoiseV<InvAlpha) discard; //If the red value of the pixel is less than the alpha value of the model, discard
    

     

    EDIT:

    This is what I get from the above code, not sure what to do about the shadow the model casts (I'm not good with shaders but I try where I can)

    • Upvote 6
  8. Hmm, wouldn't a rand() function run for each pixel meaning during the time I'm reducing the alpha from 1-0 the same pixel could be discarded and then not discarded, then discarded, etc, over time instead of the constant a noise map would provide? Not sure how that would look vs a constant noise map.

     

    That's what I thought on first reading that, but if the built in rand() function is anything like the first few google results then it will return a the same value for the same input.

     

    So on the pixel shader it does a texture lookup on the above image and? I'm lost now. What is a noise value? The shades of gray in the noise texture?

     

    Since the noise is greyscale you just take the R G or B value of the pixel and use that as your noise. To get the value of the pixel you need to pass your texture into the shader and look it up the same way it (for example) looks up the diffuse texture.

     

    I'm keen to give this a try myself once I get home, will post the results if you haven't got a solution working.

  9. context->SetColor(1,1,1);

     

    Works biggrin.png , but why? ph34r.png

     

    This is my basic explanation, hopefully I'm not too wrong.

     

    When the image is drawn the color of each pixel is multiplied against the color set by context->SetColor.

     

    So for example if pixel in the image is white (RGB = 255,255,255), and the context color is white (1,1,1), then they get multplied together.

    R := 255 x 1.0 = 255
    G := 255 x 1.0 = 255
    B := 255 x 1.0 = 255

     

    If the context color was black (0,0,0) everything would be multiplied by 0: 255x0=0

     

    If the image pixel as red (255,0,0), and the context color was 50% grey (0.5,0.5,0.5) the final color would be a darker red (127,0,0)

    R := 255 x 0.5 = 127
    G :=   0 x 0.5 = 0
    B :=   0 x 0.5 = 0

     

    And the final example, the reason you would use this feature, is if your image was white you can use the context color to color the image. So, image is white (255,255,255) and say context color is orange (1,0.47,0)

    R := 255 x 1.0  = 255
    G := 255 x 0.47 = 120
    B := 255 x 0.0  = 0
    

    • Upvote 1
  10. I haven't tried these functions myself, I was just browsing the documentation when I came across them and was hoping someone could clarify. The Steamworks class seems to provide functions for working with game controllers and I assume you have to initialize Steamworks for it to work. If distributing your game outside of Steam does this mean you can't access the controllers? Or do I have it wrong and you can access the controller functions without initializing it?

     

    EDIT: Well, that page says it itself "Note: Steamworks must be initialized before using the Steam Controller functions."

    So, is there a way to access joysticks/controllers (from Lua?) without Steamworks?

     

    MORE EDIT: After looking at this I realise I might have misunderstood, Steamworks functions are only for working with actual Steam Controller... I jumped the gun and assumed it was any kind of controller.

  11. Ok thanks, that's easy enough. But is it not possible to do it with just one shader applied with context:SetShader before drawing all my GUI?

    I'm hoping to have it be able to switch on and off. I could do it by editting both those shaders as you've said and adding a uniform value to toggle it on and off but from what I've read it's not a good idea to do boolean things like that in shader code?

     

    EDIT:

    For now I've gone ahead and done that - editted them and added a uniform value that will be 1 or 0 for whether greyscale is active, then used mix() to get the output.

     

    //in drawimage.shader
    
    //added a uniform
    uniform int GrayscaleActive;
    
    //changed main loop
    void main(void)
    {
       vec4 color = drawcolor * texture(texture0,vTexCoords0);
       float l = color.r * 0.2126 + color.g * 0.7152 + color.b * 0.0722;
       vec4 lumCol = vec4(l,l,l,color.a);
       fragData0 = mix(color,lumCol,GrayscaleActive);
    }
    

  12. I'm trying to use context:SetShader before drawing my GUI but it requires a different kind of shader I guess, if I use the same grayscale shader then the whole context becomes invisible (transparent?).

    I'm really inexperienced with shaders and have only really copy and paste-editted them up to this point. I've tried modifying some of the default 'Drawing' shaders but haven't been able to get anything that just modifies the colour of what I draw to the context - I always end up with either a solid block of color, an unrelated image over the top, or nothing.

    The default grayscale shader is easy to enough to understand, I just don't know why it won't work when used for context:SetShader

  13. I'm using the default grayscale posteffect shader to make everything black and white, but this doesn't affect anything drawn during Script:PostRender(context) (eg, red text is still red). Is it possible to make a shader apply after drawing takes place? Or any solution easier than manually changing the colour/textures of GUI elements - ideally more advanced shaders could also be used.

     

     

    This script shows my problem. You can put this script on any entity and link it to a camera, you will see everything is greyscale except the text 'Always red'.

    Script.Camera = nil --entity "Camera"
    Script.Enabled = true --bool "Enabled"
    
    function Script:Start()
    self.WasEnabled = -1
    end
    
    function Script:_Enable()
    self.Camera:AddPostEffect("Shaders/PostEffects/grayscale.shader")
    end
    
    function Script:_Disable()
    self.Camera:ClearPostEffects()
    end
    
    function Script:UpdateWorld()
    if self.Enabled~=self.WasEnabled then
    if self.Enabled then
    self:_Enable()
    else
    self._Disable()
    end
    end
    self.WasEnabled = self.Enabled
    end
    
    function Script:PostRender(context)
    context:SetBlendMode(Blend.Solid)
    context:SetColor(1,0,0,1)
    context:DrawText("Always red", 5, 5)
    end

     

     

     

    EDIT: Right after posting this I found context:SetShader, it sounds like what I want. And the forum ruined my code indentation sad.png

  14. I've managed to get a Buffer (and Texture) filled with the current screen. I want to write it to a file, so my game will have a builtin screenshot feature.

    Leadwerks 2 apparently had a function SaveBuffer which would do exactly what I want, but as far as I can tell it doesn't exist or has been renamed to something else.

    So, before I try to manually write the bytes to a file, does anyone know if there is a current function for writing a buffer to an image file? (Or maybe there is complete function for taking a screenshot that I don't know about?)

     

    EDIT: How do I even get individual values out of a buffer?

×
×
  • Create New...