HLSL DirectX9: Is there a getTime () function or similar?

I am currently working on a project using C ++ and DirectX9, and I am studying the creation of a light source that changes over time.

I know that C ++ has a timeGetTime () function, but was wondering if anyone knows about a function in HLSL that will allow me to do this?

Sincerely. Mike.

+3
source share
4 answers

Use the shader constant in HLSL (see introduction ). Here is a sample HLSL code that uses timeInSeconds to change the texture coordinate:

// HLSL
float4x4 view_proj_matrix; 
float4x4 texture_matrix0; 
// My time in seconds, passed in by CPU program
float    timeInSeconds;

struct VS_OUTPUT 
{ 
   float4 Pos     : POSITION; 
   float3 Pshade  : TEXCOORD0; 
}; 


VS_OUTPUT main (float4 vPosition : POSITION) 
{ 
   VS_OUTPUT Out = (VS_OUTPUT) 0;  

   // Transform position to clip space 
   Out.Pos = mul (view_proj_matrix, vPosition); 

   // Transform Pshade 
   Out.Pshade = mul (texture_matrix0, vPosition);

   // Transform according to time
   Out.Pshade = MyFunctionOfTime( Out.Pshade, timeInSeconds );

   return Out; 
} 

(), Begin() , :

// C++
myLightSourceTime = GetTime(); // Or system equivalent here:
m_pEffect->SetFloat ("timeInSeconds ", &myLightSourceTime); 

, PDF. HLSL (, bool, float, float4, float4x4 ).

+6

HLSL, GLSL.

"" "". "" , "" .

- , GLSL "", HLSL.

, .

- . ( , OpenGL). , .

+4

. "". CPU , (, , ..), GPU - . ( ) , ( ).

+1

HLSL Unity, _Time.

0

Source: https://habr.com/ru/post/1724237/


All Articles