Wings 3D Development Forum

Full Version: A new release
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3 4 5 6
I figured that much after porting the shader to be GLSL 4.2+ compliant to remap the texture units using the layout keyword. I've found the diffuse, normal and environment map.

I have some understanding of coding.. maybe I'll take a look when I've got some spare time.

Would be neat to have a realtime preview in Wings too Wink
I would prefer if you modified the default shader, which I used for bump maps.

The current way the shaders work are an ugly hack and should be rewritten, sigh..

But in the mean time I would like a "uber shader" that handles everything possible,
like I did with normal maps. But I GLSL 4.2+ is a little high for our users...
more like GLSL 1.0 :-(

But maybe we should change that..
Would porting it to 4.2+ make wings require 4.2 compliant hardware across the board? or only for using "advanced" shader features?

4.2 is almost 3 years old, and while many probably still have hardware older than that, it'll only decrease over time.
@Nova
when you choose HELP / OpenGL Info
...you can see it is possible to check what the user is using.
...another option is to let the user choose what is supported from the hardware

so, it is possible to program a support for some target hardware at the same time (support for old and new)
[Image: f8MV5c.png]

hemilight.vs
Code:
// $Id$
//
// Vertex shader for hemispherical lighting
//
// Author: Randi Rost
//
// Copyright (C) 2005 3Dlabs, Inc.
//
// See 3Dlabs-License.txt for license information
//
// modified by rattle 2014-06-22

const int LIGHT_COUNT = 2;
attribute vec4 wings_tangent;

varying vec3 normal;
varying vec3 lightVec[LIGHT_COUNT];
varying vec3 eyeVec;
varying vec4 color;
varying vec4 tangent;

void main(void)
{
    vec3 viewPos = vec3(gl_ModelViewMatrix * gl_Vertex);
    eyeVec = normalize(-viewPos);
    for (int i = 0; i < LIGHT_COUNT; ++i) {
        lightVec[i] = normalize(gl_LightSource[i].position.xyz - viewPos);
    }
    color    = gl_FrontMaterial.diffuse * gl_Color;
    normal    = gl_NormalMatrix * gl_Normal;
    tangent.xyz = gl_NormalMatrix * wings_tangent.xyz;
    tangent.w = wings_tangent.w;
    gl_TexCoord[0]    = gl_MultiTexCoord0;
#ifdef __GLSL_CG_DATA_TYPES // Fix clipping for Nvidia and ATI
    gl_ClipVertex   = gl_ModelViewMatrix * gl_Vertex;
#endif
    gl_Position     = ftransform();
}

hemilight.fs
Code:
// $Id$
//
// Fragment shader for hemispherical lighting
//
// Author: Dan Gudmundsson
//
// modified by rattle 2014-06-22

const int LIGHT_COUNT = 2;

uniform int UseDiffuseMap;
uniform int UseNormalMap;

uniform sampler2D DiffuseMap;
uniform sampler2D NormalMap;

varying vec3 normal;
varying vec3 lightVec[LIGHT_COUNT];
varying vec3 eyeVec;
varying vec4 color;
varying vec4 tangent;

vec3 get_normal(vec3 T, vec3 N, float W, sampler2D M, vec2 C) {
    N = normalize(N);
    T = normalize(T);
    T = normalize(T - dot(T, N) * N);
    vec3 B = cross(T, N) * W;
    mat3 TBN = mat3(T, B, N);
    return normalize(TBN * (2.0 * texture2D(M, C).xyz - 1.0));
}

void main(void)
{
    vec3 N = UseNormalMap>0?get_normal(tangent.xyz, normal, tangent.w, NormalMap, gl_TexCoord[0].xy):normalize(normal);
    vec4 diffuseColor = UseDiffuseMap>0?texture2D(DiffuseMap, gl_TexCoord[0].xy):color;
    vec4 diffuse, specular;
    
    for (int i = 0; i < LIGHT_COUNT; ++i) {
        gl_LightSource[i].diffuse = vec4(1.0);
        gl_LightSource[i].ambient = vec4(1.0);
        gl_LightSource[i].specular = vec4(1.0);

        vec3 E = eyeVec;
        vec3 L = lightVec[i];
        float NdotL = dot(N, L);
        if (NdotL > 0.0) {
            vec3 R = normalize(reflect(-L, N));
            diffuse += gl_FrontLightProduct[i].diffuse * NdotL;
            specular += gl_FrontLightProduct[i].specular * pow(max(dot(R, E), 0.0), clamp(gl_FrontMaterial.shininess, 1.0, 128.0));
        }
    }
    gl_FragColor = gl_FrontLightModelProduct.sceneColor + diffuseColor * diffuse + specular;
}

Okay, I've changed your shader so it takes specularity into account, which can be controlled by the shininess material property and spec color.

In the fragment shader change LIGHT_COUNT to 1 or 2, it uses either one or two hardcoded lights. Somehow gl_FrontLightProduct[].ambient always appears as black... gl_FrontLightModelProduct.sceneColor has the ambient/emissive color in it though, so it should be fine as viewport shader.
That looks really neat!
I have learned a lot from there information !!
That's really looking great.
very nice
undefined
Pages: 1 2 3 4 5 6