shadertoy 跳动的心
来源:互联网 发布:java反序列化实例 编辑:程序博客网 时间:2024/05/04 20:08
</pre>参考<a target=_blank href="http://blog.csdn.net/candycat1992/article/details/44040273">candycat博客【ShaderToy】跳动的心❤️</a></p><p></p><p>shadertoy上原代码如下:</p><p></p><p></p><pre name="code" class="plain">// Created by inigo quilez - iq/2013// License Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.void mainImage( out vec4 fragColor, in vec2 fragCoord ){vec2 p = (2.0*fragCoord-iResolution.xy)/min(iResolution.y,iResolution.x);p.y -= 0.25; // background color vec3 bcol = vec3(1.0,0.8,0.7-0.07*p.y)*(1.0-0.25*length(p)); // animate float tt = mod(iGlobalTime,1.5)/1.5; float ss = pow(tt,.2)*0.5 + 0.5; ss = 1.0 + ss*0.5*sin(tt*6.2831*3.0 + p.y*0.5)*exp(-tt*4.0); p *= vec2(0.5,1.5) + ss*vec2(0.5,-0.5); // shape float a = atan(p.x,p.y)/3.141593; float r = length(p); float h = abs(a); float d = (13.0*h - 22.0*h*h + 10.0*h*h*h)/(6.0-5.0*h);// colorfloat s = 1.0-0.5*clamp(r/d,0.0,1.0);s = 0.75 + 0.75*p.x;s *= 1.0-0.25*r;s = 0.5 + 0.6*s;s *= 0.5+0.5*pow( 1.0-clamp(r/d, 0.0, 1.0 ), 0.1 );vec3 hcol = vec3(1.0,0.5*r,0.3)*s; vec3 col = mix( bcol, hcol, smoothstep( -0.01, 0.01, d-r) ); fragColor = vec4(col,1.0);}
</pre><pre name="code" class="plain">然后将之转为hlsl,上效果图
<img src="http://img.blog.csdn.net/20160728085616421?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="" />
这里我分别使用了direct9和direct11
代码如下:
dx11:
Texture2D tex0 <string uiname="Texture0";>;
SamplerState s0 <bool visible=false;string uiname="Sampler";>{ Filter = MIN_MAG_MIP_LINEAR; AddressU = Clamp; AddressV = Clamp;}; cbuffer cbPerDraw : register( b0 ){float4x4 tVP : VIEWPROJECTION;float4x4 tW : WORLD;float2 iResolution = float2(1.0,1.0);float iGlobalTime= 0.1;float4 cAmb <bool color=true;String uiname="Color";> = { 1.0f,1.0f,1.0f,1.0f };};struct VS_IN{float4 PosO : POSITION;float4 TexCd : TEXCOORD0;};struct vs2ps{ float4 PosWVP: SV_POSITION; float4 TexCd: TEXCOORD0;};vs2ps VS(VS_IN input){ vs2ps output; output.PosWVP = mul(input.PosO,mul(tW,tVP)); output.TexCd = input.TexCd; return output;}float4 PS(vs2ps In): SV_Target{ float2 p = (2.0*In.TexCd.xy-iResolution.xy)/min(iResolution.y,iResolution.x);p.y -= 0.25; // background color float3 bcol = float3(1.0,0.8,0.7-0.07*p.y)*(1.0-0.25*length(p)); // animate float tt = fmod(iGlobalTime,1.5)/1.5; float ss = pow(abs(tt),.2)*0.5 + 0.5; ss = 1.0 + ss*0.5*sin(tt*6.2831*3.0 + p.y*0.5)*exp(-tt*4.0); p *= float2(0.5,1.5) + ss*float2(0.5,-0.5); // shape float a = atan2(p.x,p.y)/3.141593; float r = length(p); float h = abs(a); float d = (13.0*h - 22.0*h*h + 10.0*h*h*h)/(6.0-5.0*h);// colorfloat s = 1.0-0.5*clamp(r/d,0.0,1.0);s = 0.75 + 0.75*p.x;s *= 1.0-0.25*r;s = 0.5 + 0.6*s;s *= 0.5+0.5*pow( 1.0-clamp(r/d, 0.0, 1.0 ), 0.1 );float3 hcol = float3(1.0,0.5*r,0.3)*s; float3 col =lerp( bcol, hcol, smoothstep( -0.01, 0.01, d-r) ); return float4(col,1.0);}technique10 {pass P0{SetVertexShader( CompileShader( vs_4_0, VS() ) );SetPixelShader( CompileShader( ps_4_0, PS() ) );}}
dx9:
//transformsfloat4x4 tW: WORLD; //the models world matrixfloat4x4 tV: VIEW; //view matrix as set via Renderer (EX9)float4x4 tP: PROJECTION;float4x4 tWVP: WORLDVIEWPROJECTION;float2 iResolution = float2(1.0,1.0);float iGlobalTime= 0.1;//texturetexture Tex <string uiname="Texture";>;sampler Samp = sampler_state //sampler for doing the texture-lookup{ Texture = (Tex); //apply a texture to the sampler MipFilter = LINEAR; //sampler states MinFilter = LINEAR; MagFilter = LINEAR;};//texture transformation marked with semantic TEXTUREMATRIX to achieve symmetric transformationsfloat4x4 tTex: TEXTUREMATRIX <string uiname="Texture Transform";>;//the data structure: "vertexshader to pixelshader"//used as output data with the VS function//and as input data with the PS functionstruct vs2ps{ float4 Pos : POSITION; float2 TexCd : TEXCOORD0;};// --------------------------------------------------------------------------------------------------// VERTEXSHADERS// --------------------------------------------------------------------------------------------------vs2ps VS( float4 PosO : POSITION, float4 TexCd : TEXCOORD0){ //declare output struct vs2ps Out; //transform position Out.Pos = mul(PosO, tWVP); //transform texturecoordinates Out.TexCd = mul(TexCd, tTex); return Out;}// --------------------------------------------------------------------------------------------------// PIXELSHADERS:// --------------------------------------------------------------------------------------------------float4 PS(vs2ps In): COLOR{ float2 p = (2.0*In.TexCd.xy-iResolution.xy)/min(iResolution.y,iResolution.x);p.y -= 0.25; // background color float3 bcol = float3(1.0,0.8,0.7-0.07*p.y)*(1.0-0.25*length(p)); // animate float tt = fmod(iGlobalTime,1.5)/1.5; float ss = pow(abs(tt),.2)*0.5 + 0.5; ss = 1.0 + ss*0.5*sin(tt*6.2831*3.0 + p.y*0.5)*exp(-tt*4.0); p *= float2(0.5,1.5) + ss*float2(0.5,-0.5); // shape float a = atan2(p.x,p.y)/3.141593; float r = length(p); float h = abs(a); float d = (13.0*h - 22.0*h*h + 10.0*h*h*h)/(6.0-5.0*h);// colorfloat s = 1.0-0.5*clamp(r/d,0.0,1.0);s = 0.75 + 0.75*p.x;s *= 1.0-0.25*r;s = 0.5 + 0.6*s;s *= 0.5+0.5*pow( 1.0-clamp(r/d, 0.0, 1.0 ), 0.1 );float3 hcol = float3(1.0,0.5*r,0.3)*s; float3 col =lerp( bcol, hcol, smoothstep( -0.01, 0.01, d-r) ); return float4(col,1.0);}// --------------------------------------------------------------------------------------------------// TECHNIQUES:// --------------------------------------------------------------------------------------------------technique star{ pass P0 { //Wrap0 = U; // useful when mesh is round like a sphere VertexShader = compile vs_1_1 VS(); PixelShader = compile ps_3_0 PS(); }}technique TFixedFunction{ pass P0 { //transforms WorldTransform[0] = (tW); ViewTransform = (tV); ProjectionTransform = (tP); //texturing Sampler[0] = (Samp); TextureTransform[0] = (tTex); TexCoordIndex[0] = 0; TextureTransformFlags[0] = COUNT2; //Wrap0 = U; // useful when mesh is round like a sphere Lighting = FALSE; //shaders VertexShader = NULL; PixelShader = NULL; }}
screengif居然也带水印了
就酱
最后感谢candycat提供思路
0 0
- 【ShaderToy】跳动的心
- shadertoy 跳动的心
- 【ShaderToy】跳动的心❤️
- 会跳动的心
- 跳动的心
- 跳动的心
- 跳动的心
- 跳动的心
- 心的跳动代码
- [WPF,XAML] 跳动的心
- Matlab绘制跳动的心
- 一颗跳动的心
- shadertoy
- ShaderToy
- ShaderToy
- 心在痛苦的跳动着......
- 写一个跳动的心lua
- 【Cocos Shader】Shader Animation 跳动的心
- SDUT3324顺序表应用1:多余元素删除之移位算法
- HDU 5761 Rower Bo(多校3)
- crontab 定时任务
- CentOS6.5安装与配置JDK-7
- 浅谈PHP弱类型安全
- shadertoy 跳动的心
- python包
- 关于智能家居主界面,通话记录界面设计的相关问题(ViewPager以及自定view)
- Java中ProcessBuilder使用
- 在html里嵌入JavaScript
- [Codeforces 451A] Game With Sticks (博弈)
- POJ 1995 Raising Modulo Numbers 【快速幂+同余定理】
- [Cloud Computing]Mechanisms: Virtual Disk
- Unity初识(1)