Jump to content
  • Advertisement
Sign in to follow this  
arkerone

Reflection effect = problem

This topic is 2482 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi everybody,

I would like to create a reflection effect to display later this reflection on the water but I have a problem. I create my reflection texture (seen from below but it don't have the clipping plane but that's not the problem), I have a plan that represent the water, it's 100px * 100px size and applied my texture on this plan but I get this:

reflectionni.jpg

My shader code:

Texture2D reflection:register(t5);
SamplerState s:register(s0);
cbuffer ConstantBuffer:register(b1){
Matrix mFull;
Matrix mFullReflection;
float4 lightDirection;
float4 ambientColor;
float4 diffuseColor;
float2 sizePlane;
};
struct VSin {
float3 pos: POSITION;
float3 normal: NORMAL;
};
struct VSout {
float4 pos: SV_POSITION;
float4 reflectionPosition : TEXCOORD;
float3 normal: NORMAL;

};
struct PSin {
float4 position : SV_POSITION;
float4 reflectionPosition : TEXCOORD;
float3 normal : NORMAL;
};
VSout VSmain( VSin Vin) {
VSout Vout = (VSout)0;
Vout.pos = mul(float4(Vin.pos,1), mFull );
Vout.normal=Vin.normal;
Vout.reflectionPosition = mul(float4(Vin.pos,1), mFullReflection );
return Vout;
};
float4 PSmain( PSin Pin ) : SV_Target {
float4 reflectionColor;
float2 reflectTexCoord;
reflectTexCoord.x = Pin.reflectionPosition.x / Pin.reflectionPosition.w / 2.0f + 0.5f;
reflectTexCoord.y = -Pin.reflectionPosition.y / Pin.reflectionPosition.w / 2.0f + 0.5f;
reflectionColor = reflection.Sample(s, reflectTexCoord);

return reflectionColor;
};


My fonction to create the plane:

bool Plane::initBuffers(ID3D11Device* p_device){
D3DXVECTOR3 v1,v2,v3,v4,v5,v6;
D3DXVECTOR3 n,n1,n2,n3,n4,n5,n6;
HRESULT res;
int index=0;

m_nbVertex = 4;
m_nbIndices = 6;
m_nbFaces = 2;
m_vertex = new Vertex_T[m_nbVertex];
m_indices= new UINT[m_nbIndices];

m_vertex[0].position=D3DXVECTOR3(0.f,m_height,0.f);
m_vertex[2].position=D3DXVECTOR3(static_cast<float>(m_width),m_height,0.f);
m_vertex[1].position=D3DXVECTOR3(0.f,m_height,static_cast<float>(m_lenght));
m_vertex[3].position=D3DXVECTOR3(static_cast<float>(m_width),m_height,static_cast<float>(m_lenght));
m_vertex[0].normal=D3DXVECTOR3(0.f,-1.f,0.f);
m_vertex[1].normal=D3DXVECTOR3(0.f,-1.f,0.f);
m_vertex[2].normal=D3DXVECTOR3(0.f,-1.f,0.f);
m_vertex[3].normal=D3DXVECTOR3(0.f,-1.f,0.f);

m_indices[index++] = 0;
m_indices[index++] = 1;
m_indices[index++]= 3;
m_indices[index++] = 0;
m_indices[index++] = 3;
m_indices[index++] = 2;

//vertex buffer
D3D11_BUFFER_DESC BufDescVertex = { m_nbVertex *sizeof(Vertex_T), D3D11_USAGE_DEFAULT, D3D11_BIND_VERTEX_BUFFER, 0,0,0 };
D3D11_SUBRESOURCE_DATA BufDataVertex = { m_vertex, 0, 0 };
res=p_device->CreateBuffer(&BufDescVertex, &BufDataVertex, &m_vertexBuffer);
if(FAILED(res))
return false;
// index buffer
D3D11_BUFFER_DESC BufDescIndex = { m_nbIndices*sizeof(UINT), D3D11_USAGE_DEFAULT,D3D11_BIND_INDEX_BUFFER, 0,0,0 };
D3D11_SUBRESOURCE_DATA BufDataIndex = { m_indices, 0, 0 };
res=p_device->CreateBuffer(&BufDescIndex, &BufDataIndex, &m_indexBuffer);
if(FAILED(res))
return false;
return true;
}


Thx for your help.

Share this post


Link to post
Share on other sites
Advertisement
The image must be projected in image space. If you don't mirror the camera, you must mirror the result. Let the clipping show a little bit extra to hide artifacts from waves.

This code sample using my own engine shows how simplified reflection and refraction works on a high level.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!