脚本与渲染器 .

news/2025/2/26 7:15:06

       一直以来都想做一个脚本驱动的渲染器.就是说可以用脚本定制渲染器的行为,比如创建多少个渲染队列,如何渲染.多少RenderTarget, 每个物体的材质也是一样. 要生成多少个Pass,每个Pass是立即渲染呢还是放到那个队列里 .
      其实我是个很懒的人 ,这个想法早在去年就有了.一直拖到现在,昨天晚上实在受不了自己的懒惰了.也受点老宋一些刺激,顺手就抓了个AngelScript.把它集成到 渲染器里了.一个简单的渲染脚本类似如下
int  queueNormal;
int  queueTranslucy;
int  queueGlow;
int  texScreen;
int  quadShader;
int  colorMorphShader;
int  rt;
int x , y ;
int x2 , y2;
int dx , dy;
int dx2 , dy2;
void StartRenderer()
{
      x = 0;
      y = 0;
      dx = 1;
      dy = 2;

      x2 = 10;
      y2 = 40;
      dx2 = 2;
      dy2 = 1;

      queueNormal    = createQueue("Normal");
      queueTranslucy = createQueue("Translucy");
      queueGlow      = createQueue("Glow");
      texScreen      = load2DTexture("default","videoTexture.mpeg");
      quadShader     = loadShader("Simple.shader");
      colorMorphShader     = loadShader("SimpleColorMorph.shader");
      rt             = createRenderTexture("RT",1024,1024,1);
}


void StopRenderer()
{
    clearRenderContex();
}

 

void Render(float passedTime)
{
      x += dx;
      y += dy;
      if(x < 0 || x > 600) dx =-dx;
      if(y < 0 || y > 400) dy =-dy;

      x2 += dx2;
      y2 += dy2;
      if(x2 < 0 || x2 > 600) dx2 =-dx2;

      if(y2 < 0 || y2 > 400) dy2 =-dy2;
      renderQueue(queueNormal);

      pushRenderTexture(rt,0);
      clearScene(1.0f,0.0f,0.0f,1.0f,1,0);
      renderQueue(queueNormal);
      popRenderTexture();

      enter2DMode();
 
      pushShader(quadShader); 
      draw2DTextureRect(rt,x,y,500,400,1.0,1.0,1.0,1.0);
      popShader();

      pushShader(colorMorphShader);
      draw2DTextureRect(texScreen,x2,y2,400,300,1.0,1.0,1.0,1.0);
      popShader();
      leave2DMode();
}

AngelScript是C语法的. 可以方便的把脚本稍加转化编译进程序里,或者做成dll插件的形式,在发布程序的时候能保证最大的效率.非常的不错.

以上这个脚本能在正常绘制一个普通渲染队列以外,额外的绘制两个矩形.  脚本能控制渲染器多少的行为完全看你给脚本暴露了多少的接口.





http://www.niftyadmin.cn/n/3647797.html

相关文章

laravel入门_Laravel入门

laravel入门视频 (Video) 关于谈话 (About the Talk) Laravel — a free, open-source PHP web application framework — is one of the best ways to build web applications. It is a strong framework that gives many niceties out of the box, freeing you to create wit…

项目开发中源代码树的组织

很多人多很重视自己代码的可读性,重用性等,尽量让自己的代码看上去更加的雅观,因为很多人都认为这是代码优劣的门面光. 不过,我却认为,代码的门面光应该是源代码树的组织. 因为,别人看你的代码首先看到的目录结构.一个良好的目录结构,能很方便的让你定位到你需要的组…

css 垂直对齐_CSS垂直对齐属性

css 垂直对齐介绍 (Introduction) vertical-align defines the vertical alignment for the content of a table cell or for an inline element against the rest of the inline flow. vertical-align定义表格单元格的内容或内联元素相对于其余内联流的垂直对齐方式。 vertic…

一道智力题的数学解

最近看数学。都看的有点锈逗了。看到一道智力题&#xff0c;情不自禁的用数学来解了。。只是不知道结果对不对。题目&#xff1a; 已知&#xff1a;每个飞机只有一个油箱&#xff0c; 一箱油可供一架飞机绕地球飞180度。飞机之间可以相互加油&#xff08;注意是相互&…

JavaScript Reduce方法介绍

介绍 (Introduction) Reduce is a method that can be difficult to understand especially with all the vague explanations that can be found on the web. There are a lot of benefits to understanding reduce as it is often used in state management (think Redux). 减…

模型动画系统设计的一些心得

模型动画系统设计的一些心得&#xff1a;模型系统是一个渲染引擎里的重要组成部分。它的质量直接关系到引擎的渲染效率,和开发效率。我觉得评价一个模型系统主要包含两个方面&#xff1a;一&#xff1a; 算法。 算法这东西其实是挺透明的。网上到处可以找到这些东西的资料。其…

web设置字体粗细css_Web上使用CSS的可变字体

web设置字体粗细cssFont variations is a new set of features defined as part of the OpenType specification. It allows for font files to contain multiple variation of a font within a single file, called a variable font. This in turns allows the use of one fon…

Gameres论坛里某大师的语录 (2007-7-11更新)

最近gameres越来越堕落了.变成了一个灌水乐园.以下是某大师级人物--VB区的游戏之家---的语录,可惜别删了不少,不然更精彩啊.收集的晚了点啊.太遗憾了.好久没更新了。 今天看到一些猛料,实在受不了.置顶, 讨论的是<变形金刚>这个游戏.游戏之家站长Exp:3181骑士队长 发表于…