Panel użytkownika
Nazwa użytkownika:
Hasło:
Nie masz jeszcze konta?

[SFML] Animowanie Wody - Shadery

Ostatnio zmodyfikowano wczoraj o godz. 19:58
Autor Wiadomość
tBane
Temat założony przez niniejszego użytkownika
[SFML] Animowanie Wody - Shadery
» 2024-09-20 18:54:41
Witam. Chciałbym animować wodę z następującej funkcji.
void surf (Input IN, inout SurfaceOutputStandard o) {
   float2 uv = IN.worldPos.xz;
   uv.y += _Time.y;
   float4 noise = tex2D(_MainTex, uv * 0.025);
   float waves = noise.z;

   fixed4 c = saturate(_Color + waves);
   o.Albedo = c.rgb;
   o.Metallic = _Metallic;
   o.Smoothness = _Glossiness;
   o.Alpha = c.a;
  }

Potrzebuję przerobić ten kod:
C/C++
class Water
    : public sf::Drawable
    , public sf::Transformable
{
public:
   
int width, height;
   
sf::Vector2i coords;
   
   
sf::VertexArray vertexes;
   
sf::Texture waterset;
   
   
std::vector < int > waters;
   
   
Water( int x, int y, int width, int height ) {
       
       
coords.x = x;
       
coords.y = y;
       
       
this->width = width;
       
this->height = height;
       
       
waterset = sf::Texture();
       
waterset = * getTexture( "floors/0_floorset" )->texture;
       
       
vertexes.setPrimitiveType( sf::Triangles );
       
vertexes.resize( width * height * 6 ); // widthMap * heightMap * TwoTrianglesVertices
       
       
waters.resize( width * height );
       
       
int coord_x, coord_y;
       
       
for( int y = 0; y < height; y++ )
       
for( int x = 0; x < width; x++ ) {
           
           
sf::Vertex * triangles = & vertexes[( y * width + x ) * 6 ];
           
           
coord_x =( coords.x + x );
           
coord_y =( coords.y + y );
           
           
triangles[ 0 ].position = sf::Vector2f( coord_x * tileSide, coord_y * tileSide );
           
triangles[ 1 ].position = sf::Vector2f(( coord_x + 1 ) * tileSide, coord_y * tileSide );
           
triangles[ 2 ].position = sf::Vector2f( coord_x * tileSide,( coord_y + 1 ) * tileSide );
           
triangles[ 3 ].position = sf::Vector2f( coord_x * tileSide,( coord_y + 1 ) * tileSide );
           
triangles[ 4 ].position = sf::Vector2f(( coord_x + 1 ) * tileSide, coord_y * tileSide );
           
triangles[ 5 ].position = sf::Vector2f(( coord_x + 1 ) * tileSide,( coord_y + 1 ) * tileSide );
           
           
edit( x, y, 0 );
       
}
       
       
    }
   
   
void edit( int x, int y, int value ) {
       
       
if( x < 0 || x >= width || y < 0 || y >= height )
           
 return;
       
       
if( value > 3 || value < 0 )
           
 return;
       
       
waters[ y * width + x ] = value;
       
       
int global_x = coords.x + x;
       
int global_y = coords.y + y;
       
       
sf::Vertex * triangles = & vertexes[( y * width + x ) * 6 ];
       
       
int tu =( int( global_x * tileSide ) % 64 ) +( value * 64 );
       
int tv =( int( global_y * tileSide ) % 64 );
       
       
//cout << "tu: " << tu << ", tv: " << tv << "\n";
       
       
triangles[ 0 ].texCoords = sf::Vector2f( tu, tv );
       
triangles[ 1 ].texCoords = sf::Vector2f( tu + tileSide, tv );
       
triangles[ 2 ].texCoords = sf::Vector2f( tu, tv + tileSide );
       
triangles[ 3 ].texCoords = sf::Vector2f( tu, tv + tileSide );
       
triangles[ 4 ].texCoords = sf::Vector2f( tu + tileSide, tv );
       
triangles[ 5 ].texCoords = sf::Vector2f( tu + tileSide, tv + tileSide );
   
}
   
P-181608
pekfos
» 2024-09-20 19:10:44
P-181609
tBane
Temat założony przez niniejszego użytkownika
» 2024-09-20 19:13:34
Tak. Właśnie na tej podstawie chciałbym  stworzyć podobną funkcję.
P-181610
pekfos
» 2024-09-20 19:19:50
Zatem poczytaj o użyciu fragment shadera w SFML: https://www.sfml-dev.org/tutorials/2.6/graphics-shader.php
P-181611
« 1 »
  Strona 1 z 1