Bonjour à tous,
je voudrais créer un effet de réflexion pour plus tard afficher cette réflexion sur de l'eau mais j'ai un problème. J'ai créer ma texture de réflexion qui fait la taille de ma fenêtre (il faut encore que j'applique un plan de clipping quand je créer ma texture mais là n'est pas le problème )et j'ai un plan qui représente l'eau qui est de taille 100px*100px et une height map qui est de taille 256*256px, j'applique ma texture sur le e plan mais j'obtiens ceci:
Mon code du shader:
Et ma fonction pour créer le plan :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41 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; };
Une idée du problème?
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42 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; }
Merci.
Partager