Używam Ogre3D jako silnika graficznego.Czy robię coś nie tak z tym programem CG?
utworzyć siatkę ręcznie, co działa dobrze, UVS są poprawne i są ustawione do reprezentowania współrzędne siatki (w tym przykładzie siatka to 10 x 10)
zrobić nic w programie wierzchołków i mają bardzo prosty program fragmentów. Objaśniłem oba programy oraz plik materiałowy.
Mój problem polega na tym, że nawet przy ustawieniu filtrowania na none kolory nie wydają się być takie same, jak mój oryginalny obraz (jest to tylko obraz testowy, którego używam, ponieważ miałem problemy z ręcznym tworzeniem tekstury w ogr). Okazuje się, że problem nie jest moim kodem w ogre, ale bardziej prawdopodobny jest jakiś związek z plikiem materialnym lub programami fragment/vertex.
Mam również zrzut ekranu wyjścia po lewej stronie i oryginalny obraz po prawej stronie. Shader fragmentów rysuje prostą siatkę nad wierzchołkiem, dzięki czemu mogłem upewnić się, że współrzędne uv zostały poprawnie przekazane. Które wydają się być.
Każdy wgląd byłby znacznie ceniona, jak jestem naprawdę pewien, co robię źle.
Materiał file:
// CG Vertex shader definition
vertex_program PlainTexture_VS cg
{
// Look in this source file for shader code
source GameObjStandard.cg
// Use this function for the vertex shader
entry_point main_plain_texture_vp
// Compile the shader to vs_1_1 format
profiles arbvp1
// This block saves us from manually setting parameters in code
default_params
{
// Ogre will put the worldviewproj into our 'worldViewProj' parameter for us.
param_named_auto worldViewProj worldviewproj_matrix
// Note that 'worldViewProj' is a parameter in the cg code.
}
}
// CG Pixel shader definition
fragment_program PlainTexture_PS cg
{
// Look in this source file for shader code
source GameObjStandard.cg
// Use this function for the pixel shader
entry_point main_plain_texture_fp
// Compile to ps_1_1 format
profiles arbfp1
}
material PlainTexture
{
// Material has one technique
technique
{
// This technique has one pass
pass
{
// Make this pass use the vertex shader defined above
vertex_program_ref PlainTexture_VS
{
}
// Make this pass use the pixel shader defined above
fragment_program_ref PlainTexture_PS
{
}
texture_unit 0
{
filtering none
// This pass will use this 2D texture as its input
texture test.png 2d
}
texture_unit 1
{
texture textureatlas.png 2d
tex_address_mode clamp
filtering none
}
}
}
}
CG Plik:
void main_plain_texture_vp(
// Vertex Inputs
float4 position : POSITION, // Vertex position in model space
float2 texCoord0 : TEXCOORD0, // Texture UV set 0
// Outputs
out float4 oPosition : POSITION, // Transformed vertex position
out float2 uv0 : TEXCOORD0, // UV0
// Model Level Inputs
uniform float4x4 worldViewProj)
{
// Calculate output position
oPosition = mul(worldViewProj, position);
// Simply copy the input vertex UV to the output
uv0 = texCoord0;
}
void main_plain_texture_fp(
// Pixel Inputs
float2 uv0 : TEXCOORD0, // UV interpolated for current pixel
// Outputs
out float4 color : COLOR, // Output color we want to write
// Model Level Inputs
uniform sampler2D Tex0: TEXUNIT0,
uniform sampler2D Tex1: TEXUNIT1) // Texture we're going to use
{
//get the index position by truncating the uv coordinates
float2 flooredIndexes = floor(uv0);
if((uv0.x > 0.9 && uv0.x < 1.1)
|| (uv0.x > 1.9 && uv0.x < 2.1)
|| (uv0.x > 2.9 && uv0.x < 3.1)
|| (uv0.x > 3.9 && uv0.x < 4.1)
|| (uv0.x > 4.9 && uv0.x < 5.1)
|| (uv0.x > 5.9 && uv0.x < 6.1)
|| (uv0.x > 6.9 && uv0.x < 7.1)
|| (uv0.x > 7.9 && uv0.x < 8.1)
|| (uv0.x > 8.9 && uv0.x < 9.1)) {
float4 color1 = {1.0,0,0,0};
color = color1;
} else if((uv0.y > 0.9 && uv0.y < 1.1)
|| (uv0.y > 1.9 && uv0.y < 2.1)
|| (uv0.y > 2.9 && uv0.y < 3.1)
|| (uv0.y > 3.9 && uv0.y < 4.1)
|| (uv0.y > 4.9 && uv0.y < 5.1)
|| (uv0.y > 5.9 && uv0.y < 6.1)
|| (uv0.y > 6.9 && uv0.y < 7.1)
|| (uv0.y > 7.9 && uv0.y < 8.1)
|| (uv0.y > 8.9 && uv0.y < 9.1)) {
float4 color1 = {1.0,0,0,0};
color = color1;
} else {
//get the colour of the index texture Tex0 at this floored coordinate
float4 indexColour = tex2D(Tex0, (1.0/10)*flooredIndexes);
color = indexColour;
}
}
Dzięki za edycję, ja byłem pewien czy jak umieścić obrazy w :) –
zmieniając 'float4 indexColour = tex2D (Tex0 (1.0/10) * flooredIndexes);' na ' float4 indexColour = tex2D (Tex0, (1.0/20) * flooredIndexes); 'może rozwiązać problem. – hamed
Nie jestem pewien, czy to pomogło lub nie, to nie rozwiązało problemu. Powodem, dla którego mnożyłem się o 1/10 jest to, że indeksy w uv0 biegną obecnie od 0 do 10 w kierunku u i v. Podaję tę wartość, ponieważ jest ona interpolowana w programie fragmentów, więc otrzymuję wartości takie jak 5.6, jeśli podaję tę wartość, otrzymuję 5, która podzielona przez liczbę szerokości płytek (10) daje mi współrzędną uv, której potrzebuję, 0,5 –