≡
Products
▼
Support
▼
Company
▼
Forum
Ambiera Forum
Discussions, Help and Support.
Create a new account
,
Search
, or Login:
Create reply in
shader for web target
Posted by:
(you are not logged in)
Enter the missing letter in: "Internati?nal"
(you are not logged in)
Text:
[quote][b]csp-games[/b] wrote: Here's animated material shader, giving you a hint on how to use it as behavior, but also how you can use the texture coords to actually distort, manipulate or animate the texture. In this case I take the correct tex coords v_texCoord1.s and v_texCoord1.t and use them as angles for sin and cos, the output is then used as new coordinates. [code] // Supported types are: int, float, string, bool, color, vect3d, scenenode, texture, action /* <behavior jsname="behavior_MyTest" description="shader tests"> <property name="Something" type="float" default="1.0" /> </behavior> */ behavior_MyTest = function() { this.old_ms = 0; }; // called every frame: behavior_MyTest.prototype.onAnimate = function(node, timeMs) { // run only once: if (this.old_ms == 0) { this.old_ms=1; // shader test---- var vertexShader = ""; vertexShader +="uniform mat4 worldviewproj; \n" vertexShader +=" \n" vertexShader +="attribute vec4 vPosition; \n" vertexShader +="attribute vec4 vNormal; \n" vertexShader +="attribute vec4 vColor; \n" vertexShader +="attribute vec2 vTexCoord1; \n" vertexShader +="attribute vec2 vTexCoord2; \n" vertexShader +=" \n" vertexShader +="varying vec4 v_color; \n" vertexShader +="varying vec2 v_texCoord1; \n" vertexShader +="varying vec2 v_texCoord2; \n" vertexShader +=" \n" vertexShader +="void main() \n" vertexShader +="{ \n" vertexShader +=" v_color = vColor; \n" vertexShader +=" gl_Position = worldviewproj * vPosition; \n" vertexShader +=" v_texCoord1 = vTexCoord1.st; \n" vertexShader +=" v_texCoord2 = vTexCoord2.st; \n" vertexShader +="} "; var fragmentShader = ""; fragmentShader += "uniform sampler2D texture1; \n" fragmentShader += "uniform sampler2D texture2; \n" fragmentShader += "uniform vec4 pulse; \n" fragmentShader += " \n" fragmentShader += "varying vec2 v_texCoord1; \n" fragmentShader += "varying vec2 v_texCoord2; \n" fragmentShader += " \n" fragmentShader += "void main() \n" fragmentShader += "{ \n" fragmentShader += " vec2 texCoord; \n" fragmentShader += " texCoord[0] =cos(pulse.x)+1.0+ ((2.0+sin( mod( (v_texCoord1.s*18.0),6.2832) ))*v_texCoord1.t); \n" fragmentShader += " texCoord[1] =sin(pulse.x)+1.0+ ((2.0+sin( mod( (v_texCoord1.t*18.8),6.2832) ))*v_texCoord1.s); \n" fragmentShader += " gl_FragColor = texture2D(texture1, texCoord); \n" fragmentShader += "} \n"; myShaderCallBack = function() { var time = new Date().getTime(); var pulse = ((time % 36000)/5729.577951); ccbSetShaderConstant(2, 'pulse', pulse, pulse, pulse, pulse); // 2?, name, r,g,b,? } var newMaterial = ccbCreateMaterial(vertexShader, fragmentShader, 12, myShaderCallBack); // note, "node" is automaticly the mesh you applied this bahaviour to. not working with terrain or scene node var cube = node; ccbSetSceneNodeMaterialProperty(cube, 0, 'Type', newMaterial); //---- shader test end return false; } return true; } [/code][/quote]
Possible Codes
Feature
Code
Link
[url] www.example.com [/url]
Bold
[b]bold text[/b]
Image
[img]http://www.example.com/image.jpg[/img]
Quote
[quote]quoted text[/quote]
Code
[code]source code[/code]
Emoticons
Copyright© Ambiera e.U. all rights reserved.
Privacy Policy | Terms and Conditions | Imprint | Contact