Passing a float from c++ to the pixel shader
category: general [glöplog]
Hej,
iam programming my first pixel shader, but how can i pass data to the hlsl code?
Displays a nice color an the screen, but how can i use Data from the c++ side?
How can i pass the
DWORD currentTime = timeGetTime();
currentTime to the pixel shader?
Thaaanx
iam programming my first pixel shader, but how can i pass data to the hlsl code?
Code:
// hlsl pixel shader
struct PS_IN {
float4 pos : SV_POSITION;
//float4 k : LOLIMASEMANTIC;
//float4 color : COLOR;
};
struct PS_OUT {
float4 color : COLOR;
};
PS_OUT SimplePixelShader(PS_IN input) : SV_Target {
PS_OUT output;
output.color.g = 0.0f;
output.color.r = input.pos.r/1280;
output.color.b = input.pos.g/720;
return output;
}
Displays a nice color an the screen, but how can i use Data from the c++ side?
How can i pass the
DWORD currentTime = timeGetTime();
currentTime to the pixel shader?
Thaaanx
Iam on DX11
In that case you have to create a constant buffer: https://msdn.microsoft.com/en-us/library/windows/desktop/ff476896%28v=vs.85%29.aspx
HLSL:
DX_Effect->SetFloat("t", time);
DX_Effect->SetFloat("t", time);
You can pass in whatever you want, it´s easy once you know how to, but always remember: passing out ain´t possible, except you write your data to some Texture! ;) (isPossible == true)
Declare a constant buffer in your hlsl code: (you can have an implicit default constant buffer if you want for size reasons, but..)
create a constant buffer and bind it to the pixel shader:
Update the buffer data every frame:
hardy: effect is so dx9 ;)
Code:
cbuffer mybuffer{ int time; }
create a constant buffer and bind it to the pixel shader:
Code:
D3D11_BUFFER_DESC ConstBufferDesc = {16, D3D11_USAGE_DEFAULT,D3D11_BIND_CONSTANT_BUFFER,0,0,0};
pDevice->CreateBuffer( &ConstBufferDesc, NULL, &pConstants);
pImmediateContext->PSSetConstantBuffers( 0, 1, &pConstants );
Update the buffer data every frame:
Code:
int time = timeGetTime();
pImmediateContext->UpdateSubresource(pConstants,0,0,&time,4,4);
hardy: effect is so dx9 ;)
Psycho: i love you and all you do!
But why the overhead size of a struct for a simple "field","member","variable" ?
But why the overhead size of a struct for a simple "field","member","variable" ?
Didn't want to go all out dirty 1k style ;)
But if you just declare variables in the global scope they will actually form an implicit constant buffer (I think it's only there if no explicit buffer is declared). Of course it then becomes harder to figure out the byte offsets for the variables in that case.
The above code (even without the cbuffer{}) with a single value is more overhead than dx9/ogl, but with more variables it's nice just moving a chunk of data instead of setting a bunch of different kinds.
But if you just declare variables in the global scope they will actually form an implicit constant buffer (I think it's only there if no explicit buffer is declared). Of course it then becomes harder to figure out the byte offsets for the variables in that case.
The above code (even without the cbuffer{}) with a single value is more overhead than dx9/ogl, but with more variables it's nice just moving a chunk of data instead of setting a bunch of different kinds.
memorywize 32bit is still just like 0.5 times amount of data...why do i still use dx9? ;)
i did global illumination in a directx9-shader, so what for going up at all? tessellation? noone needs this feat, concerning intros! :p
i did global illumination in a directx9-shader, so what for going up at all? tessellation? noone needs this feat, concerning intros! :p