directx - Changing shader variables within the same frame -


this perhaps newbie question again i've inherited lot of 3d code need maintain.

on broad level, question is possible use single shader technique render multiple objects within same frame while using different textures every object being rendered. so, in short, shader variables reset multiple times between 1 beginscene , endscene.

here briefly shader code

texture g_meshtexture; texture g_meshtexturetextleft; texture g_meshtexturetextright;  sampler meshtexturesampler = sampler_state {     texture = <g_meshtexture>;     mipfilter = linear;     minfilter = linear;     magfilter = linear; };  sampler meshtexturesamplertextleft = sampler_state {     texture = <g_meshtexturetextleft>;     mipfilter = linear;     minfilter = linear;     magfilter = linear; };  sampler meshtexturesamplertextright = sampler_state {     texture = <g_meshtexturetextright>;     mipfilter = linear;     minfilter = linear;     magfilter = linear; };  vstexture_output_2 vstexturev1_1     (     float4 position : position,      float2 texcoord : texcoord0    ) {      vstexture_output_2 out = (vstexture_output_2)0;      float3 p = mul(position, g_mworldview);            //position (view space)      out.position = mul(float4(p, 1), g_mprojection);    //projected position     out.texcoord = texcoord;                        //texture coordinates     out.texcoord2 = texcoord;     out.texcoord3 = texcoord;      return out;     }  ps_output generictextureps( vstexture_output_2 in )  {      ps_output output;      float4 main = tex2d(meshtexturesampler, in.texcoord);     float4 left = tex2d(meshtexturesamplertextleft, in.texcoord2);     float4 right = tex2d(meshtexturesamplertextright, in.texcoord3);     float4 usecolor;       if (left.a > right.a )         usecolor = left;     else          usecolor = right;      if (usecolor.a == 0)         output.rgbcolor = main;     else          output.rgbcolor = usecolor;     return output; }  technique generictexture {     pass p0     {         vertexshader = compile vs_1_1 vstexturev1_1();         pixelshader  = compile ps_1_1 generictextureps();         } } 

now within main render loop, depending upon object, set 3 input texture variables

pseudocode  render() { beginscene()     seteffect("g_meshtexture", firsttexture);       rendershader();     seteffect("g_meshtexture", secondtexture);       rendershader();     .... endscene() } 

i have thought work based upon examples have seen, app hangs @ beginscene after frame painted first time.

i appreciate pointers i've been struggling quite time now.

many thanks!


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -