当前位置: 首页>>代码示例>>Java>>正文


Java Shader.getUniform方法代码示例

本文整理汇总了Java中com.jme3.shader.Shader.getUniform方法的典型用法代码示例。如果您正苦于以下问题:Java Shader.getUniform方法的具体用法?Java Shader.getUniform怎么用?Java Shader.getUniform使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.jme3.shader.Shader的用法示例。


在下文中一共展示了Shader.getUniform方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: updateLightListUniforms

import com.jme3.shader.Shader; //导入方法依赖的package包/类
/**
 * Uploads the lights in the light list as two uniform arrays.<br/><br/>
 *      * <p>
 * <code>uniform vec4 g_LightColor[numLights];</code><br/>
 * // g_LightColor.rgb is the diffuse/specular color of the light.<br/>
 * // g_Lightcolor.a is the type of light, 0 = Directional, 1 = Point, <br/>
 * // 2 = Spot. <br/>
 * <br/>
 * <code>uniform vec4 g_LightPosition[numLights];</code><br/>
 * // g_LightPosition.xyz is the position of the light (for point lights)<br/>
 * // or the direction of the light (for directional lights).<br/>
 * // g_LightPosition.w is the inverse radius (1/r) of the light (for attenuation) <br/>
 * </p>
 */
protected void updateLightListUniforms(Shader shader, Geometry g, int numLights) {
    if (numLights == 0){ // this shader does not do lighting, ignore.
        return;
    }

    LightList lightList = g.getWorldLightList();
    Uniform lightColor = shader.getUniform("g_LightColor");
    Uniform lightPos = shader.getUniform("g_LightPosition");
    lightColor.setVector4Length(numLights);
    lightPos.setVector4Length(numLights);

    Uniform ambientColor = shader.getUniform("g_AmbientLightColor");
    ambientColor.setValue(VarType.Vector4, getAmbientColor(lightList));
    
    int lightIndex = 0;
    
    for (int i = 0; i < numLights; i++) {
        if (lightList.size() <= i) {
            lightColor.setVector4InArray(0f, 0f, 0f, 0f, lightIndex);
            lightPos.setVector4InArray(0f, 0f, 0f, 0f, lightIndex);
        } else {
            Light l = lightList.get(i);
            ColorRGBA color = l.getColor();
            lightColor.setVector4InArray(color.getRed(),
                    color.getGreen(),
                    color.getBlue(),
                    l.getType().getId(),
                    i);

            switch (l.getType()) {
                case Directional:
                    DirectionalLight dl = (DirectionalLight) l;
                    Vector3f dir = dl.getDirection();
                    lightPos.setVector4InArray(dir.getX(), dir.getY(), dir.getZ(), -1, lightIndex);
                    break;
                case Point:
                    PointLight pl = (PointLight) l;
                    Vector3f pos = pl.getPosition();
                    float invRadius = pl.getRadius();
                    if (invRadius != 0) {
                        invRadius = 1f / invRadius;
                    }
                    lightPos.setVector4InArray(pos.getX(), pos.getY(), pos.getZ(), invRadius, lightIndex);
                    break;
                case Ambient:
                    // skip this light. Does not increase lightIndex
                    continue;
                default:
                    throw new UnsupportedOperationException("Unknown type of light: " + l.getType());
            }
        }
        
        lightIndex++;
    }
    
    while (lightIndex < numLights){
        lightColor.setVector4InArray(0f, 0f, 0f, 0f, lightIndex);
        lightPos.setVector4InArray(0f, 0f, 0f, 0f, lightIndex);
        
        lightIndex++;
    }
}
 
开发者ID:mleoking,项目名称:PhET,代码行数:77,代码来源:Material.java

示例2: updateLightListUniforms

import com.jme3.shader.Shader; //导入方法依赖的package包/类
@Deprecated
protected void updateLightListUniforms(Shader shader, Geometry g, int numLights) {
    if (numLights == 0) { // this shader does not do lighting, ignore.
        return;
    }
    
    LightList worldLightList = g.getWorldLightList();
    ColorRGBA ambLightColor = new ColorRGBA(0f, 0f, 0f, 1f);
    lightList.ensureCapacity(worldLightList.size());
    
    for (int i = 0; i < worldLightList.size(); i++) {
        Light light = worldLightList.get(i);
        if (light instanceof AmbientLight) {
            ambLightColor.addLocal(light.getColor());
        } else {
            lightList.add(light);
        }
    }
    numLights = lightList.size();
    this.setInt("NumLights", numLights);
    Uniform lightColor = shader.getUniform("g_LightColor");
    Uniform lightPos = shader.getUniform("g_LightPosition");
    Uniform lightDir = shader.getUniform("g_LightDirection");
    lightColor.setVector4Length(4);
    lightPos.setVector4Length(4);
    lightDir.setVector4Length(4);

    Uniform ambientColor = shader.getUniform("g_AmbientLightColor");
    ambLightColor.a = 1.0f;
    ambientColor.setValue(VarType.Vector4, ambLightColor);
    
    for (int i = 0; i < numLights; i++) {
        
        Light l = lightList.get(i);
        ColorRGBA color = l.getColor();
        lightColor.setVector4InArray(color.getRed(),
                color.getGreen(),
                color.getBlue(),
                l.getType().getId(),
                i);

        switch (l.getType()) {
            case Directional:
                DirectionalLight dl = (DirectionalLight) l;
                Vector3f dir = dl.getDirection();
                lightPos.setVector4InArray(dir.getX(), dir.getY(), dir.getZ(), -1, i);
                break;
            case Point:
                PointLight pl = (PointLight) l;
                Vector3f pos = pl.getPosition();
                float invRadius = pl.getInvRadius();
                lightPos.setVector4InArray(pos.getX(), pos.getY(), pos.getZ(), invRadius, i);
                break;
            case Spot:
                SpotLight sl = (SpotLight) l;
                Vector3f pos2 = sl.getPosition();
                Vector3f dir2 = sl.getDirection();
                float invRange = sl.getInvSpotRange();
                float spotAngleCos = sl.getPackedAngleCos();

                lightPos.setVector4InArray(pos2.getX(), pos2.getY(), pos2.getZ(), invRange, i);
                lightDir.setVector4InArray(dir2.getX(), dir2.getY(), dir2.getZ(), spotAngleCos, i);
                break;
            default:
                throw new UnsupportedOperationException("Unknown type of light: " + l.getType());
        }
    }
    lightList.clear();
}
 
开发者ID:shamanDevel,项目名称:ProceduralTerrain,代码行数:70,代码来源:SPLightMaterial.java


注:本文中的com.jme3.shader.Shader.getUniform方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。