Jump to content

Masterxilo

Members
  • Posts

    379
  • Joined

  • Last visited

Posts posted by Masterxilo

  1. In the vertex shader, add:

    varying vec3 modelnormal;

    in the declarations before the code.

    Then in the code, after "modelvertex = ":

    modelnormal = nmat * gl_Normal;

     

    Now go to the frag shader and extend the declaration of the cube map to this:

    #ifdef LW_CUBEMAP
    uniform samplerCube LW_CUBEMAP;
       uniform float cubemapIntensity = 1.0;
       varying vec3 modelnormal;
    #endif

    and extend:

    //Diffuse
    gl_FragData[0] = diffuse;

    to

    	//Diffuse
       #ifdef LW_CUBEMAP
           // Add cubemap
           diffuse = mix(diffuse,
                         textureCube(LW_CUBEMAP, 
                             reflect(normalize(cameraposition - vertexposition.xyz), normalize(modelnormal)) * vec3(1.0,-1.0,1.0)),
                         cubemapIntensity);
       #endif
    
    gl_FragData[0] = diffuse;	

     

    Now the only thing left to do is the declaration of an "intermediate" (= include) shader.

    Mine looks like:

    // Requires meshModelnormal.vert
    
    #define LW_DIFFUSE texture0
    #define LW_CUBEMAP texture3
    
    Include "abstract::meshCubemap.frag"

    And is called mesh_diffuse_cubemap.frag

     

    This should do the trick (it does for 2.32, shouldn't be much different in 2.28).

  2. It's actually quite easily possible to get all that info by just retrieving the ogl id of the shader by setting it and getting the current shader program.

    You can then get the name and type of each uniform defined in the shader. And you can also get the current value of any uniform with known name

    (http://forum.leadwerks.com/viewtopic.php?f=16&t=3109).

     

    This class extends the LEO::Shader class and implements the mentioned functionality:

    #pragma once
    
    #include "eleoCommon.h"
    
    ELEO_NAMESPACE_BEGIN
    
    struct Uniform
    {
       std::string name;
    
       GLint size;
    
       /*  Any of
       GL_FLOAT, GL_FLOAT_VEC2, GL_FLOAT_VEC3, GL_FLOAT_VEC4, GL_INT, GL_INT_VEC2, GL_INT_VEC3, GL_INT_VEC4, GL_BOOL, GL_BOOL_VEC2, GL_BOOL_VEC3, GL_BOOL_VEC4,
    GL_FLOAT_MAT2, GL_FLOAT_MAT3, GL_FLOAT_MAT4, GL_FLOAT_MAT2x3, GL_FLOAT_MAT2x4, GL_FLOAT_MAT3x2, GL_FLOAT_MAT3x4, GL_FLOAT_MAT4x2, GL_FLOAT_MAT4x3,
    GL_SAMPLER_1D, GL_SAMPLER_2D, GL_SAMPLER_3D, GL_SAMPLER_CUBE, GL_SAMPLER_1D_SHADOW, GL_SAMPLER_2D_SHADOW
       See http://www.opengl.org/sdk/docs/man/xhtml/glGetActiveUniform.xml*/
       GLenum type;
    };
    
    class EShader : public LEO::Shader
    {
    public:
       EShader( TEntity buf = NULL) : LEO::Shader(buf) {m_glProgram = -1;} 
    
       void LoadPostfilter(const std::string& fragshader, const std::string& defines = "")
       {
           EShader::Load("abstract::postfilter.vert", fragshader, defines);
       }
    
       void Load( const std::string& vertpath, const std::string& fragpath, const std::string& defines = "" )
       {
           __super::Load(vertpath, fragpath, defines);
           GrabGLInfo();
       }
    
       const std::list<Uniform>& GetUniforms() const {return m_uniforms;}
    
       void GetUniformf(const std::string& uniformname, GLfloat* flts) const
       {
           glGetUniformfv(m_glProgram, 
               glGetUniformLocation(m_glProgram, uniformname.c_str()),
               flts);
       }
    
       void GetUniformi(const std::string& uniformname, GLint* ints) const
       {
           glGetUniformiv(m_glProgram, 
               glGetUniformLocation(m_glProgram, uniformname.c_str()),
               ints);
       }
    
       bool IsValid() {return __super::IsValid() && glIsProgram(m_glProgram);}
    
    private:
       void GrabGLInfo()
       {
           Set();
           glGetIntegerv(GL_CURRENT_PROGRAM, &m_glProgram);
    
           GLint iUniforms; 
           glGetProgramiv(m_glProgram, GL_ACTIVE_UNIFORMS, &iUniforms);
    
           for (int i = 0; i < iUniforms; i++)
           {
               Uniform uniform; GLint x;
               char namebuffer[200] = {0};
    
               glGetActiveUniform (m_glProgram, i, sizeof(namebuffer), NULL, &uniform.size, &uniform.type, namebuffer);
    
               uniform.name = namebuffer;
               m_uniforms.push_back(uniform);
           }
           Set(false);
       }
    
       GLint              m_glProgram;
       std::list<Uniform> m_uniforms;
    };
    
    ELEO_NAMESPACE_END

     

    Just thought I might share.

    This is very handy for testing and tweaking shaders without manually copying the uniform names, types and default values to the program:

    post-150-12752433602516_thumb.png

  3. and mantain an hashtable to let me copy if already loaded.

     

    You don't have to do this yourself. If oildrum.gmf is already loaded, calling LoadModel("abstract::oildrum.gmf"); again will automatically return an instanced copy of it.

  4. When disabling vsync things do move to fast for like 1 second because the AppSpeed has to recalculate.

    But except for that, objects fall at the same speed at no matter what framerate for me.

     

    Really can't say why it doesn't work for you. Make sure UpdateAppTime() and UpdateWorld() are called once and only once per loop.

  5. For anyone interested, here's a cleaned up version of that shader that works with LE:

    // from http://www.gamedev.net/community/forums/topic.asp?topic_id=556187&whichpage=9
    // / http://www.pasteall.org/12282 (newer)
    uniform sampler2D texture0; //RenderedTexture;
    uniform sampler2D texture1; //DepthTexture;
    //uniform sampler2D LuminanceTexture;
    
    uniform float apptime;
    uniform vec2  buffersize;
    uniform vec2  camerarange;
    
    // Math constants
    const float _2PI = 2.0*3.14159265;
    
    // Effect settings
    const int   samples         = 6; // samples on each ring (3-7) ! This gets multiplied by the current ring index ! -> very expensive
    const int   rings           = 4; // ring count (2-8)
    const float aoCap           = 1.0;
    const float aoMultiplier    = 100.0;
    const float aoMultiplier2   = 1.0;
    const float depthTolerance  = 0.0000;
    const float aorange         = 60.0;// units in space the AO effect extends to (this gets divided by the camera camerarange.y range
    const float radius          = 0.5;
    const float aoexp           = 1; 
    const float noiseMultiplier = 1.0;
    
    const vec3 treshold = vec3(0.3);
    const bool allowEarlyOut = true;
    
    // Globals
    vec2 texCoord;
    
    // Functions
    inline vec2 rand(in vec2 coord) //generating random noise
    {
       float noiseX = (fract(sin(apptime*0.0001+dot(coord, vec2(12.9898,78.233)))     * 43758.5453));
       float noiseY = (fract(sin(apptime*0.0001+dot(coord, vec2(12.9898,78.233)*2.0)) * 43758.5453));
       return vec2(noiseX,noiseY) * 0.004;
    }
    
    inline float readDepth(in vec2 coord)
    {
       float depth = texture2D(texture1, coord ).x;
       return (2.0 * camerarange.x) / (camerarange.y + camerarange.x - depth * (camerarange.y-camerarange.x));
    }
    
    inline float compareDepths( in float depth1, in float depth2 )
    {
       float  diff = sqrt(clamp(1.0-(depth1-depth2) / (aorange/(camerarange.y-camerarange.x)),0.0,1.0));
       float  ao   = min(aoCap, max(0.0,depth1-depth2-depthTolerance) * aoMultiplier) * diff;
       return ao;
    }
    
    void main(void)
    {
       // Calculate texCoord of current pixel
       texCoord = gl_FragCoord.xy/buffersize;
    
       // Get color and calculate luminance
       vec3 color = texture2D(texture0,texCoord).rgb;
       vec3 luminance = color;
       luminance = clamp(max(vec3(0.0),luminance-treshold) * vec3(3.0), vec3(0.0), vec3(1.0)); // high pass, original code
    
       // Early out if the luminance is nearly white
       if (allowEarlyOut && any(greaterThanEqual(luminance, vec3(0.7)))){gl_FragColor = vec4(color,1.0); return;}
    
       // Calculate ao
       float depth     = readDepth(texCoord);
       if (allowEarlyOut && depth >= 1.0){gl_FragColor = vec4(color,1.0); return;}
    
       float aspect    = buffersize.x/buffersize.y;
       vec2  noise     = rand(texCoord);
       vec2  pixelSize = (vec2(1.0) / buffersize)/ vec2(clamp(depth,0.05,1.0))+(noise*(vec2(1.0)-noise)) * vec2(noiseMultiplier);
    
       float ao = 0.0, // Total ao
             s  = 0.0;  // Steps
    
       float fade = 1.0;
    
       for (int i = 0 ; i < rings; ++i)
       {
           float _step = _2PI / (samples*i);
           fade *= 0.5;
    
           for (int j = 0 ; j < samples*i; ++j)
           {
               float pw = (cos(j * _step) * i * radius);
               float ph = (sin(j * _step) * i * radius) * aspect;
               float d = readDepth( 
                   vec2(texCoord.s + pw * pixelSize.x, 
                        texCoord.t + ph * pixelSize.y));
    
               ao += compareDepths(depth, d)*fade;     
               s  += 1.0*fade;
           }
       }
    
       ao /= s;
       ao *= aoMultiplier2;
       ao = 1.0-ao;
       ao = clamp(ao, 0.0, 1.0);
       ao = pow(ao,aoexp);
    
       gl_FragColor = vec4(color * mix(vec3(ao), vec3(1.0), vec3(luminance)), 1.0);
       return;
    }

     

    Doesn't look too bad:

    post-150-12737548795374_thumb.jpg

  6. Yeah, but this makes pirating the engine even easier, everything people need is an engine.dll, and that is included in any le game.

    On the old forum, we were told to NEVER post any engine headers.

    On the forum here it's ok, since only registered people can access the programming section.

    But everyone can go to the showcase forum, download any game (or even just the evaluation), then go to that google code page,

    download the wrapper and he'll be ready for programming le without paying for it...

×
×
  • Create New...