eGospodarka.pl
eGospodarka.pl poleca

eGospodarka.plGrupypl.comp.programmingcpu shading by sse intrinsics › cpu shading by sse intrinsics
  • X-Received: by 10.140.96.197 with SMTP id k63mr139370qge.0.1403952485787; Sat, 28 Jun
    2014 03:48:05 -0700 (PDT)
    X-Received: by 10.140.96.197 with SMTP id k63mr139370qge.0.1403952485787; Sat, 28 Jun
    2014 03:48:05 -0700 (PDT)
    Path: news-archive.icm.edu.pl!agh.edu.pl!news.agh.edu.pl!newsfeed2.atman.pl!newsfeed.
    atman.pl!goblin2!goblin.stu.neva.ru!feeder.erje.net!us.feeder.erje.net!news.glo
    rb.com!hn18no16496960igb.0!news-out.google.com!a8ni0qaq.1!nntp.google.com!i13no
    2342904qae.1!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mai
    l
    Newsgroups: pl.comp.programming
    Date: Sat, 28 Jun 2014 03:48:05 -0700 (PDT)
    Complaints-To: g...@g...com
    Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=93.154.170.198;
    posting-account=Sb6m8goAAABbWsBL7gouk3bfLsuxwMgN
    NNTP-Posting-Host: 93.154.170.198
    User-Agent: G2/1.0
    MIME-Version: 1.0
    Message-ID: <4...@g...com>
    Subject: cpu shading by sse intrinsics
    From: firr <p...@g...com>
    Injection-Date: Sat, 28 Jun 2014 10:48:05 +0000
    Content-Type: text/plain; charset=ISO-8859-2
    Content-Transfer-Encoding: quoted-printable
    Xref: news-archive.icm.edu.pl pl.comp.programming:206077
    [ ukryj nagłówki ]

    w moim rasteryzerze mam blog do flat shadingu
    trojkatów od 4rech swiateł - wyglada on wyjatkowo niechlujnie moim zdaniem ale do
    końca nie wiem co
    z nim zrobic



    // input: float x1, y1, z1, x2, y2, z2, x3, y3, z3;


    static float3 lightDir1= {0.2, -1.6, -1.7 };
    static float3 lightDir2 = {0.5, -0.7, 20.3 };
    static float3 lightDir3 = {-0.5,-0.3, -0.6 };
    static float3 lightDir4 = {-0.5, 1.3, 0.6 };

    static float3 lightColor1= {.4, .414, .515 };
    static float3 lightColor2 = {.4145, .451, .543 };
    static float3 lightColor3 = {.584, .51414, .43 };
    static float3 lightColor4 = {.41, .44, .3414 };


    float3 u = {x2-x1, y2-y1, z2-z1 };
    float3 v = {x3-x2, y3-y2, z3-z2 };

    float3 normal = cross_(u,v);

    // normal.x = (y2-y1)*(z3-z2) - (z2-z1)*(y3-y2);
    // normal.y = (z2-z1)*(x3-x2) - (x2-x1)*(z3-z2);
    // normal.z = (x2-x1)*(y3-y2) - (y2-y1)*(x3-x2);

    normalize(&normal);

    float s1 = dot(normal, lightDir1);
    float s2 = dot(normal, lightDir2);
    float s3 = dot(normal, lightDir3);
    float s4 = dot(normal, lightDir4);


    if(s1<0) s1=0;
    if(s2<0) s2=0;
    if(s3<0) s3=0;
    if(s4<0) s4=0;


    int b = (color&0x000000ff);
    int g = (color&0x0000ff00)>>8;
    int r = (color&0x00ff0000)>>16;

    float lr= .1 + (s1*lightColor1.x + s2*lightColor2.x + s3*lightColor3.x+
    s4*lightColor4.x);
    float lg= .1 +(s1*lightColor1.y + s2*lightColor2.y + s3*lightColor3.y+
    s4*lightColor4.y);
    float lb= .1 + (s1*lightColor1.z + s2*lightColor2.z + s3*lightColor3.z+
    s4*lightColor4.z);


    r*=lr;
    g*=lg;
    b*=lb;

    if(r>255) r=255;
    if(g>255) g=255;
    if(b>255) b=255;

    return rgb(b,g,r);

    chodzi o dwie rzeczy
    1) jak ew przyspieszyc czy ladniej to zapisac z poziomu c
    2) jak przepisac to i przyspieszyc przy pomocy sse intrinsics (uzywam mingw gcc 4.7
    wiec tak zeby poszlo pod tym kompilatorem)

    glownie chodzi o ta drugą rzecz, nie mam moze nawet w sumie az tak duzo czasu na to
    ;/ ale z drugiej strony troche podlubac by sie przydalo ;\

Podziel się

Poleć ten post znajomemu poleć

Wydrukuj ten post drukuj


Następne wpisy z tego wątku

Najnowsze wątki z tej grupy


Najnowsze wątki

Szukaj w grupach

Eksperci egospodarka.pl

1 1 1

Wpisz nazwę miasta, dla którego chcesz znaleźć jednostkę ZUS.

Wzory dokumentów

Bezpłatne wzory dokumentów i formularzy.
Wyszukaj i pobierz za darmo: