游戏开发论坛

 找回密码
 立即注册
搜索
查看: 2192|回复: 2

提问:有关OGRE中Demo_CelShading中Shader算法效率的问题?

[复制链接]

2

主题

19

帖子

31

积分

注册会员

Rank: 2

积分
31
发表于 2005-11-3 14:54:00 | 显示全部楼层 |阅读模式
OGRE中对Shander支持的示例Demo_CelShading中的FPS要明显低于其他一般示例的FPS,
请问是否是他采用的Shader算法效率低得原因呢?能否改善呢?怎样改善。

注:其他Demo的FPS一般随面数的多少而变化,而这个示例中一旦摄像机中有了头像,FPS就急剧下降,把这个头像和算法放到其他的场景中也一样。

以下是那个算法的源码。请高手指教。

/* Cel shading vertex program for single-pass rendering
   In this program, we want to calculate the diffuse and specular
   ramp components, and the edge factor (for doing simple outlining)
   For the outlining to look good, we need a pretty well curved model.
*/
void main_vp(float4 position        : POSITION,
                         float3 normal                : NORMAL,
                         // outputs
                         out float4 oPosition : POSITION,
                         out float  diffuse                 : TEXCOORD0,
                         out float  specular         : TEXCOORD1,
                         out float  edge                 : TEXCOORD2,
                         // parameters
                         uniform float3 lightPosition, // object space
                         uniform float3 eyePosition,   // object space
                         uniform float4  shininess,
                         uniform float4x4 worldViewProj)
{
        // calculate output position
        oPosition = mul(worldViewProj, position);

        // calculate light vector
        float3 N = normalize(normal);
        float3 L = normalize(lightPosition - position.xyz);
       
        // Calculate diffuse component
        diffuse = max(dot(N, L) , 0);

        // Calculate specular component
        float3 E = normalize(eyePosition - position.xyz);
        float3 H = normalize(L + E);
        specular = pow(max(dot(N, H), 0), shininess);
        // Mask off specular if diffuse is 0
        if (diffuse == 0) specular = 0;

        // Edge detection, dot eye and normal vectors
        edge = max(dot(N, E), 0);
}

void main_fp(float diffuseIn         : TEXCOORD0,
                         float specularIn        : TEXCOORD1,
                         float edge                : TEXCOORD2,
                         
                         out float4 colour        : COLOR,
                         
                         uniform float4 diffuse,
                         uniform float4 specular,
                         
                         uniform sampler1D diffuseRamp,
                         uniform sampler1D specularRamp,
                         uniform sampler1D edgeRamp)
{
        // Step functions from textures
        diffuseIn = tex1D(diffuseRamp, diffuseIn).x;
        specularIn = tex1D(specularRamp, specularIn).x;
        edge = tex1D(edgeRamp, edge).x;

        colour = edge * ((diffuse * diffuseIn) +
                                        (specular * specularIn));
}

69

主题

450

帖子

473

积分

中级会员

战魂缔造者

Rank: 3Rank: 3

积分
473
QQ
发表于 2005-11-3 19:50:00 | 显示全部楼层

Re:提问:有关OGRE中Demo_CelShading中Shader算法效率的问题?

用MS的HLSL做的卡通渲染同样效率很低,可能在采样上面吧

2

主题

19

帖子

31

积分

注册会员

Rank: 2

积分
31
 楼主| 发表于 2005-11-7 09:25:00 | 显示全部楼层

Re: 提问:有关OGRE中Demo_CelShading中Shader算法效率的问题?

Thanks a lot for your response!
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

作品发布|文章投稿|广告合作|关于本站|游戏开发论坛 ( 闽ICP备17032699号-3 )

GMT+8, 2026-1-22 13:29

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表