⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 phongtexturepixelshader.cg

📁 基于java的3d开发库。对坐java3d的朋友有很大的帮助。
💻 CG
字号:
//===========================================================================
//= This fragment shader follows the parameters indicated in the VitralSDK  =
//= shader programming guidelines, as documented in the file                =
//= ./doc/shaderStandards.txt inside the main VitralSDK distribution        =
//= directory.  Please refer to that file to get a clear understanding of   =
//= variable names and common programming patterns used.                    =
//= Note that any variable name or registry assigment change could make the =
//= shader incompatible with main VitralSDK shader framework!               =
//===========================================================================

/**
Note that first sampler2D is by default associated with default OpenGL
texture map (the one currently binded).  Aditional sampler2D maps can
be explicity specified using the cgGLEnableTextureParameter function.

Remember that in Cg, the `lit` function gives:
    clampedTerms.y = (NdolL > 0)?NdolL:0.0;
    clampedTerms.z = (NdolL > 0 && NdotH > 0)?pow(NdotH, phongExponent):0.0;
and is recommended to use it as can give access to optimized operations in
the GPU.
*/
half4 main(uniform sampler2D textureMap,
           uniform half3 lightColor,
           uniform half3 phongExponent,
           uniform half withTexture,
           in float3 PView              : TEXCOORD0,
           in half3 NView               : TEXCOORD1,
           in half2 uvTextureCoordinate : TEXCOORD2,
           in half3 cameraPositionView  : TEXCOORD3,
           in half3 lightPositionView   : TEXCOORD4,
           in half3 Ka                  : TEXCOORD5,
           in half3 Kd                  : COLOR0,
           in half3 Ks                  : COLOR1) : COLOR
{
    //-----------------------------------------------------------------------
    // Prepare basic illumination model variables
    half3 N = normalize(NView);
    half3 L = normalize(lightPositionView - PView);
    half3 V = normalize(cameraPositionView - PView);
    half3 H = normalize(L + V);
    half NdotL = dot(N, L);
    half NdotH = dot(N, H);
    half3 clampedTerms = lit(NdotL, NdotH, phongExponent);

    //-----------------------------------------------------------------------
    // Apply illumination model's equations
    half3 diffuseComponent;
    diffuseComponent = Kd * clampedTerms.y;

    if ( withTexture > 0.0 ) {
        diffuseComponent = diffuseComponent *
            (half3)tex2D(textureMap, uvTextureCoordinate).xyz;
    }
    half3 specularComponent = Ks * clampedTerms.z;
    half3 finalColor =
      Ka + lightColor * (diffuseComponent + specularComponent);

    //-----------------------------------------------------------------------
    // Return final color, setting alpha value to 1
    return half4(finalColor, 1);
}

//===========================================================================
//= EOF                                                                     =
//===========================================================================

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -